Fix typos (bug #1597137).
[phpmyadmin/last10db.git] / db_structure.php
blob7be4945ed33e7e89d5301f5dae70a7d560325ca9
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once './libraries/common.lib.php';
6 require_once './libraries/Table.class.php';
8 /**
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_structure.php';
17 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
18 require './libraries/mult_submits.inc.php';
19 $message = $strSuccess;
21 require './libraries/db_common.inc.php';
22 $url_query .= '&amp;goto=db_structure.php';
24 // Gets the database structure
25 $sub_part = '_structure';
26 require './libraries/db_info.inc.php';
29 // 1. No tables
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)
37 /**
38 * Displays the footer
40 require_once './libraries/footer.inc.php';
41 exit;
44 // else
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);
54 // Display function
55 /**
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['is_show_stats']
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) {
79 $action_colspan = 3;
80 } else {
81 $action_colspan = 6;
84 echo '<table class="data" style="float: left;">' . "\n"
85 .'<thead>' . "\n"
86 .'<tr><td></td>' . "\n"
87 .' <th>' . $GLOBALS['strTable'] . '</th>' . "\n"
88 .' <th colspan="' . $action_colspan . '">' . "\n"
89 .' ' . $GLOBALS['strAction'] . "\n"
90 .' </th>'
91 .' <th>' . $GLOBALS['strRecords']
92 .PMA_showHint($GLOBALS['strApproximateCount']) . "\n"
93 .' </th>' . "\n";
94 if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
95 echo ' <th>' . $GLOBALS['strType'] . '</th>' . "\n";
96 $cnt++;
97 if (PMA_MYSQL_INT_VERSION >= 40100) {
98 echo ' <th>' . $GLOBALS['strCollation'] . '</th>' . "\n";
99 $cnt++;
102 if ($GLOBALS['is_show_stats']) {
103 echo ' <th>' . $GLOBALS['strSize'] . '</th>' . "\n"
104 . ' <th>' . $GLOBALS['strOverhead'] . '</th>' . "\n";
105 $cnt += 2;
107 echo '</tr>' . "\n";
108 echo '</thead>' . "\n";
109 echo '<tbody>' . "\n";
110 $GLOBALS['structure_tbl_col_cnt'] = $cnt + $action_colspan + 3;
111 } // end function PMA_TableHeader()
113 $titles = array();
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;
140 } else {
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_structure.php" name="tablesForm" id="tablesForm">
159 <?php
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;
170 $row_count = 0;
173 $hidden_fields = array();
174 $odd_row = true;
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 . '&amp;table=' . $table_encoded;
197 $i++;
199 $row_count++;
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 . '&amp;pos=0">' . $titles['Browse'] . '</a>';
206 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
207 } else {
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
215 . '&amp;sql_query=';
216 if (PMA_MYSQL_INT_VERSION >= 40000) {
217 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
218 . '&amp;zero_rows='
219 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
220 . '" onclick="return confirmLink(this, \'TRUNCATE ';
221 } else {
222 $empty_table .= urlencode('DELETE FROM ' . PMA_backquote($each_table['TABLE_NAME']))
223 . '&amp;zero_rows='
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>';
228 } else {
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
244 // is accurate.
245 if (preg_match('@^(MyISAM|ISAM|HEAP|MEMORY)$@', $each_table['ENGINE'])) {
246 if ($is_show_stats) {
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
258 // sizes are.
259 if ($is_show_stats) {
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 ($is_show_stats) {
269 $formatted_size = ' - ';
270 $unit = '';
272 $sum_entries += $each_table['TABLE_ROWS'];
273 } else {
274 // Unknown table type.
275 if ($is_show_stats) {
276 $formatted_size = 'unknown';
277 $unit = '';
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>';
286 } else {
287 $collation = '---';
291 if ($is_show_stats) {
292 if (isset($formatted_overhead)) {
293 $overhead = '<a href="tbl_structure.php?'
294 . $tbl_url_query . '#showusage">' . $formatted_overhead
295 . ' ' . $overhead_unit . '</a>' . "\n";
296 unset($formatted_overhead);
297 $overhead_check .=
298 "document.getElementById('checkbox_tbl_$i').checked = true;";
299 } else {
300 $overhead = '-';
302 } // end if
303 } // end if (isset($each_table['TABLE_ROWS'])
305 if ($num_columns > 0 && $num_tables > $num_columns
306 && (($row_count % $num_columns) == 0)) {
307 $row_count = 1;
308 $odd_row = true;
310 </tr>
311 </tbody>
312 </table>
313 <?php
314 PMA_TableHeader();
317 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
318 <td align="center">
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>
324 </th>
325 <td align="center"><?php echo $browse_table; ?></td>
326 <td align="center">
327 <a href="tbl_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) { ?>
331 <td align="center">
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>
335 <td align="center">
336 <a href="sql.php?<?php echo $tbl_url_query;
337 ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php
338 echo urlencode($drop_query); ?>&amp;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>';
354 } else {
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>
363 <?php } ?>
364 <?php } ?>
366 <?php if ($is_show_stats) { ?>
367 <td class="value"><a
368 href="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
369 ><?php echo $formatted_size . ' ' . $unit; ?></a></td>
370 <td class="value"><?php echo $overhead; ?></td>
371 <?php } // end if ?>
372 <?php } elseif ($table_is_view) { ?>
373 <td class="value">-</td>
374 <td><?php echo $strView; ?></td>
375 <td>---</td>
376 <?php if ($is_show_stats) { ?>
377 <td class="value">-</td>
378 <td class="value">-</td>
379 <?php } ?>
380 <?php } else { ?>
381 <td colspan="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
382 align="center">
383 <?php echo $strInUse; ?></td>
384 <?php } // end if (isset($each_table['TABLE_ROWS'])) else ?>
385 </tr>
386 <?php
387 } // end foreach
389 // Show Summary
390 if ($is_show_stats) {
391 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
392 list($overhead_formatted, $overhead_unit) =
393 PMA_formatByteDown($overhead_size, 3, 1);
396 </tbody>
397 <tbody>
398 <tr><td></td>
399 <th align="center" nowrap="nowrap">
400 <?php echo sprintf($strTables, PMA_formatNumber($num_tables, 0)); ?>
401 </th>
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>
405 <?php
406 if (!($cfg['PropertiesNumColumns'] > 1)) {
407 $default_engine = PMA_DBI_get_default_engine();
408 echo ' <th align="center">' . "\n"
409 . ' <dfn title="'
410 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</th>' . "\n";
411 // Have to account for old MySQL with no collation (bug 1554885)
412 if (PMA_MYSQL_INT_VERSION >= 40100) {
413 // we got a case where $db_collation was empty
414 echo ' <th align="center">' . "\n";
415 if (! empty($db_collation)) {
416 echo ' <dfn title="'
417 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
418 . '</dfn>';
420 echo '</th>';
424 if ($is_show_stats) {
426 <th class="value"><?php echo $sum_formatted . ' ' . $unit; ?></th>
427 <th class="value"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
428 <?php
431 </tr>
432 </tbody>
433 </table>
435 <div class="clearfloat">
436 <?php
437 // Check all tables url
438 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
440 <img class="selectallarrow" src="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
441 width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
442 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
443 onclick="if (markAllRows('tablesForm')) return false;">
444 <?php echo $strCheckAll; ?></a>
446 <a href="<?php echo $checkall_url; ?>"
447 onclick="if (unMarkAllRows('tablesForm')) return false;">
448 <?php echo $strUncheckAll; ?></a>
449 <?php if ($overhead_check != '') { ?>
451 <a href="#" onclick="unMarkAllRows('tablesForm');
452 <?php echo $overhead_check; ?> return false;">
453 <?php echo $strCheckOverhead; ?></a>
454 <?php } ?>
456 <select name="submit_mult" onchange="this.form.submit();" style="margin: 0 3em 0 3em;">
457 <?php
458 echo ' <option value="' . $strWithChecked . '" selected="selected">'
459 . $strWithChecked . '</option>' . "\n";
460 echo ' <option value="' . $strEmpty . '" >'
461 . $strEmpty . '</option>' . "\n";
462 echo ' <option value="' . $strDrop . '" >'
463 . $strDrop . '</option>' . "\n";
464 echo ' <option value="' . $strPrintView . '" >'
465 . $strPrintView . '</option>' . "\n";
466 echo ' <option value="' . $strCheckTable . '" >'
467 . $strCheckTable . '</option>' . "\n";
468 echo ' <option value="' . $strOptimizeTable . '" >'
469 . $strOptimizeTable . '</option>' . "\n";
470 echo ' <option value="' . $strRepairTable . '" >'
471 . $strRepairTable . '</option>' . "\n";
472 echo ' <option value="' . $strAnalyzeTable . '" >'
473 . $strAnalyzeTable . '</option>' . "\n";
475 </select>
476 <script type="text/javascript" language="javascript">
477 <!--
478 // Fake js to allow the use of the <noscript> tag
479 //-->
480 </script>
481 <noscript>
482 <input type="submit" value="<?php echo $strGo; ?>" />
483 </noscript>
484 <?php echo implode("\n", $hidden_fields) . "\n"; ?>
485 </div>
486 </form>
487 <?php
488 // Notice about row count for views
490 if ($at_least_one_view_exceeds_max_count && !$db_is_information_schema) {
491 echo '<div class="notice">' . "\n";
492 echo '<sup>1</sup>' . PMA_sanitize(sprintf($strViewMaxExactCount, PMA_formatNumber($cfg['MaxExactCount'], 0), '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]')) . "\n";
493 echo '</div>' . "\n";
496 <hr />
498 <?php
500 * Work on the database
501 * redesigned 2004-05-08 by mkkeck
503 /* DATABASE WORK */
504 /* Printable view of a table */
505 echo '<p>';
506 echo '<a href="db_printview.php?' . $url_query . '">';
507 if ($cfg['PropertiesIconic']) {
508 echo '<img class="icon" src="' . $pmaThemeImage
509 .'b_print.png" width="16" height="16" alt="" />';
511 echo $strPrintView . '</a> ';
513 echo '<a href="./db_datadict.php?' . $url_query . '">';
514 if ($cfg['PropertiesIconic']) {
515 echo '<img class="icon" src="' . $pmaThemeImage
516 .'b_tblanalyse.png" width="16" height="16" alt="" />';
518 echo $strDataDict . '</a>';
519 echo '</p>';
521 if (empty($db_is_information_schema)) {
522 require './libraries/display_create_table.lib.php';
523 } // end if (Create Table dialog)
526 * Displays the footer
528 require_once './libraries/footer.inc.php';