3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Prepares the tables list if the user where not redirected to this script
8 * because there is no table in the database ($is_info is TRUE)
10 if (empty($is_info)) {
11 if (!defined('PMA_GRAB_GLOBALS_INCLUDED')) {
12 include('./libraries/grab_globals.lib.php3');
14 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
15 include('./libraries/common.lib.php3');
18 // Drops/deletes/etc. multiple tables if required
19 if ((!empty($submit_mult) && isset($selected_tbl))
20 ||
isset($mult_btn)) {
21 $action = 'db_details_structure.php3';
22 include('./mult_submits.inc.php3');
24 include('./db_details_common.php3');
25 $url_query .= '&goto=db_details_structure.php3';
27 // Gets the database structure
28 $sub_part = '_structure';
29 include('./db_details_db_info.php3');
33 * Show result of multi submit operation
35 if ((!empty($submit_mult) && isset($selected_tbl))
36 ||
isset($mult_btn)) {
37 PMA_showMessage($strSuccess);
43 * Settings for relations stuff
45 require('./libraries/relation.lib.php3');
46 $cfgRelation = PMA_getRelationsParam();
49 * Check if comments were updated
51 if ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {
52 PMA_SetComment($db, '', '(db_comment)', $comment);
56 * Displays the tables list
64 if ($num_tables == 0) {
65 echo $strNoTablesFound . "\n";
68 // 2. Shows table informations on mysql >= 3.23.03 - staybyte - 11 June 2001
69 else if (PMA_MYSQL_INT_VERSION
>= 32303) {
71 // Get additional information about tables for tooltip
72 if ($cfg['ShowTooltip']) {
73 $tooltip_truename = array();
74 $tooltip_aliasname = array();
76 $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db));
77 while ($tmp = PMA_mysql_fetch_array($result)) {
78 $tooltip_truename[$tmp['Name']] = ($cfg['ShowTooltipAliasTB'] ?
(!empty($tmp['Comment']) ?
$tmp['Comment'] . ' ' : $tmp['Name']) : $tmp['Name']);
79 $tooltip_aliasname[$tmp['Name']] = ($cfg['ShowTooltipAliasTB'] ?
$tmp['Name'] : (!empty($tmp['Comment']) ?
$tmp['Comment'] . ' ' : ''));
80 if (isset($tmp['Create_time']) && !empty($tmp['Create_time'])) {
81 $tooltip_aliasname[$tmp['Name']] .= ', ' . $strStatCreateTime . ': ' . PMA_localisedDate(strtotime($tmp['Create_time']));
84 if (isset($tmp['Update_time']) && !empty($tmp['Update_time'])) {
85 $tooltip_aliasname[$tmp['Name']] .= ', ' . $strStatUpdateTime . ': ' . PMA_localisedDate(strtotime($tmp['Update_time']));
88 if (isset($tmp['Check_time']) && !empty($tmp['Check_time'])) {
89 $tooltip_aliasname[$tmp['Name']] .= ', ' . $strStatCheckTime . ': ' . PMA_localisedDate(strtotime($tmp['Check_time']));
95 if ($cfgRelation['commwork']) {
96 $comment = PMA_getComments($db);
99 * Displays table comment
101 if (is_array($comment)) {
105 <?php
echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?
>
111 <form method
="post" action
="db_details_structure.php3" name
="tablesForm">
112 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
114 <table border
="<?php echo $cfg['Border']; ?>">
117 <th
> 
;<?php
echo $strTable; ?
> 
;</th
>
118 <th colspan
="6"><?php
echo $strAction; ?
></th
>
119 <th
><?php
echo $strRecords; ?
></th
>
120 <th
><?php
echo $strType; ?
></th
>
122 if ($cfg['ShowStats']) {
123 echo '<th>' . $strSize . '</th>';
129 $i = $sum_entries = 0;
130 (double) $sum_size = 0;
131 $checked = (!empty($checkall) ?
' checked="checked"' : '');
132 while (list($keyname, $sts_data) = each($tables)) {
133 $table = $sts_data['Name'];
134 $table_encoded = urlencode($table);
135 $table_name = htmlspecialchars($table);
137 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$table]))
138 ?
htmlspecialchars($tooltip_aliasname[$table])
139 : htmlspecialchars($sts_data['Name']);
140 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$table]))
141 ?
htmlspecialchars($tooltip_truename[$table])
142 : htmlspecialchars($sts_data['Name']);
144 // Sets parameters for links
145 $tbl_url_query = $url_query . '&table=' . $table_encoded;
146 $bgcolor = ($i++ %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
150 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>">
151 <input type
="checkbox" name
="selected_tbl[]" value
="<?php echo $table_encoded; ?>" id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> />
153 <td bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap">
154  
;<b
><label
for="checkbox_tbl_<?php echo $i; ?>" title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></label
> 
;</b
> 
;
156 <td bgcolor
="<?php echo $bgcolor; ?>">
158 include('./libraries/bookmark.lib.php3');
159 $book_sql_query = PMA_queryBookmarks($db, $cfg['Bookmark'], '\'' . PMA_sqlAddslashes($table) . '\'', 'label');
161 if (!empty($sts_data['Rows'])) {
162 echo '<a href="sql.php3?' . $tbl_url_query . '&sql_query='
163 . (isset($book_sql_query) && $book_sql_query != FALSE ?
urlencode($book_sql_query) : urlencode('SELECT * FROM ' . PMA_backquote($table)))
164 . '&pos=0">' . $strBrowse . '</a>';
170 <td bgcolor
="<?php echo $bgcolor; ?>">
172 if (!empty($sts_data['Rows'])) {
173 echo '<a href="tbl_select.php3?' . $tbl_url_query . '">'
174 . $strSelect . '</a>';
180 <td bgcolor
="<?php echo $bgcolor; ?>">
181 <a href
="tbl_change.php3?<?php echo $tbl_url_query; ?>">
182 <?php
echo $strInsert; ?
></a
>
184 <td bgcolor
="<?php echo $bgcolor; ?>">
185 <a href
="tbl_properties_structure.php3?<?php echo $tbl_url_query; ?>">
186 <?php
echo $strProperties; ?
></a
>
188 <td bgcolor
="<?php echo $bgcolor; ?>">
189 <a href
="sql.php3?<?php echo $tbl_url_query; ?>&reload=1&purge=1&sql_query=<?php echo urlencode('DROP TABLE ' . PMA_backquote($table)); ?>&zero_rows=<?php echo urlencode(sprintf($strTableHasBeenDropped, htmlspecialchars($table))); ?>"
190 onclick
="return confirmLink(this, 'DROP TABLE <?php echo PMA_jsFormat($table); ?>')">
191 <?php
echo $strDrop; ?
></a
>
193 <td bgcolor
="<?php echo $bgcolor; ?>">
195 if (!empty($sts_data['Rows'])) {
196 echo '<a href="sql.php3?' . $tbl_url_query
198 if (PMA_MYSQL_INT_VERSION
>= 40000) {
199 echo urlencode('TRUNCATE ' . PMA_backquote($table))
201 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($table)))
202 . '" onclick="return confirmLink(this, \'TRUNCATE ';
204 echo urlencode('DELETE FROM ' . PMA_backquote($table))
206 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($table)))
207 . '" onclick="return confirmLink(this, \'DELETE FROM ';
209 echo PMA_jsFormat($table) . '\')">' . $strEmpty . '</a>';
218 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
219 // statistics whatever is the table type
220 if (isset($sts_data['Rows'])) {
221 // MyISAM, ISAM or Heap table: Row count, data size and index size
223 if (isset($sts_data['Type']) && ereg('^(MyISAM|ISAM|HEAP)$', $sts_data['Type'])) {
224 if ($cfg['ShowStats']) {
225 $tblsize = doubleval($sts_data['Data_length']) +
doubleval($sts_data['Index_length']);
226 $sum_size +
= $tblsize;
227 list($formated_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
229 $sum_entries +
= $sts_data['Rows'];
230 $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
233 // InnoDB table: Row count is not accurate but data and index
235 else if (isset($sts_data['Type']) && $sts_data['Type'] == 'InnoDB') {
236 if ($cfg['ShowStats']) {
237 $tblsize = $sts_data['Data_length'] +
$sts_data['Index_length'];
238 $sum_size +
= $tblsize;
239 list($formated_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
241 //$display_rows = ' - ';
242 // get row count with another method
243 $local_query = 'SELECT COUNT(*) AS count FROM '
244 . PMA_backquote($db) . '.'
245 . PMA_backquote($table);
246 $table_info_result = PMA_mysql_query($local_query)
247 or PMA_mysqlDie('', $local_query, '', $err_url_0);
248 $row_count = PMA_mysql_result($table_info_result, 0, 'count');
249 $sum_entries +
= $row_count;
250 $display_rows = number_format($row_count, 0, $number_decimal_separator, $number_thousands_separator);
253 // Merge or BerkleyDB table: Only row count is accurate.
254 else if (isset($sts_data['Type']) && ereg('^(MRG_MyISAM|BerkeleyDB)$', $sts_data['Type'])) {
255 if ($cfg['ShowStats']) {
256 $formated_size = ' - ';
259 $sum_entries +
= $sts_data['Rows'];
260 $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
263 // Unknown table type.
265 if ($cfg['ShowStats']) {
266 $formated_size = 'unknown';
269 $display_rows = 'unknown';
272 <td align
="right" bgcolor
="<?php echo $bgcolor; ?>">
274 echo "\n" . ' ' . $display_rows . "\n";
277 <td bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap">
278  
;<?php
echo (isset($sts_data['Type']) ?
$sts_data['Type'] : ' '); ?
> 
;
281 if ($cfg['ShowStats']) {
284 <td align
="right" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap">
286 <a href
="tbl_properties_structure.php3?<?php echo $tbl_url_query; ?>#showusage"><?php
echo $formated_size . ' ' . $unit; ?
></a
>
293 <td colspan
="3" align
="center" bgcolor
="<?php echo $bgcolor; ?>">
294 <?php
echo $strInUse . "\n"; ?
>
304 if ($cfg['ShowStats']) {
305 list($sum_formated, $unit) = PMA_formatByteDown($sum_size, 3, 1);
311 <th align
="center" nowrap
="nowrap">
312  
;<b
><?php
echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?
></b
> 
;
314 <th colspan
="6" align
="center">
315 <b
><?php
echo $strSum; ?
></b
>
317 <th align
="right" nowrap
="nowrap">
318 <b
><?php
echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?
></b
>
324 if ($cfg['ShowStats']) {
327 <th align
="right" nowrap
="nowrap">
329 <b
><?php
echo $sum_formated . ' ' . $unit; ?
></b
>
338 // Check all tables url
339 $checkall_url = 'db_details_structure.php3?' . PMA_generate_common_url($db);
343 <td colspan
="<?php echo (($cfg['ShowStats']) ? '11' : '10'); ?>" valign
="bottom">
344 <img src
="./images/arrow_<?php echo $text_dir; ?>.gif" border
="0" width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
345 <a href
="<?php echo $checkall_url; ?>&checkall=1" onclick
="setCheckboxes('tablesForm', true); return false;">
346 <?php
echo $strCheckAll; ?
></a
>
348 <a href
="<?php echo $checkall_url; ?>" onclick
="setCheckboxes('tablesForm', false); return false;">
349 <?php
echo $strUncheckAll; ?
></a
>
351 <img src
="./images/spacer.gif" border
="0" width
="38" height
="1" alt
="" />
352 <select name
="submit_mult" dir
="ltr" onchange
="this.form.submit();">
355 echo ' <option value="' . $strWithChecked . '" selected="selected">'
356 . $strWithChecked . '</option>' . "\n";
357 echo ' <option value="' . $strDrop . '" >'
358 . $strDrop . '</option>' . "\n";
359 echo ' <option value="' . $strEmpty . '" >'
360 . $strEmpty . '</option>' . "\n";
361 echo ' <option value="' . $strPrintView . '" >'
362 . $strPrintView . '</option>' . "\n";
363 echo ' <option value="' . $strCheckTable . '" >'
364 . $strCheckTable . '</option>' . "\n";
365 echo ' <option value="' . $strOptimizeTable . '" >'
366 . $strOptimizeTable . '</option>' . "\n";
367 echo ' <option value="' . $strRepairTable . '" >'
368 . $strRepairTable . '</option>' . "\n";
369 echo ' <option value="' . $strAnalyzeTable . '" >'
370 . $strAnalyzeTable . '</option>' . "\n";
373 <script type
="text/javascript" language
="javascript">
375 // Fake js to allow the use of the <noscript> tag
379 <input type
="submit" value
="<?php echo $strGo; ?>" />
387 } // end case mysql >= 3.23.03
389 // 3. Shows tables list mysql < 3.23.03
391 if ($cfgRelation['commwork']) {
392 $comment = PMA_getComments($db);
395 * Displays table comment
397 if (is_array($comment)) {
401 <?php
echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?
>
410 <form action
="db_details_structure.php3">
411 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
413 <table border
="<?php echo $cfg['Border']; ?>">
416 <th
> 
;<?php
echo $strTable; ?
> 
;</th
>
417 <th colspan
="6"><?php
echo $strAction; ?
></th
>
418 <th
><?php
echo $strRecords; ?
></th
>
421 $checked = (!empty($checkall) ?
' checked="checked"' : '');
422 while ($i < $num_tables) {
423 $table = $tables[$i];
424 $table_encoded = urlencode($table);
425 $table_name = htmlspecialchars($table);
427 // Sets parameters for links
428 $tbl_url_query = $url_query . '&table=' . $table_encoded;
429 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
433 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>">
434 <input type
="checkbox" name
="selected_tbl[]" value
="<?php echo $table_encoded; ?>" id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> />
436 <td bgcolor
="<?php echo $bgcolor; ?>" class="data">
437 <b
> 
;<label
for="checkbox_tbl_<?php echo $i; ?>"><?php
echo $table_name; ?
></label
> 
;</b
>
439 <td bgcolor
="<?php echo $bgcolor; ?>">
440 <a href
="sql.php3?<?php echo $tbl_url_query; ?>&sql_query=<?php echo urlencode('SELECT * FROM ' . PMA_backquote($table)); ?>&pos=0"><?php
echo $strBrowse; ?
></a
>
442 <td bgcolor
="<?php echo $bgcolor; ?>">
443 <a href
="tbl_select.php3?<?php echo $tbl_url_query; ?>"><?php
echo $strSelect; ?
></a
>
445 <td bgcolor
="<?php echo $bgcolor; ?>">
446 <a href
="tbl_change.php3?<?php echo $tbl_url_query; ?>"><?php
echo $strInsert; ?
></a
>
448 <td bgcolor
="<?php echo $bgcolor; ?>">
449 <a href
="tbl_properties.php3?<?php echo $tbl_url_query; ?>"><?php
echo $strProperties; ?
></a
>
451 <td bgcolor
="<?php echo $bgcolor; ?>">
452 <a href
="sql.php3?<?php echo $tbl_url_query; ?>&reload=1&purge=1&sql_query=<?php echo urlencode('DROP TABLE ' . PMA_backquote($table)); ?>&zero_rows=<?php echo urlencode(sprintf($strTableHasBeenDropped, $table_name)); ?>"><?php
echo $strDrop; ?
></a
>
454 <td bgcolor
="<?php echo $bgcolor; ?>">
455 <a href
="sql.php3?<?php echo $tbl_url_query; ?>&sql_query=<?php echo urlencode('DELETE FROM ' . PMA_backquote($table)); ?>&zero_rows=<?php echo urlencode(sprintf($strTableHasBeenEmptied, $table_name)); ?>"><?php
echo $strEmpty; ?
></a
>
457 <td align
="right" bgcolor
="<?php echo $bgcolor; ?>">
458 <?php
PMA_countRecords($db, $table); echo "\n"; ?
>
466 // Check all tables url
467 $checkall_url = 'db_details_structure.php3?' . PMA_generate_common_url($db);
471 <img src
="./images/arrow_<?php echo $text_dir; ?>.gif" border
="0" width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
472 <a href
="<?php echo $checkall_url; ?>&checkall=1" onclick
="setCheckboxes('tablesForm', true); return false;">
473 <?php
echo $strCheckAll; ?
></a
>
475 <a href
="<?php echo $checkall_url; ?>" onclick
="setCheckboxes('tablesForm', false); return false;">
476 <?php
echo $strUncheckAll; ?
></a
>
482 <img src
="./images/spacer.gif" border
="0" width
="38" height
="1" alt
="" />
483 <i
><?php
echo $strWithChecked; ?
></i
> 
; 
;
484 <input type
="submit" name
="submit_mult" value
="<?php echo $strDrop; ?>" />
485  
;<?php
$strOr . "\n"; ?
> 
;
486 <input type
="submit" name
="submit_mult" value
="<?php echo $strEmpty; ?>" />
493 } // end case mysql < 3.23.03
502 * Work on the database
505 <!-- DATABASE WORK
-->
509 if ($num_tables > 0) {
511 <!-- Printable view of a table
-->
513 <div style
="margin-bottom: 10px"><a href
="db_printview.php3?<?php echo $url_query; ?>"><?php
echo $strPrintView; ?
></a
></div
>
516 <div style
="margin-bottom: 10px"><a href
="./db_datadict.php3?<?php echo $url_query; ?>"><?php
echo $strDataDict; ?
></a
></div
>
523 if ($cfgRelation['commwork']) {
525 <!-- Alter
/Enter db
-comment
-->
527 <form method
="post" action
="db_details_structure.php3">
528 <?php
echo $strDBComment; ?
>
529 <input type
="hidden" name
="db_comment" value
="true" />
530 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
531 <input type
="text" name
="comment" class="textfield" value
="<?php echo (isset($comment) && is_array($comment) ? htmlspecialchars(implode(' ', $comment)) : ''); ?>" />
532 <input type
="submit" value
="<?php echo $strGo; ?>" />
539 <!-- Create a
new table
-->
541 <form method
="post" action
="tbl_create.php3"
542 onsubmit
="return (emptyFormElements(this, 'table') && checkFormElementInRange(this, 'num_fields', 1))">
543 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
545 echo ' ' . sprintf($strCreateNewTable, htmlspecialchars($db)) . ' :<br />' . "\n";
546 echo ' ' . $strName . ' : ' . "\n";
547 echo ' ' . '<input type="text" name="table" maxlength="64" class="textfield" />' . "\n";
548 echo ' ' . '<br />' . "\n";
549 echo ' ' . $strFields . ' : ' . "\n";
550 echo ' ' . '<input type="text" name="num_fields" size="2" class="textfield" />' . "\n";
551 echo ' ' . ' <input type="submit" value="' . $strGo . '" />' . "\n";
558 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) {
560 echo ' <div style="margin-bottom: 10px">' . "\n";
561 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
562 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php3?' . $url_query . '">';
563 echo ' ' . sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
564 echo ' </div>' . "\n";
565 echo ' </li>' . "\n";
568 // is this OK to check for 'class' support?
569 $takeaway = $url_query . '&table=' . urlencode($table);
570 if ($cfgRelation['pdfwork'] && $num_tables > 0) {
572 <!-- Work on PDF Pages
-->
574 <div style
="margin-bottom: 10px"><a href
="pdf_pages.php3?<?php echo $takeaway; ?>"><?php
echo $strEditPDFPages; ?
></a
></div
>
579 // We only show this if we find something in the new pdf_pages table
581 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
582 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
583 $test_rs = PMA_query_as_cu($test_query);
584 if ($test_rs && mysql_num_rows($test_rs) > 0) {
588 <form method
="post" action
="pdf_schema.php3">
589 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
590 <?php
echo $strDisplayPDF; ?
> 
;:<br
/>
591 <?php
echo $strPageNumber; ?
> 
;
592 <select name
="pdf_page_number">
594 while ($pages = @PMA_mysql_fetch_array
($test_rs)) {
596 . '<option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>';
601 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
602 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
603 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" />
604 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
605 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
606 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
607 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
608 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
> <br
/>
609 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
610 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
> <br
/>
611 <?php
echo $strShowDatadictAs; ?
>
612 <select name
="orientation">
613 <option value
="L"><?php
echo $strLandscape;?
></option
>
614 <option value
="P"><?php
echo $strPortrait;?
></option
>
616  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
624 && $cfgRelation['relwork'] && $cfgRelation['commwork']) {
626 <!-- import docSQL files
-->
628 <div style
="margin-bottom: 10px"><a href
="db_details_importdocsql.php3?<?php echo $takeaway . '">' . $strImportDocSQL; ?></a></div>
636 * Displays the footer
639 require('./footer
.inc
.php3
');