3 // vim: expandtab sw=4 ts=4 sts=4:
9 require('./tbl_properties_common.php3');
10 //$err_url = 'tbl_properties_operations.php3' . $err_url;
11 $url_query .= '&goto=tbl_properties_operations.php3&back=tbl_properties_operations.php3';
15 * Gets relation settings
17 require('./libraries/relation.lib.php3');
18 $cfgRelation = PMA_getRelationsParam();
21 * Gets available MySQL charsets
23 if (PMA_MYSQL_INT_VERSION
>= 40100 && !defined('PMA_MYSQL_CHARSETS_LIB_INCLUDED')) {
24 include('./libraries/mysql_charsets.lib.php3');
28 * Updates table comment, type and options if required
30 if (isset($submitcomment)) {
31 if (empty($prev_comment) ||
urldecode($prev_comment) != $comment) {
32 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\'';
33 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url);
34 $message = $strSuccess;
37 if (isset($submittype)) {
38 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' TYPE = ' . $tbl_type;
39 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url);
40 $message = $strSuccess;
42 if (isset($submitcharset)) {
43 $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' CHARACTER SET = ' . $tbl_charset;
44 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url);
45 $message = $strSuccess;
47 if (isset($submitoptions)) {
48 $sql_query = 'ALTER TABLE ' . PMA_backquote($table)
49 . (isset($pack_keys) ?
' pack_keys=1': ' pack_keys=0')
50 . (isset($checksum) ?
' checksum=1': ' checksum=0')
51 . (isset($delay_key_write) ?
' delay_key_write=1': ' delay_key_write=0')
52 . (isset($auto_increment) ?
' auto_increment=' . PMA_sqlAddslashes($auto_increment) : '');
53 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url);
54 $message = $strSuccess;
57 // Displays a message if a query had been submitted
58 if (isset($message)) {
59 PMA_showMessage($message);
65 * Reordering the table has been requested by the user
67 if (isset($submitorderby) && !empty($order_field)) {
68 $sql_query = 'ALTER TABLE ' . PMA_backquote($table)
69 . ' ORDER BY ' . PMA_backquote(urldecode($order_field));
70 $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $err_url);
71 PMA_showMessage($strSuccess);
76 * Gets tables informations and displays top links
78 require('./tbl_properties_table_info.php3');
84 $local_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db);
85 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url);
86 for ($i = 0; $row = PMA_mysql_fetch_array($result); $i++
) {
87 $columns[$i] = $row['Field'];
89 mysql_free_result($result);
99 if (PMA_MYSQL_INT_VERSION
>= 32334) {
101 <!-- Order the table
-->
103 <form method
="post" action
="tbl_properties_operations.php3">
104 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
105 <?php
echo $strAlterOrderBy; ?
> 
;:
106 <select name
="order_field" style
="vertical-align: middle">
110 while (list($junk, $fieldname) = each($columns)) {
111 echo ' <option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
116 <input type
="submit" name
="submitorderby" value
="<?php echo $strGo; ?>" style
="vertical-align: middle" />
117  
;<?php
echo $strSingly . "\n"; ?
>
125 <!-- Change table name
-->
127 <form method
="post" action
="tbl_rename.php3"
128 onsubmit
="return emptyFormElements(this, 'new_name')">
129 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
130 <input type
="hidden" name
="reload" value
="1" />
131 <?php
echo $strRenameTable; ?
> 
;:
132 <input type
="text" size
="20" name
="new_name" value
="<?php echo htmlspecialchars($table); ?>" class="textfield" onfocus
="this.select()" /> 
;
133 <input type
="submit" value
="<?php echo $strGo; ?>" />
139 <?php
echo $strMoveTable . "\n"; ?
>
140 <form method
="post" action
="tbl_move_copy.php3"
141 onsubmit
="return emptyFormElements(this, 'new_name')">
142 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
143 <input type
="hidden" name
="reload" value
="1" />
144 <input type
="hidden" name
="what" value
="data" />
145 <table border
="0" cellspacing
="0" cellpadding
="0">
148 <select name
="target_db">
150 // The function used below is defined in "common.lib.php3"
151 PMA_availableDatabases('main.php3?' . PMA_generate_common_url());
152 for ($i = 0; $i < $num_dbs; $i++
) {
154 echo '<option value="' . htmlspecialchars($dblist[$i]) . '">' . htmlspecialchars($dblist[$i]) . '</option>';
160 <input type
="text" size
="20" name
="new_name" value
="<?php echo htmlspecialchars($table); ?>" class="textfield" onfocus
="this.select()" />
164 <td align
="<?php echo $cell_align_right; ?>" valign
="top">
165 <input type
="submit" name
="submit_move" value
="<?php echo $strGo; ?>" />
174 <?php
echo $strCopyTable . "\n"; ?
>
175 <form method
="post" action
="tbl_move_copy.php3"
176 onsubmit
="return emptyFormElements(this, 'new_name')">
177 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
178 <input type
="hidden" name
="reload" value
="1" />
179 <table border
="0" cellspacing
="0" cellpadding
="0">
182 <select name
="target_db">
184 for ($i = 0; $i < $num_dbs; $i++
) {
186 echo '<option value="' . htmlspecialchars($dblist[$i]) . '"';
187 if ($dblist[$i] == $db) {
188 echo ' selected="selected"';
190 echo '>' . htmlspecialchars($dblist[$i]) . '</option>';
196 <input type
="text" size
="20" name
="new_name" class="textfield" onfocus
="this.select()" />
201 <input type
="radio" name
="what" value
="structure" id
="radio_copy_structure" checked
="checked" />
202 <label
for="radio_copy_structure"><?php
echo $strStrucOnly; ?
></label
> 
; 
;<br
/>
203 <input type
="radio" name
="what" value
="data" id
="radio_copy_data" />
204 <label
for="radio_copy_data"><?php
echo $strStrucData; ?
></label
> 
; 
;<br
/>
205 <input type
="radio" name
="what" value
="dataonly" id
="radio_copy_dataonly" />
206 <label
for="radio_copy_dataonly"><?php
echo $strDataOnly; ?
></label
> 
; 
;<br
/>
207 <input type
="checkbox" name
="drop_if_exists" value
="true" id
="checkbox_drop" />
208 <label
for="checkbox_drop"><?php
echo $strStrucDrop; ?
></label
> 
; 
;<br
/>
210 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true') {
211 $pma_switch_to_new = 'true';
212 } elseif (isset($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_switch_to_new']) && $HTTP_COOKIE_VARS['pma_switch_to_new'] == 'true') {
213 $pma_switch_to_new = 'true';
216 <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"' : ''); ?
>/>
217 <label
for="checkbox_switch"><?php
echo $strSwitchToTable; ?
></label
> 
; 
;
219 <td align
="<?php echo $cell_align_right; ?>" valign
="top">
220 <input type
="submit" name
="submit_copy" value
="<?php echo $strGo; ?>" />
227 <!-- Table maintenance
-->
229 <?php
echo $strTableMaintenance; ?
>
232 if (PMA_MYSQL_INT_VERSION
>= 32322) {
233 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB' ||
$tbl_type == 'INNODB') {
235 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'INNODB') {
238 <a href
="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('CHECK TABLE ' . PMA_backquote($table)); ?>">
239 <?php
echo $strCheckTable; ?
></a
> 
;
240 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE') . "\n"; ?
>
245 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB') {
248 <a href
="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ANALYZE TABLE ' . PMA_backquote($table)); ?>">
249 <?php
echo $strAnalyzeTable; ?
></a
> 
;
250 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE') . "\n";?
>
255 if ($tbl_type == 'MYISAM') {
258 <a href
="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('REPAIR TABLE ' . PMA_backquote($table)); ?>">
259 <?php
echo $strRepairTable; ?
></a
> 
;
260 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE') . "\n"; ?
>
265 if ($tbl_type == 'MYISAM' ||
$tbl_type == 'BERKELEYDB') {
268 <a href
="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>">
269 <?php
echo $strOptimizeTable; ?
></a
> 
;
270 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE') . "\n"; ?
>
277 } // end MYISAM or BERKELEYDB case
279 } // end MySQL >= 3.23.22
281 // loic1: "OPTIMIZE" statement is available for MyISAM and BERKELEYDB tables only and
282 // MyISAM/BERKELEYDB tables exists since MySQL 3.23.06/3.23.34
283 else if (PMA_MYSQL_INT_VERSION
>= 32306
284 && ($tbl_type == 'MYISAM' or $tbl_type == 'BERKELEYDB')) {
287 <a href
="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>">
288 <?php
echo $strOptimizeTable; ?
></a
> 
;
289 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE') . "\n"; ?
>
293 } // end 3.23.06 < MySQL < 3.23.22
296 <a href
="sql.php3?<?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'; ?>">
297 <?php
echo $strFlushTable; ?
></a
> 
;
298 <?php
echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH') . "\n"; ?
>
302 // Referential integrity check
303 if ($cfgRelation['relwork']) {
305 // we need this PMA_mysql_select_db if the user has access to more than one db
306 // and $db is not the last of the list, because PMA_availableDatabases()
307 // has made a PMA_mysql_select_db() on the last one
308 PMA_mysql_select_db($db);
309 $foreign = PMA_getForeigners($db, $table);
313 <!-- Referential integrity check
-->
315 <?php
echo $strReferentialIntegrity; ?
><br
/>
318 while (list($master, $arr) = each($foreign)){
319 $join_query = 'SELECT ' . PMA_backquote($table) . '.* FROM '
320 . PMA_backquote($table) . ' LEFT JOIN '
321 . PMA_backquote($arr['foreign_table']);
322 if ($arr['foreign_table'] == $table) {
323 $foreign_table = $table . '1';
324 $join_query .= ' AS ' . PMA_backquote($foreign_table);
326 $foreign_table = $arr['foreign_table'];
328 $join_query .= ' ON '
329 . PMA_backquote($table) . '.' . PMA_backquote($master)
330 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
332 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
334 . PMA_backquote($table) . '.' . PMA_backquote($master)
337 . '<a href="sql.php3?' . $url_query
339 . urlencode($join_query)
340 . '">' . $master . ' -> ' . $arr['foreign_table'] . '.' . $arr['foreign_field']
341 . '</a><br />' . "\n";
342 unset($foreign_table);
348 } // end if ($result)
351 } // end if (!empty($cfg['Server']['relation']))
360 * Displays form controls
362 if (PMA_MYSQL_INT_VERSION
>= 32322) {
364 <!-- Table comments
-->
366 <form method
="post" action
="tbl_properties_operations.php3">
367 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
368 <?php
echo $strTableComments; ?
> 
;: 
;
369 <?php
$comment = ereg_replace('; InnoDB free:[^;]*$' , '', ereg_replace('^InnoDB free:[^;]*$', '', $show_comment)); ?
>
370 <input type
="hidden" name
="prev_comment" value
="<?php echo urlencode($comment); ?>" /> 
;
371 <input type
="text" name
="comment" maxlength
="60" size
="30" value
="<?php echo htmlspecialchars($comment); ?>" class="textfield" style
="vertical-align: middle" onfocus
="this.select()" /> 
;
372 <input type
="submit" name
="submitcomment" value
="<?php echo $strGo; ?>" style
="vertical-align: middle" />
378 // modify robbat2 code - staybyte - 11. June 2001
379 $query = 'SHOW VARIABLES LIKE \'have_%\'';
380 $result = PMA_mysql_query($query);
381 if ($result != FALSE && mysql_num_rows($result) > 0) {
382 while ($tmp = PMA_mysql_fetch_array($result)) {
383 if (isset($tmp['Variable_name'])) {
384 switch ($tmp['Variable_name']) {
386 if ($tmp['Value'] == 'YES') {
391 if ($tmp['Value'] == 'YES') {
396 if ($tmp['Value'] == 'YES') {
401 if ($tmp['Value'] == 'YES') {
406 } // end if isset($tmp['Variable_name'])
410 mysql_free_result($result);
414 <form method
="post" action
="tbl_properties_operations.php3">
415 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
416 <?php
echo $strTableType; ?
> 
;: 
;
417 <select name
="tbl_type" style
="vertical-align: middle">
418 <option value
="MYISAM"<?php
if ($tbl_type == 'MYISAM') echo ' selected="selected"'; ?
>>MyISAM
</option
>
419 <option value
="HEAP"<?php
if ($tbl_type == 'HEAP') echo ' selected="selected"'; ?
>>Heap
</option
>
422 if (isset($tbl_bdb)) {
423 $tbl_types .= ' <option value="BERKELEYDB"'
424 . (($tbl_type == 'BERKELEYDB') ?
' selected="selected"' : '')
425 . '>Berkeley DB</option>' . "\n";
427 if (isset($tbl_gemini)) {
428 $tbl_types .= ' <option value="GEMINI"'
429 . (($tbl_type == 'GEMINI') ?
' selected="selected"' : '')
430 . '>Gemini</option>' . "\n";
432 if (isset($tbl_innodb)) {
433 $tbl_types .= ' <option value="INNODB"'
434 . (($tbl_type == 'INNODB') ?
' selected="selected"' : '')
435 . '>INNO DB</option>' . "\n";
437 if (isset($tbl_isam)) {
438 $tbl_types .= ' <option value="ISAM"'
439 . (($tbl_type == 'ISAM') ?
' selected="selected"' : '')
440 . '>ISAM</option>' . "\n";
445 <option value
="MERGE"<?php
if ($tbl_type == 'MRG_MYISAM') echo ' selected="selected"'; ?
>>Merge
</option
>
447 <input type
="submit" name
="submittype" value
="<?php echo $strGo; ?>" style
="vertical-align: middle" /> 
;
448 <?php
echo PMA_showMySQLDocu('Table_types', 'Table_types') . "\n"; ?
>
453 if (PMA_MYSQL_INT_VERSION
>= 40100) {
455 . '<!-- Table character set -->' . "\n"
457 . ' <form method="post" action="tbl_properties_operations.php3">' . "\n"
458 . PMA_generate_common_hidden_inputs($db, $table, 3)
459 . ' ' . $strCharset . ' : ' . "\n"
460 . ' <select name="tbl_charset" style="vertical-align: middle">' . "\n";
461 $real_charset = strpos($tbl_charset, '_') ?
substr($tbl_charset, 0, strpos($tbl_charset, '_')) : $tbl_charset;
462 for ($i = 1; isset($mysql_charsets[$i]); $i++
) {
463 echo ' <option value="' . $mysql_charsets[$i] . '"' . ($mysql_charsets[$i] == $real_charset ?
' selected="selected"' : '') . '>' . $mysql_charsets[$i] . '</option>' . "\n";
466 unset($real_charset);
467 echo ' </select> ' . "\n"
468 . ' <input type="submit" name="submitcharset" value="' . $strGo . '" style="vertical-align: middle" /> ' . "\n"
475 <!-- Table options
-->
477 <?php
echo $strTableOptions; ?
>:<br
/>
478 <table border
="0" cellspacing
="0" cellpadding
="0">
481 <form method
="post" action
="tbl_properties_operations.php3">
482 <?php
echo PMA_generate_common_hidden_inputs($db, $table); ?
>
484 <table border
="0" cellspacing
="1" cellpadding
="1">
486 <td align
="right"><input type
="checkbox" name
="pack_keys" id
="pack_keys_opt"
487 <?php
echo (isset($pack_keys) && $pack_keys == 1) ?
' checked="checked"' : ''; ?
> /></td
>
488 <td
><label
for="pack_keys_opt">pack_keys
</label
> 
; 
;</td
>
491 <td align
="right"><input type
="checkbox" name
="checksum" id
="checksum_opt"
492 <?php
echo (isset($checksum) && $checksum == 1) ?
' checked="checked"' : ''; ?
> /></td
>
493 <td
><label
for="checksum_opt">checksum
</label
> 
; 
;</td
>
496 <td align
="right"><input type
="checkbox" name
="delay_key_write" id
="delay_key_write_opt"
497 <?php
echo (isset($delay_key_write) && $delay_key_write == 1) ?
' checked="checked"' : ''; ?
> /></td
>
498 <td
><label
for="delay_key_write_opt">delay_key_write
</label
> 
; 
;</td
>
501 <td
><input type
="text" name
="auto_increment" id
="auto_increment_opt" class="textfield" style
="width: 30px"
502 <?php
echo (isset($auto_increment) && !empty($auto_increment) ?
' value="' . $auto_increment . '"' : ''); ?
> /></td
>
503 <td valign
="top"><label
for="auto_increment_opt">auto_increment
</label
> 
; 
;<input type
="submit" name
="submitoptions" value
="<?php echo $strGo; ?>" /></td
>
513 } // end if (PMA_MYSQL_INT_VERSION >= 32322)
516 * Displays the footer
519 require('./footer.inc.php3');