2 /* vim: set expandtab sw=4 ts=4 sts=4: */
12 require_once './libraries/common.inc.php';
13 require_once './libraries/Table.class.php';
15 $GLOBALS['js_include'][] = 'mootools.js';
18 * Prepares the tables list if the user where not redirected to this script
19 * because there is no table in the database ($is_info is true)
21 if (empty($is_info)) {
22 // Drops/deletes/etc. multiple tables if required
23 if ((!empty($submit_mult) && isset($selected_tbl))
24 ||
isset($mult_btn)) {
25 $action = 'db_structure.php';
26 $err_url = 'db_structure.php?'. PMA_generate_common_url($db);
27 require './libraries/mult_submits.inc.php';
28 if (empty($message)) {
29 $message = PMA_Message
::success();
32 require './libraries/db_common.inc.php';
33 $url_query .= '&goto=db_structure.php';
35 // Gets the database structure
36 $sub_part = '_structure';
37 require './libraries/db_info.inc.php';
41 if ($num_tables == 0) {
42 echo '<p>' . $strNoTablesFound . '</p>' . "\n";
44 if (empty($db_is_information_schema)) {
45 require './libraries/display_create_table.lib.php';
46 } // end if (Create Table dialog)
51 require_once './libraries/footer.inc.php';
56 // 2. Shows table informations - staybyte - 11 June 2001
58 require_once './libraries/bookmark.lib.php';
60 require_once './libraries/mysql_charsets.lib.php';
61 $db_collation = PMA_getDbCollation($db);
65 * void PMA_TableHeader([bool $db_is_information_schema = false])
66 * display table header (<table><thead>...</thead><tbody>)
68 * @uses PMA_showHint()
69 * @uses $GLOBALS['cfg']['PropertiesNumColumns']
70 * @uses $GLOBALS['is_show_stats']
71 * @uses $GLOBALS['strTable']
72 * @uses $GLOBALS['strAction']
73 * @uses $GLOBALS['strRecords']
74 * @uses $GLOBALS['strApproximateCount']
75 * @uses $GLOBALS['strType']
76 * @uses $GLOBALS['strCollation']
77 * @uses $GLOBALS['strSize']
78 * @uses $GLOBALS['strOverhead']
79 * @uses $GLOBALS['structure_tbl_col_cnt']
80 * @param boolean $db_is_information_schema
82 function PMA_TableHeader($db_is_information_schema = false)
84 $cnt = 0; // Let's count the columns...
86 if ($db_is_information_schema) {
92 echo '<table class="data" style="float: left;">' . "\n"
94 .'<tr><td></td>' . "\n"
95 .' <th>' . $GLOBALS['strTable'] . '</th>' . "\n"
96 .' <th colspan="' . $action_colspan . '">' . "\n"
97 .' ' . $GLOBALS['strAction'] . "\n"
99 .' <th>' . $GLOBALS['strRecords']
100 .PMA_showHint(PMA_sanitize($GLOBALS['strApproximateCount'])) . "\n"
102 if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
103 echo ' <th>' . $GLOBALS['strType'] . '</th>' . "\n";
105 echo ' <th>' . $GLOBALS['strCollation'] . '</th>' . "\n";
108 if ($GLOBALS['is_show_stats']) {
109 echo ' <th>' . $GLOBALS['strSize'] . '</th>' . "\n"
110 . ' <th>' . $GLOBALS['strOverhead'] . '</th>' . "\n";
114 echo '</thead>' . "\n";
115 echo '<tbody>' . "\n";
116 $GLOBALS['structure_tbl_col_cnt'] = $cnt +
$action_colspan +
3;
117 } // end function PMA_TableHeader()
120 if (true == $cfg['PropertiesIconic']) {
121 $titles['Browse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
122 $titles['NoBrowse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
123 $titles['Search'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
124 $titles['NoSearch'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
125 $titles['Insert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
126 $titles['NoInsert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
127 $titles['Structure'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_props.png" alt="' . $strStructure . '" title="' . $strStructure . '" />';
128 $titles['Drop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
129 $titles['NoDrop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
130 $titles['Empty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
131 $titles['NoEmpty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
133 if ('both' === $cfg['PropertiesIconic']) {
134 $titles['Browse'] .= $strBrowse;
135 $titles['Search'] .= $strSearch;
136 $titles['NoBrowse'] .= $strBrowse;
137 $titles['NoSearch'] .= $strSearch;
138 $titles['Insert'] .= $strInsert;
139 $titles['NoInsert'] .= $strInsert;
140 $titles['Structure'] .= $strStructure;
141 $titles['Drop'] .= $strDrop;
142 $titles['NoDrop'] .= $strDrop;
143 $titles['Empty'] .= $strEmpty;
144 $titles['NoEmpty'] .= $strEmpty;
147 $titles['Browse'] = $strBrowse;
148 $titles['Search'] = $strSearch;
149 $titles['NoBrowse'] = $strBrowse;
150 $titles['NoSearch'] = $strSearch;
151 $titles['Insert'] = $strInsert;
152 $titles['NoInsert'] = $strInsert;
153 $titles['Structure'] = $strStructure;
154 $titles['Drop'] = $strDrop;
155 $titles['NoDrop'] = $strDrop;
156 $titles['Empty'] = $strEmpty;
157 $titles['NoEmpty'] = $strEmpty;
161 * Displays the tables list
164 $_url_params = array(
168 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
171 <form method
="post" action
="db_structure.php" name
="tablesForm" id
="tablesForm">
173 echo PMA_generate_common_hidden_inputs($db);
175 PMA_TableHeader($db_is_information_schema);
177 $i = $sum_entries = 0;
178 $sum_size = (double) 0;
179 $overhead_size = (double) 0;
180 $overhead_check = '';
181 $checked = !empty($checkall) ?
' checked="checked"' : '';
182 $num_columns = $cfg['PropertiesNumColumns'] > 1 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1 : 0;
186 $hidden_fields = array();
188 $sum_row_count_pre = '';
190 // added by rajk - for blobstreaming
191 $PMA_Config = $_SESSION['PMA_Config'];
193 if (!empty ($PMA_Config))
194 $session_bs_tables = $PMA_Config->get('BLOBSTREAMING_TABLES'); // list of blobstreaming tables
196 $tableReductionCount = 0; // the amount to reduce the table count by
198 foreach ($tables as $keyname => $each_table) {
199 if (isset($session_bs_tables))
201 // compare table name against blobstreaming tables
202 foreach ($session_bs_tables as $table_key=>$table_val)
203 // if the table is a blobstreaming table, reduce table count and skip outer foreach loop
204 if ($table_key == $keyname)
206 $tableReductionCount++
;
211 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
212 // statistics whatever is the table type
214 $table_is_view = false;
215 $table_encoded = urlencode($each_table['TABLE_NAME']);
216 // Sets parameters for links
217 $tbl_url_query = $url_query . '&table=' . $table_encoded;
219 switch ( $each_table['ENGINE']) {
220 // MyISAM, ISAM or Heap table: Row count, data size and index size
226 if ($is_show_stats) {
227 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
228 $sum_size +
= $tblsize;
229 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
230 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
231 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ?
1 : 0);
232 $overhead_size +
= $each_table['Data_free'];
237 // InnoDB table: Row count is not accurate but data and index
240 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
241 $each_table['COUNTED'] = true;
242 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
243 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
246 $each_table['COUNTED'] = false;
249 if ($is_show_stats) {
250 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
251 $sum_size +
= $tblsize;
252 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
254 //$display_rows = ' - ';
258 // Merge or BerkleyDB table: Only row count is accurate.
259 if ($is_show_stats) {
260 $formatted_size = ' - ';
264 // for a view, the ENGINE is null
267 // countRecords() takes care of $cfg['MaxExactCountViews']
268 $each_table['TABLE_ROWS'] = PMA_Table
::countRecords($db,
269 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
271 $table_is_view = true;
274 // Unknown table type.
275 if ($is_show_stats) {
276 $formatted_size = 'unknown';
280 $sum_entries +
= $each_table['TABLE_ROWS'];
282 if (isset($each_table['Collation'])) {
283 $collation = '<dfn title="'
284 . PMA_getCollationDescr($each_table['Collation']) . '">'
285 . $each_table['Collation'] . '</dfn>';
290 if ($is_show_stats) {
291 if (isset($formatted_overhead)) {
292 $overhead = '<a href="tbl_structure.php?'
293 . $tbl_url_query . '#showusage">' . $formatted_overhead
294 . ' ' . $overhead_unit . '</a>' . "\n";
295 unset($formatted_overhead);
297 "document.getElementById('checkbox_tbl_" . ($i +
1) . "').checked = true;";
303 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
304 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
305 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
306 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
307 ?
str_replace(' ', ' ', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
308 : str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME']));
313 if ($table_is_view) {
314 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $each_table['TABLE_NAME'] . '" />';
317 if ($each_table['TABLE_ROWS'] > 0) {
318 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&pos=0">' . $titles['Browse'] . '</a>';
319 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
321 $browse_table = $titles['NoBrowse'];
322 $search_table = $titles['NoSearch'];
325 if (! $db_is_information_schema) {
326 if (! empty($each_table['TABLE_ROWS'])) {
327 $empty_table = '<a href="sql.php?' . $tbl_url_query
329 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
331 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
332 . '" onclick="return confirmLink(this, \'TRUNCATE ';
333 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
335 $empty_table = $titles['NoEmpty'];
337 $drop_query = 'DROP '
338 . ($table_is_view ?
'VIEW' : 'TABLE')
339 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
340 $drop_message = sprintf(
341 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
342 str_replace(' ', ' ', htmlspecialchars($each_table['TABLE_NAME'])));
345 if ($num_columns > 0 && $num_tables > $num_columns
346 && (($row_count %
$num_columns) == 0)) {
357 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
359 <input type
="checkbox" name
="selected_tbl[]"
360 value
="<?php echo $each_table['TABLE_NAME']; ?>"
361 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
362 <th
><label
for="checkbox_tbl_<?php echo $i; ?>"
363 title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></label
>
365 <td align
="center"><?php
echo $browse_table; ?
></td
>
367 <a href
="tbl_structure.php?<?php echo $tbl_url_query; ?>">
368 <?php
echo $titles['Structure']; ?
></a
></td
>
369 <td align
="center"><?php
echo $search_table; ?
></td
>
370 <?php
if (! $db_is_information_schema) { ?
>
372 <a href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
373 <?php
echo $titles['Insert']; ?
></a
></td
>
374 <td align
="center"><?php
echo $empty_table; ?
></td
>
376 <a href
="sql.php?<?php echo $tbl_url_query;
377 ?>&reload=1&purge=1&sql_query=<?php
378 echo urlencode($drop_query); ?>&zero_rows=<?php
379 echo urlencode($drop_message); ?>"
380 onclick
="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
381 <?php
echo $titles['Drop']; ?
></a
></td
>
382 <?php
} // end if (! $db_is_information_schema)
384 // there is a null value in the ENGINE
385 // - when the table needs to be repaired, or
386 // - when it's a view
387 // so ensure that we'll display "in use" below for a table
388 // that needs to be repaired
389 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null ||
$table_is_view)) {
390 if ($table_is_view) {
391 $row_count_pre = '~';
392 $sum_row_count_pre = '~';
393 $show_superscript = PMA_showHint(PMA_sanitize(sprintf($strViewHasAtLeast, '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
394 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
395 // InnoDB table: we did not get an accurate row count
396 $row_count_pre = '~';
397 $sum_row_count_pre = '~';
398 $show_superscript = '';
401 $show_superscript = '';
404 <td
class="value"><?php
echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?
></td
>
405 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
406 <td nowrap
="nowrap"><?php
echo ($table_is_view ?
$strView : $each_table['ENGINE']); ?
></td
>
407 <?php
if (isset($collation)) { ?
>
408 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
412 <?php
if ($is_show_stats) { ?
>
414 href
="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
415 ><?php
echo $formatted_size . ' ' . $unit; ?
></a
></td
>
416 <td
class="value"><?php
echo $overhead; ?
></td
>
418 <?php
} elseif ($table_is_view) { ?
>
419 <td
class="value">-</td
>
420 <td
><?php
echo $strView; ?
></td
>
422 <?php
if ($is_show_stats) { ?
>
423 <td
class="value">-</td
>
424 <td
class="value">-</td
>
427 <td colspan
="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
429 <?php
echo $strInUse; ?
></td
>
430 <?php
} // end if (isset($each_table['TABLE_ROWS'])) else ?>
436 if ($is_show_stats) {
437 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
438 list($overhead_formatted, $overhead_unit) =
439 PMA_formatByteDown($overhead_size, 3, 1);
445 <th align
="center" nowrap
="nowrap">
447 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
448 // (we don't want negative numbers here) - rajk
449 if ($num_tables == 0)
450 $tableReductionCount = 0;
452 echo sprintf($strTables, PMA_formatNumber($num_tables - $tableReductionCount, 0));
455 <th colspan
="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align
="center">
456 <?php
echo $strSum; ?
></th
>
457 <th
class="value"><?php
echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?
></th
>
459 if (!($cfg['PropertiesNumColumns'] > 1)) {
460 $default_engine = PMA_DBI_get_default_engine();
461 echo ' <th align="center">' . "\n"
463 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
464 // we got a case where $db_collation was empty
465 echo ' <th align="center">' . "\n";
466 if (! empty($db_collation)) {
468 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
474 if ($is_show_stats) {
476 <th
class="value"><?php
echo $sum_formatted . ' ' . $unit; ?
></th
>
477 <th
class="value"><?php
echo $overhead_formatted . ' ' . $overhead_unit; ?
></th
>
485 <div
class="clearfloat">
487 // Check all tables url
488 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
490 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
491 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
492 <a href
="<?php echo $checkall_url; ?>&checkall=1"
493 onclick
="if (markAllRows('tablesForm')) return false;">
494 <?php
echo $strCheckAll; ?
></a
>
496 <a href
="<?php echo $checkall_url; ?>"
497 onclick
="if (unMarkAllRows('tablesForm')) return false;">
498 <?php
echo $strUncheckAll; ?
></a
>
499 <?php
if ($overhead_check != '') { ?
>
501 <a href
="#" onclick
="unMarkAllRows('tablesForm');
502 <?php echo $overhead_check; ?> return false;">
503 <?php
echo $strCheckOverhead; ?
></a
>
506 <select name
="submit_mult" onchange
="this.form.submit();" style
="margin: 0 3em 0 3em;">
508 echo ' <option value="' . $strWithChecked . '" selected="selected">'
509 . $strWithChecked . '</option>' . "\n";
510 echo ' <option value="' . $strEmpty . '" >'
511 . $strEmpty . '</option>' . "\n";
512 echo ' <option value="' . $strDrop . '" >'
513 . $strDrop . '</option>' . "\n";
514 echo ' <option value="' . $strPrintView . '" >'
515 . $strPrintView . '</option>' . "\n";
516 echo ' <option value="' . $strCheckTable . '" >'
517 . $strCheckTable . '</option>' . "\n";
518 echo ' <option value="' . $strOptimizeTable . '" >'
519 . $strOptimizeTable . '</option>' . "\n";
520 echo ' <option value="' . $strRepairTable . '" >'
521 . $strRepairTable . '</option>' . "\n";
522 echo ' <option value="' . $strAnalyzeTable . '" >'
523 . $strAnalyzeTable . '</option>' . "\n";
526 <script type
="text/javascript">
528 // Fake js to allow the use of the <noscript> tag
532 <input type
="submit" value
="<?php echo $strGo; ?>" />
534 <?php
echo implode("\n", $hidden_fields) . "\n"; ?
>
538 // display again the table list navigator
539 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
545 require './libraries/db_routines.inc.php';
548 if (PMA_MYSQL_INT_VERSION
> 50100) {
549 require './libraries/db_events.inc.php';
553 * Work on the database
554 * redesigned 2004-05-08 by mkkeck
557 /* Printable view of a table */
559 echo '<a href="db_printview.php?' . $url_query . '">';
560 if ($cfg['PropertiesIconic']) {
561 echo '<img class="icon" src="' . $pmaThemeImage
562 .'b_print.png" width="16" height="16" alt="" />';
564 echo $strPrintView . '</a> ';
566 echo '<a href="./db_datadict.php?' . $url_query . '">';
567 if ($cfg['PropertiesIconic']) {
568 echo '<img class="icon" src="' . $pmaThemeImage
569 .'b_tblanalyse.png" width="16" height="16" alt="" />';
571 echo $strDataDict . '</a>';
574 if (empty($db_is_information_schema)) {
575 require './libraries/display_create_table.lib.php';
576 } // end if (Create Table dialog)
579 * Displays the footer
581 require_once './libraries/footer.inc.php';