tbl_move_copy.php 2.8 KB

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