2 /* vim: set expandtab sw=4 ts=4 sts=4: */
11 require_once './libraries/common.inc.php';
12 require_once './libraries/Table.class.php';
14 $GLOBALS['js_include'][] = 'mootools.js';
15 $GLOBALS['js_include'][] = 'mootools-domready.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);
27 require './libraries/mult_submits.inc.php';
28 if (empty($message)) {
29 $message = PMA_Message
::success();
32 require './libraries/db_common.inc.php';
33 $url_query .= '&goto=db_structure.php';
35 // Gets the database structure
36 $sub_part = '_structure';
37 require './libraries/db_info.inc.php';
41 if ($num_tables == 0) {
42 echo '<p>' . $strNoTablesFound . '</p>' . "\n";
44 if (empty($db_is_information_schema)) {
45 require './libraries/display_create_table.lib.php';
46 } // end if (Create Table dialog)
51 require_once './libraries/footer.inc.php';
56 // 2. Shows table informations - staybyte - 11 June 2001
58 require_once './libraries/bookmark.lib.php';
60 require_once './libraries/mysql_charsets.lib.php';
61 $db_collation = PMA_getDbCollation($db);
65 * void PMA_TableHeader([bool $db_is_information_schema = false])
66 * display table header (<table><thead>...</thead><tbody>)
68 * @uses PMA_showHint()
69 * @uses $GLOBALS['cfg']['PropertiesNumColumns']
70 * @uses $GLOBALS['is_show_stats']
71 * @uses $GLOBALS['strTable']
72 * @uses $GLOBALS['strAction']
73 * @uses $GLOBALS['strRecords']
74 * @uses $GLOBALS['strApproximateCount']
75 * @uses $GLOBALS['strType']
76 * @uses $GLOBALS['strCollation']
77 * @uses $GLOBALS['strSize']
78 * @uses $GLOBALS['strOverhead']
79 * @uses $GLOBALS['structure_tbl_col_cnt']
80 * @param boolean $db_is_information_schema
82 function PMA_TableHeader($db_is_information_schema = false)
84 $cnt = 0; // Let's count the columns...
86 if ($db_is_information_schema) {
92 echo '<table class="data" style="float: left;">' . "\n"
94 .'<tr><td></td>' . "\n"
95 .' <th>' . $GLOBALS['strTable'] . '</th>' . "\n"
96 .' <th colspan="' . $action_colspan . '">' . "\n"
97 .' ' . $GLOBALS['strAction'] . "\n"
99 .' <th>' . $GLOBALS['strRecords']
100 .PMA_showHint($GLOBALS['strApproximateCount']) . "\n"
102 if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
103 echo ' <th>' . $GLOBALS['strType'] . '</th>' . "\n";
105 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 $sum_row_count_pre = '';
190 foreach ($tables as $keyname => $each_table) {
191 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
192 // statistics whatever is the table type
194 $table_is_view = false;
195 $table_encoded = urlencode($each_table['TABLE_NAME']);
196 // Sets parameters for links
197 $tbl_url_query = $url_query . '&table=' . $table_encoded;
199 switch ( $each_table['ENGINE']) {
200 // MyISAM, ISAM or Heap table: Row count, data size and index size
206 if ($is_show_stats) {
207 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
208 $sum_size +
= $tblsize;
209 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
210 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
211 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
212 $overhead_size +
= $each_table['Data_free'];
217 // InnoDB table: Row count is not accurate but data and index
220 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
221 $each_table['COUNTED'] = true;
222 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
223 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
226 $each_table['COUNTED'] = false;
229 if ($is_show_stats) {
230 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
231 $sum_size +
= $tblsize;
232 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
234 //$display_rows = ' - ';
238 // Merge or BerkleyDB table: Only row count is accurate.
239 if ($is_show_stats) {
240 $formatted_size = ' - ';
244 // for a view, the ENGINE is null
247 // countRecords() takes care of $cfg['MaxExactCountViews']
248 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
249 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
251 $table_is_view = true;
254 // Unknown table type.
255 if ($is_show_stats) {
256 $formatted_size = 'unknown';
260 $sum_entries +
= $each_table['TABLE_ROWS'];
262 if (isset($each_table['Collation'])) {
263 $collation = '<dfn title="'
264 . PMA_getCollationDescr($each_table['Collation']) . '">'
265 . $each_table['Collation'] . '</dfn>';
270 if ($is_show_stats) {
271 if (isset($formatted_overhead)) {
272 $overhead = '<a href="tbl_structure.php?'
273 . $tbl_url_query . '#showusage">' . $formatted_overhead
274 . ' ' . $overhead_unit . '</a>' . "\n";
275 unset($formatted_overhead);
277 "document.getElementById('checkbox_tbl_$i').checked = true;";
283 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
284 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
285 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
286 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
287 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
288 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
293 if ($table_is_view) {
294 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $table_encoded . '" />';
297 if ($each_table['TABLE_ROWS'] > 0) {
298 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
299 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
301 $browse_table = $titles['NoBrowse'];
302 $search_table = $titles['NoSearch'];
305 if (! $db_is_information_schema) {
306 if (! empty($each_table['TABLE_ROWS'])) {
307 $empty_table = '<a href="sql.php?' . $tbl_url_query
309 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
311 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
312 . '" onclick="return confirmLink(this, \'TRUNCATE ';
313 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
315 $empty_table = $titles['NoEmpty'];
317 $drop_query = 'DROP '
318 . ($table_is_view ?
'VIEW' : 'TABLE')
319 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
320 $drop_message = sprintf(
321 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
322 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME'])));
325 if ($num_columns > 0 && $num_tables > $num_columns
326 && (($row_count %
$num_columns) == 0)) {
337 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
339 <input type
="checkbox" name
="selected_tbl[]"
340 value
="<?php echo $table_encoded; ?>"
341 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
342 <th
><label
for="checkbox_tbl_<?php echo $i; ?>"
343 title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></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 $row_count_pre = '~';
372 $sum_row_count_pre = '~';
373 $show_superscript = PMA_showHint(PMA_sanitize(sprintf($strViewHasAtLeast, '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
374 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
375 // InnoDB table: we did not get an accurate row count
376 $row_count_pre = '~';
377 $sum_row_count_pre = '~';
378 $show_superscript = '';
381 $show_superscript = '';
384 <td
class="value"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
385 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
386 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
$strView : $each_table['ENGINE']); ?
></td
>
387 <?php
if (isset($collation)) { ?
>
388 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
392 <?php
if ($is_show_stats) { ?
>
394 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
395 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
396 <td
class="value"><?php
echo $overhead; ?
></td
>
398 <?php
} elseif ($table_is_view) { ?
>
399 <td
class="value">-</td
>
400 <td
><?php
echo $strView; ?
></td
>
402 <?php
if ($is_show_stats) { ?
>
403 <td
class="value">-</td
>
404 <td
class="value">-</td
>
407 <td colspan
="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
409 <?php
echo $strInUse; ?
></td
>
410 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
416 if ($is_show_stats) {
417 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
418 list($overhead_formatted, $overhead_unit) =
419 PMA_formatByteDown($overhead_size, 3, 1);
425 <th align
="center" nowrap
="nowrap">
426 <?php
echo sprintf($strTables, PMA_formatNumber($num_tables, 0)); ?
>
428 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
429 <?php
echo $strSum; ?
></th
>
430 <th
class="value"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
432 if (!($cfg['PropertiesNumColumns'] > 1)) {
433 $default_engine = PMA_DBI_get_default_engine();
434 echo ' <th align="center">' . "\n"
436 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
437 // we got a case where $db_collation was empty
438 echo ' <th align="center">' . "\n";
439 if (! empty($db_collation)) {
441 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
447 if ($is_show_stats) {
449 <th
class="value"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
450 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
458 <div
class="clearfloat">
460 // Check all tables url
461 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
463 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
464 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
465 <a href
="<?php echo $checkall_url; ?>&checkall=1"
466 onclick
="if (markAllRows('tablesForm')) return false;">
467 <?php
echo $strCheckAll; ?
></a
>
469 <a href
="<?php echo $checkall_url; ?>"
470 onclick
="if (unMarkAllRows('tablesForm')) return false;">
471 <?php
echo $strUncheckAll; ?
></a
>
472 <?php
if ($overhead_check != '') { ?
>
474 <a href
="#" onclick
="unMarkAllRows('tablesForm');
475 <?php echo $overhead_check; ?> return false;">
476 <?php
echo $strCheckOverhead; ?
></a
>
479 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
481 echo ' <option value="' . $strWithChecked . '" selected="selected">'
482 . $strWithChecked . '</option>' . "\n";
483 echo ' <option value="' . $strEmpty . '" >'
484 . $strEmpty . '</option>' . "\n";
485 echo ' <option value="' . $strDrop . '" >'
486 . $strDrop . '</option>' . "\n";
487 echo ' <option value="' . $strPrintView . '" >'
488 . $strPrintView . '</option>' . "\n";
489 echo ' <option value="' . $strCheckTable . '" >'
490 . $strCheckTable . '</option>' . "\n";
491 echo ' <option value="' . $strOptimizeTable . '" >'
492 . $strOptimizeTable . '</option>' . "\n";
493 echo ' <option value="' . $strRepairTable . '" >'
494 . $strRepairTable . '</option>' . "\n";
495 echo ' <option value="' . $strAnalyzeTable . '" >'
496 . $strAnalyzeTable . '</option>' . "\n";
499 <script type
="text/javascript">
501 // Fake js to allow the use of the <noscript> tag
505 <input type
="submit" value
="<?php echo $strGo; ?>" />
507 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
511 // display again the table list navigator
512 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
518 require './libraries/db_routines.inc.php';
521 if (PMA_MYSQL_INT_VERSION
> 50100) {
522 require './libraries/db_events.inc.php';
526 * Work on the database
527 * redesigned 2004-05-08 by mkkeck
530 /* Printable view of a table */
532 echo '<a href="db_printview.php?' . $url_query . '">';
533 if ($cfg['PropertiesIconic']) {
534 echo '<img class="icon" src="' . $pmaThemeImage
535 .'b_print.png" width="16" height="16" alt="" />';
537 echo $strPrintView . '</a> ';
539 echo '<a href="./db_datadict.php?' . $url_query . '">';
540 if ($cfg['PropertiesIconic']) {
541 echo '<img class="icon" src="' . $pmaThemeImage
542 .'b_tblanalyse.png" width="16" height="16" alt="" />';
544 echo $strDataDict . '</a>';
547 if (empty($db_is_information_schema)) {
548 require './libraries/display_create_table.lib.php';
549 } // end if (Create Table dialog)
552 * Displays the footer
554 require_once './libraries/footer.inc.php';