2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once './libraries/common.inc.php';
12 require_once './libraries/Table.class.php';
15 * Prepares the tables list if the user where not redirected to this script
16 * because there is no table in the database ($is_info is true)
18 if (empty($is_info)) {
19 // Drops/deletes/etc. multiple tables if required
20 if ((!empty($submit_mult) && isset($selected_tbl))
21 ||
isset($mult_btn)) {
22 $action = 'db_structure.php';
23 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
24 require './libraries/mult_submits.inc.php';
25 $message = $strSuccess;
27 require './libraries/db_common.inc.php';
28 $url_query .= '&goto=db_structure.php';
30 // Gets the database structure
31 $sub_part = '_structure';
32 require './libraries/db_info.inc.php';
36 if ($num_tables == 0) {
37 echo '<p>' . $strNoTablesFound . '</p>' . "\n";
39 if (empty($db_is_information_schema)) {
40 require './libraries/display_create_table.lib.php';
41 } // end if (Create Table dialog)
46 require_once './libraries/footer.inc.php';
51 // 2. Shows table informations - staybyte - 11 June 2001
53 require_once './libraries/bookmark.lib.php';
55 if (PMA_MYSQL_INT_VERSION
>= 40101) {
56 require_once './libraries/mysql_charsets.lib.php';
57 $db_collation = PMA_getDbCollation($db);
62 * void PMA_TableHeader([bool $db_is_information_schema = false])
63 * display table header (<table><thead>...</thead><tbody>)
65 * @uses PMA_showHint()
66 * @uses PMA_MYSQL_INT_VERSION
67 * @uses $GLOBALS['cfg']['PropertiesNumColumns']
68 * @uses $GLOBALS['is_show_stats']
69 * @uses $GLOBALS['strTable']
70 * @uses $GLOBALS['strAction']
71 * @uses $GLOBALS['strRecords']
72 * @uses $GLOBALS['strApproximateCount']
73 * @uses $GLOBALS['strType']
74 * @uses $GLOBALS['strCollation']
75 * @uses $GLOBALS['strSize']
76 * @uses $GLOBALS['strOverhead']
77 * @uses $GLOBALS['structure_tbl_col_cnt']
78 * @param boolean $db_is_information_schema
80 function PMA_TableHeader($db_is_information_schema = false)
82 $cnt = 0; // Let's count the columns...
84 if ($db_is_information_schema) {
90 echo '<table class="data" style="float: left;">' . "\n"
92 .'<tr><td></td>' . "\n"
93 .' <th>' . $GLOBALS['strTable'] . '</th>' . "\n"
94 .' <th colspan="' . $action_colspan . '">' . "\n"
95 .' ' . $GLOBALS['strAction'] . "\n"
97 .' <th>' . $GLOBALS['strRecords']
98 .PMA_showHint($GLOBALS['strApproximateCount']) . "\n"
100 if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
101 echo ' <th>' . $GLOBALS['strType'] . '</th>' . "\n";
103 if (PMA_MYSQL_INT_VERSION
>= 40100) {
104 echo ' <th>' . $GLOBALS['strCollation'] . '</th>' . "\n";
108 if ($GLOBALS['is_show_stats']) {
109 echo ' <th>' . $GLOBALS['strSize'] . '</th>' . "\n"
110 . ' <th>' . $GLOBALS['strOverhead'] . '</th>' . "\n";
114 echo '</thead>' . "\n";
115 echo '<tbody>' . "\n";
116 $GLOBALS['structure_tbl_col_cnt'] = $cnt +
$action_colspan +
3;
117 } // end function PMA_TableHeader()
120 if (true == $cfg['PropertiesIconic']) {
121 $titles['Browse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
122 $titles['NoBrowse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
123 $titles['Search'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
124 $titles['NoSearch'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
125 $titles['Insert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
126 $titles['NoInsert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
127 $titles['Structure'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_props.png" alt="' . $strStructure . '" title="' . $strStructure . '" />';
128 $titles['Drop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
129 $titles['NoDrop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
130 $titles['Empty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
131 $titles['NoEmpty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
133 if ('both' === $cfg['PropertiesIconic']) {
134 $titles['Browse'] .= $strBrowse;
135 $titles['Search'] .= $strSearch;
136 $titles['NoBrowse'] .= $strBrowse;
137 $titles['NoSearch'] .= $strSearch;
138 $titles['Insert'] .= $strInsert;
139 $titles['NoInsert'] .= $strInsert;
140 $titles['Structure'] .= $strStructure;
141 $titles['Drop'] .= $strDrop;
142 $titles['NoDrop'] .= $strDrop;
143 $titles['Empty'] .= $strEmpty;
144 $titles['NoEmpty'] .= $strEmpty;
147 $titles['Browse'] = $strBrowse;
148 $titles['Search'] = $strSearch;
149 $titles['NoBrowse'] = $strBrowse;
150 $titles['NoSearch'] = $strSearch;
151 $titles['Insert'] = $strInsert;
152 $titles['NoInsert'] = $strInsert;
153 $titles['Structure'] = $strStructure;
154 $titles['Drop'] = $strDrop;
155 $titles['NoDrop'] = $strDrop;
156 $titles['Empty'] = $strEmpty;
157 $titles['NoEmpty'] = $strEmpty;
161 * Displays the tables list
164 $_url_params = array(
168 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
171 <form method
="post" action
="db_structure.php" name
="tablesForm" id
="tablesForm">
173 echo PMA_generate_common_hidden_inputs($db);
175 PMA_TableHeader($db_is_information_schema);
177 $i = $sum_entries = 0;
178 $sum_size = (double) 0;
179 $overhead_size = (double) 0;
180 $overhead_check = '';
181 $checked = !empty($checkall) ?
' checked="checked"' : '';
182 $num_columns = $cfg['PropertiesNumColumns'] > 1 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1 : 0;
186 $hidden_fields = array();
188 $at_least_one_view_exceeds_max_count = false;
189 $sum_row_count_pre = '';
191 foreach ($tables as $keyname => $each_table) {
192 if ($each_table['TABLE_ROWS'] === null ||
$each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
193 $each_table['COUNTED'] = true;
194 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
195 $each_table['TABLE_NAME'], $return = true, $force_exact = true);
197 $each_table['COUNTED'] = false;
200 $table_encoded = urlencode($each_table['TABLE_NAME']);
201 // MySQL < 5.0.13 returns "view", >= 5.0.13 returns "VIEW"
202 $table_is_view = ($each_table['TABLE_TYPE'] === 'VIEW'
203 ||
$each_table['TABLE_TYPE'] === 'SYSTEM VIEW');
205 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
206 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
207 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
208 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
209 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
210 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
212 // Sets parameters for links
213 $tbl_url_query = $url_query . '&table=' . $table_encoded;
217 if ($table_is_view) {
218 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $table_encoded . '" />';
221 if ($each_table['TABLE_ROWS'] > 0) {
222 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
223 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
225 $browse_table = $titles['NoBrowse'];
226 $search_table = $titles['NoSearch'];
229 if (! $db_is_information_schema) {
230 if (! empty($each_table['TABLE_ROWS'])) {
231 $empty_table = '<a href="sql.php?' . $tbl_url_query
233 if (PMA_MYSQL_INT_VERSION
>= 40000) {
234 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
236 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
237 . '" onclick="return confirmLink(this, \'TRUNCATE ';
239 $empty_table .= urlencode('DELETE FROM ' . PMA_backquote($each_table['TABLE_NAME']))
241 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
242 . '" onclick="return confirmLink(this, \'DELETE FROM ';
244 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
246 $empty_table = $titles['NoEmpty'];
248 $drop_query = 'DROP '
249 . ($table_is_view ?
'VIEW' : 'TABLE')
250 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
251 $drop_message = sprintf(
252 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
253 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME'])));
256 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
257 // statistics whatever is the table type
259 if (isset($each_table['TABLE_ROWS'])) {
260 // MyISAM, ISAM or Heap table: Row count, data size and index size
262 if (preg_match('@^(MyISAM|ISAM|HEAP|MEMORY)$@', $each_table['ENGINE'])) {
263 if ($is_show_stats) {
264 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
265 $sum_size +
= $tblsize;
266 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
267 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
268 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
269 $overhead_size +
= $each_table['Data_free'];
272 $sum_entries +
= $each_table['TABLE_ROWS'];
273 } elseif ($each_table['ENGINE'] == 'InnoDB') {
274 // InnoDB table: Row count is not accurate but data and index
276 if ($is_show_stats) {
277 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
278 $sum_size +
= $tblsize;
279 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
281 //$display_rows = ' - ';
282 $sum_entries +
= $each_table['TABLE_ROWS'];
283 } elseif (preg_match('@^(MRG_MyISAM|BerkeleyDB)$@', $each_table['ENGINE'])) {
284 // Merge or BerkleyDB table: Only row count is accurate.
285 if ($is_show_stats) {
286 $formatted_size = ' - ';
289 $sum_entries +
= $each_table['TABLE_ROWS'];
291 // Unknown table type.
292 if ($is_show_stats) {
293 $formatted_size = 'unknown';
298 if (PMA_MYSQL_INT_VERSION
>= 40100) {
299 if (isset($each_table['Collation'])) {
300 $collation = '<dfn title="'
301 . PMA_getCollationDescr($each_table['Collation']) . '">'
302 . $each_table['Collation'] . '</dfn>';
308 if ($is_show_stats) {
309 if (isset($formatted_overhead)) {
310 $overhead = '<a href="tbl_structure.php?'
311 . $tbl_url_query . '#showusage">' . $formatted_overhead
312 . ' ' . $overhead_unit . '</a>' . "\n";
313 unset($formatted_overhead);
315 "document.getElementById('checkbox_tbl_$i').checked = true;";
320 } // end if (isset($each_table['TABLE_ROWS'])
322 if ($num_columns > 0 && $num_tables > $num_columns
323 && (($row_count %
$num_columns) == 0)) {
334 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
336 <input type
="checkbox" name
="selected_tbl[]"
337 value
="<?php echo $table_encoded; ?>"
338 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
339 <th
><label
for="checkbox_tbl_<?php echo $i; ?>"
340 title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></label
>
342 <td align
="center"><?php
echo $browse_table; ?
></td
>
344 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
345 <?php
echo $titles['Structure']; ?
></a
></td
>
346 <td align
="center"><?php
echo $search_table; ?
></td
>
347 <?php
if (! $db_is_information_schema) { ?
>
349 <a href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
350 <?php
echo $titles['Insert']; ?
></a
></td
>
351 <td align
="center"><?php
echo $empty_table; ?
></td
>
353 <a href
="sql.php?<?php echo $tbl_url_query;
354 ?>&reload=1&purge=1&sql_query=<?php
355 echo urlencode($drop_query); ?>&zero_rows=<?php
356 echo urlencode($drop_message); ?>"
357 onclick
="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
358 <?php
echo $titles['Drop']; ?
></a
></td
>
359 <?php
} // end if (! $db_is_information_schema)
361 // there is a null value in the ENGINE
362 // - when the table needs to be repaired, or
363 // - when it's a view
364 // so ensure that we'll display "in use" below for a table
365 // that needs to be repaired
367 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
368 if ($table_is_view && $each_table['TABLE_ROWS'] >= $cfg['MaxExactCountViews']) {
369 $at_least_one_view_exceeds_max_count = true;
370 $row_count_pre = '~';
371 $sum_row_count_pre = '~';
372 $show_superscript = '<sup>1</sup>';
373 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
374 // InnoDB table: we did not get an accurate row count
375 $row_count_pre = '~';
376 $sum_row_count_pre = '~';
377 $show_superscript = '';
380 $show_superscript = '';
383 <td
class="value"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
384 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
385 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
$strView : $each_table['ENGINE']); ?
></td
>
386 <?php
if (isset($collation)) { ?
>
387 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
391 <?php
if ($is_show_stats) { ?
>
393 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
394 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
395 <td
class="value"><?php
echo $overhead; ?
></td
>
397 <?php
} elseif ($table_is_view) { ?
>
398 <td
class="value">-</td
>
399 <td
><?php
echo $strView; ?
></td
>
401 <?php
if ($is_show_stats) { ?
>
402 <td
class="value">-</td
>
403 <td
class="value">-</td
>
406 <td colspan
="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
408 <?php
echo $strInUse; ?
></td
>
409 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
415 if ($is_show_stats) {
416 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
417 list($overhead_formatted, $overhead_unit) =
418 PMA_formatByteDown($overhead_size, 3, 1);
424 <th align
="center" nowrap
="nowrap">
425 <?php
echo sprintf($strTables, PMA_formatNumber($num_tables, 0)); ?
>
427 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
428 <?php
echo $strSum; ?
></th
>
429 <th
class="value"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
431 if (!($cfg['PropertiesNumColumns'] > 1)) {
432 $default_engine = PMA_DBI_get_default_engine();
433 echo ' <th align="center">' . "\n"
435 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
436 // Have to account for old MySQL with no collation (bug 1554885)
437 if (PMA_MYSQL_INT_VERSION
>= 40100) {
438 // we got a case where $db_collation was empty
439 echo ' <th align="center">' . "\n";
440 if (! empty($db_collation)) {
442 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
449 if ($is_show_stats) {
451 <th
class="value"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
452 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
460 <div
class="clearfloat">
462 // Check all tables url
463 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
465 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
466 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
467 <a href
="<?php echo $checkall_url; ?>&checkall=1"
468 onclick
="if (markAllRows('tablesForm')) return false;">
469 <?php
echo $strCheckAll; ?
></a
>
471 <a href
="<?php echo $checkall_url; ?>"
472 onclick
="if (unMarkAllRows('tablesForm')) return false;">
473 <?php
echo $strUncheckAll; ?
></a
>
474 <?php
if ($overhead_check != '') { ?
>
476 <a href
="#" onclick
="unMarkAllRows('tablesForm');
477 <?php echo $overhead_check; ?> return false;">
478 <?php
echo $strCheckOverhead; ?
></a
>
481 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
483 echo ' <option value="' . $strWithChecked . '" selected="selected">'
484 . $strWithChecked . '</option>' . "\n";
485 echo ' <option value="' . $strEmpty . '" >'
486 . $strEmpty . '</option>' . "\n";
487 echo ' <option value="' . $strDrop . '" >'
488 . $strDrop . '</option>' . "\n";
489 echo ' <option value="' . $strPrintView . '" >'
490 . $strPrintView . '</option>' . "\n";
491 echo ' <option value="' . $strCheckTable . '" >'
492 . $strCheckTable . '</option>' . "\n";
493 echo ' <option value="' . $strOptimizeTable . '" >'
494 . $strOptimizeTable . '</option>' . "\n";
495 echo ' <option value="' . $strRepairTable . '" >'
496 . $strRepairTable . '</option>' . "\n";
497 echo ' <option value="' . $strAnalyzeTable . '" >'
498 . $strAnalyzeTable . '</option>' . "\n";
501 <script type
="text/javascript">
503 // Fake js to allow the use of the <noscript> tag
507 <input type
="submit" value
="<?php echo $strGo; ?>" />
509 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
513 // Notice about row count for views
515 if ($at_least_one_view_exceeds_max_count && !$db_is_information_schema) {
516 echo '<div class="notice">' . "\n";
517 echo '<sup>1</sup>' . PMA_sanitize(sprintf($strViewMaxExactCount, PMA_formatNumber($cfg['MaxExactCountViews'], 0), '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')) . "\n";
518 echo '</div>' . "\n";
520 // display again the table list navigator
521 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
527 require './libraries/db_routines.inc.php';
530 * Work on the database
531 * redesigned 2004-05-08 by mkkeck
534 /* Printable view of a table */
536 echo '<a href="db_printview.php?' . $url_query . '">';
537 if ($cfg['PropertiesIconic']) {
538 echo '<img class="icon" src="' . $pmaThemeImage
539 .'b_print.png" width="16" height="16" alt="" />';
541 echo $strPrintView . '</a> ';
543 echo '<a href="./db_datadict.php?' . $url_query . '">';
544 if ($cfg['PropertiesIconic']) {
545 echo '<img class="icon" src="' . $pmaThemeImage
546 .'b_tblanalyse.png" width="16" height="16" alt="" />';
548 echo $strDataDict . '</a>';
551 if (empty($db_is_information_schema)) {
552 require './libraries/display_create_table.lib.php';
553 } // end if (Create Table dialog)
556 * Displays the footer
558 require_once './libraries/footer.inc.php';