2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once './libraries/common.inc.php';
12 require_once './libraries/Table.class.php';
14 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
19 require './libraries/tbl_common.php';
20 $url_query .= '&goto=tbl_operations.php&back=tbl_operations.php';
21 $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
24 * Gets relation settings
26 require_once './libraries/relation.lib.php';
27 $cfgRelation = PMA_getRelationsParam();
30 * Gets available MySQL charsets and storage engines
32 require_once './libraries/mysql_charsets.lib.php';
33 require_once './libraries/StorageEngine.class.php';
35 // reselect current db (needed in some cases probably due to
36 // the calling of relation.lib.php)
37 PMA_DBI_select_db($GLOBALS['db']);
40 * Gets tables informations
43 require './libraries/tbl_info.inc.php';
47 $table_alters = array();
50 * Updates table comment, type and options if required
52 if (isset($_REQUEST['submitoptions'])) {
54 if (isset($_REQUEST['new_name'])) {
55 if ($pma_table->rename($_REQUEST['new_name'])) {
56 $message .= $pma_table->getLastMessage();
57 $GLOBALS['table'] = $pma_table->getName();;
61 $errors[] = $pma_table->getLastError();
62 $message .= $pma_table->getLastError();
65 if (isset($_REQUEST['comment'])
66 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
67 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
69 if (! empty($_REQUEST['new_tbl_type'])
70 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
71 $table_alters[] = PMA_ENGINE_KEYWORD
. ' = ' . $_REQUEST['new_tbl_type'];
72 $tbl_type = $_REQUEST['new_tbl_type'];
75 if (! empty($_REQUEST['tbl_collation'])
76 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
77 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
80 $l_tbl_type = strtolower($tbl_type);
82 if (($l_tbl_type === 'myisam' ||
$l_tbl_type === 'isam')
83 && isset($_REQUEST['new_pack_keys'])
84 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
85 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
88 $checksum = empty($checksum) ?
'0' : '1';
89 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ?
'0' : '1';
90 if (($l_tbl_type === 'myisam')
91 && $_REQUEST['new_checksum'] !== $checksum) {
92 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
95 $delay_key_write = empty($delay_key_write) ?
'0' : '1';
96 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ?
'0' : '1';
97 if (($l_tbl_type === 'myisam')
98 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
99 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
102 if (($l_tbl_type === 'myisam' ||
$l_tbl_type === 'innodb')
103 && ! empty($_REQUEST['new_auto_increment'])
104 && (! isset($auto_increment) ||
$_REQUEST['new_auto_increment'] !== $auto_increment)) {
105 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
108 if (count($table_alters) > 0) {
109 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
110 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
111 $message .= PMA_DBI_query($sql_query) ?
$strSuccess : $strError;
113 unset($table_alters);
117 * Reordering the table has been requested by the user
119 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
121 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
122 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
123 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
124 $sql_query .= ' DESC';
126 $message = PMA_DBI_query($sql_query) ?
$strSuccess : $strError;
131 $checksum = $delay_key_write = 0;
132 require './libraries/tbl_info.inc.php';
137 * Displays top menu links
139 require_once './libraries/tbl_links.inc.php';
141 $url_params['goto'] = 'tbl_operations.php';
142 $url_params['back'] = 'tbl_operations.php';
149 FROM ' . PMA_backquote($GLOBALS['table']) . '
150 FROM ' . PMA_backquote($GLOBALS['db']);
151 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
158 <!-- Order the table
-->
159 <div id
="div_table_order">
160 <form method
="post" action
="tbl_operations.php">
161 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
162 <fieldset id
="fieldset_table_order">
163 <legend
><?php
echo $strAlterOrderBy; ?
></legend
>
164 <select name
="order_field">
166 foreach ($columns as $fieldname) {
167 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
168 . htmlspecialchars($fieldname) . '</option>' . "\n";
172 </select
> <?php
echo $strSingly; ?
>
173 <select name
="order_order">
174 <option value
="asc"><?php
echo $strAscending; ?
></option
>
175 <option value
="desc"><?php
echo $strDescending; ?
></option
>
177 <input type
="submit" name
="submitorderby" value
="<?php echo $strGo; ?>" />
183 <div id
="div_table_rename">
184 <form method
="post" action
="tbl_move_copy.php"
185 onsubmit
="return emptyFormElements(this, 'new_name')">
186 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
187 <input type
="hidden" name
="reload" value
="1" />
188 <input type
="hidden" name
="what" value
="data" />
189 <fieldset id
="fieldset_table_rename">
190 <legend
><?php
echo $strMoveTable; ?
></legend
>
191 <?php
if ($GLOBALS['PMA_List_Database']->count() > $GLOBALS['cfg']['MaxDbList']) {
193 <input type
="text" maxlength
="100" size
="30" name
="target_db" value
="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
197 <select name
="target_db">
198 <?php
echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?
>
204 <input type
="text" size
="20" name
="new_name" onfocus
="this.select()"
205 value
="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br
/>
207 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
208 // next value but users can decide if they want it or not for the operation
210 <input type
="checkbox" name
="sql_auto_increment" value
="1" id
="checkbox_auto_increment_mv" checked
="checked" />
211 <label
for="checkbox_auto_increment_mv"><?php
echo $strAddAutoIncrement; ?
></label
><br
/>
213 <fieldset
class="tblFooters">
214 <input type
="submit" name
="submit_move" value
="<?php echo $strGo; ?>" />
220 if (strstr($show_comment, '; InnoDB free') === false) {
221 if (strstr($show_comment, 'InnoDB free') === false) {
222 // only user entered comment
223 $comment = $show_comment;
225 // here we have just InnoDB generated part
229 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
230 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
233 // PACK_KEYS: MyISAM or ISAM
234 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
235 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
237 // nijel: Here should be version check for InnoDB, however it is supported
238 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
242 <!-- Table options
-->
243 <div id
="div_table_options">
244 <form method
="post" action
="tbl_operations.php">
245 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
246 <input type
="hidden" name
="reload" value
="1" />
248 <legend
><?php
echo $strTableOptions; ?
></legend
>
251 <!-- Change table name
-->
252 <tr
><td
><?php
echo $strRenameTable; ?
></td
>
253 <td
><input type
="text" size
="20" name
="new_name" onfocus
="this.select()"
254 value
="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
258 <!-- Table comments
-->
259 <tr
><td
><?php
echo $strTableComments; ?
></td
>
260 <td
><input type
="text" name
="comment" maxlength
="60" size
="30"
261 value
="<?php echo htmlspecialchars($comment); ?>" onfocus
="this.select()" />
262 <input type
="hidden" name
="prev_comment" value
="<?php echo urlencode($comment); ?>" />
266 <!-- Storage engine
-->
267 <tr
><td
><?php
echo $strStorageEngine; ?
>
268 <?php
echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?
>
270 <td
><?php
echo PMA_StorageEngine
::getHtmlSelect('new_tbl_type', null, $tbl_type); ?
>
275 if (PMA_MYSQL_INT_VERSION
>= 40100) {
277 <!-- Table character set
-->
278 <tr
><td
><?php
echo $strCollation; ?
></td
>
279 <td
><?php
echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
280 'tbl_collation', null, $tbl_collation, false, 3); ?
>
285 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'ISAM') {
288 <td
><label
for="new_pack_keys">pack_keys
</label
></td
>
289 <td
><select name
="new_pack_keys" id
="new_pack_keys">
290 <option value
="DEFAULT"
291 <?php
if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?
>
294 <?php
if ($pack_keys == '0') echo 'selected="selected"'; ?
>
297 <?php
if ($pack_keys == '1') echo 'selected="selected"'; ?
>
303 } // end if (MYISAM|ISAM)
305 if ($tbl_type == 'MYISAM') {
307 <tr
><td
><label
for="new_checksum">checksum
</label
></td
>
308 <td
><input type
="checkbox" name
="new_checksum" id
="new_checksum"
310 <?php
echo (isset($checksum) && $checksum == 1)
311 ?
' checked="checked"'
316 <tr
><td
><label
for="new_delay_key_write">delay_key_write
</label
></td
>
317 <td
><input type
="checkbox" name
="new_delay_key_write" id
="new_delay_key_write"
319 <?php
echo (isset($delay_key_write) && $delay_key_write == 1)
320 ?
' checked="checked"'
328 if (isset($auto_increment) && strlen($auto_increment) > 0
329 && ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB')) {
331 <tr
><td
><label
for="auto_increment_opt">auto_increment
</label
></td
>
332 <td
><input type
="text" name
="new_auto_increment" id
="auto_increment_opt"
333 value
="<?php echo $auto_increment; ?>" /></td
>
336 } // end if (MYISAM|INNODB)
340 <fieldset
class="tblFooters">
341 <input type
="submit" name
="submitoptions" value
="<?php echo $strGo; ?>" />
347 <div id
="div_table_copy">
348 <form method
="post" action
="tbl_move_copy.php"
349 onsubmit
="return emptyFormElements(this, 'new_name')">
350 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
351 <input type
="hidden" name
="reload" value
="1" />
353 <legend
><?php
echo $strCopyTable; ?
></legend
>
354 <?php
if ($GLOBALS['PMA_List_Database']->count() > $GLOBALS['cfg']['MaxDbList']) {
356 <input type
="text" maxlength
="100" size
="30" name
="target_db" value
="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
360 <select name
="target_db">
361 <?php
echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?
>
367 <input type
="text" size
="20" name
="new_name" onfocus
="this.select()" /><br
/>
369 <input type
="radio" name
="what" value
="structure" id
="radio_copy_structure" />
370 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
><br
/>
371 <input type
="radio" name
="what" value
="data" id
="radio_copy_data" checked
="checked" />
372 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
><br
/>
373 <input type
="radio" name
="what" value
="dataonly" id
="radio_copy_dataonly" />
374 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
><br
/>
376 <input type
="checkbox" name
="drop_if_exists" value
="true" id
="checkbox_drop" />
377 <label
for="checkbox_drop"><?php
echo sprintf($strAddClause, 'DROP TABLE'); ?
></label
><br
/>
378 <input type
="checkbox" name
="sql_auto_increment" value
="1" id
="checkbox_auto_increment_cp" />
379 <label
for="checkbox_auto_increment_cp"><?php
echo $strAddAutoIncrement; ?
></label
><br
/>
381 // display "Add constraints" choice only if there are
383 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
385 <input type
="checkbox" name
="add_constraints" value
="1" id
="checkbox_constraints" />
386 <label
for="checkbox_constraints"><?php
echo $strAddConstraints; ?
></label
><br
/>
389 if (isset($_COOKIE['pma_switch_to_new'])
390 && $_COOKIE['pma_switch_to_new'] == 'true') {
391 $pma_switch_to_new = 'true';
394 <input type
="checkbox" name
="switch_to_new" value
="true"
395 id
="checkbox_switch"<?php
echo
396 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
397 ?
' checked="checked"'
399 <label
for="checkbox_switch"><?php
echo $strSwitchToTable; ?
></label
>
401 <fieldset
class="tblFooters">
402 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
407 <br
class="clearfloat"/>
409 <h1
><?php
echo $strTableMaintenance; ?
></h1
>
413 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
414 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB') {
415 $this_url_params = array_merge($url_params,
416 array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
418 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
419 <?php
echo $strCheckTable; ?
></a
>
420 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?
>
424 if ($tbl_type == 'INNODB') {
425 $this_url_params = array_merge($url_params,
426 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . PMA_ENGINE_KEYWORD
. '=InnoDB'));
428 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
429 <?php
echo $strDefragment; ?
></a
>
430 <?php
echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?
>
434 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB') {
435 $this_url_params = array_merge($url_params,
436 array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
438 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
439 <?php
echo $strAnalyzeTable; ?
></a
>
440 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?
>
444 if ($tbl_type == 'MYISAM') {
445 $this_url_params = array_merge($url_params,
446 array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
448 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
449 <?php
echo $strRepairTable; ?
></a
>
450 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?
>
454 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
455 $this_url_params = array_merge($url_params,
456 array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
458 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
459 <?php
echo $strOptimizeTable; ?
></a
>
460 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?
>
464 } // end MYISAM or BERKELEYDB case
465 $this_url_params = array_merge($url_params,
467 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
468 'zero_rows' => sprintf($strTableHasBeenFlushed,
469 htmlspecialchars($GLOBALS['table'])),
473 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
474 <?php
echo $strFlushTable; ?
></a
>
475 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?
>
479 // Referential integrity check
480 // The Referential integrity check was intended for the non-InnoDB
481 // tables for which the relations are defined in pmadb
482 // so I assume that if the current table is InnoDB, I don't display
483 // this choice (InnoDB maintains integrity by itself)
485 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
487 // we need this PMA_DBI_select_db if the user has access to more than one db
488 // and $GLOBALS['db'] is not the last of the list, because
489 // PMA_List_Database::_checkAccess()
490 // has made a PMA_DBI_select_db() on the last one
491 PMA_DBI_select_db($GLOBALS['db']);
492 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
496 <!-- Referential integrity check
-->
498 <?php
echo $strReferentialIntegrity; ?
><br
/>
501 foreach ($foreign AS $master => $arr) {
502 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
503 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
504 . PMA_backquote($arr['foreign_table']);
505 if ($arr['foreign_table'] == $GLOBALS['table']) {
506 $foreign_table = $GLOBALS['table'] . '1';
507 $join_query .= ' AS ' . PMA_backquote($foreign_table);
509 $foreign_table = $arr['foreign_table'];
511 $join_query .= ' ON '
512 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
513 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
515 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
517 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
519 $this_url_params = array_merge($url_params,
520 array('sql_query' => $join_query));
523 . PMA_generate_common_url($this_url_params)
524 . '">' . $master . ' -> ' . $arr['foreign_table'] . '.' . $arr['foreign_field']
525 . '</a></li>' . "\n";
526 } // foreach $foreign
527 unset($foreign_table, $join_query);
531 } // end if ($result)
533 } // end if (!empty($cfg['Server']['relation']))
537 * Displays the footer
539 require_once './libraries/footer.inc.php';