update
[phpmyadmin/crack.git] / tbl_properties_operations.php3
blobb2ba1597a188f69a7f13bf3d0d25488108c6da42
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * Runs common work
8 */
9 require('./tbl_properties_common.php3');
10 //$err_url = 'tbl_properties_operations.php3' . $err_url;
11 $url_query .= '&amp;goto=tbl_properties_operations.php3&amp;back=tbl_properties_operations.php3';
14 /**
15 * Gets relation settings
17 require('./libraries/relation.lib.php3');
18 $cfgRelation = PMA_getRelationsParam();
20 /**
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');
27 /**
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);
64 /**
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);
72 } // end if
75 /**
76 * Gets tables informations and displays top links
78 require('./tbl_properties_table_info.php3');
81 /**
82 * Get columns names
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);
92 /**
93 * Displays the page
96 <ul>
98 <?php
99 if (PMA_MYSQL_INT_VERSION >= 32334) {
101 <!-- Order the table -->
102 <li>
103 <form method="post" action="tbl_properties_operations.php3">
104 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
105 <?php echo $strAlterOrderBy; ?>&nbsp;:
106 <select name="order_field" style="vertical-align: middle">
107 <?php
108 echo "\n";
109 reset($columns);
110 while (list($junk, $fieldname) = each($columns)) {
111 echo ' <option value="' . htmlspecialchars($fieldname) . '">' . htmlspecialchars($fieldname) . '</option>' . "\n";
113 unset($columns);
115 </select>
116 <input type="submit" name="submitorderby" value="<?php echo $strGo; ?>" style="vertical-align: middle" />
117 &nbsp;<?php echo $strSingly . "\n"; ?>
118 </form>
119 </li>
120 <?php
122 echo "\n";
125 <!-- Change table name -->
126 <li>
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; ?>&nbsp;:
132 <input type="text" size="20" name="new_name" value="<?php echo htmlspecialchars($table); ?>" class="textfield" onfocus="this.select()" />&nbsp;
133 <input type="submit" value="<?php echo $strGo; ?>" />
134 </form>
135 </li>
137 <!-- Move table -->
138 <li>
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">
146 <tr>
147 <td>
148 <select name="target_db">
149 <?php
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++) {
153 echo ' ';
154 echo '<option value="' . htmlspecialchars($dblist[$i]) . '">' . htmlspecialchars($dblist[$i]) . '</option>';
155 echo "\n";
156 } // end for
158 </select>
159 &nbsp;<b>.</b>&nbsp;
160 <input type="text" size="20" name="new_name" value="<?php echo htmlspecialchars($table); ?>" class="textfield" onfocus="this.select()" />
161 </td>
162 </tr>
163 <tr>
164 <td align="<?php echo $cell_align_right; ?>" valign="top">
165 <input type="submit" name="submit_move" value="<?php echo $strGo; ?>" />
166 </td>
167 </tr>
168 </table>
169 </form>
170 </li>
172 <!-- Copy table -->
173 <li>
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">
180 <tr>
181 <td colspan="2">
182 <select name="target_db">
183 <?php
184 for ($i = 0; $i < $num_dbs; $i++) {
185 echo ' ';
186 echo '<option value="' . htmlspecialchars($dblist[$i]) . '"';
187 if ($dblist[$i] == $db) {
188 echo ' selected="selected"';
190 echo '>' . htmlspecialchars($dblist[$i]) . '</option>';
191 echo "\n";
192 } // end for
194 </select>
195 &nbsp;<b>.</b>&nbsp;
196 <input type="text" size="20" name="new_name" class="textfield" onfocus="this.select()" />
197 </td>
198 </tr>
199 <tr>
200 <td nowrap="nowrap">
201 <input type="radio" name="what" value="structure" id="radio_copy_structure" checked="checked" />
202 <label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label>&nbsp;&nbsp;<br />
203 <input type="radio" name="what" value="data" id="radio_copy_data" />
204 <label for="radio_copy_data"><?php echo $strStrucData; ?></label>&nbsp;&nbsp;<br />
205 <input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" />
206 <label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label>&nbsp;&nbsp;<br />
207 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
208 <label for="checkbox_drop"><?php echo $strStrucDrop; ?></label>&nbsp;&nbsp;<br />
209 <?php
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>&nbsp;&nbsp;
218 </td>
219 <td align="<?php echo $cell_align_right; ?>" valign="top">
220 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
221 </td>
222 </tr>
223 </table>
224 </form>
225 </li>
227 <!-- Table maintenance -->
228 <li>
229 <?php echo $strTableMaintenance; ?>
230 <ul>
231 <?php
232 if (PMA_MYSQL_INT_VERSION >= 32322) {
233 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
234 echo "\n";
235 if ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB') {
237 <li>
238 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('CHECK TABLE ' . PMA_backquote($table)); ?>">
239 <?php echo $strCheckTable; ?></a>&nbsp;
240 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE') . "\n"; ?>
241 </li>
242 <?php
244 echo "\n";
245 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') {
247 <li>
248 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ANALYZE TABLE ' . PMA_backquote($table)); ?>">
249 <?php echo $strAnalyzeTable; ?></a>&nbsp;
250 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE') . "\n";?>
251 </li>
252 <?php
254 echo "\n";
255 if ($tbl_type == 'MYISAM') {
257 <li>
258 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('REPAIR TABLE ' . PMA_backquote($table)); ?>">
259 <?php echo $strRepairTable; ?></a>&nbsp;
260 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE') . "\n"; ?>
261 </li>
262 <?php
264 echo "\n";
265 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') {
267 <li>
268 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>">
269 <?php echo $strOptimizeTable; ?></a>&nbsp;
270 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE') . "\n"; ?>
271 </li>
272 <?php
274 echo "\n";
276 <?php
277 } // end MYISAM or BERKELEYDB case
278 echo "\n";
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')) {
286 <li>
287 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>">
288 <?php echo $strOptimizeTable; ?></a>&nbsp;
289 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE') . "\n"; ?>
290 </li>
291 <?php
292 echo "\n";
293 } // end 3.23.06 < MySQL < 3.23.22
295 <li>
296 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('FLUSH TABLE ' . PMA_backquote($table)); ?>&amp;zero_rows=<?php echo urlencode(sprintf($strTableHasBeenFlushed, htmlspecialchars($table))); if ($cfg['ShowTooltip']) echo '&amp;reload=1'; ?>">
297 <?php echo $strFlushTable; ?></a>&nbsp;
298 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH') . "\n"; ?>
299 </li>
301 <?php
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);
311 if ($foreign) {
313 <!-- Referential integrity check -->
314 <li>
315 <?php echo $strReferentialIntegrity; ?><br />
316 <?php
317 echo "\n";
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);
325 } else {
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'])
331 . ' WHERE '
332 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
333 . ' IS NULL AND '
334 . PMA_backquote($table) . '.' . PMA_backquote($master)
335 . ' IS NOT NULL';
336 echo ' '
337 . '<a href="sql.php3?' . $url_query
338 . '&amp;sql_query='
339 . urlencode($join_query)
340 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
341 . '</a><br />' . "\n";
342 unset($foreign_table);
343 unset($join_query);
344 } // end while
346 </li>
347 <?php
348 } // end if ($result)
349 echo "\n";
351 } // end if (!empty($cfg['Server']['relation']))
353 <br />
354 </ul>
355 </li>
357 <?php
360 * Displays form controls
362 if (PMA_MYSQL_INT_VERSION >= 32322) {
364 <!-- Table comments -->
365 <li>
366 <form method="post" action="tbl_properties_operations.php3">
367 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
368 <?php echo $strTableComments; ?>&nbsp;:&nbsp;
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); ?>" />&nbsp;
371 <input type="text" name="comment" maxlength="60" size="30" value="<?php echo htmlspecialchars($comment); ?>" class="textfield" style="vertical-align: middle" onfocus="this.select()" />&nbsp;
372 <input type="submit" name="submitcomment" value="<?php echo $strGo; ?>" style="vertical-align: middle" />
373 </form>
374 </li>
376 <!-- Table type -->
377 <?php
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']) {
385 case 'have_bdb':
386 if ($tmp['Value'] == 'YES') {
387 $tbl_bdb = TRUE;
389 break;
390 case 'have_gemini':
391 if ($tmp['Value'] == 'YES') {
392 $tbl_gemini = TRUE;
394 break;
395 case 'have_innodb':
396 if ($tmp['Value'] == 'YES') {
397 $tbl_innodb = TRUE;
399 break;
400 case 'have_isam':
401 if ($tmp['Value'] == 'YES') {
402 $tbl_isam = TRUE;
404 break;
405 } // end switch
406 } // end if isset($tmp['Variable_name'])
407 } // end while
408 } // end if $result
410 mysql_free_result($result);
411 echo "\n";
413 <li>
414 <form method="post" action="tbl_properties_operations.php3">
415 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
416 <?php echo $strTableType; ?>&nbsp;:&nbsp;
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>
420 <?php
421 $tbl_types = "\n";
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";
443 echo $tbl_types;
445 <option value="MERGE"<?php if ($tbl_type == 'MRG_MYISAM') echo ' selected="selected"'; ?>>Merge</option>
446 </select>&nbsp;
447 <input type="submit" name="submittype" value="<?php echo $strGo; ?>" style="vertical-align: middle" />&nbsp;
448 <?php echo PMA_showMySQLDocu('Table_types', 'Table_types') . "\n"; ?>
449 </form>
450 </li>
451 <?php
453 if (PMA_MYSQL_INT_VERSION >= 40100) {
454 echo "\n"
455 . '<!-- Table character set -->' . "\n"
456 . ' <li>' . "\n"
457 . ' <form method="post" action="tbl_properties_operations.php3">' . "\n"
458 . PMA_generate_common_hidden_inputs($db, $table, 3)
459 . ' ' . $strCharset . '&nbsp;:&nbsp;' . "\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";
465 unset($i);
466 unset($real_charset);
467 echo ' </select>&nbsp;' . "\n"
468 . ' <input type="submit" name="submitcharset" value="' . $strGo . '" style="vertical-align: middle" />&nbsp;' . "\n"
469 . ' </form>' . "\n"
470 . ' </li>' . "\n";
475 <!-- Table options -->
476 <li>
477 <?php echo $strTableOptions; ?>:<br />
478 <table border="0" cellspacing="0" cellpadding="0">
479 <tr>
480 <td valign="top">
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">
485 <tr>
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>&nbsp;&nbsp;</td>
489 </tr>
490 <tr>
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>&nbsp;&nbsp;</td>
494 </tr>
495 <tr>
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>&nbsp;&nbsp;</td>
499 </tr>
500 <tr>
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>&nbsp;&nbsp;<input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" /></td>
504 </tr>
505 </table>
506 </form>
507 </td>
508 </tr>
509 </table>
510 </li>
511 </ul>
512 <?php
513 } // end if (PMA_MYSQL_INT_VERSION >= 32322)
516 * Displays the footer
518 echo "\n";
519 require('./footer.inc.php3');