Remove old onchange attribute
[phpmyadmin/mlewandow.git] / db_structure.php
blob0004d375b310eab4c490c5af51d8c31876115666
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @package phpMyAdmin
6 */
8 /**
11 require_once './libraries/common.inc.php';
13 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
14 $GLOBALS['js_include'][] = 'db_structure.js';
16 /**
17 * Prepares the tables list if the user where not redirected to this script
18 * because there is no table in the database ($is_info is true)
20 if (empty($is_info)) {
21 // Drops/deletes/etc. multiple tables if required
22 if ((!empty($submit_mult) && isset($selected_tbl))
23 || isset($mult_btn)) {
24 $action = 'db_structure.php';
25 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
27 // see bug #2794840; in this case, code path is:
28 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
29 // -> db_structure.php and if we got an error on the multi submit,
30 // we must display it here and not call again mult_submits.inc.php
31 if (! isset($error) || FALSE === $error) {
32 require './libraries/mult_submits.inc.php';
34 if (empty($message)) {
35 $message = PMA_Message::success();
38 require './libraries/db_common.inc.php';
39 $url_query .= '&amp;goto=db_structure.php';
41 // Gets the database structure
42 $sub_part = '_structure';
43 require './libraries/db_info.inc.php';
45 require_once './libraries/replication.inc.php';
48 require_once './libraries/bookmark.lib.php';
50 require_once './libraries/mysql_charsets.lib.php';
51 $db_collation = PMA_getDbCollation($db);
53 // in a separate file to avoid redeclaration of functions in some code paths
54 require_once './libraries/db_structure.lib.php';
55 $titles = PMA_buildActionTitles();
57 // 1. No tables
58 if ($num_tables == 0) {
59 echo '<p>' . __('No tables found in database') . '</p>' . "\n";
61 // Routines
62 require './libraries/db_routines.inc.php';
64 // Events
65 if (PMA_MYSQL_INT_VERSION > 50100) {
66 require './libraries/db_events.inc.php';
69 if (empty($db_is_information_schema)) {
70 require './libraries/display_create_table.lib.php';
71 } // end if (Create Table dialog)
73 /**
74 * Displays the footer
76 require_once './libraries/footer.inc.php';
77 exit;
80 // else
81 // 2. Shows table informations
83 /**
84 * Displays the tables list
86 $_url_params = array(
87 'pos' => $pos,
88 'db' => $db);
90 // Add the sort options if they exists
91 if (isset($_REQUEST['sort'])) {
92 $_url_params['sort'] = $_REQUEST['sort'];
95 if (isset($_REQUEST['sort_order'])) {
96 $_url_params['sort_order'] = $_REQUEST['sort_order'];
99 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
102 <form method="post" action="db_structure.php" name="tablesForm" id="tablesForm">
103 <?php
104 echo PMA_generate_common_hidden_inputs($db);
106 PMA_TableHeader($db_is_information_schema, $server_slave_status);
108 $i = $sum_entries = 0;
109 $sum_size = (double) 0;
110 $overhead_size = (double) 0;
111 $overhead_check = '';
112 $checked = !empty($checkall) ? ' checked="checked"' : '';
113 $num_columns = $cfg['PropertiesNumColumns'] > 1 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1 : 0;
114 $row_count = 0;
117 $hidden_fields = array();
118 $odd_row = true;
119 $sum_row_count_pre = '';
121 $tableReductionCount = 0; // the amount to reduce the table count by
123 foreach ($tables as $keyname => $each_table) {
124 if (PMA_BS_IsHiddenTable($keyname)) {
125 $tableReductionCount++;
126 continue;
129 // Get valid statistics whatever is the table type
131 $table_is_view = false;
132 $table_encoded = urlencode($each_table['TABLE_NAME']);
133 // Sets parameters for links
134 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
135 // do not list the previous table's size info for a view
136 $formatted_size = '-';
137 $unit = '';
139 switch ( $each_table['ENGINE']) {
140 // MyISAM, ISAM or Heap table: Row count, data size and index size
141 // are accurate; data size is accurate for ARCHIVE
142 case 'MyISAM' :
143 case 'ISAM' :
144 case 'HEAP' :
145 case 'MEMORY' :
146 case 'ARCHIVE' :
147 case 'Aria' :
148 case 'Maria' :
149 if ($db_is_information_schema) {
150 $each_table['Rows'] = PMA_Table::countRecords($db,
151 $each_table['Name']);
154 if ($is_show_stats) {
155 $tblsize = doubleval($each_table['Data_length']) + doubleval($each_table['Index_length']);
156 $sum_size += $tblsize;
157 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
158 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
159 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ? 1 : 0);
160 $overhead_size += $each_table['Data_free'];
163 break;
164 case 'InnoDB' :
165 // InnoDB table: Row count is not accurate but data and index
166 // sizes are.
168 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
169 $each_table['COUNTED'] = true;
170 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
171 $each_table['TABLE_NAME'], $force_exact = true,
172 $is_view = false);
173 } else {
174 $each_table['COUNTED'] = false;
177 if ($is_show_stats) {
178 $tblsize = $each_table['Data_length'] + $each_table['Index_length'];
179 $sum_size += $tblsize;
180 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
182 //$display_rows = ' - ';
183 break;
184 // Mysql 5.0.x (and lower) uses MRG_MyISAM and MySQL 5.1.x (and higher) uses MRG_MYISAM
185 // Both are aliases for MERGE
186 case 'MRG_MyISAM' :
187 case 'MRG_MYISAM' :
188 case 'MERGE' :
189 case 'BerkeleyDB' :
190 // Merge or BerkleyDB table: Only row count is accurate.
191 if ($is_show_stats) {
192 $formatted_size = ' - ';
193 $unit = '';
195 break;
196 // for a view, the ENGINE is sometimes reported as null,
197 // or on some servers it's reported as "SYSTEM VIEW"
198 case null :
199 case 'SYSTEM VIEW' :
200 // if table is broken, Engine is reported as null, so one more test
201 if ($each_table['TABLE_TYPE'] == 'VIEW') {
202 // countRecords() takes care of $cfg['MaxExactCountViews']
203 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
204 $each_table['TABLE_NAME'], $force_exact = true,
205 $is_view = true);
206 $table_is_view = true;
208 break;
209 default :
210 // Unknown table type.
211 if ($is_show_stats) {
212 $formatted_size = 'unknown';
213 $unit = '';
215 } // end switch
217 if (! PMA_Table::isMerge($db, $each_table['TABLE_NAME'])) {
218 $sum_entries += $each_table['TABLE_ROWS'];
221 if (isset($each_table['Collation'])) {
222 $collation = '<dfn title="'
223 . PMA_getCollationDescr($each_table['Collation']) . '">'
224 . $each_table['Collation'] . '</dfn>';
225 } else {
226 $collation = '---';
229 if ($is_show_stats) {
230 if (isset($formatted_overhead)) {
231 $overhead = '<a href="tbl_structure.php?'
232 . $tbl_url_query . '#showusage">' . $formatted_overhead
233 . ' ' . $overhead_unit . '</a>' . "\n";
234 unset($formatted_overhead);
235 $overhead_check .=
236 "document.getElementById('checkbox_tbl_" . ($i + 1) . "').checked = true;";
237 } else {
238 $overhead = '-';
240 } // end if
242 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
243 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
244 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
245 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
246 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
247 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
249 $i++;
251 $row_count++;
252 if ($table_is_view) {
253 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . htmlspecialchars($each_table['TABLE_NAME']) . '" />';
256 if ($each_table['TABLE_ROWS'] > 0) {
257 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&amp;pos=0">' . $titles['Browse'] . '</a>';
258 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
259 $browse_table_label = '<a href="sql.php?' . $tbl_url_query . '&amp;pos=0">' . $truename . '</a>';
260 } else {
261 $browse_table = $titles['NoBrowse'];
262 $search_table = $titles['NoSearch'];
263 $browse_table_label = '<a href="tbl_structure.php?' . $tbl_url_query . '">' . $truename . '</a>';
266 if (! $db_is_information_schema) {
267 if (! empty($each_table['TABLE_ROWS'])) {
268 $empty_table = '<a class="truncate_table_anchor" href="sql.php?' . $tbl_url_query
269 . '&amp;sql_query=';
270 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
271 . '&amp;message_to_show='
272 . urlencode(sprintf(__('Table %s has been emptied'), htmlspecialchars($each_table['TABLE_NAME'])))
273 .'">' . $titles['Empty'] . '</a>';
274 } else {
275 $empty_table = $titles['NoEmpty'];
277 $drop_query = 'DROP '
278 . ($table_is_view ? 'VIEW' : 'TABLE')
279 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
280 $drop_message = sprintf(
281 $table_is_view ? __('View %s has been dropped') : __('Table %s has been dropped'),
282 str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME'])));
285 $tracking_icon = '';
286 if (PMA_Tracker::isActive()) {
287 if (PMA_Tracker::isTracked($GLOBALS["db"], $truename)) {
288 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query.'&amp;table=' . $truename . '"><img class="icon" width="14" height="14" src="' . $pmaThemeImage . 'eye.png" alt="' . __('Tracking is active.') . '" title="' . __('Tracking is active.') . '" /></a>';
289 } elseif (PMA_Tracker::getVersion($GLOBALS["db"], $truename) > 0) {
290 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query . '&amp;table=' . $truename . '"><img class="icon" width="14" height="14" src="' . $pmaThemeImage . 'eye_grey.png" alt="' . __('Tracking is not active.') . '" title="' . __('Tracking is not active.') . '" /></a>';
294 if ($num_columns > 0 && $num_tables > $num_columns
295 && (($row_count % $num_columns) == 0)) {
296 $row_count = 1;
297 $odd_row = true;
299 </tr>
300 </tbody>
301 </table>
302 <?php
303 PMA_TableHeader(false, $server_slave_status);
306 $ignored = false;
307 $do = false;
309 if ($server_slave_status) {
310 ////////////////////////////////////////////////////////////////
312 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
313 || (strlen(array_search($db, $server_slave_Do_DB)) > 0)
314 || (count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
316 $do = true;
318 foreach ($server_slave_Wild_Do_Table as $db_table) {
319 $table_part = PMA_extract_db_or_table($db_table, 'table');
320 if (($db == PMA_extract_db_or_table($db_table, 'db')) && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))) {
321 $do = true;
324 ////////////////////////////////////////////////////////////////////
325 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0) || (strlen(array_search($db, $server_slave_Ignore_DB)) > 0)) {
326 $ignored = true;
328 foreach ($server_slave_Wild_Ignore_Table as $db_table) {
329 $table_part = PMA_extract_db_or_table($db_table, 'table');
330 if (($db == PMA_extract_db_or_table($db_table)) && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))) {
331 $ignored = true;
334 unset($table_part);
337 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
338 <td align="center">
339 <input type="checkbox" name="selected_tbl[]"
340 value="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
341 id="checkbox_tbl_<?php echo $i; ?>"<?php echo $checked; ?> /></td>
342 <th><?php echo $browse_table_label; ?>
343 <?php echo (! empty($tracking_icon) ? $tracking_icon : ''); ?>
344 </th>
345 <?php if ($server_slave_status) { ?><td align="center"><?php echo $ignored ? ' <img class="icon" src="' . $pmaThemeImage . 's_cancel.png" width="16" height="16" alt="NOT REPLICATED" />' : ''. $do ? ' <img class="icon" src="' . $pmaThemeImage . 's_success.png" width="16" height="16" alt="REPLICATED" />' : ''; ?></td><?php } ?>
346 <td align="center"><?php echo $browse_table; ?></td>
347 <td align="center">
348 <a href="tbl_structure.php?<?php echo $tbl_url_query; ?>">
349 <?php echo $titles['Structure']; ?></a></td>
350 <td align="center"><?php echo $search_table; ?></td>
351 <?php if (! $db_is_information_schema) { ?>
352 <td align="center">
353 <a href="tbl_change.php?<?php echo $tbl_url_query; ?>">
354 <?php echo $titles['Insert']; ?></a></td>
355 <td align="center"><?php echo $empty_table; ?></td>
356 <td align="center">
357 <a class="drop_table_anchor" href="sql.php?<?php echo $tbl_url_query;
358 ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php
359 echo urlencode($drop_query); ?>&amp;message_to_show=<?php
360 echo urlencode($drop_message); ?>" >
361 <?php echo $titles['Drop']; ?></a></td>
362 <?php } // end if (! $db_is_information_schema)
364 // there is a null value in the ENGINE
365 // - when the table needs to be repaired, or
366 // - when it's a view
367 // so ensure that we'll display "in use" below for a table
368 // that needs to be repaired
369 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null || $table_is_view)) {
370 if ($table_is_view) {
371 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']){
372 $row_count_pre = '~';
373 $sum_row_count_pre = '~';
374 $show_superscript = PMA_showHint(PMA_sanitize(sprintf(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'), '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
376 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
377 // InnoDB table: we did not get an accurate row count
378 $row_count_pre = '~';
379 $sum_row_count_pre = '~';
380 $show_superscript = '';
381 } else {
382 $row_count_pre = '';
383 $show_superscript = '';
386 <td class="value tbl_rows"><?php echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?></td>
387 <?php if (!($cfg['PropertiesNumColumns'] > 1)) { ?>
388 <td nowrap="nowrap"><?php echo ($table_is_view ? __('View') : $each_table['ENGINE']); ?></td>
389 <?php if (isset($collation)) { ?>
390 <td nowrap="nowrap"><?php echo $collation ?></td>
391 <?php } ?>
392 <?php } ?>
394 <?php if ($is_show_stats) { ?>
395 <td class="value tbl_size"><a
396 href="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
397 ><?php echo $formatted_size . ' ' . $unit; ?></a></td>
398 <td class="value"><?php echo $overhead; ?></td>
399 <?php } // end if ?>
400 <?php } elseif ($table_is_view) { ?>
401 <td class="value">-</td>
402 <td><?php echo __('View'); ?></td>
403 <td>---</td>
404 <?php if ($is_show_stats) { ?>
405 <td class="value">-</td>
406 <td class="value">-</td>
407 <?php } ?>
408 <?php } else { ?>
409 <td colspan="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
410 align="center">
411 <?php echo __('in use'); ?></td>
412 <?php } // end if (isset($each_table['TABLE_ROWS'])) else ?>
413 </tr>
414 <?php
415 } // end foreach
417 // Show Summary
418 if ($is_show_stats) {
419 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
420 list($overhead_formatted, $overhead_unit) =
421 PMA_formatByteDown($overhead_size, 3, 1);
424 </tbody>
425 <tbody id="tbl_summary_row">
426 <tr><th></th>
427 <th align="center" nowrap="nowrap">
428 <?php
429 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
430 // (we don't want negative numbers here)
431 if ($num_tables == 0)
432 $tableReductionCount = 0;
434 echo sprintf(_ngettext('%s table', '%s tables', $num_tables - $tableReductionCount), PMA_formatNumber($num_tables - $tableReductionCount, 0));
436 </th>
437 <?php
438 if ($server_slave_status) {
439 echo ' <th>' . __('Replication') . '</th>' . "\n";
442 <th colspan="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align="center">
443 <?php echo __('Sum'); ?></th>
444 <th class="value tbl_rows"><?php echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?></th>
445 <?php
446 if (!($cfg['PropertiesNumColumns'] > 1)) {
447 $default_engine = PMA_DBI_get_default_engine();
448 echo ' <th align="center">' . "\n"
449 . ' <dfn title="'
450 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
451 // we got a case where $db_collation was empty
452 echo ' <th align="center">' . "\n";
453 if (! empty($db_collation)) {
454 echo ' <dfn title="'
455 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
456 . '</dfn>';
458 echo '</th>';
461 if ($is_show_stats) {
463 <th class="value tbl_size"><?php echo $sum_formatted . ' ' . $unit; ?></th>
464 <th class="value"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
465 <?php
468 </tr>
469 </tbody>
470 </table>
472 <div class="clearfloat">
473 <?php
474 // Check all tables url
475 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
477 <img class="selectallarrow" src="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
478 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
479 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
480 onclick="if (markAllRows('tablesForm')) return false;">
481 <?php echo __('Check All'); ?></a>
483 <a href="<?php echo $checkall_url; ?>"
484 onclick="if (unMarkAllRows('tablesForm')) return false;">
485 <?php echo __('Uncheck All'); ?></a>
486 <?php if ($overhead_check != '') { ?>
488 <a href="#" onclick="unMarkAllRows('tablesForm');
489 <?php echo $overhead_check; ?> return false;">
490 <?php echo __('Check tables having overhead'); ?></a>
491 <?php } ?>
493 <select name="submit_mult" onchange="this.form.submit();" style="margin: 0 3em 0 3em;">
494 <?php
495 echo ' <option value="' . __('With selected:') . '" selected="selected">'
496 . __('With selected:') . '</option>' . "\n";
497 echo ' <option value="' . __('Export') . '" >'
498 . __('Export') . '</option>' . "\n";
499 echo ' <option value="' . __('Print view') . '" >'
500 . __('Print view') . '</option>' . "\n";
502 if (!$db_is_information_schema) {
503 echo ' <option value="' . __('Empty') . '" >'
504 . __('Empty') . '</option>' . "\n";
505 echo ' <option value="' . __('Drop') . '" >'
506 . __('Drop') . '</option>' . "\n";
507 echo ' <option value="' . __('Check table') . '" >'
508 . __('Check table') . '</option>' . "\n";
509 echo ' <option value="' . __('Optimize table') . '" >'
510 . __('Optimize table') . '</option>' . "\n";
511 echo ' <option value="' . __('Repair table') . '" >'
512 . __('Repair table') . '</option>' . "\n";
513 echo ' <option value="' . __('Analyze table') . '" >'
514 . __('Analyze table') . '</option>' . "\n";
517 </select>
518 <script type="text/javascript">
519 <!--
520 // Fake js to allow the use of the <noscript> tag
521 //-->
522 </script>
523 <noscript>
524 <input type="submit" value="<?php echo __('Go'); ?>" />
525 </noscript>
526 <?php echo implode("\n", $hidden_fields) . "\n"; ?>
527 </div>
528 </form>
529 <?php
530 // display again the table list navigator
531 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
533 <hr />
535 <?php
536 // Routines
537 require './libraries/db_routines.inc.php';
539 // Events
540 if (PMA_MYSQL_INT_VERSION > 50100) {
541 require './libraries/db_events.inc.php';
545 * Work on the database
547 /* DATABASE WORK */
548 /* Printable view of a table */
549 echo '<p>';
550 echo '<a href="db_printview.php?' . $url_query . '">';
551 if ($cfg['PropertiesIconic']) {
552 echo '<img class="icon" src="' . $pmaThemeImage
553 .'b_print.png" width="16" height="16" alt="" />';
555 echo __('Print view') . '</a> ';
557 echo '<a href="./db_datadict.php?' . $url_query . '">';
558 if ($cfg['PropertiesIconic']) {
559 echo '<img class="icon" src="' . $pmaThemeImage
560 .'b_tblanalyse.png" width="16" height="16" alt="" />';
562 echo __('Data Dictionary') . '</a>';
563 echo '</p>';
565 if (empty($db_is_information_schema)) {
566 require './libraries/display_create_table.lib.php';
567 } // end if (Create Table dialog)
570 * Displays the footer
572 require './libraries/footer.inc.php';