Refactored ConfigFile class so that it is no longer a singleton
[phpmyadmin.git] / tbl_move_copy.php
blob402da2efcb11706cf63a064a987d5522925b1802
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Table moving and copying
6 * @package PhpMyAdmin
7 */
9 /**
10 * Gets some core libraries
12 require_once 'libraries/common.inc.php';
14 // Check parameters
15 PMA_Util::checkParameters(array('db', 'table'));
17 /**
18 * Defines the url to return to in case of error in a sql statement
20 $err_url = 'tbl_sql.php?' . PMA_URL_getCommon($db, $table);
23 /**
24 * Selects the database to work with
26 $GLOBALS['dbi']->selectDb($db);
28 $goto = $cfg['DefaultTabTable'];
30 /**
31 * $_REQUEST['target_db'] could be empty in case we came from an input field
32 * (when there are many databases, no drop-down)
34 if (empty($_REQUEST['target_db'])) {
35 $_REQUEST['target_db'] = $db;
38 /**
39 * A target table name has been sent to this script -> do the work
41 if (PMA_isValid($_REQUEST['new_name'])) {
42 if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) {
43 if (isset($_REQUEST['submit_move'])) {
44 $message = PMA_Message::error(__('Can\'t move table to same one!'));
45 } else {
46 $message = PMA_Message::error(__('Can\'t copy table to same one!'));
48 $result = false;
49 } else {
50 $result = PMA_Table::moveCopy(
51 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'],
52 $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table'
55 if (isset($_REQUEST['submit_move'])) {
56 $message = PMA_Message::success(__('Table %s has been moved to %s.'));
57 } else {
58 $message = PMA_Message::success(__('Table %s has been copied to %s.'));
60 $old = PMA_Util::backquote($db) . '.'
61 . PMA_Util::backquote($table);
62 $message->addParam($old);
63 $new = PMA_Util::backquote($_REQUEST['target_db']) . '.'
64 . PMA_Util::backquote($_REQUEST['new_name']);
65 $message->addParam($new);
67 /* Check: Work on new table or on old table? */
68 if (isset($_REQUEST['submit_move'])
69 || PMA_isValid($_REQUEST['switch_to_new'])
70 ) {
71 $db = $_REQUEST['target_db'];
72 $table = $_REQUEST['new_name'];
74 $reload = 1;
76 } else {
77 /**
78 * No new name for the table!
80 $message = PMA_Message::error(__('The table name is empty!'));
81 $result = false;
84 if ($GLOBALS['is_ajax_request'] == true) {
85 $response = PMA_Response::getInstance();
86 $response->addJSON('message', $message);
87 if ($message->isSuccess()) {
88 $response->addJSON('db', $GLOBALS['db']);
89 $response->addJSON(
90 'sql_query',
91 PMA_Util::getMessage(null, $sql_query)
93 } else {
94 $response->isSuccess(false);
96 exit;
99 /**
100 * Back to the calling script
102 $_message = $message;
103 unset($message);