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;
218 switch ( $each_table['ENGINE']) {
219 // MyISAM, ISAM or Heap table: Row count, data size and index size
225 if ($is_show_stats) {
226 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
227 $sum_size +
= $tblsize;
228 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
229 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
230 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
231 $overhead_size +
= $each_table['Data_free'];
236 // InnoDB table: Row count is not accurate but data and index
239 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
240 $each_table['COUNTED'] = true;
241 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
242 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
245 $each_table['COUNTED'] = false;
248 if ($is_show_stats) {
249 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
250 $sum_size +
= $tblsize;
251 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
253 //$display_rows = ' - ';
257 // Merge or BerkleyDB table: Only row count is accurate.
258 if ($is_show_stats) {
259 $formatted_size = ' - ';
263 // for a view, the ENGINE is null
266 // countRecords() takes care of $cfg['MaxExactCountViews']
267 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
268 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
270 $table_is_view = true;
273 // Unknown table type.
274 if ($is_show_stats) {
275 $formatted_size = 'unknown';
279 $sum_entries +
= $each_table['TABLE_ROWS'];
281 if (isset($each_table['Collation'])) {
282 $collation = '<dfn title="'
283 . PMA_getCollationDescr($each_table['Collation']) . '">'
284 . $each_table['Collation'] . '</dfn>';
289 if ($is_show_stats) {
290 if (isset($formatted_overhead)) {
291 $overhead = '<a href="tbl_structure.php?'
292 . $tbl_url_query . '#showusage">' . $formatted_overhead
293 . ' ' . $overhead_unit . '</a>' . "\n";
294 unset($formatted_overhead);
296 "document.getElementById('checkbox_tbl_" . ($i +
1) . "').checked = true;";
302 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
303 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
304 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
305 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
306 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
307 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
312 if ($table_is_view) {
313 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $each_table['TABLE_NAME'] . '" />';
316 if ($each_table['TABLE_ROWS'] > 0) {
317 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
318 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
320 $browse_table = $titles['NoBrowse'];
321 $search_table = $titles['NoSearch'];
324 if (! $db_is_information_schema) {
325 if (! empty($each_table['TABLE_ROWS'])) {
326 $empty_table = '<a href="sql.php?' . $tbl_url_query
328 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
330 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
331 . '" onclick="return confirmLink(this, \'TRUNCATE ';
332 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
334 $empty_table = $titles['NoEmpty'];
336 $drop_query = 'DROP '
337 . ($table_is_view ?
'VIEW' : 'TABLE')
338 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
339 $drop_message = sprintf(
340 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
341 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME'])));
344 if ($num_columns > 0 && $num_tables > $num_columns
345 && (($row_count %
$num_columns) == 0)) {
356 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
358 <input type
="checkbox" name
="selected_tbl[]"
359 value
="<?php echo $each_table['TABLE_NAME']; ?>"
360 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
361 <th
><label
for="checkbox_tbl_<?php echo $i; ?>"
362 title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></label
>
364 <td align
="center"><?php
echo $browse_table; ?
></td
>
366 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
367 <?php
echo $titles['Structure']; ?
></a
></td
>
368 <td align
="center"><?php
echo $search_table; ?
></td
>
369 <?php
if (! $db_is_information_schema) { ?
>
371 <a href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
372 <?php
echo $titles['Insert']; ?
></a
></td
>
373 <td align
="center"><?php
echo $empty_table; ?
></td
>
375 <a href
="sql.php?<?php echo $tbl_url_query;
376 ?>&reload=1&purge=1&sql_query=<?php
377 echo urlencode($drop_query); ?>&zero_rows=<?php
378 echo urlencode($drop_message); ?>"
379 onclick
="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
380 <?php
echo $titles['Drop']; ?
></a
></td
>
381 <?php
} // end if (! $db_is_information_schema)
383 // there is a null value in the ENGINE
384 // - when the table needs to be repaired, or
385 // - when it's a view
386 // so ensure that we'll display "in use" below for a table
387 // that needs to be repaired
388 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
389 if ($table_is_view) {
390 $row_count_pre = '~';
391 $sum_row_count_pre = '~';
392 $show_superscript = PMA_showHint(PMA_sanitize(sprintf($strViewHasAtLeast, '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
393 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
394 // InnoDB table: we did not get an accurate row count
395 $row_count_pre = '~';
396 $sum_row_count_pre = '~';
397 $show_superscript = '';
400 $show_superscript = '';
403 <td
class="value"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
404 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
405 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
$strView : $each_table['ENGINE']); ?
></td
>
406 <?php
if (isset($collation)) { ?
>
407 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
411 <?php
if ($is_show_stats) { ?
>
413 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
414 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
415 <td
class="value"><?php
echo $overhead; ?
></td
>
417 <?php
} elseif ($table_is_view) { ?
>
418 <td
class="value">-</td
>
419 <td
><?php
echo $strView; ?
></td
>
421 <?php
if ($is_show_stats) { ?
>
422 <td
class="value">-</td
>
423 <td
class="value">-</td
>
426 <td colspan
="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
428 <?php
echo $strInUse; ?
></td
>
429 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
435 if ($is_show_stats) {
436 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
437 list($overhead_formatted, $overhead_unit) =
438 PMA_formatByteDown($overhead_size, 3, 1);
444 <th align
="center" nowrap
="nowrap">
446 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
447 // (we don't want negative numbers here) - rajk
448 if ($num_tables == 0)
449 $tableReductionCount = 0;
451 echo sprintf($strTables, PMA_formatNumber($num_tables - $tableReductionCount, 0));
454 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
455 <?php
echo $strSum; ?
></th
>
456 <th
class="value"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
458 if (!($cfg['PropertiesNumColumns'] > 1)) {
459 $default_engine = PMA_DBI_get_default_engine();
460 echo ' <th align="center">' . "\n"
462 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
463 // we got a case where $db_collation was empty
464 echo ' <th align="center">' . "\n";
465 if (! empty($db_collation)) {
467 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
473 if ($is_show_stats) {
475 <th
class="value"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
476 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
484 <div
class="clearfloat">
486 // Check all tables url
487 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
489 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
490 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
491 <a href
="<?php echo $checkall_url; ?>&checkall=1"
492 onclick
="if (markAllRows('tablesForm')) return false;">
493 <?php
echo $strCheckAll; ?
></a
>
495 <a href
="<?php echo $checkall_url; ?>"
496 onclick
="if (unMarkAllRows('tablesForm')) return false;">
497 <?php
echo $strUncheckAll; ?
></a
>
498 <?php
if ($overhead_check != '') { ?
>
500 <a href
="#" onclick
="unMarkAllRows('tablesForm');
501 <?php echo $overhead_check; ?> return false;">
502 <?php
echo $strCheckOverhead; ?
></a
>
505 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
507 echo ' <option value="' . $strWithChecked . '" selected="selected">'
508 . $strWithChecked . '</option>' . "\n";
509 echo ' <option value="' . $strEmpty . '" >'
510 . $strEmpty . '</option>' . "\n";
511 echo ' <option value="' . $strDrop . '" >'
512 . $strDrop . '</option>' . "\n";
513 echo ' <option value="' . $strPrintView . '" >'
514 . $strPrintView . '</option>' . "\n";
515 echo ' <option value="' . $strCheckTable . '" >'
516 . $strCheckTable . '</option>' . "\n";
517 echo ' <option value="' . $strOptimizeTable . '" >'
518 . $strOptimizeTable . '</option>' . "\n";
519 echo ' <option value="' . $strRepairTable . '" >'
520 . $strRepairTable . '</option>' . "\n";
521 echo ' <option value="' . $strAnalyzeTable . '" >'
522 . $strAnalyzeTable . '</option>' . "\n";
525 <script type
="text/javascript">
527 // Fake js to allow the use of the <noscript> tag
531 <input type
="submit" value
="<?php echo $strGo; ?>" />
533 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
537 // display again the table list navigator
538 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
544 require './libraries/db_routines.inc.php';
547 if (PMA_MYSQL_INT_VERSION
> 50100) {
548 require './libraries/db_events.inc.php';
552 * Work on the database
553 * redesigned 2004-05-08 by mkkeck
556 /* Printable view of a table */
558 echo '<a href="db_printview.php?' . $url_query . '">';
559 if ($cfg['PropertiesIconic']) {
560 echo '<img class="icon" src="' . $pmaThemeImage
561 .'b_print.png" width="16" height="16" alt="" />';
563 echo $strPrintView . '</a> ';
565 echo '<a href="./db_datadict.php?' . $url_query . '">';
566 if ($cfg['PropertiesIconic']) {
567 echo '<img class="icon" src="' . $pmaThemeImage
568 .'b_tblanalyse.png" width="16" height="16" alt="" />';
570 echo $strDataDict . '</a>';
573 if (empty($db_is_information_schema)) {
574 require './libraries/display_create_table.lib.php';
575 } // end if (Create Table dialog)
578 * Displays the footer
580 require_once './libraries/footer.inc.php';