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 if ($sts_data['Rows'] < $cfg['MaxExactCount']) {
244 $local_query = 'SELECT COUNT(*) AS count FROM '
245 . PMA_backquote($db) . '.'
246 . PMA_backquote($table);
247 $table_info_result = PMA_mysql_query($local_query)
248 or PMA_mysqlDie('', $local_query, '', $err_url_0);
249 $row_count = PMA_mysql_result($table_info_result, 0, 'count');
250 $sum_entries +
= $row_count;
253 $sum_entries +
= $sts_data['Rows'];
255 $display_rows = number_format($row_count, 0, $number_decimal_separator, $number_thousands_separator);
258 // Merge or BerkleyDB table: Only row count is accurate.
259 else if (isset($sts_data['Type']) && ereg('^(MRG_MyISAM|BerkeleyDB)$', $sts_data['Type'])) {
260 if ($cfg['ShowStats']) {
261 $formated_size = ' - ';
264 $sum_entries +
= $sts_data['Rows'];
265 $display_rows = number_format($sts_data['Rows'], 0, $number_decimal_separator, $number_thousands_separator);
268 // Unknown table type.
270 if ($cfg['ShowStats']) {
271 $formated_size = 'unknown';
274 $display_rows = 'unknown';
277 <td align
="right" bgcolor
="<?php echo $bgcolor; ?>">
279 echo "\n" . ' ' . $display_rows . "\n";
282 <td bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap">
283  
;<?php
echo (isset($sts_data['Type']) ?
$sts_data['Type'] : ' '); ?
> 
;
286 if ($cfg['ShowStats']) {
289 <td align
="right" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap">
291 <a href
="tbl_properties_structure.php3?<?php echo $tbl_url_query; ?>#showusage"><?php
echo $formated_size . ' ' . $unit; ?
></a
>
298 <td colspan
="3" align
="center" bgcolor
="<?php echo $bgcolor; ?>">
299 <?php
echo $strInUse . "\n"; ?
>
309 if ($cfg['ShowStats']) {
310 list($sum_formated, $unit) = PMA_formatByteDown($sum_size, 3, 1);
316 <th align
="center" nowrap
="nowrap">
317  
;<b
><?php
echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?
></b
> 
;
319 <th colspan
="6" align
="center">
320 <b
><?php
echo $strSum; ?
></b
>
322 <th align
="right" nowrap
="nowrap">
323 <b
><?php
echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?
></b
>
329 if ($cfg['ShowStats']) {
332 <th align
="right" nowrap
="nowrap">
334 <b
><?php
echo $sum_formated . ' ' . $unit; ?
></b
>
343 // Check all tables url
344 $checkall_url = 'db_details_structure.php3?' . PMA_generate_common_url($db);
348 <td colspan
="<?php echo (($cfg['ShowStats']) ? '11' : '10'); ?>" valign
="bottom">
349 <img src
="./images/arrow_<?php echo $text_dir; ?>.gif" border
="0" width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
350 <a href
="<?php echo $checkall_url; ?>&checkall=1" onclick
="setCheckboxes('tablesForm', true); return false;">
351 <?php
echo $strCheckAll; ?
></a
>
353 <a href
="<?php echo $checkall_url; ?>" onclick
="setCheckboxes('tablesForm', false); return false;">
354 <?php
echo $strUncheckAll; ?
></a
>
356 <img src
="./images/spacer.gif" border
="0" width
="38" height
="1" alt
="" />
357 <select name
="submit_mult" dir
="ltr" onchange
="this.form.submit();">
360 echo ' <option value="' . $strWithChecked . '" selected="selected">'
361 . $strWithChecked . '</option>' . "\n";
362 echo ' <option value="' . $strDrop . '" >'
363 . $strDrop . '</option>' . "\n";
364 echo ' <option value="' . $strEmpty . '" >'
365 . $strEmpty . '</option>' . "\n";
366 echo ' <option value="' . $strPrintView . '" >'
367 . $strPrintView . '</option>' . "\n";
368 echo ' <option value="' . $strCheckTable . '" >'
369 . $strCheckTable . '</option>' . "\n";
370 echo ' <option value="' . $strOptimizeTable . '" >'
371 . $strOptimizeTable . '</option>' . "\n";
372 echo ' <option value="' . $strRepairTable . '" >'
373 . $strRepairTable . '</option>' . "\n";
374 echo ' <option value="' . $strAnalyzeTable . '" >'
375 . $strAnalyzeTable . '</option>' . "\n";
378 <script type
="text/javascript" language
="javascript">
380 // Fake js to allow the use of the <noscript> tag
384 <input type
="submit" value
="<?php echo $strGo; ?>" />
392 } // end case mysql >= 3.23.03
394 // 3. Shows tables list mysql < 3.23.03
396 if ($cfgRelation['commwork']) {
397 $comment = PMA_getComments($db);
400 * Displays table comment
402 if (is_array($comment)) {
406 <?php
echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?
>
415 <form action
="db_details_structure.php3">
416 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
418 <table border
="<?php echo $cfg['Border']; ?>">
421 <th
> 
;<?php
echo $strTable; ?
> 
;</th
>
422 <th colspan
="6"><?php
echo $strAction; ?
></th
>
423 <th
><?php
echo $strRecords; ?
></th
>
426 $checked = (!empty($checkall) ?
' checked="checked"' : '');
427 while ($i < $num_tables) {
428 $table = $tables[$i];
429 $table_encoded = urlencode($table);
430 $table_name = htmlspecialchars($table);
432 // Sets parameters for links
433 $tbl_url_query = $url_query . '&table=' . $table_encoded;
434 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
438 <td align
="center" bgcolor
="<?php echo $bgcolor; ?>">
439 <input type
="checkbox" name
="selected_tbl[]" value
="<?php echo $table_encoded; ?>" id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> />
441 <td bgcolor
="<?php echo $bgcolor; ?>" class="data">
442 <b
> 
;<label
for="checkbox_tbl_<?php echo $i; ?>"><?php
echo $table_name; ?
></label
> 
;</b
>
444 <td bgcolor
="<?php echo $bgcolor; ?>">
445 <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
>
447 <td bgcolor
="<?php echo $bgcolor; ?>">
448 <a href
="tbl_select.php3?<?php echo $tbl_url_query; ?>"><?php
echo $strSelect; ?
></a
>
450 <td bgcolor
="<?php echo $bgcolor; ?>">
451 <a href
="tbl_change.php3?<?php echo $tbl_url_query; ?>"><?php
echo $strInsert; ?
></a
>
453 <td bgcolor
="<?php echo $bgcolor; ?>">
454 <a href
="tbl_properties.php3?<?php echo $tbl_url_query; ?>"><?php
echo $strProperties; ?
></a
>
456 <td bgcolor
="<?php echo $bgcolor; ?>">
457 <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
>
459 <td bgcolor
="<?php echo $bgcolor; ?>">
460 <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
>
462 <td align
="right" bgcolor
="<?php echo $bgcolor; ?>">
463 <?php
PMA_countRecords($db, $table); echo "\n"; ?
>
471 // Check all tables url
472 $checkall_url = 'db_details_structure.php3?' . PMA_generate_common_url($db);
476 <img src
="./images/arrow_<?php echo $text_dir; ?>.gif" border
="0" width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
477 <a href
="<?php echo $checkall_url; ?>&checkall=1" onclick
="setCheckboxes('tablesForm', true); return false;">
478 <?php
echo $strCheckAll; ?
></a
>
480 <a href
="<?php echo $checkall_url; ?>" onclick
="setCheckboxes('tablesForm', false); return false;">
481 <?php
echo $strUncheckAll; ?
></a
>
487 <img src
="./images/spacer.gif" border
="0" width
="38" height
="1" alt
="" />
488 <i
><?php
echo $strWithChecked; ?
></i
> 
; 
;
489 <input type
="submit" name
="submit_mult" value
="<?php echo $strDrop; ?>" />
490  
;<?php
$strOr . "\n"; ?
> 
;
491 <input type
="submit" name
="submit_mult" value
="<?php echo $strEmpty; ?>" />
498 } // end case mysql < 3.23.03
507 * Work on the database
510 <!-- DATABASE WORK
-->
514 if ($num_tables > 0) {
516 <!-- Printable view of a table
-->
518 <div style
="margin-bottom: 10px"><a href
="db_printview.php3?<?php echo $url_query; ?>"><?php
echo $strPrintView; ?
></a
></div
>
521 <div style
="margin-bottom: 10px"><a href
="./db_datadict.php3?<?php echo $url_query; ?>"><?php
echo $strDataDict; ?
></a
></div
>
528 if ($cfgRelation['commwork']) {
530 <!-- Alter
/Enter db
-comment
-->
532 <form method
="post" action
="db_details_structure.php3">
533 <?php
echo $strDBComment; ?
>
534 <input type
="hidden" name
="db_comment" value
="true" />
535 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
536 <input type
="text" name
="comment" class="textfield" value
="<?php echo (isset($comment) && is_array($comment) ? htmlspecialchars(implode(' ', $comment)) : ''); ?>" />
537 <input type
="submit" value
="<?php echo $strGo; ?>" />
544 <!-- Create a
new table
-->
546 <form method
="post" action
="tbl_create.php3"
547 onsubmit
="return (emptyFormElements(this, 'table') && checkFormElementInRange(this, 'num_fields', 1))">
548 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
550 echo ' ' . sprintf($strCreateNewTable, htmlspecialchars($db)) . ' :<br />' . "\n";
551 echo ' ' . $strName . ' : ' . "\n";
552 echo ' ' . '<input type="text" name="table" maxlength="64" class="textfield" />' . "\n";
553 echo ' ' . '<br />' . "\n";
554 echo ' ' . $strFields . ' : ' . "\n";
555 echo ' ' . '<input type="text" name="num_fields" size="2" class="textfield" />' . "\n";
556 echo ' ' . ' <input type="submit" value="' . $strGo . '" />' . "\n";
563 && !$cfgRelation['allworks'] && $cfg['PmaNoRelation_DisableWarning'] == FALSE) {
565 echo ' <div style="margin-bottom: 10px">' . "\n";
566 echo ' <font color="red">' . $strError . '</font><br />' . "\n";
567 $url_to_goto = '<a href="' . $cfg['PmaAbsoluteUri'] . 'chk_rel.php3?' . $url_query . '">';
568 echo ' ' . sprintf($strRelationNotWorking, $url_to_goto, '</a>') . "\n";
569 echo ' </div>' . "\n";
570 echo ' </li>' . "\n";
573 // is this OK to check for 'class' support?
574 $takeaway = $url_query . '&table=' . urlencode($table);
575 if ($cfgRelation['pdfwork'] && $num_tables > 0) {
577 <!-- Work on PDF Pages
-->
579 <div style
="margin-bottom: 10px"><a href
="pdf_pages.php3?<?php echo $takeaway; ?>"><?php
echo $strEditPDFPages; ?
></a
></div
>
584 // We only show this if we find something in the new pdf_pages table
586 $test_query = 'SELECT * FROM ' . PMA_backquote($cfgRelation['pdf_pages'])
587 . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'';
588 $test_rs = PMA_query_as_cu($test_query);
589 if ($test_rs && mysql_num_rows($test_rs) > 0) {
593 <form method
="post" action
="pdf_schema.php3">
594 <?php
echo PMA_generate_common_hidden_inputs($db); ?
>
595 <?php
echo $strDisplayPDF; ?
> 
;:<br
/>
596 <?php
echo $strPageNumber; ?
> 
;
597 <select name
="pdf_page_number">
599 while ($pages = @PMA_mysql_fetch_array
($test_rs)) {
601 . '<option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . $pages['page_descr'] . '</option>';
606 <input type
="checkbox" name
="show_grid" id
="show_grid_opt" />
607 <label
for="show_grid_opt"><?php
echo $strShowGrid; ?
></label
><br
/>
608 <input type
="checkbox" name
="show_color" id
="show_color_opt" checked
="checked" />
609 <label
for="show_color_opt"><?php
echo $strShowColor; ?
></label
><br
/>
610 <input type
="checkbox" name
="show_table_dimension" id
="show_table_dim_opt" />
611 <label
for="show_table_dim_opt"><?php
echo $strShowTableDimension; ?
></label
><br
/>
612 <input type
="checkbox" name
="all_tab_same_wide" id
="all_tab_same_wide" />
613 <label
for="all_tab_same_wide"><?php
echo $strAllTableSameWidth; ?
></label
> <br
/>
614 <input type
="checkbox" name
="with_doc" id
="with_doc" checked
="checked" />
615 <label
for="with_doc"><?php
echo $strDataDict; ?
></label
> <br
/>
616 <?php
echo $strShowDatadictAs; ?
>
617 <select name
="orientation">
618 <option value
="L"><?php
echo $strLandscape;?
></option
>
619 <option value
="P"><?php
echo $strPortrait;?
></option
>
621  
; 
;<input type
="submit" value
="<?php echo $strGo; ?>" />
629 && $cfgRelation['relwork'] && $cfgRelation['commwork']) {
631 <!-- import docSQL files
-->
633 <div style
="margin-bottom: 10px"><a href
="db_details_importdocsql.php3?<?php echo $takeaway . '">' . $strImportDocSQL; ?></a></div>
641 * Displays the footer
644 require('./footer
.inc
.php3
');