diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 0ddd2f2b16..69a52a2234 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -405,7 +405,6 @@ $goto_whitelist = array( 'tbl_create.php', 'tbl_import.php', 'tbl_indexes.php', - 'tbl_move_copy.php', 'tbl_printview.php', 'tbl_sql.php', 'tbl_export.php', diff --git a/libraries/operations.lib.php b/libraries/operations.lib.php index 2f94d65c64..a37ee6b600 100644 --- a/libraries/operations.lib.php +++ b/libraries/operations.lib.php @@ -1599,4 +1599,92 @@ function PMA_getQueryAndResultForPartition() return array($sql_query, $result); } + +/** + * Move or copy a table + * + * @param string $db current database name + * @param string $table current table name + * + * @return void + */ +function PMA_moveOrCopyTable($db, $table) +{ + /** + * Selects the database to work with + */ + $GLOBALS['dbi']->selectDb($db); + + /** + * $_REQUEST['target_db'] could be empty in case we came from an input field + * (when there are many databases, no drop-down) + */ + if (empty($_REQUEST['target_db'])) { + $_REQUEST['target_db'] = $db; + } + + /** + * A target table name has been sent to this script -> do the work + */ + if (PMA_isValid($_REQUEST['new_name'])) { + if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) { + if (isset($_REQUEST['submit_move'])) { + $message = PMA_Message::error(__('Can\'t move table to same one!')); + } else { + $message = PMA_Message::error(__('Can\'t copy table to same one!')); + } + $result = false; + } else { + $result = PMA_Table::moveCopy( + $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'], + $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table' + ); + + if (isset($_REQUEST['submit_move'])) { + $message = PMA_Message::success( + __('Table %s has been moved to %s.') + ); + } else { + $message = PMA_Message::success( + __('Table %s has been copied to %s.') + ); + } + $old = PMA_Util::backquote($db) . '.' + . PMA_Util::backquote($table); + $message->addParam($old); + $new = PMA_Util::backquote($_REQUEST['target_db']) . '.' + . PMA_Util::backquote($_REQUEST['new_name']); + $message->addParam($new); + + /* Check: Work on new table or on old table? */ + if (isset($_REQUEST['submit_move']) + || PMA_isValid($_REQUEST['switch_to_new']) + ) { + $db = $_REQUEST['target_db']; + $table = $_REQUEST['new_name']; + } + } + } else { + /** + * No new name for the table! + */ + $message = PMA_Message::error(__('The table name is empty!')); + $result = false; + } + + if ($GLOBALS['is_ajax_request'] == true) { + $response = PMA_Response::getInstance(); + $response->addJSON('message', $message); + if ($message->isSuccess()) { + $response->addJSON('db', $GLOBALS['db']); + $response->addJSON( + 'sql_query', + PMA_Util::getMessage(null, $sql_query) + ); + } else { + $response->isSuccess(false); + } + exit; + } +} ?> diff --git a/tbl_move_copy.php b/tbl_move_copy.php deleted file mode 100644 index 402da2efcb..0000000000 --- a/tbl_move_copy.php +++ /dev/null @@ -1,104 +0,0 @@ -selectDb($db); - -$goto = $cfg['DefaultTabTable']; - -/** - * $_REQUEST['target_db'] could be empty in case we came from an input field - * (when there are many databases, no drop-down) - */ -if (empty($_REQUEST['target_db'])) { - $_REQUEST['target_db'] = $db; -} - -/** - * A target table name has been sent to this script -> do the work - */ -if (PMA_isValid($_REQUEST['new_name'])) { - if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) { - if (isset($_REQUEST['submit_move'])) { - $message = PMA_Message::error(__('Can\'t move table to same one!')); - } else { - $message = PMA_Message::error(__('Can\'t copy table to same one!')); - } - $result = false; - } else { - $result = PMA_Table::moveCopy( - $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'], - $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table' - ); - - if (isset($_REQUEST['submit_move'])) { - $message = PMA_Message::success(__('Table %s has been moved to %s.')); - } else { - $message = PMA_Message::success(__('Table %s has been copied to %s.')); - } - $old = PMA_Util::backquote($db) . '.' - . PMA_Util::backquote($table); - $message->addParam($old); - $new = PMA_Util::backquote($_REQUEST['target_db']) . '.' - . PMA_Util::backquote($_REQUEST['new_name']); - $message->addParam($new); - - /* Check: Work on new table or on old table? */ - if (isset($_REQUEST['submit_move']) - || PMA_isValid($_REQUEST['switch_to_new']) - ) { - $db = $_REQUEST['target_db']; - $table = $_REQUEST['new_name']; - } - $reload = 1; - } -} else { - /** - * No new name for the table! - */ - $message = PMA_Message::error(__('The table name is empty!')); - $result = false; -} - -if ($GLOBALS['is_ajax_request'] == true) { - $response = PMA_Response::getInstance(); - $response->addJSON('message', $message); - if ($message->isSuccess()) { - $response->addJSON('db', $GLOBALS['db']); - $response->addJSON( - 'sql_query', - PMA_Util::getMessage(null, $sql_query) - ); - } else { - $response->isSuccess(false); - } - exit; -} - -/** - * Back to the calling script - */ -$_message = $message; -unset($message); -?> diff --git a/tbl_operations.php b/tbl_operations.php index c4c0a47094..75b88c6090 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -80,8 +80,10 @@ $pmaString = $GLOBALS['PMA_String']; * If the table has to be moved to some other database */ if (isset($_REQUEST['submit_move']) || isset($_REQUEST['submit_copy'])) { - $_message = ''; - include_once 'tbl_move_copy.php'; + //$_message = ''; + PMA_moveOrCopyTable($db, $table); + // This was ended in an Ajax call + exit; } /** * If the table has to be maintained