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(PMA_sanitize($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 // added by rajk - for blobstreaming
190 $PMA_Config = $_SESSION['PMA_Config'];
192 if (!empty ($PMA_Config))
193 $session_bs_tables = $PMA_Config->get('BLOBSTREAMING_TABLES'); // list of blobstreaming tables
195 $tableReductionCount = 0; // the amount to reduce the table count by
197 foreach ($tables as $keyname => $each_table) {
198 if (isset($session_bs_tables))
200 // compare table name against blobstreaming tables
201 foreach ($session_bs_tables as $table_key=>$table_val)
202 // if the table is a blobstreaming table, reduce table count and skip outer foreach loop
203 if ($table_key == $keyname)
205 $tableReductionCount++
;
210 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
211 // statistics whatever is the table type
213 $table_is_view = false;
214 $table_encoded = urlencode($each_table['TABLE_NAME']);
215 // Sets parameters for links
216 $tbl_url_query = $url_query . '&table=' . $table_encoded;
217 // do not list the previous table's size info for a view
218 $formatted_size = '-';
221 switch ( $each_table['ENGINE']) {
222 // MyISAM, ISAM or Heap table: Row count, data size and index size
228 if ($is_show_stats) {
229 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
230 $sum_size +
= $tblsize;
231 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
232 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
233 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
234 $overhead_size +
= $each_table['Data_free'];
239 // InnoDB table: Row count is not accurate but data and index
242 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
243 $each_table['COUNTED'] = true;
244 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
245 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
248 $each_table['COUNTED'] = false;
251 if ($is_show_stats) {
252 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
253 $sum_size +
= $tblsize;
254 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
256 //$display_rows = ' - ';
260 // Merge or BerkleyDB table: Only row count is accurate.
261 if ($is_show_stats) {
262 $formatted_size = ' - ';
266 // for a view, the ENGINE is null
269 // countRecords() takes care of $cfg['MaxExactCountViews']
270 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
271 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
273 $table_is_view = true;
276 // Unknown table type.
277 if ($is_show_stats) {
278 $formatted_size = 'unknown';
282 $sum_entries +
= $each_table['TABLE_ROWS'];
284 if (isset($each_table['Collation'])) {
285 $collation = '<dfn title="'
286 . PMA_getCollationDescr($each_table['Collation']) . '">'
287 . $each_table['Collation'] . '</dfn>';
292 if ($is_show_stats) {
293 if (isset($formatted_overhead)) {
294 $overhead = '<a href="tbl_structure.php?'
295 . $tbl_url_query . '#showusage">' . $formatted_overhead
296 . ' ' . $overhead_unit . '</a>' . "\n";
297 unset($formatted_overhead);
299 "document.getElementById('checkbox_tbl_" . ($i +
1) . "').checked = true;";
305 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
306 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
307 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
308 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
309 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
310 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
315 if ($table_is_view) {
316 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $each_table['TABLE_NAME'] . '" />';
319 if ($each_table['TABLE_ROWS'] > 0) {
320 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
321 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
323 $browse_table = $titles['NoBrowse'];
324 $search_table = $titles['NoSearch'];
327 if (! $db_is_information_schema) {
328 if (! empty($each_table['TABLE_ROWS'])) {
329 $empty_table = '<a href="sql.php?' . $tbl_url_query
331 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
333 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
334 . '" onclick="return confirmLink(this, \'TRUNCATE ';
335 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
337 $empty_table = $titles['NoEmpty'];
339 $drop_query = 'DROP '
340 . ($table_is_view ?
'VIEW' : 'TABLE')
341 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
342 $drop_message = sprintf(
343 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
344 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME'])));
347 if ($num_columns > 0 && $num_tables > $num_columns
348 && (($row_count %
$num_columns) == 0)) {
359 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
361 <input type
="checkbox" name
="selected_tbl[]"
362 value
="<?php echo $each_table['TABLE_NAME']; ?>"
363 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
364 <th
><label
for="checkbox_tbl_<?php echo $i; ?>"
365 title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></label
>
367 <td align
="center"><?php
echo $browse_table; ?
></td
>
369 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
370 <?php
echo $titles['Structure']; ?
></a
></td
>
371 <td align
="center"><?php
echo $search_table; ?
></td
>
372 <?php
if (! $db_is_information_schema) { ?
>
374 <a href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
375 <?php
echo $titles['Insert']; ?
></a
></td
>
376 <td align
="center"><?php
echo $empty_table; ?
></td
>
378 <a href
="sql.php?<?php echo $tbl_url_query;
379 ?>&reload=1&purge=1&sql_query=<?php
380 echo urlencode($drop_query); ?>&zero_rows=<?php
381 echo urlencode($drop_message); ?>"
382 onclick
="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
383 <?php
echo $titles['Drop']; ?
></a
></td
>
384 <?php
} // end if (! $db_is_information_schema)
386 // there is a null value in the ENGINE
387 // - when the table needs to be repaired, or
388 // - when it's a view
389 // so ensure that we'll display "in use" below for a table
390 // that needs to be repaired
391 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
392 if ($table_is_view) {
393 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']){
394 $row_count_pre = '~';
395 $sum_row_count_pre = '~';
396 $show_superscript = PMA_showHint(PMA_sanitize(sprintf($strViewHasAtLeast, '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
398 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
399 // InnoDB table: we did not get an accurate row count
400 $row_count_pre = '~';
401 $sum_row_count_pre = '~';
402 $show_superscript = '';
405 $show_superscript = '';
408 <td
class="value"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
409 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
410 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
$strView : $each_table['ENGINE']); ?
></td
>
411 <?php
if (isset($collation)) { ?
>
412 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
416 <?php
if ($is_show_stats) { ?
>
418 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
419 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
420 <td
class="value"><?php
echo $overhead; ?
></td
>
422 <?php
} elseif ($table_is_view) { ?
>
423 <td
class="value">-</td
>
424 <td
><?php
echo $strView; ?
></td
>
426 <?php
if ($is_show_stats) { ?
>
427 <td
class="value">-</td
>
428 <td
class="value">-</td
>
431 <td colspan
="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
433 <?php
echo $strInUse; ?
></td
>
434 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
440 if ($is_show_stats) {
441 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
442 list($overhead_formatted, $overhead_unit) =
443 PMA_formatByteDown($overhead_size, 3, 1);
449 <th align
="center" nowrap
="nowrap">
451 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
452 // (we don't want negative numbers here) - rajk
453 if ($num_tables == 0)
454 $tableReductionCount = 0;
456 echo sprintf($strTables, PMA_formatNumber($num_tables - $tableReductionCount, 0));
459 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
460 <?php
echo $strSum; ?
></th
>
461 <th
class="value"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
463 if (!($cfg['PropertiesNumColumns'] > 1)) {
464 $default_engine = PMA_DBI_get_default_engine();
465 echo ' <th align="center">' . "\n"
467 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
468 // we got a case where $db_collation was empty
469 echo ' <th align="center">' . "\n";
470 if (! empty($db_collation)) {
472 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
478 if ($is_show_stats) {
480 <th
class="value"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
481 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
489 <div
class="clearfloat">
491 // Check all tables url
492 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
494 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
495 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
496 <a href
="<?php echo $checkall_url; ?>&checkall=1"
497 onclick
="if (markAllRows('tablesForm')) return false;">
498 <?php
echo $strCheckAll; ?
></a
>
500 <a href
="<?php echo $checkall_url; ?>"
501 onclick
="if (unMarkAllRows('tablesForm')) return false;">
502 <?php
echo $strUncheckAll; ?
></a
>
503 <?php
if ($overhead_check != '') { ?
>
505 <a href
="#" onclick
="unMarkAllRows('tablesForm');
506 <?php echo $overhead_check; ?> return false;">
507 <?php
echo $strCheckOverhead; ?
></a
>
510 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
512 echo ' <option value="' . $strWithChecked . '" selected="selected">'
513 . $strWithChecked . '</option>' . "\n";
514 echo ' <option value="' . $strEmpty . '" >'
515 . $strEmpty . '</option>' . "\n";
516 echo ' <option value="' . $strDrop . '" >'
517 . $strDrop . '</option>' . "\n";
518 echo ' <option value="' . $strPrintView . '" >'
519 . $strPrintView . '</option>' . "\n";
520 echo ' <option value="' . $strCheckTable . '" >'
521 . $strCheckTable . '</option>' . "\n";
522 echo ' <option value="' . $strOptimizeTable . '" >'
523 . $strOptimizeTable . '</option>' . "\n";
524 echo ' <option value="' . $strRepairTable . '" >'
525 . $strRepairTable . '</option>' . "\n";
526 echo ' <option value="' . $strAnalyzeTable . '" >'
527 . $strAnalyzeTable . '</option>' . "\n";
530 <script type
="text/javascript">
532 // Fake js to allow the use of the <noscript> tag
536 <input type
="submit" value
="<?php echo $strGo; ?>" />
538 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
542 // display again the table list navigator
543 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
549 require './libraries/db_routines.inc.php';
552 if (PMA_MYSQL_INT_VERSION
> 50100) {
553 require './libraries/db_events.inc.php';
557 * Work on the database
558 * redesigned 2004-05-08 by mkkeck
561 /* Printable view of a table */
563 echo '<a href="db_printview.php?' . $url_query . '">';
564 if ($cfg['PropertiesIconic']) {
565 echo '<img class="icon" src="' . $pmaThemeImage
566 .'b_print.png" width="16" height="16" alt="" />';
568 echo $strPrintView . '</a> ';
570 echo '<a href="./db_datadict.php?' . $url_query . '">';
571 if ($cfg['PropertiesIconic']) {
572 echo '<img class="icon" src="' . $pmaThemeImage
573 .'b_tblanalyse.png" width="16" height="16" alt="" />';
575 echo $strDataDict . '</a>';
578 if (empty($db_is_information_schema)) {
579 require './libraries/display_create_table.lib.php';
580 } // end if (Create Table dialog)
583 * Displays the footer
585 require_once './libraries/footer.inc.php';