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 * Gets the relations settings
17 require('./libraries/relation.lib.php3');
18 $cfgRelation = PMA_getRelationsParam();
22 * Defines the url to return to in case of error in a sql statement
25 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
27 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
32 * Selects the database
34 PMA_mysql_select_db($db);
38 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
39 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
41 if (isset($selected_tbl) && is_array($selected_tbl)) {
42 $the_tables = $selected_tbl;
43 } else if (isset($table)) {
44 $the_tables[] = $table;
46 $multi_tables = (count($the_tables) > 1);
50 while (list($key, $table) = each($the_tables)) {
51 $tbl_list .= (empty($tbl_list) ?
'' : ', ')
52 . PMA_backquote(urldecode($table));
54 echo '<b>'. $strShowTables . ' : ' . $tbl_list . '</b>' . "\n";
58 $tables_cnt = count($the_tables);
62 while (list($key, $table) = each($the_tables)) {
63 $table = urldecode($table);
64 if ($counter +
1 >= $tables_cnt) {
67 $breakstyle = ' style="page-break-after: always;"';
70 echo '<div' . $breakstyle . '>' . "\n";
71 echo '<h1>' . $table . '</h1>' . "\n";
74 * Gets table informations
76 // The 'show table' statement works correct since 3.23.03
77 if (PMA_MYSQL_INT_VERSION
>= 32303) {
78 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
79 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
80 $showtable = PMA_mysql_fetch_array($result);
81 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
82 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
84 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
85 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
87 $num_rows = PMA_mysql_result($result, 0, 'count');
89 } // end display comments
91 mysql_free_result($result);
96 * Gets table keys and retains them
98 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
99 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
103 $indexes_info = array();
104 $indexes_data = array();
105 $pk_array = array(); // will be use to emphasis prim. keys in the table
107 while ($row = PMA_mysql_fetch_array($result)) {
108 // Backups the list of primary keys
109 if ($row['Key_name'] == 'PRIMARY') {
110 $primary .= $row['Column_name'] . ', ';
111 $pk_array[$row['Column_name']] = 1;
113 // Retains keys informations
114 if ($row['Key_name'] != $lastIndex ){
115 $indexes[] = $row['Key_name'];
116 $lastIndex = $row['Key_name'];
118 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
119 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
120 if (isset($row['Cardinality'])) {
121 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
123 // I don't know what does following column mean....
124 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
125 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
127 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
128 if (isset($row['Sub_part'])) {
129 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
134 mysql_free_result($result);
139 * Gets fields properties
141 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
142 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
143 $fields_cnt = mysql_num_rows($result);
145 // Check if we can use Relations (Mike Beck)
146 if (!empty($cfgRelation['relation'])) {
147 // Find which tables are related with the current one and write it in
149 $res_rel = PMA_getForeigners($db, $table);
151 if (count($res_rel) > 0) {
163 * Displays the comments of the table if MySQL >= 3.23
165 if (!empty($show_comment)) {
166 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
170 * Displays the table structure
174 <!-- TABLE INFORMATIONS
-->
175 <table width
="95%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
177 <th width
="50"><?php
echo $strField; ?
></th
>
178 <th width
="80"><?php
echo $strType; ?
></th
>
179 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
180 <th width
="40"><?php
echo $strNull; ?
></th
>
181 <th width
="70"><?php
echo $strDefault; ?
></th
>
182 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
186 echo ' <th>' . $strLinksTo . '</th>' . "\n";
188 if ($cfgRelation['commwork']) {
189 echo ' <th>' . $strComments . '</th>' . "\n";
196 while ($row = PMA_mysql_fetch_array($result)) {
197 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
200 $type = $row['Type'];
201 // reformat mysql query output - staybyte - 9. June 2001
202 // loic1: set or enum types: slashes single quotes inside options
203 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
204 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
205 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
212 $type_nowrap = ' nowrap="nowrap"';
213 $type = eregi_replace('BINARY', '', $type);
214 $type = eregi_replace('ZEROFILL', '', $type);
215 $type = eregi_replace('UNSIGNED', '', $type);
220 $binary = eregi('BINARY', $row['Type'], $test);
221 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
222 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
224 $strAttribute = ' ';
226 $strAttribute = 'BINARY';
229 $strAttribute = 'UNSIGNED';
232 $strAttribute = 'UNSIGNED ZEROFILL';
234 if (!isset($row['Default'])) {
235 if ($row['Null'] != '') {
236 $row['Default'] = '<i>NULL</i>';
239 $row['Default'] = htmlspecialchars($row['Default']);
241 $field_name = htmlspecialchars($row['Field']);
245 <td width
="50" class="print" nowrap
="nowrap">
247 if (isset($pk_array[$row['Field']])) {
248 echo ' <u>' . $field_name . '</u> ' . "\n";
250 echo ' ' . $field_name . ' ' . "\n";
254 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
255 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
256 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
257 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
258 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
262 echo ' <td class="print">';
263 if (isset($res_rel[$field_name])) {
264 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
266 echo ' </td>' . "\n";
268 if ($cfgRelation['commwork']) {
269 echo ' <td class="print">';
270 $comments = PMA_getComments($db, $table);
271 if (isset($comments[$field_name])) {
272 echo htmlspecialchars($comments[$field_name]);
274 echo ' </td>' . "\n";
280 mysql_free_result($result);
291 $index_count = (isset($indexes))
294 if ($index_count > 0) {
300  
;<big
><?php
echo $strIndexes . ' :'; ?
></big
>
301 <table bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
303 <th
><?php
echo $strKeyname; ?
></th
>
304 <th
><?php
echo $strType; ?
></th
>
305 <th
><?php
echo $strCardinality; ?
></th
>
306 <th colspan
="2"><?php
echo $strField; ?
></th
>
310 while (list($index_no, $index_name) = each($indexes)) {
311 $cell_bgd = (($index_no %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
312 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
315 . ' ' . htmlspecialchars($index_name) . "\n"
318 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
319 $index_type = 'FULLTEXT';
320 } else if ($index_name == 'PRIMARY') {
321 $index_type = 'PRIMARY';
322 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
323 $index_type = 'UNIQUE';
325 $index_type = 'INDEX';
328 . ' ' . $index_type . "\n"
332 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ?
$indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
335 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
339 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
340 echo ' <td class="print">' . "\n"
341 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
343 echo ' <td align="right" class="print">' . "\n"
344 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
346 echo ' </tr>' . "\n";
348 echo ' <td class="print" colspan="2">' . "\n"
349 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
351 echo ' </tr>' . "\n";
360 } // end display indexes
364 * Displays Space usage and row statistics
366 * staybyte - 9 June 2001
368 if ($cfg['ShowStats']) {
370 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
373 if (PMA_MYSQL_INT_VERSION
>= 32303 && $nonisam == FALSE) {
376 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
379 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
380 if ($mergetable == FALSE) {
381 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
383 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
384 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
385 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
389 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
391 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
393 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
400 <table border
="0" cellspacing
="0" cellpadding
="0">
404 <td
class="print" valign
="top">
405  
;<big
><?php
echo $strSpaceUsage . ' :'; ?
></big
>
406 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
408 <th
><?php
echo $strType; ?
></th
>
409 <th colspan
="2" align
="center"><?php
echo $strUsage; ?
></th
>
412 <td
class="print" style
="padding-right: 10px"><?php
echo $strData; ?
></td
>
413 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $data_size; ?
></td
>
414 <td
class="print"><?php
echo $data_unit; ?
></td
>
417 if (isset($index_size)) {
421 <td
class="print" style
="padding-right: 10px"><?php
echo $strIndex; ?
></td
>
422 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $index_size; ?
></td
>
423 <td
class="print"><?php
echo $index_unit; ?
></td
>
427 if (isset($free_size)) {
430 <tr style
="color: #bb0000">
431 <td
class="print" style
="padding-right: 10px"><?php
echo $strOverhead; ?
></td
>
432 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $free_size; ?
></td
>
433 <td
class="print"><?php
echo $free_unit; ?
></td
>
436 <td
class="print" style
="padding-right: 10px"><?php
echo $strEffective; ?
></td
>
437 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $effect_size; ?
></td
>
438 <td
class="print"><?php
echo $effect_unit; ?
></td
>
442 if (isset($tot_size) && $mergetable == FALSE) {
446 <td
class="print" style
="padding-right: 10px"><?php
echo $strTotalUC; ?
></td
>
447 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $tot_size; ?
></td
>
448 <td
class="print"><?php
echo $tot_unit; ?
></td
>
457 <td width
="20" class="print"> 
;</td
>
459 <!-- Rows Statistic
-->
461  
;<big
><?php
echo $strRowsStatistic . ' :'; ?
></big
>
462 <table width
=100% bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
464 <th
><?php
echo $strStatement; ?
></th
>
465 <th align
="center"><?php
echo $strValue; ?
></th
>
469 if (isset($showtable['Row_format'])) {
470 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
474 <td
class="print"><?php
echo ucfirst($strFormat); ?
></td
>
475 <td align
="<?php echo $cell_align_left; ?>" class="print" nowrap
="nowrap">
478 if ($showtable['Row_format'] == 'Fixed') {
480 } else if ($showtable['Row_format'] == 'Dynamic') {
483 echo $showtable['Row_format'];
491 if (isset($showtable['Rows'])) {
492 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
496 <td
class="print"><?php
echo ucfirst($strRows); ?
></td
>
497 <td align
="right" class="print" nowrap
="nowrap">
498 <?php
echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
503 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
504 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
508 <td
class="print"><?php
echo ucfirst($strRowLength); ?
> 
;ø
;</td
>
509 <td
class="print" nowrap
="nowrap">
510 <?php
echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
515 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
516 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
520 <td
class="print"><?php
echo ucfirst($strRowSize); ?
> 
;ø
;</td
>
521 <td align
="right" class="print" nowrap
="nowrap">
522 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
527 if (isset($showtable['Auto_increment'])) {
528 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
532 <td
class="print"><?php
echo ucfirst($strNext); ?
> 
;Autoindex
</td
>
533 <td align
="right" class="print" nowrap
="nowrap">
534 <?php
echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
547 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
548 } // end if ($cfg['ShowStats'])
554 unset($show_comment);
555 echo '<hr />' . "\n";
557 echo '</div>' . "\n";
564 * Displays the footer
568 <script type
="text/javascript" language
="javascript1.2">
572 document
.all
.print.style
.visibility
= 'hidden';
574 if (typeof(window
.print) != 'undefined') {
577 document
.all
.print.style
.visibility
= '';
582 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="Print" onclick="printPage()">' . "\n";
584 require('./footer.inc.php3');