Translated using Weblate (Slovenian)
[phpmyadmin.git] / libraries / operations.lib.php
blobefdf6c1caba83828d504bb518730ea940bb02889
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="' . htmlspecialchars($db) . '"/>';
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="' . htmlspecialchars($db) . '" '
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 // lower_case_table_names=1 `DB` becomes `db`
357 if ($GLOBALS['dbi']->getLowerCaseNames() === '1') {
358 $_REQUEST['newname'] = mb_strtolower(
359 $_REQUEST['newname']
363 $local_query = 'CREATE DATABASE IF NOT EXISTS '
364 . Util::backquote($_REQUEST['newname']);
365 if (isset($_REQUEST['db_collation'])) {
366 $local_query .= ' DEFAULT'
367 . Util::getCharsetQueryPart($_REQUEST['db_collation']);
369 $local_query .= ';';
370 $GLOBALS['sql_query'] .= $local_query;
372 // save the original db name because Tracker.php which
373 // may be called under $GLOBALS['dbi']->query() changes $GLOBALS['db']
374 // for some statements, one of which being CREATE DATABASE
375 $original_db = $GLOBALS['db'];
376 $GLOBALS['dbi']->query($local_query);
377 $GLOBALS['db'] = $original_db;
379 // Set the SQL mode to NO_AUTO_VALUE_ON_ZERO to prevent MySQL from creating
380 // export statements it cannot import
381 $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'";
382 $GLOBALS['dbi']->query($sql_set_mode);
384 // rebuild the database list because Table::moveCopy
385 // checks in this list if the target db exists
386 $GLOBALS['dblist']->databases->build();
390 * Get views as an array and create SQL view stand-in
392 * @param array $tables_full array of all tables in given db or dbs
393 * @param ExportSql $export_sql_plugin export plugin instance
394 * @param string $db database name
396 * @return array $views
398 function PMA_getViewsAndCreateSqlViewStandIn(
399 $tables_full, $export_sql_plugin, $db
401 $views = array();
402 foreach ($tables_full as $each_table => $tmp) {
403 // to be able to rename a db containing views,
404 // first all the views are collected and a stand-in is created
405 // the real views are created after the tables
406 if ($GLOBALS['dbi']->getTable($db, $each_table)->isView()) {
408 // If view exists, and 'add drop view' is selected: Drop it!
409 if ($_REQUEST['what'] != 'nocopy'
410 && isset($_REQUEST['drop_if_exists'])
411 && $_REQUEST['drop_if_exists'] == 'true'
413 $drop_query = 'DROP VIEW IF EXISTS '
414 . Util::backquote($_REQUEST['newname']) . '.'
415 . Util::backquote($each_table);
416 $GLOBALS['dbi']->query($drop_query);
418 $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
421 $views[] = $each_table;
422 // Create stand-in definition to resolve view dependencies
423 $sql_view_standin = $export_sql_plugin->getTableDefStandIn(
424 $db, $each_table, "\n"
426 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
427 $GLOBALS['dbi']->query($sql_view_standin);
428 $GLOBALS['sql_query'] .= "\n" . $sql_view_standin;
431 return $views;
435 * Get sql query for copy/rename table and boolean for whether copy/rename or not
437 * @param array $tables_full array of all tables in given db or dbs
438 * @param boolean $move whether database name is empty or not
439 * @param string $db database name
441 * @return array SQL queries for the constraints
443 function PMA_copyTables($tables_full, $move, $db)
445 $sqlContraints = array();
446 foreach ($tables_full as $each_table => $tmp) {
447 // skip the views; we have created stand-in definitions
448 if ($GLOBALS['dbi']->getTable($db, $each_table)->isView()) {
449 continue;
452 // value of $what for this table only
453 $this_what = $_REQUEST['what'];
455 // do not copy the data from a Merge table
456 // note: on the calling FORM, 'data' means 'structure and data'
457 if ($GLOBALS['dbi']->getTable($db, $each_table)->isMerge()) {
458 if ($this_what == 'data') {
459 $this_what = 'structure';
461 if ($this_what == 'dataonly') {
462 $this_what = 'nocopy';
466 if ($this_what != 'nocopy') {
467 // keep the triggers from the original db+table
468 // (third param is empty because delimiters are only intended
469 // for importing via the mysql client or our Import feature)
470 $triggers = $GLOBALS['dbi']->getTriggers($db, $each_table, '');
472 if (! Table::moveCopy(
473 $db, $each_table, $_REQUEST['newname'], $each_table,
474 (isset($this_what) ? $this_what : 'data'),
475 $move, 'db_copy'
476 )) {
477 $GLOBALS['_error'] = true;
478 break;
480 // apply the triggers to the destination db+table
481 if ($triggers) {
482 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
483 foreach ($triggers as $trigger) {
484 $GLOBALS['dbi']->query($trigger['create']);
485 $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';';
489 // this does not apply to a rename operation
490 if (isset($_REQUEST['add_constraints'])
491 && ! empty($GLOBALS['sql_constraints_query'])
493 $sqlContraints[] = $GLOBALS['sql_constraints_query'];
494 unset($GLOBALS['sql_constraints_query']);
498 return $sqlContraints;
502 * Run the EVENT definition for selected database
504 * to avoid selecting alternatively the current and new db
505 * we would need to modify the CREATE definitions to qualify
506 * the db name
508 * @param string $db database name
510 * @return void
512 function PMA_runEventDefinitionsForDb($db)
514 $event_names = $GLOBALS['dbi']->fetchResult(
515 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \''
516 . $GLOBALS['dbi']->escapeString($db) . '\';'
518 if ($event_names) {
519 foreach ($event_names as $event_name) {
520 $GLOBALS['dbi']->selectDb($db);
521 $tmp_query = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $event_name);
522 // collect for later display
523 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
524 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
525 $GLOBALS['dbi']->query($tmp_query);
531 * Handle the views, return the boolean value whether table rename/copy or not
533 * @param array $views views as an array
534 * @param boolean $move whether database name is empty or not
535 * @param string $db database name
537 * @return void
539 function PMA_handleTheViews($views, $move, $db)
541 // temporarily force to add DROP IF EXIST to CREATE VIEW query,
542 // to remove stand-in VIEW that was created earlier
543 // ( $_REQUEST['drop_if_exists'] is used in moveCopy() )
544 if (isset($_REQUEST['drop_if_exists'])) {
545 $temp_drop_if_exists = $_REQUEST['drop_if_exists'];
548 $_REQUEST['drop_if_exists'] = 'true';
549 foreach ($views as $view) {
550 $copying_succeeded = Table::moveCopy(
551 $db, $view, $_REQUEST['newname'], $view, 'structure', $move, 'db_copy'
553 if (! $copying_succeeded) {
554 $GLOBALS['_error'] = true;
555 break;
558 unset($_REQUEST['drop_if_exists']);
560 if (isset($temp_drop_if_exists)) {
561 // restore previous value
562 $_REQUEST['drop_if_exists'] = $temp_drop_if_exists;
567 * Adjust the privileges after Renaming the db
569 * @param string $oldDb Database name before renaming
570 * @param string $newname New Database name requested
572 * @return void
574 function PMA_AdjustPrivileges_moveDB($oldDb, $newname)
576 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
577 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
578 && $GLOBALS['is_reload_priv']
580 $GLOBALS['dbi']->selectDb('mysql');
581 $newname = str_replace("_", "\_", $newname);
582 $oldDb = str_replace("_", "\_", $oldDb);
584 // For Db specific privileges
585 $query_db_specific = 'UPDATE ' . Util::backquote('db')
586 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
587 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
588 $GLOBALS['dbi']->query($query_db_specific);
590 // For table specific privileges
591 $query_table_specific = 'UPDATE ' . Util::backquote('tables_priv')
592 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
593 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
594 $GLOBALS['dbi']->query($query_table_specific);
596 // For column specific privileges
597 $query_col_specific = 'UPDATE ' . Util::backquote('columns_priv')
598 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
599 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
600 $GLOBALS['dbi']->query($query_col_specific);
602 // For procedures specific privileges
603 $query_proc_specific = 'UPDATE ' . Util::backquote('procs_priv')
604 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newname)
605 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\';';
606 $GLOBALS['dbi']->query($query_proc_specific);
608 // Finally FLUSH the new privileges
609 $flush_query = "FLUSH PRIVILEGES;";
610 $GLOBALS['dbi']->query($flush_query);
615 * Adjust the privileges after Copying the db
617 * @param string $oldDb Database name before copying
618 * @param string $newname New Database name requested
620 * @return void
622 function PMA_AdjustPrivileges_copyDB($oldDb, $newname)
624 if ($GLOBALS['db_priv'] && $GLOBALS['table_priv']
625 && $GLOBALS['col_priv'] && $GLOBALS['proc_priv']
626 && $GLOBALS['is_reload_priv']
628 $GLOBALS['dbi']->selectDb('mysql');
629 $newname = str_replace("_", "\_", $newname);
630 $oldDb = str_replace("_", "\_", $oldDb);
632 $query_db_specific_old = 'SELECT * FROM '
633 . Util::backquote('db') . ' WHERE '
634 . 'Db = "' . $oldDb . '";';
636 $old_privs_db = $GLOBALS['dbi']->fetchResult($query_db_specific_old, 0);
638 foreach ($old_privs_db as $old_priv) {
639 $newDb_db_privs_query = 'INSERT INTO ' . Util::backquote('db')
640 . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
641 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
642 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
643 . $old_priv[7] . '", "' . $old_priv[8] . '", "' . $old_priv[9]
644 . '", "' . $old_priv[10] . '", "' . $old_priv[11] . '", "'
645 . $old_priv[12] . '", "' . $old_priv[13] . '", "' . $old_priv[14]
646 . '", "' . $old_priv[15] . '", "' . $old_priv[16] . '", "'
647 . $old_priv[17] . '", "' . $old_priv[18] . '", "' . $old_priv[19]
648 . '", "' . $old_priv[20] . '", "' . $old_priv[21] . '");';
650 $GLOBALS['dbi']->query($newDb_db_privs_query);
653 // For Table Specific privileges
654 $query_table_specific_old = 'SELECT * FROM '
655 . Util::backquote('tables_priv') . ' WHERE '
656 . 'Db = "' . $oldDb . '";';
658 $old_privs_table = $GLOBALS['dbi']->fetchResult(
659 $query_table_specific_old,
663 foreach ($old_privs_table as $old_priv) {
664 $newDb_table_privs_query = 'INSERT INTO ' . Util::backquote(
665 'tables_priv'
666 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
667 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
668 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
669 . $old_priv[7] . '");';
671 $GLOBALS['dbi']->query($newDb_table_privs_query);
674 // For Column Specific privileges
675 $query_col_specific_old = 'SELECT * FROM '
676 . Util::backquote('columns_priv') . ' WHERE '
677 . 'Db = "' . $oldDb . '";';
679 $old_privs_col = $GLOBALS['dbi']->fetchResult(
680 $query_col_specific_old,
684 foreach ($old_privs_col as $old_priv) {
685 $newDb_col_privs_query = 'INSERT INTO ' . Util::backquote(
686 'columns_priv'
687 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
688 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
689 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '");';
691 $GLOBALS['dbi']->query($newDb_col_privs_query);
694 // For Procedure Specific privileges
695 $query_proc_specific_old = 'SELECT * FROM '
696 . Util::backquote('procs_priv') . ' WHERE '
697 . 'Db = "' . $oldDb . '";';
699 $old_privs_proc = $GLOBALS['dbi']->fetchResult(
700 $query_proc_specific_old,
704 foreach ($old_privs_proc as $old_priv) {
705 $newDb_proc_privs_query = 'INSERT INTO ' . Util::backquote(
706 'procs_priv'
707 ) . ' VALUES("' . $old_priv[0] . '", "' . $newname . '", "'
708 . $old_priv[2] . '", "' . $old_priv[3] . '", "' . $old_priv[4]
709 . '", "' . $old_priv[5] . '", "' . $old_priv[6] . '", "'
710 . $old_priv[7] . '");';
712 $GLOBALS['dbi']->query($newDb_proc_privs_query);
715 // Finally FLUSH the new privileges
716 $flush_query = "FLUSH PRIVILEGES;";
717 $GLOBALS['dbi']->query($flush_query);
722 * Create all accumulated constraints
724 * @param array $sqlConstratints array of sql constraints for the database
726 * @return void
728 function PMA_createAllAccumulatedConstraints($sqlConstratints)
730 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
731 foreach ($sqlConstratints as $one_query) {
732 $GLOBALS['dbi']->query($one_query);
733 // and prepare to display them
734 $GLOBALS['sql_query'] .= "\n" . $one_query;
739 * Duplicate the bookmarks for the db (done once for each db)
741 * @param boolean $_error whether table rename/copy or not
742 * @param string $db database name
744 * @return void
746 function PMA_duplicateBookmarks($_error, $db)
748 if (! $_error && $db != $_REQUEST['newname']) {
749 $get_fields = array('user', 'label', 'query');
750 $where_fields = array('dbase' => $db);
751 $new_fields = array('dbase' => $_REQUEST['newname']);
752 Table::duplicateInfo(
753 'bookmarkwork', 'bookmark', $get_fields,
754 $where_fields, $new_fields
760 * Get the HTML snippet for order the table
762 * @param array $columns columns array
764 * @return string $html_out
766 function PMA_getHtmlForOrderTheTable($columns)
768 $html_output = '<div class="operations_half_width">';
769 $html_output .= '<form method="post" id="alterTableOrderby" '
770 . 'action="tbl_operations.php">';
771 $html_output .= URL::getHiddenInputs(
772 $GLOBALS['db'], $GLOBALS['table']
774 $html_output .= '<fieldset id="fieldset_table_order">'
775 . '<legend>' . __('Alter table order by') . '</legend>'
776 . '<select name="order_field">';
778 foreach ($columns as $fieldname) {
779 $html_output .= '<option '
780 . 'value="' . htmlspecialchars($fieldname['Field']) . '">'
781 . htmlspecialchars($fieldname['Field']) . '</option>' . "\n";
783 $html_output .= '</select> ' . __('(singly)') . ' '
784 . '<br />'
785 . '<input id="order_order_asc" name="order_order"'
786 . ' type="radio" value="asc" checked="checked" />'
787 . '<label for="order_order_asc">' . __('Ascending') . '</label>'
788 . '<input id="order_order_desc" name="order_order"'
789 . ' type="radio" value="desc" />'
790 . '<label for="order_order_desc">' . __('Descending') . '</label>'
791 . '</fieldset>'
792 . '<fieldset class="tblFooters">'
793 . '<input type="hidden" name="submitorderby" value="1" />'
794 . '<input type="submit" value="' . __('Go') . '" />'
795 . '</fieldset>'
796 . '</form>'
797 . '</div>';
799 return $html_output;
803 * Get the HTML snippet for move table
805 * @return string $html_output
807 function PMA_getHtmlForMoveTable()
809 $html_output = '<div class="operations_half_width">';
810 $html_output .= '<form method="post" action="tbl_operations.php"'
811 . ' id="moveTableForm" class="ajax"'
812 . ' onsubmit="return emptyCheckTheField(this, \'new_name\')">'
813 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
815 $html_output .= '<input type="hidden" name="reload" value="1" />'
816 . '<input type="hidden" name="what" value="data" />'
817 . '<fieldset id="fieldset_table_rename">';
819 $html_output .= '<legend>' . __('Move table to (database<b>.</b>table)')
820 . '</legend>';
822 if (count($GLOBALS['dblist']->databases) > $GLOBALS['cfg']['MaxDbList']) {
823 $html_output .= '<input type="text" maxlength="100" size="30" '
824 . 'name="target_db" value="' . htmlspecialchars($GLOBALS['db'])
825 . '"/>';
826 } else {
827 $html_output .= '<select class="halfWidth" name="target_db">'
828 . $GLOBALS['dblist']->databases->getHtmlOptions(true, false)
829 . '</select>';
831 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
832 $html_output .= '<input class="halfWidth" type="text" size="20" name="new_name"'
833 . ' maxlength="64" required="required" '
834 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" /><br />';
836 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
837 // next value but users can decide if they want it or not for the operation
839 $html_output .= '<input type="checkbox" name="sql_auto_increment" '
840 . 'value="1" id="checkbox_auto_increment_mv" checked="checked" />'
841 . '<label for="checkbox_auto_increment_mv">'
842 . __('Add AUTO_INCREMENT value')
843 . '</label><br />';
845 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
846 && $GLOBALS['is_reload_priv']
848 $html_output .= '<input type="checkbox" name="adjust_privileges" '
849 . 'value="1" id="checkbox_privileges_tables_move" '
850 . 'checked="checked" />';
851 } else {
852 $html_output .= '<input type="checkbox" name="adjust_privileges" '
853 . 'value="1" id="checkbox_privileges_tables_move" title="' . __(
854 'You don\'t have sufficient privileges to perform this '
855 . 'operation; Please refer to the documentation for more details'
857 . '" disabled/>';
859 $html_output .= '<label for="checkbox_privileges_tables_move">'
860 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
861 . '</label><br />';
863 $html_output .= '</fieldset><fieldset class="tblFooters">'
864 . '<input type="submit" name="submit_move" value="' . __('Go') . '" />'
865 . '</fieldset>'
866 . '</form>'
867 . '</div>';
869 return $html_output;
873 * Get the HTML div for Table option
875 * @param Table $pma_table Table object
876 * @param string $comment Comment
877 * @param array $tbl_collation table collation
878 * @param string $tbl_storage_engine table storage engine
879 * @param string $pack_keys pack keys
880 * @param string $auto_increment value of auto increment
881 * @param string $delay_key_write delay key write
882 * @param string $transactional value of transactional
883 * @param string $page_checksum value of page checksum
884 * @param string $checksum the checksum
886 * @return string $html_output
888 function PMA_getTableOptionDiv($pma_table, $comment, $tbl_collation, $tbl_storage_engine,
889 $pack_keys, $auto_increment, $delay_key_write,
890 $transactional, $page_checksum, $checksum
892 $html_output = '<div class="operations_half_width clearfloat">';
893 $html_output .= '<form method="post" action="tbl_operations.php"';
894 $html_output .= ' id="tableOptionsForm" class="ajax">';
895 $html_output .= URL::getHiddenInputs(
896 $GLOBALS['db'], $GLOBALS['table']
898 $html_output .= '<input type="hidden" name="reload" value="1" />';
900 $html_output .= PMA_getTableOptionFieldset(
901 $pma_table, $comment, $tbl_collation,
902 $tbl_storage_engine, $pack_keys,
903 $delay_key_write, $auto_increment, $transactional, $page_checksum,
904 $checksum
907 $html_output .= '<fieldset class="tblFooters">'
908 . '<input type="hidden" name="submitoptions" value="1" />'
909 . '<input type="submit" value="' . __('Go') . '" />'
910 . '</fieldset>'
911 . '</form>'
912 . '</div>';
914 return $html_output;
918 * Get HTML for the rename table part of table options
920 * @return string $html_output
922 function PMA_getHtmlForRenameTable()
924 $html_output = '<tr><td class="vmiddle">' . __('Rename table to') . '</td>'
925 . '<td>'
926 . '<input type="text" size="20" name="new_name" maxlength="64" '
927 . 'value="' . htmlspecialchars($GLOBALS['table'])
928 . '" required="required" />'
929 . '</td></tr>'
930 . '<tr><td></td><td>';
932 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
933 && $GLOBALS['is_reload_priv']
935 $html_output .= '<input type="checkbox" name="adjust_privileges" '
936 . 'value="1" id="checkbox_privileges_table_options" '
937 . 'checked="checked" />';
938 } else {
939 $html_output .= '<input type="checkbox" name="adjust_privileges" '
940 . 'value="1" id="checkbox_privileges_table_options" title="' . __(
941 'You don\'t have sufficient privileges to perform this '
942 . 'operation; Please refer to the documentation for more details'
944 . '" disabled/>';
946 $html_output .= '<label for="checkbox_privileges_table_options">'
947 . __('Adjust privileges') . '&nbsp;'
948 . Util::showDocu('faq', 'faq6-39') . '</label>';
950 $html_output .= '</td></tr>';
951 return $html_output;
955 * Get HTML for the table comments part of table options
957 * @param string $current_value of the table comments
959 * @return string $html_output
961 function PMA_getHtmlForTableComments($current_value)
963 $commentLength = PMA_MYSQL_INT_VERSION >= 50503 ? 2048 : 60;
964 $html_output = '<tr><td class="vmiddle">' . __('Table comments') . '</td>'
965 . '<td><input type="text" name="comment" '
966 . 'maxlength="' . $commentLength . '" size="30"'
967 . 'value="' . htmlspecialchars($current_value) . '" />'
968 . '<input type="hidden" name="prev_comment" value="'
969 . htmlspecialchars($current_value) . '" />'
970 . '</td>'
971 . '</tr>';
973 return $html_output;
977 * Get HTML for the PACK KEYS part of table options
979 * @param string $current_value of the pack keys option
981 * @return string $html_output
983 function PMA_getHtmlForPackKeys($current_value)
985 $html_output = '<tr>'
986 . '<td class="vmiddle"><label for="new_pack_keys">PACK_KEYS</label></td>'
987 . '<td><select name="new_pack_keys" id="new_pack_keys">';
989 $html_output .= '<option value="DEFAULT"';
990 if ($current_value == 'DEFAULT') {
991 $html_output .= 'selected="selected"';
993 $html_output .= '>DEFAULT</option>
994 <option value="0"';
995 if ($current_value == '0') {
996 $html_output .= 'selected="selected"';
998 $html_output .= '>0</option>
999 <option value="1" ';
1000 if ($current_value == '1') {
1001 $html_output .= 'selected="selected"';
1003 $html_output .= '>1</option>'
1004 . '</select>'
1005 . '</td>'
1006 . '</tr>';
1008 return $html_output;
1012 * Get HTML fieldset for Table option, it contains HTML table for options
1014 * @param Table $pma_table Table object
1015 * @param string $comment Comment
1016 * @param array $tbl_collation table collation
1017 * @param string $tbl_storage_engine table storage engine
1018 * @param string $pack_keys pack keys
1019 * @param string $delay_key_write delay key write
1020 * @param string $auto_increment value of auto increment
1021 * @param string $transactional value of transactional
1022 * @param string $page_checksum value of page checksum
1023 * @param string $checksum the checksum
1025 * @return string $html_output
1027 function PMA_getTableOptionFieldset($pma_table, $comment, $tbl_collation,
1028 $tbl_storage_engine, $pack_keys,
1029 $delay_key_write, $auto_increment, $transactional,
1030 $page_checksum, $checksum
1032 $html_output = '<fieldset>'
1033 . '<legend>' . __('Table options') . '</legend>';
1035 $html_output .= '<table>';
1036 $html_output .= PMA_getHtmlForRenameTable();
1037 $html_output .= PMA_getHtmlForTableComments($comment);
1039 //Storage engine
1040 $html_output .= '<tr><td class="vmiddle">' . __('Storage Engine')
1041 . '&nbsp;' . Util::showMySQLDocu('Storage_engines')
1042 . '</td>'
1043 . '<td>'
1044 . StorageEngine::getHtmlSelect(
1045 'new_tbl_storage_engine', null, $tbl_storage_engine
1047 . '</td>'
1048 . '</tr>';
1050 //Table character set
1051 $html_output .= '<tr><td class="vmiddle">' . __('Collation') . '</td>'
1052 . '<td>'
1053 . Charsets::getCollationDropdownBox(
1054 'tbl_collation', null, $tbl_collation, false
1056 . '</td>'
1057 . '</tr>';
1059 // Change all Column collations
1060 $html_output .= '<tr><td></td><td>'
1061 . '<input type="checkbox" name="change_all_collations" value="1" '
1062 . 'id="checkbox_change_all_collations" />'
1063 . '<label for="checkbox_change_all_collations">'
1064 . __('Change all column collations')
1065 . '</label>'
1066 . '</td></tr>';
1068 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'ISAM'))) {
1069 $html_output .= PMA_getHtmlForPackKeys($pack_keys);
1070 } // end if (MYISAM|ISAM)
1072 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))) {
1073 $html_output .= PMA_getHtmlForTableRow(
1074 'new_checksum',
1075 'CHECKSUM',
1076 $checksum
1079 $html_output .= PMA_getHtmlForTableRow(
1080 'new_delay_key_write',
1081 'DELAY_KEY_WRITE',
1082 $delay_key_write
1084 } // end if (MYISAM)
1086 if ($pma_table->isEngine('ARIA')) {
1087 $html_output .= PMA_getHtmlForTableRow(
1088 'new_transactional',
1089 'TRANSACTIONAL',
1090 $transactional
1093 $html_output .= PMA_getHtmlForTableRow(
1094 'new_page_checksum',
1095 'PAGE_CHECKSUM',
1096 $page_checksum
1098 } // end if (ARIA)
1100 if (strlen($auto_increment) > 0
1101 && $pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1103 $html_output .= '<tr><td class="vmiddle">'
1104 . '<label for="auto_increment_opt">AUTO_INCREMENT</label></td>'
1105 . '<td><input type="number" name="new_auto_increment" '
1106 . 'id="auto_increment_opt"'
1107 . 'value="' . $auto_increment . '" /></td>'
1108 . '</tr> ';
1109 } // end if (MYISAM|INNODB)
1111 $possible_row_formats = PMA_getPossibleRowFormat();
1113 // for MYISAM there is also COMPRESSED but it can be set only by the
1114 // myisampack utility, so don't offer here the choice because if we
1115 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
1116 // does not return a warning
1117 // (if the table was compressed, it can be seen on the Structure page)
1119 if (isset($possible_row_formats[$tbl_storage_engine])) {
1120 $current_row_format
1121 = mb_strtoupper($GLOBALS['showtable']['Row_format']);
1122 $html_output .= '<tr><td class="vmiddle">'
1123 . '<label for="new_row_format">ROW_FORMAT</label></td>'
1124 . '<td>';
1125 $html_output .= Util::getDropdown(
1126 'new_row_format', $possible_row_formats[$tbl_storage_engine],
1127 $current_row_format, 'new_row_format'
1129 $html_output .= '</td></tr>';
1131 $html_output .= '</table>'
1132 . '</fieldset>';
1134 return $html_output;
1138 * Get the common HTML table row (tr) for new_checksum, new_delay_key_write,
1139 * new_transactional and new_page_checksum
1141 * @param string $attribute class, name and id attribute
1142 * @param string $label label value
1143 * @param string $val checksum, delay_key_write, transactional, page_checksum
1145 * @return string $html_output
1147 function PMA_getHtmlForTableRow($attribute, $label, $val)
1149 return '<tr>'
1150 . '<td class="vmiddle">'
1151 . '<label for="' . $attribute . '">' . $label . '</label>'
1152 . '</td>'
1153 . '<td>'
1154 . '<input type="checkbox" name="' . $attribute . '" id="' . $attribute . '"'
1155 . ' value="1"' . ((!empty($val) && $val == 1) ? ' checked="checked"' : '')
1156 . '/>'
1157 . '</td>'
1158 . '</tr>';
1162 * Get array of possible row formats
1164 * @return array $possible_row_formats
1166 function PMA_getPossibleRowFormat()
1168 // the outer array is for engines, the inner array contains the dropdown
1169 // option values as keys then the dropdown option labels
1171 $possible_row_formats = array(
1172 'ARCHIVE' => array(
1173 'COMPRESSED' => 'COMPRESSED',
1175 'ARIA' => array(
1176 'FIXED' => 'FIXED',
1177 'DYNAMIC' => 'DYNAMIC',
1178 'PAGE' => 'PAGE'
1180 'MARIA' => array(
1181 'FIXED' => 'FIXED',
1182 'DYNAMIC' => 'DYNAMIC',
1183 'PAGE' => 'PAGE'
1185 'MYISAM' => array(
1186 'FIXED' => 'FIXED',
1187 'DYNAMIC' => 'DYNAMIC'
1189 'PBXT' => array(
1190 'FIXED' => 'FIXED',
1191 'DYNAMIC' => 'DYNAMIC'
1193 'INNODB' => array(
1194 'COMPACT' => 'COMPACT',
1195 'REDUNDANT' => 'REDUNDANT'
1199 /** @var Innodb $innodbEnginePlugin */
1200 $innodbEnginePlugin = StorageEngine::getEngine('Innodb');
1201 $innodbPluginVersion = $innodbEnginePlugin->getInnodbPluginVersion();
1202 if (!empty($innodbPluginVersion)) {
1203 $innodb_file_format = $innodbEnginePlugin->getInnodbFileFormat();
1204 } else {
1205 $innodb_file_format = '';
1207 if ('Barracuda' == $innodb_file_format
1208 && $innodbEnginePlugin->supportsFilePerTable()
1210 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
1211 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
1214 return $possible_row_formats;
1218 * Get HTML div for copy table
1220 * @return string $html_output
1222 function PMA_getHtmlForCopytable()
1224 $html_output = '<div class="operations_half_width">';
1225 $html_output .= '<form method="post" action="tbl_operations.php" '
1226 . 'name="copyTable" '
1227 . 'id="copyTable" '
1228 . ' class="ajax" '
1229 . 'onsubmit="return emptyCheckTheField(this, \'new_name\')">'
1230 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1231 . '<input type="hidden" name="reload" value="1" />';
1233 $html_output .= '<fieldset>';
1234 $html_output .= '<legend>'
1235 . __('Copy table to (database<b>.</b>table)') . '</legend>';
1237 if (count($GLOBALS['dblist']->databases) > $GLOBALS['cfg']['MaxDbList']) {
1238 $html_output .= '<input class="halfWidth" type="text" maxlength="100" '
1239 . 'size="30" name="target_db" '
1240 . 'value="' . htmlspecialchars($GLOBALS['db']) . '"/>';
1241 } else {
1242 $html_output .= '<select class="halfWidth" name="target_db">'
1243 . $GLOBALS['dblist']->databases->getHtmlOptions(true, false)
1244 . '</select>';
1246 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
1247 $html_output .= '<input class="halfWidth" type="text" required="required" '
1248 . 'size="20" name="new_name" maxlength="64" '
1249 . 'value="' . htmlspecialchars($GLOBALS['table']) . '"/><br />';
1251 $choices = array(
1252 'structure' => __('Structure only'),
1253 'data' => __('Structure and data'),
1254 'dataonly' => __('Data only')
1257 $html_output .= Util::getRadioFields(
1258 'what', $choices, 'data', true
1260 $html_output .= '<br />';
1262 $html_output .= '<input type="checkbox" name="drop_if_exists" '
1263 . 'value="true" id="checkbox_drop" />'
1264 . '<label for="checkbox_drop">'
1265 . sprintf(__('Add %s'), 'DROP TABLE') . '</label><br />'
1266 . '<input type="checkbox" name="sql_auto_increment" '
1267 . 'value="1" id="checkbox_auto_increment_cp" />'
1268 . '<label for="checkbox_auto_increment_cp">'
1269 . __('Add AUTO_INCREMENT value') . '</label><br />';
1271 // display "Add constraints" choice only if there are
1272 // foreign keys
1273 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
1274 $html_output .= '<input type="checkbox" name="add_constraints" '
1275 . 'value="1" id="checkbox_constraints" checked="checked"/>';
1276 $html_output .= '<label for="checkbox_constraints">'
1277 . __('Add constraints') . '</label><br />';
1278 } // endif
1280 $html_output .= '<br />';
1282 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1283 && $GLOBALS['is_reload_priv']
1285 $html_output .= '<input type="checkbox" name="adjust_privileges" '
1286 . 'value="1" id="checkbox_adjust_privileges" checked="checked" />';
1287 } else {
1288 $html_output .= '<input type="checkbox" name="adjust_privileges" '
1289 . 'value="1" id="checkbox_adjust_privileges" title="' . __(
1290 'You don\'t have sufficient privileges to perform this '
1291 . 'operation; Please refer to the documentation for more details'
1293 . '" disabled/>';
1295 $html_output .= '<label for="checkbox_adjust_privileges">'
1296 . __('Adjust privileges') . Util::showDocu('faq', 'faq6-39')
1297 . '</label><br />';
1299 if (isset($_COOKIE['pma_switch_to_new'])
1300 && $_COOKIE['pma_switch_to_new'] == 'true'
1302 $pma_switch_to_new = 'true';
1305 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
1306 . 'id="checkbox_switch"'
1307 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
1308 ? ' checked="checked"'
1309 : '' . '/>');
1310 $html_output .= '<label for="checkbox_switch">'
1311 . __('Switch to copied table') . '</label>'
1312 . '</fieldset>';
1314 $html_output .= '<fieldset class="tblFooters">'
1315 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
1316 . '</fieldset>'
1317 . '</form>'
1318 . '</div>';
1320 return $html_output;
1324 * Get HTML snippet for table maintenance
1326 * @param Table $pma_table Table object
1327 * @param array $url_params array of URL parameters
1329 * @return string $html_output
1331 function PMA_getHtmlForTableMaintenance($pma_table, $url_params)
1333 $html_output = '<div class="operations_half_width">';
1334 $html_output .= '<fieldset>'
1335 . '<legend>' . __('Table maintenance') . '</legend>';
1336 $html_output .= '<ul id="tbl_maintenance">';
1338 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
1339 $html_output .= PMA_getListofMaintainActionLink($pma_table, $url_params);
1341 $html_output .= '</ul>'
1342 . '</fieldset>'
1343 . '</div>';
1345 return $html_output;
1349 * Get HTML 'li' having a link of maintain action
1351 * @param Table $pma_table Table object
1352 * @param array $url_params Array of URL parameters
1354 * @return string $html_output
1356 function PMA_getListofMaintainActionLink($pma_table, $url_params)
1358 $html_output = '';
1360 // analyze table
1361 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'BERKELEYDB'))) {
1362 $params = array(
1363 'sql_query' => 'ANALYZE TABLE '
1364 . Util::backquote($GLOBALS['table']),
1365 'table_maintenance' => 'Go',
1367 $html_output .= PMA_getMaintainActionlink(
1368 __('Analyze table'),
1369 $params,
1370 $url_params,
1371 'ANALYZE_TABLE'
1375 // check table
1376 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB'))) {
1377 $params = array(
1378 'sql_query' => 'CHECK TABLE '
1379 . Util::backquote($GLOBALS['table']),
1380 'table_maintenance' => 'Go',
1382 $html_output .= PMA_getMaintainActionlink(
1383 __('Check table'),
1384 $params,
1385 $url_params,
1386 'CHECK_TABLE'
1390 // checksum table
1391 $params = array(
1392 'sql_query' => 'CHECKSUM TABLE '
1393 . Util::backquote($GLOBALS['table']),
1394 'table_maintenance' => 'Go',
1396 $html_output .= PMA_getMaintainActionlink(
1397 __('Checksum table'),
1398 $params,
1399 $url_params,
1400 'CHECKSUM_TABLE'
1403 // defragment table
1404 if ($pma_table->isEngine(array('INNODB'))) {
1405 $params = array(
1406 'sql_query' => 'ALTER TABLE '
1407 . Util::backquote($GLOBALS['table'])
1408 . ' ENGINE = InnoDB;'
1410 $html_output .= PMA_getMaintainActionlink(
1411 __('Defragment table'),
1412 $params,
1413 $url_params,
1414 'InnoDB_File_Defragmenting'
1418 // flush table
1419 $params = array(
1420 'sql_query' => 'FLUSH TABLE '
1421 . Util::backquote($GLOBALS['table']),
1422 'message_to_show' => sprintf(
1423 __('Table %s has been flushed.'),
1424 htmlspecialchars($GLOBALS['table'])
1426 'reload' => 1,
1428 $html_output .= PMA_getMaintainActionlink(
1429 __('Flush the table (FLUSH)'),
1430 $params,
1431 $url_params,
1432 'FLUSH'
1435 // optimize table
1436 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'BERKELEYDB'))) {
1437 $params = array(
1438 'sql_query' => 'OPTIMIZE TABLE '
1439 . Util::backquote($GLOBALS['table']),
1440 'table_maintenance' => 'Go',
1442 $html_output .= PMA_getMaintainActionlink(
1443 __('Optimize table'),
1444 $params,
1445 $url_params,
1446 'OPTIMIZE_TABLE'
1450 // repair table
1451 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))) {
1452 $params = array(
1453 'sql_query' => 'REPAIR TABLE '
1454 . Util::backquote($GLOBALS['table']),
1455 'table_maintenance' => 'Go',
1457 $html_output .= PMA_getMaintainActionlink(
1458 __('Repair table'),
1459 $params,
1460 $url_params,
1461 'REPAIR_TABLE'
1465 return $html_output;
1469 * Get maintain action HTML link
1471 * @param string $action_message action message
1472 * @param array $params url parameters array
1473 * @param array $url_params additional url parameters
1474 * @param string $link contains name of page/anchor that is being linked
1476 * @return string $html_output
1478 function PMA_getMaintainActionlink($action_message, $params, $url_params, $link)
1480 return '<li>'
1481 . '<a class="maintain_action ajax" '
1482 . 'href="sql.php'
1483 . URL::getCommon(array_merge($url_params, $params)) . '">'
1484 . $action_message
1485 . '</a>'
1486 . Util::showMySQLDocu($link)
1487 . '</li>';
1491 * Get HTML for Delete data or table (truncate table, drop table)
1493 * @param array $truncate_table_url_params url parameter array for truncate table
1494 * @param array $dropTableUrlParams url parameter array for drop table
1496 * @return string $html_output
1498 function PMA_getHtmlForDeleteDataOrTable(
1499 $truncate_table_url_params,
1500 $dropTableUrlParams
1502 $html_output = '<div class="operations_half_width">'
1503 . '<fieldset class="caution">'
1504 . '<legend>' . __('Delete data or table') . '</legend>';
1506 $html_output .= '<ul>';
1508 if (! empty($truncate_table_url_params)) {
1509 $html_output .= PMA_getDeleteDataOrTablelink(
1510 $truncate_table_url_params,
1511 'TRUNCATE_TABLE',
1512 __('Empty the table (TRUNCATE)'),
1513 'truncate_tbl_anchor'
1516 if (!empty($dropTableUrlParams)) {
1517 $html_output .= PMA_getDeleteDataOrTablelink(
1518 $dropTableUrlParams,
1519 'DROP_TABLE',
1520 __('Delete the table (DROP)'),
1521 'drop_tbl_anchor'
1524 $html_output .= '</ul></fieldset></div>';
1526 return $html_output;
1530 * Get the HTML link for Truncate table, Drop table and Drop db
1532 * @param array $url_params url parameter array for delete data or table
1533 * @param string $syntax TRUNCATE_TABLE or DROP_TABLE or DROP_DATABASE
1534 * @param string $link link to be shown
1535 * @param string $htmlId id of the link
1537 * @return String html output
1539 function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $htmlId)
1541 return '<li><a '
1542 . 'href="sql.php' . URL::getCommon($url_params) . '"'
1543 . ' id="' . $htmlId . '" class="ajax">'
1544 . $link . '</a>'
1545 . Util::showMySQLDocu($syntax)
1546 . '</li>';
1550 * Get HTML snippet for partition maintenance
1552 * @param array $partition_names array of partition names for a specific db/table
1553 * @param array $url_params url parameters
1555 * @return string $html_output
1557 function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
1559 $choices = array(
1560 'ANALYZE' => __('Analyze'),
1561 'CHECK' => __('Check'),
1562 'OPTIMIZE' => __('Optimize'),
1563 'REBUILD' => __('Rebuild'),
1564 'REPAIR' => __('Repair'),
1565 'TRUNCATE' => __('Truncate')
1568 $partition_method = Partition::getPartitionMethod(
1569 $GLOBALS['db'], $GLOBALS['table']
1571 // add COALESCE or DROP option to choices array depeding on Partition method
1572 if ($partition_method == 'RANGE'
1573 || $partition_method == 'RANGE COLUMNS'
1574 || $partition_method == 'LIST'
1575 || $partition_method == 'LIST COLUMNS'
1577 $choices['DROP'] = __('Drop');
1578 } else {
1579 $choices['COALESCE'] = __('Coalesce');
1582 $html_output = '<div class="operations_half_width">'
1583 . '<form id="partitionsForm" class="ajax" '
1584 . 'method="post" action="tbl_operations.php" >'
1585 . URL::getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1586 . '<fieldset>'
1587 . '<legend>'
1588 . __('Partition maintenance')
1589 . Util::showMySQLDocu('partitioning_maintenance')
1590 . '</legend>';
1592 $html_select = '<select id="partition_name" name="partition_name[]"'
1593 . ' multiple="multiple" required="required">' . "\n";
1594 $first = true;
1595 foreach ($partition_names as $one_partition) {
1596 $one_partition = htmlspecialchars($one_partition);
1597 $html_select .= '<option value="' . $one_partition . '"';
1598 if ($first) {
1599 $html_select .= ' selected="selected"';
1600 $first = false;
1602 $html_select .= '>' . $one_partition . '</option>' . "\n";
1604 $html_select .= '</select>' . "\n";
1605 $html_output .= sprintf(__('Partition %s'), $html_select);
1607 $html_output .= '<div class="clearfloat" />';
1608 $html_output .= Util::getRadioFields(
1609 'partition_operation', $choices, 'ANALYZE', false, true, 'floatleft'
1611 $this_url_params = array_merge(
1612 $url_params,
1613 array(
1614 'sql_query' => 'ALTER TABLE '
1615 . Util::backquote($GLOBALS['table'])
1616 . ' REMOVE PARTITIONING;'
1619 $html_output .= '<div class="clearfloat" /><br />';
1621 $html_output .= '<a href="sql.php'
1622 . URL::getCommon($this_url_params) . '">'
1623 . __('Remove partitioning') . '</a>';
1625 $html_output .= '</fieldset>'
1626 . '<fieldset class="tblFooters">'
1627 . '<input type="hidden" name="submit_partition" value="1">'
1628 . '<input type="submit" value="' . __('Go') . '" />'
1629 . '</fieldset>'
1630 . '</form>'
1631 . '</div>';
1633 return $html_output;
1637 * Get the HTML for Referential Integrity check
1639 * @param array $foreign all Relations to foreign tables for a given table
1640 * or optionally a given column in a table
1641 * @param array $url_params array of url parameters
1643 * @return string $html_output
1645 function PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
1647 $html_output = '<div class="operations_half_width">'
1648 . '<fieldset>'
1649 . '<legend>' . __('Check referential integrity:') . '</legend>';
1651 $html_output .= '<ul>';
1653 foreach ($foreign as $master => $arr) {
1654 $join_query = 'SELECT '
1655 . Util::backquote($GLOBALS['table']) . '.*'
1656 . ' FROM ' . Util::backquote($GLOBALS['table'])
1657 . ' LEFT JOIN '
1658 . Util::backquote($arr['foreign_db'])
1659 . '.'
1660 . Util::backquote($arr['foreign_table']);
1661 if ($arr['foreign_table'] == $GLOBALS['table']) {
1662 $foreign_table = $GLOBALS['table'] . '1';
1663 $join_query .= ' AS ' . Util::backquote($foreign_table);
1664 } else {
1665 $foreign_table = $arr['foreign_table'];
1667 $join_query .= ' ON '
1668 . Util::backquote($GLOBALS['table']) . '.'
1669 . Util::backquote($master)
1670 . ' = '
1671 . Util::backquote($arr['foreign_db'])
1672 . '.'
1673 . Util::backquote($foreign_table) . '.'
1674 . Util::backquote($arr['foreign_field'])
1675 . ' WHERE '
1676 . Util::backquote($arr['foreign_db'])
1677 . '.'
1678 . Util::backquote($foreign_table) . '.'
1679 . Util::backquote($arr['foreign_field'])
1680 . ' IS NULL AND '
1681 . Util::backquote($GLOBALS['table']) . '.'
1682 . Util::backquote($master)
1683 . ' IS NOT NULL';
1684 $this_url_params = array_merge(
1685 $url_params,
1686 array('sql_query' => $join_query)
1689 $html_output .= '<li>'
1690 . '<a href="sql.php'
1691 . URL::getCommon($this_url_params)
1692 . '">'
1693 . $master . '&nbsp;->&nbsp;' . $arr['foreign_db'] . '.'
1694 . $arr['foreign_table'] . '.' . $arr['foreign_field']
1695 . '</a></li>' . "\n";
1696 } // foreach $foreign
1697 $html_output .= '</ul></fieldset></div>';
1699 return $html_output;
1703 * Reorder table based on request params
1705 * @return array SQL query and result
1707 function PMA_getQueryAndResultForReorderingTable()
1709 $sql_query = 'ALTER TABLE '
1710 . Util::backquote($GLOBALS['table'])
1711 . ' ORDER BY '
1712 . Util::backquote(urldecode($_REQUEST['order_field']));
1713 if (isset($_REQUEST['order_order'])
1714 && $_REQUEST['order_order'] === 'desc'
1716 $sql_query .= ' DESC';
1718 $sql_query .= ';';
1719 $result = $GLOBALS['dbi']->query($sql_query);
1721 return array($sql_query, $result);
1725 * Get table alters array
1727 * @param Table $pma_table The Table object
1728 * @param string $pack_keys pack keys
1729 * @param string $checksum value of checksum
1730 * @param string $page_checksum value of page checksum
1731 * @param string $delay_key_write delay key write
1732 * @param string $row_format row format
1733 * @param string $newTblStorageEngine table storage engine
1734 * @param string $transactional value of transactional
1735 * @param string $tbl_collation collation of the table
1737 * @return array $table_alters
1739 function PMA_getTableAltersArray($pma_table, $pack_keys,
1740 $checksum, $page_checksum, $delay_key_write,
1741 $row_format, $newTblStorageEngine, $transactional, $tbl_collation
1743 global $auto_increment;
1745 $table_alters = array();
1747 if (isset($_REQUEST['comment'])
1748 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']
1750 $table_alters[] = 'COMMENT = \''
1751 . $GLOBALS['dbi']->escapeString($_REQUEST['comment']) . '\'';
1754 if (! empty($newTblStorageEngine)
1755 && mb_strtolower($newTblStorageEngine) !== mb_strtolower($GLOBALS['tbl_storage_engine'])
1757 $table_alters[] = 'ENGINE = ' . $newTblStorageEngine;
1759 if (! empty($_REQUEST['tbl_collation'])
1760 && $_REQUEST['tbl_collation'] !== $tbl_collation
1762 $table_alters[] = 'DEFAULT '
1763 . Util::getCharsetQueryPart($_REQUEST['tbl_collation']);
1766 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'ISAM'))
1767 && isset($_REQUEST['new_pack_keys'])
1768 && $_REQUEST['new_pack_keys'] != (string)$pack_keys
1770 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
1773 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
1774 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))
1775 && $_REQUEST['new_checksum'] !== $checksum
1777 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
1780 $_REQUEST['new_transactional']
1781 = empty($_REQUEST['new_transactional']) ? '0' : '1';
1782 if ($pma_table->isEngine('ARIA')
1783 && $_REQUEST['new_transactional'] !== $transactional
1785 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
1788 $_REQUEST['new_page_checksum']
1789 = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
1790 if ($pma_table->isEngine('ARIA')
1791 && $_REQUEST['new_page_checksum'] !== $page_checksum
1793 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
1796 $_REQUEST['new_delay_key_write']
1797 = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
1798 if ($pma_table->isEngine(array('MYISAM', 'ARIA'))
1799 && $_REQUEST['new_delay_key_write'] !== $delay_key_write
1801 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
1804 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1805 && ! empty($_REQUEST['new_auto_increment'])
1806 && (! isset($auto_increment)
1807 || $_REQUEST['new_auto_increment'] !== $auto_increment)
1809 $table_alters[] = 'auto_increment = '
1810 . $GLOBALS['dbi']->escapeString($_REQUEST['new_auto_increment']);
1813 if (! empty($_REQUEST['new_row_format'])) {
1814 $newRowFormat = $_REQUEST['new_row_format'];
1815 $newRowFormatLower = mb_strtolower($newRowFormat);
1816 if ($pma_table->isEngine(array('MYISAM', 'ARIA', 'INNODB', 'PBXT'))
1817 && (strlen($row_format) === 0
1818 || $newRowFormatLower !== mb_strtolower($row_format))
1820 $table_alters[] = 'ROW_FORMAT = '
1821 . $GLOBALS['dbi']->escapeString($newRowFormat);
1825 return $table_alters;
1829 * Get warning messages array
1831 * @return array $warning_messages
1833 function PMA_getWarningMessagesArray()
1835 $warning_messages = array();
1836 foreach ($GLOBALS['dbi']->getWarnings() as $warning) {
1837 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
1838 // and if TRANSACTIONAL was set, the system reports an error;
1839 // I discussed with a Maria developer and he agrees that this
1840 // should not be reported with a Level of Error, so here
1841 // I just ignore it. But there are other 1478 messages
1842 // that it's better to show.
1843 if (! ($_REQUEST['new_tbl_storage_engine'] == 'MyISAM'
1844 && $warning['Code'] == '1478'
1845 && $warning['Level'] == 'Error')
1847 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
1848 . ' ' . $warning['Message'];
1851 return $warning_messages;
1855 * Get SQL query and result after ran this SQL query for a partition operation
1856 * has been requested by the user
1858 * @return array $sql_query, $result
1860 function PMA_getQueryAndResultForPartition()
1862 $sql_query = 'ALTER TABLE '
1863 . Util::backquote($GLOBALS['table']) . ' '
1864 . $_REQUEST['partition_operation']
1865 . ' PARTITION ';
1867 if ($_REQUEST['partition_operation'] == 'COALESCE') {
1868 $sql_query .= count($_REQUEST['partition_name']);
1869 } else {
1870 $sql_query .= implode(', ', $_REQUEST['partition_name']) . ';';
1873 $result = $GLOBALS['dbi']->query($sql_query);
1875 return array($sql_query, $result);
1879 * Adjust the privileges after renaming/moving a table
1881 * @param string $oldDb Database name before table renaming/moving table
1882 * @param string $oldTable Table name before table renaming/moving table
1883 * @param string $newDb Database name after table renaming/ moving table
1884 * @param string $newTable Table name after table renaming/moving table
1886 * @return void
1888 function PMA_AdjustPrivileges_renameOrMoveTable($oldDb, $oldTable, $newDb, $newTable)
1890 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1891 && $GLOBALS['is_reload_priv']
1893 $GLOBALS['dbi']->selectDb('mysql');
1895 // For table specific privileges
1896 $query_table_specific = 'UPDATE ' . Util::backquote('tables_priv')
1897 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newDb) . '\', Table_name = \'' . $GLOBALS['dbi']->escapeString($newTable)
1898 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\' AND Table_name = \'' . $GLOBALS['dbi']->escapeString($oldTable)
1899 . '\';';
1900 $GLOBALS['dbi']->query($query_table_specific);
1902 // For column specific privileges
1903 $query_col_specific = 'UPDATE ' . Util::backquote('columns_priv')
1904 . 'SET Db = \'' . $GLOBALS['dbi']->escapeString($newDb) . '\', Table_name = \'' . $GLOBALS['dbi']->escapeString($newTable)
1905 . '\' where Db = \'' . $GLOBALS['dbi']->escapeString($oldDb) . '\' AND Table_name = \'' . $GLOBALS['dbi']->escapeString($oldTable)
1906 . '\';';
1907 $GLOBALS['dbi']->query($query_col_specific);
1909 // Finally FLUSH the new privileges
1910 $flush_query = "FLUSH PRIVILEGES;";
1911 $GLOBALS['dbi']->query($flush_query);
1916 * Adjust the privileges after copying a table
1918 * @param string $oldDb Database name before table copying
1919 * @param string $oldTable Table name before table copying
1920 * @param string $newDb Database name after table copying
1921 * @param string $newTable Table name after table copying
1923 * @return void
1925 function PMA_AdjustPrivileges_copyTable($oldDb, $oldTable, $newDb, $newTable)
1927 if ($GLOBALS['table_priv'] && $GLOBALS['col_priv']
1928 && $GLOBALS['is_reload_priv']
1930 $GLOBALS['dbi']->selectDb('mysql');
1932 // For Table Specific privileges
1933 $query_table_specific_old = 'SELECT * FROM '
1934 . Util::backquote('tables_priv') . ' where '
1935 . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";';
1937 $old_privs_table = $GLOBALS['dbi']->fetchResult(
1938 $query_table_specific_old,
1942 foreach ($old_privs_table as $old_priv) {
1943 $newDb_table_privs_query = 'INSERT INTO '
1944 . Util::backquote('tables_priv') . ' VALUES("'
1945 . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "'
1946 . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5]
1947 . '", "' . $old_priv[6] . '", "' . $old_priv[7] . '");';
1949 $GLOBALS['dbi']->query($newDb_table_privs_query);
1952 // For Column Specific privileges
1953 $query_col_specific_old = 'SELECT * FROM '
1954 . Util::backquote('columns_priv') . ' WHERE '
1955 . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";';
1957 $old_privs_col = $GLOBALS['dbi']->fetchResult(
1958 $query_col_specific_old,
1962 foreach ($old_privs_col as $old_priv) {
1963 $newDb_col_privs_query = 'INSERT INTO '
1964 . Util::backquote('columns_priv') . ' VALUES("'
1965 . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "'
1966 . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5]
1967 . '", "' . $old_priv[6] . '");';
1969 $GLOBALS['dbi']->query($newDb_col_privs_query);
1972 // Finally FLUSH the new privileges
1973 $flush_query = "FLUSH PRIVILEGES;";
1974 $GLOBALS['dbi']->query($flush_query);
1979 * Change all collations and character sets of all columns in table
1981 * @param string $db Database name
1982 * @param string $table Table name
1983 * @param string $tbl_collation Collation Name
1985 * @return void
1987 function PMA_changeAllColumnsCollation($db, $table, $tbl_collation)
1989 $GLOBALS['dbi']->selectDb($db);
1991 $change_all_collations_query = 'ALTER TABLE '
1992 . Util::backquote($table)
1993 . ' CONVERT TO';
1995 list($charset) = explode('_', $tbl_collation);
1997 $change_all_collations_query .= ' CHARACTER SET ' . $charset
1998 . ($charset == $tbl_collation ? '' : ' COLLATE ' . $tbl_collation);
2000 $GLOBALS['dbi']->query($change_all_collations_query);
2004 * Move or copy a table
2006 * @param string $db current database name
2007 * @param string $table current table name
2009 * @return void
2011 function PMA_moveOrCopyTable($db, $table)
2014 * Selects the database to work with
2016 $GLOBALS['dbi']->selectDb($db);
2019 * $_REQUEST['target_db'] could be empty in case we came from an input field
2020 * (when there are many databases, no drop-down)
2022 if (empty($_REQUEST['target_db'])) {
2023 $_REQUEST['target_db'] = $db;
2027 * A target table name has been sent to this script -> do the work
2029 if (PMA_isValid($_REQUEST['new_name'])) {
2030 if ($db == $_REQUEST['target_db'] && $table == $_REQUEST['new_name']) {
2031 if (isset($_REQUEST['submit_move'])) {
2032 $message = Message::error(__('Can\'t move table to same one!'));
2033 } else {
2034 $message = Message::error(__('Can\'t copy table to same one!'));
2036 } else {
2037 Table::moveCopy(
2038 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name'],
2039 $_REQUEST['what'], isset($_REQUEST['submit_move']), 'one_table'
2042 if (isset($_REQUEST['adjust_privileges'])
2043 && ! empty($_REQUEST['adjust_privileges'])
2045 if (isset($_REQUEST['submit_move'])) {
2046 PMA_AdjustPrivileges_renameOrMoveTable(
2047 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']
2049 } else {
2050 PMA_AdjustPrivileges_copyTable(
2051 $db, $table, $_REQUEST['target_db'], $_REQUEST['new_name']
2055 if (isset($_REQUEST['submit_move'])) {
2056 $message = Message::success(
2058 'Table %s has been moved to %s. Privileges have been '
2059 . 'adjusted.'
2062 } else {
2063 $message = Message::success(
2065 'Table %s has been copied to %s. Privileges have been '
2066 . 'adjusted.'
2071 } else {
2072 if (isset($_REQUEST['submit_move'])) {
2073 $message = Message::success(
2074 __('Table %s has been moved to %s.')
2076 } else {
2077 $message = Message::success(
2078 __('Table %s has been copied to %s.')
2083 $old = Util::backquote($db) . '.'
2084 . Util::backquote($table);
2085 $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 || PMA_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;