Translated using Weblate (Dutch)
[phpmyadmin.git] / libraries / operations.lib.php
blobef5b8f304eccc2f57b5ae629452659b0475b13b6
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\Core;
11 use PMA\libraries\Message;
12 use PMA\libraries\Partition;
13 use PMA\libraries\plugins\export\ExportSql;
14 use PMA\libraries\Response;
15 use PMA\libraries\StorageEngine;
16 use PMA\libraries\Table;
17 use PMA\libraries\Util;
18 use PMA\libraries\URL;
20 /**
21 * Get HTML output for database comment
23 * @param string $db database name
25 * @return string $html_output
27 function PMA_getHtmlForDatabaseComment($db)
29 $html_output = '<div class="operations_half_width">'
30 . '<form method="post" action="db_operations.php" id="formDatabaseComment">'
31 . URL::getHiddenInputs($db)
32 . '<fieldset>'
33 . '<legend>';
34 if (Util::showIcons('ActionLinksMode')) {
35 $html_output .= Util::getImage('b_comment.png') . '&nbsp;';
37 $html_output .= __('Database comment');
38 $html_output .= '</legend>';
39 $html_output .= '<input type="text" name="comment" '
40 . 'class="textfield" size="30"'
41 . 'value="' . htmlspecialchars(PMA_getDBComment($db)) . '" />'
42 . '</fieldset>';
43 $html_output .= '<fieldset class="tblFooters">'
44 . '<input type="submit" value="' . __('Go') . '" />'
45 . '</fieldset>'
46 . '</form>'
47 . '</div>';
49 return $html_output;
52 /**
53 * Get HTML output for rename database
55 * @param string $db database name
57 * @return string $html_output
59 function PMA_getHtmlForRenameDatabase($db)
61 $html_output = '<div class="operations_half_width">'
62 . '<form id="rename_db_form" '
63 . 'class="ajax" '
64 . 'method="post" action="db_operations.php" '
65 . 'onsubmit="return emptyCheckTheField(this, \'newname\')">';
66 if (isset($_REQUEST['db_collation'])) {
67 $html_output .= '<input type="hidden" name="db_collation" '
68 . 'value="' . $_REQUEST['db_collation']
69 . '" />' . "\n";
71 $html_output .= '<input type="hidden" name="what" value="data" />'
72 . '<input type="hidden" name="db_rename" value="true" />'
73 . URL::getHiddenInputs($db)
74 . '<fieldset>'
75 . '<legend>';
77 if (Util::showIcons('ActionLinksMode')) {
78 $html_output .= Util::getImage('b_edit.png') . '&nbsp;';
80 $html_output .= __('Rename database to')
81 . '</legend>';
83 $html_output .= '<input id="new_db_name" type="text" name="newname" '
84 . 'maxlength="64" size="30" class="textfield" required="required"/>';
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" required="required" /><br />'
205 . Util::getRadioFields(
206 'what', $choices, 'data', true
208 $html_output .= '<br />';
209 $html_output .= '<input type="checkbox" name="create_database_before_copying" '
210 . 'value="1" id="checkbox_create_database_before_copying"'
211 . 'checked="checked" />';
212 $html_output .= '<label for="checkbox_create_database_before_copying">'
213 . __('CREATE DATABASE before copying') . '</label><br />';
214 $html_output .= '<input type="checkbox" name="drop_if_exists" value="true"'
215 . 'id="checkbox_drop" />';
216 $html_output .= '<label for="checkbox_drop">'
217 . sprintf(__('Add %s'), $drop_clause)
218 . '</label><br />';
219 $html_output .= '<input type="checkbox" name="sql_auto_increment" value="1" '
220 . 'checked="checked" id="checkbox_auto_increment" />';
221 $html_output .= '<label for="checkbox_auto_increment">'
222 . __('Add AUTO_INCREMENT value') . '</label><br />';
223 $html_output .= '<input type="checkbox" name="add_constraints" value="1"'
224 . 'id="checkbox_constraints" checked="checked"/>';
225 $html_output .= '<label for="checkbox_constraints">'
226 . __('Add constraints') . '</label><br />';
227 $html_output .= '<br />';
229 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
230 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
231 && $GLOBALS['is_reload_priv']
233 $html_output .= '<input type="checkbox" name="adjust_privileges" '
234 . 'value="1" id="checkbox_privileges" checked="checked" />';
235 } else {
236 $html_output .= '<input type="checkbox" name="adjust_privileges" '
237 . 'value="1" id="checkbox_privileges" title="' . __(
238 'You don\'t have sufficient privileges to perform this '
239 . 'operation; Please refer to the documentation for more details'
241 . '" disabled/>';
243 $html_output .= '<label for="checkbox_privileges">'
244 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
245 . '</label><br />';
247 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
248 . 'id="checkbox_switch"'
249 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
250 ? ' checked="checked"'
251 : '')
252 . '/>';
253 $html_output .= '<label for="checkbox_switch">'
254 . __('Switch to copied database') . '</label>'
255 . '</fieldset>';
256 $html_output .= '<fieldset class="tblFooters">'
257 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
258 . '</fieldset>'
259 . '</form>'
260 . '</div>';
262 return $html_output;
266 * Get HTML snippet for change database charset
268 * @param string $db database name
269 * @param string $table table name
271 * @return string $html_output
273 function PMA_getHtmlForChangeDatabaseCharset($db, $table)
275 $html_output = '<div class="operations_half_width">'
276 . '<form id="change_db_charset_form" ';
277 $html_output .= 'class="ajax" ';
278 $html_output .= 'method="post" action="db_operations.php">';
280 $html_output .= URL::getHiddenInputs($db, $table);
282 $html_output .= '<fieldset>' . "\n"
283 . ' <legend>';
284 if (Util::showIcons('ActionLinksMode')) {
285 $html_output .= Util::getImage('s_asci.png') . '&nbsp';
287 $html_output .= '<label for="select_db_collation">' . __('Collation')
288 . '</label>' . "\n"
289 . '</legend>' . "\n"
290 . Charsets::getCollationDropdownBox(
291 'db_collation',
292 'select_db_collation',
293 isset($_REQUEST['db_collation']) ? $_REQUEST['db_collation'] : '',
294 false
296 . '</fieldset>'
297 . '<fieldset class="tblFooters">'
298 . '<input type="submit" name="submitcollation"'
299 . ' value="' . __('Go') . '" />' . "\n"
300 . '</fieldset>' . "\n"
301 . '</form></div>' . "\n";
303 return $html_output;
307 * Run the Procedure definitions and function definitions
309 * to avoid selecting alternatively the current and new db
310 * we would need to modify the CREATE definitions to qualify
311 * the db name
313 * @param string $db database name
315 * @return void
317 function PMA_runProcedureAndFunctionDefinitions($db)
319 $procedure_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'PROCEDURE');
320 if ($procedure_names) {
321 foreach ($procedure_names as $procedure_name) {
322 $GLOBALS['dbi']->selectDb($db);
323 $tmp_query = $GLOBALS['dbi']->getDefinition(
324 $db, 'PROCEDURE', $procedure_name
326 // collect for later display
327 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
328 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
329 $GLOBALS['dbi']->query($tmp_query);
333 $function_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'FUNCTION');
334 if ($function_names) {
335 foreach ($function_names as $function_name) {
336 $GLOBALS['dbi']->selectDb($db);
337 $tmp_query = $GLOBALS['dbi']->getDefinition(
338 $db, 'FUNCTION', $function_name
340 // collect for later display
341 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
342 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
343 $GLOBALS['dbi']->query($tmp_query);
349 * Create database before copy
351 * @return void
353 function PMA_createDbBeforeCopy()
355 // lower_case_table_names=1 `DB` becomes `db`
356 if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
357 $_REQUEST['newname'] = mb_strtolower(
358 $_REQUEST['newname']
362 $local_query = 'CREATE DATABASE IF NOT EXISTS '
363 . Util::backquote($_REQUEST['newname']);
364 if (isset($_REQUEST['db_collation'])) {
365 $local_query .= ' DEFAULT'
366 . Util::getCharsetQueryPart($_REQUEST['db_collation']);
368 $local_query .= ';';
369 $GLOBALS['sql_query'] .= $local_query;
371 // save the original db name because Tracker.php which
372 // may be called under $GLOBALS['dbi']->query() changes $GLOBALS['db']
373 // for some statements, one of which being CREATE DATABASE
374 $original_db = $GLOBALS['db'];
375 $GLOBALS['dbi']->query($local_query);
376 $GLOBALS['db'] = $original_db;
378 // Set the SQL mode to NO_AUTO_VALUE_ON_ZERO to prevent MySQL from creating
379 // export statements it cannot import
380 $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'";
381 $GLOBALS['dbi']->query($sql_set_mode);
383 // rebuild the database list because Table::moveCopy
384 // checks in this list if the target db exists
385 $GLOBALS['dblist']->databases->build();
389 * Get views as an array and create SQL view stand-in
391 * @param array $tables_full array of all tables in given db or dbs
392 * @param ExportSql $export_sql_plugin export plugin instance
393 * @param string $db database name
395 * @return array $views
397 function PMA_getViewsAndCreateSqlViewStandIn(
398 $tables_full, $export_sql_plugin, $db
400 $views = array();
401 foreach ($tables_full as $each_table => $tmp) {
402 // to be able to rename a db containing views,
403 // first all the views are collected and a stand-in is created
404 // the real views are created after the tables
405 if ($GLOBALS['dbi']->getTable($db, $each_table)->isView()) {
407 // If view exists, and 'add drop view' is selected: Drop it!
408 if ($_REQUEST['what'] != 'nocopy'
409 && isset($_REQUEST['drop_if_exists'])
410 && $_REQUEST['drop_if_exists'] == 'true'
412 $drop_query = 'DROP VIEW IF EXISTS '
413 . Util::backquote($_REQUEST['newname']) . '.'
414 . Util::backquote($each_table);
415 $GLOBALS['dbi']->query($drop_query);
417 $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
420 $views[] = $each_table;
421 // Create stand-in definition to resolve view dependencies
422 $sql_view_standin = $export_sql_plugin->getTableDefStandIn(
423 $db, $each_table, "\n"
425 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
426 $GLOBALS['dbi']->query($sql_view_standin);
427 $GLOBALS['sql_query'] .= "\n" . $sql_view_standin;
430 return $views;
434 * Get sql query for copy/rename table and boolean for whether copy/rename or not
436 * @param array $tables_full array of all tables in given db or dbs
437 * @param boolean $move whether database name is empty or not
438 * @param string $db database name
440 * @return array SQL queries for the constraints
442 function PMA_copyTables($tables_full, $move, $db)
444 $sqlContraints = array();
445 foreach ($tables_full as $each_table => $tmp) {
446 // skip the views; we have created stand-in definitions
447 if ($GLOBALS['dbi']->getTable($db, $each_table)->isView()) {
448 continue;
451 // value of $what for this table only
452 $this_what = $_REQUEST['what'];
454 // do not copy the data from a Merge table
455 // note: on the calling FORM, 'data' means 'structure and data'
456 if ($GLOBALS['dbi']->getTable($db, $each_table)->isMerge()) {
457 if ($this_what == 'data') {
458 $this_what = 'structure';
460 if ($this_what == 'dataonly') {
461 $this_what = 'nocopy';
465 if ($this_what != 'nocopy') {
466 // keep the triggers from the original db+table
467 // (third param is empty because delimiters are only intended
468 // for importing via the mysql client or our Import feature)
469 $triggers = $GLOBALS['dbi']->getTriggers($db, $each_table, '');
471 if (! Table::moveCopy(
472 $db, $each_table, $_REQUEST['newname'], $each_table,
473 (isset($this_what) ? $this_what : 'data'),
474 $move, 'db_copy'
475 )) {
476 $GLOBALS['_error'] = true;
477 break;
479 // apply the triggers to the destination db+table
480 if ($triggers) {
481 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
482 foreach ($triggers as $trigger) {
483 $GLOBALS['dbi']->query($trigger['create']);
484 $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';';
488 // this does not apply to a rename operation
489 if (isset($_REQUEST['add_constraints'])
490 && ! empty($GLOBALS['sql_constraints_query'])
492 $sqlContraints[] = $GLOBALS['sql_constraints_query'];
493 unset($GLOBALS['sql_constraints_query']);
497 return $sqlContraints;
501 * Run the EVENT definition for selected database
503 * to avoid selecting alternatively the current and new db
504 * we would need to modify the CREATE definitions to qualify
505 * the db name
507 * @param string $db database name
509 * @return void
511 function PMA_runEventDefinitionsForDb($db)
513 $event_names = $GLOBALS['dbi']->fetchResult(
514 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \''
515 . $GLOBALS['dbi']->escapeString($db) . '\';'
517 if ($event_names) {
518 foreach ($event_names as $event_name) {
519 $GLOBALS['dbi']->selectDb($db);
520 $tmp_query = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $event_name);
521 // collect for later display
522 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
523 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
524 $GLOBALS['dbi']->query($tmp_query);
530 * Handle the views, return the boolean value whether table rename/copy or not
532 * @param array $views views as an array
533 * @param boolean $move whether database name is empty or not
534 * @param string $db database name
536 * @return void
538 function PMA_handleTheViews($views, $move, $db)
540 // temporarily force to add DROP IF EXIST to CREATE VIEW query,
541 // to remove stand-in VIEW that was created earlier
542 // ( $_REQUEST['drop_if_exists'] is used in moveCopy() )
543 if (isset($_REQUEST['drop_if_exists'])) {
544 $temp_drop_if_exists = $_REQUEST['drop_if_exists'];
547 $_REQUEST['drop_if_exists'] = 'true';
548 foreach ($views as $view) {
549 $copying_succeeded = Table::moveCopy(
550 $db, $view, $_REQUEST['newname'], $view, 'structure', $move, 'db_copy'
552 if (! $copying_succeeded) {
553 $GLOBALS['_error'] = true;
554 break;
557 unset($_REQUEST['drop_if_exists']);
559 if (isset($temp_drop_if_exists)) {
560 // restore previous value
561 $_REQUEST['drop_if_exists'] = $temp_drop_if_exists;
566 * Adjust the privileges after Renaming the db
568 * @param string $oldDb Database name before renaming
569 * @param string $newname New Database name requested
571 * @return void
573 function PMA_AdjustPrivileges_moveDB($oldDb, $newname)
575 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
576 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
577 && $GLOBALS['is_reload_priv']
579 $GLOBALS['dbi']->selectDb('mysql');
580 $newname = str_replace("_", "\_", $newname);
581 $oldDb = str_replace("_", "\_", $oldDb);
583 // For Db specific privileges
584 $query_db_specific = 'UPDATE ' . Util::backquote('db')
585 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
586 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
587 $GLOBALS['dbi']->query($query_db_specific);
589 // For table specific privileges
590 $query_table_specific = 'UPDATE ' . Util::backquote('tables_priv')
591 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
592 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
593 $GLOBALS['dbi']->query($query_table_specific);
595 // For column specific privileges
596 $query_col_specific = 'UPDATE ' . Util::backquote('columns_priv')
597 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
598 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
599 $GLOBALS['dbi']->query($query_col_specific);
601 // For procedures specific privileges
602 $query_proc_specific = 'UPDATE ' . Util::backquote('procs_priv')
603 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
604 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
605 $GLOBALS['dbi']->query($query_proc_specific);
607 // Finally FLUSH the new privileges
608 $flush_query = "FLUSH PRIVILEGES;";
609 $GLOBALS['dbi']->query($flush_query);
614 * Adjust the privileges after Copying the db
616 * @param string $oldDb Database name before copying
617 * @param string $newname New Database name requested
619 * @return void
621 function PMA_AdjustPrivileges_copyDB($oldDb, $newname)
623 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
624 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
625 && $GLOBALS['is_reload_priv']
627 $GLOBALS['dbi']->selectDb('mysql');
628 $newname = str_replace("_", "\_", $newname);
629 $oldDb = str_replace("_", "\_", $oldDb);
631 $query_db_specific_old = 'SELECT * FROM '
632 . Util::backquote('db') . ' WHERE '
633 . 'Db = "' . $oldDb . '";';
635 $old_privs_db = $GLOBALS['dbi']->fetchResult($query_db_specific_old, 0);
637 foreach ($old_privs_db as $old_priv) {
638 $newDb_db_privs_query = 'INSERT INTO ' . Util::backquote('db')
639 . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
640 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
641 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
642 . $old_priv[7] . '", "' . $old_priv[8] . '", "' . $old_priv[9]
643 . '", "' . $old_priv[10] . '", "' . $old_priv[11] . '", "'
644 . $old_priv[12] . '", "' . $old_priv[13] . '", "' . $old_priv[14]
645 . '", "' . $old_priv[15] . '", "' . $old_priv[16] . '", "'
646 . $old_priv[17] . '", "' . $old_priv[18] . '", "' . $old_priv[19]
647 . '", "' . $old_priv[20] . '", "' . $old_priv[21] . '");';
649 $GLOBALS['dbi']->query($newDb_db_privs_query);
652 // For Table Specific privileges
653 $query_table_specific_old = 'SELECT * FROM '
654 . Util::backquote('tables_priv') . ' WHERE '
655 . 'Db = "' . $oldDb . '";';
657 $old_privs_table = $GLOBALS['dbi']->fetchResult(
658 $query_table_specific_old,
662 foreach ($old_privs_table as $old_priv) {
663 $newDb_table_privs_query = 'INSERT INTO ' . Util::backquote(
664 'tables_priv'
665 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
666 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
667 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
668 . $old_priv[7] . '");';
670 $GLOBALS['dbi']->query($newDb_table_privs_query);
673 // For Column Specific privileges
674 $query_col_specific_old = 'SELECT * FROM '
675 . Util::backquote('columns_priv') . ' WHERE '
676 . 'Db = "' . $oldDb . '";';
678 $old_privs_col = $GLOBALS['dbi']->fetchResult(
679 $query_col_specific_old,
683 foreach ($old_privs_col as $old_priv) {
684 $newDb_col_privs_query = 'INSERT INTO ' . Util::backquote(
685 'columns_priv'
686 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
687 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
688 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '");';
690 $GLOBALS['dbi']->query($newDb_col_privs_query);
693 // For Procedure Specific privileges
694 $query_proc_specific_old = 'SELECT * FROM '
695 . Util::backquote('procs_priv') . ' WHERE '
696 . 'Db = "' . $oldDb . '";';
698 $old_privs_proc = $GLOBALS['dbi']->fetchResult(
699 $query_proc_specific_old,
703 foreach ($old_privs_proc as $old_priv) {
704 $newDb_proc_privs_query = 'INSERT INTO ' . Util::backquote(
705 'procs_priv'
706 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
707 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
708 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
709 . $old_priv[7] . '");';
711 $GLOBALS['dbi']->query($newDb_proc_privs_query);
714 // Finally FLUSH the new privileges
715 $flush_query = "FLUSH PRIVILEGES;";
716 $GLOBALS['dbi']->query($flush_query);
721 * Create all accumulated constraints
723 * @param array $sqlConstratints array of sql constraints for the database
725 * @return void
727 function PMA_createAllAccumulatedConstraints($sqlConstratints)
729 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
730 foreach ($sqlConstratints as $one_query) {
731 $GLOBALS['dbi']->query($one_query);
732 // and prepare to display them
733 $GLOBALS['sql_query'] .= "\n" . $one_query;
738 * Duplicate the bookmarks for the db (done once for each db)
740 * @param boolean $_error whether table rename/copy or not
741 * @param string $db database name
743 * @return void
745 function PMA_duplicateBookmarks($_error, $db)
747 if (! $_error && $db != $_REQUEST['newname']) {
748 $get_fields = array('user', 'label', 'query');
749 $where_fields = array('dbase' => $db);
750 $new_fields = array('dbase' => $_REQUEST['newname']);
751 Table::duplicateInfo(
752 'bookmarkwork', 'bookmark', $get_fields,
753 $where_fields, $new_fields
759 * Get the HTML snippet for order the table
761 * @param array $columns columns array
763 * @return string $html_out
765 function PMA_getHtmlForOrderTheTable($columns)
767 $html_output = '<div class="operations_half_width">';
768 $html_output .= '<form method="post" id="alterTableOrderby" '
769 . 'action="tbl_operations.php">';
770 $html_output .= URL::getHiddenInputs(
771 $GLOBALS['db'], $GLOBALS['table']
773 $html_output .= '<fieldset id="fieldset_table_order">'
774 . '<legend>' . __('Alter table order by') . '</legend>'
775 . '<select name="order_field">';
777 foreach ($columns as $fieldname) {
778 $html_output .= '<option '
779 . 'value="' . htmlspecialchars($fieldname['Field']) . '">'
780 . htmlspecialchars($fieldname['Field']) . '</option>' . "\n";
782 $html_output .= '</select> ' . __('(singly)') . ' '
783 . '<br />'
784 . '<input id="order_order_asc" name="order_order"'
785 . ' type="radio" value="asc" checked="checked" />'
786 . '<label for="order_order_asc">' . __('Ascending') . '</label>'
787 . '<input id="order_order_desc" name="order_order"'
788 . ' type="radio" value="desc" />'
789 . '<label for="order_order_desc">' . __('Descending') . '</label>'
790 . '</fieldset>'
791 . '<fieldset class="tblFooters">'
792 . '<input type="hidden" name="submitorderby" value="1" />'
793 . '<input type="submit" value="' . __('Go') . '" />'
794 . '</fieldset>'
795 . '</form>'
796 . '</div>';
798 return $html_output;
802 * Get the HTML snippet for move table
804 * @return string $html_output
806 function PMA_getHtmlForMoveTable()
808 $html_output = '<div class="operations_half_width">';
809 $html_output .= '<form method="post" action="tbl_operations.php"'
810 . ' id="moveTableForm" class="ajax"'
811 . ' onsubmit="return emptyCheckTheField(this, \'new_name\')">'
812 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
814 $html_output .= '<input type="hidden" name="reload" value="1" />'
815 . '<input type="hidden" name="what" value="data" />'
816 . '<fieldset id="fieldset_table_rename">';
818 $html_output .= '<legend>' . __('Move table to (database<b>.</b>table)')
819 . '</legend>';
821 if (count($GLOBALS['dblist']->databases) > $GLOBALS['cfg']['MaxDbList']) {
822 $html_output .= '<input type="text" maxlength="100" size="30" '
823 . 'name="target_db" value="' . htmlspecialchars($GLOBALS['db'])
824 . '"/>';
825 } else {
826 $html_output .= '<select class="halfWidth" name="target_db">'
827 . $GLOBALS['dblist']->databases->getHtmlOptions(true, false)
828 . '</select>';
830 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
831 $html_output .= '<input class="halfWidth" type="text" size="20" name="new_name"'
832 . ' maxlength="64" required="required" '
833 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" /><br />';
835 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
836 // next value but users can decide if they want it or not for the operation
838 $html_output .= '<input type="checkbox" name="sql_auto_increment" '
839 . 'value="1" id="checkbox_auto_increment_mv" checked="checked" />'
840 . '<label for="checkbox_auto_increment_mv">'
841 . __('Add AUTO_INCREMENT value')
842 . '</label><br />';
844 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
845 && $GLOBALS['is_reload_priv']
847 $html_output .= '<input type="checkbox" name="adjust_privileges" '
848 . 'value="1" id="checkbox_privileges_tables_move" '
849 . 'checked="checked" />';
850 } else {
851 $html_output .= '<input type="checkbox" name="adjust_privileges" '
852 . 'value="1" id="checkbox_privileges_tables_move" title="' . __(
853 'You don\'t have sufficient privileges to perform this '
854 . 'operation; Please refer to the documentation for more details'
856 . '" disabled/>';
858 $html_output .= '<label for="checkbox_privileges_tables_move">'
859 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
860 . '</label><br />';
862 $html_output .= '</fieldset><fieldset class="tblFooters">'
863 . '<input type="submit" name="submit_move" value="' . __('Go') . '" />'
864 . '</fieldset>'
865 . '</form>'
866 . '</div>';
868 return $html_output;
872 * Get the HTML div for Table option
874 * @param Table $pma_table Table object
875 * @param string $comment Comment
876 * @param array $tbl_collation table collation
877 * @param string $tbl_storage_engine table storage engine
878 * @param string $pack_keys pack keys
879 * @param string $auto_increment value of auto increment
880 * @param string $delay_key_write delay key write
881 * @param string $transactional value of transactional
882 * @param string $page_checksum value of page checksum
883 * @param string $checksum the checksum
885 * @return string $html_output
887 function PMA_getTableOptionDiv($pma_table, $comment, $tbl_collation, $tbl_storage_engine,
888 $pack_keys, $auto_increment, $delay_key_write,
889 $transactional, $page_checksum, $checksum
891 $html_output = '<div class="operations_half_width clearfloat">';
892 $html_output .= '<form method="post" action="tbl_operations.php"';
893 $html_output .= ' id="tableOptionsForm" class="ajax">';
894 $html_output .= URL::getHiddenInputs(
895 $GLOBALS['db'], $GLOBALS['table']
897 $html_output .= '<input type="hidden" name="reload" value="1" />';
899 $html_output .= PMA_getTableOptionFieldset(
900 $pma_table, $comment, $tbl_collation,
901 $tbl_storage_engine, $pack_keys,
902 $delay_key_write, $auto_increment, $transactional, $page_checksum,
903 $checksum
906 $html_output .= '<fieldset class="tblFooters">'
907 . '<input type="hidden" name="submitoptions" value="1" />'
908 . '<input type="submit" value="' . __('Go') . '" />'
909 . '</fieldset>'
910 . '</form>'
911 . '</div>';
913 return $html_output;
917 * Get HTML for the rename table part of table options
919 * @return string $html_output
921 function PMA_getHtmlForRenameTable()
923 $html_output = '<tr><td class="vmiddle">' . __('Rename table to') . '</td>'
924 . '<td>'
925 . '<input type="text" size="20" name="new_name" maxlength="64" '
926 . 'value="' . htmlspecialchars($GLOBALS['table'])
927 . '" required="required" />'
928 . '</td></tr>'
929 . '<tr><td></td><td>';
931 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
932 && $GLOBALS['is_reload_priv']
934 $html_output .= '<input type="checkbox" name="adjust_privileges" '
935 . 'value="1" id="checkbox_privileges_table_options" '
936 . 'checked="checked" />';
937 } else {
938 $html_output .= '<input type="checkbox" name="adjust_privileges" '
939 . 'value="1" id="checkbox_privileges_table_options" title="' . __(
940 'You don\'t have sufficient privileges to perform this '
941 . 'operation; Please refer to the documentation for more details'
943 . '" disabled/>';
945 $html_output .= '<label for="checkbox_privileges_table_options">'
946 . __('Adjust privileges') . '&nbsp;'
947 . Util::showDocu('faq', 'faq6-39') . '</label>';
949 $html_output .= '</td></tr>';
950 return $html_output;
954 * Get HTML for the table comments part of table options
956 * @param string $current_value of the table comments
958 * @return string $html_output
960 function PMA_getHtmlForTableComments($current_value)
962 $commentLength = PMA_MYSQL_INT_VERSION >= 50503 ? 2048 : 60;
963 $html_output = '<tr><td class="vmiddle">' . __('Table comments') . '</td>'
964 . '<td><input type="text" name="comment" '
965 . 'maxlength="' . $commentLength . '" size="30"'
966 . 'value="' . htmlspecialchars($current_value) . '" />'
967 . '<input type="hidden" name="prev_comment" value="'
968 . htmlspecialchars($current_value) . '" />'
969 . '</td>'
970 . '</tr>';
972 return $html_output;
976 * Get HTML for the PACK KEYS part of table options
978 * @param string $current_value of the pack keys option
980 * @return string $html_output
982 function PMA_getHtmlForPackKeys($current_value)
984 $html_output = '<tr>'
985 . '<td class="vmiddle"><label for="new_pack_keys">PACK_KEYS</label></td>'
986 . '<td><select name="new_pack_keys" id="new_pack_keys">';
988 $html_output .= '<option value="DEFAULT"';
989 if ($current_value == 'DEFAULT') {
990 $html_output .= 'selected="selected"';
992 $html_output .= '>DEFAULT</option>
993 <option value="0"';
994 if ($current_value == '0') {
995 $html_output .= 'selected="selected"';
997 $html_output .= '>0</option>
998 <option value="1" ';
999 if ($current_value == '1') {
1000 $html_output .= 'selected="selected"';
1002 $html_output .= '>1</option>'
1003 . '</select>'
1004 . '</td>'
1005 . '</tr>';
1007 return $html_output;
1011 * Get HTML fieldset for Table option, it contains HTML table for options
1013 * @param Table $pma_table Table object
1014 * @param string $comment Comment
1015 * @param array $tbl_collation table collation
1016 * @param string $tbl_storage_engine table storage engine
1017 * @param string $pack_keys pack keys
1018 * @param string $delay_key_write delay key write
1019 * @param string $auto_increment value of auto increment
1020 * @param string $transactional value of transactional
1021 * @param string $page_checksum value of page checksum
1022 * @param string $checksum the checksum
1024 * @return string $html_output
1026 function PMA_getTableOptionFieldset($pma_table, $comment, $tbl_collation,
1027 $tbl_storage_engine, $pack_keys,
1028 $delay_key_write, $auto_increment, $transactional,
1029 $page_checksum, $checksum
1031 $html_output = '<fieldset>'
1032 . '<legend>' . __('Table options') . '</legend>';
1034 $html_output .= '<table>';
1035 $html_output .= PMA_getHtmlForRenameTable();
1036 $html_output .= PMA_getHtmlForTableComments($comment);
1038 //Storage engine
1039 $html_output .= '<tr><td class="vmiddle">' . __('Storage Engine')
1040 . '&nbsp;' . Util::showMySQLDocu('Storage_engines')
1041 . '</td>'
1042 . '<td>'
1043 . StorageEngine::getHtmlSelect(
1044 'new_tbl_storage_engine', null, $tbl_storage_engine
1046 . '</td>'
1047 . '</tr>';
1049 //Table character set
1050 $html_output .= '<tr><td class="vmiddle">' . __('Collation') . '</td>'
1051 . '<td>'
1052 . Charsets::getCollationDropdownBox(
1053 'tbl_collation', null, $tbl_collation, false
1055 . '</td>'
1056 . '</tr>';
1058 // Change all Column collations
1059 $html_output .= '<tr><td></td><td>'
1060 . '<input type="checkbox" name="change_all_collations" value="1" '
1061 . 'id="checkbox_change_all_collations" />'
1062 . '<label for="checkbox_change_all_collations">'
1063 . __('Change all column collations')
1064 . '</label>'
1065 . '</td></tr>';
1067 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'ISAM'))) {
1068 $html_output .= PMA_getHtmlForPackKeys($pack_keys);
1069 } // end if (MYISAM|ISAM)
1071 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))) {
1072 $html_output .= PMA_getHtmlForTableRow(
1073 'new_checksum',
1074 'CHECKSUM',
1075 $checksum
1078 $html_output .= PMA_getHtmlForTableRow(
1079 'new_delay_key_write',
1080 'DELAY_KEY_WRITE',
1081 $delay_key_write
1083 } // end if (MYISAM)
1085 if ($pma_table->isEngine('ARIA')) {
1086 $html_output .= PMA_getHtmlForTableRow(
1087 'new_transactional',
1088 'TRANSACTIONAL',
1089 $transactional
1092 $html_output .= PMA_getHtmlForTableRow(
1093 'new_page_checksum',
1094 'PAGE_CHECKSUM',
1095 $page_checksum
1097 } // end if (ARIA)
1099 if (strlen($auto_increment) > 0
1100 && $pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1102 $html_output .= '<tr><td class="vmiddle">'
1103 . '<label for="auto_increment_opt">AUTO_INCREMENT</label></td>'
1104 . '<td><input type="number" name="new_auto_increment" '
1105 . 'id="auto_increment_opt"'
1106 . 'value="' . $auto_increment . '" /></td>'
1107 . '</tr> ';
1108 } // end if (MYISAM|INNODB)
1110 $possible_row_formats = PMA_getPossibleRowFormat();
1112 // for MYISAM there is also COMPRESSED but it can be set only by the
1113 // myisampack utility, so don't offer here the choice because if we
1114 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
1115 // does not return a warning
1116 // (if the table was compressed, it can be seen on the Structure page)
1118 if (isset($possible_row_formats[$tbl_storage_engine])) {
1119 $current_row_format
1120 = mb_strtoupper($GLOBALS['showtable']['Row_format']);
1121 $html_output .= '<tr><td class="vmiddle">'
1122 . '<label for="new_row_format">ROW_FORMAT</label></td>'
1123 . '<td>';
1124 $html_output .= Util::getDropdown(
1125 'new_row_format', $possible_row_formats[$tbl_storage_engine],
1126 $current_row_format, 'new_row_format'
1128 $html_output .= '</td></tr>';
1130 $html_output .= '</table>'
1131 . '</fieldset>';
1133 return $html_output;
1137 * Get the common HTML table row (tr) for new_checksum, new_delay_key_write,
1138 * new_transactional and new_page_checksum
1140 * @param string $attribute class, name and id attribute
1141 * @param string $label label value
1142 * @param string $val checksum, delay_key_write, transactional, page_checksum
1144 * @return string $html_output
1146 function PMA_getHtmlForTableRow($attribute, $label, $val)
1148 return '<tr>'
1149 . '<td class="vmiddle">'
1150 . '<label for="' . $attribute . '">' . $label . '</label>'
1151 . '</td>'
1152 . '<td>'
1153 . '<input type="checkbox" name="' . $attribute . '" id="' . $attribute . '"'
1154 . ' value="1"' . ((!empty($val) && $val == 1) ? ' checked="checked"' : '')
1155 . '/>'
1156 . '</td>'
1157 . '</tr>';
1161 * Get array of possible row formats
1163 * @return array $possible_row_formats
1165 function PMA_getPossibleRowFormat()
1167 // the outer array is for engines, the inner array contains the dropdown
1168 // option values as keys then the dropdown option labels
1170 $possible_row_formats = array(
1171 'ARCHIVE' => array(
1172 'COMPRESSED' => 'COMPRESSED',
1174 'ARIA' => array(
1175 'FIXED' => 'FIXED',
1176 'DYNAMIC' => 'DYNAMIC',
1177 'PAGE' => 'PAGE'
1179 'MARIA' => array(
1180 'FIXED' => 'FIXED',
1181 'DYNAMIC' => 'DYNAMIC',
1182 'PAGE' => 'PAGE'
1184 'MYISAM' => array(
1185 'FIXED' => 'FIXED',
1186 'DYNAMIC' => 'DYNAMIC'
1188 'PBXT' => array(
1189 'FIXED' => 'FIXED',
1190 'DYNAMIC' => 'DYNAMIC'
1192 'INNODB' => array(
1193 'COMPACT' => 'COMPACT',
1194 'REDUNDANT' => 'REDUNDANT'
1198 /** @var Innodb $innodbEnginePlugin */
1199 $innodbEnginePlugin = StorageEngine::getEngine('Innodb');
1200 $innodbPluginVersion = $innodbEnginePlugin->getInnodbPluginVersion();
1201 if (!empty($innodbPluginVersion)) {
1202 $innodb_file_format = $innodbEnginePlugin->getInnodbFileFormat();
1203 } else {
1204 $innodb_file_format = '';
1206 if ('Barracuda' == $innodb_file_format
1207 && $innodbEnginePlugin->supportsFilePerTable()
1209 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
1210 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
1213 return $possible_row_formats;
1217 * Get HTML div for copy table
1219 * @return string $html_output
1221 function PMA_getHtmlForCopytable()
1223 $html_output = '<div class="operations_half_width">';
1224 $html_output .= '<form method="post" action="tbl_operations.php" '
1225 . 'name="copyTable" '
1226 . 'id="copyTable" '
1227 . ' class="ajax" '
1228 . 'onsubmit="return emptyCheckTheField(this, \'new_name\')">'
1229 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1230 . '<input type="hidden" name="reload" value="1" />';
1232 $html_output .= '<fieldset>';
1233 $html_output .= '<legend>'
1234 . __('Copy table to (database<b>.</b>table)') . '</legend>';
1236 if (count($GLOBALS['dblist']->databases) > $GLOBALS['cfg']['MaxDbList']) {
1237 $html_output .= '<input class="halfWidth" type="text" maxlength="100" '
1238 . 'size="30" name="target_db" '
1239 . 'value="' . htmlspecialchars($GLOBALS['db']) . '"/>';
1240 } else {
1241 $html_output .= '<select class="halfWidth" name="target_db">'
1242 . $GLOBALS['dblist']->databases->getHtmlOptions(true, false)
1243 . '</select>';
1245 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
1246 $html_output .= '<input class="halfWidth" type="text" required="required" '
1247 . 'size="20" name="new_name" maxlength="64" '
1248 . 'value="' . htmlspecialchars($GLOBALS['table']) . '"/><br />';
1250 $choices = array(
1251 'structure' => __('Structure only'),
1252 'data' => __('Structure and data'),
1253 'dataonly' => __('Data only')
1256 $html_output .= Util::getRadioFields(
1257 'what', $choices, 'data', true
1259 $html_output .= '<br />';
1261 $html_output .= '<input type="checkbox" name="drop_if_exists" '
1262 . 'value="true" id="checkbox_drop" />'
1263 . '<label for="checkbox_drop">'
1264 . sprintf(__('Add %s'), 'DROP TABLE') . '</label><br />'
1265 . '<input type="checkbox" name="sql_auto_increment" '
1266 . 'value="1" id="checkbox_auto_increment_cp" />'
1267 . '<label for="checkbox_auto_increment_cp">'
1268 . __('Add AUTO_INCREMENT value') . '</label><br />';
1270 // display "Add constraints" choice only if there are
1271 // foreign keys
1272 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
1273 $html_output .= '<input type="checkbox" name="add_constraints" '
1274 . 'value="1" id="checkbox_constraints" checked="checked"/>';
1275 $html_output .= '<label for="checkbox_constraints">'
1276 . __('Add constraints') . '</label><br />';
1277 } // endif
1279 $html_output .= '<br />';
1281 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1282 && $GLOBALS['is_reload_priv']
1284 $html_output .= '<input type="checkbox" name="adjust_privileges" '
1285 . 'value="1" id="checkbox_adjust_privileges" checked="checked" />';
1286 } else {
1287 $html_output .= '<input type="checkbox" name="adjust_privileges" '
1288 . 'value="1" id="checkbox_adjust_privileges" title="' . __(
1289 'You don\'t have sufficient privileges to perform this '
1290 . 'operation; Please refer to the documentation for more details'
1292 . '" disabled/>';
1294 $html_output .= '<label for="checkbox_adjust_privileges">'
1295 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
1296 . '</label><br />';
1298 if (isset($_COOKIE['pma_switch_to_new'])
1299 && $_COOKIE['pma_switch_to_new'] == 'true'
1301 $pma_switch_to_new = 'true';
1304 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
1305 . 'id="checkbox_switch"'
1306 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
1307 ? ' checked="checked"'
1308 : '' . '/>');
1309 $html_output .= '<label for="checkbox_switch">'
1310 . __('Switch to copied table') . '</label>'
1311 . '</fieldset>';
1313 $html_output .= '<fieldset class="tblFooters">'
1314 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
1315 . '</fieldset>'
1316 . '</form>'
1317 . '</div>';
1319 return $html_output;
1323 * Get HTML snippet for table maintenance
1325 * @param Table $pma_table Table object
1326 * @param array $url_params array of URL parameters
1328 * @return string $html_output
1330 function PMA_getHtmlForTableMaintenance($pma_table, $url_params)
1332 $html_output = '<div class="operations_half_width">';
1333 $html_output .= '<fieldset>'
1334 . '<legend>' . __('Table maintenance') . '</legend>';
1335 $html_output .= '<ul id="tbl_maintenance">';
1337 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
1338 $html_output .= PMA_getListofMaintainActionLink($pma_table, $url_params);
1340 $html_output .= '</ul>'
1341 . '</fieldset>'
1342 . '</div>';
1344 return $html_output;
1348 * Get HTML 'li' having a link of maintain action
1350 * @param Table $pma_table Table object
1351 * @param array $url_params Array of URL parameters
1353 * @return string $html_output
1355 function PMA_getListofMaintainActionLink($pma_table, $url_params)
1357 $html_output = '';
1359 // analyze table
1360 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'BERKELEYDB', 'TOKUDB'))) {
1361 $params = array(
1362 'sql_query' => 'ANALYZE TABLE '
1363 . Util::backquote($GLOBALS['table']),
1364 'table_maintenance' => 'Go',
1366 $html_output .= PMA_getMaintainActionlink(
1367 __('Analyze table'),
1368 $params,
1369 $url_params,
1370 'ANALYZE_TABLE'
1374 // check table
1375 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'TOKUDB'))) {
1376 $params = array(
1377 'sql_query' => 'CHECK TABLE '
1378 . Util::backquote($GLOBALS['table']),
1379 'table_maintenance' => 'Go',
1381 $html_output .= PMA_getMaintainActionlink(
1382 __('Check table'),
1383 $params,
1384 $url_params,
1385 'CHECK_TABLE'
1389 // checksum table
1390 $params = array(
1391 'sql_query' => 'CHECKSUM TABLE '
1392 . Util::backquote($GLOBALS['table']),
1393 'table_maintenance' => 'Go',
1395 $html_output .= PMA_getMaintainActionlink(
1396 __('Checksum table'),
1397 $params,
1398 $url_params,
1399 'CHECKSUM_TABLE'
1402 // defragment table
1403 if ($pma_table->isEngine(array('INNODB'))) {
1404 $params = array(
1405 'sql_query' => 'ALTER TABLE '
1406 . Util::backquote($GLOBALS['table'])
1407 . ' ENGINE = InnoDB;'
1409 $html_output .= PMA_getMaintainActionlink(
1410 __('Defragment table'),
1411 $params,
1412 $url_params,
1413 'InnoDB_File_Defragmenting'
1417 // flush table
1418 $params = array(
1419 'sql_query' => 'FLUSH TABLE '
1420 . Util::backquote($GLOBALS['table']),
1421 'message_to_show' => sprintf(
1422 __('Table %s has been flushed.'),
1423 htmlspecialchars($GLOBALS['table'])
1425 'reload' => 1,
1427 $html_output .= PMA_getMaintainActionlink(
1428 __('Flush the table (FLUSH)'),
1429 $params,
1430 $url_params,
1431 'FLUSH'
1434 // optimize table
1435 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'BERKELEYDB', 'TOKUDB'))) {
1436 $params = array(
1437 'sql_query' => 'OPTIMIZE TABLE '
1438 . Util::backquote($GLOBALS['table']),
1439 'table_maintenance' => 'Go',
1441 $html_output .= PMA_getMaintainActionlink(
1442 __('Optimize table'),
1443 $params,
1444 $url_params,
1445 'OPTIMIZE_TABLE'
1449 // repair table
1450 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))) {
1451 $params = array(
1452 'sql_query' => 'REPAIR TABLE '
1453 . Util::backquote($GLOBALS['table']),
1454 'table_maintenance' => 'Go',
1456 $html_output .= PMA_getMaintainActionlink(
1457 __('Repair table'),
1458 $params,
1459 $url_params,
1460 'REPAIR_TABLE'
1464 return $html_output;
1468 * Get maintain action HTML link
1470 * @param string $action_message action message
1471 * @param array $params url parameters array
1472 * @param array $url_params additional url parameters
1473 * @param string $link contains name of page/anchor that is being linked
1475 * @return string $html_output
1477 function PMA_getMaintainActionlink($action_message, $params, $url_params, $link)
1479 return '<li>'
1480 . '<a class="maintain_action ajax" '
1481 . 'href="sql.php'
1482 . URL::getCommon(array_merge($url_params, $params)) . '">'
1483 . $action_message
1484 . '</a>'
1485 . Util::showMySQLDocu($link)
1486 . '</li>';
1490 * Get HTML for Delete data or table (truncate table, drop table)
1492 * @param array $truncate_table_url_params url parameter array for truncate table
1493 * @param array $dropTableUrlParams url parameter array for drop table
1495 * @return string $html_output
1497 function PMA_getHtmlForDeleteDataOrTable(
1498 $truncate_table_url_params,
1499 $dropTableUrlParams
1501 $html_output = '<div class="operations_half_width">'
1502 . '<fieldset class="caution">'
1503 . '<legend>' . __('Delete data or table') . '</legend>';
1505 $html_output .= '<ul>';
1507 if (! empty($truncate_table_url_params)) {
1508 $html_output .= PMA_getDeleteDataOrTablelink(
1509 $truncate_table_url_params,
1510 'TRUNCATE_TABLE',
1511 __('Empty the table (TRUNCATE)'),
1512 'truncate_tbl_anchor'
1515 if (!empty($dropTableUrlParams)) {
1516 $html_output .= PMA_getDeleteDataOrTablelink(
1517 $dropTableUrlParams,
1518 'DROP_TABLE',
1519 __('Delete the table (DROP)'),
1520 'drop_tbl_anchor'
1523 $html_output .= '</ul></fieldset></div>';
1525 return $html_output;
1529 * Get the HTML link for Truncate table, Drop table and Drop db
1531 * @param array $url_params url parameter array for delete data or table
1532 * @param string $syntax TRUNCATE_TABLE or DROP_TABLE or DROP_DATABASE
1533 * @param string $link link to be shown
1534 * @param string $htmlId id of the link
1536 * @return String html output
1538 function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $htmlId)
1540 return '<li><a '
1541 . 'href="sql.php' . URL::getCommon($url_params) . '"'
1542 . ' id="' . $htmlId . '" class="ajax">'
1543 . $link . '</a>'
1544 . Util::showMySQLDocu($syntax)
1545 . '</li>';
1549 * Get HTML snippet for partition maintenance
1551 * @param array $partition_names array of partition names for a specific db/table
1552 * @param array $url_params url parameters
1554 * @return string $html_output
1556 function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
1558 $choices = array(
1559 'ANALYZE' => __('Analyze'),
1560 'CHECK' => __('Check'),
1561 'OPTIMIZE' => __('Optimize'),
1562 'REBUILD' => __('Rebuild'),
1563 'REPAIR' => __('Repair'),
1564 'TRUNCATE' => __('Truncate')
1567 $partition_method = Partition::getPartitionMethod(
1568 $GLOBALS['db'], $GLOBALS['table']
1570 // add COALESCE or DROP option to choices array depeding on Partition method
1571 if ($partition_method == 'RANGE'
1572 || $partition_method == 'RANGE COLUMNS'
1573 || $partition_method == 'LIST'
1574 || $partition_method == 'LIST COLUMNS'
1576 $choices['DROP'] = __('Drop');
1577 } else {
1578 $choices['COALESCE'] = __('Coalesce');
1581 $html_output = '<div class="operations_half_width">'
1582 . '<form id="partitionsForm" class="ajax" '
1583 . 'method="post" action="tbl_operations.php" >'
1584 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1585 . '<fieldset>'
1586 . '<legend>'
1587 . __('Partition maintenance')
1588 . Util::showMySQLDocu('partitioning_maintenance')
1589 . '</legend>';
1591 $html_select = '<select id="partition_name" name="partition_name[]"'
1592 . ' multiple="multiple" required="required">' . "\n";
1593 $first = true;
1594 foreach ($partition_names as $one_partition) {
1595 $one_partition = htmlspecialchars($one_partition);
1596 $html_select .= '<option value="' . $one_partition . '"';
1597 if ($first) {
1598 $html_select .= ' selected="selected"';
1599 $first = false;
1601 $html_select .= '>' . $one_partition . '</option>' . "\n";
1603 $html_select .= '</select>' . "\n";
1604 $html_output .= sprintf(__('Partition %s'), $html_select);
1606 $html_output .= '<div class="clearfloat" />';
1607 $html_output .= Util::getRadioFields(
1608 'partition_operation', $choices, 'ANALYZE', false, true, 'floatleft'
1610 $this_url_params = array_merge(
1611 $url_params,
1612 array(
1613 'sql_query' => 'ALTER TABLE '
1614 . Util::backquote($GLOBALS['table'])
1615 . ' REMOVE PARTITIONING;'
1618 $html_output .= '<div class="clearfloat" /><br />';
1620 $html_output .= '<a href="sql.php'
1621 . URL::getCommon($this_url_params) . '">'
1622 . __('Remove partitioning') . '</a>';
1624 $html_output .= '</fieldset>'
1625 . '<fieldset class="tblFooters">'
1626 . '<input type="hidden" name="submit_partition" value="1">'
1627 . '<input type="submit" value="' . __('Go') . '" />'
1628 . '</fieldset>'
1629 . '</form>'
1630 . '</div>';
1632 return $html_output;
1636 * Get the HTML for Referential Integrity check
1638 * @param array $foreign all Relations to foreign tables for a given table
1639 * or optionally a given column in a table
1640 * @param array $url_params array of url parameters
1642 * @return string $html_output
1644 function PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
1646 $html_output = '<div class="operations_half_width">'
1647 . '<fieldset>'
1648 . '<legend>' . __('Check referential integrity:') . '</legend>';
1650 $html_output .= '<ul>';
1652 foreach ($foreign as $master => $arr) {
1653 $join_query = 'SELECT '
1654 . Util::backquote($GLOBALS['table']) . '.*'
1655 . ' FROM ' . Util::backquote($GLOBALS['table'])
1656 . ' LEFT JOIN '
1657 . Util::backquote($arr['foreign_db'])
1658 . '.'
1659 . Util::backquote($arr['foreign_table']);
1660 if ($arr['foreign_table'] == $GLOBALS['table']) {
1661 $foreign_table = $GLOBALS['table'] . '1';
1662 $join_query .= ' AS ' . Util::backquote($foreign_table);
1663 } else {
1664 $foreign_table = $arr['foreign_table'];
1666 $join_query .= ' ON '
1667 . Util::backquote($GLOBALS['table']) . '.'
1668 . Util::backquote($master)
1669 . ' = '
1670 . Util::backquote($arr['foreign_db'])
1671 . '.'
1672 . Util::backquote($foreign_table) . '.'
1673 . Util::backquote($arr['foreign_field'])
1674 . ' WHERE '
1675 . Util::backquote($arr['foreign_db'])
1676 . '.'
1677 . Util::backquote($foreign_table) . '.'
1678 . Util::backquote($arr['foreign_field'])
1679 . ' IS NULL AND '
1680 . Util::backquote($GLOBALS['table']) . '.'
1681 . Util::backquote($master)
1682 . ' IS NOT NULL';
1683 $this_url_params = array_merge(
1684 $url_params,
1685 array('sql_query' => $join_query)
1688 $html_output .= '<li>'
1689 . '<a href="sql.php'
1690 . URL::getCommon($this_url_params)
1691 . '">'
1692 . $master . '&nbsp;->&nbsp;' . $arr['foreign_db'] . '.'
1693 . $arr['foreign_table'] . '.' . $arr['foreign_field']
1694 . '</a></li>' . "\n";
1695 } // foreach $foreign
1696 $html_output .= '</ul></fieldset></div>';
1698 return $html_output;
1702 * Reorder table based on request params
1704 * @return array SQL query and result
1706 function PMA_getQueryAndResultForReorderingTable()
1708 $sql_query = 'ALTER TABLE '
1709 . Util::backquote($GLOBALS['table'])
1710 . ' ORDER BY '
1711 . Util::backquote(urldecode($_REQUEST['order_field']));
1712 if (isset($_REQUEST['order_order'])
1713 && $_REQUEST['order_order'] === 'desc'
1715 $sql_query .= ' DESC';
1716 } else {
1717 $sql_query .= ' ASC';
1719 $sql_query .= ';';
1720 $result = $GLOBALS['dbi']->query($sql_query);
1722 return array($sql_query, $result);
1726 * Get table alters array
1728 * @param Table $pma_table The Table object
1729 * @param string $pack_keys pack keys
1730 * @param string $checksum value of checksum
1731 * @param string $page_checksum value of page checksum
1732 * @param string $delay_key_write delay key write
1733 * @param string $row_format row format
1734 * @param string $newTblStorageEngine table storage engine
1735 * @param string $transactional value of transactional
1736 * @param string $tbl_collation collation of the table
1738 * @return array $table_alters
1740 function PMA_getTableAltersArray($pma_table, $pack_keys,
1741 $checksum, $page_checksum, $delay_key_write,
1742 $row_format, $newTblStorageEngine, $transactional, $tbl_collation
1744 global $auto_increment;
1746 $table_alters = array();
1748 if (isset($_REQUEST['comment'])
1749 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']
1751 $table_alters[] = 'COMMENT = \''
1752 . $GLOBALS['dbi']->escapeString($_REQUEST['comment']) . '\'';
1755 if (! empty($newTblStorageEngine)
1756 && mb_strtolower($newTblStorageEngine) !== mb_strtolower($GLOBALS['tbl_storage_engine'])
1758 $table_alters[] = 'ENGINE = ' . $newTblStorageEngine;
1760 if (! empty($_REQUEST['tbl_collation'])
1761 && $_REQUEST['tbl_collation'] !== $tbl_collation
1763 $table_alters[] = 'DEFAULT '
1764 . Util::getCharsetQueryPart($_REQUEST['tbl_collation']);
1767 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'ISAM'))
1768 && isset($_REQUEST['new_pack_keys'])
1769 && $_REQUEST['new_pack_keys'] != (string)$pack_keys
1771 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
1774 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
1775 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))
1776 && $_REQUEST['new_checksum'] !== $checksum
1778 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
1781 $_REQUEST['new_transactional']
1782 = empty($_REQUEST['new_transactional']) ? '0' : '1';
1783 if ($pma_table->isEngine('ARIA')
1784 && $_REQUEST['new_transactional'] !== $transactional
1786 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
1789 $_REQUEST['new_page_checksum']
1790 = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
1791 if ($pma_table->isEngine('ARIA')
1792 && $_REQUEST['new_page_checksum'] !== $page_checksum
1794 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
1797 $_REQUEST['new_delay_key_write']
1798 = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
1799 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))
1800 && $_REQUEST['new_delay_key_write'] !== $delay_key_write
1802 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
1805 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1806 && ! empty($_REQUEST['new_auto_increment'])
1807 && (! isset($auto_increment)
1808 || $_REQUEST['new_auto_increment'] !== $auto_increment)
1810 $table_alters[] = 'auto_increment = '
1811 . $GLOBALS['dbi']->escapeString($_REQUEST['new_auto_increment']);
1814 if (! empty($_REQUEST['new_row_format'])) {
1815 $newRowFormat = $_REQUEST['new_row_format'];
1816 $newRowFormatLower = mb_strtolower($newRowFormat);
1817 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1818 && (strlen($row_format) === 0
1819 || $newRowFormatLower !== mb_strtolower($row_format))
1821 $table_alters[] = 'ROW_FORMAT = '
1822 . $GLOBALS['dbi']->escapeString($newRowFormat);
1826 return $table_alters;
1830 * Get warning messages array
1832 * @return array $warning_messages
1834 function PMA_getWarningMessagesArray()
1836 $warning_messages = array();
1837 foreach ($GLOBALS['dbi']->getWarnings() as $warning) {
1838 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
1839 // and if TRANSACTIONAL was set, the system reports an error;
1840 // I discussed with a Maria developer and he agrees that this
1841 // should not be reported with a Level of Error, so here
1842 // I just ignore it. But there are other 1478 messages
1843 // that it's better to show.
1844 if (! ($_REQUEST['new_tbl_storage_engine'] == 'MyISAM'
1845 && $warning['Code'] == '1478'
1846 && $warning['Level'] == 'Error')
1848 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
1849 . ' ' . $warning['Message'];
1852 return $warning_messages;
1856 * Get SQL query and result after ran this SQL query for a partition operation
1857 * has been requested by the user
1859 * @return array $sql_query, $result
1861 function PMA_getQueryAndResultForPartition()
1863 $sql_query = 'ALTER TABLE '
1864 . Util::backquote($GLOBALS['table']) . ' '
1865 . $_REQUEST['partition_operation']
1866 . ' PARTITION ';
1868 if ($_REQUEST['partition_operation'] == 'COALESCE') {
1869 $sql_query .= count($_REQUEST['partition_name']);
1870 } else {
1871 $sql_query .= implode(', ', $_REQUEST['partition_name']) . ';';
1874 $result = $GLOBALS['dbi']->query($sql_query);
1876 return array($sql_query, $result);
1880 * Adjust the privileges after renaming/moving a table
1882 * @param string $oldDb Database name before table renaming/moving table
1883 * @param string $oldTable Table name before table renaming/moving table
1884 * @param string $newDb Database name after table renaming/ moving table
1885 * @param string $newTable Table name after table renaming/moving table
1887 * @return void
1889 function PMA_AdjustPrivileges_renameOrMoveTable($oldDb, $oldTable, $newDb, $newTable)
1891 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1892 && $GLOBALS['is_reload_priv']
1894 $GLOBALS['dbi']->selectDb('mysql');
1896 // For table specific privileges
1897 $query_table_specific = 'UPDATE ' . Util::backquote('tables_priv')
1898 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newDb) . '\', Table_name = \'' . $GLOBALS['dbi']->escapeString($newTable)
1899 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\' AND Table_name = \'' . $GLOBALS['dbi']->escapeString($oldTable)
1900 . '\';';
1901 $GLOBALS['dbi']->query($query_table_specific);
1903 // For column specific privileges
1904 $query_col_specific = 'UPDATE ' . Util::backquote('columns_priv')
1905 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newDb) . '\', Table_name = \'' . $GLOBALS['dbi']->escapeString($newTable)
1906 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\' AND Table_name = \'' . $GLOBALS['dbi']->escapeString($oldTable)
1907 . '\';';
1908 $GLOBALS['dbi']->query($query_col_specific);
1910 // Finally FLUSH the new privileges
1911 $flush_query = "FLUSH PRIVILEGES;";
1912 $GLOBALS['dbi']->query($flush_query);
1917 * Adjust the privileges after copying a table
1919 * @param string $oldDb Database name before table copying
1920 * @param string $oldTable Table name before table copying
1921 * @param string $newDb Database name after table copying
1922 * @param string $newTable Table name after table copying
1924 * @return void
1926 function PMA_AdjustPrivileges_copyTable($oldDb, $oldTable, $newDb, $newTable)
1928 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1929 && $GLOBALS['is_reload_priv']
1931 $GLOBALS['dbi']->selectDb('mysql');
1933 // For Table Specific privileges
1934 $query_table_specific_old = 'SELECT * FROM '
1935 . Util::backquote('tables_priv') . ' where '
1936 . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";';
1938 $old_privs_table = $GLOBALS['dbi']->fetchResult(
1939 $query_table_specific_old,
1943 foreach ($old_privs_table as $old_priv) {
1944 $newDb_table_privs_query = 'INSERT INTO '
1945 . Util::backquote('tables_priv') . ' VALUES("'
1946 . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "'
1947 . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5]
1948 . '", "' . $old_priv[6] . '", "' . $old_priv[7] . '");';
1950 $GLOBALS['dbi']->query($newDb_table_privs_query);
1953 // For Column Specific privileges
1954 $query_col_specific_old = 'SELECT * FROM '
1955 . Util::backquote('columns_priv') . ' WHERE '
1956 . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";';
1958 $old_privs_col = $GLOBALS['dbi']->fetchResult(
1959 $query_col_specific_old,
1963 foreach ($old_privs_col as $old_priv) {
1964 $newDb_col_privs_query = 'INSERT INTO '
1965 . Util::backquote('columns_priv') . ' VALUES("'
1966 . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "'
1967 . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5]
1968 . '", "' . $old_priv[6] . '");';
1970 $GLOBALS['dbi']->query($newDb_col_privs_query);
1973 // Finally FLUSH the new privileges
1974 $flush_query = "FLUSH PRIVILEGES;";
1975 $GLOBALS['dbi']->query($flush_query);
1980 * Change all collations and character sets of all columns in table
1982 * @param string $db Database name
1983 * @param string $table Table name
1984 * @param string $tbl_collation Collation Name
1986 * @return void
1988 function PMA_changeAllColumnsCollation($db, $table, $tbl_collation)
1990 $GLOBALS['dbi']->selectDb($db);
1992 $change_all_collations_query = 'ALTER TABLE '
1993 . Util::backquote($table)
1994 . ' CONVERT TO';
1996 list($charset) = explode('_', $tbl_collation);
1998 $change_all_collations_query .= ' CHARACTER SET ' . $charset
1999 . ($charset == $tbl_collation ? '' : ' COLLATE ' . $tbl_collation);
2001 $GLOBALS['dbi']->query($change_all_collations_query);
2005 * Move or copy a table
2007 * @param string $db current database name
2008 * @param string $table current table name
2010 * @return void
2012 function PMA_moveOrCopyTable($db, $table)
2015 * Selects the database to work with
2017 $GLOBALS['dbi']->selectDb($db);
2020 * $_REQUEST['target_db'] could be empty in case we came from an input field
2021 * (when there are many databases, no drop-down)
2023 if (empty($_REQUEST['target_db'])) {
2024 $_REQUEST['target_db'] = $db;
2028 * A target table name has been sent to this script -> do the work
2030 if (Core::isValid($_REQUEST['new_name'])) {
2031 if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) {
2032 if (isset($_REQUEST['submit_move'])) {
2033 $message = Message::error(__('Can\'t move table to same one!'));
2034 } else {
2035 $message = Message::error(__('Can\'t copy table to same one!'));
2037 } else {
2038 Table::moveCopy(
2039 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'],
2040 $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table'
2043 if (isset($_REQUEST['adjust_privileges'])
2044 && ! empty($_REQUEST['adjust_privileges'])
2046 if (isset($_REQUEST['submit_move'])) {
2047 PMA_AdjustPrivileges_renameOrMoveTable(
2048 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']
2050 } else {
2051 PMA_AdjustPrivileges_copyTable(
2052 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']
2056 if (isset($_REQUEST['submit_move'])) {
2057 $message = Message::success(
2059 'Table %s has been moved to %s. Privileges have been '
2060 . 'adjusted.'
2063 } else {
2064 $message = Message::success(
2066 'Table %s has been copied to %s. Privileges have been '
2067 . 'adjusted.'
2072 } else {
2073 if (isset($_REQUEST['submit_move'])) {
2074 $message = Message::success(
2075 __('Table %s has been moved to %s.')
2077 } else {
2078 $message = Message::success(
2079 __('Table %s has been copied to %s.')
2084 $old = Util::backquote($db) . '.'
2085 . Util::backquote($table);
2086 $message->addParam($old);
2088 $new_name = $_REQUEST['new_name'];
2089 if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
2090 $new_name = strtolower($new_name);
2093 $new = Util::backquote($_REQUEST['target_db']) . '.'
2094 . Util::backquote($new_name);
2095 $message->addParam($new);
2097 /* Check: Work on new table or on old table? */
2098 if (isset($_REQUEST['submit_move'])
2099 || Core::isValid($_REQUEST['switch_to_new'])
2103 } else {
2105 * No new name for the table!
2107 $message = Message::error(__('The table name is empty!'));
2110 $response = Response::getInstance();
2111 if ($response->isAjax()) {
2112 $response->addJSON('message', $message);
2113 if ($message->isSuccess()) {
2114 $response->addJSON('db', $GLOBALS['db']);
2115 } else {
2116 $response->setRequestStatus(false);
2118 exit;