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';
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);
26 require './libraries/mult_submits.inc.php';
27 if (empty($message)) {
28 $message = PMA_Message
::success();
31 require './libraries/db_common.inc.php';
32 $url_query .= '&goto=db_structure.php';
34 // Gets the database structure
35 $sub_part = '_structure';
36 require './libraries/db_info.inc.php';
40 if ($num_tables == 0) {
41 echo '<p>' . $strNoTablesFound . '</p>' . "\n";
43 if (empty($db_is_information_schema)) {
44 require './libraries/display_create_table.lib.php';
45 } // end if (Create Table dialog)
50 require_once './libraries/footer.inc.php';
55 // 2. Shows table informations - staybyte - 11 June 2001
57 require_once './libraries/bookmark.lib.php';
59 require_once './libraries/mysql_charsets.lib.php';
60 $db_collation = PMA_getDbCollation($db);
64 * void PMA_TableHeader([bool $db_is_information_schema = false])
65 * display table header (<table><thead>...</thead><tbody>)
67 * @uses PMA_showHint()
68 * @uses $GLOBALS['cfg']['PropertiesNumColumns']
69 * @uses $GLOBALS['is_show_stats']
70 * @uses $GLOBALS['strTable']
71 * @uses $GLOBALS['strAction']
72 * @uses $GLOBALS['strRecords']
73 * @uses $GLOBALS['strApproximateCount']
74 * @uses $GLOBALS['strType']
75 * @uses $GLOBALS['strCollation']
76 * @uses $GLOBALS['strSize']
77 * @uses $GLOBALS['strOverhead']
78 * @uses $GLOBALS['structure_tbl_col_cnt']
79 * @param boolean $db_is_information_schema
81 function PMA_TableHeader($db_is_information_schema = false)
83 $cnt = 0; // Let's count the columns...
85 if ($db_is_information_schema) {
91 echo '<table class="data" style="float: left;">' . "\n"
93 .'<tr><td></td>' . "\n"
94 .' <th>' . $GLOBALS['strTable'] . '</th>' . "\n"
95 .' <th colspan="' . $action_colspan . '">' . "\n"
96 .' ' . $GLOBALS['strAction'] . "\n"
98 .' <th>' . $GLOBALS['strRecords']
99 .PMA_showHint($GLOBALS['strApproximateCount']) . "\n"
101 if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
102 echo ' <th>' . $GLOBALS['strType'] . '</th>' . "\n";
104 echo ' <th>' . $GLOBALS['strCollation'] . '</th>' . "\n";
107 if ($GLOBALS['is_show_stats']) {
108 echo ' <th>' . $GLOBALS['strSize'] . '</th>' . "\n"
109 . ' <th>' . $GLOBALS['strOverhead'] . '</th>' . "\n";
113 echo '</thead>' . "\n";
114 echo '<tbody>' . "\n";
115 $GLOBALS['structure_tbl_col_cnt'] = $cnt +
$action_colspan +
3;
116 } // end function PMA_TableHeader()
119 if (true == $cfg['PropertiesIconic']) {
120 $titles['Browse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
121 $titles['NoBrowse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
122 $titles['Search'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
123 $titles['NoSearch'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
124 $titles['Insert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
125 $titles['NoInsert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
126 $titles['Structure'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_props.png" alt="' . $strStructure . '" title="' . $strStructure . '" />';
127 $titles['Drop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
128 $titles['NoDrop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
129 $titles['Empty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
130 $titles['NoEmpty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
132 if ('both' === $cfg['PropertiesIconic']) {
133 $titles['Browse'] .= $strBrowse;
134 $titles['Search'] .= $strSearch;
135 $titles['NoBrowse'] .= $strBrowse;
136 $titles['NoSearch'] .= $strSearch;
137 $titles['Insert'] .= $strInsert;
138 $titles['NoInsert'] .= $strInsert;
139 $titles['Structure'] .= $strStructure;
140 $titles['Drop'] .= $strDrop;
141 $titles['NoDrop'] .= $strDrop;
142 $titles['Empty'] .= $strEmpty;
143 $titles['NoEmpty'] .= $strEmpty;
146 $titles['Browse'] = $strBrowse;
147 $titles['Search'] = $strSearch;
148 $titles['NoBrowse'] = $strBrowse;
149 $titles['NoSearch'] = $strSearch;
150 $titles['Insert'] = $strInsert;
151 $titles['NoInsert'] = $strInsert;
152 $titles['Structure'] = $strStructure;
153 $titles['Drop'] = $strDrop;
154 $titles['NoDrop'] = $strDrop;
155 $titles['Empty'] = $strEmpty;
156 $titles['NoEmpty'] = $strEmpty;
160 * Displays the tables list
163 $_url_params = array(
167 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
170 <form method
="post" action
="db_structure.php" name
="tablesForm" id
="tablesForm">
172 echo PMA_generate_common_hidden_inputs($db);
174 PMA_TableHeader($db_is_information_schema);
176 $i = $sum_entries = 0;
177 $sum_size = (double) 0;
178 $overhead_size = (double) 0;
179 $overhead_check = '';
180 $checked = !empty($checkall) ?
' checked="checked"' : '';
181 $num_columns = $cfg['PropertiesNumColumns'] > 1 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1 : 0;
185 $hidden_fields = array();
187 $sum_row_count_pre = '';
189 foreach ($tables as $keyname => $each_table) {
190 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
191 // statistics whatever is the table type
193 $table_is_view = false;
194 $table_encoded = urlencode($each_table['TABLE_NAME']);
195 // Sets parameters for links
196 $tbl_url_query = $url_query . '&table=' . $table_encoded;
198 switch ( $each_table['ENGINE']) {
199 // MyISAM, ISAM or Heap table: Row count, data size and index size
205 if ($is_show_stats) {
206 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
207 $sum_size +
= $tblsize;
208 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
209 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
210 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
211 $overhead_size +
= $each_table['Data_free'];
216 // InnoDB table: Row count is not accurate but data and index
219 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
220 $each_table['COUNTED'] = true;
221 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
222 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
225 $each_table['COUNTED'] = false;
228 if ($is_show_stats) {
229 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
230 $sum_size +
= $tblsize;
231 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
233 //$display_rows = ' - ';
237 // Merge or BerkleyDB table: Only row count is accurate.
238 if ($is_show_stats) {
239 $formatted_size = ' - ';
243 // for a view, the ENGINE is null
246 // countRecords() takes care of $cfg['MaxExactCountViews']
247 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
248 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
250 $table_is_view = true;
253 // Unknown table type.
254 if ($is_show_stats) {
255 $formatted_size = 'unknown';
259 $sum_entries +
= $each_table['TABLE_ROWS'];
261 if (isset($each_table['Collation'])) {
262 $collation = '<dfn title="'
263 . PMA_getCollationDescr($each_table['Collation']) . '">'
264 . $each_table['Collation'] . '</dfn>';
269 if ($is_show_stats) {
270 if (isset($formatted_overhead)) {
271 $overhead = '<a href="tbl_structure.php?'
272 . $tbl_url_query . '#showusage">' . $formatted_overhead
273 . ' ' . $overhead_unit . '</a>' . "\n";
274 unset($formatted_overhead);
276 "document.getElementById('checkbox_tbl_$i').checked = true;";
282 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
283 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
284 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
285 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
286 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
287 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
292 if ($table_is_view) {
293 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $each_table['TABLE_NAME'] . '" />';
296 if ($each_table['TABLE_ROWS'] > 0) {
297 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
298 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
300 $browse_table = $titles['NoBrowse'];
301 $search_table = $titles['NoSearch'];
304 if (! $db_is_information_schema) {
305 if (! empty($each_table['TABLE_ROWS'])) {
306 $empty_table = '<a href="sql.php?' . $tbl_url_query
308 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
310 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
311 . '" onclick="return confirmLink(this, \'TRUNCATE ';
312 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
314 $empty_table = $titles['NoEmpty'];
316 $drop_query = 'DROP '
317 . ($table_is_view ?
'VIEW' : 'TABLE')
318 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
319 $drop_message = sprintf(
320 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
321 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME'])));
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
>
344 <td align
="center"><?php
echo $browse_table; ?
></td
>
346 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
347 <?php
echo $titles['Structure']; ?
></a
></td
>
348 <td align
="center"><?php
echo $search_table; ?
></td
>
349 <?php
if (! $db_is_information_schema) { ?
>
351 <a href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
352 <?php
echo $titles['Insert']; ?
></a
></td
>
353 <td align
="center"><?php
echo $empty_table; ?
></td
>
355 <a href
="sql.php?<?php echo $tbl_url_query;
356 ?>&reload=1&purge=1&sql_query=<?php
357 echo urlencode($drop_query); ?>&zero_rows=<?php
358 echo urlencode($drop_message); ?>"
359 onclick
="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
360 <?php
echo $titles['Drop']; ?
></a
></td
>
361 <?php
} // end if (! $db_is_information_schema)
363 // there is a null value in the ENGINE
364 // - when the table needs to be repaired, or
365 // - when it's a view
366 // so ensure that we'll display "in use" below for a table
367 // that needs to be repaired
368 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
369 if ($table_is_view) {
370 $row_count_pre = '~';
371 $sum_row_count_pre = '~';
372 $show_superscript = PMA_showHint(PMA_sanitize(sprintf($strViewHasAtLeast, '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
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 // we got a case where $db_collation was empty
437 echo ' <th align="center">' . "\n";
438 if (! empty($db_collation)) {
440 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
446 if ($is_show_stats) {
448 <th
class="value"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
449 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
457 <div
class="clearfloat">
459 // Check all tables url
460 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
462 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
463 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
464 <a href
="<?php echo $checkall_url; ?>&checkall=1"
465 onclick
="if (markAllRows('tablesForm')) return false;">
466 <?php
echo $strCheckAll; ?
></a
>
468 <a href
="<?php echo $checkall_url; ?>"
469 onclick
="if (unMarkAllRows('tablesForm')) return false;">
470 <?php
echo $strUncheckAll; ?
></a
>
471 <?php
if ($overhead_check != '') { ?
>
473 <a href
="#" onclick
="unMarkAllRows('tablesForm');
474 <?php echo $overhead_check; ?> return false;">
475 <?php
echo $strCheckOverhead; ?
></a
>
478 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
480 echo ' <option value="' . $strWithChecked . '" selected="selected">'
481 . $strWithChecked . '</option>' . "\n";
482 echo ' <option value="' . $strEmpty . '" >'
483 . $strEmpty . '</option>' . "\n";
484 echo ' <option value="' . $strDrop . '" >'
485 . $strDrop . '</option>' . "\n";
486 echo ' <option value="' . $strPrintView . '" >'
487 . $strPrintView . '</option>' . "\n";
488 echo ' <option value="' . $strCheckTable . '" >'
489 . $strCheckTable . '</option>' . "\n";
490 echo ' <option value="' . $strOptimizeTable . '" >'
491 . $strOptimizeTable . '</option>' . "\n";
492 echo ' <option value="' . $strRepairTable . '" >'
493 . $strRepairTable . '</option>' . "\n";
494 echo ' <option value="' . $strAnalyzeTable . '" >'
495 . $strAnalyzeTable . '</option>' . "\n";
498 <script type
="text/javascript">
500 // Fake js to allow the use of the <noscript> tag
504 <input type
="submit" value
="<?php echo $strGo; ?>" />
506 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
510 // display again the table list navigator
511 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
517 require './libraries/db_routines.inc.php';
520 if (PMA_MYSQL_INT_VERSION
> 50100) {
521 require './libraries/db_events.inc.php';
525 * Work on the database
526 * redesigned 2004-05-08 by mkkeck
529 /* Printable view of a table */
531 echo '<a href="db_printview.php?' . $url_query . '">';
532 if ($cfg['PropertiesIconic']) {
533 echo '<img class="icon" src="' . $pmaThemeImage
534 .'b_print.png" width="16" height="16" alt="" />';
536 echo $strPrintView . '</a> ';
538 echo '<a href="./db_datadict.php?' . $url_query . '">';
539 if ($cfg['PropertiesIconic']) {
540 echo '<img class="icon" src="' . $pmaThemeImage
541 .'b_tblanalyse.png" width="16" height="16" alt="" />';
543 echo $strDataDict . '</a>';
546 if (empty($db_is_information_schema)) {
547 require './libraries/display_create_table.lib.php';
548 } // end if (Create Table dialog)
551 * Displays the footer
553 require_once './libraries/footer.inc.php';