3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once './libraries/common.lib.php';
6 require_once './libraries/Table.class.php';
8 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
13 require './libraries/tbl_properties_common.php';
14 $url_query .= '&goto=tbl_properties_operations.php&back=tbl_properties_operations.php';
15 $url_params['goto'] = $url_params['back'] = 'tbl_properties_operations.php';
18 * Gets relation settings
20 require_once './libraries/relation.lib.php';
21 $cfgRelation = PMA_getRelationsParam();
24 * Gets available MySQL charsets and storage engines
26 require_once './libraries/mysql_charsets.lib.php';
27 require_once './libraries/storage_engines.lib.php';
29 // reselect current db (needed in some cases probably due to
30 // the calling of relation.lib.php)
31 PMA_DBI_select_db($GLOBALS['db']);
34 * Gets tables informations
37 require './libraries/tbl_properties_table_info.inc.php';
41 $table_alters = array();
44 * Updates table comment, type and options if required
46 if (isset($_REQUEST['submitoptions'])) {
48 if (isset($_REQUEST['new_name'])) {
49 if ($pma_table->rename($_REQUEST['new_name'])) {
50 $message .= $pma_table->getLastMessage();
51 $GLOBALS['table'] = $pma_table->getName();;
55 $errors[] = $pma_table->getLastError();
56 $message .= $pma_table->getLastError();
59 if (isset($_REQUEST['comment'])
60 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
61 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
63 if (! empty($_REQUEST['new_tbl_type'])
64 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
65 $table_alters[] = PMA_ENGINE_KEYWORD
. ' = ' . $_REQUEST['new_tbl_type'];
66 $tbl_type = $_REQUEST['new_tbl_type'];
69 if (! empty($_REQUEST['tbl_collation'])
70 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
71 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
74 $l_tbl_type = strtolower($tbl_type);
76 $pack_keys = empty($pack_keys) ?
'0' : '1';
77 $_REQUEST['new_pack_keys'] = empty($_REQUEST['new_pack_keys']) ?
'0' : '1';
78 if (($l_tbl_type === 'myisam' ||
$l_tbl_type === 'isam')
79 && $_REQUEST['new_pack_keys'] !== $pack_keys) {
80 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
83 $checksum = empty($checksum) ?
'0' : '1';
84 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ?
'0' : '1';
85 if (($l_tbl_type === 'myisam')
86 && $_REQUEST['new_checksum'] !== $checksum) {
87 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
90 $delay_key_write = empty($delay_key_write) ?
'0' : '1';
91 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ?
'0' : '1';
92 if (($l_tbl_type === 'myisam')
93 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
94 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
97 if (($l_tbl_type === 'myisam' ||
$l_tbl_type === 'innodb')
98 && ! empty($_REQUEST['new_auto_increment'])
99 && (! isset($auto_increment) ||
$_REQUEST['new_auto_increment'] !== $auto_increment)) {
100 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
103 if (count($table_alters) > 0) {
104 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
105 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
106 $message .= PMA_DBI_query($sql_query) ?
$strSuccess : $strError;
108 unset($table_alters);
112 * Reordering the table has been requested by the user
114 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
116 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
117 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
118 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
119 $sql_query .= ' DESC';
121 $message = PMA_DBI_query($sql_query) ?
$strSuccess : $strError;
126 $pack_keys = $checksum = $delay_key_write = 0;
127 require './libraries/tbl_properties_table_info.inc.php';
132 * Displays top menu links
134 require_once './libraries/tbl_properties_links.inc.php';
136 $url_params['goto'] = 'tbl_properties_operations.php';
137 $url_params['back'] = 'tbl_properties_operations.php';
144 FROM ' . PMA_backquote($GLOBALS['table']) . '
145 FROM ' . PMA_backquote($GLOBALS['db']);
146 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
153 <!-- Order the table
-->
154 <div id
="div_table_order">
155 <form method
="post" action
="tbl_properties_operations.php">
156 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
157 <fieldset id
="fieldset_table_order">
158 <legend
><?php
echo $strAlterOrderBy; ?
></legend
>
159 <select name
="order_field">
161 foreach ($columns as $fieldname) {
162 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
163 . htmlspecialchars($fieldname) . '</option>' . "\n";
167 </select
> <?php
echo $strSingly; ?
>
168 <select name
="order_order">
169 <option value
="asc"><?php
echo $strAscending; ?
></option
>
170 <option value
="desc"><?php
echo $strDescending; ?
></option
>
172 <input type
="submit" name
="submitorderby" value
="<?php echo $strGo; ?>" />
178 <div id
="div_table_rename">
179 <form method
="post" action
="tbl_move_copy.php"
180 onsubmit
="return emptyFormElements(this, 'new_name')">
181 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
182 <input type
="hidden" name
="reload" value
="1" />
183 <input type
="hidden" name
="what" value
="data" />
184 <fieldset id
="fieldset_table_rename">
185 <legend
><?php
echo $strMoveTable; ?
></legend
>
186 <select name
="target_db">
188 // The function used below is defined in "common.lib.php"
189 PMA_availableDatabases('main.php?' . PMA_generate_common_url());
190 foreach ($dblist as $each_db) {
192 echo '<option value="' . htmlspecialchars($each_db) . '">'
193 . htmlspecialchars($each_db) . '</option>';
195 } // end foreach $dblist
199 <input type
="text" size
="20" name
="new_name" onfocus
="this.select()"
200 value
="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
201 <input type
="submit" name
="submit_move" value
="<?php echo $strGo; ?>" />
207 if (strstr($show_comment, '; InnoDB free') === false) {
208 if (strstr($show_comment, 'InnoDB free') === false) {
209 // only user entered comment
210 $comment = $show_comment;
212 // here we have just InnoDB generated part
216 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
217 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
220 // PACK_KEYS: MyISAM or ISAM
221 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
222 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
224 // nijel: Here should be version check for InnoDB, however it is supported
225 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
229 <!-- Table options
-->
230 <div id
="div_table_options">
231 <form method
="post" action
="tbl_properties_operations.php">
232 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
233 <input type
="hidden" name
="reload" value
="1" />
235 <legend
><?php
echo $strTableOptions; ?
></legend
>
238 <!-- Change table name
-->
239 <tr
><td
><?php
echo $strRenameTable; ?
></td
>
240 <td
><input type
="text" size
="20" name
="new_name" onfocus
="this.select()"
241 value
="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
245 <!-- Table comments
-->
246 <tr
><td
><?php
echo $strTableComments; ?
></td
>
247 <td
><input type
="text" name
="comment" maxlength
="60" size
="30"
248 value
="<?php echo htmlspecialchars($comment); ?>" onfocus
="this.select()" />
249 <input type
="hidden" name
="prev_comment" value
="<?php echo urlencode($comment); ?>" />
253 <!-- Storage engine
-->
254 <tr
><td
><?php
echo $strStorageEngine; ?
>
255 <?php
echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?
>
257 <td
><?php
echo PMA_generateEnginesDropdown('new_tbl_type', null, false, $tbl_type, 4); ?
>
262 if (PMA_MYSQL_INT_VERSION
>= 40100) {
264 <!-- Table character set
-->
265 <tr
><td
><?php
echo $strCollation; ?
></td
>
266 <td
><?php
echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
,
267 'tbl_collation', null, $tbl_collation, false, 3); ?
>
272 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'ISAM') {
275 <td
><label
for="new_pack_keys">pack_keys
</label
></td
>
276 <td
><input type
="checkbox" name
="new_pack_keys" id
="new_pack_keys"
278 <?php
echo (isset($pack_keys) && $pack_keys == 1)
279 ?
' checked="checked"'
284 } // end if (MYISAM|ISAM)
286 if ($tbl_type == 'MYISAM') {
288 <tr
><td
><label
for="new_checksum">checksum
</label
></td
>
289 <td
><input type
="checkbox" name
="new_checksum" id
="new_checksum"
291 <?php
echo (isset($checksum) && $checksum == 1)
292 ?
' checked="checked"'
297 <tr
><td
><label
for="new_delay_key_write">delay_key_write
</label
></td
>
298 <td
><input type
="checkbox" name
="new_delay_key_write" id
="new_delay_key_write"
300 <?php
echo (isset($delay_key_write) && $delay_key_write == 1)
301 ?
' checked="checked"'
309 if (isset($auto_increment) && strlen($auto_increment) > 0
310 && ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB')) {
312 <tr
><td
><label
for="auto_increment_opt">auto_increment
</label
></td
>
313 <td
><input type
="text" name
="new_auto_increment" id
="auto_increment_opt"
314 value
="<?php echo $auto_increment; ?>" /></td
>
317 } // end if (MYISAM|INNODB)
321 <fieldset
class="tblFooters">
322 <input type
="submit" name
="submitoptions" value
="<?php echo $strGo; ?>" />
328 <div id
="div_table_copy">
329 <form method
="post" action
="tbl_move_copy.php"
330 onsubmit
="return emptyFormElements(this, 'new_name')">
331 <?php
echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?
>
332 <input type
="hidden" name
="reload" value
="1" />
334 <legend
><?php
echo $strCopyTable; ?
></legend
>
335 <select name
="target_db">
337 foreach ($dblist as $each_db) {
339 echo '<option value="' . htmlspecialchars($each_db) . '"';
340 if ($each_db === $GLOBALS['db']) {
341 echo ' selected="selected"';
343 echo '>' . htmlspecialchars($each_db) . '</option>';
345 } // end foreach $dblist
349 <input type
="text" size
="20" name
="new_name" onfocus
="this.select()" /><br
/>
351 <input type
="radio" name
="what" value
="structure" id
="radio_copy_structure" />
352 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
><br
/>
353 <input type
="radio" name
="what" value
="data" id
="radio_copy_data" checked
="checked" />
354 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
><br
/>
355 <input type
="radio" name
="what" value
="dataonly" id
="radio_copy_dataonly" />
356 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
><br
/>
358 <input type
="checkbox" name
="drop_if_exists" value
="true" id
="checkbox_drop" />
359 <label
for="checkbox_drop"><?php
echo sprintf($strAddClause, 'DROP TABLE'); ?
></label
><br
/>
360 <input type
="checkbox" name
="sql_auto_increment" value
="1" id
="checkbox_auto_increment" />
361 <label
for="checkbox_auto_increment"><?php
echo $strAddAutoIncrement; ?
></label
><br
/>
363 // display "Add constraints" choice only if there are
365 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
367 <input type
="checkbox" name
="constraints" value
="1" id
="checkbox_constraints" />
368 <label
for="checkbox_constraints"><?php
echo $strAddConstraints; ?
></label
><br
/>
371 if (isset($_COOKIE['pma_switch_to_new'])
372 && $_COOKIE['pma_switch_to_new'] == 'true') {
373 $pma_switch_to_new = 'true';
376 <input type
="checkbox" name
="switch_to_new" value
="true"
377 id
="checkbox_switch"<?php
echo
378 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
379 ?
' checked="checked"'
381 <label
for="checkbox_switch"><?php
echo $strSwitchToTable; ?
></label
>
383 <fieldset
class="tblFooters">
384 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
389 <br
class="clearfloat"/>
391 <h1
><?php
echo $strTableMaintenance; ?
></h1
>
395 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
396 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB') {
397 $this_url_params = array_merge($url_params,
398 array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
400 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
401 <?php
echo $strCheckTable; ?
></a
>
402 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?
>
406 if ($tbl_type == 'INNODB') {
407 $this_url_params = array_merge($url_params,
408 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . PMA_ENGINE_KEYWORD
. '=InnoDB'));
410 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
411 <?php
echo $strDefragment; ?
></a
>
412 <?php
echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?
>
416 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB') {
417 $this_url_params = array_merge($url_params,
418 array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
420 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
421 <?php
echo $strAnalyzeTable; ?
></a
>
422 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?
>
426 if ($tbl_type == 'MYISAM') {
427 $this_url_params = array_merge($url_params,
428 array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
430 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
431 <?php
echo $strRepairTable; ?
></a
>
432 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?
>
436 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
437 $this_url_params = array_merge($url_params,
438 array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
440 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
441 <?php
echo $strOptimizeTable; ?
></a
>
442 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?
>
446 } // end MYISAM or BERKELEYDB case
447 $this_url_params = array_merge($url_params,
449 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
450 'zero_rows' => sprintf($strTableHasBeenFlushed,
451 htmlspecialchars($GLOBALS['table'])),
455 <li
><a href
="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
456 <?php
echo $strFlushTable; ?
></a
>
457 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?
>
461 // Referential integrity check
462 // The Referential integrity check was intended for the non-InnoDB
463 // tables for which the relations are defined in pmadb
464 // so I assume that if the current table is InnoDB, I don't display
465 // this choice (InnoDB maintains integrity by itself)
467 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
469 // we need this PMA_DBI_select_db if the user has access to more than one db
470 // and $GLOBALS['db'] is not the last of the list, because PMA_availableDatabases()
471 // has made a PMA_DBI_select_db() on the last one
472 PMA_DBI_select_db($GLOBALS['db']);
473 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
477 <!-- Referential integrity check
-->
479 <?php
echo $strReferentialIntegrity; ?
><br
/>
482 foreach ($foreign AS $master => $arr) {
483 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
484 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
485 . PMA_backquote($arr['foreign_table']);
486 if ($arr['foreign_table'] == $GLOBALS['table']) {
487 $foreign_table = $GLOBALS['table'] . '1';
488 $join_query .= ' AS ' . PMA_backquote($foreign_table);
490 $foreign_table = $arr['foreign_table'];
492 $join_query .= ' ON '
493 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
494 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
496 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
498 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
500 $this_url_params = array_merge($url_params,
501 array('sql_query' => $join_query));
504 . PMA_generate_common_url($this_url_params)
505 . '">' . $master . ' -> ' . $arr['foreign_table'] . '.' . $arr['foreign_field']
506 . '</a></li>' . "\n";
507 } // foreach $foreign
508 unset($foreign_table, $join_query);
512 } // end if ($result)
514 } // end if (!empty($cfg['Server']['relation']))
518 * Displays the footer
520 require_once './libraries/footer.inc.php';