updated czech translation
[phpmyadmin/crack.git] / tbl_move_copy.php3
blobc0e5aae08057ae85ff4ce395ac2c52e7e9e4d043
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Insert data from one table to another one
8 * @param string the original insert statement
10 * @global string the database name
11 * @global string the original table name
12 * @global string the target database and table names
13 * @global string the sql query used to copy the data
15 function PMA_myHandler($sql_insert = '')
17 global $db, $table, $target;
18 global $sql_insert_data;
20 $sql_insert = eregi_replace('INSERT INTO (`?)' . $table . '(`?)', 'INSERT INTO ' . $target, $sql_insert);
21 $result = PMA_mysql_query($sql_insert) or PMA_mysqlDie('', $sql_insert, '', $GLOBALS['err_url']);
23 $sql_insert_data .= $sql_insert . ';' . "\n";
24 } // end of the 'PMA_myHandler()' function
27 /**
28 * Gets some core libraries
30 require('./libraries/grab_globals.lib.php3');
31 require('./libraries/common.lib.php3');
34 /**
35 * Defines the url to return to in case of error in a sql statement
37 $err_url = 'tbl_properties.php3'
38 . '?lang=' . $lang
39 . '&amp;convcharset=' . $convcharset
40 . '&amp;server=' . $server
41 . '&amp;db=' . urlencode($db)
42 . '&amp;table=' . urlencode($table);
45 /**
46 * Selects the database to work with
48 PMA_mysql_select_db($db);
51 /**
52 * A target table name has been sent to this script -> do the work
54 if (isset($new_name) && trim($new_name) != '') {
55 $use_backquotes = 1;
56 $asfile = 1;
58 if (get_magic_quotes_gpc()) {
59 if (!empty($target_db)) {
60 $target_db = stripslashes($target_db);
61 } else {
62 $target_db = stripslashes($db);
64 $new_name = stripslashes($new_name);
67 // Ensure the target is valid
68 if (count($dblist) > 0 &&
69 (PMA_isInto($db, $dblist) == -1 || PMA_isInto($target_db, $dblist) == -1)) {
70 exit();
72 if (PMA_MYSQL_INT_VERSION < 32306) {
73 PMA_checkReservedWords($target_db, $err_url);
74 PMA_checkReservedWords($new_name, $err_url);
77 $source = PMA_backquote($db) . '.' . PMA_backquote($table);
78 $target = PMA_backquote($target_db) . '.' . PMA_backquote($new_name);
80 include('./libraries/build_dump.lib.php3');
82 $sql_structure = PMA_getTableDef($db, $table, "\n", $err_url);
83 $parsed_sql = PMA_SQP_parse($sql_structure);
84 // no need to PMA_backquote()
85 $parsed_sql[2]['data'] = $target;
86 $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
88 // do not create the table if dataonly
89 if ($what != 'dataonly') {
90 $result = @PMA_mysql_query($sql_structure);
91 if (PMA_mysql_error()) {
92 include('./header.inc.php3');
93 PMA_mysqlDie('', $sql_structure, '', $err_url);
94 } else if (isset($sql_query)) {
95 $sql_query .= "\n" . $sql_structure . ';';
96 } else {
97 $sql_query = $sql_structure . ';';
99 } else {
100 $sql_query='';
103 // Copy the data
104 if ($result != FALSE && ($what == 'data' || $what == 'dataonly')) {
105 // speedup copy table - staybyte - 22. Juni 2001
106 if (PMA_MYSQL_INT_VERSION >= 32300) {
107 $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
108 $result = @PMA_mysql_query($sql_insert_data);
109 if (PMA_mysql_error()) {
110 include('./header.inc.php3');
111 PMA_mysqlDie('', $sql_insert_data, '', $err_url);
113 } // end MySQL >= 3.23
114 else {
115 $sql_insert_data = '';
116 PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $err_url);
117 } // end MySQL < 3.23
118 $sql_query .= "\n\n" . $sql_insert_data;
121 // Drops old table if the user has requested to move it
122 if (isset($submit_move)) {
123 $sql_drop_table = 'DROP TABLE ' . $source;
124 $result = @PMA_mysql_query($sql_drop_table);
125 if (PMA_mysql_error()) {
126 include('./header.inc.php3');
127 PMA_mysqlDie('', $sql_drop_table, '', $err_url);
129 $sql_query .= "\n\n" . $sql_drop_table . ';';
130 $db = $target_db;
131 $table = $new_name;
134 $message = (isset($submit_move) ? $strMoveTableOK : $strCopyTableOK);
135 $message = sprintf($message, $source, $target);
136 $reload = 1;
137 $js_to_run = 'functions.js';
138 include('./header.inc.php3');
139 } // end is target table name
143 * No new name for the table!
145 else {
146 include('./header.inc.php3');
147 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
152 * Back to the calling script
154 require('./tbl_properties.php3');