Translated using Weblate (Albanian)
[phpmyadmin.git] / libraries / operations.lib.php
blobfa64146ea665658c9eb32b5941f572dac9380896
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * set of functions with the operations section in pma
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\engines\Innodb;
9 use PMA\libraries\Charsets;
10 use PMA\libraries\Message;
11 use PMA\libraries\Partition;
12 use PMA\libraries\plugins\export\ExportSql;
13 use PMA\libraries\Response;
14 use PMA\libraries\StorageEngine;
15 use PMA\libraries\Table;
16 use PMA\libraries\Util;
17 use PMA\libraries\URL;
19 /**
20 * Get HTML output for database comment
22 * @param string $db database name
24 * @return string $html_output
26 function PMA_getHtmlForDatabaseComment($db)
28 $html_output = '<div class="operations_half_width">'
29 . '<form method="post" action="db_operations.php" id="formDatabaseComment">'
30 . URL::getHiddenInputs($db)
31 . '<fieldset>'
32 . '<legend>';
33 if (Util::showIcons('ActionLinksMode')) {
34 $html_output .= Util::getImage('b_comment.png') . '&nbsp;';
36 $html_output .= __('Database comment');
37 $html_output .= '</legend>';
38 $html_output .= '<input type="text" name="comment" '
39 . 'class="textfield" size="30"'
40 . 'value="' . htmlspecialchars(PMA_getDBComment($db)) . '" />'
41 . '</fieldset>';
42 $html_output .= '<fieldset class="tblFooters">'
43 . '<input type="submit" value="' . __('Go') . '" />'
44 . '</fieldset>'
45 . '</form>'
46 . '</div>';
48 return $html_output;
51 /**
52 * Get HTML output for rename database
54 * @param string $db database name
56 * @return string $html_output
58 function PMA_getHtmlForRenameDatabase($db)
60 $html_output = '<div class="operations_half_width">'
61 . '<form id="rename_db_form" '
62 . 'class="ajax" '
63 . 'method="post" action="db_operations.php" '
64 . 'onsubmit="return emptyCheckTheField(this, \'newname\')">';
65 if (isset($_REQUEST['db_collation'])) {
66 $html_output .= '<input type="hidden" name="db_collation" '
67 . 'value="' . $_REQUEST['db_collation']
68 . '" />' . "\n";
70 $html_output .= '<input type="hidden" name="what" value="data" />'
71 . '<input type="hidden" name="db_rename" value="true" />'
72 . URL::getHiddenInputs($db)
73 . '<fieldset>'
74 . '<legend>';
76 if (Util::showIcons('ActionLinksMode')) {
77 $html_output .= Util::getImage('b_edit.png') . '&nbsp;';
79 $html_output .= __('Rename database to')
80 . '</legend>';
82 $html_output .= '<input id="new_db_name" type="text" name="newname" '
83 . 'maxlength="64" size="30" class="textfield" required="required" '
84 . 'value=""/>';
86 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
87 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
88 && $GLOBALS['is_reload_priv']
89 ) {
90 $html_output .= '<input type="checkbox" name="adjust_privileges" '
91 . 'value="1" id="checkbox_adjust_privileges" checked="checked" />';
92 } else {
93 $html_output .= '<input type="checkbox" name="adjust_privileges" '
94 . 'value="1" id="checkbox_adjust_privileges" title="' . __(
95 'You don\'t have sufficient privileges to perform this '
96 . 'operation; Please refer to the documentation for more details'
98 . '" disabled/>';
101 $html_output .= '<label for="checkbox_adjust_privileges">'
102 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
103 . '</label><br />';
105 $html_output .= ''
106 . '</fieldset>'
107 . '<fieldset class="tblFooters">'
108 . '<input id="rename_db_input" type="submit" value="' . __('Go') . '" />'
109 . '</fieldset>'
110 . '</form>'
111 . '</div>';
113 return $html_output;
117 * Get HTML for database drop link
119 * @param string $db database name
121 * @return string $html_output
123 function PMA_getHtmlForDropDatabaseLink($db)
125 $this_sql_query = 'DROP DATABASE ' . Util::backquote($db);
126 $this_url_params = array(
127 'sql_query' => $this_sql_query,
128 'back' => 'db_operations.php',
129 'goto' => 'index.php',
130 'reload' => '1',
131 'purge' => '1',
132 'message_to_show' => sprintf(
133 __('Database %s has been dropped.'),
134 htmlspecialchars(Util::backquote($db))
136 'db' => null,
139 $html_output = '<div class="operations_half_width">'
140 . '<fieldset class="caution">';
141 $html_output .= '<legend>';
142 if (Util::showIcons('ActionLinksMode')) {
143 $html_output .= Util::getImage('b_deltbl.png') . '&nbsp';
145 $html_output .= __('Remove database')
146 . '</legend>';
147 $html_output .= '<ul>';
148 $html_output .= PMA_getDeleteDataOrTablelink(
149 $this_url_params,
150 'DROP_DATABASE',
151 __('Drop the database (DROP)'),
152 'drop_db_anchor'
154 $html_output .= '</ul></fieldset>'
155 . '</div>';
157 return $html_output;
161 * Get HTML snippet for copy database
163 * @param string $db database name
165 * @return string $html_output
167 function PMA_getHtmlForCopyDatabase($db)
169 $drop_clause = 'DROP TABLE / DROP VIEW';
170 $choices = array(
171 'structure' => __('Structure only'),
172 'data' => __('Structure and data'),
173 'dataonly' => __('Data only')
176 if (isset($_COOKIE)
177 && isset($_COOKIE['pma_switch_to_new'])
178 && $_COOKIE['pma_switch_to_new'] == 'true'
180 $pma_switch_to_new = 'true';
183 $html_output = '<div class="operations_half_width clearfloat">';
184 $html_output .= '<form id="copy_db_form" '
185 . 'class="ajax" '
186 . 'method="post" action="db_operations.php" '
187 . 'onsubmit="return emptyCheckTheField(this, \'newname\')">';
189 if (isset($_REQUEST['db_collation'])) {
190 $html_output .= '<input type="hidden" name="db_collation" '
191 . 'value="' . $_REQUEST['db_collation'] . '" />' . "\n";
193 $html_output .= '<input type="hidden" name="db_copy" value="true" />' . "\n"
194 . URL::getHiddenInputs($db);
195 $html_output .= '<fieldset>'
196 . '<legend>';
198 if (Util::showIcons('ActionLinksMode')) {
199 $html_output .= Util::getImage('b_edit.png') . '&nbsp';
201 $html_output .= __('Copy database to')
202 . '</legend>'
203 . '<input type="text" maxlength="64" name="newname" size="30" '
204 . 'class="textfield" value="" '
205 . 'required="required" /><br />'
206 . Util::getRadioFields(
207 'what', $choices, 'data', true
209 $html_output .= '<br />';
210 $html_output .= '<input type="checkbox" name="create_database_before_copying" '
211 . 'value="1" id="checkbox_create_database_before_copying"'
212 . 'checked="checked" />';
213 $html_output .= '<label for="checkbox_create_database_before_copying">'
214 . __('CREATE DATABASE before copying') . '</label><br />';
215 $html_output .= '<input type="checkbox" name="drop_if_exists" value="true"'
216 . 'id="checkbox_drop" />';
217 $html_output .= '<label for="checkbox_drop">'
218 . sprintf(__('Add %s'), $drop_clause)
219 . '</label><br />';
220 $html_output .= '<input type="checkbox" name="sql_auto_increment" value="1" '
221 . 'checked="checked" id="checkbox_auto_increment" />';
222 $html_output .= '<label for="checkbox_auto_increment">'
223 . __('Add AUTO_INCREMENT value') . '</label><br />';
224 $html_output .= '<input type="checkbox" name="add_constraints" value="1"'
225 . 'id="checkbox_constraints" checked="checked"/>';
226 $html_output .= '<label for="checkbox_constraints">'
227 . __('Add constraints') . '</label><br />';
228 $html_output .= '<br />';
230 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
231 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
232 && $GLOBALS['is_reload_priv']
234 $html_output .= '<input type="checkbox" name="adjust_privileges" '
235 . 'value="1" id="checkbox_privileges" checked="checked" />';
236 } else {
237 $html_output .= '<input type="checkbox" name="adjust_privileges" '
238 . 'value="1" id="checkbox_privileges" title="' . __(
239 'You don\'t have sufficient privileges to perform this '
240 . 'operation; Please refer to the documentation for more details'
242 . '" disabled/>';
244 $html_output .= '<label for="checkbox_privileges">'
245 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
246 . '</label><br />';
248 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
249 . 'id="checkbox_switch"'
250 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
251 ? ' checked="checked"'
252 : '')
253 . '/>';
254 $html_output .= '<label for="checkbox_switch">'
255 . __('Switch to copied database') . '</label>'
256 . '</fieldset>';
257 $html_output .= '<fieldset class="tblFooters">'
258 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
259 . '</fieldset>'
260 . '</form>'
261 . '</div>';
263 return $html_output;
267 * Get HTML snippet for change database charset
269 * @param string $db database name
270 * @param string $table table name
272 * @return string $html_output
274 function PMA_getHtmlForChangeDatabaseCharset($db, $table)
276 $html_output = '<div class="operations_half_width">'
277 . '<form id="change_db_charset_form" ';
278 $html_output .= 'class="ajax" ';
279 $html_output .= 'method="post" action="db_operations.php">';
281 $html_output .= URL::getHiddenInputs($db, $table);
283 $html_output .= '<fieldset>' . "\n"
284 . ' <legend>';
285 if (Util::showIcons('ActionLinksMode')) {
286 $html_output .= Util::getImage('s_asci.png') . '&nbsp';
288 $html_output .= '<label for="select_db_collation">' . __('Collation')
289 . '</label>' . "\n"
290 . '</legend>' . "\n"
291 . Charsets::getCollationDropdownBox(
292 'db_collation',
293 'select_db_collation',
294 isset($_REQUEST['db_collation']) ? $_REQUEST['db_collation'] : '',
295 false
297 . '</fieldset>'
298 . '<fieldset class="tblFooters">'
299 . '<input type="submit" name="submitcollation"'
300 . ' value="' . __('Go') . '" />' . "\n"
301 . '</fieldset>' . "\n"
302 . '</form></div>' . "\n";
304 return $html_output;
308 * Run the Procedure definitions and function definitions
310 * to avoid selecting alternatively the current and new db
311 * we would need to modify the CREATE definitions to qualify
312 * the db name
314 * @param string $db database name
316 * @return void
318 function PMA_runProcedureAndFunctionDefinitions($db)
320 $procedure_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'PROCEDURE');
321 if ($procedure_names) {
322 foreach ($procedure_names as $procedure_name) {
323 $GLOBALS['dbi']->selectDb($db);
324 $tmp_query = $GLOBALS['dbi']->getDefinition(
325 $db, 'PROCEDURE', $procedure_name
327 // collect for later display
328 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
329 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
330 $GLOBALS['dbi']->query($tmp_query);
334 $function_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'FUNCTION');
335 if ($function_names) {
336 foreach ($function_names as $function_name) {
337 $GLOBALS['dbi']->selectDb($db);
338 $tmp_query = $GLOBALS['dbi']->getDefinition(
339 $db, 'FUNCTION', $function_name
341 // collect for later display
342 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
343 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
344 $GLOBALS['dbi']->query($tmp_query);
350 * Create database before copy
352 * @return void
354 function PMA_createDbBeforeCopy()
356 $local_query = 'CREATE DATABASE IF NOT EXISTS '
357 . Util::backquote($_REQUEST['newname']);
358 if (isset($_REQUEST['db_collation'])) {
359 $local_query .= ' DEFAULT'
360 . Util::getCharsetQueryPart($_REQUEST['db_collation']);
362 $local_query .= ';';
363 $GLOBALS['sql_query'] .= $local_query;
365 // save the original db name because Tracker.php which
366 // may be called under $GLOBALS['dbi']->query() changes $GLOBALS['db']
367 // for some statements, one of which being CREATE DATABASE
368 $original_db = $GLOBALS['db'];
369 $GLOBALS['dbi']->query($local_query);
370 $GLOBALS['db'] = $original_db;
372 // Set the SQL mode to NO_AUTO_VALUE_ON_ZERO to prevent MySQL from creating
373 // export statements it cannot import
374 $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'";
375 $GLOBALS['dbi']->query($sql_set_mode);
377 // rebuild the database list because Table::moveCopy
378 // checks in this list if the target db exists
379 $GLOBALS['dblist']->databases->build();
383 * Get views as an array and create SQL view stand-in
385 * @param array $tables_full array of all tables in given db or dbs
386 * @param ExportSql $export_sql_plugin export plugin instance
387 * @param string $db database name
389 * @return array $views
391 function PMA_getViewsAndCreateSqlViewStandIn(
392 $tables_full, $export_sql_plugin, $db
394 $views = array();
395 foreach ($tables_full as $each_table => $tmp) {
396 // to be able to rename a db containing views,
397 // first all the views are collected and a stand-in is created
398 // the real views are created after the tables
399 if ($GLOBALS['dbi']->getTable($db, $each_table)->isView()) {
401 // If view exists, and 'add drop view' is selected: Drop it!
402 if ($_REQUEST['what'] != 'nocopy'
403 && isset($_REQUEST['drop_if_exists'])
404 && $_REQUEST['drop_if_exists'] == 'true'
406 $drop_query = 'DROP VIEW IF EXISTS '
407 . Util::backquote($_REQUEST['newname']) . '.'
408 . Util::backquote($each_table);
409 $GLOBALS['dbi']->query($drop_query);
411 $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
414 $views[] = $each_table;
415 // Create stand-in definition to resolve view dependencies
416 $sql_view_standin = $export_sql_plugin->getTableDefStandIn(
417 $db, $each_table, "\n"
419 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
420 $GLOBALS['dbi']->query($sql_view_standin);
421 $GLOBALS['sql_query'] .= "\n" . $sql_view_standin;
424 return $views;
428 * Get sql query for copy/rename table and boolean for whether copy/rename or not
430 * @param array $tables_full array of all tables in given db or dbs
431 * @param boolean $move whether database name is empty or not
432 * @param string $db database name
434 * @return array SQL queries for the constraints
436 function PMA_copyTables($tables_full, $move, $db)
438 $sqlContraints = array();
439 foreach ($tables_full as $each_table => $tmp) {
440 // skip the views; we have created stand-in definitions
441 if ($GLOBALS['dbi']->getTable($db, $each_table)->isView()) {
442 continue;
445 // value of $what for this table only
446 $this_what = $_REQUEST['what'];
448 // do not copy the data from a Merge table
449 // note: on the calling FORM, 'data' means 'structure and data'
450 if ($GLOBALS['dbi']->getTable($db, $each_table)->isMerge()) {
451 if ($this_what == 'data') {
452 $this_what = 'structure';
454 if ($this_what == 'dataonly') {
455 $this_what = 'nocopy';
459 if ($this_what != 'nocopy') {
460 // keep the triggers from the original db+table
461 // (third param is empty because delimiters are only intended
462 // for importing via the mysql client or our Import feature)
463 $triggers = $GLOBALS['dbi']->getTriggers($db, $each_table, '');
465 if (! Table::moveCopy(
466 $db, $each_table, $_REQUEST['newname'], $each_table,
467 (isset($this_what) ? $this_what : 'data'),
468 $move, 'db_copy'
469 )) {
470 $GLOBALS['_error'] = true;
471 break;
473 // apply the triggers to the destination db+table
474 if ($triggers) {
475 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
476 foreach ($triggers as $trigger) {
477 $GLOBALS['dbi']->query($trigger['create']);
478 $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';';
482 // this does not apply to a rename operation
483 if (isset($_REQUEST['add_constraints'])
484 && ! empty($GLOBALS['sql_constraints_query'])
486 $sqlContraints[] = $GLOBALS['sql_constraints_query'];
487 unset($GLOBALS['sql_constraints_query']);
491 return $sqlContraints;
495 * Run the EVENT definition for selected database
497 * to avoid selecting alternatively the current and new db
498 * we would need to modify the CREATE definitions to qualify
499 * the db name
501 * @param string $db database name
503 * @return void
505 function PMA_runEventDefinitionsForDb($db)
507 $event_names = $GLOBALS['dbi']->fetchResult(
508 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \''
509 . $GLOBALS['dbi']->escapeString($db) . '\';'
511 if ($event_names) {
512 foreach ($event_names as $event_name) {
513 $GLOBALS['dbi']->selectDb($db);
514 $tmp_query = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $event_name);
515 // collect for later display
516 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
517 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
518 $GLOBALS['dbi']->query($tmp_query);
524 * Handle the views, return the boolean value whether table rename/copy or not
526 * @param array $views views as an array
527 * @param boolean $move whether database name is empty or not
528 * @param string $db database name
530 * @return void
532 function PMA_handleTheViews($views, $move, $db)
534 // temporarily force to add DROP IF EXIST to CREATE VIEW query,
535 // to remove stand-in VIEW that was created earlier
536 // ( $_REQUEST['drop_if_exists'] is used in moveCopy() )
537 if (isset($_REQUEST['drop_if_exists'])) {
538 $temp_drop_if_exists = $_REQUEST['drop_if_exists'];
541 $_REQUEST['drop_if_exists'] = 'true';
542 foreach ($views as $view) {
543 $copying_succeeded = Table::moveCopy(
544 $db, $view, $_REQUEST['newname'], $view, 'structure', $move, 'db_copy'
546 if (! $copying_succeeded) {
547 $GLOBALS['_error'] = true;
548 break;
551 unset($_REQUEST['drop_if_exists']);
553 if (isset($temp_drop_if_exists)) {
554 // restore previous value
555 $_REQUEST['drop_if_exists'] = $temp_drop_if_exists;
560 * Adjust the privileges after Renaming the db
562 * @param string $oldDb Database name before renaming
563 * @param string $newname New Database name requested
565 * @return void
567 function PMA_AdjustPrivileges_moveDB($oldDb, $newname)
569 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
570 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
571 && $GLOBALS['is_reload_priv']
573 $GLOBALS['dbi']->selectDb('mysql');
574 $newname = str_replace("_", "\_", $newname);
575 $oldDb = str_replace("_", "\_", $oldDb);
577 // For Db specific privileges
578 $query_db_specific = 'UPDATE ' . Util::backquote('db')
579 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
580 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
581 $GLOBALS['dbi']->query($query_db_specific);
583 // For table specific privileges
584 $query_table_specific = 'UPDATE ' . Util::backquote('tables_priv')
585 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
586 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
587 $GLOBALS['dbi']->query($query_table_specific);
589 // For column specific privileges
590 $query_col_specific = 'UPDATE ' . Util::backquote('columns_priv')
591 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
592 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
593 $GLOBALS['dbi']->query($query_col_specific);
595 // For procedures specific privileges
596 $query_proc_specific = 'UPDATE ' . Util::backquote('procs_priv')
597 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
598 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
599 $GLOBALS['dbi']->query($query_proc_specific);
601 // Finally FLUSH the new privileges
602 $flush_query = "FLUSH PRIVILEGES;";
603 $GLOBALS['dbi']->query($flush_query);
608 * Adjust the privileges after Copying the db
610 * @param string $oldDb Database name before copying
611 * @param string $newname New Database name requested
613 * @return void
615 function PMA_AdjustPrivileges_copyDB($oldDb, $newname)
617 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
618 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
619 && $GLOBALS['is_reload_priv']
621 $GLOBALS['dbi']->selectDb('mysql');
622 $newname = str_replace("_", "\_", $newname);
623 $oldDb = str_replace("_", "\_", $oldDb);
625 $query_db_specific_old = 'SELECT * FROM '
626 . Util::backquote('db') . ' WHERE '
627 . 'Db = "' . $oldDb . '";';
629 $old_privs_db = $GLOBALS['dbi']->fetchResult($query_db_specific_old, 0);
631 foreach ($old_privs_db as $old_priv) {
632 $newDb_db_privs_query = 'INSERT INTO ' . Util::backquote('db')
633 . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
634 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
635 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
636 . $old_priv[7] . '", "' . $old_priv[8] . '", "' . $old_priv[9]
637 . '", "' . $old_priv[10] . '", "' . $old_priv[11] . '", "'
638 . $old_priv[12] . '", "' . $old_priv[13] . '", "' . $old_priv[14]
639 . '", "' . $old_priv[15] . '", "' . $old_priv[16] . '", "'
640 . $old_priv[17] . '", "' . $old_priv[18] . '", "' . $old_priv[19]
641 . '", "' . $old_priv[20] . '", "' . $old_priv[21] . '");';
643 $GLOBALS['dbi']->query($newDb_db_privs_query);
646 // For Table Specific privileges
647 $query_table_specific_old = 'SELECT * FROM '
648 . Util::backquote('tables_priv') . ' WHERE '
649 . 'Db = "' . $oldDb . '";';
651 $old_privs_table = $GLOBALS['dbi']->fetchResult(
652 $query_table_specific_old,
656 foreach ($old_privs_table as $old_priv) {
657 $newDb_table_privs_query = 'INSERT INTO ' . Util::backquote(
658 'tables_priv'
659 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
660 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
661 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
662 . $old_priv[7] . '");';
664 $GLOBALS['dbi']->query($newDb_table_privs_query);
667 // For Column Specific privileges
668 $query_col_specific_old = 'SELECT * FROM '
669 . Util::backquote('columns_priv') . ' WHERE '
670 . 'Db = "' . $oldDb . '";';
672 $old_privs_col = $GLOBALS['dbi']->fetchResult(
673 $query_col_specific_old,
677 foreach ($old_privs_col as $old_priv) {
678 $newDb_col_privs_query = 'INSERT INTO ' . Util::backquote(
679 'columns_priv'
680 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
681 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
682 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '");';
684 $GLOBALS['dbi']->query($newDb_col_privs_query);
687 // For Procedure Specific privileges
688 $query_proc_specific_old = 'SELECT * FROM '
689 . Util::backquote('procs_priv') . ' WHERE '
690 . 'Db = "' . $oldDb . '";';
692 $old_privs_proc = $GLOBALS['dbi']->fetchResult(
693 $query_proc_specific_old,
697 foreach ($old_privs_proc as $old_priv) {
698 $newDb_proc_privs_query = 'INSERT INTO ' . Util::backquote(
699 'procs_priv'
700 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
701 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
702 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
703 . $old_priv[7] . '");';
705 $GLOBALS['dbi']->query($newDb_proc_privs_query);
708 // Finally FLUSH the new privileges
709 $flush_query = "FLUSH PRIVILEGES;";
710 $GLOBALS['dbi']->query($flush_query);
715 * Create all accumulated constraints
717 * @param array $sqlConstratints array of sql constraints for the database
719 * @return void
721 function PMA_createAllAccumulatedConstraints($sqlConstratints)
723 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
724 foreach ($sqlConstratints as $one_query) {
725 $GLOBALS['dbi']->query($one_query);
726 // and prepare to display them
727 $GLOBALS['sql_query'] .= "\n" . $one_query;
732 * Duplicate the bookmarks for the db (done once for each db)
734 * @param boolean $_error whether table rename/copy or not
735 * @param string $db database name
737 * @return void
739 function PMA_duplicateBookmarks($_error, $db)
741 if (! $_error && $db != $_REQUEST['newname']) {
742 $get_fields = array('user', 'label', 'query');
743 $where_fields = array('dbase' => $db);
744 $new_fields = array('dbase' => $_REQUEST['newname']);
745 Table::duplicateInfo(
746 'bookmarkwork', 'bookmark', $get_fields,
747 $where_fields, $new_fields
753 * Get the HTML snippet for order the table
755 * @param array $columns columns array
757 * @return string $html_out
759 function PMA_getHtmlForOrderTheTable($columns)
761 $html_output = '<div class="operations_half_width">';
762 $html_output .= '<form method="post" id="alterTableOrderby" '
763 . 'action="tbl_operations.php">';
764 $html_output .= URL::getHiddenInputs(
765 $GLOBALS['db'], $GLOBALS['table']
767 $html_output .= '<fieldset id="fieldset_table_order">'
768 . '<legend>' . __('Alter table order by') . '</legend>'
769 . '<select name="order_field">';
771 foreach ($columns as $fieldname) {
772 $html_output .= '<option '
773 . 'value="' . htmlspecialchars($fieldname['Field']) . '">'
774 . htmlspecialchars($fieldname['Field']) . '</option>' . "\n";
776 $html_output .= '</select> ' . __('(singly)') . ' '
777 . '<br />'
778 . '<input id="order_order_asc" name="order_order"'
779 . ' type="radio" value="asc" checked="checked" />'
780 . '<label for="order_order_asc">' . __('Ascending') . '</label>'
781 . '<input id="order_order_desc" name="order_order"'
782 . ' type="radio" value="desc" />'
783 . '<label for="order_order_desc">' . __('Descending') . '</label>'
784 . '</fieldset>'
785 . '<fieldset class="tblFooters">'
786 . '<input type="hidden" name="submitorderby" value="1" />'
787 . '<input type="submit" value="' . __('Go') . '" />'
788 . '</fieldset>'
789 . '</form>'
790 . '</div>';
792 return $html_output;
796 * Get the HTML snippet for move table
798 * @return string $html_output
800 function PMA_getHtmlForMoveTable()
802 $html_output = '<div class="operations_half_width">';
803 $html_output .= '<form method="post" action="tbl_operations.php"'
804 . ' id="moveTableForm" class="ajax"'
805 . ' onsubmit="return emptyCheckTheField(this, \'new_name\')">'
806 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
808 $html_output .= '<input type="hidden" name="reload" value="1" />'
809 . '<input type="hidden" name="what" value="data" />'
810 . '<fieldset id="fieldset_table_rename">';
812 $html_output .= '<legend>' . __('Move table to (database<b>.</b>table)')
813 . '</legend>';
815 if (count($GLOBALS['dblist']->databases) > $GLOBALS['cfg']['MaxDbList']) {
816 $html_output .= '<input type="text" maxlength="100" size="30" '
817 . 'name="target_db" value="' . htmlspecialchars($GLOBALS['db'])
818 . '"/>';
819 } else {
820 $html_output .= '<select class="halfWidth" name="target_db">'
821 . $GLOBALS['dblist']->databases->getHtmlOptions(true, false)
822 . '</select>';
824 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
825 $html_output .= '<input class="halfWidth" type="text" size="20" name="new_name"'
826 . ' maxlength="64" required="required" '
827 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" /><br />';
829 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
830 // next value but users can decide if they want it or not for the operation
832 $html_output .= '<input type="checkbox" name="sql_auto_increment" '
833 . 'value="1" id="checkbox_auto_increment_mv" checked="checked" />'
834 . '<label for="checkbox_auto_increment_mv">'
835 . __('Add AUTO_INCREMENT value')
836 . '</label><br />';
838 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
839 && $GLOBALS['is_reload_priv']
841 $html_output .= '<input type="checkbox" name="adjust_privileges" '
842 . 'value="1" id="checkbox_privileges_tables_move" '
843 . 'checked="checked" />';
844 } else {
845 $html_output .= '<input type="checkbox" name="adjust_privileges" '
846 . 'value="1" id="checkbox_privileges_tables_move" title="' . __(
847 'You don\'t have sufficient privileges to perform this '
848 . 'operation; Please refer to the documentation for more details'
850 . '" disabled/>';
852 $html_output .= '<label for="checkbox_privileges_tables_move">'
853 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
854 . '</label><br />';
856 $html_output .= '</fieldset><fieldset class="tblFooters">'
857 . '<input type="submit" name="submit_move" value="' . __('Go') . '" />'
858 . '</fieldset>'
859 . '</form>'
860 . '</div>';
862 return $html_output;
866 * Get the HTML div for Table option
868 * @param Table $pma_table Table object
869 * @param string $comment Comment
870 * @param array $tbl_collation table collation
871 * @param string $tbl_storage_engine table storage engine
872 * @param string $pack_keys pack keys
873 * @param string $auto_increment value of auto increment
874 * @param string $delay_key_write delay key write
875 * @param string $transactional value of transactional
876 * @param string $page_checksum value of page checksum
877 * @param string $checksum the checksum
879 * @return string $html_output
881 function PMA_getTableOptionDiv($pma_table, $comment, $tbl_collation, $tbl_storage_engine,
882 $pack_keys, $auto_increment, $delay_key_write,
883 $transactional, $page_checksum, $checksum
885 $html_output = '<div class="operations_half_width clearfloat">';
886 $html_output .= '<form method="post" action="tbl_operations.php"';
887 $html_output .= ' id="tableOptionsForm" class="ajax">';
888 $html_output .= URL::getHiddenInputs(
889 $GLOBALS['db'], $GLOBALS['table']
891 $html_output .= '<input type="hidden" name="reload" value="1" />';
893 $html_output .= PMA_getTableOptionFieldset(
894 $pma_table, $comment, $tbl_collation,
895 $tbl_storage_engine, $pack_keys,
896 $delay_key_write, $auto_increment, $transactional, $page_checksum,
897 $checksum
900 $html_output .= '<fieldset class="tblFooters">'
901 . '<input type="hidden" name="submitoptions" value="1" />'
902 . '<input type="submit" value="' . __('Go') . '" />'
903 . '</fieldset>'
904 . '</form>'
905 . '</div>';
907 return $html_output;
911 * Get HTML for the rename table part of table options
913 * @return string $html_output
915 function PMA_getHtmlForRenameTable()
917 $html_output = '<tr><td class="vmiddle">' . __('Rename table to') . '</td>'
918 . '<td>'
919 . '<input type="text" size="20" name="new_name" maxlength="64" '
920 . 'value="' . htmlspecialchars($GLOBALS['table'])
921 . '" required="required" />'
922 . '</td></tr>'
923 . '<tr><td></td><td>';
925 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
926 && $GLOBALS['is_reload_priv']
928 $html_output .= '<input type="checkbox" name="adjust_privileges" '
929 . 'value="1" id="checkbox_privileges_table_options" '
930 . 'checked="checked" />';
931 } else {
932 $html_output .= '<input type="checkbox" name="adjust_privileges" '
933 . 'value="1" id="checkbox_privileges_table_options" title="' . __(
934 'You don\'t have sufficient privileges to perform this '
935 . 'operation; Please refer to the documentation for more details'
937 . '" disabled/>';
939 $html_output .= '<label for="checkbox_privileges_table_options">'
940 . __('Adjust privileges') . '&nbsp;'
941 . Util::showDocu('faq', 'faq6-39') . '</label>';
943 $html_output .= '</td></tr>';
944 return $html_output;
948 * Get HTML for the table comments part of table options
950 * @param string $current_value of the table comments
952 * @return string $html_output
954 function PMA_getHtmlForTableComments($current_value)
956 $commentLength = PMA_MYSQL_INT_VERSION >= 50503 ? 2048 : 60;
957 $html_output = '<tr><td class="vmiddle">' . __('Table comments') . '</td>'
958 . '<td><input type="text" name="comment" '
959 . 'maxlength="' . $commentLength . '" size="30"'
960 . 'value="' . htmlspecialchars($current_value) . '" />'
961 . '<input type="hidden" name="prev_comment" value="'
962 . htmlspecialchars($current_value) . '" />'
963 . '</td>'
964 . '</tr>';
966 return $html_output;
970 * Get HTML for the PACK KEYS part of table options
972 * @param string $current_value of the pack keys option
974 * @return string $html_output
976 function PMA_getHtmlForPackKeys($current_value)
978 $html_output = '<tr>'
979 . '<td class="vmiddle"><label for="new_pack_keys">PACK_KEYS</label></td>'
980 . '<td><select name="new_pack_keys" id="new_pack_keys">';
982 $html_output .= '<option value="DEFAULT"';
983 if ($current_value == 'DEFAULT') {
984 $html_output .= 'selected="selected"';
986 $html_output .= '>DEFAULT</option>
987 <option value="0"';
988 if ($current_value == '0') {
989 $html_output .= 'selected="selected"';
991 $html_output .= '>0</option>
992 <option value="1" ';
993 if ($current_value == '1') {
994 $html_output .= 'selected="selected"';
996 $html_output .= '>1</option>'
997 . '</select>'
998 . '</td>'
999 . '</tr>';
1001 return $html_output;
1005 * Get HTML fieldset for Table option, it contains HTML table for options
1007 * @param Table $pma_table Table object
1008 * @param string $comment Comment
1009 * @param array $tbl_collation table collation
1010 * @param string $tbl_storage_engine table storage engine
1011 * @param string $pack_keys pack keys
1012 * @param string $delay_key_write delay key write
1013 * @param string $auto_increment value of auto increment
1014 * @param string $transactional value of transactional
1015 * @param string $page_checksum value of page checksum
1016 * @param string $checksum the checksum
1018 * @return string $html_output
1020 function PMA_getTableOptionFieldset($pma_table, $comment, $tbl_collation,
1021 $tbl_storage_engine, $pack_keys,
1022 $delay_key_write, $auto_increment, $transactional,
1023 $page_checksum, $checksum
1025 $html_output = '<fieldset>'
1026 . '<legend>' . __('Table options') . '</legend>';
1028 $html_output .= '<table>';
1029 $html_output .= PMA_getHtmlForRenameTable();
1030 $html_output .= PMA_getHtmlForTableComments($comment);
1032 //Storage engine
1033 $html_output .= '<tr><td class="vmiddle">' . __('Storage Engine')
1034 . '&nbsp;' . Util::showMySQLDocu('Storage_engines')
1035 . '</td>'
1036 . '<td>'
1037 . StorageEngine::getHtmlSelect(
1038 'new_tbl_storage_engine', null, $tbl_storage_engine
1040 . '</td>'
1041 . '</tr>';
1043 //Table character set
1044 $html_output .= '<tr><td class="vmiddle">' . __('Collation') . '</td>'
1045 . '<td>'
1046 . Charsets::getCollationDropdownBox(
1047 'tbl_collation', null, $tbl_collation, false
1049 . '</td>'
1050 . '</tr>';
1052 // Change all Column collations
1053 $html_output .= '<tr><td></td><td>'
1054 . '<input type="checkbox" name="change_all_collations" value="1" '
1055 . 'id="checkbox_change_all_collations" />'
1056 . '<label for="checkbox_change_all_collations">'
1057 . __('Change all column collations')
1058 . '</label>'
1059 . '</td></tr>';
1061 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'ISAM'))) {
1062 $html_output .= PMA_getHtmlForPackKeys($pack_keys);
1063 } // end if (MYISAM|ISAM)
1065 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))) {
1066 $html_output .= PMA_getHtmlForTableRow(
1067 'new_checksum',
1068 'CHECKSUM',
1069 $checksum
1072 $html_output .= PMA_getHtmlForTableRow(
1073 'new_delay_key_write',
1074 'DELAY_KEY_WRITE',
1075 $delay_key_write
1077 } // end if (MYISAM)
1079 if ($pma_table->isEngine('ARIA')) {
1080 $html_output .= PMA_getHtmlForTableRow(
1081 'new_transactional',
1082 'TRANSACTIONAL',
1083 $transactional
1086 $html_output .= PMA_getHtmlForTableRow(
1087 'new_page_checksum',
1088 'PAGE_CHECKSUM',
1089 $page_checksum
1091 } // end if (ARIA)
1093 if (strlen($auto_increment) > 0
1094 && $pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1096 $html_output .= '<tr><td class="vmiddle">'
1097 . '<label for="auto_increment_opt">AUTO_INCREMENT</label></td>'
1098 . '<td><input type="number" name="new_auto_increment" '
1099 . 'id="auto_increment_opt"'
1100 . 'value="' . $auto_increment . '" /></td>'
1101 . '</tr> ';
1102 } // end if (MYISAM|INNODB)
1104 $possible_row_formats = PMA_getPossibleRowFormat();
1106 // for MYISAM there is also COMPRESSED but it can be set only by the
1107 // myisampack utility, so don't offer here the choice because if we
1108 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
1109 // does not return a warning
1110 // (if the table was compressed, it can be seen on the Structure page)
1112 if (isset($possible_row_formats[$tbl_storage_engine])) {
1113 $current_row_format
1114 = mb_strtoupper($GLOBALS['showtable']['Row_format']);
1115 $html_output .= '<tr><td class="vmiddle">'
1116 . '<label for="new_row_format">ROW_FORMAT</label></td>'
1117 . '<td>';
1118 $html_output .= Util::getDropdown(
1119 'new_row_format', $possible_row_formats[$tbl_storage_engine],
1120 $current_row_format, 'new_row_format'
1122 $html_output .= '</td></tr>';
1124 $html_output .= '</table>'
1125 . '</fieldset>';
1127 return $html_output;
1131 * Get the common HTML table row (tr) for new_checksum, new_delay_key_write,
1132 * new_transactional and new_page_checksum
1134 * @param string $attribute class, name and id attribute
1135 * @param string $label label value
1136 * @param string $val checksum, delay_key_write, transactional, page_checksum
1138 * @return string $html_output
1140 function PMA_getHtmlForTableRow($attribute, $label, $val)
1142 return '<tr>'
1143 . '<td class="vmiddle">'
1144 . '<label for="' . $attribute . '">' . $label . '</label>'
1145 . '</td>'
1146 . '<td>'
1147 . '<input type="checkbox" name="' . $attribute . '" id="' . $attribute . '"'
1148 . ' value="1"' . ((!empty($val) && $val == 1) ? ' checked="checked"' : '')
1149 . '/>'
1150 . '</td>'
1151 . '</tr>';
1155 * Get array of possible row formats
1157 * @return array $possible_row_formats
1159 function PMA_getPossibleRowFormat()
1161 // the outer array is for engines, the inner array contains the dropdown
1162 // option values as keys then the dropdown option labels
1164 $possible_row_formats = array(
1165 'ARCHIVE' => array(
1166 'COMPRESSED' => 'COMPRESSED',
1168 'ARIA' => array(
1169 'FIXED' => 'FIXED',
1170 'DYNAMIC' => 'DYNAMIC',
1171 'PAGE' => 'PAGE'
1173 'MARIA' => array(
1174 'FIXED' => 'FIXED',
1175 'DYNAMIC' => 'DYNAMIC',
1176 'PAGE' => 'PAGE'
1178 'MYISAM' => array(
1179 'FIXED' => 'FIXED',
1180 'DYNAMIC' => 'DYNAMIC'
1182 'PBXT' => array(
1183 'FIXED' => 'FIXED',
1184 'DYNAMIC' => 'DYNAMIC'
1186 'INNODB' => array(
1187 'COMPACT' => 'COMPACT',
1188 'REDUNDANT' => 'REDUNDANT'
1192 /** @var Innodb $innodbEnginePlugin */
1193 $innodbEnginePlugin = StorageEngine::getEngine('Innodb');
1194 $innodbPluginVersion = $innodbEnginePlugin->getInnodbPluginVersion();
1195 if (!empty($innodbPluginVersion)) {
1196 $innodb_file_format = $innodbEnginePlugin->getInnodbFileFormat();
1197 } else {
1198 $innodb_file_format = '';
1200 if ('Barracuda' == $innodb_file_format
1201 && $innodbEnginePlugin->supportsFilePerTable()
1203 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
1204 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
1207 return $possible_row_formats;
1211 * Get HTML div for copy table
1213 * @return string $html_output
1215 function PMA_getHtmlForCopytable()
1217 $html_output = '<div class="operations_half_width">';
1218 $html_output .= '<form method="post" action="tbl_operations.php" '
1219 . 'name="copyTable" '
1220 . 'id="copyTable" '
1221 . ' class="ajax" '
1222 . 'onsubmit="return emptyCheckTheField(this, \'new_name\')">'
1223 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1224 . '<input type="hidden" name="reload" value="1" />';
1226 $html_output .= '<fieldset>';
1227 $html_output .= '<legend>'
1228 . __('Copy table to (database<b>.</b>table)') . '</legend>';
1230 if (count($GLOBALS['dblist']->databases) > $GLOBALS['cfg']['MaxDbList']) {
1231 $html_output .= '<input class="halfWidth" type="text" maxlength="100" '
1232 . 'size="30" name="target_db" '
1233 . 'value="' . htmlspecialchars($GLOBALS['db']) . '"/>';
1234 } else {
1235 $html_output .= '<select class="halfWidth" name="target_db">'
1236 . $GLOBALS['dblist']->databases->getHtmlOptions(true, false)
1237 . '</select>';
1239 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
1240 $html_output .= '<input class="halfWidth" type="text" required="required" '
1241 . 'size="20" name="new_name" maxlength="64" '
1242 . 'value="' . htmlspecialchars($GLOBALS['table']) . '"/><br />';
1244 $choices = array(
1245 'structure' => __('Structure only'),
1246 'data' => __('Structure and data'),
1247 'dataonly' => __('Data only')
1250 $html_output .= Util::getRadioFields(
1251 'what', $choices, 'data', true
1253 $html_output .= '<br />';
1255 $html_output .= '<input type="checkbox" name="drop_if_exists" '
1256 . 'value="true" id="checkbox_drop" />'
1257 . '<label for="checkbox_drop">'
1258 . sprintf(__('Add %s'), 'DROP TABLE') . '</label><br />'
1259 . '<input type="checkbox" name="sql_auto_increment" '
1260 . 'value="1" id="checkbox_auto_increment_cp" />'
1261 . '<label for="checkbox_auto_increment_cp">'
1262 . __('Add AUTO_INCREMENT value') . '</label><br />';
1264 // display "Add constraints" choice only if there are
1265 // foreign keys
1266 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
1267 $html_output .= '<input type="checkbox" name="add_constraints" '
1268 . 'value="1" id="checkbox_constraints" checked="checked"/>';
1269 $html_output .= '<label for="checkbox_constraints">'
1270 . __('Add constraints') . '</label><br />';
1271 } // endif
1273 $html_output .= '<br />';
1275 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1276 && $GLOBALS['is_reload_priv']
1278 $html_output .= '<input type="checkbox" name="adjust_privileges" '
1279 . 'value="1" id="checkbox_adjust_privileges" checked="checked" />';
1280 } else {
1281 $html_output .= '<input type="checkbox" name="adjust_privileges" '
1282 . 'value="1" id="checkbox_adjust_privileges" title="' . __(
1283 'You don\'t have sufficient privileges to perform this '
1284 . 'operation; Please refer to the documentation for more details'
1286 . '" disabled/>';
1288 $html_output .= '<label for="checkbox_adjust_privileges">'
1289 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
1290 . '</label><br />';
1292 if (isset($_COOKIE['pma_switch_to_new'])
1293 && $_COOKIE['pma_switch_to_new'] == 'true'
1295 $pma_switch_to_new = 'true';
1298 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
1299 . 'id="checkbox_switch"'
1300 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
1301 ? ' checked="checked"'
1302 : '' . '/>');
1303 $html_output .= '<label for="checkbox_switch">'
1304 . __('Switch to copied table') . '</label>'
1305 . '</fieldset>';
1307 $html_output .= '<fieldset class="tblFooters">'
1308 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
1309 . '</fieldset>'
1310 . '</form>'
1311 . '</div>';
1313 return $html_output;
1317 * Get HTML snippet for table maintenance
1319 * @param Table $pma_table Table object
1320 * @param array $url_params array of URL parameters
1322 * @return string $html_output
1324 function PMA_getHtmlForTableMaintenance($pma_table, $url_params)
1326 $html_output = '<div class="operations_half_width">';
1327 $html_output .= '<fieldset>'
1328 . '<legend>' . __('Table maintenance') . '</legend>';
1329 $html_output .= '<ul id="tbl_maintenance">';
1331 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
1332 $html_output .= PMA_getListofMaintainActionLink($pma_table, $url_params);
1334 $html_output .= '</ul>'
1335 . '</fieldset>'
1336 . '</div>';
1338 return $html_output;
1342 * Get HTML 'li' having a link of maintain action
1344 * @param Table $pma_table Table object
1345 * @param array $url_params Array of URL parameters
1347 * @return string $html_output
1349 function PMA_getListofMaintainActionLink($pma_table, $url_params)
1351 $html_output = '';
1353 // analyze table
1354 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'BERKELEYDB', 'TOKUDB'))) {
1355 $params = array(
1356 'sql_query' => 'ANALYZE TABLE '
1357 . Util::backquote($GLOBALS['table']),
1358 'table_maintenance' => 'Go',
1360 $html_output .= PMA_getMaintainActionlink(
1361 __('Analyze table'),
1362 $params,
1363 $url_params,
1364 'ANALYZE_TABLE'
1368 // check table
1369 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'TOKUDB'))) {
1370 $params = array(
1371 'sql_query' => 'CHECK TABLE '
1372 . Util::backquote($GLOBALS['table']),
1373 'table_maintenance' => 'Go',
1375 $html_output .= PMA_getMaintainActionlink(
1376 __('Check table'),
1377 $params,
1378 $url_params,
1379 'CHECK_TABLE'
1383 // checksum table
1384 $params = array(
1385 'sql_query' => 'CHECKSUM TABLE '
1386 . Util::backquote($GLOBALS['table']),
1387 'table_maintenance' => 'Go',
1389 $html_output .= PMA_getMaintainActionlink(
1390 __('Checksum table'),
1391 $params,
1392 $url_params,
1393 'CHECKSUM_TABLE'
1396 // defragment table
1397 if ($pma_table->isEngine(array('INNODB'))) {
1398 $params = array(
1399 'sql_query' => 'ALTER TABLE '
1400 . Util::backquote($GLOBALS['table'])
1401 . ' ENGINE = InnoDB;'
1403 $html_output .= PMA_getMaintainActionlink(
1404 __('Defragment table'),
1405 $params,
1406 $url_params,
1407 'InnoDB_File_Defragmenting'
1411 // flush table
1412 $params = array(
1413 'sql_query' => 'FLUSH TABLE '
1414 . Util::backquote($GLOBALS['table']),
1415 'message_to_show' => sprintf(
1416 __('Table %s has been flushed.'),
1417 htmlspecialchars($GLOBALS['table'])
1419 'reload' => 1,
1421 $html_output .= PMA_getMaintainActionlink(
1422 __('Flush the table (FLUSH)'),
1423 $params,
1424 $url_params,
1425 'FLUSH'
1428 // optimize table
1429 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'BERKELEYDB', 'TOKUDB'))) {
1430 $params = array(
1431 'sql_query' => 'OPTIMIZE TABLE '
1432 . Util::backquote($GLOBALS['table']),
1433 'table_maintenance' => 'Go',
1435 $html_output .= PMA_getMaintainActionlink(
1436 __('Optimize table'),
1437 $params,
1438 $url_params,
1439 'OPTIMIZE_TABLE'
1443 // repair table
1444 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))) {
1445 $params = array(
1446 'sql_query' => 'REPAIR TABLE '
1447 . Util::backquote($GLOBALS['table']),
1448 'table_maintenance' => 'Go',
1450 $html_output .= PMA_getMaintainActionlink(
1451 __('Repair table'),
1452 $params,
1453 $url_params,
1454 'REPAIR_TABLE'
1458 return $html_output;
1462 * Get maintain action HTML link
1464 * @param string $action_message action message
1465 * @param array $params url parameters array
1466 * @param array $url_params additional url parameters
1467 * @param string $link contains name of page/anchor that is being linked
1469 * @return string $html_output
1471 function PMA_getMaintainActionlink($action_message, $params, $url_params, $link)
1473 return '<li>'
1474 . '<a class="maintain_action ajax" '
1475 . 'href="sql.php'
1476 . URL::getCommon(array_merge($url_params, $params)) . '">'
1477 . $action_message
1478 . '</a>'
1479 . Util::showMySQLDocu($link)
1480 . '</li>';
1484 * Get HTML for Delete data or table (truncate table, drop table)
1486 * @param array $truncate_table_url_params url parameter array for truncate table
1487 * @param array $dropTableUrlParams url parameter array for drop table
1489 * @return string $html_output
1491 function PMA_getHtmlForDeleteDataOrTable(
1492 $truncate_table_url_params,
1493 $dropTableUrlParams
1495 $html_output = '<div class="operations_half_width">'
1496 . '<fieldset class="caution">'
1497 . '<legend>' . __('Delete data or table') . '</legend>';
1499 $html_output .= '<ul>';
1501 if (! empty($truncate_table_url_params)) {
1502 $html_output .= PMA_getDeleteDataOrTablelink(
1503 $truncate_table_url_params,
1504 'TRUNCATE_TABLE',
1505 __('Empty the table (TRUNCATE)'),
1506 'truncate_tbl_anchor'
1509 if (!empty($dropTableUrlParams)) {
1510 $html_output .= PMA_getDeleteDataOrTablelink(
1511 $dropTableUrlParams,
1512 'DROP_TABLE',
1513 __('Delete the table (DROP)'),
1514 'drop_tbl_anchor'
1517 $html_output .= '</ul></fieldset></div>';
1519 return $html_output;
1523 * Get the HTML link for Truncate table, Drop table and Drop db
1525 * @param array $url_params url parameter array for delete data or table
1526 * @param string $syntax TRUNCATE_TABLE or DROP_TABLE or DROP_DATABASE
1527 * @param string $link link to be shown
1528 * @param string $htmlId id of the link
1530 * @return String html output
1532 function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $htmlId)
1534 return '<li><a '
1535 . 'href="sql.php' . URL::getCommon($url_params) . '"'
1536 . ' id="' . $htmlId . '" class="ajax">'
1537 . $link . '</a>'
1538 . Util::showMySQLDocu($syntax)
1539 . '</li>';
1543 * Get HTML snippet for partition maintenance
1545 * @param array $partition_names array of partition names for a specific db/table
1546 * @param array $url_params url parameters
1548 * @return string $html_output
1550 function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
1552 $choices = array(
1553 'ANALYZE' => __('Analyze'),
1554 'CHECK' => __('Check'),
1555 'OPTIMIZE' => __('Optimize'),
1556 'REBUILD' => __('Rebuild'),
1557 'REPAIR' => __('Repair'),
1558 'TRUNCATE' => __('Truncate')
1561 $partition_method = Partition::getPartitionMethod(
1562 $GLOBALS['db'], $GLOBALS['table']
1564 // add COALESCE or DROP option to choices array depeding on Partition method
1565 if ($partition_method == 'RANGE'
1566 || $partition_method == 'RANGE COLUMNS'
1567 || $partition_method == 'LIST'
1568 || $partition_method == 'LIST COLUMNS'
1570 $choices['DROP'] = __('Drop');
1571 } else {
1572 $choices['COALESCE'] = __('Coalesce');
1575 $html_output = '<div class="operations_half_width">'
1576 . '<form id="partitionsForm" class="ajax" '
1577 . 'method="post" action="tbl_operations.php" >'
1578 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1579 . '<fieldset>'
1580 . '<legend>'
1581 . __('Partition maintenance')
1582 . Util::showMySQLDocu('partitioning_maintenance')
1583 . '</legend>';
1585 $html_select = '<select id="partition_name" name="partition_name[]"'
1586 . ' multiple="multiple" required="required">' . "\n";
1587 $first = true;
1588 foreach ($partition_names as $one_partition) {
1589 $one_partition = htmlspecialchars($one_partition);
1590 $html_select .= '<option value="' . $one_partition . '"';
1591 if ($first) {
1592 $html_select .= ' selected="selected"';
1593 $first = false;
1595 $html_select .= '>' . $one_partition . '</option>' . "\n";
1597 $html_select .= '</select>' . "\n";
1598 $html_output .= sprintf(__('Partition %s'), $html_select);
1600 $html_output .= '<div class="clearfloat" />';
1601 $html_output .= Util::getRadioFields(
1602 'partition_operation', $choices, 'ANALYZE', false, true, 'floatleft'
1604 $this_url_params = array_merge(
1605 $url_params,
1606 array(
1607 'sql_query' => 'ALTER TABLE '
1608 . Util::backquote($GLOBALS['table'])
1609 . ' REMOVE PARTITIONING;'
1612 $html_output .= '<div class="clearfloat" /><br />';
1614 $html_output .= '<a href="sql.php'
1615 . URL::getCommon($this_url_params) . '">'
1616 . __('Remove partitioning') . '</a>';
1618 $html_output .= '</fieldset>'
1619 . '<fieldset class="tblFooters">'
1620 . '<input type="hidden" name="submit_partition" value="1">'
1621 . '<input type="submit" value="' . __('Go') . '" />'
1622 . '</fieldset>'
1623 . '</form>'
1624 . '</div>';
1626 return $html_output;
1630 * Get the HTML for Referential Integrity check
1632 * @param array $foreign all Relations to foreign tables for a given table
1633 * or optionally a given column in a table
1634 * @param array $url_params array of url parameters
1636 * @return string $html_output
1638 function PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
1640 $html_output = '<div class="operations_half_width">'
1641 . '<fieldset>'
1642 . '<legend>' . __('Check referential integrity:') . '</legend>';
1644 $html_output .= '<ul>';
1646 foreach ($foreign as $master => $arr) {
1647 $join_query = 'SELECT '
1648 . Util::backquote($GLOBALS['table']) . '.*'
1649 . ' FROM ' . Util::backquote($GLOBALS['table'])
1650 . ' LEFT JOIN '
1651 . Util::backquote($arr['foreign_db'])
1652 . '.'
1653 . Util::backquote($arr['foreign_table']);
1654 if ($arr['foreign_table'] == $GLOBALS['table']) {
1655 $foreign_table = $GLOBALS['table'] . '1';
1656 $join_query .= ' AS ' . Util::backquote($foreign_table);
1657 } else {
1658 $foreign_table = $arr['foreign_table'];
1660 $join_query .= ' ON '
1661 . Util::backquote($GLOBALS['table']) . '.'
1662 . Util::backquote($master)
1663 . ' = '
1664 . Util::backquote($arr['foreign_db'])
1665 . '.'
1666 . Util::backquote($foreign_table) . '.'
1667 . Util::backquote($arr['foreign_field'])
1668 . ' WHERE '
1669 . Util::backquote($arr['foreign_db'])
1670 . '.'
1671 . Util::backquote($foreign_table) . '.'
1672 . Util::backquote($arr['foreign_field'])
1673 . ' IS NULL AND '
1674 . Util::backquote($GLOBALS['table']) . '.'
1675 . Util::backquote($master)
1676 . ' IS NOT NULL';
1677 $this_url_params = array_merge(
1678 $url_params,
1679 array('sql_query' => $join_query)
1682 $html_output .= '<li>'
1683 . '<a href="sql.php'
1684 . URL::getCommon($this_url_params)
1685 . '">'
1686 . $master . '&nbsp;->&nbsp;' . $arr['foreign_db'] . '.'
1687 . $arr['foreign_table'] . '.' . $arr['foreign_field']
1688 . '</a></li>' . "\n";
1689 } // foreach $foreign
1690 $html_output .= '</ul></fieldset></div>';
1692 return $html_output;
1696 * Reorder table based on request params
1698 * @return array SQL query and result
1700 function PMA_getQueryAndResultForReorderingTable()
1702 $sql_query = 'ALTER TABLE '
1703 . Util::backquote($GLOBALS['table'])
1704 . ' ORDER BY '
1705 . Util::backquote(urldecode($_REQUEST['order_field']));
1706 if (isset($_REQUEST['order_order'])
1707 && $_REQUEST['order_order'] === 'desc'
1709 $sql_query .= ' DESC';
1710 } else {
1711 $sql_query .= ' ASC';
1713 $sql_query .= ';';
1714 $result = $GLOBALS['dbi']->query($sql_query);
1716 return array($sql_query, $result);
1720 * Get table alters array
1722 * @param Table $pma_table The Table object
1723 * @param string $pack_keys pack keys
1724 * @param string $checksum value of checksum
1725 * @param string $page_checksum value of page checksum
1726 * @param string $delay_key_write delay key write
1727 * @param string $row_format row format
1728 * @param string $newTblStorageEngine table storage engine
1729 * @param string $transactional value of transactional
1730 * @param string $tbl_collation collation of the table
1732 * @return array $table_alters
1734 function PMA_getTableAltersArray($pma_table, $pack_keys,
1735 $checksum, $page_checksum, $delay_key_write,
1736 $row_format, $newTblStorageEngine, $transactional, $tbl_collation
1738 global $auto_increment;
1740 $table_alters = array();
1742 if (isset($_REQUEST['comment'])
1743 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']
1745 $table_alters[] = 'COMMENT = \''
1746 . $GLOBALS['dbi']->escapeString($_REQUEST['comment']) . '\'';
1749 if (! empty($newTblStorageEngine)
1750 && mb_strtolower($newTblStorageEngine) !== mb_strtolower($GLOBALS['tbl_storage_engine'])
1752 $table_alters[] = 'ENGINE = ' . $newTblStorageEngine;
1754 if (! empty($_REQUEST['tbl_collation'])
1755 && $_REQUEST['tbl_collation'] !== $tbl_collation
1757 $table_alters[] = 'DEFAULT '
1758 . Util::getCharsetQueryPart($_REQUEST['tbl_collation']);
1761 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'ISAM'))
1762 && isset($_REQUEST['new_pack_keys'])
1763 && $_REQUEST['new_pack_keys'] != (string)$pack_keys
1765 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
1768 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
1769 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))
1770 && $_REQUEST['new_checksum'] !== $checksum
1772 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
1775 $_REQUEST['new_transactional']
1776 = empty($_REQUEST['new_transactional']) ? '0' : '1';
1777 if ($pma_table->isEngine('ARIA')
1778 && $_REQUEST['new_transactional'] !== $transactional
1780 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
1783 $_REQUEST['new_page_checksum']
1784 = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
1785 if ($pma_table->isEngine('ARIA')
1786 && $_REQUEST['new_page_checksum'] !== $page_checksum
1788 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
1791 $_REQUEST['new_delay_key_write']
1792 = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
1793 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))
1794 && $_REQUEST['new_delay_key_write'] !== $delay_key_write
1796 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
1799 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1800 && ! empty($_REQUEST['new_auto_increment'])
1801 && (! isset($auto_increment)
1802 || $_REQUEST['new_auto_increment'] !== $auto_increment)
1804 $table_alters[] = 'auto_increment = '
1805 . $GLOBALS['dbi']->escapeString($_REQUEST['new_auto_increment']);
1808 if (! empty($_REQUEST['new_row_format'])) {
1809 $newRowFormat = $_REQUEST['new_row_format'];
1810 $newRowFormatLower = mb_strtolower($newRowFormat);
1811 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1812 && (strlen($row_format) === 0
1813 || $newRowFormatLower !== mb_strtolower($row_format))
1815 $table_alters[] = 'ROW_FORMAT = '
1816 . $GLOBALS['dbi']->escapeString($newRowFormat);
1820 return $table_alters;
1824 * Get warning messages array
1826 * @return array $warning_messages
1828 function PMA_getWarningMessagesArray()
1830 $warning_messages = array();
1831 foreach ($GLOBALS['dbi']->getWarnings() as $warning) {
1832 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
1833 // and if TRANSACTIONAL was set, the system reports an error;
1834 // I discussed with a Maria developer and he agrees that this
1835 // should not be reported with a Level of Error, so here
1836 // I just ignore it. But there are other 1478 messages
1837 // that it's better to show.
1838 if (! ($_REQUEST['new_tbl_storage_engine'] == 'MyISAM'
1839 && $warning['Code'] == '1478'
1840 && $warning['Level'] == 'Error')
1842 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
1843 . ' ' . $warning['Message'];
1846 return $warning_messages;
1850 * Get SQL query and result after ran this SQL query for a partition operation
1851 * has been requested by the user
1853 * @return array $sql_query, $result
1855 function PMA_getQueryAndResultForPartition()
1857 $sql_query = 'ALTER TABLE '
1858 . Util::backquote($GLOBALS['table']) . ' '
1859 . $_REQUEST['partition_operation']
1860 . ' PARTITION ';
1862 if ($_REQUEST['partition_operation'] == 'COALESCE') {
1863 $sql_query .= count($_REQUEST['partition_name']);
1864 } else {
1865 $sql_query .= implode(', ', $_REQUEST['partition_name']) . ';';
1868 $result = $GLOBALS['dbi']->query($sql_query);
1870 return array($sql_query, $result);
1874 * Adjust the privileges after renaming/moving a table
1876 * @param string $oldDb Database name before table renaming/moving table
1877 * @param string $oldTable Table name before table renaming/moving table
1878 * @param string $newDb Database name after table renaming/ moving table
1879 * @param string $newTable Table name after table renaming/moving table
1881 * @return void
1883 function PMA_AdjustPrivileges_renameOrMoveTable($oldDb, $oldTable, $newDb, $newTable)
1885 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1886 && $GLOBALS['is_reload_priv']
1888 $GLOBALS['dbi']->selectDb('mysql');
1890 // For table specific privileges
1891 $query_table_specific = 'UPDATE ' . Util::backquote('tables_priv')
1892 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newDb) . '\', Table_name = \'' . $GLOBALS['dbi']->escapeString($newTable)
1893 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\' AND Table_name = \'' . $GLOBALS['dbi']->escapeString($oldTable)
1894 . '\';';
1895 $GLOBALS['dbi']->query($query_table_specific);
1897 // For column specific privileges
1898 $query_col_specific = 'UPDATE ' . Util::backquote('columns_priv')
1899 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newDb) . '\', Table_name = \'' . $GLOBALS['dbi']->escapeString($newTable)
1900 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\' AND Table_name = \'' . $GLOBALS['dbi']->escapeString($oldTable)
1901 . '\';';
1902 $GLOBALS['dbi']->query($query_col_specific);
1904 // Finally FLUSH the new privileges
1905 $flush_query = "FLUSH PRIVILEGES;";
1906 $GLOBALS['dbi']->query($flush_query);
1911 * Adjust the privileges after copying a table
1913 * @param string $oldDb Database name before table copying
1914 * @param string $oldTable Table name before table copying
1915 * @param string $newDb Database name after table copying
1916 * @param string $newTable Table name after table copying
1918 * @return void
1920 function PMA_AdjustPrivileges_copyTable($oldDb, $oldTable, $newDb, $newTable)
1922 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1923 && $GLOBALS['is_reload_priv']
1925 $GLOBALS['dbi']->selectDb('mysql');
1927 // For Table Specific privileges
1928 $query_table_specific_old = 'SELECT * FROM '
1929 . Util::backquote('tables_priv') . ' where '
1930 . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";';
1932 $old_privs_table = $GLOBALS['dbi']->fetchResult(
1933 $query_table_specific_old,
1937 foreach ($old_privs_table as $old_priv) {
1938 $newDb_table_privs_query = 'INSERT INTO '
1939 . Util::backquote('tables_priv') . ' VALUES("'
1940 . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "'
1941 . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5]
1942 . '", "' . $old_priv[6] . '", "' . $old_priv[7] . '");';
1944 $GLOBALS['dbi']->query($newDb_table_privs_query);
1947 // For Column Specific privileges
1948 $query_col_specific_old = 'SELECT * FROM '
1949 . Util::backquote('columns_priv') . ' WHERE '
1950 . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";';
1952 $old_privs_col = $GLOBALS['dbi']->fetchResult(
1953 $query_col_specific_old,
1957 foreach ($old_privs_col as $old_priv) {
1958 $newDb_col_privs_query = 'INSERT INTO '
1959 . Util::backquote('columns_priv') . ' VALUES("'
1960 . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "'
1961 . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5]
1962 . '", "' . $old_priv[6] . '");';
1964 $GLOBALS['dbi']->query($newDb_col_privs_query);
1967 // Finally FLUSH the new privileges
1968 $flush_query = "FLUSH PRIVILEGES;";
1969 $GLOBALS['dbi']->query($flush_query);
1974 * Change all collations and character sets of all columns in table
1976 * @param string $db Database name
1977 * @param string $table Table name
1978 * @param string $tbl_collation Collation Name
1980 * @return void
1982 function PMA_changeAllColumnsCollation($db, $table, $tbl_collation)
1984 $GLOBALS['dbi']->selectDb($db);
1986 $change_all_collations_query = 'ALTER TABLE '
1987 . Util::backquote($table)
1988 . ' CONVERT TO';
1990 list($charset) = explode('_', $tbl_collation);
1992 $change_all_collations_query .= ' CHARACTER SET ' . $charset
1993 . ($charset == $tbl_collation ? '' : ' COLLATE ' . $tbl_collation);
1995 $GLOBALS['dbi']->query($change_all_collations_query);
1999 * Move or copy a table
2001 * @param string $db current database name
2002 * @param string $table current table name
2004 * @return void
2006 function PMA_moveOrCopyTable($db, $table)
2009 * Selects the database to work with
2011 $GLOBALS['dbi']->selectDb($db);
2014 * $_REQUEST['target_db'] could be empty in case we came from an input field
2015 * (when there are many databases, no drop-down)
2017 if (empty($_REQUEST['target_db'])) {
2018 $_REQUEST['target_db'] = $db;
2022 * A target table name has been sent to this script -> do the work
2024 if (PMA_isValid($_REQUEST['new_name'])) {
2025 if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) {
2026 if (isset($_REQUEST['submit_move'])) {
2027 $message = Message::error(__('Can\'t move table to same one!'));
2028 } else {
2029 $message = Message::error(__('Can\'t copy table to same one!'));
2031 } else {
2032 Table::moveCopy(
2033 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'],
2034 $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table'
2037 if (isset($_REQUEST['adjust_privileges'])
2038 && ! empty($_REQUEST['adjust_privileges'])
2040 if (isset($_REQUEST['submit_move'])) {
2041 PMA_AdjustPrivileges_renameOrMoveTable(
2042 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']
2044 } else {
2045 PMA_AdjustPrivileges_copyTable(
2046 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']
2050 if (isset($_REQUEST['submit_move'])) {
2051 $message = Message::success(
2053 'Table %s has been moved to %s. Privileges have been '
2054 . 'adjusted.'
2057 } else {
2058 $message = Message::success(
2060 'Table %s has been copied to %s. Privileges have been '
2061 . 'adjusted.'
2066 } else {
2067 if (isset($_REQUEST['submit_move'])) {
2068 $message = Message::success(
2069 __('Table %s has been moved to %s.')
2071 } else {
2072 $message = Message::success(
2073 __('Table %s has been copied to %s.')
2078 $old = Util::backquote($db) . '.'
2079 . Util::backquote($table);
2080 $message->addParam($old);
2083 $new_name = $_REQUEST['new_name'];
2084 if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
2085 $new_name = strtolower($new_name);
2088 $new = Util::backquote($_REQUEST['target_db']) . '.'
2089 . Util::backquote($new_name);
2090 $message->addParam($new);
2092 /* Check: Work on new table or on old table? */
2093 if (isset($_REQUEST['submit_move'])
2094 || PMA_isValid($_REQUEST['switch_to_new'])
2098 } else {
2100 * No new name for the table!
2102 $message = Message::error(__('The table name is empty!'));
2105 $response = Response::getInstance();
2106 if ($response->isAjax()) {
2107 $response->addJSON('message', $message);
2108 if ($message->isSuccess()) {
2109 $response->addJSON('db', $GLOBALS['db']);
2110 } else {
2111 $response->setRequestStatus(false);
2113 exit;