bug #1455373, CONVERT not in reserved words
[phpmyadmin/crack.git] / tbl_properties_operations.php
blob325f30b00665cf68ee4b6549719e66ab3a3d1ce1
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 $pack_keys = empty($pack_keys) ? '0' : '1';
77 $_REQUEST['new_pack_keys'] = empty($_REQUEST['new_pack_keys']) ? '0' : '1';
78 if (($l_tbl_type === 'myisam' || $l_tbl_type === 'isam')
79 && $_REQUEST['new_pack_keys'] !== $pack_keys) {
80 $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
83 $checksum = empty($checksum) ? '0' : '1';
84 $_REQUEST['new_checksum'] = empty($_REQUEST['new_checksum']) ? '0' : '1';
85 if (($l_tbl_type === 'myisam')
86 && $_REQUEST['new_checksum'] !== $checksum) {
87 $table_alters[] = 'checksum = ' . $_REQUEST['new_checksum'];
90 $delay_key_write = empty($delay_key_write) ? '0' : '1';
91 $_REQUEST['new_delay_key_write'] = empty($_REQUEST['new_delay_key_write']) ? '0' : '1';
92 if (($l_tbl_type === 'myisam')
93 && $_REQUEST['new_delay_key_write'] !== $delay_key_write) {
94 $table_alters[] = 'delay_key_write = ' . $_REQUEST['new_delay_key_write'];
97 if (($l_tbl_type === 'myisam' || $l_tbl_type === 'innodb')
98 && ! empty($_REQUEST['new_auto_increment'])
99 && (! isset($auto_increment) || $_REQUEST['new_auto_increment'] !== $auto_increment)) {
100 $table_alters[] = 'auto_increment = ' . PMA_sqlAddslashes($_REQUEST['new_auto_increment']);
103 if (count($table_alters) > 0) {
104 $sql_query = 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']);
105 $sql_query .= "\r\n" . implode("\r\n", $table_alters);
106 $message .= PMA_DBI_query($sql_query) ? $strSuccess : $strError;
107 $reread_info = true;
108 unset($table_alters);
112 * Reordering the table has been requested by the user
114 if (isset($_REQUEST['submitorderby']) && ! empty($_REQUEST['order_field'])) {
115 $sql_query = '
116 ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . '
117 ORDER BY ' . PMA_backquote(urldecode($_REQUEST['order_field']));
118 if (isset($_REQUEST['order_order']) && $_REQUEST['order_order'] === 'desc') {
119 $sql_query .= ' DESC';
121 $message = PMA_DBI_query($sql_query) ? $strSuccess : $strError;
122 } // end if
125 if ($reread_info) {
126 $pack_keys = $checksum = $delay_key_write = 0;
127 require './libraries/tbl_properties_table_info.inc.php';
129 unset($reread_info);
132 * Displays top menu links
134 require_once './libraries/tbl_properties_links.inc.php';
136 $url_params['goto'] = 'tbl_properties_operations.php';
137 $url_params['back'] = 'tbl_properties_operations.php';
140 * Get columns names
142 $local_query = '
143 SHOW COLUMNS
144 FROM ' . PMA_backquote($GLOBALS['table']) . '
145 FROM ' . PMA_backquote($GLOBALS['db']);
146 $columns = PMA_DBI_fetch_result($local_query, null, 'Field');
147 unset($local_query);
150 * Displays the page
153 <!-- Order the table -->
154 <div id="div_table_order">
155 <form method="post" action="tbl_properties_operations.php">
156 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
157 <fieldset id="fieldset_table_order">
158 <legend><?php echo $strAlterOrderBy; ?></legend>
159 <select name="order_field">
160 <?php
161 foreach ($columns as $fieldname) {
162 echo ' <option value="' . htmlspecialchars($fieldname) . '">'
163 . htmlspecialchars($fieldname) . '</option>' . "\n";
165 unset($columns);
167 </select> <?php echo $strSingly; ?>
168 <select name="order_order">
169 <option value="asc"><?php echo $strAscending; ?></option>
170 <option value="desc"><?php echo $strDescending; ?></option>
171 </select>
172 <input type="submit" name="submitorderby" value="<?php echo $strGo; ?>" />
173 </fieldset>
174 </form>
175 </div>
177 <!-- Move table -->
178 <div id="div_table_rename">
179 <form method="post" action="tbl_move_copy.php"
180 onsubmit="return emptyFormElements(this, 'new_name')">
181 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
182 <input type="hidden" name="reload" value="1" />
183 <input type="hidden" name="what" value="data" />
184 <fieldset id="fieldset_table_rename">
185 <legend><?php echo $strMoveTable; ?></legend>
186 <select name="target_db">
187 <?php
188 // The function used below is defined in "common.lib.php"
189 PMA_availableDatabases('main.php?' . PMA_generate_common_url());
190 foreach ($dblist as $each_db) {
191 echo ' ';
192 echo '<option value="' . htmlspecialchars($each_db) . '">'
193 . htmlspecialchars($each_db) . '</option>';
194 echo "\n";
195 } // end foreach $dblist
197 </select>
198 &nbsp;<b>.</b>&nbsp;
199 <input type="text" size="20" name="new_name" onfocus="this.select()"
200 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
201 <input type="submit" name="submit_move" value="<?php echo $strGo; ?>" />
202 </fieldset>
203 </form>
204 </div>
206 <?php
207 if (strstr($show_comment, '; InnoDB free') === false) {
208 if (strstr($show_comment, 'InnoDB free') === false) {
209 // only user entered comment
210 $comment = $show_comment;
211 } else {
212 // here we have just InnoDB generated part
213 $comment = '';
215 } else {
216 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
217 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
220 // PACK_KEYS: MyISAM or ISAM
221 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
222 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
224 // nijel: Here should be version check for InnoDB, however it is supported
225 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
226 // check for version
229 <!-- Table options -->
230 <div id="div_table_options">
231 <form method="post" action="tbl_properties_operations.php">
232 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
233 <input type="hidden" name="reload" value="1" />
234 <fieldset>
235 <legend><?php echo $strTableOptions; ?></legend>
237 <table>
238 <!-- Change table name -->
239 <tr><td><?php echo $strRenameTable; ?></td>
240 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
241 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
242 </td>
243 </tr>
245 <!-- Table comments -->
246 <tr><td><?php echo $strTableComments; ?></td>
247 <td><input type="text" name="comment" maxlength="60" size="30"
248 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
249 <input type="hidden" name="prev_comment" value="<?php echo urlencode($comment); ?>" />
250 </td>
251 </tr>
253 <!-- Storage engine -->
254 <tr><td><?php echo $strStorageEngine; ?>
255 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
256 </td>
257 <td><?php echo PMA_generateEnginesDropdown('new_tbl_type', null, false, $tbl_type, 4); ?>
258 </td>
259 </tr>
261 <?php
262 if (PMA_MYSQL_INT_VERSION >= 40100) {
264 <!-- Table character set -->
265 <tr><td><?php echo $strCollation; ?></td>
266 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
267 'tbl_collation', null, $tbl_collation, false, 3); ?>
268 </td>
269 </tr>
270 <?php
272 if ($tbl_type == 'MYISAM' || $tbl_type == 'ISAM') {
274 <tr>
275 <td><label for="new_pack_keys">pack_keys</label></td>
276 <td><input type="checkbox" name="new_pack_keys" id="new_pack_keys"
277 value="1"
278 <?php echo (isset($pack_keys) && $pack_keys == 1)
279 ? ' checked="checked"'
280 : ''; ?> />
281 </td>
282 </tr>
283 <?php
284 } // end if (MYISAM|ISAM)
286 if ($tbl_type == 'MYISAM') {
288 <tr><td><label for="new_checksum">checksum</label></td>
289 <td><input type="checkbox" name="new_checksum" id="new_checksum"
290 value="1"
291 <?php echo (isset($checksum) && $checksum == 1)
292 ? ' checked="checked"'
293 : ''; ?> />
294 </td>
295 </tr>
297 <tr><td><label for="new_delay_key_write">delay_key_write</label></td>
298 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
299 value="1"
300 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
301 ? ' checked="checked"'
302 : ''; ?> />
303 </td>
304 </tr>
306 <?php
307 } // end if (MYISAM)
309 if (isset($auto_increment) && strlen($auto_increment) > 0
310 && ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB')) {
312 <tr><td><label for="auto_increment_opt">auto_increment</label></td>
313 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
314 value="<?php echo $auto_increment; ?>" /></td>
315 </tr>
316 <?php
317 } // end if (MYISAM|INNODB)
319 </table>
320 </fieldset>
321 <fieldset class="tblFooters">
322 <input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" />
323 </fieldset>
324 </form>
325 </div>
327 <!-- Copy table -->
328 <div id="div_table_copy">
329 <form method="post" action="tbl_move_copy.php"
330 onsubmit="return emptyFormElements(this, 'new_name')">
331 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
332 <input type="hidden" name="reload" value="1" />
333 <fieldset>
334 <legend><?php echo $strCopyTable; ?></legend>
335 <select name="target_db">
336 <?php
337 foreach ($dblist as $each_db) {
338 echo ' ';
339 echo '<option value="' . htmlspecialchars($each_db) . '"';
340 if ($each_db === $GLOBALS['db']) {
341 echo ' selected="selected"';
343 echo '>' . htmlspecialchars($each_db) . '</option>';
344 echo "\n";
345 } // end foreach $dblist
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" />
361 <label for="checkbox_auto_increment"><?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="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 PMA_availableDatabases()
471 // has made a PMA_DBI_select_db() on the last one
472 PMA_DBI_select_db($GLOBALS['db']);
473 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
475 if ($foreign) {
477 <!-- Referential integrity check -->
478 <ul>
479 <?php echo $strReferentialIntegrity; ?><br />
480 <?php
481 echo "\n";
482 foreach ($foreign AS $master => $arr) {
483 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
484 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
485 . PMA_backquote($arr['foreign_table']);
486 if ($arr['foreign_table'] == $GLOBALS['table']) {
487 $foreign_table = $GLOBALS['table'] . '1';
488 $join_query .= ' AS ' . PMA_backquote($foreign_table);
489 } else {
490 $foreign_table = $arr['foreign_table'];
492 $join_query .= ' ON '
493 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
494 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
495 . ' WHERE '
496 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
497 . ' IS NULL AND '
498 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
499 . ' IS NOT NULL';
500 $this_url_params = array_merge($url_params,
501 array('sql_query' => $join_query));
502 echo ' <li>'
503 . '<a href="sql.php'
504 . PMA_generate_common_url($this_url_params)
505 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
506 . '</a></li>' . "\n";
507 } // foreach $foreign
508 unset($foreign_table, $join_query);
510 </ul>
511 <?php
512 } // end if ($result)
514 } // end if (!empty($cfg['Server']['relation']))
518 * Displays the footer
520 require_once './libraries/footer.inc.php';