3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once('./libraries/common.lib.php');
8 * Prepares the tables list if the user where not redirected to this script
9 * because there is no table in the database ($is_info is TRUE)
11 if ( empty( $is_info ) ) {
12 // Drops/deletes/etc. multiple tables if required
13 if ((!empty($submit_mult) && isset($selected_tbl))
14 ||
isset($mult_btn)) {
15 $action = 'db_details_structure.php';
16 $err_url = 'db_details_structure.php?'. PMA_generate_common_url($db);
17 require('./mult_submits.inc.php');
18 $message = $strSuccess;
20 require('./db_details_common.php');
21 $url_query .= '&goto=db_details_structure.php';
23 // Gets the database structure
24 $sub_part = '_structure';
25 require('./db_details_db_info.php');
29 if ( $num_tables == 0 ) {
30 echo '<p>' . $strNoTablesFound . '</p>' . "\n";
32 if ( empty( $db_is_information_schema ) ) {
33 require('./libraries/display_create_table.lib.php');
34 } // end if (Create Table dialog)
39 require_once('./footer.inc.php');
44 // 2. Shows table informations - staybyte - 11 June 2001
46 require_once('./libraries/bookmark.lib.php');
48 if ( PMA_MYSQL_INT_VERSION
>= 40101 ) {
49 require_once('./libraries/mysql_charsets.lib.php');
50 $db_collation = PMA_getDbCollation( $db );
54 function PMA_TableHeader( $db_is_information_schema = false ) {
55 $cnt = 0; // Let's count the columns...
57 if ( $db_is_information_schema ) {
63 echo '<table class="data" style="float: left;">' . "\n"
65 .'<tr><td></td>' . "\n"
66 .' <th>' . $GLOBALS['strTable'] . '</th>' . "\n"
67 .' <th colspan="' . $action_colspan . '">' . "\n"
68 .' ' . $GLOBALS['strAction'] . "\n"
70 .' <th>' . $GLOBALS['strRecords']
71 .PMA_showHint( $GLOBALS['strApproximateCount'] ) . "\n"
73 if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) {
74 echo ' <th>' . $GLOBALS['strType'] . '</th>' . "\n";
76 if (PMA_MYSQL_INT_VERSION
>= 40100) {
77 echo ' <th>' . $GLOBALS['strCollation'] . '</th>' . "\n";
81 if ($GLOBALS['cfg']['ShowStats']) {
82 echo ' <th>' . $GLOBALS['strSize'] . '</th>' . "\n"
83 . ' <th>' . $GLOBALS['strOverhead'] . '</th>' . "\n";
87 echo '</thead>' . "\n";
88 echo '<tbody>' . "\n";
89 $GLOBALS['structure_tbl_col_cnt'] = $cnt +
$action_colspan +
3;
93 if ( true == $cfg['PropertiesIconic'] ) {
94 $titles['Browse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
95 $titles['NoBrowse'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_browse.png" alt="' . $strBrowse . '" title="' . $strBrowse . '" />';
96 $titles['Search'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
97 $titles['NoSearch'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_select.png" alt="' . $strSearch . '" title="' . $strSearch . '" />';
98 $titles['Insert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
99 $titles['NoInsert'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_insrow.png" alt="' . $strInsert . '" title="' . $strInsert . '" />';
100 $titles['Structure'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_props.png" alt="' . $strStructure . '" title="' . $strStructure . '" />';
101 $titles['Drop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
102 $titles['NoDrop'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_drop.png" alt="' . $strDrop . '" title="' . $strDrop . '" />';
103 $titles['Empty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'b_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
104 $titles['NoEmpty'] = '<img class="icon" width="16" height="16" src="' .$pmaThemeImage . 'bd_empty.png" alt="' . $strEmpty . '" title="' . $strEmpty . '" />';
106 if ( 'both' === $cfg['PropertiesIconic'] ) {
107 $titles['Browse'] .= $strBrowse;
108 $titles['Search'] .= $strSearch;
109 $titles['NoBrowse'] .= $strBrowse;
110 $titles['NoSearch'] .= $strSearch;
111 $titles['Insert'] .= $strInsert;
112 $titles['NoInsert'] .= $strInsert;
113 $titles['Structure'] .= $strStructure;
114 $titles['Drop'] .= $strDrop;
115 $titles['NoDrop'] .= $strDrop;
116 $titles['Empty'] .= $strEmpty;
117 $titles['NoEmpty'] .= $strEmpty;
120 $titles['Browse'] = $strBrowse;
121 $titles['Search'] = $strSearch;
122 $titles['NoBrowse'] = $strBrowse;
123 $titles['NoSearch'] = $strSearch;
124 $titles['Insert'] = $strInsert;
125 $titles['NoInsert'] = $strInsert;
126 $titles['Structure'] = $strStructure;
127 $titles['Drop'] = $strDrop;
128 $titles['NoDrop'] = $strDrop;
129 $titles['Empty'] = $strEmpty;
130 $titles['NoEmpty'] = $strEmpty;
134 * Displays the tables list
137 <form method
="post" action
="db_details_structure.php" name
="tablesForm" id
="tablesForm">
139 echo PMA_generate_common_hidden_inputs( $db );
141 PMA_TableHeader( $db_is_information_schema );
143 $i = $sum_entries = 0;
144 $sum_size = (double) 0;
145 $overhead_size = (double) 0;
146 $overhead_check = '';
147 $checked = !empty($checkall) ?
' checked="checked"' : '';
148 $num_columns = $cfg['PropertiesNumColumns'] > 1 ?
ceil($num_tables / $cfg['PropertiesNumColumns']) +
1 : 0;
152 $hidden_fields = array();
154 foreach ( $tables as $keyname => $each_table ) {
155 if ( $each_table['TABLE_ROWS'] === NULL ||
$each_table['TABLE_ROWS'] < $GLOBALS['cfg']['MaxExactCount']) {
156 $each_table['TABLE_ROWS'] = PMA_countRecords( $db,
157 $each_table['TABLE_NAME'], $return = true, $force_exact = true );
160 $table_encoded = urlencode($each_table['TABLE_NAME']);
161 // MySQL < 5.0.13 returns "view", >= 5.0.13 returns "VIEW"
162 $table_is_view = ( $each_table['TABLE_TYPE'] === 'VIEW'
163 ||
$each_table['TABLE_TYPE'] === 'SYSTEM VIEW' );
165 $alias = (!empty($tooltip_aliasname) && isset($tooltip_aliasname[$each_table['TABLE_NAME']]))
166 ?
htmlspecialchars($tooltip_aliasname[$each_table['TABLE_NAME']])
167 : htmlspecialchars($each_table['TABLE_NAME']);
168 $truename = (!empty($tooltip_truename) && isset($tooltip_truename[$each_table['TABLE_NAME']]))
169 ?
htmlspecialchars($tooltip_truename[$each_table['TABLE_NAME']])
170 : htmlspecialchars($each_table['TABLE_NAME']);
172 // Sets parameters for links
173 $tbl_url_query = $url_query . '&table=' . $table_encoded;
177 if ( $table_is_view ) {
178 $hidden_fields[] = '<input type="hidden" name="views[]" value="' . $table_encoded . '" />';
181 if ( $each_table['TABLE_ROWS'] > 0 ) {
182 $book_sql_query = PMA_queryBookmarks($db, $cfg['Bookmark'], '\'' . PMA_sqlAddslashes($each_table['TABLE_NAME']) . '\'', 'label');
183 $browse_table = '<a href="sql.php?' . $tbl_url_query . '&sql_query='
184 . ( $book_sql_query ?
urlencode($book_sql_query) : urlencode('SELECT * FROM ' . PMA_backquote($each_table['TABLE_NAME'])))
185 . '&pos=0">' . $titles['Browse'] . '</a>';
186 $search_table = '<a href="tbl_select.php?' . $tbl_url_query . '">'
187 . $titles['Search'] . '</a>';
189 $browse_table = $titles['NoBrowse'];
190 $search_table = $titles['NoSearch'];
193 if ( ! $db_is_information_schema ) {
194 if ( ! empty($each_table['TABLE_ROWS']) ) {
195 $empty_table = '<a href="sql.php?' . $tbl_url_query
197 if (PMA_MYSQL_INT_VERSION
>= 40000) {
198 $empty_table .= urlencode('TRUNCATE ' . PMA_backquote($each_table['TABLE_NAME']))
200 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
201 . '" onclick="return confirmLink(this, \'TRUNCATE ';
203 $empty_table .= urlencode('DELETE FROM ' . PMA_backquote($each_table['TABLE_NAME']))
205 . urlencode(sprintf($strTableHasBeenEmptied, htmlspecialchars($each_table['TABLE_NAME'])))
206 . '" onclick="return confirmLink(this, \'DELETE FROM ';
208 $empty_table .= PMA_jsFormat($each_table['TABLE_NAME']) . '\')">' . $titles['Empty'] . '</a>';
210 $empty_table = $titles['NoEmpty'];
212 $drop_query = 'DROP '
213 . ( $table_is_view ?
'VIEW' : 'TABLE' )
214 . ' ' . PMA_backquote($each_table['TABLE_NAME']);
215 $drop_message = sprintf(
216 $table_is_view ?
$strViewHasBeenDropped : $strTableHasBeenDropped,
217 htmlspecialchars( $each_table['TABLE_NAME'] ) );
220 // loic1: Patch from Joshua Nye <josh at boxcarmedia.com> to get valid
221 // statistics whatever is the table type
222 if ( isset( $each_table['TABLE_ROWS'] ) ) {
223 // MyISAM, ISAM or Heap table: Row count, data size and index size
225 if ( preg_match('@^(MyISAM|ISAM|HEAP|MEMORY)$@', $each_table['ENGINE']) ) {
226 if ($cfg['ShowStats']) {
227 $tblsize = doubleval($each_table['Data_length']) +
doubleval($each_table['Index_length']);
228 $sum_size +
= $tblsize;
229 list($formated_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
230 if (isset($each_table['Data_free']) && $each_table['Data_free'] > 0) {
231 list($formated_overhead, $overhead_unit) = PMA_formatByteDown($each_table['Data_free']);
232 $overhead_size +
= $each_table['Data_free'];
235 $sum_entries +
= $each_table['TABLE_ROWS'];
236 } elseif ( $each_table['ENGINE'] == 'InnoDB' ) {
237 // InnoDB table: Row count is not accurate but data and index
239 if ($cfg['ShowStats']) {
240 $tblsize = $each_table['Data_length'] +
$each_table['Index_length'];
241 $sum_size +
= $tblsize;
242 list($formated_size, $unit) = PMA_formatByteDown($tblsize, 3, ($tblsize > 0) ?
1 : 0);
244 //$display_rows = ' - ';
245 $sum_entries +
= $each_table['TABLE_ROWS'];
246 } elseif ( preg_match('@^(MRG_MyISAM|BerkeleyDB)$@', $each_table['ENGINE']) ) {
247 // Merge or BerkleyDB table: Only row count is accurate.
248 if ($cfg['ShowStats']) {
249 $formated_size = ' - ';
252 $sum_entries +
= $each_table['TABLE_ROWS'];
254 // Unknown table type.
255 if ($cfg['ShowStats']) {
256 $formated_size = 'unknown';
261 if (PMA_MYSQL_INT_VERSION
>= 40100) {
262 if ( isset( $each_table['Collation'] ) ) {
263 $collation = '<dfn title="'
264 . PMA_getCollationDescr($each_table['Collation']) . '">'
265 . $each_table['Collation'] . '</dfn>';
271 if ( $cfg['ShowStats']) {
272 if (isset($formated_overhead)) {
273 $overhead = '<a href="tbl_properties_structure.php?'
274 . $tbl_url_query . '#showusage">' . $formated_overhead
275 . ' ' . $overhead_unit . '</a>' . "\n";
276 unset($formated_overhead);
278 "document.getElementById('checkbox_tbl_$i').checked = true;";
285 if ( $num_columns > 0 && $num_tables > $num_columns
286 && ( ($row_count %
$num_columns) == 0 )) {
297 <tr
class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
299 <input type
="checkbox" name
="selected_tbl[]"
300 value
="<?php echo $table_encoded; ?>"
301 id
="checkbox_tbl_<?php echo $i; ?>"<?php
echo $checked; ?
> /></td
>
302 <th
><label
for="checkbox_tbl_<?php echo $i; ?>"
303 title
="<?php echo $alias; ?>"><?php
echo $truename; ?
></label
>
305 <td align
="center"><?php
echo $browse_table; ?
></td
>
307 <a href
="tbl_properties_structure.php?<?php echo $tbl_url_query; ?>">
308 <?php
echo $titles['Structure']; ?
></a
></td
>
309 <td align
="center"><?php
echo $search_table; ?
></td
>
310 <?php
if ( ! $db_is_information_schema ) { ?
>
312 <a href
="tbl_change.php?<?php echo $tbl_url_query; ?>">
313 <?php
echo $titles['Insert']; ?
></a
></td
>
314 <td align
="center"><?php
echo $empty_table; ?
></td
>
316 <a href
="sql.php?<?php echo $tbl_url_query;
317 ?>&reload=1&purge=1&sql_query=<?php
318 echo urlencode($drop_query); ?>&zero_rows=<?php
319 echo urlencode($drop_message); ?>"
320 onclick
="return confirmLink(this, '<?php echo PMA_jsFormat($drop_query, FALSE); ?>')">
321 <?php
echo $titles['Drop']; ?
></a
></td
>
322 <?php
} // end if ( ! $db_is_information_schema ) ?>
323 <?php
if ( isset( $each_table['TABLE_ROWS'] ) ) { ?
>
324 <td
class="value"><?php
echo PMA_formatNumber( $each_table['TABLE_ROWS'], 0 ); ?
></td
>
325 <?php
if (!($cfg['PropertiesNumColumns'] > 1)) { ?
>
326 <td nowrap
="nowrap"><?php
echo $each_table['ENGINE']; ?
></td
>
327 <?php
if ( isset( $collation ) ) { ?
>
328 <td nowrap
="nowrap"><?php
echo $collation ?
></td
>
332 <?php
if ( $cfg['ShowStats']) { ?
>
334 href
="tbl_properties_structure.php?<?php echo $tbl_url_query; ?>#showusage"
335 ><?php
echo $formated_size . ' ' . $unit; ?
></a
></td
>
336 <td
class="value"><?php
echo $overhead; ?
></td
>
338 <?php
} elseif ( $table_is_view ) { ?
>
339 <td
class="value">-</td
>
340 <td
><?php
echo $strView; ?
></td
>
342 <?php
if ($cfg['ShowStats']) { ?
>
343 <td
class="value">-</td
>
344 <td
class="value">-</td
>
347 <td colspan
="<?php echo ($structure_tbl_col_cnt - ($db_is_information_schema ? 5 : 8)) ?>"
349 <?php
echo $strInUse; ?
></td
>
350 <?php
} // end if ( isset( $each_table['TABLE_ROWS'] ) ) else ?>
356 if ($cfg['ShowStats']) {
357 list($sum_formated, $unit) = PMA_formatByteDown($sum_size, 3, 1);
358 list($overhead_formated, $overhead_unit) =
359 PMA_formatByteDown($overhead_size, 3, 1);
365 <th align
="center" nowrap
="nowrap">
366 <?php
echo sprintf( $strTables, PMA_formatNumber( $num_tables, 0 ) ); ?
>
368 <th colspan
="<?php echo ( $db_is_information_schema ? 3 : 6 ) ?>" align
="center">
369 <?php
echo $strSum; ?
></th
>
370 <th
class="value"><?php
echo PMA_formatNumber( $sum_entries, 0 ); ?
></th
>
372 if (!($cfg['PropertiesNumColumns'] > 1)) {
373 echo ' <th align="center">'
374 .PMA_DBI_get_default_engine() . '</th>' . "\n";
375 if ( ! empty( $db_collation ) ) {
376 echo ' <th align="center">' . "\n"
378 . PMA_getCollationDescr($db_collation) . '">' . $db_collation
383 if ($cfg['ShowStats']) {
385 <th
class="value"><?php
echo $sum_formated . ' ' . $unit; ?
></th
>
386 <th
class="value"><?php
echo $overhead_formated . ' ' . $overhead_unit; ?
></th
>
394 <div
class="clearfloat">
396 // Check all tables url
397 $checkall_url = 'db_details_structure.php?' . PMA_generate_common_url($db);
399 <img
class="selectallarrow" src
="<?php echo $pmaThemeImage .'arrow_'.$text_dir.'.png'; ?>"
400 width
="38" height
="22" alt
="<?php echo $strWithChecked; ?>" />
401 <a href
="<?php echo $checkall_url; ?>&checkall=1"
402 onclick
="if ( markAllRows('tablesForm') ) return false;">
403 <?php
echo $strCheckAll; ?
></a
>
405 <a href
="<?php echo $checkall_url; ?>"
406 onclick
="if ( unMarkAllRows('tablesForm') ) return false;">
407 <?php
echo $strUncheckAll; ?
></a
>
408 <?php
if ($overhead_check != '') { ?
>
410 <a href
="#" onclick
="unMarkAllRows('tablesForm');
411 <?php echo $overhead_check; ?> return false;">
412 <?php
echo $strCheckOverhead; ?
></a
>
415 <img src
="<?php echo $GLOBALS['pmaThemeImage'] . 'spacer.png'; ?>"
416 width
="38" height
="1" alt
="" />
417 <select name
="submit_mult" onchange
="this.form.submit();">
419 echo ' <option value="' . $strWithChecked . '" selected="selected">'
420 . $strWithChecked . '</option>' . "\n";
421 echo ' <option value="' . $strDrop . '" >'
422 . $strDrop . '</option>' . "\n";
423 echo ' <option value="' . $strEmpty . '" >'
424 . $strEmpty . '</option>' . "\n";
425 echo ' <option value="' . $strPrintView . '" >'
426 . $strPrintView . '</option>' . "\n";
427 echo ' <option value="' . $strCheckTable . '" >'
428 . $strCheckTable . '</option>' . "\n";
429 echo ' <option value="' . $strOptimizeTable . '" >'
430 . $strOptimizeTable . '</option>' . "\n";
431 echo ' <option value="' . $strRepairTable . '" >'
432 . $strRepairTable . '</option>' . "\n";
433 echo ' <option value="' . $strAnalyzeTable . '" >'
434 . $strAnalyzeTable . '</option>' . "\n";
437 <script type
="text/javascript" language
="javascript">
439 // Fake js to allow the use of the <noscript> tag
443 <input type
="submit" value
="<?php echo $strGo; ?>" />
445 <?php
echo implode( "\n", $hidden_fields ) . "\n"; ?
>
452 * Work on the database
453 * redesigned 2004-05-08 by mkkeck
456 /* Printable view of a table */
458 echo '<a href="db_printview.php?' . $url_query . '">';
459 if ( $cfg['PropertiesIconic'] ) {
460 echo '<img class="icon" src="' . $pmaThemeImage
461 .'b_print.png" width="16" height="16" alt="" />';
463 echo $strPrintView . '</a> ';
465 echo '<a href="./db_datadict.php?' . $url_query . '">';
466 if($cfg['PropertiesIconic']){
467 echo '<img class="icon" src="' . $pmaThemeImage
468 .'b_tblanalyse.png" width="16" height="16" alt="" />';
470 echo $strDataDict . '</a>';
473 if ( empty( $db_is_information_schema ) ) {
474 require('./libraries/display_create_table.lib.php');
475 } // end if (Create Table dialog)
478 * Displays the footer
480 require_once('./footer.inc.php');