2.11.3-rc1, 2.11.4-dev
[phpmyadmin/crack.git] / tbl_operations.php
bloba198bf765c8d3efcd16cd8327468632a088f953b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
11 require_once './libraries/common.inc.php';
12 require_once './libraries/Table.class.php';
14 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
16 /**
17 * Runs common work
19 require './libraries/tbl_common.php';
20 $url_query .= '&amp;goto=tbl_operations.php&amp;back=tbl_operations.php';
21 $url_params['goto'] = $url_params['back'] = 'tbl_operations.php';
23 /**
24 * Gets relation settings
26 require_once './libraries/relation.lib.php';
27 $cfgRelation = PMA_getRelationsParam();
29 /**
30 * Gets available MySQL charsets and storage engines
32 require_once './libraries/mysql_charsets.lib.php';
33 require_once './libraries/StorageEngine.class.php';
35 // reselect current db (needed in some cases probably due to
36 // the calling of relation.lib.php)
37 PMA_DBI_select_db($GLOBALS['db']);
39 /**
40 * Gets tables informations
43 require './libraries/tbl_info.inc.php';
45 $reread_info = false;
46 $errors = array();
47 $table_alters = array();
49 /**
50 * Updates table comment, type and options if required
52 if (isset($_REQUEST['submitoptions'])) {
53 $message = '';
54 if (isset($_REQUEST['new_name'])) {
55 if ($pma_table->rename($_REQUEST['new_name'])) {
56 $message .= $pma_table->getLastMessage();
57 $GLOBALS['table'] = $pma_table->getName();;
58 $reread_info = true;
59 $reload = true;
60 } else {
61 $errors[] = $pma_table->getLastError();
62 $message .= $pma_table->getLastError();
65 if (isset($_REQUEST['comment'])
66 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
67 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
69 if (! empty($_REQUEST['new_tbl_type'])
70 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
71 $table_alters[] = PMA_ENGINE_KEYWORD . ' = ' . $_REQUEST['new_tbl_type'];
72 $tbl_type = $_REQUEST['new_tbl_type'];
75 if (! empty($_REQUEST['tbl_collation'])
76 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
77 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
80 $l_tbl_type = strtolower($tbl_type);
82 if (($l_tbl_type === 'myisam' || $l_tbl_type === 'isam')
83 && isset($_REQUEST['new_pack_keys'])
84 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
85 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
88 $checksum = empty($checksum) ? '0' : '1';
89 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
90 if (($l_tbl_type === 'myisam')
91 && $_REQUEST['new_checksum'] !== $checksum) {
92 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
95 $delay_key_write = empty($delay_key_write) ? '0' : '1';
96 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
97 if (($l_tbl_type === 'myisam')
98 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
99 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
102 if (($l_tbl_type === 'myisam' || $l_tbl_type === 'innodb')
103 && ! empty($_REQUEST['new_auto_increment'])
104 && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
105 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
108 if (count($table_alters) > 0) {
109 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
110 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
111 $message .= PMA_DBI_query($sql_query) ? $strSuccess : $strError;
112 $reread_info = true;
113 unset($table_alters);
117 * Reordering the table has been requested by the user
119 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
120 $sql_query = '
121 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
122 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
123 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
124 $sql_query .= ' DESC';
126 $message = PMA_DBI_query($sql_query) ? $strSuccess : $strError;
127 } // end if
130 if ($reread_info) {
131 $checksum = $delay_key_write = 0;
132 require './libraries/tbl_info.inc.php';
134 unset($reread_info);
137 * Displays top menu links
139 require_once './libraries/tbl_links.inc.php';
141 $url_params['goto'] = 'tbl_operations.php';
142 $url_params['back'] = 'tbl_operations.php';
145 * Get columns names
147 $local_query = '
148 SHOW COLUMNS
149 FROM ' . PMA_backquote($GLOBALS['table']) . '
150 FROM ' . PMA_backquote($GLOBALS['db']);
151 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
152 unset($local_query);
155 * Displays the page
158 <!-- Order the table -->
159 <div id="div_table_order">
160 <form method="post" action="tbl_operations.php">
161 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
162 <fieldset id="fieldset_table_order">
163 <legend><?php echo $strAlterOrderBy; ?></legend>
164 <select name="order_field">
165 <?php
166 foreach ($columns as $fieldname) {
167 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
168 . htmlspecialchars($fieldname) . '</option>' . "\n";
170 unset($columns);
172 </select> <?php echo $strSingly; ?>
173 <select name="order_order">
174 <option value="asc"><?php echo $strAscending; ?></option>
175 <option value="desc"><?php echo $strDescending; ?></option>
176 </select>
177 <input type="submit" name="submitorderby" value="<?php echo $strGo; ?>" />
178 </fieldset>
179 </form>
180 </div>
182 <!-- Move table -->
183 <div id="div_table_rename">
184 <form method="post" action="tbl_move_copy.php"
185 onsubmit="return emptyFormElements(this, 'new_name')">
186 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
187 <input type="hidden" name="reload" value="1" />
188 <input type="hidden" name="what" value="data" />
189 <fieldset id="fieldset_table_rename">
190 <legend><?php echo $strMoveTable; ?></legend>
191 <select name="target_db">
192 <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?>
193 </select>
194 &nbsp;<b>.</b>&nbsp;
195 <input type="text" size="20" name="new_name" onfocus="this.select()"
196 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
197 <?php
198 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
199 // next value but users can decide if they want it or not for the operation
201 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_mv" checked="checked" />
202 <label for="checkbox_auto_increment_mv"><?php echo $strAddAutoIncrement; ?></label><br />
203 </fieldset>
204 <fieldset class="tblFooters">
205 <input type="submit" name="submit_move" value="<?php echo $strGo; ?>" />
206 </fieldset>
207 </form>
208 </div>
210 <?php
211 if (strstr($show_comment, '; InnoDB free') === false) {
212 if (strstr($show_comment, 'InnoDB free') === false) {
213 // only user entered comment
214 $comment = $show_comment;
215 } else {
216 // here we have just InnoDB generated part
217 $comment = '';
219 } else {
220 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
221 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
224 // PACK_KEYS: MyISAM or ISAM
225 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
226 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
228 // nijel: Here should be version check for InnoDB, however it is supported
229 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
230 // check for version
233 <!-- Table options -->
234 <div id="div_table_options">
235 <form method="post" action="tbl_operations.php">
236 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
237 <input type="hidden" name="reload" value="1" />
238 <fieldset>
239 <legend><?php echo $strTableOptions; ?></legend>
241 <table>
242 <!-- Change table name -->
243 <tr><td><?php echo $strRenameTable; ?></td>
244 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
245 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
246 </td>
247 </tr>
249 <!-- Table comments -->
250 <tr><td><?php echo $strTableComments; ?></td>
251 <td><input type="text" name="comment" maxlength="60" size="30"
252 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
253 <input type="hidden" name="prev_comment" value="<?php echo urlencode($comment); ?>" />
254 </td>
255 </tr>
257 <!-- Storage engine -->
258 <tr><td><?php echo $strStorageEngine; ?>
259 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
260 </td>
261 <td><?php echo PMA_StorageEngine::getHtmlSelect('new_tbl_type', null, $tbl_type); ?>
262 </td>
263 </tr>
265 <?php
266 if (PMA_MYSQL_INT_VERSION >= 40100) {
268 <!-- Table character set -->
269 <tr><td><?php echo $strCollation; ?></td>
270 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
271 'tbl_collation', null, $tbl_collation, false, 3); ?>
272 </td>
273 </tr>
274 <?php
276 if ($tbl_type == 'MYISAM' || $tbl_type == 'ISAM') {
278 <tr>
279 <td><label for="new_pack_keys">pack_keys</label></td>
280 <td><select name="new_pack_keys" id="new_pack_keys">
281 <option value="DEFAULT"
282 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
283 >DEFAULT</option>
284 <option value="0"
285 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
286 >0</option>
287 <option value="1"
288 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
289 >1</option>
290 </select>
291 </td>
292 </tr>
293 <?php
294 } // end if (MYISAM|ISAM)
296 if ($tbl_type == 'MYISAM') {
298 <tr><td><label for="new_checksum">checksum</label></td>
299 <td><input type="checkbox" name="new_checksum" id="new_checksum"
300 value="1"
301 <?php echo (isset($checksum) && $checksum == 1)
302 ? ' checked="checked"'
303 : ''; ?> />
304 </td>
305 </tr>
307 <tr><td><label for="new_delay_key_write">delay_key_write</label></td>
308 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
309 value="1"
310 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
311 ? ' checked="checked"'
312 : ''; ?> />
313 </td>
314 </tr>
316 <?php
317 } // end if (MYISAM)
319 if (isset($auto_increment) && strlen($auto_increment) > 0
320 && ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB')) {
322 <tr><td><label for="auto_increment_opt">auto_increment</label></td>
323 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
324 value="<?php echo $auto_increment; ?>" /></td>
325 </tr>
326 <?php
327 } // end if (MYISAM|INNODB)
329 </table>
330 </fieldset>
331 <fieldset class="tblFooters">
332 <input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" />
333 </fieldset>
334 </form>
335 </div>
337 <!-- Copy table -->
338 <div id="div_table_copy">
339 <form method="post" action="tbl_move_copy.php"
340 onsubmit="return emptyFormElements(this, 'new_name')">
341 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
342 <input type="hidden" name="reload" value="1" />
343 <fieldset>
344 <legend><?php echo $strCopyTable; ?></legend>
345 <select name="target_db">
346 <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?>
347 </select>
348 &nbsp;<b>.</b>&nbsp;
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_cp" />
361 <label for="checkbox_auto_increment_cp"><?php echo $strAddAutoIncrement; ?></label><br />
362 <?php
363 // display "Add constraints" choice only if there are
364 // foreign keys
365 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
367 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
368 <label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
369 <?php
370 } // endif
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"'
380 : ''; ?> />
381 <label for="checkbox_switch"><?php echo $strSwitchToTable; ?></label>
382 </fieldset>
383 <fieldset class="tblFooters">
384 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
385 </fieldset>
386 </form>
387 </div>
389 <br class="clearfloat"/>
391 <h1><?php echo $strTableMaintenance; ?></h1>
393 <ul>
394 <?php
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'); ?>
403 </li>
404 <?php
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'); ?>
413 </li>
414 <?php
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');?>
423 </li>
424 <?php
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'); ?>
433 </li>
434 <?php
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'); ?>
443 </li>
444 <?php
446 } // end MYISAM or BERKELEYDB case
447 $this_url_params = array_merge($url_params,
448 array(
449 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
450 'zero_rows' => sprintf($strTableHasBeenFlushed,
451 htmlspecialchars($GLOBALS['table'])),
452 'reload' => 1,
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'); ?>
458 </li>
459 </ul>
460 <?php
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
471 // PMA_List_Database::_checkAccess()
472 // has made a PMA_DBI_select_db() on the last one
473 PMA_DBI_select_db($GLOBALS['db']);
474 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
476 if ($foreign) {
478 <!-- Referential integrity check -->
479 <ul>
480 <?php echo $strReferentialIntegrity; ?><br />
481 <?php
482 echo "\n";
483 foreach ($foreign AS $master => $arr) {
484 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
485 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
486 . PMA_backquote($arr['foreign_table']);
487 if ($arr['foreign_table'] == $GLOBALS['table']) {
488 $foreign_table = $GLOBALS['table'] . '1';
489 $join_query .= ' AS ' . PMA_backquote($foreign_table);
490 } else {
491 $foreign_table = $arr['foreign_table'];
493 $join_query .= ' ON '
494 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
495 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
496 . ' WHERE '
497 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
498 . ' IS NULL AND '
499 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
500 . ' IS NOT NULL';
501 $this_url_params = array_merge($url_params,
502 array('sql_query' => $join_query));
503 echo ' <li>'
504 . '<a href="sql.php'
505 . PMA_generate_common_url($this_url_params)
506 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
507 . '</a></li>' . "\n";
508 } // foreach $foreign
509 unset($foreign_table, $join_query);
511 </ul>
512 <?php
513 } // end if ($result)
515 } // end if (!empty($cfg['Server']['relation']))
519 * Displays the footer
521 require_once './libraries/footer.inc.php';