update
[phpmyadmin/crack.git] / tbl_properties_operations.php3
blobe17322f465f06ebfd44afc700b969b5fc866e201
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 <input type="checkbox" name="auto_increment" value="1" id="checkbox_auto_increment" />
210 <label for="checkbox_auto_increment"><?php echo $strAddAutoIncrement; ?></label><br />
211 <?php
212 if (isset($_COOKIE) && isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true') {
213 $pma_switch_to_new = 'true';
214 } elseif (isset($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_switch_to_new']) && $HTTP_COOKIE_VARS['pma_switch_to_new'] == 'true') {
215 $pma_switch_to_new = 'true';
218 <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"' : ''); ?>/>
219 <label for="checkbox_switch"><?php echo $strSwitchToTable; ?></label>&nbsp;&nbsp;
220 </td>
221 <td align="<?php echo $cell_align_right; ?>" valign="top">
222 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
223 </td>
224 </tr>
225 </table>
226 </form>
227 </li>
229 <!-- Table maintenance -->
230 <li>
231 <?php echo $strTableMaintenance; ?>
232 <ul>
233 <?php
234 if (PMA_MYSQL_INT_VERSION >= 32322) {
235 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
236 echo "\n";
237 if ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB') {
239 <li>
240 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('CHECK TABLE ' . PMA_backquote($table)); ?>">
241 <?php echo $strCheckTable; ?></a>&nbsp;
242 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE') . "\n"; ?>
243 </li>
244 <?php
246 echo "\n";
247 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') {
249 <li>
250 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('ANALYZE TABLE ' . PMA_backquote($table)); ?>">
251 <?php echo $strAnalyzeTable; ?></a>&nbsp;
252 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE') . "\n";?>
253 </li>
254 <?php
256 echo "\n";
257 if ($tbl_type == 'MYISAM') {
259 <li>
260 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('REPAIR TABLE ' . PMA_backquote($table)); ?>">
261 <?php echo $strRepairTable; ?></a>&nbsp;
262 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE') . "\n"; ?>
263 </li>
264 <?php
266 echo "\n";
267 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') {
269 <li>
270 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>">
271 <?php echo $strOptimizeTable; ?></a>&nbsp;
272 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE') . "\n"; ?>
273 </li>
274 <?php
276 echo "\n";
278 <?php
279 } // end MYISAM or BERKELEYDB case
280 echo "\n";
281 } // end MySQL >= 3.23.22
283 // loic1: "OPTIMIZE" statement is available for MyISAM and BERKELEYDB tables only and
284 // MyISAM/BERKELEYDB tables exists since MySQL 3.23.06/3.23.34
285 else if (PMA_MYSQL_INT_VERSION >= 32306
286 && ($tbl_type == 'MYISAM' or $tbl_type == 'BERKELEYDB')) {
288 <li>
289 <a href="sql.php3?<?php echo $url_query; ?>&amp;sql_query=<?php echo urlencode('OPTIMIZE TABLE ' . PMA_backquote($table)); ?>">
290 <?php echo $strOptimizeTable; ?></a>&nbsp;
291 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE') . "\n"; ?>
292 </li>
293 <?php
294 echo "\n";
295 } // end 3.23.06 < MySQL < 3.23.22
297 <li>
298 <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'; ?>">
299 <?php echo $strFlushTable; ?></a>&nbsp;
300 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH') . "\n"; ?>
301 </li>
303 <?php
304 // Referential integrity check
305 // The Referential integrity check was intended for the non-InnoDB
306 // tables for which the relations are defined in pmadb
307 // so I assume that if the current table is InnoDB, I don't display
308 // this choice (InnoDB maintains integrity by itself)
310 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
312 // we need this PMA_mysql_select_db if the user has access to more than one db
313 // and $db is not the last of the list, because PMA_availableDatabases()
314 // has made a PMA_mysql_select_db() on the last one
315 PMA_mysql_select_db($db);
316 $foreign = PMA_getForeigners($db, $table);
318 if ($foreign) {
320 <!-- Referential integrity check -->
321 <li>
322 <?php echo $strReferentialIntegrity; ?><br />
323 <?php
324 echo "\n";
325 while (list($master, $arr) = each($foreign)){
326 $join_query = 'SELECT ' . PMA_backquote($table) . '.* FROM '
327 . PMA_backquote($table) . ' LEFT JOIN '
328 . PMA_backquote($arr['foreign_table']);
329 if ($arr['foreign_table'] == $table) {
330 $foreign_table = $table . '1';
331 $join_query .= ' AS ' . PMA_backquote($foreign_table);
332 } else {
333 $foreign_table = $arr['foreign_table'];
335 $join_query .= ' ON '
336 . PMA_backquote($table) . '.' . PMA_backquote($master)
337 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
338 . ' WHERE '
339 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
340 . ' IS NULL AND '
341 . PMA_backquote($table) . '.' . PMA_backquote($master)
342 . ' IS NOT NULL';
343 echo ' '
344 . '<a href="sql.php3?' . $url_query
345 . '&amp;sql_query='
346 . urlencode($join_query)
347 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
348 . '</a><br />' . "\n";
349 unset($foreign_table);
350 unset($join_query);
351 } // end while
353 </li>
354 <?php
355 } // end if ($result)
356 echo "\n";
358 } // end if (!empty($cfg['Server']['relation']))
360 <br />
361 </ul>
362 </li>
364 <?php
367 * Displays form controls
369 if (PMA_MYSQL_INT_VERSION >= 32322) {
371 <!-- Table comments -->
372 <li>
373 <form method="post" action="tbl_properties_operations.php3">
374 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
375 <?php echo $strTableComments; ?>&nbsp;:&nbsp;
376 <?php $comment = ereg_replace('; InnoDB free:[^;]*$' , '', ereg_replace('^InnoDB free:[^;]*$', '', $show_comment)); ?>
377 <input type="hidden" name="prev_comment" value="<?php echo urlencode($comment); ?>" />&nbsp;
378 <input type="text" name="comment" maxlength="60" size="30" value="<?php echo htmlspecialchars($comment); ?>" class="textfield" style="vertical-align: middle" onfocus="this.select()" />&nbsp;
379 <input type="submit" name="submitcomment" value="<?php echo $strGo; ?>" style="vertical-align: middle" />
380 </form>
381 </li>
383 <!-- Table type -->
384 <?php
385 // modify robbat2 code - staybyte - 11. June 2001
386 $query = 'SHOW VARIABLES LIKE \'have_%\'';
387 $result = PMA_mysql_query($query);
388 if ($result != FALSE && mysql_num_rows($result) > 0) {
389 while ($tmp = PMA_mysql_fetch_array($result)) {
390 if (isset($tmp['Variable_name'])) {
391 switch ($tmp['Variable_name']) {
392 case 'have_bdb':
393 if ($tmp['Value'] == 'YES') {
394 $tbl_bdb = TRUE;
396 break;
397 case 'have_gemini':
398 if ($tmp['Value'] == 'YES') {
399 $tbl_gemini = TRUE;
401 break;
402 case 'have_innodb':
403 if ($tmp['Value'] == 'YES') {
404 $tbl_innodb = TRUE;
406 break;
407 case 'have_isam':
408 if ($tmp['Value'] == 'YES') {
409 $tbl_isam = TRUE;
411 break;
412 } // end switch
413 } // end if isset($tmp['Variable_name'])
414 } // end while
415 } // end if $result
417 mysql_free_result($result);
418 echo "\n";
420 <li>
421 <form method="post" action="tbl_properties_operations.php3">
422 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
423 <?php echo $strTableType; ?>&nbsp;:&nbsp;
424 <select name="tbl_type" style="vertical-align: middle">
425 <option value="MYISAM"<?php if ($tbl_type == 'MYISAM') echo ' selected="selected"'; ?>>MyISAM</option>
426 <option value="HEAP"<?php if ($tbl_type == 'HEAP') echo ' selected="selected"'; ?>>Heap</option>
427 <?php
428 $tbl_types = "\n";
429 if (isset($tbl_bdb)) {
430 $tbl_types .= ' <option value="BERKELEYDB"'
431 . (($tbl_type == 'BERKELEYDB') ? ' selected="selected"' : '')
432 . '>Berkeley DB</option>' . "\n";
434 if (isset($tbl_gemini)) {
435 $tbl_types .= ' <option value="GEMINI"'
436 . (($tbl_type == 'GEMINI') ? ' selected="selected"' : '')
437 . '>Gemini</option>' . "\n";
439 if (isset($tbl_innodb)) {
440 $tbl_types .= ' <option value="INNODB"'
441 . (($tbl_type == 'INNODB') ? ' selected="selected"' : '')
442 . '>INNO DB</option>' . "\n";
444 if (isset($tbl_isam)) {
445 $tbl_types .= ' <option value="ISAM"'
446 . (($tbl_type == 'ISAM') ? ' selected="selected"' : '')
447 . '>ISAM</option>' . "\n";
450 echo $tbl_types;
452 <option value="MERGE"<?php if ($tbl_type == 'MRG_MYISAM') echo ' selected="selected"'; ?>>Merge</option>
453 </select>&nbsp;
454 <input type="submit" name="submittype" value="<?php echo $strGo; ?>" style="vertical-align: middle" />&nbsp;
455 <?php echo PMA_showMySQLDocu('Table_types', 'Table_types') . "\n"; ?>
456 </form>
457 </li>
458 <?php
460 if (PMA_MYSQL_INT_VERSION >= 40100) {
461 echo "\n"
462 . '<!-- Table character set -->' . "\n"
463 . ' <li>' . "\n"
464 . ' <form method="post" action="tbl_properties_operations.php3">' . "\n"
465 . PMA_generate_common_hidden_inputs($db, $table, 3)
466 . ' ' . $strCharset . '&nbsp;:&nbsp;' . "\n"
467 . ' <select name="tbl_charset" style="vertical-align: middle">' . "\n";
468 $real_charset = strpos($tbl_charset, '_') ? substr($tbl_charset, 0, strpos($tbl_charset, '_')) : $tbl_charset;
469 for ($i = 1; isset($mysql_charsets[$i]); $i++) {
470 echo ' <option value="' . $mysql_charsets[$i] . '"' . ($mysql_charsets[$i] == $real_charset ? ' selected="selected"' : '') . '>' . $mysql_charsets[$i] . '</option>' . "\n";
472 unset($i);
473 unset($real_charset);
474 echo ' </select>&nbsp;' . "\n"
475 . ' <input type="submit" name="submitcharset" value="' . $strGo . '" style="vertical-align: middle" />&nbsp;' . "\n"
476 . ' </form>' . "\n"
477 . ' </li>' . "\n";
482 <!-- Table options -->
483 <li>
484 <?php echo $strTableOptions; ?>:<br />
485 <table border="0" cellspacing="0" cellpadding="0">
486 <tr>
487 <td valign="top">
488 <form method="post" action="tbl_properties_operations.php3">
489 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
491 <table border="0" cellspacing="1" cellpadding="1">
492 <tr>
493 <td align="right"><input type="checkbox" name="pack_keys" id="pack_keys_opt"
494 <?php echo (isset($pack_keys) && $pack_keys == 1) ? ' checked="checked"' : ''; ?> /></td>
495 <td><label for="pack_keys_opt">pack_keys</label>&nbsp;&nbsp;</td>
496 </tr>
497 <tr>
498 <td align="right"><input type="checkbox" name="checksum" id="checksum_opt"
499 <?php echo (isset($checksum) && $checksum == 1) ? ' checked="checked"' : ''; ?> /></td>
500 <td><label for="checksum_opt">checksum</label>&nbsp;&nbsp;</td>
501 </tr>
502 <tr>
503 <td align="right"><input type="checkbox" name="delay_key_write" id="delay_key_write_opt"
504 <?php echo (isset($delay_key_write) && $delay_key_write == 1) ? ' checked="checked"' : ''; ?> /></td>
505 <td><label for="delay_key_write_opt">delay_key_write</label>&nbsp;&nbsp;</td>
506 </tr>
507 <tr>
508 <td><input type="text" name="auto_increment" id="auto_increment_opt" class="textfield" style="width: 30px"
509 <?php echo (isset($auto_increment) && !empty($auto_increment) ? ' value="' . $auto_increment . '"' : ''); ?> /></td>
510 <td valign="top"><label for="auto_increment_opt">auto_increment</label>&nbsp;&nbsp;<input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" /></td>
511 </tr>
512 </table>
513 </form>
514 </td>
515 </tr>
516 </table>
517 </li>
518 </ul>
519 <?php
520 } // end if (PMA_MYSQL_INT_VERSION >= 32322)
523 * Displays the footer
525 echo "\n";
526 require('./footer.inc.php3');