6 * Gets the variables sent or posted to this script, then displays headers
8 if (!isset($selected_tbl)) {
9 include('./libraries/grab_globals.lib.php3');
10 include('./header.inc.php3');
15 if (!defined('PMA_COMMON_LIB_INCLUDED')) {
16 include('./libraries/common.lib.php3');
19 PMA_checkParameters(array('the_tables'));
20 if (!is_array($the_tables)) {
25 * Gets the relations settings
27 require('./libraries/relation.lib.php3');
28 require('./libraries/transformations.lib.php3');
30 $cfgRelation = PMA_getRelationsParam();
34 * Defines the url to return to in case of error in a sql statement
37 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
39 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
44 * Selects the database
46 PMA_mysql_select_db($db);
50 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
51 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
53 if (isset($selected_tbl) && is_array($selected_tbl)) {
54 $the_tables = $selected_tbl;
55 } else if (isset($table)) {
56 $the_tables[] = $table;
58 $multi_tables = (count($the_tables) > 1);
62 while (list($key, $table) = each($the_tables)) {
63 $tbl_list .= (empty($tbl_list) ?
'' : ', ')
64 . PMA_backquote(urldecode($table));
66 echo '<b>'. $strShowTables . ' : ' . $tbl_list . '</b>' . "\n";
70 $tables_cnt = count($the_tables);
74 while (list($key, $table) = each($the_tables)) {
75 $table = urldecode($table);
76 if ($counter +
1 >= $tables_cnt) {
79 $breakstyle = ' style="page-break-after: always;"';
82 echo '<div' . $breakstyle . '>' . "\n";
83 echo '<h1>' . $table . '</h1>' . "\n";
86 * Gets table informations
88 // The 'show table' statement works correct since 3.23.03
89 if (PMA_MYSQL_INT_VERSION
>= 32303) {
90 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
91 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
92 $showtable = PMA_mysql_fetch_array($result);
93 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
94 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
96 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
97 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
99 $num_rows = PMA_mysql_result($result, 0, 'count');
101 } // end display comments
103 mysql_free_result($result);
108 * Gets table keys and retains them
110 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
111 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
115 $indexes_info = array();
116 $indexes_data = array();
117 $pk_array = array(); // will be use to emphasis prim. keys in the table
119 while ($row = PMA_mysql_fetch_array($result)) {
120 // Backups the list of primary keys
121 if ($row['Key_name'] == 'PRIMARY') {
122 $primary .= $row['Column_name'] . ', ';
123 $pk_array[$row['Column_name']] = 1;
125 // Retains keys informations
126 if ($row['Key_name'] != $lastIndex ){
127 $indexes[] = $row['Key_name'];
128 $lastIndex = $row['Key_name'];
130 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
131 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
132 if (isset($row['Cardinality'])) {
133 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
135 // I don't know what does following column mean....
136 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
137 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
139 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
140 if (isset($row['Sub_part'])) {
141 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
146 mysql_free_result($result);
151 * Gets fields properties
153 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
154 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
155 $fields_cnt = mysql_num_rows($result);
157 // Check if we can use Relations (Mike Beck)
158 if (!empty($cfgRelation['relation'])) {
159 // Find which tables are related with the current one and write it in
161 $res_rel = PMA_getForeigners($db, $table);
163 if (count($res_rel) > 0) {
175 * Displays the comments of the table if MySQL >= 3.23
177 if (!empty($show_comment)) {
178 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
182 * Displays the table structure
186 <!-- TABLE INFORMATIONS
-->
187 <table width
="95%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
189 <th width
="50"><?php
echo $strField; ?
></th
>
190 <th width
="80"><?php
echo $strType; ?
></th
>
191 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
192 <th width
="40"><?php
echo $strNull; ?
></th
>
193 <th width
="70"><?php
echo $strDefault; ?
></th
>
194 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
198 echo ' <th>' . $strLinksTo . '</th>' . "\n";
200 if ($cfgRelation['commwork']) {
201 echo ' <th>' . $strComments . '</th>' . "\n";
203 if ($cfgRelation['mimework']) {
204 echo ' <th>MIME</th>' . "\n";
211 while ($row = PMA_mysql_fetch_array($result)) {
212 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
215 $type = $row['Type'];
216 // reformat mysql query output - staybyte - 9. June 2001
217 // loic1: set or enum types: slashes single quotes inside options
218 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
219 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
220 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
227 $type_nowrap = ' nowrap="nowrap"';
228 $type = eregi_replace('BINARY', '', $type);
229 $type = eregi_replace('ZEROFILL', '', $type);
230 $type = eregi_replace('UNSIGNED', '', $type);
235 $binary = eregi('BINARY', $row['Type'], $test);
236 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
237 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
239 $strAttribute = ' ';
241 $strAttribute = 'BINARY';
244 $strAttribute = 'UNSIGNED';
247 $strAttribute = 'UNSIGNED ZEROFILL';
249 if (!isset($row['Default'])) {
250 if ($row['Null'] != '') {
251 $row['Default'] = '<i>NULL</i>';
254 $row['Default'] = htmlspecialchars($row['Default']);
256 $field_name = htmlspecialchars($row['Field']);
260 <td width
="50" class="print" nowrap
="nowrap">
262 if (isset($pk_array[$row['Field']])) {
263 echo ' <u>' . $field_name . '</u> ' . "\n";
265 echo ' ' . $field_name . ' ' . "\n";
269 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
270 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
271 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
272 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
273 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
277 echo ' <td class="print">';
278 if (isset($res_rel[$field_name])) {
279 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
281 echo ' </td>' . "\n";
283 if ($cfgRelation['commwork']) {
284 echo ' <td class="print">';
285 $comments = PMA_getComments($db, $table);
286 if (isset($comments[$field_name])) {
287 echo htmlspecialchars($comments[$field_name]);
289 echo ' </td>' . "\n";
291 if ($cfgRelation['mimework']) {
292 $mime_map = PMA_getMIME($db, $table, true);
294 echo ' <td class="print">';
295 if (isset($mime_map[$field_name])) {
296 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
298 echo ' </td>' . "\n";
304 mysql_free_result($result);
315 $index_count = (isset($indexes))
318 if ($index_count > 0) {
324  
;<big
><?php
echo $strIndexes . ' :'; ?
></big
>
325 <table bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
327 <th
><?php
echo $strKeyname; ?
></th
>
328 <th
><?php
echo $strType; ?
></th
>
329 <th
><?php
echo $strCardinality; ?
></th
>
330 <th colspan
="2"><?php
echo $strField; ?
></th
>
334 while (list($index_no, $index_name) = each($indexes)) {
335 $cell_bgd = (($index_no %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
336 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
339 . ' ' . htmlspecialchars($index_name) . "\n"
342 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
343 $index_type = 'FULLTEXT';
344 } else if ($index_name == 'PRIMARY') {
345 $index_type = 'PRIMARY';
346 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
347 $index_type = 'UNIQUE';
349 $index_type = 'INDEX';
352 . ' ' . $index_type . "\n"
356 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ?
$indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
359 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
363 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
364 echo ' <td class="print">' . "\n"
365 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
367 echo ' <td align="right" class="print">' . "\n"
368 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
370 echo ' </tr>' . "\n";
372 echo ' <td class="print" colspan="2">' . "\n"
373 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
375 echo ' </tr>' . "\n";
384 } // end display indexes
388 * Displays Space usage and row statistics
390 * staybyte - 9 June 2001
392 if ($cfg['ShowStats']) {
394 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
397 if (PMA_MYSQL_INT_VERSION
>= 32303 && $nonisam == FALSE) {
400 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
403 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
404 if ($mergetable == FALSE) {
405 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
407 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
408 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
409 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
413 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
415 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
417 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
424 <table border
="0" cellspacing
="0" cellpadding
="0">
428 <td
class="print" valign
="top">
429  
;<big
><?php
echo $strSpaceUsage . ' :'; ?
></big
>
430 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
432 <th
><?php
echo $strType; ?
></th
>
433 <th colspan
="2" align
="center"><?php
echo $strUsage; ?
></th
>
436 <td
class="print" style
="padding-right: 10px"><?php
echo $strData; ?
></td
>
437 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $data_size; ?
></td
>
438 <td
class="print"><?php
echo $data_unit; ?
></td
>
441 if (isset($index_size)) {
445 <td
class="print" style
="padding-right: 10px"><?php
echo $strIndex; ?
></td
>
446 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $index_size; ?
></td
>
447 <td
class="print"><?php
echo $index_unit; ?
></td
>
451 if (isset($free_size)) {
454 <tr style
="color: #bb0000">
455 <td
class="print" style
="padding-right: 10px"><?php
echo $strOverhead; ?
></td
>
456 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $free_size; ?
></td
>
457 <td
class="print"><?php
echo $free_unit; ?
></td
>
460 <td
class="print" style
="padding-right: 10px"><?php
echo $strEffective; ?
></td
>
461 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $effect_size; ?
></td
>
462 <td
class="print"><?php
echo $effect_unit; ?
></td
>
466 if (isset($tot_size) && $mergetable == FALSE) {
470 <td
class="print" style
="padding-right: 10px"><?php
echo $strTotalUC; ?
></td
>
471 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $tot_size; ?
></td
>
472 <td
class="print"><?php
echo $tot_unit; ?
></td
>
481 <td width
="20" class="print"> 
;</td
>
483 <!-- Rows Statistic
-->
485  
;<big
><?php
echo $strRowsStatistic . ' :'; ?
></big
>
486 <table width
=100% bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
488 <th
><?php
echo $strStatement; ?
></th
>
489 <th align
="center"><?php
echo $strValue; ?
></th
>
493 if (isset($showtable['Row_format'])) {
494 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
498 <td
class="print"><?php
echo ucfirst($strFormat); ?
></td
>
499 <td align
="<?php echo $cell_align_left; ?>" class="print" nowrap
="nowrap">
502 if ($showtable['Row_format'] == 'Fixed') {
504 } else if ($showtable['Row_format'] == 'Dynamic') {
507 echo $showtable['Row_format'];
515 if (isset($showtable['Rows'])) {
516 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
520 <td
class="print"><?php
echo ucfirst($strRows); ?
></td
>
521 <td align
="right" class="print" nowrap
="nowrap">
522 <?php
echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
527 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
528 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
532 <td
class="print"><?php
echo ucfirst($strRowLength); ?
> 
;ø
;</td
>
533 <td
class="print" nowrap
="nowrap">
534 <?php
echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
539 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
540 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
544 <td
class="print"><?php
echo ucfirst($strRowSize); ?
> 
;ø
;</td
>
545 <td align
="right" class="print" nowrap
="nowrap">
546 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
551 if (isset($showtable['Auto_increment'])) {
552 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
556 <td
class="print"><?php
echo ucfirst($strNext); ?
> 
;Autoindex
</td
>
557 <td align
="right" class="print" nowrap
="nowrap">
558 <?php
echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
565 if (isset($showtable['Create_time'])) {
566 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
570 <td
class="print"><?php
echo $strStatCreateTime; ?
></td
>
571 <td align
="right" class="print" nowrap
="nowrap">
572 <?php
echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?
>
579 if (isset($showtable['Update_time'])) {
580 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
584 <td
class="print"><?php
echo $strStatUpdateTime; ?
></td
>
585 <td align
="right" class="print" nowrap
="nowrap">
586 <?php
echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?
>
593 if (isset($showtable['Check_time'])) {
594 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
598 <td
class="print"><?php
echo $strStatCheckTime; ?
></td
>
599 <td align
="right" class="print" nowrap
="nowrap">
600 <?php
echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?
>
613 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
614 } // end if ($cfg['ShowStats'])
620 unset($show_comment);
621 echo '<hr />' . "\n";
623 echo '</div>' . "\n";
630 * Displays the footer
634 <script type
="text/javascript" language
="javascript1.2">
638 document
.getElementById('print').style
.visibility
= 'hidden';
640 if (typeof(window
.print) != 'undefined') {
643 document
.getElementById('print').style
.visibility
= '';
648 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
650 require('./footer.inc.php3');