unneeded deactivated code
[phpmyadmin/crack.git] / db_structure.php
blob0422ebb3c52d7676bca941d43f06a8e901e2d6e8
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
11 require_once './libraries/common.inc.php';
12 require_once './libraries/Table.class.php';
14 $GLOBALS['js_include'][] = 'mootools.js';
16 /**
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 .= '&amp;goto=db_structure.php';
34 // Gets the database structure
35 $sub_part = '_structure';
36 require './libraries/db_info.inc.php';
39 // 1. No tables
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)
47 /**
48 * Displays the footer
50 require_once './libraries/footer.inc.php';
51 exit;
54 // else
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);
62 // Display function
63 /**
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) {
86 $action_colspan = 3;
87 } else {
88 $action_colspan = 6;
91 echo '<table class="data" style="float: left;">' . "\n"
92 .'<thead>' . "\n"
93 .'<tr><td></td>' . "\n"
94 .' <th>' . $GLOBALS['strTable'] . '</th>' . "\n"
95 .' <th colspan="' . $action_colspan . '">' . "\n"
96 .' ' . $GLOBALS['strAction'] . "\n"
97 .' </th>'
98 .' <th>' . $GLOBALS['strRecords']
99 .PMA_showHint($GLOBALS['strApproximateCount']) . "\n"
100 .' </th>' . "\n";
101 if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
102 echo ' <th>' . $GLOBALS['strType'] . '</th>' . "\n";
103 $cnt++;
104 echo ' <th>' . $GLOBALS['strCollation'] . '</th>' . "\n";
105 $cnt++;
107 if ($GLOBALS['is_show_stats']) {
108 echo ' <th>' . $GLOBALS['strSize'] . '</th>' . "\n"
109 . ' <th>' . $GLOBALS['strOverhead'] . '</th>' . "\n";
110 $cnt += 2;
112 echo '</tr>' . "\n";
113 echo '</thead>' . "\n";
114 echo '<tbody>' . "\n";
115 $GLOBALS['structure_tbl_col_cnt'] = $cnt + $action_colspan + 3;
116 } // end function PMA_TableHeader()
118 $titles = array();
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;
145 } else {
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(
164 'pos' => $pos,
165 'db' => $db);
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">
171 <?php
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;
182 $row_count = 0;
185 $hidden_fields = array();
186 $odd_row = true;
187 $sum_row_count_pre = '';
189 foreach ($tables as $keyname => $each_table) {
190 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
191 // statistics whatever is the table type
193 $table_is_view = false;
194 $table_encoded = urlencode($each_table['TABLE_NAME']);
195 // Sets parameters for links
196 $tbl_url_query = $url_query . '&amp;table=' . $table_encoded;
198 switch ( $each_table['ENGINE']) {
199 // MyISAM, ISAM or Heap table: Row count, data size and index size
200 // are accurate.
201 case 'MyISAM' :
202 case 'ISAM' :
203 case 'HEAP' :
204 case 'MEMORY' :
205 if ($is_show_stats) {
206 $tblsize = doubleval($each_table['Data_length']) + doubleval($each_table['Index_length']);
207 $sum_size += $tblsize;
208 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
209 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
210 list($formatted_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free'], 3, ($each_table['Data_free'] > 0) ? 1 : 0);
211 $overhead_size += $each_table['Data_free'];
214 break;
215 case 'InnoDB' :
216 // InnoDB table: Row count is not accurate but data and index
217 // sizes are.
219 if ($each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
220 $each_table['COUNTED'] = true;
221 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
222 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
223 $is_view = false);
224 } else {
225 $each_table['COUNTED'] = false;
228 if ($is_show_stats) {
229 $tblsize = $each_table['Data_length'] + $each_table['Index_length'];
230 $sum_size += $tblsize;
231 list($formatted_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ? 1 : 0);
233 //$display_rows = ' - ';
234 break;
235 case 'MRG_MyISAM' :
236 case 'BerkeleyDB' :
237 // Merge or BerkleyDB table: Only row count is accurate.
238 if ($is_show_stats) {
239 $formatted_size = ' - ';
240 $unit = '';
242 break;
243 // for a view, the ENGINE is null
244 case null :
245 case 'SYSTEM VIEW' :
246 // countRecords() takes care of $cfg['MaxExactCountViews']
247 $each_table['TABLE_ROWS'] = PMA_Table::countRecords($db,
248 $each_table['TABLE_NAME'], $return = true, $force_exact = true,
249 $is_view = true);
250 $table_is_view = true;
251 break;
252 default :
253 // Unknown table type.
254 if ($is_show_stats) {
255 $formatted_size = 'unknown';
256 $unit = '';
258 } // end switch
259 $sum_entries += $each_table['TABLE_ROWS'];
261 if (isset($each_table['Collation'])) {
262 $collation = '<dfn title="'
263 . PMA_getCollationDescr($each_table['Collation']) . '">'
264 . $each_table['Collation'] . '</dfn>';
265 } else {
266 $collation = '---';
269 if ($is_show_stats) {
270 if (isset($formatted_overhead)) {
271 $overhead = '<a href="tbl_structure.php?'
272 . $tbl_url_query . '#showusage">' . $formatted_overhead
273 . ' ' . $overhead_unit . '</a>' . "\n";
274 unset($formatted_overhead);
275 $overhead_check .=
276 "document.getElementById('checkbox_tbl_$i').checked = true;";
277 } else {
278 $overhead = '-';
280 } // end if
282 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
283 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
284 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
285 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
286 ? str_replace(' ', '&nbsp;', htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']]))
287 : str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME']));
289 $i++;
291 $row_count++;
292 if ($table_is_view) {
293 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $each_table['TABLE_NAME'] . '" />';
296 if ($each_table['TABLE_ROWS'] > 0) {
297 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&amp;pos=0">' . $titles['Browse'] . '</a>';
298 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">' . $titles['Search'] . '</a>';
299 } else {
300 $browse_table = $titles['NoBrowse'];
301 $search_table = $titles['NoSearch'];
304 if (! $db_is_information_schema) {
305 if (! empty($each_table['TABLE_ROWS'])) {
306 $empty_table = '<a href="sql.php?' . $tbl_url_query
307 . '&amp;sql_query=';
308 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
309 . '&amp;zero_rows='
310 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
311 . '" onclick="return confirmLink(this, \'TRUNCATE ';
312 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
313 } else {
314 $empty_table = $titles['NoEmpty'];
316 $drop_query = 'DROP '
317 . ($table_is_view ? 'VIEW' : 'TABLE')
318 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
319 $drop_message = sprintf(
320 $table_is_view ? $strViewHasBeenDropped : $strTableHasBeenDropped,
321 str_replace(' ', '&nbsp;', htmlspecialchars($each_table['TABLE_NAME'])));
324 if ($num_columns > 0 && $num_tables > $num_columns
325 && (($row_count % $num_columns) == 0)) {
326 $row_count = 1;
327 $odd_row = true;
329 </tr>
330 </tbody>
331 </table>
332 <?php
333 PMA_TableHeader();
336 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
337 <td align="center">
338 <input type="checkbox" name="selected_tbl[]"
339 value="<?php echo $each_table['TABLE_NAME']; ?>"
340 id="checkbox_tbl_<?php echo $i; ?>"<?php echo $checked; ?> /></td>
341 <th><label for="checkbox_tbl_<?php echo $i; ?>"
342 title="<?php echo $alias; ?>"><?php echo $truename; ?></label>
343 </th>
344 <td align="center"><?php echo $browse_table; ?></td>
345 <td align="center">
346 <a href="tbl_structure.php?<?php echo $tbl_url_query; ?>">
347 <?php echo $titles['Structure']; ?></a></td>
348 <td align="center"><?php echo $search_table; ?></td>
349 <?php if (! $db_is_information_schema) { ?>
350 <td align="center">
351 <a href="tbl_change.php?<?php echo $tbl_url_query; ?>">
352 <?php echo $titles['Insert']; ?></a></td>
353 <td align="center"><?php echo $empty_table; ?></td>
354 <td align="center">
355 <a href="sql.php?<?php echo $tbl_url_query;
356 ?>&amp;reload=1&amp;purge=1&amp;sql_query=<?php
357 echo urlencode($drop_query); ?>&amp;zero_rows=<?php
358 echo urlencode($drop_message); ?>"
359 onclick="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, false); ?>')">
360 <?php echo $titles['Drop']; ?></a></td>
361 <?php } // end if (! $db_is_information_schema)
363 // there is a null value in the ENGINE
364 // - when the table needs to be repaired, or
365 // - when it's a view
366 // so ensure that we'll display "in use" below for a table
367 // that needs to be repaired
368 if (isset($each_table['TABLE_ROWS']) && ($each_table['ENGINE'] != null || $table_is_view)) {
369 if ($table_is_view) {
370 $row_count_pre = '~';
371 $sum_row_count_pre = '~';
372 $show_superscript = PMA_showHint(PMA_sanitize(sprintf($strViewHasAtLeast, '[a@./Documentation.html#cfg_MaxExactCountViews@_blank]', '[/a]')));
373 } elseif($each_table['ENGINE'] == 'InnoDB' && (! $each_table['COUNTED'])) {
374 // InnoDB table: we did not get an accurate row count
375 $row_count_pre = '~';
376 $sum_row_count_pre = '~';
377 $show_superscript = '';
378 } else {
379 $row_count_pre = '';
380 $show_superscript = '';
383 <td class="value"><?php echo $row_count_pre . PMA_formatNumber($each_table['TABLE_ROWS'], 0) . $show_superscript; ?></td>
384 <?php if (!($cfg['PropertiesNumColumns'] > 1)) { ?>
385 <td nowrap="nowrap"><?php echo ($table_is_view ? $strView : $each_table['ENGINE']); ?></td>
386 <?php if (isset($collation)) { ?>
387 <td nowrap="nowrap"><?php echo $collation ?></td>
388 <?php } ?>
389 <?php } ?>
391 <?php if ($is_show_stats) { ?>
392 <td class="value"><a
393 href="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
394 ><?php echo $formatted_size . ' ' . $unit; ?></a></td>
395 <td class="value"><?php echo $overhead; ?></td>
396 <?php } // end if ?>
397 <?php } elseif ($table_is_view) { ?>
398 <td class="value">-</td>
399 <td><?php echo $strView; ?></td>
400 <td>---</td>
401 <?php if ($is_show_stats) { ?>
402 <td class="value">-</td>
403 <td class="value">-</td>
404 <?php } ?>
405 <?php } else { ?>
406 <td colspan="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
407 align="center">
408 <?php echo $strInUse; ?></td>
409 <?php } // end if (isset($each_table['TABLE_ROWS'])) else ?>
410 </tr>
411 <?php
412 } // end foreach
414 // Show Summary
415 if ($is_show_stats) {
416 list($sum_formatted, $unit) = PMA_formatByteDown($sum_size, 3, 1);
417 list($overhead_formatted, $overhead_unit) =
418 PMA_formatByteDown($overhead_size, 3, 1);
421 </tbody>
422 <tbody>
423 <tr><td></td>
424 <th align="center" nowrap="nowrap">
425 <?php echo sprintf($strTables, PMA_formatNumber($num_tables, 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";
497 </select>
498 <script type="text/javascript">
499 <!--
500 // Fake js to allow the use of the <noscript> tag
501 //-->
502 </script>
503 <noscript>
504 <input type="submit" value="<?php echo $strGo; ?>" />
505 </noscript>
506 <?php echo implode("\n", $hidden_fields) . "\n"; ?>
507 </div>
508 </form>
509 <?php
510 // display again the table list navigator
511 PMA_listNavigator($total_num_tables, $pos, $_url_params, 'db_structure.php', 'frame_content', $GLOBALS['cfg']['MaxTableList']);
513 <hr />
515 <?php
516 // Routines
517 require './libraries/db_routines.inc.php';
519 // Events
520 if (PMA_MYSQL_INT_VERSION > 50100) {
521 require './libraries/db_events.inc.php';
525 * Work on the database
526 * redesigned 2004-05-08 by mkkeck
528 /* DATABASE WORK */
529 /* Printable view of a table */
530 echo '<p>';
531 echo '<a href="db_printview.php?' . $url_query . '">';
532 if ($cfg['PropertiesIconic']) {
533 echo '<img class="icon" src="' . $pmaThemeImage
534 .'b_print.png" width="16" height="16" alt="" />';
536 echo $strPrintView . '</a> ';
538 echo '<a href="./db_datadict.php?' . $url_query . '">';
539 if ($cfg['PropertiesIconic']) {
540 echo '<img class="icon" src="' . $pmaThemeImage
541 .'b_tblanalyse.png" width="16" height="16" alt="" />';
543 echo $strDataDict . '</a>';
544 echo '</p>';
546 if (empty($db_is_information_schema)) {
547 require './libraries/display_create_table.lib.php';
548 } // end if (Create Table dialog)
551 * Displays the footer
553 require_once './libraries/footer.inc.php';