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