2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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';
15 $GLOBALS['js_include'][] = 'tbl_change.js';
18 * Prepares the tables list if the user where not redirected to this script
19 * because there is no table in the database ($is_info is true)
21 if (empty($is_info)) {
22 // Drops/deletes/etc. multiple tables if required
23 if ((!empty($submit_mult) && isset($selected_tbl))
24 ||
isset($mult_btn)) {
25 $action = 'db_structure.php';
26 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
28 // see bug #2794840; in this case, code path is:
29 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
30 // -> db_structure.php and if we got an error on the multi submit,
31 // we must display it here and not call again mult_submits.inc.php
32 if (! isset($error) ||
false === $error) {
33 require './libraries/mult_submits.inc.php';
35 if (empty($message)) {
36 $message = PMA_Message
::success();
39 require './libraries/db_common.inc.php';
40 $url_query .= '&goto=db_structure.php';
42 // Gets the database structure
43 $sub_part = '_structure';
44 require './libraries/db_info.inc.php';
46 require_once './libraries/replication.inc.php';
49 require_once './libraries/bookmark.lib.php';
51 require_once './libraries/mysql_charsets.lib.php';
52 $db_collation = PMA_getDbCollation($db);
54 // in a separate file to avoid redeclaration of functions in some code paths
55 require_once './libraries/db_structure.lib.php';
56 $titles = PMA_buildActionTitles();
59 if ($num_tables == 0) {
60 echo '<p>' . __('No tables found in database') . '</p>' . "\n";
63 require './libraries/db_routines.inc.php';
66 if (PMA_MYSQL_INT_VERSION
> 50100) {
67 require './libraries/db_events.inc.php';
70 if (empty($db_is_information_schema)) {
71 require './libraries/display_create_table.lib.php';
72 } // end if (Create Table dialog)
77 require_once './libraries/footer.inc.php';
82 // 2. Shows table informations
85 * Displays the tables list
87 echo '<div id="tableslistcontainer">';
92 // Add the sort options if they exists
93 if (isset($_REQUEST['sort'])) {
94 $_url_params['sort'] = $_REQUEST['sort'];
97 if (isset($_REQUEST['sort_order'])) {
98 $_url_params['sort_order'] = $_REQUEST['sort_order'];
101 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
104 <form method
="post" action
="db_structure.php" name
="tablesForm" id
="tablesForm">
106 echo PMA_generate_common_hidden_inputs($db);
108 PMA_TableHeader($db_is_information_schema, $server_slave_status);
110 $i = $sum_entries = 0;
111 $sum_size = (double) 0;
112 $overhead_size = (double) 0;
113 $overhead_check = '';
114 $checked = !empty($checkall) ?
' checked="checked"' : '';
115 $num_columns = $cfg['PropertiesNumColumns'] > 1 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1 : 0;
119 $hidden_fields = array();
121 $sum_row_count_pre = '';
123 $tableReductionCount = 0; // the amount to reduce the table count by
125 foreach ($tables as $keyname => $each_table) {
126 if (PMA_BS_IsHiddenTable($keyname)) {
127 $tableReductionCount++
;
131 // Get valid statistics whatever is the table type
133 $table_is_view = false;
134 $table_encoded = urlencode($each_table['TABLE_NAME']);
135 // Sets parameters for links
136 $tbl_url_query = $url_query . '&table=' . $table_encoded;
137 // do not list the previous table's size info for a view
138 $formatted_size = '-';
141 switch ( $each_table['ENGINE']) {
142 // MyISAM, ISAM or Heap table: Row count, data size and index size
143 // are accurate; data size is accurate for ARCHIVE
151 if ($db_is_information_schema) {
152 $each_table['Rows'] = PMA_Table
::countRecords($db,
153 $each_table['Name']);
156 if ($is_show_stats) {
157 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
158 $sum_size +
= $tblsize;
159 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
160 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
161 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
162 $overhead_size +
= $each_table['Data_free'];
167 // InnoDB table: Row count is not accurate but data and index
170 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
171 $each_table['COUNTED'] = true;
172 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
173 $each_table['TABLE_NAME'], $force_exact = true,
176 $each_table['COUNTED'] = false;
179 if ($is_show_stats) {
180 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
181 $sum_size +
= $tblsize;
182 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
184 //$display_rows = ' - ';
186 // Mysql 5.0.x (and lower) uses MRG_MyISAM and MySQL 5.1.x (and higher) uses MRG_MYISAM
187 // Both are aliases for MERGE
192 // Merge or BerkleyDB table: Only row count is accurate.
193 if ($is_show_stats) {
194 $formatted_size = ' - ';
198 // for a view, the ENGINE is sometimes reported as null,
199 // or on some servers it's reported as "SYSTEM VIEW"
202 // if table is broken, Engine is reported as null, so one more test
203 if ($each_table['TABLE_TYPE'] == 'VIEW') {
204 // countRecords() takes care of $cfg['MaxExactCountViews']
205 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
206 $each_table['TABLE_NAME'], $force_exact = true,
208 $table_is_view = true;
212 // Unknown table type.
213 if ($is_show_stats) {
214 $formatted_size = 'unknown';
219 if (! PMA_Table
::isMerge($db, $each_table['TABLE_NAME'])) {
220 $sum_entries +
= $each_table['TABLE_ROWS'];
223 if (isset($each_table['Collation'])) {
224 $collation = '<dfn title="'
225 . PMA_getCollationDescr($each_table['Collation']) . '">'
226 . $each_table['Collation'] . '</dfn>';
231 if ($is_show_stats) {
232 if (isset($formatted_overhead)) {
233 $overhead = '<a href="tbl_structure.php?'
234 . $tbl_url_query . '#showusage">' . $formatted_overhead
235 . ' ' . $overhead_unit . '</a>' . "\n";
236 unset($formatted_overhead);
238 "document.getElementById('checkbox_tbl_" . ($i +
1) . "').checked = true;";
244 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
245 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
246 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
247 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
248 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
249 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
254 if ($table_is_view) {
255 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . htmlspecialchars($each_table['TABLE_NAME']) . '" />';
258 if ($each_table['TABLE_ROWS'] > 0) {
259 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
260 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
261 $browse_table_label = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $truename . '</a>';
263 $browse_table = $titles['NoBrowse'];
264 $search_table = $titles['NoSearch'];
265 $browse_table_label = '<a href="tbl_structure.php?' . $tbl_url_query . '">' . $truename . '</a>';
268 if (! $db_is_information_schema) {
269 if (! empty($each_table['TABLE_ROWS'])) {
270 $empty_table = '<a ';
271 if ($GLOBALS['cfg']['AjaxEnable']) {
272 $empty_table .= 'class="truncate_table_anchor"';
274 $empty_table .= ' href="sql.php?' . $tbl_url_query
276 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
277 . '&message_to_show='
278 . urlencode(sprintf(__('Table %s has been emptied'), htmlspecialchars($each_table['TABLE_NAME'])))
279 .'">' . $titles['Empty'] . '</a>';
281 $empty_table = $titles['NoEmpty'];
283 $drop_query = 'DROP '
284 . ($table_is_view ?
'VIEW' : 'TABLE')
285 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
286 $drop_message = sprintf(
287 $table_is_view ?
__('View %s has been dropped') : __('Table %s has been dropped'),
288 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME'])));
292 if (PMA_Tracker
::isActive()) {
293 if (PMA_Tracker
::isTracked($GLOBALS["db"], $truename)) {
294 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query.'&table=' . $truename . '"><img class="icon" width="14" height="14" src="' . $pmaThemeImage . 'eye.png" alt="' . __('Tracking is active.') . '" title="' . __('Tracking is active.') . '" /></a>';
295 } elseif (PMA_Tracker
::getVersion($GLOBALS["db"], $truename) > 0) {
296 $tracking_icon = '<a href="tbl_tracking.php?' . $url_query . '&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>';
300 if ($num_columns > 0 && $num_tables > $num_columns
301 && (($row_count %
$num_columns) == 0)) {
309 PMA_TableHeader(false, $server_slave_status);
315 if ($server_slave_status) {
316 ////////////////////////////////////////////////////////////////
318 if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
319 ||
(strlen(array_search($db, $server_slave_Do_DB)) > 0)
320 ||
(count($server_slave_Do_DB) == 1 && count($server_slave_Ignore_DB) == 1)
324 foreach ($server_slave_Wild_Do_Table as $db_table) {
325 $table_part = PMA_extract_db_or_table($db_table, 'table');
326 if (($db == PMA_extract_db_or_table($db_table, 'db')) && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))) {
330 ////////////////////////////////////////////////////////////////////
331 if ((strlen(array_search($truename, $server_slave_Ignore_Table)) > 0) ||
(strlen(array_search($db, $server_slave_Ignore_DB)) > 0)) {
334 foreach ($server_slave_Wild_Ignore_Table as $db_table) {
335 $table_part = PMA_extract_db_or_table($db_table, 'table');
336 if (($db == PMA_extract_db_or_table($db_table)) && (preg_match("@^" . substr($table_part, 0, strlen($table_part) - 1) . "@", $truename))) {
343 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
345 <input type
="checkbox" name
="selected_tbl[]"
346 value
="<?php echo htmlspecialchars($each_table['TABLE_NAME']); ?>"
347 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
348 <th
><?php
echo $browse_table_label; ?
>
349 <?php
echo (! empty($tracking_icon) ?
$tracking_icon : ''); ?
>
351 <?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
} ?
>
352 <td align
="center"><?php
echo $browse_table; ?
></td
>
354 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
355 <?php
echo $titles['Structure']; ?
></a
></td
>
356 <td align
="center"><?php
echo $search_table; ?
></td
>
357 <?php
if (! $db_is_information_schema) { ?
>
358 <td align
="center" class="insert_table">
359 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="ajax"' : ''); ?
> href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
360 <?php
echo $titles['Insert']; ?
></a
></td
>
361 <td align
="center"><?php
echo $empty_table; ?
></td
>
363 <a
<?php
echo ($GLOBALS['cfg']['AjaxEnable'] ?
'class="drop_table_anchor"' : ''); ?
> href
="sql.php?<?php echo $tbl_url_query;
364 ?>&reload=1&purge=1&sql_query=<?php
365 echo urlencode($drop_query); ?>&message_to_show=<?php
366 echo urlencode($drop_message); ?>" >
367 <?php
echo $titles['Drop']; ?
></a
></td
>
368 <?php
} // end if (! $db_is_information_schema)
370 // there is a null value in the ENGINE
371 // - when the table needs to be repaired, or
372 // - when it's a view
373 // so ensure that we'll display "in use" below for a table
374 // that needs to be repaired
375 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
376 if ($table_is_view) {
377 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']){
378 $row_count_pre = '~';
379 $sum_row_count_pre = '~';
380 $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]')));
382 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
383 // InnoDB table: we did not get an accurate row count
384 $row_count_pre = '~';
385 $sum_row_count_pre = '~';
386 $show_superscript = '';
389 $show_superscript = '';
392 <td
class="value tbl_rows"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
393 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
394 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
__('View') : $each_table['ENGINE']); ?
></td
>
395 <?php
if (isset($collation)) { ?
>
396 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
400 <?php
if ($is_show_stats) { ?
>
401 <td
class="value tbl_size"><a
402 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
403 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
404 <td
class="value"><?php
echo $overhead; ?
></td
>
406 <?php
} elseif ($table_is_view) { ?
>
407 <td
class="value">-</td
>
408 <td
><?php
echo __('View'); ?
></td
>
410 <?php
if ($is_show_stats) { ?
>
411 <td
class="value">-</td
>
412 <td
class="value">-</td
>
415 <td colspan
="<?php echo ($colspan_for_structure - ($db_is_information_schema ? 5 : 8)) ?>"
417 <?php
echo __('in use'); ?
></td
>
418 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
424 if ($is_show_stats) {
425 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
426 list($overhead_formatted, $overhead_unit) =
427 PMA_formatByteDown($overhead_size, 3, 1);
431 <tbody id
="tbl_summary_row">
433 <th align
="center" nowrap
="nowrap">
435 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
436 // (we don't want negative numbers here)
437 if ($num_tables == 0)
438 $tableReductionCount = 0;
440 echo sprintf(_ngettext('%s table', '%s tables', $num_tables - $tableReductionCount), PMA_formatNumber($num_tables - $tableReductionCount, 0));
444 if ($server_slave_status) {
445 echo ' <th>' . __('Replication') . '</th>' . "\n";
448 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
449 <?php
echo __('Sum'); ?
></th
>
450 <th
class="value tbl_rows"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
452 if (!($cfg['PropertiesNumColumns'] > 1)) {
453 $default_engine = PMA_DBI_get_default_engine();
454 echo ' <th align="center">' . "\n"
456 . sprintf(__('%s is the default storage engine on this MySQL server.'), $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
457 // we got a case where $db_collation was empty
458 echo ' <th align="center">' . "\n";
459 if (! empty($db_collation)) {
461 . PMA_getCollationDescr($db_collation) . ' (' . __('Default') . ')">' . $db_collation
467 if ($is_show_stats) {
469 <th
class="value tbl_size"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
470 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
478 <div
class="clearfloat">
480 // Check all tables url
481 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
483 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
484 width
="38" height
="22" alt
="<?php echo __('With selected:'); ?>" />
485 <a href
="<?php echo $checkall_url; ?>&checkall=1"
486 onclick
="if (markAllRows('tablesForm')) return false;">
487 <?php
echo __('Check All'); ?
></a
>
489 <a href
="<?php echo $checkall_url; ?>"
490 onclick
="if (unMarkAllRows('tablesForm')) return false;">
491 <?php
echo __('Uncheck All'); ?
></a
>
492 <?php
if ($overhead_check != '') { ?
>
494 <a href
="#" onclick
="unMarkAllRows('tablesForm');
495 <?php echo $overhead_check; ?> return false;">
496 <?php
echo __('Check tables having overhead'); ?
></a
>
499 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
501 echo ' <option value="' . __('With selected:') . '" selected="selected">'
502 . __('With selected:') . '</option>' . "\n";
503 echo ' <option value="export" >'
504 . __('Export') . '</option>' . "\n";
505 echo ' <option value="print" >'
506 . __('Print view') . '</option>' . "\n";
508 if (!$db_is_information_schema && !$cfg['DisableMultiTableMaintenance']) {
509 echo ' <option value="empty_tbl" >'
510 . __('Empty') . '</option>' . "\n";
511 echo ' <option value="drop_tbl" >'
512 . __('Drop') . '</option>' . "\n";
513 echo ' <option value="check_tbl" >'
514 . __('Check table') . '</option>' . "\n";
515 echo ' <option value="optimize_tbl" >'
516 . __('Optimize table') . '</option>' . "\n";
517 echo ' <option value="repair_tbl" >'
518 . __('Repair table') . '</option>' . "\n";
519 echo ' <option value="analyze_tbl" >'
520 . __('Analyze table') . '</option>' . "\n";
521 echo ' <option value="add_prefix_tbl" >'
522 . __('Add prefix to table') . '</option>' . "\n";
523 echo ' <option value="replace_prefix_tbl" >'
524 . __('Replace table prefix') . '</option>' . "\n";
525 echo ' <option value="copy_tbl_change_prefix" >'
526 . __('Copy table with prefix') . '</option>' . "\n";
530 <script type
="text/javascript">
532 // Fake js to allow the use of the <noscript> tag
536 <input type
="submit" value
="<?php echo __('Go'); ?>" />
538 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
542 // display again the table list navigator
543 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
550 require './libraries/db_routines.inc.php';
553 if (PMA_MYSQL_INT_VERSION
> 50100) {
554 require './libraries/db_events.inc.php';
558 * Work on the database
561 /* Printable view of a table */
563 echo '<a href="db_printview.php?' . $url_query . '">';
564 if ($cfg['PropertiesIconic']) {
565 echo '<img class="icon" src="' . $pmaThemeImage
566 .'b_print.png" width="16" height="16" alt="" />';
568 echo __('Print view') . '</a> ';
570 echo '<a href="./db_datadict.php?' . $url_query . '">';
571 if ($cfg['PropertiesIconic']) {
572 echo '<img class="icon" src="' . $pmaThemeImage
573 .'b_tblanalyse.png" width="16" height="16" alt="" />';
575 echo __('Data Dictionary') . '</a>';
578 if (empty($db_is_information_schema)) {
579 require './libraries/display_create_table.lib.php';
580 } // end if (Create Table dialog)
583 * Displays the footer
585 require './libraries/footer.inc.php';