Merge remote branch 'origin/master'
[phpmyadmin-themes.git] / db_structure.php
blobf826ce1c17b636053f72fa56a8f98d9523f7b65f
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 // 1. No tables
49 if ($num_tables == 0) {
50 echo '<p>' . __('No tables found in database.') . '</p>' . "\n";
52 if (empty($db_is_information_schema)) {
53 require './libraries/display_create_table.lib.php';
54 } // end if (Create Table dialog)
56 /**
57 * Displays the footer
59 require './libraries/footer.inc.php';
60 exit;
63 // else
64 // 2. Shows table informations
66 require_once './libraries/bookmark.lib.php';
68 require_once './libraries/mysql_charsets.lib.php';
69 $db_collation = PMA_getDbCollation($db);
71 // in a separate file to avoid redeclaration of functions in some code paths
72 require_once './libraries/db_structure.lib.php';
73 require_once './libraries/build_action_titles.inc.php';
75 /**
76 * Displays the tables list
78 $_url_params = array(
79 'pos' => $pos,
80 'db' => $db);
82 // Add the sort options if they exists
83 if (isset($_REQUEST['sort'])) {
84 $_url_params['sort'] = $_REQUEST['sort'];
87 if (isset($_REQUEST['sort_order'])) {
88 $_url_params['sort_order'] = $_REQUEST['sort_order'];
91 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
94 <form method="post" action="db_structure.php" name="tablesForm" id="tablesForm">
95 <?php
96 echo PMA_generate_common_hidden_inputs($db);
98 PMA_TableHeader($db_is_information_schema, $server_slave_status);
100 $i = $sum_entries = 0;
101 $sum_size = (double) 0;
102 $overhead_size = (double) 0;
103 $overhead_check = '';
104 $checked = !empty($checkall) ? ' checked="checked"' : '';
105 $num_columns = $cfg['PropertiesNumColumns'] > 1 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1 : 0;
106 $row_count = 0;
109 $hidden_fields = array();
110 $odd_row = true;
111 $sum_row_count_pre = '';
113 $tableReductionCount = 0; // the amount to reduce the table count by
115 foreach ($tables as $keyname => $each_table) {
116 if (PMA_BS_IsHiddenTable($keyname)) {
117 $tableReductionCount++;
118 continue;
121 // Get valid statistics whatever is the table type
123 $table_is_view = false;
124 $table_encoded = urlencode($each_table['TABLE_NAME']);
125 // Sets parameters for links
126 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
127 // do not list the previous table's size info for a view
128 $formatted_size = '-';
129 $unit = '';
131 switch ( $each_table['ENGINE']) {
132 // MyISAM, ISAM or Heap table: Row count, data size and index size
133 // are accurate; data size is accurate for ARCHIVE
134 case 'MyISAM' :
135 case 'ISAM' :
136 case 'HEAP' :
137 case 'MEMORY' :
138 case 'ARCHIVE' :
139 if ($db_is_information_schema) {
140 $each_table['Rows'] = PMA_Table::countRecords($db,
141 $each_table['Name']);
144 if ($is_show_stats) {
145 $tblsize = doubleval($each_table['Data_length']) + doubleval($each_table['Index_length']);
146 $sum_size += $tblsize;
147 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
148 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
149 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ? 1 : 0);
150 $overhead_size += $each_table['Data_free'];
153 break;
154 case 'InnoDB' :
155 // InnoDB table: Row count is not accurate but data and index
156 // sizes are.
158 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
159 $each_table['COUNTED'] = true;
160 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
161 $each_table['TABLE_NAME'], $force_exact = true,
162 $is_view = false);
163 } else {
164 $each_table['COUNTED'] = false;
167 if ($is_show_stats) {
168 $tblsize = $each_table['Data_length'] + $each_table['Index_length'];
169 $sum_size += $tblsize;
170 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
172 //$display_rows = ' - ';
173 break;
174 // Mysql 5.0.x (and lower) uses MRG_MyISAM and MySQL 5.1.x (and higher) uses MRG_MYISAM
175 // Both are aliases for MERGE
176 case 'MRG_MyISAM' :
177 case 'MRG_MYISAM' :
178 case 'MERGE' :
179 case 'BerkeleyDB' :
180 // Merge or BerkleyDB table: Only row count is accurate.
181 if ($is_show_stats) {
182 $formatted_size = ' - ';
183 $unit = '';
185 break;
186 // for a view, the ENGINE is sometimes reported as null,
187 // or on some servers it's reported as "SYSTEM VIEW"
188 case null :
189 case 'SYSTEM VIEW' :
190 // if table is broken, Engine is reported as null, so one more test
191 if ($each_table['TABLE_TYPE'] == 'VIEW') {
192 // countRecords() takes care of $cfg['MaxExactCountViews']
193 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
194 $each_table['TABLE_NAME'], $force_exact = true,
195 $is_view = true);
196 $table_is_view = true;
198 break;
199 default :
200 // Unknown table type.
201 if ($is_show_stats) {
202 $formatted_size = 'unknown';
203 $unit = '';
205 } // end switch
207 if (! PMA_Table::isMerge($db, $each_table['TABLE_NAME'])) {
208 $sum_entries += $each_table['TABLE_ROWS'];
211 if (isset($each_table['Collation'])) {
212 $collation = '<dfn title="'
213 . PMA_getCollationDescr($each_table['Collation']) . '">'
214 . $each_table['Collation'] . '</dfn>';
215 } else {
216 $collation = '---';
219 if ($is_show_stats) {
220 if (isset($formatted_overhead)) {
221 $overhead = '<a href="tbl_structure.php?'
222 . $tbl_url_query . '#showusage">' . $formatted_overhead
223 . ' ' . $overhead_unit . '</a>' . "\n";
224 unset($formatted_overhead);
225 $overhead_check .=
226 "document.getElementById('checkbox_tbl_" . ($i + 1) . "').checked = true;";
227 } else {
228 $overhead = '-';
230 } // end if
232 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
233 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
234 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
235 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
236 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
237 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
239 $i++;
241 $row_count++;
242 if ($table_is_view) {
243 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . htmlspecialchars($each_table['TABLE_NAME']) . '" />';
246 if ($each_table['TABLE_ROWS'] > 0) {
247 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&amp;pos=0">' . $titles['Browse'] . '</a>';
248 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
249 $browse_table_label = '<a href="sql.php?' . $tbl_url_query . '&amp;pos=0">' . $truename . '</a>';
250 } else {
251 $browse_table = $titles['NoBrowse'];
252 $search_table = $titles['NoSearch'];
253 $browse_table_label = '<a href="tbl_structure.php?' . $tbl_url_query . '">' . $truename . '</a>';
256 if (! $db_is_information_schema) {
257 if (! empty($each_table['TABLE_ROWS'])) {
258 $empty_table = '<a class="truncate_table_anchor" href="sql.php?' . $tbl_url_query
259 . '&amp;sql_query=';
260 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
261 . '&amp;message_to_show='
262 . urlencode(sprintf(__('Table %s has been emptied'), htmlspecialchars($each_table['TABLE_NAME'])))
263 .'">' . $titles['Empty'] . '</a>';
264 } else {
265 $empty_table = $titles['NoEmpty'];
267 $drop_query = 'DROP '
268 . ($table_is_view ? 'VIEW' : 'TABLE')
269 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
270 $drop_message = sprintf(
271 $table_is_view ? __('View %s has been dropped') : __('Table %s has been dropped'),
272 str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME'])));
275 $tracking_icon = '';
276 if (PMA_Tracker::isActive()) {
277 if (PMA_Tracker::isTracked($GLOBALS["db"], $truename)) {
278 $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>';
279 } elseif (PMA_Tracker::getVersion($GLOBALS["db"], $truename) > 0) {
280 $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>';
284 if ($num_columns > 0 && $num_tables > $num_columns
285 && (($row_count % $num_columns) == 0)) {
286 $row_count = 1;
287 $odd_row = true;
289 </tr>
290 </tbody>
291 </table>
292 <?php
293 PMA_TableHeader(false, $server_slave_status);
296 $ignored = false;
297 $do = false;
299 if ($server_slave_status) {
300 ////////////////////////////////////////////////////////////////
302 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
303 || (strlen(array_search($db, $server_slave_Do_DB)) > 0)
304 || (count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
306 $do = true;
308 foreach ($server_slave_Wild_Do_Table as $db_table) {
309 $table_part = PMA_extract_db_or_table($db_table, 'table');
310 if (($db == PMA_extract_db_or_table($db_table, 'db')) && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))) {
311 $do = true;
314 ////////////////////////////////////////////////////////////////////
315 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0) || (strlen(array_search($db, $server_slave_Ignore_DB)) > 0)) {
316 $ignored = true;
318 foreach ($server_slave_Wild_Ignore_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)) && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))) {
321 $ignored = true;
324 unset($table_part);
327 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
328 <td align="center">
329 <input type="checkbox" name="selected_tbl[]"
330 value="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
331 id="checkbox_tbl_<?php echo $i; ?>"<?php echo $checked; ?> /></td>
332 <th><?php echo $browse_table_label; ?>
333 <?php echo (! empty($tracking_icon) ? $tracking_icon : ''); ?>
334 </th>
335 <?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 } ?>
336 <td align="center"><?php echo $browse_table; ?></td>
337 <td align="center">
338 <a href="tbl_structure.php?<?php echo $tbl_url_query; ?>">
339 <?php echo $titles['Structure']; ?></a></td>
340 <td align="center"><?php echo $search_table; ?></td>
341 <?php if (! $db_is_information_schema) { ?>
342 <td align="center">
343 <a href="tbl_change.php?<?php echo $tbl_url_query; ?>">
344 <?php echo $titles['Insert']; ?></a></td>
345 <td align="center"><?php echo $empty_table; ?></td>
346 <td align="center">
347 <a class="drop_table_anchor" href="sql.php?<?php echo $tbl_url_query;
348 ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php
349 echo urlencode($drop_query); ?>&amp;message_to_show=<?php
350 echo urlencode($drop_message); ?>" >
351 <?php echo $titles['Drop']; ?></a></td>
352 <?php } // end if (! $db_is_information_schema)
354 // there is a null value in the ENGINE
355 // - when the table needs to be repaired, or
356 // - when it's a view
357 // so ensure that we'll display "in use" below for a table
358 // that needs to be repaired
359 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null || $table_is_view)) {
360 if ($table_is_view) {
361 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']){
362 $row_count_pre = '~';
363 $sum_row_count_pre = '~';
364 $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]')));
366 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
367 // InnoDB table: we did not get an accurate row count
368 $row_count_pre = '~';
369 $sum_row_count_pre = '~';
370 $show_superscript = '';
371 } else {
372 $row_count_pre = '';
373 $show_superscript = '';
376 <td class="value"><?php echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?></td>
377 <?php if (!($cfg['PropertiesNumColumns'] > 1)) { ?>
378 <td nowrap="nowrap"><?php echo ($table_is_view ? __('View') : $each_table['ENGINE']); ?></td>
379 <?php if (isset($collation)) { ?>
380 <td nowrap="nowrap"><?php echo $collation ?></td>
381 <?php } ?>
382 <?php } ?>
384 <?php if ($is_show_stats) { ?>
385 <td class="value"><a
386 href="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
387 ><?php echo $formatted_size . ' ' . $unit; ?></a></td>
388 <td class="value"><?php echo $overhead; ?></td>
389 <?php } // end if ?>
390 <?php } elseif ($table_is_view) { ?>
391 <td class="value">-</td>
392 <td><?php echo __('View'); ?></td>
393 <td>---</td>
394 <?php if ($is_show_stats) { ?>
395 <td class="value">-</td>
396 <td class="value">-</td>
397 <?php } ?>
398 <?php } else { ?>
399 <td colspan="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
400 align="center">
401 <?php echo __('in use'); ?></td>
402 <?php } // end if (isset($each_table['TABLE_ROWS'])) else ?>
403 </tr>
404 <?php
405 } // end foreach
407 // Show Summary
408 if ($is_show_stats) {
409 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
410 list($overhead_formatted, $overhead_unit) =
411 PMA_formatByteDown($overhead_size, 3, 1);
414 </tbody>
415 <tbody id="tbl_summary_row">
416 <tr><th></th>
417 <th align="center" nowrap="nowrap">
418 <?php
419 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
420 // (we don't want negative numbers here)
421 if ($num_tables == 0)
422 $tableReductionCount = 0;
424 echo sprintf(_ngettext('%s table', '%s tables', $num_tables - $tableReductionCount), PMA_formatNumber($num_tables - $tableReductionCount, 0));
426 </th>
427 <?php
428 if ($server_slave_status) {
429 echo ' <th>' . __('Replication') . '</th>' . "\n";
432 <th colspan="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align="center">
433 <?php echo __('Sum'); ?></th>
434 <th class="value"><?php echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?></th>
435 <?php
436 if (!($cfg['PropertiesNumColumns'] > 1)) {
437 $default_engine = PMA_DBI_get_default_engine();
438 echo ' <th align="center">' . "\n"
439 . ' <dfn title="'
440 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
441 // we got a case where $db_collation was empty
442 echo ' <th align="center">' . "\n";
443 if (! empty($db_collation)) {
444 echo ' <dfn title="'
445 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
446 . '</dfn>';
448 echo '</th>';
451 if ($is_show_stats) {
453 <th class="value"><?php echo $sum_formatted . ' ' . $unit; ?></th>
454 <th class="value"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
455 <?php
458 </tr>
459 </tbody>
460 </table>
462 <div class="clearfloat">
463 <?php
464 // Check all tables url
465 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
467 <img class="selectallarrow" src="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
468 width="38" height="22" alt="<?php echo __('With selected:'); ?>" />
469 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
470 onclick="if (markAllRows('tablesForm')) return false;">
471 <?php echo __('Check All'); ?></a>
473 <a href="<?php echo $checkall_url; ?>"
474 onclick="if (unMarkAllRows('tablesForm')) return false;">
475 <?php echo __('Uncheck All'); ?></a>
476 <?php if ($overhead_check != '') { ?>
478 <a href="#" onclick="unMarkAllRows('tablesForm');
479 <?php echo $overhead_check; ?> return false;">
480 <?php echo __('Check tables having overhead'); ?></a>
481 <?php } ?>
483 <select name="submit_mult" onchange="this.form.submit();" style="margin: 0 3em 0 3em;">
484 <?php
485 echo ' <option value="' . __('With selected:') . '" selected="selected">'
486 . __('With selected:') . '</option>' . "\n";
487 echo ' <option value="' . __('Export') . '" >'
488 . __('Export') . '</option>' . "\n";
489 echo ' <option value="' . __('Print view') . '" >'
490 . __('Print view') . '</option>' . "\n";
492 if (!$db_is_information_schema) {
493 echo ' <option value="' . __('Empty') . '" >'
494 . __('Empty') . '</option>' . "\n";
495 echo ' <option value="' . __('Drop') . '" >'
496 . __('Drop') . '</option>' . "\n";
497 echo ' <option value="' . __('Check table') . '" >'
498 . __('Check table') . '</option>' . "\n";
499 echo ' <option value="' . __('Optimize table') . '" >'
500 . __('Optimize table') . '</option>' . "\n";
501 echo ' <option value="' . __('Repair table') . '" >'
502 . __('Repair table') . '</option>' . "\n";
503 echo ' <option value="' . __('Analyze table') . '" >'
504 . __('Analyze table') . '</option>' . "\n";
507 </select>
508 <script type="text/javascript">
509 <!--
510 // Fake js to allow the use of the <noscript> tag
511 //-->
512 </script>
513 <noscript>
514 <input type="submit" value="<?php echo __('Go'); ?>" />
515 </noscript>
516 <?php echo implode("\n", $hidden_fields) . "\n"; ?>
517 </div>
518 </form>
519 <?php
520 // display again the table list navigator
521 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
523 <hr />
525 <?php
526 // Routines
527 require './libraries/db_routines.inc.php';
529 // Events
530 if (PMA_MYSQL_INT_VERSION > 50100) {
531 require './libraries/db_events.inc.php';
535 * Work on the database
537 /* DATABASE WORK */
538 /* Printable view of a table */
539 echo '<p>';
540 echo '<a href="db_printview.php?' . $url_query . '">';
541 if ($cfg['PropertiesIconic']) {
542 echo '<img class="icon" src="' . $pmaThemeImage
543 .'b_print.png" width="16" height="16" alt="" />';
545 echo __('Print view') . '</a> ';
547 echo '<a href="./db_datadict.php?' . $url_query . '">';
548 if ($cfg['PropertiesIconic']) {
549 echo '<img class="icon" src="' . $pmaThemeImage
550 .'b_tblanalyse.png" width="16" height="16" alt="" />';
552 echo __('Data Dictionary') . '</a>';
553 echo '</p>';
555 if (empty($db_is_information_schema)) {
556 require './libraries/display_create_table.lib.php';
557 } // end if (Create Table dialog)
560 * Displays the footer
562 require './libraries/footer.inc.php';