3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once('./libraries/common.lib.php');
10 require('./tbl_properties_common.php');
11 //$err_url = 'tbl_properties_operations.php' . $err_url;
12 $url_query .= '&goto=tbl_properties_operations.php&back=tbl_properties_operations.php';
16 * Gets relation settings
18 require_once('./libraries/relation.lib.php');
19 $cfgRelation = PMA_getRelationsParam();
22 * Gets available MySQL charsets and storage engines
24 require_once('./libraries/mysql_charsets.lib.php');
25 require_once('./libraries/storage_engines.lib.php');
27 // reselect current db (needed in some cases probably due to
28 // the calling of relation.lib.php)
29 PMA_DBI_select_db($db);
34 * Updates table comment, type and options if required
36 if (isset($submitcomment)) {
37 if (empty($prev_comment) ||
urldecode($prev_comment) != $comment) {
38 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
39 $result = PMA_DBI_query($sql_query);
40 $message = $strSuccess;
44 if (isset($submittype)) {
45 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' TYPE = ' . $new_tbl_type;
46 $result = PMA_DBI_query($sql_query);
47 $message = $strSuccess;
50 if (isset($submitcollation)) {
51 // since something modifies $tbl_collation between the moment it is
52 // set from $_POST and this point, need to restore it
53 // (bug seen in MySQL 5.0.4)
54 $tbl_collation = $_POST['tbl_collation'];
55 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' DEFAULT' . PMA_generateCharsetQueryPart($tbl_collation);
56 $result = PMA_DBI_query($sql_query);
57 $message = $strSuccess;
58 unset($tbl_collation);
61 if (isset($submitoptions)) {
62 $sql_query = 'ALTER TABLE ' . PMA_backquote($table);
63 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'ISAM') {
64 $sql_query .= isset($new_pack_keys) ?
' pack_keys=1': ' pack_keys=0';
66 if ($tbl_type == 'MYISAM') {
67 $sql_query .= (isset($new_checksum) ?
' checksum=1': ' checksum=0')
68 . (isset($new_delay_key_write) ?
' delay_key_write=1': ' delay_key_write=0');
70 // nijel: Here should be version check for InnoDB, however it is supported
71 // in 5.0.x x>4, 4.1.y y>12 and also works in 4.0.11, so I decided not to
73 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB') {
74 $sql_query .= !empty($new_auto_increment) ?
' auto_increment=' . PMA_sqlAddslashes($new_auto_increment) : '';
76 $result = PMA_DBI_query($sql_query);
77 $message = $strSuccess;
82 require('./tbl_properties_table_info.php');
87 * Reordering the table has been requested by the user
89 if (isset($submitorderby) && !empty($order_field)) {
90 $sql_query = 'ALTER TABLE ' . PMA_backquote($table)
91 . ' ORDER BY ' . PMA_backquote(urldecode($order_field));
92 if (isset($order_order) && $order_order == 'desc') {
93 $sql_query .= ' DESC';
95 $result = PMA_DBI_query($sql_query);
96 $message = $result ?
$strSuccess : $strError;
100 * Gets tables informations
102 require_once('./tbl_properties_table_info.php');
105 * Displays top menu links
107 require_once('./tbl_properties_links.php');
112 $local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
113 $result = PMA_DBI_query($local_query);
114 for ($i = 0; $row = PMA_DBI_fetch_assoc($result); $i++
) {
115 $columns[$i] = $row['Field'];
117 PMA_DBI_free_result($result);
121 <table border
="0" align
="left" cellpadding
="3" cellspacing
="0">
128 if (PMA_MYSQL_INT_VERSION
>= 32334) {
130 <!-- Order the table
-->
132 <form method
="post" action
="tbl_properties_operations.php">
133 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
135 <th
class="tblHeaders" colspan
="2" align
="left"><?php
echo $strAlterOrderBy; ?
>: 
;</th
></tr
>
137 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
138 <select name
="order_field" style
="vertical-align: middle">
141 foreach ($columns AS $junk => $fieldname) {
142 echo ' <option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
146 </select
> 
;<?php
echo $strSingly . "\n"; ?
>
147 <select name
="order_order" style
="vertical-align: middle">
148 <option value
="asc"><?php
echo $strAscending; ?
></option
>
149 <option value
="desc"><?php
echo $strDescending; ?
></option
>
152 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>" align
="right">
153 <input type
="submit" name
="submitorderby" value
="<?php echo $strGo; ?>" style
="vertical-align: middle" />
157 <tr
><td colspan
="2" height
="5"></td
></tr
>
162 <!-- Change table name
-->
163 <form method
="post" action
="tbl_rename.php" onsubmit
="return emptyFormElements(this, 'new_name')">
165 <th
class="tblHeaders" colspan
="2" align
="left">
166 <?php
echo $strRenameTable; ?
>: 
;
167 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
168 <input type
="hidden" name
="reload" value
="1" />
172 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
173 <input type
="text" size
="20" name
="new_name" value
="<?php echo htmlspecialchars($table); ?>" class="textfield" onfocus
="this.select()" /> 
;
175 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>" align
="right">
176 <input type
="submit" value
="<?php echo $strGo; ?>" />
180 <tr
><td colspan
="2" height
="5"></td
></tr
>
182 <form method
="post" action
="tbl_move_copy.php" onsubmit
="return emptyFormElements(this, 'new_name')">
184 <th
class="tblHeaders" colspan
="2" align
="left">
185 <?php
echo $strMoveTable . "\n"; ?
>
186 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
187 <input type
="hidden" name
="reload" value
="1" />
188 <input type
="hidden" name
="what" value
="data" />
192 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>" nowrap
="nowrap">
193 <select name
="target_db">
195 // The function used below is defined in "common.lib.php"
196 PMA_availableDatabases('main.php?' . PMA_generate_common_url());
197 for ($i = 0; $i < $num_dbs; $i++
) {
199 echo '<option value="' . htmlspecialchars($dblist[$i]) . '">' . htmlspecialchars($dblist[$i]) . '</option>';
205 <input type
="text" size
="20" name
="new_name" value
="<?php echo htmlspecialchars($table); ?>" class="textfield" onfocus
="this.select()" />
207 <td align
="<?php echo $cell_align_right; ?>" bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
208 <input type
="submit" name
="submit_move" value
="<?php echo $strGo; ?>" />
212 <tr
><td colspan
="2" height
="5"></td
></tr
>
214 <form method
="post" action
="tbl_move_copy.php" onsubmit
="return emptyFormElements(this, 'new_name')">
216 <th
class="tblHeaders" colspan
="2" align
="left">
217 <?php
echo $strCopyTable . "\n"; ?
>
218 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
219 <input type
="hidden" name
="reload" value
="1" />
223 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>" colspan
="2" nowrap
="nowrap">
224 <select name
="target_db">
226 for ($i = 0; $i < $num_dbs; $i++
) {
228 echo '<option value="' . htmlspecialchars($dblist[$i]) . '"';
229 if ($dblist[$i] == $db) {
230 echo ' selected="selected"';
232 echo '>' . htmlspecialchars($dblist[$i]) . '</option>';
238 <input type
="text" size
="20" name
="new_name" class="textfield" onfocus
="this.select()" />
242 <td nowrap
="nowrap" bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
243 <input type
="radio" name
="what" value
="structure" id
="radio_copy_structure" style
="vertical-align: middle" /><label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
> 
; 
;<br
/>
244 <input type
="radio" name
="what" value
="data" id
="radio_copy_data" checked
="checked" style
="vertical-align: middle" /><label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
> 
; 
;<br
/>
245 <input type
="radio" name
="what" value
="dataonly" id
="radio_copy_dataonly" style
="vertical-align: middle" /><label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
> 
; 
;<br
/>
247 <input type
="checkbox" name
="drop_if_exists" value
="true" id
="checkbox_drop" style
="vertical-align: middle" /><label
for="checkbox_drop"><?php
echo $strStrucDrop; ?
></label
> 
; 
;<br
/>
248 <input type
="checkbox" name
="sql_auto_increment" value
="1" id
="checkbox_auto_increment" style
="vertical-align: middle" /><label
for="checkbox_auto_increment"><?php
echo $strAddAutoIncrement; ?
></label
><br
/>
250 // display "Add constraints" choice only if there are
252 if (PMA_getForeigners($db, $table, '', 'innodb')) {
254 <input type
="checkbox" name
="constraints" value
="1" id
="checkbox_constraints" style
="vertical-align: middle" /><label
for="checkbox_constraints"><?php
echo $strAddConstraints; ?
></label
><br
/>
257 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true') {
258 $pma_switch_to_new = 'true';
261 <input type
="checkbox" name
="switch_to_new" value
="true" id
="checkbox_switch"<?php
echo ((isset($pma_switch_to_new) && $pma_switch_to_new == 'true') ?
' checked="checked"' : ''); ?
> style
="vertical-align: middle" /><label
for="checkbox_switch"><?php
echo $strSwitchToTable; ?
></label
> 
; 
;
263 <td align
="<?php echo $cell_align_right; ?>" valign
="bottom" bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
264 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
268 <tr
><td colspan
="2" height
="5"></td
></tr
>
272 * Displays form controls
275 <!-- Table comments
-->
276 <form method
="post" action
="tbl_properties_operations.php">
278 <th colspan
="2" class="tblHeaders" align
="left">
280 echo PMA_generate_common_hidden_inputs($db, $table);
281 echo $strTableComments . ' ';
282 if (strstr($show_comment, '; InnoDB free') === FALSE) {
283 if (strstr($show_comment, 'InnoDB free') === FALSE) {
284 // only user entered comment
285 $comment = $show_comment;
287 // here we have just InnoDB generated part
291 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
292 $comment = preg_replace('@; InnoDB free:.*?$@' , '', $show_comment);
295 <input type
="hidden" name
="prev_comment" value
="<?php echo urlencode($comment); ?>" /> 
;
298 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
299 <input type
="text" name
="comment" maxlength
="60" size
="30" value
="<?php echo htmlspecialchars($comment); ?>" class="textfield" style
="vertical-align: middle" onfocus
="this.select()" /> 
;
301 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>" align
="right">
302 <input type
="submit" name
="submitcomment" value
="<?php echo $strGo; ?>" style
="vertical-align: middle" />
306 <tr
><td colspan
="2" height
="5"></td
></tr
>
309 // modify robbat2 code - staybyte - 11. June 2001
310 $result = PMA_DBI_query('SHOW VARIABLES LIKE \'have_%\';');
312 while ($tmp = PMA_DBI_fetch_assoc($result)) {
313 if (isset($tmp['Variable_name'])) {
314 switch ($tmp['Variable_name']) {
316 if ($tmp['Value'] == 'YES') {
321 if ($tmp['Value'] == 'YES') {
326 if ($tmp['Value'] == 'YES') {
331 if ($tmp['Value'] == 'YES') {
336 } // end if isset($tmp['Variable_name'])
340 PMA_DBI_free_result($result);
343 <form method
="post" action
="tbl_properties_operations.php">
345 <th colspan
="2" class="tblHeaders" align
="left">
346 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
347 <?php
echo $strTableType; ?
>: 
;
348 <?php
echo PMA_showMySQLDocu('Table_types', 'Table_types') . "\n"; ?
>
352 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
353 <?php
echo PMA_generateEnginesDropdown('new_tbl_type', NULL, FALSE, $tbl_type, 4); ?
>
355 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>" align
="right">
356 <input type
="submit" name
="submittype" value
="<?php echo $strGo; ?>" />
360 <tr
><td colspan
="2" height
="5"></td
></tr
>
363 if (PMA_MYSQL_INT_VERSION
>= 40100) {
365 . '<!-- Table character set -->' . "\n"
366 . ' <form method="post" action="tbl_properties_operations.php">' . "\n"
368 . ' <th colspan="2" class="tblHeaders" align="left">' . "\n"
369 . PMA_generate_common_hidden_inputs($db, $table, 3)
370 . ' ' . $strCollation . ': ' . "\n"
374 . ' <td bgcolor="' . $cfg['BgcolorOne'] . '">' . "\n"
375 . PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION
, 'tbl_collation', NULL, $tbl_collation, FALSE, 3)
377 . ' <td bgcolor="' . $cfg['BgcolorOne'] . '" align="right">' . "\n"
378 . ' <input type="submit" name="submitcollation" value="' . $strGo . '" style="vertical-align: middle" />' . "\n"
382 . ' <tr><td colspan="2" height="5"></td></tr>' . "\n";
384 // PACK_KEYS: MyISAM or ISAM
385 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
386 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
388 // nijel: Here should be version check for InnoDB, however it is supported
389 // in 5.0.x x>4, 4.1.y y>12 and also works in 4.0.11, so I decided not to
391 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'ISAM' ||
$tbl_type == 'INNODB') {
393 <!-- Table options
-->
394 <form method
="post" action
="tbl_properties_operations.php">
396 <th colspan
="2" class="tblHeaders" align
="left">
397 <?php
echo $strTableOptions; ?
>: 
;
398 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
402 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
404 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'ISAM') {
406 <input type
="checkbox" name
="new_pack_keys" id
="pack_keys_opt"
407 <?php
echo (isset($pack_keys) && $pack_keys == 1) ?
' checked="checked"' : ''; ?
> style
="vertical-align: middle" /><label
for="pack_keys_opt">pack_keys
</label
><br
/>
409 } // end if (MYISAM|ISAM)
410 if ($tbl_type == 'MYISAM') {
412 <input type
="checkbox" name
="new_checksum" id
="checksum_opt"
413 <?php
echo (isset($checksum) && $checksum == 1) ?
' checked="checked"' : ''; ?
> style
="vertical-align: middle" /><label
for="checksum_opt">checksum
</label
><br
/>
415 <input type
="checkbox" name
="new_delay_key_write" id
="delay_key_write_opt"
416 <?php
echo (isset($delay_key_write) && $delay_key_write == 1) ?
' checked="checked"' : ''; ?
> style
="vertical-align: middle" /><label
for="delay_key_write_opt">delay_key_write
</label
><br
/>
420 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB') {
422 <input type
="text" name
="new_auto_increment" id
="auto_increment_opt" class="textfield"
423 <?php
echo (isset($auto_increment) && !empty($auto_increment) ?
' value="' . $auto_increment . '"' : ''); ?
> style
="width: 30px; vertical-align: middle" /> 
;<label
for="auto_increment_opt">auto_increment
</label
>
426 } // end if (MYISAM|INNODB)
428 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>" align
="right" valign
="bottom">
429 <input type
="submit" name
="submitoptions" value
="<?php echo $strGo; ?>" />
434 } // end if (MYISAM or ISAM)
437 <img src
="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>" width
="25" height
="1" border
="0" align
="left" />
439 <table border
="0" cellpadding
="3" cellspacing
="0">
441 <th
class="tblHeaders" colspan
="2" align
="left">
442 <?php
echo $strTableMaintenance; ?
>
446 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
448 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB') {
451 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
452 <a href
="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('CHECK TABLE ' . PMA_backquote($table)); ?>">
453 <?php
echo $strCheckTable; ?
></a
> 
;
455 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
456 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE') . "\n"; ?
>
462 if ($tbl_type == 'INNODB') {
465 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
466 <a href
="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . PMA_backquote($table) . ' TYPE=InnoDB'); ?>">
467 <?php
echo $strDefragment; ?
></a
> 
;
469 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
470 <?php
echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting') . "\n"; ?
>
476 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB') {
479 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
480 <a href
="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ANALYZE TABLE ' . PMA_backquote($table)); ?>">
481 <?php
echo $strAnalyzeTable; ?
></a
> 
;
483 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
484 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE') . "\n";?
>
490 if ($tbl_type == 'MYISAM') {
493 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
494 <a href
="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('REPAIR TABLE ' . PMA_backquote($table)); ?>">
495 <?php
echo $strRepairTable; ?
></a
> 
;
497 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
498 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE') . "\n"; ?
>
504 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB') {
507 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
508 <a href
="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>">
509 <?php
echo $strOptimizeTable; ?
></a
> 
;
511 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
512 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE') . "\n"; ?
>
520 } // end MYISAM or BERKELEYDB case
524 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
525 <a href
="sql.php?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('FLUSH TABLE ' . PMA_backquote($table)); ?>&zero_rows=<?php echo urlencode(sprintf($strTableHasBeenFlushed, htmlspecialchars($table))); if ($cfg['ShowTooltip']) echo '&reload=1'; ?>">
526 <?php
echo $strFlushTable; ?
></a
> 
;
528 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>">
529 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH') . "\n"; ?
>
534 // Referential integrity check
535 // The Referential integrity check was intended for the non-InnoDB
536 // tables for which the relations are defined in pmadb
537 // so I assume that if the current table is InnoDB, I don't display
538 // this choice (InnoDB maintains integrity by itself)
540 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
542 // we need this PMA_DBI_select_db if the user has access to more than one db
543 // and $db is not the last of the list, because PMA_availableDatabases()
544 // has made a PMA_DBI_select_db() on the last one
545 PMA_DBI_select_db($db);
546 $foreign = PMA_getForeigners($db, $table);
550 <!-- Referential integrity check
-->
552 <td bgcolor
="<?php echo $cfg['BgcolorOne']; ?>" colspan
="2">
553 <?php
echo $strReferentialIntegrity; ?
><br
/>
556 foreach ($foreign AS $master => $arr) {
557 $join_query = 'SELECT ' . PMA_backquote($table) . '.* FROM '
558 . PMA_backquote($table) . ' LEFT JOIN '
559 . PMA_backquote($arr['foreign_table']);
560 if ($arr['foreign_table'] == $table) {
561 $foreign_table = $table . '1';
562 $join_query .= ' AS ' . PMA_backquote($foreign_table);
564 $foreign_table = $arr['foreign_table'];
566 $join_query .= ' ON '
567 . PMA_backquote($table) . '.' . PMA_backquote($master)
568 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
570 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
572 . PMA_backquote($table) . '.' . PMA_backquote($master)
575 . '<a href="sql.php?' . $url_query
577 . urlencode($join_query)
578 . '">' . $master . ' -> ' . $arr['foreign_table'] . '.' . $arr['foreign_field']
579 . '</a><br />' . "\n";
580 unset($foreign_table);
587 } // end if ($result)
590 } // end if (!empty($cfg['Server']['relation']))
596 * Displays the footer
599 require_once('./footer.inc.php');