2.11.7-dev
[phpmyadmin/sankalp_k.git] / tbl_operations.php
blob4dab6a1a439e8e37fa3601920402e900775174ff
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 <?php if ($GLOBALS['PMA_List_Database']->count() > $GLOBALS['cfg']['MaxDbList']) {
193 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
194 <?php
195 } else {
197 <select name="target_db">
198 <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?>
199 </select>
200 <?php
201 } // end if
203 &nbsp;<b>.</b>&nbsp;
204 <input type="text" size="20" name="new_name" onfocus="this.select()"
205 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
206 <?php
207 // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
208 // next value but users can decide if they want it or not for the operation
210 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_mv" checked="checked" />
211 <label for="checkbox_auto_increment_mv"><?php echo $strAddAutoIncrement; ?></label><br />
212 </fieldset>
213 <fieldset class="tblFooters">
214 <input type="submit" name="submit_move" value="<?php echo $strGo; ?>" />
215 </fieldset>
216 </form>
217 </div>
219 <?php
220 if (strstr($show_comment, '; InnoDB free') === false) {
221 if (strstr($show_comment, 'InnoDB free') === false) {
222 // only user entered comment
223 $comment = $show_comment;
224 } else {
225 // here we have just InnoDB generated part
226 $comment = '';
228 } else {
229 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
230 $comment = preg_replace('@; InnoDB free:.*?$@', '', $show_comment);
233 // PACK_KEYS: MyISAM or ISAM
234 // DELAY_KEY_WRITE, CHECKSUM, : MyISAM only
235 // AUTO_INCREMENT: MyISAM and InnoDB since 5.0.3
237 // nijel: Here should be version check for InnoDB, however it is supported
238 // in >5.0.4, >4.1.12 and >4.0.11, so I decided not to
239 // check for version
242 <!-- Table options -->
243 <div id="div_table_options">
244 <form method="post" action="tbl_operations.php">
245 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
246 <input type="hidden" name="reload" value="1" />
247 <fieldset>
248 <legend><?php echo $strTableOptions; ?></legend>
250 <table>
251 <!-- Change table name -->
252 <tr><td><?php echo $strRenameTable; ?></td>
253 <td><input type="text" size="20" name="new_name" onfocus="this.select()"
254 value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" />
255 </td>
256 </tr>
258 <!-- Table comments -->
259 <tr><td><?php echo $strTableComments; ?></td>
260 <td><input type="text" name="comment" maxlength="60" size="30"
261 value="<?php echo htmlspecialchars($comment); ?>" onfocus="this.select()" />
262 <input type="hidden" name="prev_comment" value="<?php echo urlencode($comment); ?>" />
263 </td>
264 </tr>
266 <!-- Storage engine -->
267 <tr><td><?php echo $strStorageEngine; ?>
268 <?php echo PMA_showMySQLDocu('Storage_engines', 'Storage_engines'); ?>
269 </td>
270 <td><?php echo PMA_StorageEngine::getHtmlSelect('new_tbl_type', null, $tbl_type); ?>
271 </td>
272 </tr>
274 <?php
275 if (PMA_MYSQL_INT_VERSION >= 40100) {
277 <!-- Table character set -->
278 <tr><td><?php echo $strCollation; ?></td>
279 <td><?php echo PMA_generateCharsetDropdownBox(PMA_CSDROPDOWN_COLLATION,
280 'tbl_collation', null, $tbl_collation, false, 3); ?>
281 </td>
282 </tr>
283 <?php
285 if ($tbl_type == 'MYISAM' || $tbl_type == 'ISAM') {
287 <tr>
288 <td><label for="new_pack_keys">pack_keys</label></td>
289 <td><select name="new_pack_keys" id="new_pack_keys">
290 <option value="DEFAULT"
291 <?php if ($pack_keys == 'DEFAULT') echo 'selected="selected"'; ?>
292 >DEFAULT</option>
293 <option value="0"
294 <?php if ($pack_keys == '0') echo 'selected="selected"'; ?>
295 >0</option>
296 <option value="1"
297 <?php if ($pack_keys == '1') echo 'selected="selected"'; ?>
298 >1</option>
299 </select>
300 </td>
301 </tr>
302 <?php
303 } // end if (MYISAM|ISAM)
305 if ($tbl_type == 'MYISAM') {
307 <tr><td><label for="new_checksum">checksum</label></td>
308 <td><input type="checkbox" name="new_checksum" id="new_checksum"
309 value="1"
310 <?php echo (isset($checksum) && $checksum == 1)
311 ? ' checked="checked"'
312 : ''; ?> />
313 </td>
314 </tr>
316 <tr><td><label for="new_delay_key_write">delay_key_write</label></td>
317 <td><input type="checkbox" name="new_delay_key_write" id="new_delay_key_write"
318 value="1"
319 <?php echo (isset($delay_key_write) && $delay_key_write == 1)
320 ? ' checked="checked"'
321 : ''; ?> />
322 </td>
323 </tr>
325 <?php
326 } // end if (MYISAM)
328 if (isset($auto_increment) && strlen($auto_increment) > 0
329 && ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB')) {
331 <tr><td><label for="auto_increment_opt">auto_increment</label></td>
332 <td><input type="text" name="new_auto_increment" id="auto_increment_opt"
333 value="<?php echo $auto_increment; ?>" /></td>
334 </tr>
335 <?php
336 } // end if (MYISAM|INNODB)
338 </table>
339 </fieldset>
340 <fieldset class="tblFooters">
341 <input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" />
342 </fieldset>
343 </form>
344 </div>
346 <!-- Copy table -->
347 <div id="div_table_copy">
348 <form method="post" action="tbl_move_copy.php"
349 onsubmit="return emptyFormElements(this, 'new_name')">
350 <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); ?>
351 <input type="hidden" name="reload" value="1" />
352 <fieldset>
353 <legend><?php echo $strCopyTable; ?></legend>
354 <?php if ($GLOBALS['PMA_List_Database']->count() > $GLOBALS['cfg']['MaxDbList']) {
356 <input type="text" maxlength="100" size="30" name="target_db" value="<?php echo htmlspecialchars($GLOBALS['db']); ?>"/>
357 <?php
358 } else {
360 <select name="target_db">
361 <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true, false); ?>
362 </select>
363 <?php
364 } // end if
366 &nbsp;<b>.</b>&nbsp;
367 <input type="text" size="20" name="new_name" onfocus="this.select()" /><br />
369 <input type="radio" name="what" value="structure" id="radio_copy_structure" />
370 <label for="radio_copy_structure"><?php echo $strStrucOnly; ?></label><br />
371 <input type="radio" name="what" value="data" id="radio_copy_data" checked="checked" />
372 <label for="radio_copy_data"><?php echo $strStrucData; ?></label><br />
373 <input type="radio" name="what" value="dataonly" id="radio_copy_dataonly" />
374 <label for="radio_copy_dataonly"><?php echo $strDataOnly; ?></label><br />
376 <input type="checkbox" name="drop_if_exists" value="true" id="checkbox_drop" />
377 <label for="checkbox_drop"><?php echo sprintf($strAddClause, 'DROP TABLE'); ?></label><br />
378 <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment_cp" />
379 <label for="checkbox_auto_increment_cp"><?php echo $strAddAutoIncrement; ?></label><br />
380 <?php
381 // display "Add constraints" choice only if there are
382 // foreign keys
383 if (PMA_getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'innodb')) {
385 <input type="checkbox" name="add_constraints" value="1" id="checkbox_constraints" />
386 <label for="checkbox_constraints"><?php echo $strAddConstraints; ?></label><br />
387 <?php
388 } // endif
389 if (isset($_COOKIE['pma_switch_to_new'])
390 && $_COOKIE['pma_switch_to_new'] == 'true') {
391 $pma_switch_to_new = 'true';
394 <input type="checkbox" name="switch_to_new" value="true"
395 id="checkbox_switch"<?php echo
396 isset($pma_switch_to_new) && $pma_switch_to_new == 'true'
397 ? ' checked="checked"'
398 : ''; ?> />
399 <label for="checkbox_switch"><?php echo $strSwitchToTable; ?></label>
400 </fieldset>
401 <fieldset class="tblFooters">
402 <input type="submit" name="submit_copy" value="<?php echo $strGo; ?>" />
403 </fieldset>
404 </form>
405 </div>
407 <br class="clearfloat"/>
409 <h1><?php echo $strTableMaintenance; ?></h1>
411 <ul>
412 <?php
413 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
414 if ($tbl_type == 'MYISAM' || $tbl_type == 'INNODB') {
415 $this_url_params = array_merge($url_params,
416 array('sql_query' => 'CHECK TABLE ' . PMA_backquote($GLOBALS['table'])));
418 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
419 <?php echo $strCheckTable; ?></a>
420 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'CHECK_TABLE'); ?>
421 </li>
422 <?php
424 if ($tbl_type == 'INNODB') {
425 $this_url_params = array_merge($url_params,
426 array('sql_query' => 'ALTER TABLE ' . PMA_backquote($GLOBALS['table']) . ' ' . PMA_ENGINE_KEYWORD . '=InnoDB'));
428 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
429 <?php echo $strDefragment; ?></a>
430 <?php echo PMA_showMySQLDocu('Table_types', 'InnoDB_File_Defragmenting'); ?>
431 </li>
432 <?php
434 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB') {
435 $this_url_params = array_merge($url_params,
436 array('sql_query' => 'ANALYZE TABLE ' . PMA_backquote($GLOBALS['table'])));
438 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
439 <?php echo $strAnalyzeTable; ?></a>
440 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'ANALYZE_TABLE');?>
441 </li>
442 <?php
444 if ($tbl_type == 'MYISAM') {
445 $this_url_params = array_merge($url_params,
446 array('sql_query' => 'REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])));
448 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
449 <?php echo $strRepairTable; ?></a>
450 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'REPAIR_TABLE'); ?>
451 </li>
452 <?php
454 if ($tbl_type == 'MYISAM' || $tbl_type == 'BERKELEYDB' || $tbl_type == 'INNODB') {
455 $this_url_params = array_merge($url_params,
456 array('sql_query' => 'OPTIMIZE TABLE ' . PMA_backquote($GLOBALS['table'])));
458 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
459 <?php echo $strOptimizeTable; ?></a>
460 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'OPTIMIZE_TABLE'); ?>
461 </li>
462 <?php
464 } // end MYISAM or BERKELEYDB case
465 $this_url_params = array_merge($url_params,
466 array(
467 'sql_query' => 'FLUSH TABLE ' . PMA_backquote($GLOBALS['table']),
468 'zero_rows' => sprintf($strTableHasBeenFlushed,
469 htmlspecialchars($GLOBALS['table'])),
470 'reload' => 1,
473 <li><a href="sql.php<?php echo PMA_generate_common_url($this_url_params); ?>">
474 <?php echo $strFlushTable; ?></a>
475 <?php echo PMA_showMySQLDocu('MySQL_Database_Administration', 'FLUSH'); ?>
476 </li>
477 </ul>
478 <?php
479 // Referential integrity check
480 // The Referential integrity check was intended for the non-InnoDB
481 // tables for which the relations are defined in pmadb
482 // so I assume that if the current table is InnoDB, I don't display
483 // this choice (InnoDB maintains integrity by itself)
485 if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
487 // we need this PMA_DBI_select_db if the user has access to more than one db
488 // and $GLOBALS['db'] is not the last of the list, because
489 // PMA_List_Database::_checkAccess()
490 // has made a PMA_DBI_select_db() on the last one
491 PMA_DBI_select_db($GLOBALS['db']);
492 $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);
494 if ($foreign) {
496 <!-- Referential integrity check -->
497 <ul>
498 <?php echo $strReferentialIntegrity; ?><br />
499 <?php
500 echo "\n";
501 foreach ($foreign AS $master => $arr) {
502 $join_query = 'SELECT ' . PMA_backquote($GLOBALS['table']) . '.* FROM '
503 . PMA_backquote($GLOBALS['table']) . ' LEFT JOIN '
504 . PMA_backquote($arr['foreign_table']);
505 if ($arr['foreign_table'] == $GLOBALS['table']) {
506 $foreign_table = $GLOBALS['table'] . '1';
507 $join_query .= ' AS ' . PMA_backquote($foreign_table);
508 } else {
509 $foreign_table = $arr['foreign_table'];
511 $join_query .= ' ON '
512 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
513 . ' = ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
514 . ' WHERE '
515 . PMA_backquote($foreign_table) . '.' . PMA_backquote($arr['foreign_field'])
516 . ' IS NULL AND '
517 . PMA_backquote($GLOBALS['table']) . '.' . PMA_backquote($master)
518 . ' IS NOT NULL';
519 $this_url_params = array_merge($url_params,
520 array('sql_query' => $join_query));
521 echo ' <li>'
522 . '<a href="sql.php'
523 . PMA_generate_common_url($this_url_params)
524 . '">' . $master . '&nbsp;->&nbsp;' . $arr['foreign_table'] . '.' . $arr['foreign_field']
525 . '</a></li>' . "\n";
526 } // foreach $foreign
527 unset($foreign_table, $join_query);
529 </ul>
530 <?php
531 } // end if ($result)
533 } // end if (!empty($cfg['Server']['relation']))
537 * Displays the footer
539 require_once './libraries/footer.inc.php';