undefined message in some situations, for example when doing a logout after an import
[phpmyadmin/madhuracj.git] / db_structure.php
blobb53cc92a9d3994877e63d79db5372c20f7e8b15a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/common.inc.php';
13 require_once './libraries/Table.class.php';
15 $GLOBALS['js_include'][] = 'mootools.js';
17 /**
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);
28 // see bug #2794840; in this case, code path is:
29 // db_structure.php -> libraries/mult_submits.inc.php -> sql.php
30 // -> db_structure.php and if we got an error on the multi submit,
31 // we must display it here and not call again mult_submits.inc.php
32 if (! isset($error) || FALSE === $error) {
33 require './libraries/mult_submits.inc.php';
35 if (empty($message)) {
36 $message = PMA_Message::success();
39 require './libraries/db_common.inc.php';
40 $url_query .= '&amp;goto=db_structure.php';
42 // Gets the database structure
43 $sub_part = '_structure';
44 require './libraries/db_info.inc.php';
47 // 1. No tables
48 if ($num_tables == 0) {
49 echo '<p>' . $strNoTablesFound . '</p>' . "\n";
51 if (empty($db_is_information_schema)) {
52 require './libraries/display_create_table.lib.php';
53 } // end if (Create Table dialog)
55 /**
56 * Displays the footer
58 require_once './libraries/footer.inc.php';
59 exit;
62 // else
63 // 2. Shows table informations - staybyte - 11 June 2001
65 require_once './libraries/bookmark.lib.php';
67 require_once './libraries/mysql_charsets.lib.php';
68 $db_collation = PMA_getDbCollation($db);
70 // in a separate file to avoid redeclaration of functions in some code paths
71 require_once './libraries/db_structure.lib.php';
73 $titles = array();
74 if (true == $cfg['PropertiesIconic']) {
75 $titles['Browse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
76 $titles['NoBrowse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
77 $titles['Search'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
78 $titles['NoSearch'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
79 $titles['Insert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
80 $titles['NoInsert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
81 $titles['Structure'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_props.png" alt="' . $strStructure . '" title="' . $strStructure . '" />';
82 $titles['Drop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
83 $titles['NoDrop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
84 $titles['Empty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
85 $titles['NoEmpty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
87 if ('both' === $cfg['PropertiesIconic']) {
88 $titles['Browse'] .= $strBrowse;
89 $titles['Search'] .= $strSearch;
90 $titles['NoBrowse'] .= $strBrowse;
91 $titles['NoSearch'] .= $strSearch;
92 $titles['Insert'] .= $strInsert;
93 $titles['NoInsert'] .= $strInsert;
94 $titles['Structure'] .= $strStructure;
95 $titles['Drop'] .= $strDrop;
96 $titles['NoDrop'] .= $strDrop;
97 $titles['Empty'] .= $strEmpty;
98 $titles['NoEmpty'] .= $strEmpty;
100 } else {
101 $titles['Browse'] = $strBrowse;
102 $titles['Search'] = $strSearch;
103 $titles['NoBrowse'] = $strBrowse;
104 $titles['NoSearch'] = $strSearch;
105 $titles['Insert'] = $strInsert;
106 $titles['NoInsert'] = $strInsert;
107 $titles['Structure'] = $strStructure;
108 $titles['Drop'] = $strDrop;
109 $titles['NoDrop'] = $strDrop;
110 $titles['Empty'] = $strEmpty;
111 $titles['NoEmpty'] = $strEmpty;
115 * Displays the tables list
117 $_url_params = array(
118 'pos' => $pos,
119 'db' => $db);
121 // Add the sort options if they exists
122 if (isset($_REQUEST['sort'])) {
123 $_url_params['sort'] = $_REQUEST['sort'];
126 if (isset($_REQUEST['sort_order'])) {
127 $_url_params['sort_order'] = $_REQUEST['sort_order'];
130 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
133 <form method="post" action="db_structure.php" name="tablesForm" id="tablesForm">
134 <?php
135 echo PMA_generate_common_hidden_inputs($db);
137 PMA_TableHeader($db_is_information_schema);
139 $i = $sum_entries = 0;
140 $sum_size = (double) 0;
141 $overhead_size = (double) 0;
142 $overhead_check = '';
143 $checked = !empty($checkall) ? ' checked="checked"' : '';
144 $num_columns = $cfg['PropertiesNumColumns'] > 1 ? ceil($num_tables / $cfg['PropertiesNumColumns']) + 1 : 0;
145 $row_count = 0;
148 $hidden_fields = array();
149 $odd_row = true;
150 $sum_row_count_pre = '';
152 // added by rajk - for blobstreaming
153 $PMA_Config = $_SESSION['PMA_Config'];
155 if (!empty($PMA_Config))
156 $session_bs_tables = $PMA_Config->get('BLOBSTREAMING_TABLES'); // list of blobstreaming tables
158 $tableReductionCount = 0; // the amount to reduce the table count by
160 foreach ($tables as $keyname => $each_table) {
161 if (isset($session_bs_tables))
163 // compare table name against blobstreaming tables
164 foreach ($session_bs_tables as $table_key=>$table_val)
165 // if the table is a blobstreaming table, reduce table count and skip outer foreach loop
166 if ($table_key == $keyname)
168 $tableReductionCount++;
169 continue 2;
173 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
174 // statistics whatever is the table type
176 $table_is_view = false;
177 $table_encoded = urlencode($each_table['TABLE_NAME']);
178 // Sets parameters for links
179 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
180 // do not list the previous table's size info for a view
181 $formatted_size = '-';
182 $unit = '';
184 switch ( $each_table['ENGINE']) {
185 // MyISAM, ISAM or Heap table: Row count, data size and index size
186 // are accurate.
187 case 'MyISAM' :
188 case 'ISAM' :
189 case 'HEAP' :
190 case 'MEMORY' :
191 if ($db_is_information_schema) {
192 $each_table['Rows'] = PMA_Table::countRecords($db,
193 $each_table['Name'], $return = true);
196 if ($is_show_stats) {
197 $tblsize = doubleval($each_table['Data_length']) + doubleval($each_table['Index_length']);
198 $sum_size += $tblsize;
199 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
200 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
201 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ? 1 : 0);
202 $overhead_size += $each_table['Data_free'];
205 break;
206 case 'InnoDB' :
207 // InnoDB table: Row count is not accurate but data and index
208 // sizes are.
210 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
211 $each_table['COUNTED'] = true;
212 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
213 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
214 $is_view = false);
215 } else {
216 $each_table['COUNTED'] = false;
219 if ($is_show_stats) {
220 $tblsize = $each_table['Data_length'] + $each_table['Index_length'];
221 $sum_size += $tblsize;
222 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
224 //$display_rows = ' - ';
225 break;
226 case 'MRG_MyISAM' :
227 case 'BerkeleyDB' :
228 // Merge or BerkleyDB table: Only row count is accurate.
229 if ($is_show_stats) {
230 $formatted_size = ' - ';
231 $unit = '';
233 break;
234 // for a view, the ENGINE is null
235 case null :
236 case 'SYSTEM VIEW' :
237 // countRecords() takes care of $cfg['MaxExactCountViews']
238 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
239 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
240 $is_view = true);
241 $table_is_view = true;
242 break;
243 default :
244 // Unknown table type.
245 if ($is_show_stats) {
246 $formatted_size = 'unknown';
247 $unit = '';
249 } // end switch
250 $sum_entries += $each_table['TABLE_ROWS'];
252 if (isset($each_table['Collation'])) {
253 $collation = '<dfn title="'
254 . PMA_getCollationDescr($each_table['Collation']) . '">'
255 . $each_table['Collation'] . '</dfn>';
256 } else {
257 $collation = '---';
260 if ($is_show_stats) {
261 if (isset($formatted_overhead)) {
262 $overhead = '<a href="tbl_structure.php?'
263 . $tbl_url_query . '#showusage">' . $formatted_overhead
264 . ' ' . $overhead_unit . '</a>' . "\n";
265 unset($formatted_overhead);
266 $overhead_check .=
267 "document.getElementById('checkbox_tbl_" . ($i + 1) . "').checked = true;";
268 } else {
269 $overhead = '-';
271 } // end if
273 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
274 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
275 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
276 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
277 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
278 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
280 $i++;
282 $row_count++;
283 if ($table_is_view) {
284 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $each_table['TABLE_NAME'] . '" />';
287 if ($each_table['TABLE_ROWS'] > 0) {
288 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&amp;pos=0">' . $titles['Browse'] . '</a>';
289 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
290 } else {
291 $browse_table = $titles['NoBrowse'];
292 $search_table = $titles['NoSearch'];
295 if (! $db_is_information_schema) {
296 if (! empty($each_table['TABLE_ROWS'])) {
297 $empty_table = '<a href="sql.php?' . $tbl_url_query
298 . '&amp;sql_query=';
299 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
300 . '&amp;zero_rows='
301 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
302 . '" onclick="return confirmLink(this, \'TRUNCATE ';
303 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
304 } else {
305 $empty_table = $titles['NoEmpty'];
307 $drop_query = 'DROP '
308 . ($table_is_view ? 'VIEW' : 'TABLE')
309 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
310 $drop_message = sprintf(
311 $table_is_view ? $strViewHasBeenDropped : $strTableHasBeenDropped,
312 str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME'])));
315 if ($num_columns > 0 && $num_tables > $num_columns
316 && (($row_count % $num_columns) == 0)) {
317 $row_count = 1;
318 $odd_row = true;
320 </tr>
321 </tbody>
322 </table>
323 <?php
324 PMA_TableHeader();
327 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
328 <td align="center">
329 <input type="checkbox" name="selected_tbl[]"
330 value="<?php echo $each_table['TABLE_NAME']; ?>"
331 id="checkbox_tbl_<?php echo $i; ?>"<?php echo $checked; ?> /></td>
332 <th><label for="checkbox_tbl_<?php echo $i; ?>"
333 title="<?php echo $alias; ?>"><?php echo $truename; ?></label>
334 </th>
335 <td align="center"><?php echo $browse_table; ?></td>
336 <td align="center">
337 <a href="tbl_structure.php?<?php echo $tbl_url_query; ?>">
338 <?php echo $titles['Structure']; ?></a></td>
339 <td align="center"><?php echo $search_table; ?></td>
340 <?php if (! $db_is_information_schema) { ?>
341 <td align="center">
342 <a href="tbl_change.php?<?php echo $tbl_url_query; ?>">
343 <?php echo $titles['Insert']; ?></a></td>
344 <td align="center"><?php echo $empty_table; ?></td>
345 <td align="center">
346 <a href="sql.php?<?php echo $tbl_url_query;
347 ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php
348 echo urlencode($drop_query); ?>&amp;zero_rows=<?php
349 echo urlencode($drop_message); ?>"
350 onclick="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
351 <?php echo $titles['Drop']; ?></a></td>
352 <?php } // end if (! $db_is_information_schema)
354 // there is a null value in the ENGINE
355 // - when the table needs to be repaired, or
356 // - when it's a view
357 // so ensure that we'll display "in use" below for a table
358 // that needs to be repaired
359 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null || $table_is_view)) {
360 if ($table_is_view) {
361 if ($each_table['TABLE_ROWS'] >= $GLOBALS['cfg']['MaxExactCountViews']){
362 $row_count_pre = '~';
363 $sum_row_count_pre = '~';
364 $show_superscript = PMA_showHint(PMA_sanitize(sprintf($strViewHasAtLeast, '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
366 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
367 // InnoDB table: we did not get an accurate row count
368 $row_count_pre = '~';
369 $sum_row_count_pre = '~';
370 $show_superscript = '';
371 } else {
372 $row_count_pre = '';
373 $show_superscript = '';
376 <td class="value"><?php echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?></td>
377 <?php if (!($cfg['PropertiesNumColumns'] > 1)) { ?>
378 <td nowrap="nowrap"><?php echo ($table_is_view ? $strView : $each_table['ENGINE']); ?></td>
379 <?php if (isset($collation)) { ?>
380 <td nowrap="nowrap"><?php echo $collation ?></td>
381 <?php } ?>
382 <?php } ?>
384 <?php if ($is_show_stats) { ?>
385 <td class="value"><a
386 href="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
387 ><?php echo $formatted_size . ' ' . $unit; ?></a></td>
388 <td class="value"><?php echo $overhead; ?></td>
389 <?php } // end if ?>
390 <?php } elseif ($table_is_view) { ?>
391 <td class="value">-</td>
392 <td><?php echo $strView; ?></td>
393 <td>---</td>
394 <?php if ($is_show_stats) { ?>
395 <td class="value">-</td>
396 <td class="value">-</td>
397 <?php } ?>
398 <?php } else { ?>
399 <td colspan="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
400 align="center">
401 <?php echo $strInUse; ?></td>
402 <?php } // end if (isset($each_table['TABLE_ROWS'])) else ?>
403 </tr>
404 <?php
405 } // end foreach
407 // Show Summary
408 if ($is_show_stats) {
409 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
410 list($overhead_formatted, $overhead_unit) =
411 PMA_formatByteDown($overhead_size, 3, 1);
414 </tbody>
415 <tbody>
416 <tr><th></th>
417 <th align="center" nowrap="nowrap">
418 <?php
419 // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
420 // (we don't want negative numbers here) - rajk
421 if ($num_tables == 0)
422 $tableReductionCount = 0;
424 echo sprintf($strTables, PMA_formatNumber($num_tables - $tableReductionCount, 0));
426 </th>
427 <th colspan="<?php echo ($db_is_information_schema ? 3 : 6) ?>" align="center">
428 <?php echo $strSum; ?></th>
429 <th class="value"><?php echo $sum_row_count_pre . PMA_formatNumber($sum_entries, 0); ?></th>
430 <?php
431 if (!($cfg['PropertiesNumColumns'] > 1)) {
432 $default_engine = PMA_DBI_get_default_engine();
433 echo ' <th align="center">' . "\n"
434 . ' <dfn title="'
435 . sprintf($strDefaultEngine, $default_engine) . '">' .$default_engine . '</dfn></th>' . "\n";
436 // we got a case where $db_collation was empty
437 echo ' <th align="center">' . "\n";
438 if (! empty($db_collation)) {
439 echo ' <dfn title="'
440 . PMA_getCollationDescr($db_collation) . ' (' . $strDefault . ')">' . $db_collation
441 . '</dfn>';
443 echo '</th>';
446 if ($is_show_stats) {
448 <th class="value"><?php echo $sum_formatted . ' ' . $unit; ?></th>
449 <th class="value"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
450 <?php
453 </tr>
454 </tbody>
455 </table>
457 <div class="clearfloat">
458 <?php
459 // Check all tables url
460 $checkall_url = 'db_structure.php?' . PMA_generate_common_url($db);
462 <img class="selectallarrow" src="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
463 width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
464 <a href="<?php echo $checkall_url; ?>&amp;checkall=1"
465 onclick="if (markAllRows('tablesForm')) return false;">
466 <?php echo $strCheckAll; ?></a>
468 <a href="<?php echo $checkall_url; ?>"
469 onclick="if (unMarkAllRows('tablesForm')) return false;">
470 <?php echo $strUncheckAll; ?></a>
471 <?php if ($overhead_check != '') { ?>
473 <a href="#" onclick="unMarkAllRows('tablesForm');
474 <?php echo $overhead_check; ?> return false;">
475 <?php echo $strCheckOverhead; ?></a>
476 <?php } ?>
478 <select name="submit_mult" onchange="this.form.submit();" style="margin: 0 3em 0 3em;">
479 <?php
480 echo ' <option value="' . $strWithChecked . '" selected="selected">'
481 . $strWithChecked . '</option>' . "\n";
482 echo ' <option value="' . $strEmpty . '" >'
483 . $strEmpty . '</option>' . "\n";
484 echo ' <option value="' . $strDrop . '" >'
485 . $strDrop . '</option>' . "\n";
486 echo ' <option value="' . $strPrintView . '" >'
487 . $strPrintView . '</option>' . "\n";
488 echo ' <option value="' . $strCheckTable . '" >'
489 . $strCheckTable . '</option>' . "\n";
490 echo ' <option value="' . $strOptimizeTable . '" >'
491 . $strOptimizeTable . '</option>' . "\n";
492 echo ' <option value="' . $strRepairTable . '" >'
493 . $strRepairTable . '</option>' . "\n";
494 echo ' <option value="' . $strAnalyzeTable . '" >'
495 . $strAnalyzeTable . '</option>' . "\n";
496 echo ' <option value="' . $strExport . '" >'
497 . $strExport . '</option>' . "\n";
499 </select>
500 <script type="text/javascript">
501 <!--
502 // Fake js to allow the use of the <noscript> tag
503 //-->
504 </script>
505 <noscript>
506 <input type="submit" value="<?php echo $strGo; ?>" />
507 </noscript>
508 <?php echo implode("\n", $hidden_fields) . "\n"; ?>
509 </div>
510 </form>
511 <?php
512 // display again the table list navigator
513 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
515 <hr />
517 <?php
518 // Routines
519 require './libraries/db_routines.inc.php';
521 // Events
522 if (PMA_MYSQL_INT_VERSION > 50100) {
523 require './libraries/db_events.inc.php';
527 * Work on the database
528 * redesigned 2004-05-08 by mkkeck
530 /* DATABASE WORK */
531 /* Printable view of a table */
532 echo '<p>';
533 echo '<a href="db_printview.php?' . $url_query . '">';
534 if ($cfg['PropertiesIconic']) {
535 echo '<img class="icon" src="' . $pmaThemeImage
536 .'b_print.png" width="16" height="16" alt="" />';
538 echo $strPrintView . '</a> ';
540 echo '<a href="./db_datadict.php?' . $url_query . '">';
541 if ($cfg['PropertiesIconic']) {
542 echo '<img class="icon" src="' . $pmaThemeImage
543 .'b_tblanalyse.png" width="16" height="16" alt="" />';
545 echo $strDataDict . '</a>';
546 echo '</p>';
548 if (empty($db_is_information_schema)) {
549 require './libraries/display_create_table.lib.php';
550 } // end if (Create Table dialog)
553 * Displays the footer
555 require_once './libraries/footer.inc.php';