Translated using Weblate (Polish)
[phpmyadmin.git] / libraries / operations.lib.php
blobc570b616905dc1ca4468bbf8bede8650614ff66c
1 <?php
3 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 /**
5 * set of functions with the operations section in pma
7 * @package PhpMyAdmin
8 */
10 if (! defined('PHPMYADMIN')) {
11 exit;
14 /**
15 * Get HTML output for database comment
17 * @param string $db database name
19 * @return string $html_output
21 function PMA_getHtmlForDatabaseComment($db)
23 $html_output = '<div class="operations_half_width">'
24 . '<form method="post" action="db_operations.php">'
25 . PMA_URL_getHiddenInputs($db)
26 . '<fieldset>'
27 . '<legend>';
28 if (PMA_Util::showIcons('ActionLinksMode')) {
29 $html_output .= '<img class="icon ic_b_comment" '
30 . 'src="themes/dot.gif" alt="" />';
32 $html_output .= __('Database comment: ');
33 $html_output .= '</legend>';
34 $html_output .= '<input type="text" name="comment" '
35 . 'class="textfield" size="30"'
36 . 'value="' . htmlspecialchars(PMA_getDBComment($db)) . '" />'
37 . '</fieldset>';
38 $html_output .= '<fieldset class="tblFooters">'
39 . '<input type="submit" value="' . __('Go') . '" />'
40 . '</fieldset>'
41 . '</form>'
42 . '</div>';
44 return $html_output;
47 /**
48 * Get HTML output for rename database
50 * @param string $db database name
52 * @return string $html_output
54 function PMA_getHtmlForRenameDatabase($db)
56 $html_output = '<div class="operations_half_width">'
57 . '<form id="rename_db_form" '
58 . 'class="ajax" '
59 . 'method="post" action="db_operations.php" '
60 . 'onsubmit="return emptyFormElements(this, \'newname\')">';
61 if (isset($_REQUEST['db_collation'])) {
62 $html_output .= '<input type="hidden" name="db_collation" '
63 . 'value="' . $_REQUEST['db_collation']
64 .'" />' . "\n";
66 $html_output .= '<input type="hidden" name="what" value="data" />'
67 . '<input type="hidden" name="db_rename" value="true" />'
68 . PMA_URL_getHiddenInputs($db)
69 . '<fieldset>'
70 . '<legend>';
72 if (PMA_Util::showIcons('ActionLinksMode')) {
73 $html_output .= PMA_Util::getImage('b_edit.png');
75 $html_output .= __('Rename database to:')
76 . '</legend>';
78 $html_output .= '<input id="new_db_name" type="text" name="newname" '
79 . 'size="30" class="textfield" value="" />'
80 . '</fieldset>'
81 . '<fieldset class="tblFooters">'
82 . '<input id="rename_db_input" type="submit" value="' . __('Go') . '" />'
83 . '</fieldset>'
84 . '</form>'
85 . '</div>';
87 return $html_output;
90 /**
91 * Get HTML for database drop link
93 * @param string $db database name
95 * @return string $html_output
97 function PMA_getHtmlForDropDatabaseLink($db)
99 $this_sql_query = 'DROP DATABASE ' . PMA_Util::backquote($db);
100 $this_url_params = array(
101 'sql_query' => $this_sql_query,
102 'back' => 'db_operations.php',
103 'goto' => 'index.php',
104 'reload' => '1',
105 'purge' => '1',
106 'message_to_show' => sprintf(
107 __('Database %s has been dropped.'),
108 htmlspecialchars(PMA_Util::backquote($db))
110 'db' => null,
113 $html_output = '<div class="operations_half_width">'
114 . '<fieldset class="caution">';
115 $html_output .= '<legend>';
116 if (PMA_Util::showIcons('ActionLinksMode')) {
117 $html_output .= PMA_Util::getImage('b_deltbl.png');
119 $html_output .= __('Remove database')
120 . '</legend>';
121 $html_output .= '<ul>';
122 $html_output .= PMA_getDeleteDataOrTablelink(
123 $this_url_params,
124 'DROP_DATABASE',
125 __('Drop the database (DROP)'),
126 'drop_db_anchor'
128 $html_output .= '</ul></fieldset>'
129 . '</div>';
131 return $html_output;
135 * Get HTML snippet for copy database
137 * @param string $db database name
139 * @return string $html_output
141 function PMA_getHtmlForCopyDatabase($db)
143 $drop_clause = 'DROP TABLE / DROP VIEW';
144 $choices = array(
145 'structure' => __('Structure only'),
146 'data' => __('Structure and data'),
147 'dataonly' => __('Data only')
150 if (isset($_COOKIE)
151 && isset($_COOKIE['pma_switch_to_new'])
152 && $_COOKIE['pma_switch_to_new'] == 'true'
154 $pma_switch_to_new = 'true';
157 $html_output = '<div class="operations_half_width clearfloat">';
158 $html_output .= '<form id="copy_db_form" '
159 . 'class="ajax" '
160 . 'method="post" action="db_operations.php"'
161 . 'onsubmit="return emptyFormElements(this, \'newname\')">';
163 if (isset($_REQUEST['db_collation'])) {
164 $html_output .= '<input type="hidden" name="db_collation" '
165 . 'value="' . $_REQUEST['db_collation'] .'" />' . "\n";
167 $html_output .= '<input type="hidden" name="db_copy" value="true" />' . "\n"
168 . PMA_URL_getHiddenInputs($db);
169 $html_output .= '<fieldset>'
170 . '<legend>';
172 if (PMA_Util::showIcons('ActionLinksMode')) {
173 $html_output .= PMA_Util::getImage('b_edit.png');
175 $html_output .= __('Copy database to:')
176 . '</legend>'
177 . '<input type="text" name="newname" size="30" '
178 . 'class="textfield" value="" /><br />'
179 . PMA_Util::getRadioFields(
180 'what', $choices, 'data', true
182 $html_output .= '<input type="checkbox" name="create_database_before_copying" '
183 . 'value="1" id="checkbox_create_database_before_copying"'
184 . 'checked="checked" />';
185 $html_output .= '<label for="checkbox_create_database_before_copying">'
186 . __('CREATE DATABASE before copying') . '</label><br />';
187 $html_output .= '<input type="checkbox" name="drop_if_exists" value="true"'
188 . 'id="checkbox_drop" />';
189 $html_output .= '<label for="checkbox_drop">'
190 . sprintf(__('Add %s'), $drop_clause)
191 . '</label><br />';
192 $html_output .= '<input type="checkbox" name="sql_auto_increment" value="1" '
193 . 'checked="checked" id="checkbox_auto_increment" />';
194 $html_output .= '<label for="checkbox_auto_increment">'
195 . __('Add AUTO_INCREMENT value') . '</label><br />';
196 $html_output .= '<input type="checkbox" name="add_constraints" value="1"'
197 . 'id="checkbox_constraints" />';
198 $html_output .= '<label for="checkbox_constraints">'
199 . __('Add constraints') . '</label><br />';
200 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
201 . 'id="checkbox_switch"'
202 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
203 ? ' checked="checked"'
204 : '')
205 . '/>';
206 $html_output .= '<label for="checkbox_switch">'
207 . __('Switch to copied database') . '</label>'
208 . '</fieldset>';
209 $html_output .= '<fieldset class="tblFooters">'
210 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
211 . '</fieldset>'
212 . '</form>'
213 . '</div>';
215 return $html_output;
219 * Get HTML snippet for change database charset
221 * @param string $db database name
222 * @param string $table tabel name
224 * @return string $html_output
226 function PMA_getHtmlForChangeDatabaseCharset($db, $table)
228 $html_output = '<div class="operations_half_width">'
229 . '<form id="change_db_charset_form" ';
230 $html_output .= 'class="ajax" ';
231 $html_output .= 'method="post" action="db_operations.php">';
233 $html_output .= PMA_URL_getHiddenInputs($db, $table);
235 $html_output .= '<fieldset>' . "\n"
236 . ' <legend>';
237 if (PMA_Util::showIcons('ActionLinksMode')) {
238 $html_output .= PMA_Util::getImage('s_asci.png');
240 $html_output .= '<label for="select_db_collation">' . __('Collation')
241 . ':</label>' . "\n"
242 . '</legend>' . "\n"
243 . PMA_generateCharsetDropdownBox(
244 PMA_CSDROPDOWN_COLLATION,
245 'db_collation',
246 'select_db_collation',
247 isset($_REQUEST['db_collation']) ? $_REQUEST['db_collation'] : '',
248 false,
251 . '</fieldset>'
252 . '<fieldset class="tblFooters">'
253 . '<input type="submit" name="submitcollation"'
254 . ' value="' . __('Go') . '" />' . "\n"
255 . '</fieldset>' . "\n"
256 . '</form></div>' . "\n";
258 return $html_output;
262 * Get HTML snippet for export relational schema view
264 * @param string $url_query Query string for link
266 * @return string $html_output
268 function PMA_getHtmlForExportRelationalSchemaView($url_query)
270 $html_output = '<div class="operations_full_width">'
271 . '<fieldset><a href="schema_edit.php?' . $url_query . '">';
272 if (PMA_Util::showIcons('ActionLinksMode')) {
273 $html_output .= PMA_Util::getImage(
274 'b_edit.png'
277 $html_output .= __('Edit or export relational schema')
278 . '</a></fieldset>'
279 . '</div>';
281 return $html_output;
285 * Run the Procedure definitions and function definitions
287 * to avoid selecting alternatively the current and new db
288 * we would need to modify the CREATE definitions to qualify
289 * the db name
291 * @param string $db database name
293 * @return void
295 function PMA_runProcedureAndFunctionDefinitions($db)
297 $procedure_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'PROCEDURE');
298 if ($procedure_names) {
299 foreach ($procedure_names as $procedure_name) {
300 $GLOBALS['dbi']->selectDb($db);
301 $tmp_query = $GLOBALS['dbi']->getDefinition(
302 $db, 'PROCEDURE', $procedure_name
304 // collect for later display
305 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
306 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
307 $GLOBALS['dbi']->query($tmp_query);
311 $function_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'FUNCTION');
312 if ($function_names) {
313 foreach ($function_names as $function_name) {
314 $GLOBALS['dbi']->selectDb($db);
315 $tmp_query = $GLOBALS['dbi']->getDefinition(
316 $db, 'FUNCTION', $function_name
318 // collect for later display
319 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
320 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
321 $GLOBALS['dbi']->query($tmp_query);
327 * Get sql query and create database before copy
329 * @return string $sql_query
331 function PMA_getSqlQueryAndCreateDbBeforeCopy()
333 // lower_case_table_names=1 `DB` becomes `db`
334 if (! PMA_DRIZZLE) {
335 $lower_case_table_names = $GLOBALS['dbi']->fetchValue(
336 'SHOW VARIABLES LIKE "lower_case_table_names"', 0, 1
338 if ($lower_case_table_names === '1') {
339 $_REQUEST['newname'] = $GLOBALS['PMA_String']->strtolower(
340 $_REQUEST['newname']
345 $local_query = 'CREATE DATABASE IF NOT EXISTS '
346 . PMA_Util::backquote($_REQUEST['newname']);
347 if (isset($_REQUEST['db_collation'])) {
348 $local_query .= ' DEFAULT'
349 . PMA_generateCharsetQueryPart($_REQUEST['db_collation']);
351 $local_query .= ';';
352 $sql_query = $local_query;
353 // save the original db name because Tracker.class.php which
354 // may be called under $GLOBALS['dbi']->query() changes $GLOBALS['db']
355 // for some statements, one of which being CREATE DATABASE
356 $original_db = $GLOBALS['db'];
357 $GLOBALS['dbi']->query($local_query);
358 $GLOBALS['db'] = $original_db;
360 // Set the SQL mode to NO_AUTO_VALUE_ON_ZERO to prevent MySQL from creating
361 // export statements it cannot import
362 $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'";
363 $GLOBALS['dbi']->query($sql_set_mode);
365 // rebuild the database list because PMA_Table::moveCopy
366 // checks in this list if the target db exists
367 $GLOBALS['pma']->databases->build();
369 return $sql_query;
373 * remove all foreign key constraints and return
374 * sql constraints query for full database
376 * @param array $tables_full array of all tables in given db or dbs
377 * @param object $export_sql_plugin export plugin instance
378 * @param boolean $move whether database name is empty or not
379 * @param string $db database name
381 * @return string sql constraints query for full databases
383 function PMA_getSqlConstraintsQueryForFullDb(
384 $tables_full, $export_sql_plugin, $move, $db
386 global $sql_constraints, $sql_drop_foreign_keys;
387 $sql_constraints_query_full_db = array();
388 foreach ($tables_full as $each_table => $tmp) {
389 /* Following globals are set in getTableDef */
390 $sql_constraints = '';
391 $sql_drop_foreign_keys = '';
392 $export_sql_plugin->getTableDef(
393 $db, $each_table, "\n", '', false, false
395 if ($move && ! empty($sql_drop_foreign_keys)) {
396 $GLOBALS['dbi']->query($sql_drop_foreign_keys);
398 // keep the constraint we just dropped
399 if (! empty($sql_constraints)) {
400 $sql_constraints_query_full_db[] = $sql_constraints;
403 return $sql_constraints_query_full_db;
407 * Get views as an array and create SQL view stand-in
409 * @param array $tables_full array of all tables in given db or dbs
410 * @param object $export_sql_plugin export plugin instance
411 * @param string $db database name
413 * @return array $views
415 function PMA_getViewsAndCreateSqlViewStandIn(
416 $tables_full, $export_sql_plugin, $db
418 $views = array();
419 foreach ($tables_full as $each_table => $tmp) {
420 // to be able to rename a db containing views,
421 // first all the views are collected and a stand-in is created
422 // the real views are created after the tables
423 if (PMA_Table::isView($db, $each_table)) {
424 $views[] = $each_table;
425 // Create stand-in definition to resolve view dependencies
426 $sql_view_standin = $export_sql_plugin->getTableDefStandIn(
427 $db, $each_table, "\n"
429 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
430 $GLOBALS['dbi']->query($sql_view_standin);
431 $GLOBALS['sql_query'] .= "\n" . $sql_view_standin;
434 return $views;
438 * Get sql query for copy/rename table and boolean for whether copy/rename or not
440 * @param array $tables_full array of all tables in given db or dbs
441 * @param string $sql_query sql query for all operations
442 * @param boolean $move whether database name is empty or not
443 * @param string $db database name
445 * @return array ($sql_query, $error)
447 function PMA_getSqlQueryForCopyTable($tables_full, $sql_query, $move, $db)
449 $error = false;
450 foreach ($tables_full as $each_table => $tmp) {
451 // skip the views; we have creted stand-in definitions
452 if (PMA_Table::isView($db, $each_table)) {
453 continue;
455 $back = $sql_query;
456 $sql_query = '';
458 // value of $what for this table only
459 $this_what = $_REQUEST['what'];
461 // do not copy the data from a Merge table
462 // note: on the calling FORM, 'data' means 'structure and data'
463 if (PMA_Table::isMerge($db, $each_table)) {
464 if ($this_what == 'data') {
465 $this_what = 'structure';
467 if ($this_what == 'dataonly') {
468 $this_what = 'nocopy';
472 if ($this_what != 'nocopy') {
473 // keep the triggers from the original db+table
474 // (third param is empty because delimiters are only intended
475 // for importing via the mysql client or our Import feature)
476 $triggers = $GLOBALS['dbi']->getTriggers($db, $each_table, '');
478 if (! PMA_Table::moveCopy(
479 $db, $each_table, $_REQUEST['newname'], $each_table,
480 (isset($this_what) ? $this_what : 'data'),
481 $move, 'db_copy'
482 )) {
483 $error = true;
484 // $sql_query is filled by PMA_Table::moveCopy()
485 $sql_query = $back . $sql_query;
486 break;
488 // apply the triggers to the destination db+table
489 if ($triggers) {
490 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
491 foreach ($triggers as $trigger) {
492 $GLOBALS['dbi']->query($trigger['create']);
493 $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';';
497 // this does not apply to a rename operation
498 if (isset($_REQUEST['add_constraints'])
499 && ! empty($GLOBALS['sql_constraints_query'])
501 $GLOBALS['sql_constraints_query_full_db'][]
502 = $GLOBALS['sql_constraints_query'];
503 unset($GLOBALS['sql_constraints_query']);
506 // $sql_query is filled by PMA_Table::moveCopy()
507 $sql_query = $back . $sql_query;
509 return array($sql_query, $error);
513 * Run the EVENT definition for selected database
515 * to avoid selecting alternatively the current and new db
516 * we would need to modify the CREATE definitions to qualify
517 * the db name
519 * @param string $db database name
521 * @return void
523 function PMA_runEventDefinitionsForDb($db)
525 $event_names = $GLOBALS['dbi']->fetchResult(
526 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \''
527 . PMA_Util::sqlAddSlashes($db, true) . '\';'
529 if ($event_names) {
530 foreach ($event_names as $event_name) {
531 $GLOBALS['dbi']->selectDb($db);
532 $tmp_query = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $event_name);
533 // collect for later display
534 $GLOBALS['sql_query'] .= "\n" . $tmp_query;
535 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
536 $GLOBALS['dbi']->query($tmp_query);
542 * Handle the views, return the boolean value whether table rename/copy or not
544 * @param array $views views as an array
545 * @param boolean $move whether database name is empty or not
546 * @param string $db database name
548 * @return boolean $_error whether table rename/copy or not
550 function PMA_handleTheViews($views, $move, $db)
552 $_error = false;
553 // temporarily force to add DROP IF EXIST to CREATE VIEW query,
554 // to remove stand-in VIEW that was created earlier
555 // ( $_REQUEST['drop_if_exists'] is used in moveCopy() )
556 if (isset($_REQUEST['drop_if_exists'])) {
557 $temp_drop_if_exists = $_REQUEST['drop_if_exists'];
559 $_REQUEST['drop_if_exists'] = 'true';
561 foreach ($views as $view) {
562 $copying_succeeded = PMA_Table::moveCopy(
563 $db, $view, $_REQUEST['newname'], $view, 'structure', $move, 'db_copy'
565 if (! $copying_succeeded) {
566 $_error = true;
567 break;
570 unset($_REQUEST['drop_if_exists']);
571 if (isset($temp_drop_if_exists)) {
572 // restore previous value
573 $_REQUEST['drop_if_exists'] = $temp_drop_if_exists;
575 return $_error;
579 * Create all accumulated constraaints
581 * @return void
583 function PMA_createAllAccumulatedConstraints()
585 $GLOBALS['dbi']->selectDb($_REQUEST['newname']);
586 foreach ($GLOBALS['sql_constraints_query_full_db'] as $one_query) {
587 $GLOBALS['dbi']->query($one_query);
588 // and prepare to display them
589 $GLOBALS['sql_query'] .= "\n" . $one_query;
591 unset($GLOBALS['sql_constraints_query_full_db']);
595 * Duplicate the bookmarks for the db (done once for each db)
597 * @param boolean $_error whether table rename/copy or not
598 * @param string $db database name
600 * @return void
602 function PMA_duplicateBookmarks($_error, $db)
604 if (! $_error && $db != $_REQUEST['newname']) {
605 $get_fields = array('user', 'label', 'query');
606 $where_fields = array('dbase' => $db);
607 $new_fields = array('dbase' => $_REQUEST['newname']);
608 PMA_Table::duplicateInfo(
609 'bookmarkwork', 'bookmark', $get_fields,
610 $where_fields, $new_fields
616 * Get the HTML snippet for order the table
618 * @param array $columns columns array
620 * @return string $html_out
622 function PMA_getHtmlForOrderTheTable($columns)
624 $html_output = '<div class="operations_half_width">';
625 $html_output .= '<form method="post" id="alterTableOrderby" '
626 . 'action="tbl_operations.php">';
627 $html_output .= PMA_URL_getHiddenInputs(
628 $GLOBALS['db'], $GLOBALS['table']
630 $html_output .= '<fieldset id="fieldset_table_order">'
631 . '<legend>' . __('Alter table order by') . '</legend>'
632 . '<select name="order_field">';
634 foreach ($columns as $fieldname) {
635 $html_output .= '<option '
636 . 'value="' . htmlspecialchars($fieldname['Field']) . '">'
637 . htmlspecialchars($fieldname['Field']) . '</option>' . "\n";
639 $html_output .= '</select> ' . __('(singly)') . ' '
640 . '<br />'
641 . '<input id="order_order_asc" name="order_order"'
642 . ' type="radio" value="asc" checked="checked" />'
643 . '<label for="order_order_asc">' . __('Ascending') . '</label>'
644 . '<input id="order_order_desc" name="order_order"'
645 . ' type="radio" value="desc" />'
646 . '<label for="order_order_desc">' . __('Descending') . '</label>'
647 . '</fieldset>'
648 . '<fieldset class="tblFooters">'
649 . '<input type="hidden" name="submitorderby" value="1" />'
650 . '<input type="submit" value="' . __('Go') . '" />'
651 . '</fieldset>'
652 . '</form>'
653 . '</div>';
655 return $html_output;
659 * Get the HTML snippet for move table
661 * @return string $html_output
663 function PMA_getHtmlForMoveTable()
665 $html_output = '<div class="operations_half_width">';
666 $html_output .= '<form method="post" action="tbl_operations.php"'
667 . ' id="moveTableForm" class="ajax"'
668 . ' onsubmit="return emptyFormElements(this, \'new_name\')">'
669 . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
671 $html_output .= '<input type="hidden" name="reload" value="1" />'
672 . '<input type="hidden" name="what" value="data" />'
673 . '<fieldset id="fieldset_table_rename">';
675 $html_output .= '<legend>' . __('Move table to (database<b>.</b>table):')
676 . '</legend>';
678 if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
679 $html_output .= '<input type="text" maxlength="100" size="30" '
680 . 'name="target_db" value="' . htmlspecialchars($GLOBALS['db'])
681 . '"/>';
682 } else {
683 $html_output .= '<select class="halfWidth" name="target_db">'
684 . $GLOBALS['pma']->databases->getHtmlOptions(true, false)
685 . '</select>';
687 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
688 $html_output .= '<input class="halfWidth" type="text" size="20" name="new_name"'
689 . ' onfocus="this.select()" required '
690 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" /><br />';
692 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
693 // next value but users can decide if they want it or not for the operation
695 $html_output .= '<input type="checkbox" name="sql_auto_increment" '
696 . 'value="1" id="checkbox_auto_increment_mv" checked="checked" />'
697 . '<label for="checkbox_auto_increment_mv">'
698 . __('Add AUTO_INCREMENT value')
699 . '</label><br />'
700 . '</fieldset>';
702 $html_output .= '<fieldset class="tblFooters">'
703 . '<input type="submit" name="submit_move" value="' . __('Go') . '" />'
704 . '</fieldset>'
705 . '</form>'
706 . '</div>';
708 return $html_output;
712 * Get the HTML div for Table option
714 * @param string $comment Comment
715 * @param array $tbl_collation table collation
716 * @param string $tbl_storage_engine table storage engine
717 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
718 * @param boolean $is_isam whether ISAM or not
719 * @param array $pack_keys pack keys
720 * @param string $auto_increment value of auto increment
721 * @param string $delay_key_write delay key write
722 * @param string $transactional value of transactional
723 * @param string $page_checksum value of page checksum
724 * @param boolean $is_innodb whether INNODB or not
725 * @param boolean $is_pbxt whether PBXT or not
726 * @param boolean $is_aria whether ARIA or not
727 * @param string $checksum the checksum
729 * @return string $html_output
731 function PMA_getTableOptionDiv($comment, $tbl_collation, $tbl_storage_engine,
732 $is_myisam_or_aria, $is_isam, $pack_keys, $auto_increment, $delay_key_write,
733 $transactional, $page_checksum, $is_innodb, $is_pbxt, $is_aria, $checksum
735 $html_output = '<div class="operations_half_width clearfloat">';
736 $html_output .= '<form method="post" action="tbl_operations.php"';
737 $html_output .= ' id="tableOptionsForm" class="ajax">';
738 $html_output .= PMA_URL_getHiddenInputs(
739 $GLOBALS['db'], $GLOBALS['table']
741 $html_output .= '<input type="hidden" name="reload" value="1" />';
743 $html_output .= PMA_getTableOptionFieldset(
744 $comment, $tbl_collation,
745 $tbl_storage_engine, $is_myisam_or_aria, $is_isam, $pack_keys,
746 $delay_key_write, $auto_increment, $transactional, $page_checksum,
747 $is_innodb, $is_pbxt, $is_aria, $checksum
750 $html_output .= '<fieldset class="tblFooters">'
751 . '<input type="hidden" name="submitoptions" value="1" />'
752 . '<input type="submit" value="' . __('Go') . '" />'
753 . '</fieldset>'
754 . '</form>'
755 . '</div>';
757 return $html_output;
761 * Get HTML fieldset for Table option, it contains HTML table for options
763 * @param string $comment Comment
764 * @param array $tbl_collation table collation
765 * @param string $tbl_storage_engine table storage engine
766 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
767 * @param boolean $is_isam whether ISAM or not
768 * @param array $pack_keys pack keys
769 * @param string $delay_key_write delay key write
770 * @param string $auto_increment value of auto increment
771 * @param string $transactional value of transactional
772 * @param string $page_checksum value of page checksum
773 * @param boolean $is_innodb whether INNODB or not
774 * @param boolean $is_pbxt whether PBXT or not
775 * @param boolean $is_aria whether ARIA or not
776 * @param string $checksum the checksum
778 * @return string $html_output
780 function PMA_getTableOptionFieldset($comment, $tbl_collation,
781 $tbl_storage_engine, $is_myisam_or_aria, $is_isam, $pack_keys,
782 $delay_key_write, $auto_increment, $transactional,
783 $page_checksum, $is_innodb, $is_pbxt, $is_aria, $checksum
785 $html_output = '<fieldset>'
786 . '<legend>' . __('Table options') . '</legend>';
788 $html_output .= '<table>';
789 //Change table name
790 $html_output .= '<tr><td>' . __('Rename table to') . '</td>'
791 . '<td>'
792 . '<input type="text" size="20" name="new_name" onfocus="this.select()"'
793 . 'value="' . htmlspecialchars($GLOBALS['table']) . '" required />'
794 . '</td>'
795 . '</tr>';
797 //Table comments
798 $html_output .= '<tr><td>' . __('Table comments') . '</td>'
799 . '<td><input type="text" name="comment" maxlength="60" size="30"'
800 . 'value="' . htmlspecialchars($comment) . '" onfocus="this.select()" />'
801 . '<input type="hidden" name="prev_comment" value="'
802 . htmlspecialchars($comment) . '" />'
803 . '</td>'
804 . '</tr>';
806 //Storage engine
807 $html_output .= '<tr><td>' . __('Storage Engine')
808 . PMA_Util::showMySQLDocu('Storage_engines')
809 . '</td>'
810 . '<td>'
811 . PMA_StorageEngine::getHtmlSelect(
812 'new_tbl_storage_engine', null, $tbl_storage_engine
814 . '</td>'
815 . '</tr>';
817 //Table character set
818 $html_output .= '<tr><td>' . __('Collation') . '</td>'
819 . '<td>'
820 . PMA_generateCharsetDropdownBox(
821 PMA_CSDROPDOWN_COLLATION,
822 'tbl_collation', null, $tbl_collation, false, 3
824 . '</td>'
825 . '</tr>';
827 if ($is_myisam_or_aria || $is_isam) {
828 $html_output .= '<tr>'
829 . '<td><label for="new_pack_keys">PACK_KEYS</label></td>'
830 . '<td><select name="new_pack_keys" id="new_pack_keys">';
832 $html_output .= '<option value="DEFAULT"';
833 if ($pack_keys == 'DEFAULT') {
834 $html_output .= 'selected="selected"';
836 $html_output .= '>DEFAULT</option>
837 <option value="0"';
838 if ($pack_keys == '0') {
839 $html_output .= 'selected="selected"';
841 $html_output .= '>0</option>
842 <option value="1" ';
843 if ($pack_keys == '1') {
844 $html_output .= 'selected="selected"';
846 $html_output .= '>1</option>'
847 . '</select>'
848 . '</td>'
849 . '</tr>';
850 } // end if (MYISAM|ISAM)
852 if ($is_myisam_or_aria) {
853 $html_output .= PMA_getHtmlForTableRow(
854 'new_checksum',
855 'CHECKSUM',
856 $checksum
859 $html_output .= PMA_getHtmlForTableRow(
860 'new_delay_key_write',
861 'DELAY_KEY_WRITE',
862 $delay_key_write
864 } // end if (MYISAM)
866 if ($is_aria) {
867 $html_output .= PMA_getHtmlForTableRow(
868 'new_transactional',
869 'TRANSACTIONAL',
870 $transactional
873 $html_output .= PMA_getHtmlForTableRow(
874 'new_page_checksum',
875 'PAGE_CHECKSUM',
876 $page_checksum
878 } // end if (ARIA)
880 if (strlen($auto_increment) > 0
881 && ($is_myisam_or_aria || $is_innodb || $is_pbxt)
883 $html_output .= '<tr><td>'
884 . '<label for="auto_increment_opt">AUTO_INCREMENT</label></td>'
885 . '<td><input type="number" name="new_auto_increment" '
886 . 'id="auto_increment_opt"'
887 . 'value="' . $auto_increment . '" /></td>'
888 . '</tr> ';
889 } // end if (MYISAM|INNODB)
891 $possible_row_formats = PMA_getPossibleRowFormat();
893 // for MYISAM there is also COMPRESSED but it can be set only by the
894 // myisampack utility, so don't offer here the choice because if we
895 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
896 // does not return a warning
897 // (if the table was compressed, it can be seen on the Structure page)
899 if (isset($possible_row_formats[$tbl_storage_engine])) {
900 $current_row_format = strtoupper($GLOBALS['showtable']['Row_format']);
901 $html_output .= '<tr><td>'
902 . '<label for="new_row_format">ROW_FORMAT</label></td>'
903 . '<td>';
904 $html_output .= PMA_Util::getDropdown(
905 'new_row_format', $possible_row_formats[$tbl_storage_engine],
906 $current_row_format, 'new_row_format'
908 $html_output .= '</td></tr>';
910 $html_output .= '</table>'
911 . '</fieldset>';
913 return $html_output;
917 * Get the common HTML table row (tr) for new_checksum, new_delay_key_write,
918 * new_transactional and new_page_checksum
920 * @param string $attribute class, name and id attribute
921 * @param string $label label value
922 * @param string $val checksum, delay_key_write, transactional, page_checksum
924 * @return string $html_output
926 function PMA_getHtmlForTableRow($attribute, $label, $val)
928 return '<tr>'
929 . '<td><label for="' . $attribute . '">' . $label . '</label></td>'
930 . '<td><input type="checkbox" name="'. $attribute .'"'
931 . ' id="' . $attribute .'"'
932 . ' value="1"'
933 . ((!empty($val) && $val == 1) ? ' checked="checked"' : '') . '/></td>'
934 . '</tr>';
938 * Get array of possible row formats
940 * @return array $possible_row_formats
942 function PMA_getPossibleRowFormat()
944 // the outer array is for engines, the inner array contains the dropdown
945 // option values as keys then the dropdown option labels
947 $possible_row_formats = array(
948 'ARIA' => array(
949 'FIXED' => 'FIXED',
950 'DYNAMIC' => 'DYNAMIC',
951 'PAGE' => 'PAGE'
953 'MARIA' => array(
954 'FIXED' => 'FIXED',
955 'DYNAMIC' => 'DYNAMIC',
956 'PAGE' => 'PAGE'
958 'MYISAM' => array(
959 'FIXED' => 'FIXED',
960 'DYNAMIC' => 'DYNAMIC'
962 'PBXT' => array(
963 'FIXED' => 'FIXED',
964 'DYNAMIC' => 'DYNAMIC'
966 'INNODB' => array(
967 'COMPACT' => 'COMPACT',
968 'REDUNDANT' => 'REDUNDANT'
972 $innodb_engine_plugin = PMA_StorageEngine::getEngine('innodb');
973 $innodb_plugin_version = $innodb_engine_plugin->getInnodbPluginVersion();
974 if (!empty($innodb_plugin_version)) {
975 $innodb_file_format = $innodb_engine_plugin->getInnodbFileFormat();
976 } else {
977 $innodb_file_format = '';
979 if ('Barracuda' == $innodb_file_format
980 && $innodb_engine_plugin->supportsFilePerTable()
982 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
983 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
986 return $possible_row_formats;
990 * Get HTML div for copy table
992 * @return string $html_output
994 function PMA_getHtmlForCopytable()
996 $html_output = '<div class="operations_half_width">';
997 $html_output .= '<form method="post" action="tbl_operations.php" '
998 . 'name="copyTable" '
999 . 'id="copyTable" '
1000 . ' class="ajax" '
1001 . 'onsubmit="return emptyFormElements(this, \'new_name\')">'
1002 . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1003 . '<input type="hidden" name="reload" value="1" />';
1005 $html_output .= '<fieldset>';
1006 $html_output .= '<legend>'
1007 . __('Copy table to (database<b>.</b>table):') . '</legend>';
1009 if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
1010 $html_output .= '<input class="halfWidth" type="text" maxlength="100" '
1011 . 'size="30" name="target_db" '
1012 . 'value="'. htmlspecialchars($GLOBALS['db']) . '"/>';
1013 } else {
1014 $html_output .= '<select class="halfWidth" name="target_db">'
1015 . $GLOBALS['pma']->databases->getHtmlOptions(true, false)
1016 . '</select>';
1018 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
1019 $html_output .= '<input class="halfWidth" type="text" required '
1020 . 'size="20" name="new_name" onfocus="this.select()" '
1021 . 'value="'. htmlspecialchars($GLOBALS['table']) . '"/><br />';
1023 $choices = array(
1024 'structure' => __('Structure only'),
1025 'data' => __('Structure and data'),
1026 'dataonly' => __('Data only'));
1028 $html_output .= PMA_Util::getRadioFields(
1029 'what', $choices, 'data', true
1032 $html_output .= '<input type="checkbox" name="drop_if_exists" '
1033 . 'value="true" id="checkbox_drop" />'
1034 . '<label for="checkbox_drop">'
1035 . sprintf(__('Add %s'), 'DROP TABLE') . '</label><br />'
1036 . '<input type="checkbox" name="sql_auto_increment" '
1037 . 'value="1" id="checkbox_auto_increment_cp" />'
1038 . '<label for="checkbox_auto_increment_cp">'
1039 . __('Add AUTO_INCREMENT value') . '</label><br />';
1041 // display "Add constraints" choice only if there are
1042 // foreign keys
1043 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
1044 $html_output .= '<input type="checkbox" name="add_constraints" '
1045 . 'value="1" id="checkbox_constraints" />';
1046 $html_output .= '<label for="checkbox_constraints">'
1047 .__('Add constraints') . '</label><br />';
1048 } // endif
1050 if (isset($_COOKIE['pma_switch_to_new'])
1051 && $_COOKIE['pma_switch_to_new'] == 'true'
1053 $pma_switch_to_new = 'true';
1056 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
1057 . 'id="checkbox_switch"'
1058 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
1059 ? ' checked="checked"'
1060 : '' . '/>');
1061 $html_output .= '<label for="checkbox_switch">'
1062 . __('Switch to copied table') . '</label>'
1063 . '</fieldset>';
1065 $html_output .= '<fieldset class="tblFooters">'
1066 . '<input type="submit" name="submit_copy" value="' .__('Go') . '" />'
1067 . '</fieldset>'
1068 . '</form>'
1069 . '</div>';
1071 return $html_output;
1075 * Get HTML snippet for table maintence
1077 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1078 * @param boolean $is_innodb whether innodb or not
1079 * @param boolean $is_berkeleydb whether berkeleydb or not
1080 * @param array $url_params array of URL parameters
1082 * @return string $html_output
1084 function PMA_getHtmlForTableMaintenance(
1085 $is_myisam_or_aria, $is_innodb, $is_berkeleydb, $url_params
1087 $html_output = '<div class="operations_half_width">';
1088 $html_output .= '<fieldset>'
1089 . '<legend>' . __('Table maintenance') . '</legend>';
1090 $html_output .= '<ul id="tbl_maintenance">';
1092 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
1093 $html_output .= PMA_getListofMaintainActionLink(
1094 $is_myisam_or_aria, $is_innodb, $url_params, $is_berkeleydb
1097 $html_output .= '</ul>'
1098 . '</fieldset>'
1099 . '</div>';
1101 return $html_output;
1105 * Get HTML 'li' having a link of maintain action
1107 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1108 * @param boolean $is_innodb whether innodb or not
1109 * @param array $url_params array of URL parameters
1110 * @param boolean $is_berkeleydb whether berkeleydb or not
1112 * @return string $html_output
1114 function PMA_getListofMaintainActionLink($is_myisam_or_aria,
1115 $is_innodb, $url_params, $is_berkeleydb
1117 $html_output = '';
1119 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
1120 if ($is_myisam_or_aria || $is_innodb) {
1121 $params = array(
1122 'sql_query' => 'CHECK TABLE '
1123 . PMA_Util::backquote($GLOBALS['table']),
1124 'table_maintenance' => 'Go',
1126 $html_output .= PMA_getMaintainActionlink(
1127 __('Check table'),
1128 $params,
1129 $url_params,
1130 'CHECK_TABLE'
1133 if ($is_innodb) {
1134 $params = array(
1135 'sql_query' => 'ALTER TABLE '
1136 . PMA_Util::backquote($GLOBALS['table'])
1137 . ' ENGINE = InnoDB;'
1139 $html_output .= PMA_getMaintainActionlink(
1140 __('Defragment table'),
1141 $params,
1142 $url_params,
1143 'InnoDB_File_Defragmenting',
1144 'Table_types'
1147 if ($is_innodb || $is_myisam_or_aria || $is_berkeleydb) {
1148 $params = array(
1149 'sql_query' => 'ANALYZE TABLE '
1150 . PMA_Util::backquote($GLOBALS['table']),
1151 'table_maintenance' => 'Go',
1153 $html_output .= PMA_getMaintainActionlink(
1154 __('Analyze table'),
1155 $params,
1156 $url_params,
1157 'ANALYZE_TABLE'
1160 if ($is_myisam_or_aria && !PMA_DRIZZLE) {
1161 $params = array(
1162 'sql_query' => 'REPAIR TABLE '
1163 . PMA_Util::backquote($GLOBALS['table']),
1164 'table_maintenance' => 'Go',
1166 $html_output .= PMA_getMaintainActionlink(
1167 __('Repair table'),
1168 $params,
1169 $url_params,
1170 'REPAIR_TABLE'
1173 if (($is_myisam_or_aria || $is_innodb || $is_berkeleydb)
1174 && !PMA_DRIZZLE
1176 $params = array(
1177 'sql_query' => 'OPTIMIZE TABLE '
1178 . PMA_Util::backquote($GLOBALS['table']),
1179 'table_maintenance' => 'Go',
1181 $html_output .= PMA_getMaintainActionlink(
1182 __('Optimize table'),
1183 $params,
1184 $url_params,
1185 'OPTIMIZE_TABLE'
1188 } // end MYISAM or BERKELEYDB case
1190 $params = array(
1191 'sql_query' => 'FLUSH TABLE '
1192 . PMA_Util::backquote($GLOBALS['table']),
1193 'message_to_show' => sprintf(
1194 __('Table %s has been flushed'),
1195 htmlspecialchars($GLOBALS['table'])
1197 'reload' => 1,
1200 $html_output .= PMA_getMaintainActionlink(
1201 __('Flush the table (FLUSH)'),
1202 $params,
1203 $url_params,
1204 'FLUSH'
1207 return $html_output;
1211 * Get maintain action HTML link
1213 * @param string $action action name
1214 * @param array $params url parameters array
1215 * @param array $url_params additional url parameters
1216 * @param string $link contains name of page/anchor that is being linked
1218 * @return string $html_output
1220 function PMA_getMaintainActionlink($action, $params, $url_params, $link)
1222 return '<li>'
1223 . '<a class="maintain_action ajax" '
1224 . 'href="sql.php'
1225 . PMA_URL_getCommon(array_merge($url_params, $params)) .'">'
1226 . $action
1227 . '</a>'
1228 . PMA_Util::showMySQLDocu($link)
1229 . '</li>';
1233 * Get HTML for Delete data or table (truncate table, drop table)
1235 * @param array $truncate_table_url_params url parameter array for truncate table
1236 * @param array $drop_table_url_params url parameter array for drop table
1238 * @return string $html_output
1240 function PMA_getHtmlForDeleteDataOrTable(
1241 $truncate_table_url_params,
1242 $drop_table_url_params
1244 $html_output = '<div class="operations_half_width">'
1245 . '<fieldset class="caution">'
1246 . '<legend>' . __('Delete data or table') . '</legend>';
1248 $html_output .= '<ul>';
1250 if (! empty($truncate_table_url_params)) {
1251 $html_output .= PMA_getDeleteDataOrTablelink(
1252 $truncate_table_url_params,
1253 'TRUNCATE_TABLE',
1254 __('Empty the table (TRUNCATE)'),
1255 'truncate_tbl_anchor'
1258 if (!empty ($drop_table_url_params)) {
1259 $html_output .= PMA_getDeleteDataOrTablelink(
1260 $drop_table_url_params,
1261 'DROP_TABLE',
1262 __('Delete the table (DROP)'),
1263 'drop_tbl_anchor'
1266 $html_output .= '</ul></fieldset></div>';
1268 return $html_output;
1272 * Get the HTML link for Truncate table, Drop table and Drop db
1274 * @param array $url_params url parameter array for delete data or table
1275 * @param string $syntax TRUNCATE_TABLE or DROP_TABLE or DROP_DATABASE
1276 * @param string $link link to be shown
1277 * @param string $id id of the link
1279 * @return String html output
1281 function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $id)
1283 return '<li><a '
1284 . 'href="sql.php' . PMA_URL_getCommon($url_params) . '"'
1285 . ' id="' . $id . '" class="ajax">'
1286 . $link . '</a>'
1287 . PMA_Util::showMySQLDocu($syntax)
1288 . '</li>';
1292 * Get HTML snippet for partition maintenance
1294 * @param array $partition_names array of partition names for a specific db/table
1295 * @param array $url_params url parameters
1297 * @return string $html_output
1299 function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
1301 $choices = array(
1302 'ANALYZE' => __('Analyze'),
1303 'CHECK' => __('Check'),
1304 'OPTIMIZE' => __('Optimize'),
1305 'REBUILD' => __('Rebuild'),
1306 'REPAIR' => __('Repair')
1309 $html_output = '<div class="operations_half_width">'
1310 . '<form method="post" action="tbl_operations.php">'
1311 . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1312 . '<fieldset>'
1313 . '<legend>' . __('Partition maintenance') . '</legend>';
1315 $html_select = '<select name="partition_name">' . "\n";
1316 foreach ($partition_names as $one_partition) {
1317 $one_partition = htmlspecialchars($one_partition);
1318 $html_select .= '<option value="' . $one_partition . '">'
1319 . $one_partition . '</option>' . "\n";
1321 $html_select .= '</select>' . "\n";
1322 $html_output .= sprintf(__('Partition %s'), $html_select);
1324 $html_output .= PMA_Util::getRadioFields(
1325 'partition_operation', $choices, '', false
1327 $html_output .= PMA_Util::showMySQLDocu('partitioning_maintenance');
1328 $this_url_params = array_merge(
1329 $url_params,
1330 array(
1331 'sql_query' => 'ALTER TABLE '
1332 . PMA_Util::backquote($GLOBALS['table'])
1333 . ' REMOVE PARTITIONING;'
1336 $html_output .= '<br /><a href="sql.php'
1337 . PMA_URL_getCommon($this_url_params) . '">'
1338 . __('Remove partitioning') . '</a>';
1340 $html_output .= '</fieldset>'
1341 . '<fieldset class="tblFooters">'
1342 . '<input type="submit" name="submit_partition" '
1343 . 'value="' . __('Go') . '" />'
1344 . '</fieldset>'
1345 . '</form>'
1346 . '</div>';
1348 return $html_output;
1352 * Get the HTML for Referential Integrity check
1354 * @param array $foreign all Relations to foreign tables for a given table
1355 * or optionally a given column in a table
1356 * @param array $url_params array of url parameters
1358 * @return string $html_output
1360 function PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
1362 $html_output = '<div class="operations_half_width">'
1363 . '<fieldset>'
1364 . '<legend>' . __('Check referential integrity:') . '</legend>';
1366 $html_output .= '<ul>';
1368 foreach ($foreign as $master => $arr) {
1369 $join_query = 'SELECT '
1370 . PMA_Util::backquote($GLOBALS['table']) . '.*'
1371 . ' FROM ' . PMA_Util::backquote($GLOBALS['table'])
1372 . ' LEFT JOIN '
1373 . PMA_Util::backquote($arr['foreign_db'])
1374 . '.'
1375 . PMA_Util::backquote($arr['foreign_table']);
1376 if ($arr['foreign_table'] == $GLOBALS['table']) {
1377 $foreign_table = $GLOBALS['table'] . '1';
1378 $join_query .= ' AS ' . PMA_Util::backquote($foreign_table);
1379 } else {
1380 $foreign_table = $arr['foreign_table'];
1382 $join_query .= ' ON '
1383 . PMA_Util::backquote($GLOBALS['table']) . '.'
1384 . PMA_Util::backquote($master)
1385 . ' = '
1386 . PMA_Util::backquote($arr['foreign_db'])
1387 . '.'
1388 . PMA_Util::backquote($foreign_table) . '.'
1389 . PMA_Util::backquote($arr['foreign_field'])
1390 . ' WHERE '
1391 . PMA_Util::backquote($arr['foreign_db'])
1392 . '.'
1393 . PMA_Util::backquote($foreign_table) . '.'
1394 . PMA_Util::backquote($arr['foreign_field'])
1395 . ' IS NULL AND '
1396 . PMA_Util::backquote($GLOBALS['table']) . '.'
1397 . PMA_Util::backquote($master)
1398 . ' IS NOT NULL';
1399 $this_url_params = array_merge(
1400 $url_params,
1401 array('sql_query' => $join_query)
1404 $html_output .= '<li>'
1405 . '<a href="sql.php'
1406 . PMA_URL_getCommon($this_url_params)
1407 . '">'
1408 . $master . '&nbsp;->&nbsp;' . $arr['foreign_db'] . '.'
1409 . $arr['foreign_table'] . '.' . $arr['foreign_field']
1410 . '</a></li>' . "\n";
1411 } // foreach $foreign
1412 $html_output .= '</ul></fieldset></div>';
1414 return $html_output;
1418 * Reorder table based on request params
1420 * @return array SQL query and result
1422 function PMA_getQueryAndResultForReorderingTable()
1424 $sql_query = 'ALTER TABLE '
1425 . PMA_Util::backquote($GLOBALS['table'])
1426 . ' ORDER BY '
1427 . PMA_Util::backquote(urldecode($_REQUEST['order_field']));
1428 if (isset($_REQUEST['order_order'])
1429 && $_REQUEST['order_order'] === 'desc'
1431 $sql_query .= ' DESC';
1433 $sql_query .= ';';
1434 $result = $GLOBALS['dbi']->query($sql_query);
1436 return array($sql_query, $result);
1440 * Get table alters array
1442 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1443 * @param boolean $is_isam whether ISAM or not
1444 * @param string $pack_keys pack keys
1445 * @param string $checksum value of checksum
1446 * @param boolean $is_aria whether ARIA or not
1447 * @param string $page_checksum value of page checksum
1448 * @param string $delay_key_write delay key write
1449 * @param boolean $is_innodb whether INNODB or not
1450 * @param boolean $is_pbxt whether PBXT or not
1451 * @param string $row_format row format
1452 * @param string $new_tbl_storage_engine table storage engine
1453 * @param string $transactional value of transactional
1454 * @param string $tbl_collation collation of the table
1456 * @return array $table_alters
1458 function PMA_getTableAltersArray($is_myisam_or_aria, $is_isam, $pack_keys,
1459 $checksum, $is_aria, $page_checksum, $delay_key_write, $is_innodb,
1460 $is_pbxt, $row_format, $new_tbl_storage_engine, $transactional, $tbl_collation
1462 global $auto_increment;
1464 $table_alters = array();
1466 if (isset($_REQUEST['comment'])
1467 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']
1469 $table_alters[] = 'COMMENT = \''
1470 . PMA_Util::sqlAddSlashes($_REQUEST['comment']) . '\'';
1472 if (! empty($new_tbl_storage_engine)
1473 && strtolower($new_tbl_storage_engine) !== strtolower($GLOBALS['tbl_storage_engine'])
1475 $table_alters[] = 'ENGINE = ' . $new_tbl_storage_engine;
1477 if (! empty($_REQUEST['tbl_collation'])
1478 && $_REQUEST['tbl_collation'] !== $tbl_collation
1480 $table_alters[] = 'DEFAULT '
1481 . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
1484 if (($is_myisam_or_aria || $is_isam)
1485 && isset($_REQUEST['new_pack_keys'])
1486 && $_REQUEST['new_pack_keys'] != (string)$pack_keys
1488 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
1491 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
1492 if ($is_myisam_or_aria
1493 && $_REQUEST['new_checksum'] !== $checksum
1495 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
1498 $_REQUEST['new_transactional']
1499 = empty($_REQUEST['new_transactional']) ? '0' : '1';
1500 if ($is_aria
1501 && $_REQUEST['new_transactional'] !== $transactional
1503 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
1506 $_REQUEST['new_page_checksum']
1507 = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
1508 if ($is_aria
1509 && $_REQUEST['new_page_checksum'] !== $page_checksum
1511 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
1514 $_REQUEST['new_delay_key_write']
1515 = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
1516 if ($is_myisam_or_aria
1517 && $_REQUEST['new_delay_key_write'] !== $delay_key_write
1519 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
1522 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
1523 && ! empty($_REQUEST['new_auto_increment'])
1524 && (! isset($auto_increment)
1525 || $_REQUEST['new_auto_increment'] !== $auto_increment)
1527 $table_alters[] = 'auto_increment = '
1528 . PMA_Util::sqlAddSlashes($_REQUEST['new_auto_increment']);
1531 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
1532 && ! empty($_REQUEST['new_row_format'])
1533 && (!strlen($row_format)
1534 || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format))
1536 $table_alters[] = 'ROW_FORMAT = '
1537 . PMA_Util::sqlAddSlashes($_REQUEST['new_row_format']);
1540 return $table_alters;
1544 * set initial value of the set of variables, based on the current table engine
1546 * @param string $tbl_storage_engine table storage engine
1548 * @return array ($is_myisam_or_aria, $is_innodb, $is_isam,
1549 * $is_berkeleydb, $is_aria, $is_pbxt)
1551 function PMA_setGlobalVariablesForEngine($tbl_storage_engine)
1553 $is_myisam_or_aria = $is_isam = $is_innodb = $is_berkeleydb
1554 = $is_aria = $is_pbxt = false;
1555 $upper_tbl_storage_engine = strtoupper($tbl_storage_engine);
1557 //Options that apply to MYISAM usually apply to ARIA
1558 $is_myisam_or_aria = ($upper_tbl_storage_engine == 'MYISAM'
1559 || $upper_tbl_storage_engine == 'ARIA'
1560 || $upper_tbl_storage_engine == 'MARIA'
1562 $is_aria = ($upper_tbl_storage_engine == 'ARIA');
1564 $is_isam = ($upper_tbl_storage_engine == 'ISAM');
1565 $is_innodb = ($upper_tbl_storage_engine == 'INNODB');
1566 $is_berkeleydb = ($upper_tbl_storage_engine == 'BERKELEYDB');
1567 $is_pbxt = ($upper_tbl_storage_engine == 'PBXT');
1569 return array(
1570 $is_myisam_or_aria, $is_innodb, $is_isam,
1571 $is_berkeleydb, $is_aria, $is_pbxt
1576 * Get warning messages array
1578 * @return array $warning_messages
1580 function PMA_getWarningMessagesArray()
1582 $warning_messages = array();
1583 foreach ($GLOBALS['dbi']->getWarnings() as $warning) {
1584 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
1585 // and if TRANSACTIONAL was set, the system reports an error;
1586 // I discussed with a Maria developer and he agrees that this
1587 // should not be reported with a Level of Error, so here
1588 // I just ignore it. But there are other 1478 messages
1589 // that it's better to show.
1590 if (! ($_REQUEST['new_tbl_storage_engine'] == 'MyISAM'
1591 && $warning['Code'] == '1478'
1592 && $warning['Level'] == 'Error')
1594 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
1595 . ' ' . $warning['Message'];
1598 return $warning_messages;
1602 * Get SQL query and result after ran this SQL query for a partition operation
1603 * has been requested by the user
1605 * @return array $sql_query, $result
1607 function PMA_getQueryAndResultForPartition()
1609 $sql_query = 'ALTER TABLE '
1610 . PMA_Util::backquote($GLOBALS['table']) . ' '
1611 . $_REQUEST['partition_operation']
1612 . ' PARTITION '
1613 . $_REQUEST['partition_name'] . ';';
1614 $result = $GLOBALS['dbi']->query($sql_query);
1616 return array($sql_query, $result);