3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once './libraries/common.lib.php';
6 require_once './libraries/Table.class.php';
9 * Prepares the tables list if the user where not redirected to this script
10 * because there is no table in the database ($is_info is true)
12 if (empty($is_info)) {
13 // Drops/deletes/etc. multiple tables if required
14 if ((!empty($submit_mult) && isset($selected_tbl))
15 ||
isset($mult_btn)) {
16 $action = 'db_details_structure.php';
17 $err_url = 'db_details_structure.php?'. PMA_generate_common_url($db);
18 require './libraries/mult_submits.inc.php';
19 $message = $strSuccess;
21 require './libraries/db_details_common.inc.php';
22 $url_query .= '&goto=db_details_structure.php';
24 // Gets the database structure
25 $sub_part = '_structure';
26 require './libraries/db_details_db_info.inc.php';
30 if ($num_tables == 0) {
31 echo '<p>' . $strNoTablesFound . '</p>' . "\n";
33 if (empty($db_is_information_schema)) {
34 require './libraries/display_create_table.lib.php';
35 } // end if (Create Table dialog)
40 require_once './libraries/footer.inc.php';
45 // 2. Shows table informations - staybyte - 11 June 2001
47 require_once './libraries/bookmark.lib.php';
49 if (PMA_MYSQL_INT_VERSION
>= 40101) {
50 require_once './libraries/mysql_charsets.lib.php';
51 $db_collation = PMA_getDbCollation($db);
56 * void PMA_TableHeader([bool $db_is_information_schema = false])
57 * display table header (<table><thead>...</thead><tbody>)
59 * @uses PMA_showHint()
60 * @uses PMA_MYSQL_INT_VERSION
61 * @uses $GLOBALS['cfg']['PropertiesNumColumns']
62 * @uses $GLOBALS['cfg']['ShowStats']
63 * @uses $GLOBALS['strTable']
64 * @uses $GLOBALS['strAction']
65 * @uses $GLOBALS['strRecords']
66 * @uses $GLOBALS['strApproximateCount']
67 * @uses $GLOBALS['strType']
68 * @uses $GLOBALS['strCollation']
69 * @uses $GLOBALS['strSize']
70 * @uses $GLOBALS['strOverhead']
71 * @uses $GLOBALS['structure_tbl_col_cnt']
72 * @param boolean $db_is_information_schema
74 function PMA_TableHeader($db_is_information_schema = false)
76 $cnt = 0; // Let's count the columns...
78 if ($db_is_information_schema) {
84 echo '<table class="data" style="float: left;">' . "\n"
86 .'<tr><td></td>' . "\n"
87 .' <th>' . $GLOBALS['strTable'] . '</th>' . "\n"
88 .' <th colspan="' . $action_colspan . '">' . "\n"
89 .' ' . $GLOBALS['strAction'] . "\n"
91 .' <th>' . $GLOBALS['strRecords']
92 .PMA_showHint($GLOBALS['strApproximateCount']) . "\n"
94 if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
95 echo ' <th>' . $GLOBALS['strType'] . '</th>' . "\n";
97 if (PMA_MYSQL_INT_VERSION
>= 40100) {
98 echo ' <th>' . $GLOBALS['strCollation'] . '</th>' . "\n";
102 if ($GLOBALS['cfg']['ShowStats']) {
103 echo ' <th>' . $GLOBALS['strSize'] . '</th>' . "\n"
104 . ' <th>' . $GLOBALS['strOverhead'] . '</th>' . "\n";
108 echo '</thead>' . "\n";
109 echo '<tbody>' . "\n";
110 $GLOBALS['structure_tbl_col_cnt'] = $cnt +
$action_colspan +
3;
114 if (true == $cfg['PropertiesIconic']) {
115 $titles['Browse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
116 $titles['NoBrowse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
117 $titles['Search'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
118 $titles['NoSearch'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
119 $titles['Insert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
120 $titles['NoInsert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
121 $titles['Structure'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_props.png" alt="' . $strStructure . '" title="' . $strStructure . '" />';
122 $titles['Drop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
123 $titles['NoDrop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
124 $titles['Empty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
125 $titles['NoEmpty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
127 if ('both' === $cfg['PropertiesIconic']) {
128 $titles['Browse'] .= $strBrowse;
129 $titles['Search'] .= $strSearch;
130 $titles['NoBrowse'] .= $strBrowse;
131 $titles['NoSearch'] .= $strSearch;
132 $titles['Insert'] .= $strInsert;
133 $titles['NoInsert'] .= $strInsert;
134 $titles['Structure'] .= $strStructure;
135 $titles['Drop'] .= $strDrop;
136 $titles['NoDrop'] .= $strDrop;
137 $titles['Empty'] .= $strEmpty;
138 $titles['NoEmpty'] .= $strEmpty;
141 $titles['Browse'] = $strBrowse;
142 $titles['Search'] = $strSearch;
143 $titles['NoBrowse'] = $strBrowse;
144 $titles['NoSearch'] = $strSearch;
145 $titles['Insert'] = $strInsert;
146 $titles['NoInsert'] = $strInsert;
147 $titles['Structure'] = $strStructure;
148 $titles['Drop'] = $strDrop;
149 $titles['NoDrop'] = $strDrop;
150 $titles['Empty'] = $strEmpty;
151 $titles['NoEmpty'] = $strEmpty;
155 * Displays the tables list
158 <form method
="post" action
="db_details_structure.php" name
="tablesForm" id
="tablesForm">
160 echo PMA_generate_common_hidden_inputs($db);
162 PMA_TableHeader($db_is_information_schema);
164 $i = $sum_entries = 0;
165 $sum_size = (double) 0;
166 $overhead_size = (double) 0;
167 $overhead_check = '';
168 $checked = !empty($checkall) ?
' checked="checked"' : '';
169 $num_columns = $cfg['PropertiesNumColumns'] > 1 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1 : 0;
173 $hidden_fields = array();
175 $at_least_one_view_exceeds_max_count = false;
177 foreach ($tables as $keyname => $each_table) {
178 if ($each_table['TABLE_ROWS'] === null ||
$each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
179 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
180 $each_table['TABLE_NAME'], $return = true, $force_exact = true);
183 $table_encoded = urlencode($each_table['TABLE_NAME']);
184 // MySQL < 5.0.13 returns "view", >= 5.0.13 returns "VIEW"
185 $table_is_view = ($each_table['TABLE_TYPE'] === 'VIEW'
186 ||
$each_table['TABLE_TYPE'] === 'SYSTEM VIEW');
188 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
189 ?
htmlspecialchars($tooltip_aliasname[$each_table['TABLE_NAME']])
190 : htmlspecialchars($each_table['TABLE_NAME']);
191 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
192 ?
htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']])
193 : htmlspecialchars($each_table['TABLE_NAME']);
195 // Sets parameters for links
196 $tbl_url_query = $url_query . '&table=' . $table_encoded;
200 if ($table_is_view) {
201 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $table_encoded . '" />';
204 if ($each_table['TABLE_ROWS'] > 0) {
205 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
206 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
208 $browse_table = $titles['NoBrowse'];
209 $search_table = $titles['NoSearch'];
212 if (! $db_is_information_schema) {
213 if (! empty($each_table['TABLE_ROWS'])) {
214 $empty_table = '<a href="sql.php?' . $tbl_url_query
216 if (PMA_MYSQL_INT_VERSION
>= 40000) {
217 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
219 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
220 . '" onclick="return confirmLink(this, \'TRUNCATE ';
222 $empty_table .= urlencode('DELETE FROM ' . PMA_backquote($each_table['TABLE_NAME']))
224 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
225 . '" onclick="return confirmLink(this, \'DELETE FROM ';
227 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
229 $empty_table = $titles['NoEmpty'];
231 $drop_query = 'DROP '
232 . ($table_is_view ?
'VIEW' : 'TABLE')
233 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
234 $drop_message = sprintf(
235 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
236 htmlspecialchars($each_table['TABLE_NAME']));
239 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
240 // statistics whatever is the table type
242 if (isset($each_table['TABLE_ROWS'])) {
243 // MyISAM, ISAM or Heap table: Row count, data size and index size
245 if (preg_match('@^(MyISAM|ISAM|HEAP|MEMORY)$@', $each_table['ENGINE'])) {
246 if ($cfg['ShowStats']) {
247 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
248 $sum_size +
= $tblsize;
249 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
250 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
251 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
252 $overhead_size +
= $each_table['Data_free'];
255 $sum_entries +
= $each_table['TABLE_ROWS'];
256 } elseif ($each_table['ENGINE'] == 'InnoDB') {
257 // InnoDB table: Row count is not accurate but data and index
259 if ($cfg['ShowStats']) {
260 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
261 $sum_size +
= $tblsize;
262 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
264 //$display_rows = ' - ';
265 $sum_entries +
= $each_table['TABLE_ROWS'];
266 } elseif (preg_match('@^(MRG_MyISAM|BerkeleyDB)$@', $each_table['ENGINE'])) {
267 // Merge or BerkleyDB table: Only row count is accurate.
268 if ($cfg['ShowStats']) {
269 $formatted_size = ' - ';
272 $sum_entries +
= $each_table['TABLE_ROWS'];
274 // Unknown table type.
275 if ($cfg['ShowStats']) {
276 $formatted_size = 'unknown';
281 if (PMA_MYSQL_INT_VERSION
>= 40100) {
282 if (isset($each_table['Collation'])) {
283 $collation = '<dfn title="'
284 . PMA_getCollationDescr($each_table['Collation']) . '">'
285 . $each_table['Collation'] . '</dfn>';
291 if ($cfg['ShowStats']) {
292 if (isset($formatted_overhead)) {
293 $overhead = '<a href="tbl_properties_structure.php?'
294 . $tbl_url_query . '#showusage">' . $formatted_overhead
295 . ' ' . $overhead_unit . '</a>' . "\n";
296 unset($formatted_overhead);
298 "document.getElementById('checkbox_tbl_$i').checked = true;";
303 } // end if (isset($each_table['TABLE_ROWS'])
305 if ($num_columns > 0 && $num_tables > $num_columns
306 && (($row_count %
$num_columns) == 0)) {
317 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
319 <input type
="checkbox" name
="selected_tbl[]"
320 value
="<?php echo $table_encoded; ?>"
321 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
322 <th
><label
for="checkbox_tbl_<?php echo $i; ?>"
323 title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></label
>
325 <td align
="center"><?php
echo $browse_table; ?
></td
>
327 <a href
="tbl_properties_structure.php?<?php echo $tbl_url_query; ?>">
328 <?php
echo $titles['Structure']; ?
></a
></td
>
329 <td align
="center"><?php
echo $search_table; ?
></td
>
330 <?php
if (! $db_is_information_schema) { ?
>
332 <a href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
333 <?php
echo $titles['Insert']; ?
></a
></td
>
334 <td align
="center"><?php
echo $empty_table; ?
></td
>
336 <a href
="sql.php?<?php echo $tbl_url_query;
337 ?>&reload=1&purge=1&sql_query=<?php
338 echo urlencode($drop_query); ?>&zero_rows=<?php
339 echo urlencode($drop_message); ?>"
340 onclick
="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
341 <?php
echo $titles['Drop']; ?
></a
></td
>
342 <?php
} // end if (! $db_is_information_schema)
344 // there is a null value in the ENGINE
345 // - when the table needs to be repaired, or
346 // - when it's a view
347 // so ensure that we'll display "in use" below for a table
348 // that needs to be repaired
350 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
351 if ($table_is_view && $each_table['TABLE_ROWS'] >= $cfg['MaxExactCount']) {
352 $at_least_one_view_exceeds_max_count = true;
353 $show_superscript = '<sup>1</sup>';
355 $show_superscript = '';
358 <td
class="value"><?php
echo PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
359 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
360 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
$strView : $each_table['ENGINE']); ?
></td
>
361 <?php
if (isset($collation)) { ?
>
362 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
366 <?php
if ($cfg['ShowStats']) { ?
>
368 href
="tbl_properties_structure.php?<?php echo $tbl_url_query; ?>#showusage"
369 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
370 <td
class="value"><?php
echo $overhead; ?
></td
>
372 <?php
} elseif ($table_is_view) { ?
>
373 <td
class="value">-</td
>
374 <td
><?php
echo $strView; ?
></td
>
376 <?php
if ($cfg['ShowStats']) { ?
>
377 <td
class="value">-</td
>
378 <td
class="value">-</td
>
381 <td colspan
="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
383 <?php
echo $strInUse; ?
></td
>
384 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
390 if ($cfg['ShowStats']) {
391 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
392 list($overhead_formatted, $overhead_unit) =
393 PMA_formatByteDown($overhead_size, 3, 1);
399 <th align
="center" nowrap
="nowrap">
400 <?php
echo sprintf($strTables, PMA_formatNumber($num_tables, 0)); ?
>
402 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
403 <?php
echo $strSum; ?
></th
>
404 <th
class="value"><?php
echo PMA_formatNumber($sum_entries, 0); ?
></th
>
406 if (!($cfg['PropertiesNumColumns'] > 1)) {
407 $default_engine = PMA_DBI_get_default_engine();
408 echo ' <th align="center">' . "\n"
410 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</th>' . "\n";
411 if (! empty($db_collation)) {
412 echo ' <th align="center">' . "\n"
414 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
419 if ($cfg['ShowStats']) {
421 <th
class="value"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
422 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
430 <div
class="clearfloat">
432 // Check all tables url
433 $checkall_url = 'db_details_structure.php?' . PMA_generate_common_url($db);
435 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
436 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
437 <a href
="<?php echo $checkall_url; ?>&checkall=1"
438 onclick
="if (markAllRows('tablesForm')) return false;">
439 <?php
echo $strCheckAll; ?
></a
>
441 <a href
="<?php echo $checkall_url; ?>"
442 onclick
="if (unMarkAllRows('tablesForm')) return false;">
443 <?php
echo $strUncheckAll; ?
></a
>
444 <?php
if ($overhead_check != '') { ?
>
446 <a href
="#" onclick
="unMarkAllRows('tablesForm');
447 <?php echo $overhead_check; ?> return false;">
448 <?php
echo $strCheckOverhead; ?
></a
>
451 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
453 echo ' <option value="' . $strWithChecked . '" selected="selected">'
454 . $strWithChecked . '</option>' . "\n";
455 echo ' <option value="' . $strEmpty . '" >'
456 . $strEmpty . '</option>' . "\n";
457 echo ' <option value="' . $strDrop . '" >'
458 . $strDrop . '</option>' . "\n";
459 echo ' <option value="' . $strPrintView . '" >'
460 . $strPrintView . '</option>' . "\n";
461 echo ' <option value="' . $strCheckTable . '" >'
462 . $strCheckTable . '</option>' . "\n";
463 echo ' <option value="' . $strOptimizeTable . '" >'
464 . $strOptimizeTable . '</option>' . "\n";
465 echo ' <option value="' . $strRepairTable . '" >'
466 . $strRepairTable . '</option>' . "\n";
467 echo ' <option value="' . $strAnalyzeTable . '" >'
468 . $strAnalyzeTable . '</option>' . "\n";
471 <script type
="text/javascript" language
="javascript">
473 // Fake js to allow the use of the <noscript> tag
477 <input type
="submit" value
="<?php echo $strGo; ?>" />
479 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
483 // Notice about row count for views
485 if ($at_least_one_view_exceeds_max_count && !$db_is_information_schema) {
486 echo '<div class="notice">' . "\n";
487 echo '<sup>1</sup>' . PMA_sanitize(sprintf($strViewMaxExactCount, PMA_formatNumber($cfg['MaxExactCount'], 0), '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]')) . "\n";
488 echo '</div>' . "\n";
495 * Work on the database
496 * redesigned 2004-05-08 by mkkeck
499 /* Printable view of a table */
501 echo '<a href="db_printview.php?' . $url_query . '">';
502 if ($cfg['PropertiesIconic']) {
503 echo '<img class="icon" src="' . $pmaThemeImage
504 .'b_print.png" width="16" height="16" alt="" />';
506 echo $strPrintView . '</a> ';
508 echo '<a href="./db_datadict.php?' . $url_query . '">';
509 if ($cfg['PropertiesIconic']) {
510 echo '<img class="icon" src="' . $pmaThemeImage
511 .'b_tblanalyse.png" width="16" height="16" alt="" />';
513 echo $strDataDict . '</a>';
516 if (empty($db_is_information_schema)) {
517 require './libraries/display_create_table.lib.php';
518 } // end if (Create Table dialog)
521 * Displays the footer
523 require_once './libraries/footer.inc.php';