Improve translation.
[phpmyadmin/crack.git] / tbl_operations.php
blobcce835c3a95a9a5ffdcc863697c7783e854f1976
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 /**
36 * Class for partition management
38 require_once './libraries/Partition.class.php';
40 // reselect current db (needed in some cases probably due to
41 // the calling of relation.lib.php)
42 PMA_DBI_select_db($GLOBALS['db']);
44 /**
45 * Gets tables informations
48 require './libraries/tbl_info.inc.php';
50 $reread_info = false;
51 $table_alters = array();
53 /**
54 * Updates table comment, type and options if required
56 if (isset($_REQUEST['submitoptions'])) {
57 $_message = '';
58 if (isset($_REQUEST['new_name'])) {
59 if ($pma_table->rename($_REQUEST['new_name'])) {
60 $_message .= $pma_table->getLastMessage();
61 $result = true;
62 $GLOBALS['table'] = $pma_table->getName();
63 $reread_info = true;
64 $reload = true;
65 } else {
66 $_message .= $pma_table->getLastError();
67 $result = false;
70 if (isset($_REQUEST['comment'])
71 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
72 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
74 if (! empty($_REQUEST['new_tbl_type'])
75 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
76 $table_alters[] = PMA_ENGINE_KEYWORD . ' = ' . $_REQUEST['new_tbl_type'];
77 $tbl_type = $_REQUEST['new_tbl_type'];
80 if (! empty($_REQUEST['tbl_collation'])
81 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
82 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
85 $l_tbl_type = strtolower($tbl_type);
87 if (($l_tbl_type === 'myisam' || $l_tbl_type === 'isam')
88 && isset($_REQUEST['new_pack_keys'])
89 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
90 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
93 $checksum = empty($checksum) ? '0' : '1';
94 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
95 if (($l_tbl_type === 'myisam')
96 && $_REQUEST['new_checksum'] !== $checksum) {
97 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
100 $delay_key_write = empty($delay_key_write) ? '0' : '1';
101 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
102 if (($l_tbl_type === 'myisam')
103 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
104 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
107 if (($l_tbl_type === 'myisam' || $l_tbl_type === 'innodb')
108 && ! empty($_REQUEST['new_auto_increment'])
109 && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
110 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
113 if (count($table_alters) > 0) {
114 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
115 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
116 $result .= PMA_DBI_query($sql_query) ? true : false;
117 $reread_info = true;
118 unset($table_alters);
122 * Reordering the table has been requested by the user
124 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
125 $sql_query = '
126 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
127 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
128 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
129 $sql_query .= ' DESC';
131 $result = PMA_DBI_query($sql_query);
132 } // end if
135 * A partition operation has been requested by the user
137 if (isset($_REQUEST['submit_partition']) && ! empty($_REQUEST['partition_operation'])) {
138 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . $_REQUEST['partition_operation'] . ' PARTITION ' . $_REQUEST['partition_name'];
139 $result = PMA_DBI_query($sql_query);
140 } // end if
142 if ($reread_info) {
143 $checksum = $delay_key_write = 0;
144 require './libraries/tbl_info.inc.php';
146 unset($reread_info);
149 * Displays top menu links
151 require_once './libraries/tbl_links.inc.php';
153 if (isset($result)) {
154 if (empty($_message)) {
155 $_message = $result ? $strSuccess : $strError;
157 // $result should exist, regardless of $_message
158 $_type = $result ? 'success' : 'error';
159 PMA_showMessage($_message, $sql_query, $_type);
162 $url_params['goto'] = 'tbl_operations.php';
163 $url_params['back'] = 'tbl_operations.php';
166 * Get columns names
168 $local_query = '
169 SHOW COLUMNS
170 FROM ' . PMA_backquote($GLOBALS['table']) . '
171 FROM ' . PMA_backquote($GLOBALS['db']);
172 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
173 unset($local_query);
176 * Displays the page
179 <!-- Order the table -->
180 <div id="div_table_order">
181 <form method="post" action="tbl_operations.php">
182 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
183 <fieldset id="fieldset_table_order">
184 <legend><?php echo $strAlterOrderBy; ?></legend>
185 <select name="order_field">
186 <?php
187 foreach ($columns as $fieldname) {
188 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
189 . htmlspecialchars($fieldname) . '</option>' . "\n";
191 unset($columns);
193 </select> <?php echo $strSingly; ?>
194 <select name="order_order">
195 <option value="asc"><?php echo $strAscending; ?></option>
196 <option value="desc"><?php echo $strDescending; ?></option>
197 </select>
198 <input type="submit" name="submitorderby" value="<?php echo $strGo; ?>" />
199 </fieldset>
200 </form>
201 </div>
203 <!-- Move table -->
204 <div id="div_table_rename">
205 <form method="post" action="tbl_move_copy.php"
206 onsubmit="return emptyFormElements(this, 'new_name')">
207 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
208 <input type="hidden" name="reload" value="1" />
209 <input type="hidden" name="what" value="data" />
210 <fieldset id="fieldset_table_rename">
211 <legend><?php echo $strMoveTable; ?></legend>
212 <select name="target_db">
213 <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?>
214 </select>
215 &nbsp;<b>.</b>&nbsp;
216 <input type="text" size="20" name="new_name" onfocus="this.select()"
217 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
218 <?php
219 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
220 // next value but users can decide if they want it or not for the operation
222 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_mv" checked="checked" />
223 <label for="checkbox_auto_increment_mv"><?php echo $strAddAutoIncrement; ?></label><br />
224 </fieldset>
225 <fieldset class="tblFooters">
226 <input type="submit" name="submit_move" value="<?php echo $strGo; ?>" />
227 </fieldset>
228 </form>
229 </div>
231 <?php
232 if (strstr($show_comment, '; InnoDB free') === false) {
233 if (strstr($show_comment, 'InnoDB free') === false) {
234 // only user entered comment
235 $comment = $show_comment;
236 } else {
237 // here we have just InnoDB generated part
238 $comment = '';
240 } else {
241 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
242 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
245 // PACK_KEYS: MyISAM or ISAM
246 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
247 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
249 // nijel: Here should be version check for InnoDB, however it is supported
250 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
251 // check for version
254 <!-- Table options -->
255 <div id="div_table_options">
256 <form method="post" action="tbl_operations.php">
257 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
258 <input type="hidden" name="reload" value="1" />
259 <fieldset>
260 <legend><?php echo $strTableOptions; ?></legend>
262 <table>
263 <!-- Change table name -->
264 <tr><td><?php echo $strRenameTable; ?></td>
265 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
266 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
267 </td>
268 </tr>
270 <!-- Table comments -->
271 <tr><td><?php echo $strTableComments; ?></td>
272 <td><input type="text" name="comment" maxlength="60" size="30"
273 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
274 <input type="hidden" name="prev_comment" value="<?php echo urlencode($comment); ?>" />
275 </td>
276 </tr>
278 <!-- Storage engine -->
279 <tr><td><?php echo $strStorageEngine; ?>
280 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
281 </td>
282 <td><?php echo PMA_StorageEngine::getHtmlSelect('new_tbl_type', null, $tbl_type); ?>
283 </td>
284 </tr>
286 <!-- Table character set -->
287 <tr><td><?php echo $strCollation; ?></td>
288 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
289 'tbl_collation', null, $tbl_collation, false, 3); ?>
290 </td>
291 </tr>
292 <?php
293 if ($tbl_type == 'MYISAM' || $tbl_type == 'ISAM') {
295 <tr>
296 <td><label for="new_pack_keys">pack_keys</label></td>
297 <td><select name="new_pack_keys" id="new_pack_keys">
298 <option value="DEFAULT"
299 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
300 >DEFAULT</option>
301 <option value="0"
302 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
303 >0</option>
304 <option value="1"
305 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
306 >1</option>
307 </select>
308 </td>
309 </tr>
310 <?php
311 } // end if (MYISAM|ISAM)
313 if ($tbl_type == 'MYISAM') {
315 <tr><td><label for="new_checksum">checksum</label></td>
316 <td><input type="checkbox" name="new_checksum" id="new_checksum"
317 value="1"
318 <?php echo (isset($checksum) && $checksum == 1)
319 ? ' checked="checked"'
320 : ''; ?> />
321 </td>
322 </tr>
324 <tr><td><label for="new_delay_key_write">delay_key_write</label></td>
325 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
326 value="1"
327 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
328 ? ' checked="checked"'
329 : ''; ?> />
330 </td>
331 </tr>
333 <?php
334 } // end if (MYISAM)
336 if (isset($auto_increment) && strlen($auto_increment) > 0
337 && ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB')) {
339 <tr><td><label for="auto_increment_opt">auto_increment</label></td>
340 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
341 value="<?php echo $auto_increment; ?>" /></td>
342 </tr>
343 <?php
344 } // end if (MYISAM|INNODB)
346 </table>
347 </fieldset>
348 <fieldset class="tblFooters">
349 <input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" />
350 </fieldset>
351 </form>
352 </div>
354 <!-- Copy table -->
355 <div id="div_table_copy">
356 <form method="post" action="tbl_move_copy.php"
357 onsubmit="return emptyFormElements(this, 'new_name')">
358 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
359 <input type="hidden" name="reload" value="1" />
360 <fieldset>
361 <legend><?php echo $strCopyTable; ?></legend>
362 <select name="target_db">
363 <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?>
364 </select>
365 &nbsp;<b>.</b>&nbsp;
366 <input type="text" size="20" name="new_name" onfocus="this.select()" /><br />
368 <input type="radio" name="what" value="structure" id="radio_copy_structure" />
369 <label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label><br />
370 <input type="radio" name="what" value="data" id="radio_copy_data" checked="checked" />
371 <label for="radio_copy_data"><?php echo $strStrucData; ?></label><br />
372 <input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" />
373 <label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label><br />
375 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
376 <label for="checkbox_drop"><?php echo sprintf($strAddClause, 'DROP TABLE'); ?></label><br />
377 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_cp" />
378 <label for="checkbox_auto_increment_cp"><?php echo $strAddAutoIncrement; ?></label><br />
379 <?php
380 // display "Add constraints" choice only if there are
381 // foreign keys
382 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
384 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
385 <label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
386 <?php
387 } // endif
388 if (isset($_COOKIE['pma_switch_to_new'])
389 && $_COOKIE['pma_switch_to_new'] == 'true') {
390 $pma_switch_to_new = 'true';
393 <input type="checkbox" name="switch_to_new" value="true"
394 id="checkbox_switch"<?php echo
395 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
396 ? ' checked="checked"'
397 : ''; ?> />
398 <label for="checkbox_switch"><?php echo $strSwitchToTable; ?></label>
399 </fieldset>
400 <fieldset class="tblFooters">
401 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
402 </fieldset>
403 </form>
404 </div>
406 <br class="clearfloat"/>
408 <div id="div_table_maintenance">
409 <fieldset>
410 <legend><?php echo $strTableMaintenance; ?></legend>
412 <ul>
413 <?php
414 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
415 if ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB') {
416 $this_url_params = array_merge($url_params,
417 array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
419 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
420 <?php echo $strCheckTable; ?></a>
421 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
422 </li>
423 <?php
425 if ($tbl_type == 'INNODB') {
426 $this_url_params = array_merge($url_params,
427 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . PMA_ENGINE_KEYWORD . '=InnoDB'));
429 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
430 <?php echo $strDefragment; ?></a>
431 <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
432 </li>
433 <?php
435 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') {
436 $this_url_params = array_merge($url_params,
437 array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
439 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
440 <?php echo $strAnalyzeTable; ?></a>
441 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
442 </li>
443 <?php
445 if ($tbl_type == 'MYISAM') {
446 $this_url_params = array_merge($url_params,
447 array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
449 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
450 <?php echo $strRepairTable; ?></a>
451 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
452 </li>
453 <?php
455 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
456 $this_url_params = array_merge($url_params,
457 array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
459 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
460 <?php echo $strOptimizeTable; ?></a>
461 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
462 </li>
463 <?php
465 } // end MYISAM or BERKELEYDB case
466 $this_url_params = array_merge($url_params,
467 array(
468 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
469 'zero_rows' => sprintf($strTableHasBeenFlushed,
470 htmlspecialchars($GLOBALS['table'])),
471 'reload' => 1,
474 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
475 <?php echo $strFlushTable; ?></a>
476 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
477 </li>
478 </ul>
479 </fieldset>
480 </div>
481 <?php if (PMA_Partition::havePartitioning()) {
482 $partition_names = PMA_Partition::getPartitionNames($db, $table);
483 // show the Partition maintenance section only if we detect a partition
484 if (! is_null($partition_names[0])) {
486 <div id="div_partition_maintenance">
487 <form method="post" action="tbl_operations.php">
488 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
489 <fieldset>
490 <legend><?php echo $strPartitionMaintenance; ?></legend>
491 <?php
492 $html_select = '<select name="partition_name">' . "\n";
493 foreach($partition_names as $one_partition) {
494 $one_partition = htmlspecialchars($one_partition);
495 $html_select .= '<option value="' . $one_partition . '">' . $one_partition . '</option>' . "\n";
497 $html_select .= '</select>' . "\n";
498 printf($GLOBALS['strPartition'], $html_select);
499 unset($partition_names, $one_partition, $html_select);
500 $choices = array(
501 'ANALYZE' => $strAnalyze,
502 'CHECK' => $strCheck,
503 'OPTIMIZE' => $strOptimize,
504 'REBUILD' => $strRebuild,
505 'REPAIR' => $strRepair);
506 PMA_generate_html_radio('partition_operation', $choices, '', false);
507 unset($choices);
508 echo PMA_showMySQLDocu('partitioning_maintenance', 'partitioning_maintenance');
509 // I'm not sure of the best way to display that; this link does
510 // not depend on the Go button
511 $this_url_params = array_merge($url_params,
512 array(
513 'sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' REMOVE PARTITIONING'
516 <br /><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
517 <?php echo $strRemovePartitioning; ?></a>
518 </fieldset>
519 <fieldset class="tblFooters">
520 <input type="submit" name="submit_partition" value="<?php echo $strGo; ?>" />
521 </fieldset>
522 </form>
523 </div>
524 <?php
525 } // end if
526 } // end if
528 // Referential integrity check
529 // The Referential integrity check was intended for the non-InnoDB
530 // tables for which the relations are defined in pmadb
531 // so I assume that if the current table is InnoDB, I don't display
532 // this choice (InnoDB maintains integrity by itself)
534 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
535 PMA_DBI_select_db($GLOBALS['db']);
536 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
538 if ($foreign) {
540 <!-- Referential integrity check -->
541 <div id="div_referential_integrity">
542 <fieldset>
543 <legend><?php echo $strReferentialIntegrity; ?></legend>
544 <ul>
545 <?php
546 echo "\n";
547 foreach ($foreign AS $master => $arr) {
548 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
549 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
550 . PMA_backquote($arr['foreign_table']);
551 if ($arr['foreign_table'] == $GLOBALS['table']) {
552 $foreign_table = $GLOBALS['table'] . '1';
553 $join_query .= ' AS ' . PMA_backquote($foreign_table);
554 } else {
555 $foreign_table = $arr['foreign_table'];
557 $join_query .= ' ON '
558 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
559 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
560 . ' WHERE '
561 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
562 . ' IS NULL AND '
563 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
564 . ' IS NOT NULL';
565 $this_url_params = array_merge($url_params,
566 array('sql_query' => $join_query));
567 echo ' <li>'
568 . '<a href="sql.php'
569 . PMA_generate_common_url($this_url_params)
570 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
571 . '</a></li>' . "\n";
572 } // foreach $foreign
573 unset($foreign_table, $join_query);
575 </ul>
576 </fieldset>
577 </div>
578 <?php
579 } // end if ($foreign)
581 } // end if (!empty($cfg['Server']['relation']))
585 * Displays the footer
587 require_once './libraries/footer.inc.php';