translation update
[phpmyadmin/last10db.git] / tbl_properties_operations.php
blob7d1d85db96d537eec9094dcfad5350b1f9d05c1f
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once './libraries/common.lib.php';
6 require_once './libraries/Table.class.php';
8 $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
10 /**
11 * Runs common work
13 require './libraries/tbl_properties_common.php';
14 $url_query .= '&amp;goto=tbl_properties_operations.php&amp;back=tbl_properties_operations.php';
15 $url_params['goto'] = $url_params['back'] = 'tbl_properties_operations.php';
17 /**
18 * Gets relation settings
20 require_once './libraries/relation.lib.php';
21 $cfgRelation = PMA_getRelationsParam();
23 /**
24 * Gets available MySQL charsets and storage engines
26 require_once './libraries/mysql_charsets.lib.php';
27 require_once './libraries/storage_engines.lib.php';
29 // reselect current db (needed in some cases probably due to
30 // the calling of relation.lib.php)
31 PMA_DBI_select_db($GLOBALS['db']);
33 /**
34 * Gets tables informations
37 require './libraries/tbl_properties_table_info.inc.php';
39 $reread_info = false;
40 $errors = array();
41 $table_alters = array();
43 /**
44 * Updates table comment, type and options if required
46 if (isset($_REQUEST['submitoptions'])) {
47 $message = '';
48 if (isset($_REQUEST['new_name'])) {
49 if ($pma_table->rename($_REQUEST['new_name'])) {
50 $message .= $pma_table->getLastMessage();
51 $GLOBALS['table'] = $pma_table->getName();;
52 $reread_info = true;
53 $reload = true;
54 } else {
55 $errors[] = $pma_table->getLastError();
56 $message .= $pma_table->getLastError();
59 if (isset($_REQUEST['comment'])
60 && urldecode($_REQUEST['prev_comment']) !== $_REQUEST['comment']) {
61 $table_alters[] = 'COMMENT = \'' . PMA_sqlAddslashes($_REQUEST['comment']) . '\'';
63 if (! empty($_REQUEST['new_tbl_type'])
64 && strtolower($_REQUEST['new_tbl_type']) !== strtolower($tbl_type)) {
65 $table_alters[] = PMA_ENGINE_KEYWORD . ' = ' . $_REQUEST['new_tbl_type'];
66 $tbl_type = $_REQUEST['new_tbl_type'];
69 if (! empty($_REQUEST['tbl_collation'])
70 && $_REQUEST['tbl_collation'] !== $tbl_collation) {
71 $table_alters[] = 'DEFAULT ' . PMA_generateCharsetQueryPart($_REQUEST['tbl_collation']);
74 $l_tbl_type = strtolower($tbl_type);
76 if (($l_tbl_type === 'myisam' || $l_tbl_type === 'isam')
77 && isset($_REQUEST['new_pack_keys'])
78 && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
79 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
82 $checksum = empty($checksum) ? '0' : '1';
83 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
84 if (($l_tbl_type === 'myisam')
85 && $_REQUEST['new_checksum'] !== $checksum) {
86 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
89 $delay_key_write = empty($delay_key_write) ? '0' : '1';
90 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
91 if (($l_tbl_type === 'myisam')
92 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
93 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
96 if (($l_tbl_type === 'myisam' || $l_tbl_type === 'innodb')
97 && ! empty($_REQUEST['new_auto_increment'])
98 && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
99 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
102 if (count($table_alters) > 0) {
103 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
104 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
105 $message .= PMA_DBI_query($sql_query) ? $strSuccess : $strError;
106 $reread_info = true;
107 unset($table_alters);
111 * Reordering the table has been requested by the user
113 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
114 $sql_query = '
115 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
116 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
117 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
118 $sql_query .= ' DESC';
120 $message = PMA_DBI_query($sql_query) ? $strSuccess : $strError;
121 } // end if
124 if ($reread_info) {
125 $checksum = $delay_key_write = 0;
126 require './libraries/tbl_properties_table_info.inc.php';
128 unset($reread_info);
131 * Displays top menu links
133 require_once './libraries/tbl_properties_links.inc.php';
135 $url_params['goto'] = 'tbl_properties_operations.php';
136 $url_params['back'] = 'tbl_properties_operations.php';
139 * Get columns names
141 $local_query = '
142 SHOW COLUMNS
143 FROM ' . PMA_backquote($GLOBALS['table']) . '
144 FROM ' . PMA_backquote($GLOBALS['db']);
145 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
146 unset($local_query);
149 * Displays the page
152 <!-- Order the table -->
153 <div id="div_table_order">
154 <form method="post" action="tbl_properties_operations.php">
155 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
156 <fieldset id="fieldset_table_order">
157 <legend><?php echo $strAlterOrderBy; ?></legend>
158 <select name="order_field">
159 <?php
160 foreach ($columns as $fieldname) {
161 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
162 . htmlspecialchars($fieldname) . '</option>' . "\n";
164 unset($columns);
166 </select> <?php echo $strSingly; ?>
167 <select name="order_order">
168 <option value="asc"><?php echo $strAscending; ?></option>
169 <option value="desc"><?php echo $strDescending; ?></option>
170 </select>
171 <input type="submit" name="submitorderby" value="<?php echo $strGo; ?>" />
172 </fieldset>
173 </form>
174 </div>
176 <!-- Move table -->
177 <div id="div_table_rename">
178 <form method="post" action="tbl_move_copy.php"
179 onsubmit="return emptyFormElements(this, 'new_name')">
180 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
181 <input type="hidden" name="reload" value="1" />
182 <input type="hidden" name="what" value="data" />
183 <fieldset id="fieldset_table_rename">
184 <legend><?php echo $strMoveTable; ?></legend>
185 <select name="target_db">
186 <?php
187 // The function used below is defined in "common.lib.php"
188 PMA_availableDatabases('main.php?' . PMA_generate_common_url());
189 foreach ($dblist as $each_db) {
190 echo ' ';
191 echo '<option value="' . htmlspecialchars($each_db) . '">'
192 . htmlspecialchars($each_db) . '</option>';
193 echo "\n";
194 } // end foreach $dblist
196 </select>
197 &nbsp;<b>.</b>&nbsp;
198 <input type="text" size="20" name="new_name" onfocus="this.select()"
199 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
200 <?php
201 // after MySQL 5.0.22, SHOW CREATE TABLE includes the AUTO_INCREMENT
202 // next value of the table so we won't have to add it ourselves
203 if (PMA_MYSQL_INT_VERSION < 50023) {
204 echo '<input type="hidden" name="sql_auto_increment" value="1" />' . "\n";
207 <input type="submit" name="submit_move" value="<?php echo $strGo; ?>" />
208 </fieldset>
209 </form>
210 </div>
212 <?php
213 if (strstr($show_comment, '; InnoDB free') === false) {
214 if (strstr($show_comment, 'InnoDB free') === false) {
215 // only user entered comment
216 $comment = $show_comment;
217 } else {
218 // here we have just InnoDB generated part
219 $comment = '';
221 } else {
222 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
223 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
226 // PACK_KEYS: MyISAM or ISAM
227 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
228 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
230 // nijel: Here should be version check for InnoDB, however it is supported
231 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
232 // check for version
235 <!-- Table options -->
236 <div id="div_table_options">
237 <form method="post" action="tbl_properties_operations.php">
238 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
239 <input type="hidden" name="reload" value="1" />
240 <fieldset>
241 <legend><?php echo $strTableOptions; ?></legend>
243 <table>
244 <!-- Change table name -->
245 <tr><td><?php echo $strRenameTable; ?></td>
246 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
247 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
248 </td>
249 </tr>
251 <!-- Table comments -->
252 <tr><td><?php echo $strTableComments; ?></td>
253 <td><input type="text" name="comment" maxlength="60" size="30"
254 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
255 <input type="hidden" name="prev_comment" value="<?php echo urlencode($comment); ?>" />
256 </td>
257 </tr>
259 <!-- Storage engine -->
260 <tr><td><?php echo $strStorageEngine; ?>
261 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
262 </td>
263 <td><?php echo PMA_generateEnginesDropdown('new_tbl_type', null, false, $tbl_type, 4); ?>
264 </td>
265 </tr>
267 <?php
268 if (PMA_MYSQL_INT_VERSION >= 40100) {
270 <!-- Table character set -->
271 <tr><td><?php echo $strCollation; ?></td>
272 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
273 'tbl_collation', null, $tbl_collation, false, 3); ?>
274 </td>
275 </tr>
276 <?php
278 if ($tbl_type == 'MYISAM' || $tbl_type == 'ISAM') {
280 <tr>
281 <td><label for="new_pack_keys">pack_keys</label></td>
282 <td><select name="new_pack_keys" id="new_pack_keys">
283 <option value="DEFAULT"
284 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
285 >DEFAULT</option>
286 <option value="0"
287 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
288 >0</option>
289 <option value="1"
290 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
291 >1</option>
292 </select>
293 </td>
294 </tr>
295 <?php
296 } // end if (MYISAM|ISAM)
298 if ($tbl_type == 'MYISAM') {
300 <tr><td><label for="new_checksum">checksum</label></td>
301 <td><input type="checkbox" name="new_checksum" id="new_checksum"
302 value="1"
303 <?php echo (isset($checksum) && $checksum == 1)
304 ? ' checked="checked"'
305 : ''; ?> />
306 </td>
307 </tr>
309 <tr><td><label for="new_delay_key_write">delay_key_write</label></td>
310 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
311 value="1"
312 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
313 ? ' checked="checked"'
314 : ''; ?> />
315 </td>
316 </tr>
318 <?php
319 } // end if (MYISAM)
321 if (isset($auto_increment) && strlen($auto_increment) > 0
322 && ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB')) {
324 <tr><td><label for="auto_increment_opt">auto_increment</label></td>
325 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
326 value="<?php echo $auto_increment; ?>" /></td>
327 </tr>
328 <?php
329 } // end if (MYISAM|INNODB)
331 </table>
332 </fieldset>
333 <fieldset class="tblFooters">
334 <input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" />
335 </fieldset>
336 </form>
337 </div>
339 <!-- Copy table -->
340 <div id="div_table_copy">
341 <form method="post" action="tbl_move_copy.php"
342 onsubmit="return emptyFormElements(this, 'new_name')">
343 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
344 <input type="hidden" name="reload" value="1" />
345 <fieldset>
346 <legend><?php echo $strCopyTable; ?></legend>
347 <select name="target_db">
348 <?php
349 foreach ($dblist as $each_db) {
350 echo ' ';
351 echo '<option value="' . htmlspecialchars($each_db) . '"';
352 if ($each_db === $GLOBALS['db']) {
353 echo ' selected="selected"';
355 echo '>' . htmlspecialchars($each_db) . '</option>';
356 echo "\n";
357 } // end foreach $dblist
359 </select>
360 &nbsp;<b>.</b>&nbsp;
361 <input type="text" size="20" name="new_name" onfocus="this.select()" /><br />
363 <input type="radio" name="what" value="structure" id="radio_copy_structure" />
364 <label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label><br />
365 <input type="radio" name="what" value="data" id="radio_copy_data" checked="checked" />
366 <label for="radio_copy_data"><?php echo $strStrucData; ?></label><br />
367 <input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" />
368 <label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label><br />
370 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
371 <label for="checkbox_drop"><?php echo sprintf($strAddClause, 'DROP TABLE'); ?></label><br />
372 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment" />
373 <label for="checkbox_auto_increment"><?php echo $strAddAutoIncrement; ?></label><br />
374 <?php
375 // display "Add constraints" choice only if there are
376 // foreign keys
377 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
379 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
380 <label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
381 <?php
382 } // endif
383 if (isset($_COOKIE['pma_switch_to_new'])
384 && $_COOKIE['pma_switch_to_new'] == 'true') {
385 $pma_switch_to_new = 'true';
388 <input type="checkbox" name="switch_to_new" value="true"
389 id="checkbox_switch"<?php echo
390 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
391 ? ' checked="checked"'
392 : ''; ?> />
393 <label for="checkbox_switch"><?php echo $strSwitchToTable; ?></label>
394 </fieldset>
395 <fieldset class="tblFooters">
396 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
397 </fieldset>
398 </form>
399 </div>
401 <br class="clearfloat"/>
403 <h1><?php echo $strTableMaintenance; ?></h1>
405 <ul>
406 <?php
407 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
408 if ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB') {
409 $this_url_params = array_merge($url_params,
410 array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
412 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
413 <?php echo $strCheckTable; ?></a>
414 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
415 </li>
416 <?php
418 if ($tbl_type == 'INNODB') {
419 $this_url_params = array_merge($url_params,
420 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . PMA_ENGINE_KEYWORD . '=InnoDB'));
422 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
423 <?php echo $strDefragment; ?></a>
424 <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
425 </li>
426 <?php
428 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') {
429 $this_url_params = array_merge($url_params,
430 array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
432 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
433 <?php echo $strAnalyzeTable; ?></a>
434 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
435 </li>
436 <?php
438 if ($tbl_type == 'MYISAM') {
439 $this_url_params = array_merge($url_params,
440 array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
442 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
443 <?php echo $strRepairTable; ?></a>
444 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
445 </li>
446 <?php
448 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
449 $this_url_params = array_merge($url_params,
450 array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
452 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
453 <?php echo $strOptimizeTable; ?></a>
454 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
455 </li>
456 <?php
458 } // end MYISAM or BERKELEYDB case
459 $this_url_params = array_merge($url_params,
460 array(
461 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
462 'zero_rows' => sprintf($strTableHasBeenFlushed,
463 htmlspecialchars($GLOBALS['table'])),
464 'reload' => 1,
467 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
468 <?php echo $strFlushTable; ?></a>
469 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
470 </li>
471 </ul>
472 <?php
473 // Referential integrity check
474 // The Referential integrity check was intended for the non-InnoDB
475 // tables for which the relations are defined in pmadb
476 // so I assume that if the current table is InnoDB, I don't display
477 // this choice (InnoDB maintains integrity by itself)
479 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
481 // we need this PMA_DBI_select_db if the user has access to more than one db
482 // and $GLOBALS['db'] is not the last of the list, because PMA_availableDatabases()
483 // has made a PMA_DBI_select_db() on the last one
484 PMA_DBI_select_db($GLOBALS['db']);
485 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
487 if ($foreign) {
489 <!-- Referential integrity check -->
490 <ul>
491 <?php echo $strReferentialIntegrity; ?><br />
492 <?php
493 echo "\n";
494 foreach ($foreign AS $master => $arr) {
495 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
496 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
497 . PMA_backquote($arr['foreign_table']);
498 if ($arr['foreign_table'] == $GLOBALS['table']) {
499 $foreign_table = $GLOBALS['table'] . '1';
500 $join_query .= ' AS ' . PMA_backquote($foreign_table);
501 } else {
502 $foreign_table = $arr['foreign_table'];
504 $join_query .= ' ON '
505 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
506 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
507 . ' WHERE '
508 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
509 . ' IS NULL AND '
510 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
511 . ' IS NOT NULL';
512 $this_url_params = array_merge($url_params,
513 array('sql_query' => $join_query));
514 echo ' <li>'
515 . '<a href="sql.php'
516 . PMA_generate_common_url($this_url_params)
517 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
518 . '</a></li>' . "\n";
519 } // foreach $foreign
520 unset($foreign_table, $join_query);
522 </ul>
523 <?php
524 } // end if ($result)
526 } // end if (!empty($cfg['Server']['relation']))
530 * Displays the footer
532 require_once './libraries/footer.inc.php';