2 /* vim: set expandtab sw=4 ts=4 sts=4: */
12 require_once './libraries/common.inc.php';
13 require_once './libraries/Table.class.php';
15 $GLOBALS['js_include'][] = 'mootools.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';
48 if ($num_tables == 0) {
49 echo '<p>' . $strNoTablesFound . '</p>' . "\n";
51 if (empty($db_is_information_schema)) {
52 require './libraries/display_create_table.lib.php';
53 } // end if (Create Table dialog)
58 require_once './libraries/footer.inc.php';
63 // 2. Shows table informations - staybyte - 11 June 2001
65 require_once './libraries/bookmark.lib.php';
67 require_once './libraries/mysql_charsets.lib.php';
68 $db_collation = PMA_getDbCollation($db);
70 // in a separate file to avoid redeclaration of functions in some code paths
71 require_once './libraries/db_structure.lib.php';
74 if (true == $cfg['PropertiesIconic']) {
75 $titles['Browse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
76 $titles['NoBrowse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
77 $titles['Search'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
78 $titles['NoSearch'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
79 $titles['Insert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
80 $titles['NoInsert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
81 $titles['Structure'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_props.png" alt="' . $strStructure . '" title="' . $strStructure . '" />';
82 $titles['Drop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
83 $titles['NoDrop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
84 $titles['Empty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
85 $titles['NoEmpty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
87 if ('both' === $cfg['PropertiesIconic']) {
88 $titles['Browse'] .= $strBrowse;
89 $titles['Search'] .= $strSearch;
90 $titles['NoBrowse'] .= $strBrowse;
91 $titles['NoSearch'] .= $strSearch;
92 $titles['Insert'] .= $strInsert;
93 $titles['NoInsert'] .= $strInsert;
94 $titles['Structure'] .= $strStructure;
95 $titles['Drop'] .= $strDrop;
96 $titles['NoDrop'] .= $strDrop;
97 $titles['Empty'] .= $strEmpty;
98 $titles['NoEmpty'] .= $strEmpty;
101 $titles['Browse'] = $strBrowse;
102 $titles['Search'] = $strSearch;
103 $titles['NoBrowse'] = $strBrowse;
104 $titles['NoSearch'] = $strSearch;
105 $titles['Insert'] = $strInsert;
106 $titles['NoInsert'] = $strInsert;
107 $titles['Structure'] = $strStructure;
108 $titles['Drop'] = $strDrop;
109 $titles['NoDrop'] = $strDrop;
110 $titles['Empty'] = $strEmpty;
111 $titles['NoEmpty'] = $strEmpty;
115 * Displays the tables list
117 $_url_params = array(
121 // Add the sort options if they exists
122 if (isset($_REQUEST['sort'])) {
123 $_url_params['sort'] = $_REQUEST['sort'];
126 if (isset($_REQUEST['sort_order'])) {
127 $_url_params['sort_order'] = $_REQUEST['sort_order'];
130 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
133 <form method
="post" action
="db_structure.php" name
="tablesForm" id
="tablesForm">
135 echo PMA_generate_common_hidden_inputs($db);
137 PMA_TableHeader($db_is_information_schema);
139 $i = $sum_entries = 0;
140 $sum_size = (double) 0;
141 $overhead_size = (double) 0;
142 $overhead_check = '';
143 $checked = !empty($checkall) ?
' checked="checked"' : '';
144 $num_columns = $cfg['PropertiesNumColumns'] > 1 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1 : 0;
148 $hidden_fields = array();
150 $sum_row_count_pre = '';
152 // added by rajk - for blobstreaming
153 $PMA_Config = $_SESSION['PMA_Config'];
155 if (!empty($PMA_Config))
156 $session_bs_tables = $PMA_Config->get('BLOBSTREAMING_TABLES'); // list of blobstreaming tables
158 $tableReductionCount = 0; // the amount to reduce the table count by
160 foreach ($tables as $keyname => $each_table) {
161 if (isset($session_bs_tables))
163 // compare table name against blobstreaming tables
164 foreach ($session_bs_tables as $table_key=>$table_val)
165 // if the table is a blobstreaming table, reduce table count and skip outer foreach loop
166 if ($table_key == $keyname)
168 $tableReductionCount++
;
173 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
174 // statistics whatever is the table type
176 $table_is_view = false;
177 $table_encoded = urlencode($each_table['TABLE_NAME']);
178 // Sets parameters for links
179 $tbl_url_query = $url_query . '&table=' . $table_encoded;
180 // do not list the previous table's size info for a view
181 $formatted_size = '-';
184 switch ( $each_table['ENGINE']) {
185 // MyISAM, ISAM or Heap table: Row count, data size and index size
191 if ($db_is_information_schema) {
192 $each_table['Rows'] = PMA_Table
::countRecords($db,
193 $each_table['Name'], $return = true);
196 if ($is_show_stats) {
197 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
198 $sum_size +
= $tblsize;
199 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
200 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
201 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
202 $overhead_size +
= $each_table['Data_free'];
207 // InnoDB table: Row count is not accurate but data and index
210 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
211 $each_table['COUNTED'] = true;
212 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
213 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
216 $each_table['COUNTED'] = false;
219 if ($is_show_stats) {
220 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
221 $sum_size +
= $tblsize;
222 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
224 //$display_rows = ' - ';
228 // Merge or BerkleyDB table: Only row count is accurate.
229 if ($is_show_stats) {
230 $formatted_size = ' - ';
234 // for a view, the ENGINE is null
237 // countRecords() takes care of $cfg['MaxExactCountViews']
238 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
239 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
241 $table_is_view = true;
244 // Unknown table type.
245 if ($is_show_stats) {
246 $formatted_size = 'unknown';
250 $sum_entries +
= $each_table['TABLE_ROWS'];
252 if (isset($each_table['Collation'])) {
253 $collation = '<dfn title="'
254 . PMA_getCollationDescr($each_table['Collation']) . '">'
255 . $each_table['Collation'] . '</dfn>';
260 if ($is_show_stats) {
261 if (isset($formatted_overhead)) {
262 $overhead = '<a href="tbl_structure.php?'
263 . $tbl_url_query . '#showusage">' . $formatted_overhead
264 . ' ' . $overhead_unit . '</a>' . "\n";
265 unset($formatted_overhead);
267 "document.getElementById('checkbox_tbl_" . ($i +
1) . "').checked = true;";
273 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
274 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
275 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
276 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
277 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
278 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
283 if ($table_is_view) {
284 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $each_table['TABLE_NAME'] . '" />';
287 if ($each_table['TABLE_ROWS'] > 0) {
288 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
289 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
291 $browse_table = $titles['NoBrowse'];
292 $search_table = $titles['NoSearch'];
295 if (! $db_is_information_schema) {
296 if (! empty($each_table['TABLE_ROWS'])) {
297 $empty_table = '<a href="sql.php?' . $tbl_url_query
299 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
301 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
302 . '" onclick="return confirmLink(this, \'TRUNCATE ';
303 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
305 $empty_table = $titles['NoEmpty'];
307 $drop_query = 'DROP '
308 . ($table_is_view ?
'VIEW' : 'TABLE')
309 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
310 $drop_message = sprintf(
311 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
312 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME'])));
316 if (PMA_Tracker
::isActive()) {
317 if (PMA_Tracker
::isTracked($GLOBALS["db"], $truename)) {
318 $tracking_icon = '<a href="tbl_tracking.php?'.$url_query.'&table='.$truename.'"><img class="icon" width="14" height="14" src="' .$pmaThemeImage . 'eye.png" alt="' . $strTrackingIsActive . '" title="' . $strTrackingIsActive . '" /></a>';
319 } else if (PMA_Tracker
::getVersion($GLOBALS["db"], $truename) > 0) {
320 $tracking_icon = '<a href="tbl_tracking.php?'.$url_query.'&table='.$truename.'"><img class="icon" width="14" height="14" src="' .$pmaThemeImage . 'eye_grey.png" alt="' . $strTrackingIsDeactive . '" title="' . $strTrackingIsDeactive . '" /></a>';
324 if ($num_columns > 0 && $num_tables > $num_columns
325 && (($row_count %
$num_columns) == 0)) {
336 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
338 <input type
="checkbox" name
="selected_tbl[]"
339 value
="<?php echo $each_table['TABLE_NAME']; ?>"
340 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
341 <th
><label
for="checkbox_tbl_<?php echo $i; ?>"
342 title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></label
>
343 <label
><?php
echo $tracking_icon; ?
> </label
>
345 <td align
="center"><?php
echo $browse_table; ?
></td
>
347 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
348 <?php
echo $titles['Structure']; ?
></a
></td
>
349 <td align
="center"><?php
echo $search_table; ?
></td
>
350 <?php
if (! $db_is_information_schema) { ?
>
352 <a href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
353 <?php
echo $titles['Insert']; ?
></a
></td
>
354 <td align
="center"><?php
echo $empty_table; ?
></td
>
356 <a href
="sql.php?<?php echo $tbl_url_query;
357 ?>&reload=1&purge=1&sql_query=<?php
358 echo urlencode($drop_query); ?>&zero_rows=<?php
359 echo urlencode($drop_message); ?>"
360 onclick
="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
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($strViewHasAtLeast, '[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 = '';
383 $show_superscript = '';
386 <td
class="value"><?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 ?
$strView : $each_table['ENGINE']); ?
></td
>
389 <?php
if (isset($collation)) { ?
>
390 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
394 <?php
if ($is_show_stats) { ?
>
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
>
400 <?php
} elseif ($table_is_view) { ?
>
401 <td
class="value">-</td
>
402 <td
><?php
echo $strView; ?
></td
>
404 <?php
if ($is_show_stats) { ?
>
405 <td
class="value">-</td
>
406 <td
class="value">-</td
>
409 <td colspan
="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
411 <?php
echo $strInUse; ?
></td
>
412 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
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);
427 <th align
="center" nowrap
="nowrap">
429 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
430 // (we don't want negative numbers here) - rajk
431 if ($num_tables == 0)
432 $tableReductionCount = 0;
434 echo sprintf($strTables, PMA_formatNumber($num_tables - $tableReductionCount, 0));
437 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
438 <?php
echo $strSum; ?
></th
>
439 <th
class="value"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
441 if (!($cfg['PropertiesNumColumns'] > 1)) {
442 $default_engine = PMA_DBI_get_default_engine();
443 echo ' <th align="center">' . "\n"
445 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
446 // we got a case where $db_collation was empty
447 echo ' <th align="center">' . "\n";
448 if (! empty($db_collation)) {
450 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
456 if ($is_show_stats) {
458 <th
class="value"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
459 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
467 <div
class="clearfloat">
469 // Check all tables url
470 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
472 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
473 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
474 <a href
="<?php echo $checkall_url; ?>&checkall=1"
475 onclick
="if (markAllRows('tablesForm')) return false;">
476 <?php
echo $strCheckAll; ?
></a
>
478 <a href
="<?php echo $checkall_url; ?>"
479 onclick
="if (unMarkAllRows('tablesForm')) return false;">
480 <?php
echo $strUncheckAll; ?
></a
>
481 <?php
if ($overhead_check != '') { ?
>
483 <a href
="#" onclick
="unMarkAllRows('tablesForm');
484 <?php echo $overhead_check; ?> return false;">
485 <?php
echo $strCheckOverhead; ?
></a
>
488 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
490 echo ' <option value="' . $strWithChecked . '" selected="selected">'
491 . $strWithChecked . '</option>' . "\n";
492 echo ' <option value="' . $strEmpty . '" >'
493 . $strEmpty . '</option>' . "\n";
494 echo ' <option value="' . $strDrop . '" >'
495 . $strDrop . '</option>' . "\n";
496 echo ' <option value="' . $strPrintView . '" >'
497 . $strPrintView . '</option>' . "\n";
498 echo ' <option value="' . $strCheckTable . '" >'
499 . $strCheckTable . '</option>' . "\n";
500 echo ' <option value="' . $strOptimizeTable . '" >'
501 . $strOptimizeTable . '</option>' . "\n";
502 echo ' <option value="' . $strRepairTable . '" >'
503 . $strRepairTable . '</option>' . "\n";
504 echo ' <option value="' . $strAnalyzeTable . '" >'
505 . $strAnalyzeTable . '</option>' . "\n";
506 echo ' <option value="' . $strExport . '" >'
507 . $strExport . '</option>' . "\n";
510 <script type
="text/javascript">
512 // Fake js to allow the use of the <noscript> tag
516 <input type
="submit" value
="<?php echo $strGo; ?>" />
518 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
522 // display again the table list navigator
523 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
529 require './libraries/db_routines.inc.php';
532 if (PMA_MYSQL_INT_VERSION
> 50100) {
533 require './libraries/db_events.inc.php';
537 * Work on the database
538 * redesigned 2004-05-08 by mkkeck
541 /* Printable view of a table */
543 echo '<a href="db_printview.php?' . $url_query . '">';
544 if ($cfg['PropertiesIconic']) {
545 echo '<img class="icon" src="' . $pmaThemeImage
546 .'b_print.png" width="16" height="16" alt="" />';
548 echo $strPrintView . '</a> ';
550 echo '<a href="./db_datadict.php?' . $url_query . '">';
551 if ($cfg['PropertiesIconic']) {
552 echo '<img class="icon" src="' . $pmaThemeImage
553 .'b_tblanalyse.png" width="16" height="16" alt="" />';
555 echo $strDataDict . '</a>';
558 if (empty($db_is_information_schema)) {
559 require './libraries/display_create_table.lib.php';
560 } // end if (Create Table dialog)
563 * Displays the footer
565 require_once './libraries/footer.inc.php';