added japanese language
[openemr.git] / phpmyadmin / libraries / operations.lib.php
blobd4df2cd58ac3478e963ba79d467f1761cff617a4
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" id="formDatabaseComment">'
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="" required="required" />'
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="" required="required" /><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 $lowerCaseTableNames = $GLOBALS['dbi']->fetchValue(
336 'SHOW VARIABLES LIKE "lower_case_table_names"', 0, 1
338 if ($lowerCaseTableNames === '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 ExportSql $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, 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 ExportSql $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="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'])
794 . '" required="required" />'
795 . '</td>'
796 . '</tr>';
798 //Table comments
799 $html_output .= '<tr><td>' . __('Table comments') . '</td>'
800 . '<td><input type="text" name="comment" maxlength="60" size="30"'
801 . 'value="' . htmlspecialchars($comment) . '" onfocus="this.select()" />'
802 . '<input type="hidden" name="prev_comment" value="'
803 . htmlspecialchars($comment) . '" />'
804 . '</td>'
805 . '</tr>';
807 //Storage engine
808 $html_output .= '<tr><td>' . __('Storage Engine')
809 . PMA_Util::showMySQLDocu('Storage_engines')
810 . '</td>'
811 . '<td>'
812 . PMA_StorageEngine::getHtmlSelect(
813 'new_tbl_storage_engine', null, $tbl_storage_engine
815 . '</td>'
816 . '</tr>';
818 //Table character set
819 $html_output .= '<tr><td>' . __('Collation') . '</td>'
820 . '<td>'
821 . PMA_generateCharsetDropdownBox(
822 PMA_CSDROPDOWN_COLLATION,
823 'tbl_collation', null, $tbl_collation, false, 3
825 . '</td>'
826 . '</tr>';
828 if ($is_myisam_or_aria || $is_isam) {
829 $html_output .= '<tr>'
830 . '<td><label for="new_pack_keys">PACK_KEYS</label></td>'
831 . '<td><select name="new_pack_keys" id="new_pack_keys">';
833 $html_output .= '<option value="DEFAULT"';
834 if ($pack_keys == 'DEFAULT') {
835 $html_output .= 'selected="selected"';
837 $html_output .= '>DEFAULT</option>
838 <option value="0"';
839 if ($pack_keys == '0') {
840 $html_output .= 'selected="selected"';
842 $html_output .= '>0</option>
843 <option value="1" ';
844 if ($pack_keys == '1') {
845 $html_output .= 'selected="selected"';
847 $html_output .= '>1</option>'
848 . '</select>'
849 . '</td>'
850 . '</tr>';
851 } // end if (MYISAM|ISAM)
853 if ($is_myisam_or_aria) {
854 $html_output .= PMA_getHtmlForTableRow(
855 'new_checksum',
856 'CHECKSUM',
857 $checksum
860 $html_output .= PMA_getHtmlForTableRow(
861 'new_delay_key_write',
862 'DELAY_KEY_WRITE',
863 $delay_key_write
865 } // end if (MYISAM)
867 if ($is_aria) {
868 $html_output .= PMA_getHtmlForTableRow(
869 'new_transactional',
870 'TRANSACTIONAL',
871 $transactional
874 $html_output .= PMA_getHtmlForTableRow(
875 'new_page_checksum',
876 'PAGE_CHECKSUM',
877 $page_checksum
879 } // end if (ARIA)
881 if (strlen($auto_increment) > 0
882 && ($is_myisam_or_aria || $is_innodb || $is_pbxt)
884 $html_output .= '<tr><td>'
885 . '<label for="auto_increment_opt">AUTO_INCREMENT</label></td>'
886 . '<td><input type="number" name="new_auto_increment" '
887 . 'id="auto_increment_opt"'
888 . 'value="' . $auto_increment . '" /></td>'
889 . '</tr> ';
890 } // end if (MYISAM|INNODB)
892 $possible_row_formats = PMA_getPossibleRowFormat();
894 // for MYISAM there is also COMPRESSED but it can be set only by the
895 // myisampack utility, so don't offer here the choice because if we
896 // try it inside an ALTER TABLE, MySQL (at least in 5.1.23-maria)
897 // does not return a warning
898 // (if the table was compressed, it can be seen on the Structure page)
900 if (isset($possible_row_formats[$tbl_storage_engine])) {
901 $current_row_format = strtoupper($GLOBALS['showtable']['Row_format']);
902 $html_output .= '<tr><td>'
903 . '<label for="new_row_format">ROW_FORMAT</label></td>'
904 . '<td>';
905 $html_output .= PMA_Util::getDropdown(
906 'new_row_format', $possible_row_formats[$tbl_storage_engine],
907 $current_row_format, 'new_row_format'
909 $html_output .= '</td></tr>';
911 $html_output .= '</table>'
912 . '</fieldset>';
914 return $html_output;
918 * Get the common HTML table row (tr) for new_checksum, new_delay_key_write,
919 * new_transactional and new_page_checksum
921 * @param string $attribute class, name and id attribute
922 * @param string $label label value
923 * @param string $val checksum, delay_key_write, transactional, page_checksum
925 * @return string $html_output
927 function PMA_getHtmlForTableRow($attribute, $label, $val)
929 return '<tr>'
930 . '<td><label for="' . $attribute . '">' . $label . '</label></td>'
931 . '<td><input type="checkbox" name="' . $attribute . '"'
932 . ' id="' . $attribute . '"'
933 . ' value="1"'
934 . ((!empty($val) && $val == 1) ? ' checked="checked"' : '') . '/></td>'
935 . '</tr>';
939 * Get array of possible row formats
941 * @return array $possible_row_formats
943 function PMA_getPossibleRowFormat()
945 // the outer array is for engines, the inner array contains the dropdown
946 // option values as keys then the dropdown option labels
948 $possible_row_formats = array(
949 'ARIA' => array(
950 'FIXED' => 'FIXED',
951 'DYNAMIC' => 'DYNAMIC',
952 'PAGE' => 'PAGE'
954 'MARIA' => array(
955 'FIXED' => 'FIXED',
956 'DYNAMIC' => 'DYNAMIC',
957 'PAGE' => 'PAGE'
959 'MYISAM' => array(
960 'FIXED' => 'FIXED',
961 'DYNAMIC' => 'DYNAMIC'
963 'PBXT' => array(
964 'FIXED' => 'FIXED',
965 'DYNAMIC' => 'DYNAMIC'
967 'INNODB' => array(
968 'COMPACT' => 'COMPACT',
969 'REDUNDANT' => 'REDUNDANT'
973 $innodbEnginePlugin = PMA_StorageEngine::getEngine('innodb');
974 $innodbPluginVersion = $innodbEnginePlugin->getInnodbPluginVersion();
975 if (!empty($innodbPluginVersion)) {
976 $innodb_file_format = $innodbEnginePlugin->getInnodbFileFormat();
977 } else {
978 $innodb_file_format = '';
980 if ('Barracuda' == $innodb_file_format
981 && $innodbEnginePlugin->supportsFilePerTable()
983 $possible_row_formats['INNODB']['DYNAMIC'] = 'DYNAMIC';
984 $possible_row_formats['INNODB']['COMPRESSED'] = 'COMPRESSED';
987 return $possible_row_formats;
991 * Get HTML div for copy table
993 * @return string $html_output
995 function PMA_getHtmlForCopytable()
997 $html_output = '<div class="operations_half_width">';
998 $html_output .= '<form method="post" action="tbl_operations.php" '
999 . 'name="copyTable" '
1000 . 'id="copyTable" '
1001 . ' class="ajax" '
1002 . 'onsubmit="return emptyFormElements(this, \'new_name\')">'
1003 . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1004 . '<input type="hidden" name="reload" value="1" />';
1006 $html_output .= '<fieldset>';
1007 $html_output .= '<legend>'
1008 . __('Copy table to (database<b>.</b>table):') . '</legend>';
1010 if (count($GLOBALS['pma']->databases) > $GLOBALS['cfg']['MaxDbList']) {
1011 $html_output .= '<input class="halfWidth" type="text" maxlength="100" '
1012 . 'size="30" name="target_db" '
1013 . 'value="' . htmlspecialchars($GLOBALS['db']) . '"/>';
1014 } else {
1015 $html_output .= '<select class="halfWidth" name="target_db">'
1016 . $GLOBALS['pma']->databases->getHtmlOptions(true, false)
1017 . '</select>';
1019 $html_output .= '&nbsp;<strong>.</strong>&nbsp;';
1020 $html_output .= '<input class="halfWidth" type="text" required="required" '
1021 . 'size="20" name="new_name" onfocus="this.select()" '
1022 . 'value="' . htmlspecialchars($GLOBALS['table']) . '"/><br />';
1024 $choices = array(
1025 'structure' => __('Structure only'),
1026 'data' => __('Structure and data'),
1027 'dataonly' => __('Data only'));
1029 $html_output .= PMA_Util::getRadioFields(
1030 'what', $choices, 'data', true
1033 $html_output .= '<input type="checkbox" name="drop_if_exists" '
1034 . 'value="true" id="checkbox_drop" />'
1035 . '<label for="checkbox_drop">'
1036 . sprintf(__('Add %s'), 'DROP TABLE') . '</label><br />'
1037 . '<input type="checkbox" name="sql_auto_increment" '
1038 . 'value="1" id="checkbox_auto_increment_cp" />'
1039 . '<label for="checkbox_auto_increment_cp">'
1040 . __('Add AUTO_INCREMENT value') . '</label><br />';
1042 // display "Add constraints" choice only if there are
1043 // foreign keys
1044 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'foreign')) {
1045 $html_output .= '<input type="checkbox" name="add_constraints" '
1046 . 'value="1" id="checkbox_constraints" />';
1047 $html_output .= '<label for="checkbox_constraints">'
1048 . __('Add constraints') . '</label><br />';
1049 } // endif
1051 if (isset($_COOKIE['pma_switch_to_new'])
1052 && $_COOKIE['pma_switch_to_new'] == 'true'
1054 $pma_switch_to_new = 'true';
1057 $html_output .= '<input type="checkbox" name="switch_to_new" value="true"'
1058 . 'id="checkbox_switch"'
1059 . ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true')
1060 ? ' checked="checked"'
1061 : '' . '/>');
1062 $html_output .= '<label for="checkbox_switch">'
1063 . __('Switch to copied table') . '</label>'
1064 . '</fieldset>';
1066 $html_output .= '<fieldset class="tblFooters">'
1067 . '<input type="submit" name="submit_copy" value="' . __('Go') . '" />'
1068 . '</fieldset>'
1069 . '</form>'
1070 . '</div>';
1072 return $html_output;
1076 * Get HTML snippet for table maintence
1078 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1079 * @param boolean $is_innodb whether innodb or not
1080 * @param boolean $is_berkeleydb whether berkeleydb or not
1081 * @param array $url_params array of URL parameters
1083 * @return string $html_output
1085 function PMA_getHtmlForTableMaintenance(
1086 $is_myisam_or_aria, $is_innodb, $is_berkeleydb, $url_params
1088 $html_output = '<div class="operations_half_width">';
1089 $html_output .= '<fieldset>'
1090 . '<legend>' . __('Table maintenance') . '</legend>';
1091 $html_output .= '<ul id="tbl_maintenance">';
1093 // Note: BERKELEY (BDB) is no longer supported, starting with MySQL 5.1
1094 $html_output .= PMA_getListofMaintainActionLink(
1095 $is_myisam_or_aria, $is_innodb, $url_params, $is_berkeleydb
1098 $html_output .= '</ul>'
1099 . '</fieldset>'
1100 . '</div>';
1102 return $html_output;
1106 * Get HTML 'li' having a link of maintain action
1108 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1109 * @param boolean $is_innodb whether innodb or not
1110 * @param array $url_params array of URL parameters
1111 * @param boolean $is_berkeleydb whether berkeleydb or not
1113 * @return string $html_output
1115 function PMA_getListofMaintainActionLink($is_myisam_or_aria,
1116 $is_innodb, $url_params, $is_berkeleydb
1118 $html_output = '';
1120 if ($is_myisam_or_aria || $is_innodb || $is_berkeleydb) {
1121 if ($is_myisam_or_aria || $is_innodb) {
1122 $params = array(
1123 'sql_query' => 'CHECK TABLE '
1124 . PMA_Util::backquote($GLOBALS['table']),
1125 'table_maintenance' => 'Go',
1127 $html_output .= PMA_getMaintainActionlink(
1128 __('Check table'),
1129 $params,
1130 $url_params,
1131 'CHECK_TABLE'
1134 if ($is_innodb) {
1135 $params = array(
1136 'sql_query' => 'ALTER TABLE '
1137 . PMA_Util::backquote($GLOBALS['table'])
1138 . ' ENGINE = InnoDB;'
1140 $html_output .= PMA_getMaintainActionlink(
1141 __('Defragment table'),
1142 $params,
1143 $url_params,
1144 'InnoDB_File_Defragmenting',
1145 'Table_types'
1148 if ($is_innodb || $is_myisam_or_aria || $is_berkeleydb) {
1149 $params = array(
1150 'sql_query' => 'ANALYZE TABLE '
1151 . PMA_Util::backquote($GLOBALS['table']),
1152 'table_maintenance' => 'Go',
1154 $html_output .= PMA_getMaintainActionlink(
1155 __('Analyze table'),
1156 $params,
1157 $url_params,
1158 'ANALYZE_TABLE'
1161 if ($is_myisam_or_aria && !PMA_DRIZZLE) {
1162 $params = array(
1163 'sql_query' => 'REPAIR TABLE '
1164 . PMA_Util::backquote($GLOBALS['table']),
1165 'table_maintenance' => 'Go',
1167 $html_output .= PMA_getMaintainActionlink(
1168 __('Repair table'),
1169 $params,
1170 $url_params,
1171 'REPAIR_TABLE'
1174 if (($is_myisam_or_aria || $is_innodb || $is_berkeleydb)
1175 && !PMA_DRIZZLE
1177 $params = array(
1178 'sql_query' => 'OPTIMIZE TABLE '
1179 . PMA_Util::backquote($GLOBALS['table']),
1180 'table_maintenance' => 'Go',
1182 $html_output .= PMA_getMaintainActionlink(
1183 __('Optimize table'),
1184 $params,
1185 $url_params,
1186 'OPTIMIZE_TABLE'
1189 } // end MYISAM or BERKELEYDB case
1191 $params = array(
1192 'sql_query' => 'FLUSH TABLE '
1193 . PMA_Util::backquote($GLOBALS['table']),
1194 'message_to_show' => sprintf(
1195 __('Table %s has been flushed.'),
1196 htmlspecialchars($GLOBALS['table'])
1198 'reload' => 1,
1201 $html_output .= PMA_getMaintainActionlink(
1202 __('Flush the table (FLUSH)'),
1203 $params,
1204 $url_params,
1205 'FLUSH'
1208 return $html_output;
1212 * Get maintain action HTML link
1214 * @param string $action action name
1215 * @param array $params url parameters array
1216 * @param array $url_params additional url parameters
1217 * @param string $link contains name of page/anchor that is being linked
1219 * @return string $html_output
1221 function PMA_getMaintainActionlink($action, $params, $url_params, $link)
1223 return '<li>'
1224 . '<a class="maintain_action ajax" '
1225 . 'href="sql.php'
1226 . PMA_URL_getCommon(array_merge($url_params, $params)) . '">'
1227 . $action
1228 . '</a>'
1229 . PMA_Util::showMySQLDocu($link)
1230 . '</li>';
1234 * Get HTML for Delete data or table (truncate table, drop table)
1236 * @param array $truncate_table_url_params url parameter array for truncate table
1237 * @param array $dropTableUrlParams url parameter array for drop table
1239 * @return string $html_output
1241 function PMA_getHtmlForDeleteDataOrTable(
1242 $truncate_table_url_params,
1243 $dropTableUrlParams
1245 $html_output = '<div class="operations_half_width">'
1246 . '<fieldset class="caution">'
1247 . '<legend>' . __('Delete data or table') . '</legend>';
1249 $html_output .= '<ul>';
1251 if (! empty($truncate_table_url_params)) {
1252 $html_output .= PMA_getDeleteDataOrTablelink(
1253 $truncate_table_url_params,
1254 'TRUNCATE_TABLE',
1255 __('Empty the table (TRUNCATE)'),
1256 'truncate_tbl_anchor'
1259 if (!empty ($dropTableUrlParams)) {
1260 $html_output .= PMA_getDeleteDataOrTablelink(
1261 $dropTableUrlParams,
1262 'DROP_TABLE',
1263 __('Delete the table (DROP)'),
1264 'drop_tbl_anchor'
1267 $html_output .= '</ul></fieldset></div>';
1269 return $html_output;
1273 * Get the HTML link for Truncate table, Drop table and Drop db
1275 * @param array $url_params url parameter array for delete data or table
1276 * @param string $syntax TRUNCATE_TABLE or DROP_TABLE or DROP_DATABASE
1277 * @param string $link link to be shown
1278 * @param string $htmlId id of the link
1280 * @return String html output
1282 function PMA_getDeleteDataOrTablelink($url_params, $syntax, $link, $htmlId)
1284 return '<li><a '
1285 . 'href="sql.php' . PMA_URL_getCommon($url_params) . '"'
1286 . ' id="' . $htmlId . '" class="ajax">'
1287 . $link . '</a>'
1288 . PMA_Util::showMySQLDocu($syntax)
1289 . '</li>';
1293 * Get HTML snippet for partition maintenance
1295 * @param array $partition_names array of partition names for a specific db/table
1296 * @param array $url_params url parameters
1298 * @return string $html_output
1300 function PMA_getHtmlForPartitionMaintenance($partition_names, $url_params)
1302 $choices = array(
1303 'ANALYZE' => __('Analyze'),
1304 'CHECK' => __('Check'),
1305 'OPTIMIZE' => __('Optimize'),
1306 'REBUILD' => __('Rebuild'),
1307 'REPAIR' => __('Repair')
1310 $html_output = '<div class="operations_half_width">'
1311 . '<form method="post" action="tbl_operations.php">'
1312 . PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table'])
1313 . '<fieldset>'
1314 . '<legend>' . __('Partition maintenance') . '</legend>';
1316 $html_select = '<select name="partition_name">' . "\n";
1317 foreach ($partition_names as $one_partition) {
1318 $one_partition = htmlspecialchars($one_partition);
1319 $html_select .= '<option value="' . $one_partition . '">'
1320 . $one_partition . '</option>' . "\n";
1322 $html_select .= '</select>' . "\n";
1323 $html_output .= sprintf(__('Partition %s'), $html_select);
1325 $html_output .= PMA_Util::getRadioFields(
1326 'partition_operation', $choices, '', false
1328 $html_output .= PMA_Util::showMySQLDocu('partitioning_maintenance');
1329 $this_url_params = array_merge(
1330 $url_params,
1331 array(
1332 'sql_query' => 'ALTER TABLE '
1333 . PMA_Util::backquote($GLOBALS['table'])
1334 . ' REMOVE PARTITIONING;'
1337 $html_output .= '<br /><a href="sql.php'
1338 . PMA_URL_getCommon($this_url_params) . '">'
1339 . __('Remove partitioning') . '</a>';
1341 $html_output .= '</fieldset>'
1342 . '<fieldset class="tblFooters">'
1343 . '<input type="hidden" name="submit_partition" value="1">'
1344 . '<input type="submit" value="' . __('Go') . '" />'
1345 . '</fieldset>'
1346 . '</form>'
1347 . '</div>';
1349 return $html_output;
1353 * Get the HTML for Referential Integrity check
1355 * @param array $foreign all Relations to foreign tables for a given table
1356 * or optionally a given column in a table
1357 * @param array $url_params array of url parameters
1359 * @return string $html_output
1361 function PMA_getHtmlForReferentialIntegrityCheck($foreign, $url_params)
1363 $html_output = '<div class="operations_half_width">'
1364 . '<fieldset>'
1365 . '<legend>' . __('Check referential integrity:') . '</legend>';
1367 $html_output .= '<ul>';
1369 foreach ($foreign as $master => $arr) {
1370 $join_query = 'SELECT '
1371 . PMA_Util::backquote($GLOBALS['table']) . '.*'
1372 . ' FROM ' . PMA_Util::backquote($GLOBALS['table'])
1373 . ' LEFT JOIN '
1374 . PMA_Util::backquote($arr['foreign_db'])
1375 . '.'
1376 . PMA_Util::backquote($arr['foreign_table']);
1377 if ($arr['foreign_table'] == $GLOBALS['table']) {
1378 $foreign_table = $GLOBALS['table'] . '1';
1379 $join_query .= ' AS ' . PMA_Util::backquote($foreign_table);
1380 } else {
1381 $foreign_table = $arr['foreign_table'];
1383 $join_query .= ' ON '
1384 . PMA_Util::backquote($GLOBALS['table']) . '.'
1385 . PMA_Util::backquote($master)
1386 . ' = '
1387 . PMA_Util::backquote($arr['foreign_db'])
1388 . '.'
1389 . PMA_Util::backquote($foreign_table) . '.'
1390 . PMA_Util::backquote($arr['foreign_field'])
1391 . ' WHERE '
1392 . PMA_Util::backquote($arr['foreign_db'])
1393 . '.'
1394 . PMA_Util::backquote($foreign_table) . '.'
1395 . PMA_Util::backquote($arr['foreign_field'])
1396 . ' IS NULL AND '
1397 . PMA_Util::backquote($GLOBALS['table']) . '.'
1398 . PMA_Util::backquote($master)
1399 . ' IS NOT NULL';
1400 $this_url_params = array_merge(
1401 $url_params,
1402 array('sql_query' => $join_query)
1405 $html_output .= '<li>'
1406 . '<a href="sql.php'
1407 . PMA_URL_getCommon($this_url_params)
1408 . '">'
1409 . $master . '&nbsp;->&nbsp;' . $arr['foreign_db'] . '.'
1410 . $arr['foreign_table'] . '.' . $arr['foreign_field']
1411 . '</a></li>' . "\n";
1412 } // foreach $foreign
1413 $html_output .= '</ul></fieldset></div>';
1415 return $html_output;
1419 * Reorder table based on request params
1421 * @return array SQL query and result
1423 function PMA_getQueryAndResultForReorderingTable()
1425 $sql_query = 'ALTER TABLE '
1426 . PMA_Util::backquote($GLOBALS['table'])
1427 . ' ORDER BY '
1428 . PMA_Util::backquote(urldecode($_REQUEST['order_field']));
1429 if (isset($_REQUEST['order_order'])
1430 && $_REQUEST['order_order'] === 'desc'
1432 $sql_query .= ' DESC';
1434 $sql_query .= ';';
1435 $result = $GLOBALS['dbi']->query($sql_query);
1437 return array($sql_query, $result);
1441 * Get table alters array
1443 * @param boolean $is_myisam_or_aria whether MYISAM | ARIA or not
1444 * @param boolean $is_isam whether ISAM or not
1445 * @param string $pack_keys pack keys
1446 * @param string $checksum value of checksum
1447 * @param boolean $is_aria whether ARIA or not
1448 * @param string $page_checksum value of page checksum
1449 * @param string $delay_key_write delay key write
1450 * @param boolean $is_innodb whether INNODB or not
1451 * @param boolean $is_pbxt whether PBXT or not
1452 * @param string $row_format row format
1453 * @param string $newTblStorageEngine table storage engine
1454 * @param string $transactional value of transactional
1455 * @param string $tbl_collation collation of the table
1457 * @return array $table_alters
1459 function PMA_getTableAltersArray($is_myisam_or_aria, $is_isam, $pack_keys,
1460 $checksum, $is_aria, $page_checksum, $delay_key_write, $is_innodb,
1461 $is_pbxt, $row_format, $newTblStorageEngine, $transactional, $tbl_collation
1463 global $auto_increment;
1465 $table_alters = array();
1467 if (isset($_REQUEST['comment'])
1468 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']
1470 $table_alters[] = 'COMMENT = \''
1471 . PMA_Util::sqlAddSlashes($_REQUEST['comment']) . '\'';
1473 if (! empty($newTblStorageEngine)
1474 && strtolower($newTblStorageEngine) !== strtolower($GLOBALS['tbl_storage_engine'])
1476 $table_alters[] = 'ENGINE = ' . $newTblStorageEngine;
1478 if (! empty($_REQUEST['tbl_collation'])
1479 && $_REQUEST['tbl_collation'] !== $tbl_collation
1481 $table_alters[] = 'DEFAULT '
1482 . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
1485 if (($is_myisam_or_aria || $is_isam)
1486 && isset($_REQUEST['new_pack_keys'])
1487 && $_REQUEST['new_pack_keys'] != (string)$pack_keys
1489 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
1492 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
1493 if ($is_myisam_or_aria
1494 && $_REQUEST['new_checksum'] !== $checksum
1496 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
1499 $_REQUEST['new_transactional']
1500 = empty($_REQUEST['new_transactional']) ? '0' : '1';
1501 if ($is_aria
1502 && $_REQUEST['new_transactional'] !== $transactional
1504 $table_alters[] = 'TRANSACTIONAL = ' . $_REQUEST['new_transactional'];
1507 $_REQUEST['new_page_checksum']
1508 = empty($_REQUEST['new_page_checksum']) ? '0' : '1';
1509 if ($is_aria
1510 && $_REQUEST['new_page_checksum'] !== $page_checksum
1512 $table_alters[] = 'PAGE_CHECKSUM = ' . $_REQUEST['new_page_checksum'];
1515 $_REQUEST['new_delay_key_write']
1516 = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
1517 if ($is_myisam_or_aria
1518 && $_REQUEST['new_delay_key_write'] !== $delay_key_write
1520 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
1523 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
1524 && ! empty($_REQUEST['new_auto_increment'])
1525 && (! isset($auto_increment)
1526 || $_REQUEST['new_auto_increment'] !== $auto_increment)
1528 $table_alters[] = 'auto_increment = '
1529 . PMA_Util::sqlAddSlashes($_REQUEST['new_auto_increment']);
1532 if (($is_myisam_or_aria || $is_innodb || $is_pbxt)
1533 && ! empty($_REQUEST['new_row_format'])
1534 && (!strlen($row_format)
1535 || strtolower($_REQUEST['new_row_format']) !== strtolower($row_format))
1537 $table_alters[] = 'ROW_FORMAT = '
1538 . PMA_Util::sqlAddSlashes($_REQUEST['new_row_format']);
1541 return $table_alters;
1545 * set initial value of the set of variables, based on the current table engine
1547 * @param string $tbl_storage_engine table storage engine
1549 * @return array ($is_myisam_or_aria, $is_innodb, $is_isam,
1550 * $is_berkeleydb, $is_aria, $is_pbxt)
1552 function PMA_setGlobalVariablesForEngine($tbl_storage_engine)
1554 $upperTblStorEngine = strtoupper($tbl_storage_engine);
1556 //Options that apply to MYISAM usually apply to ARIA
1557 $is_myisam_or_aria = ($upperTblStorEngine == 'MYISAM'
1558 || $upperTblStorEngine == 'ARIA'
1559 || $upperTblStorEngine == 'MARIA'
1561 $is_aria = ($upperTblStorEngine == 'ARIA');
1563 $is_isam = ($upperTblStorEngine == 'ISAM');
1564 $is_innodb = ($upperTblStorEngine == 'INNODB');
1565 $is_berkeleydb = ($upperTblStorEngine == 'BERKELEYDB');
1566 $is_pbxt = ($upperTblStorEngine == 'PBXT');
1568 return array(
1569 $is_myisam_or_aria, $is_innodb, $is_isam,
1570 $is_berkeleydb, $is_aria, $is_pbxt
1575 * Get warning messages array
1577 * @return array $warning_messages
1579 function PMA_getWarningMessagesArray()
1581 $warning_messages = array();
1582 foreach ($GLOBALS['dbi']->getWarnings() as $warning) {
1583 // In MariaDB 5.1.44, when altering a table from Maria to MyISAM
1584 // and if TRANSACTIONAL was set, the system reports an error;
1585 // I discussed with a Maria developer and he agrees that this
1586 // should not be reported with a Level of Error, so here
1587 // I just ignore it. But there are other 1478 messages
1588 // that it's better to show.
1589 if (! ($_REQUEST['new_tbl_storage_engine'] == 'MyISAM'
1590 && $warning['Code'] == '1478'
1591 && $warning['Level'] == 'Error')
1593 $warning_messages[] = $warning['Level'] . ': #' . $warning['Code']
1594 . ' ' . $warning['Message'];
1597 return $warning_messages;
1601 * Get SQL query and result after ran this SQL query for a partition operation
1602 * has been requested by the user
1604 * @return array $sql_query, $result
1606 function PMA_getQueryAndResultForPartition()
1608 $sql_query = 'ALTER TABLE '
1609 . PMA_Util::backquote($GLOBALS['table']) . ' '
1610 . $_REQUEST['partition_operation']
1611 . ' PARTITION '
1612 . $_REQUEST['partition_name'] . ';';
1613 $result = $GLOBALS['dbi']->query($sql_query);
1615 return array($sql_query, $result);