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'
27 . '&convcharset=' . $convcharset
28 . '&server=' . $server
29 . '&db=' . urlencode($db)
30 . '&table=' . urlencode($table);
32 $err_url = 'db_details.php3'
34 . '&convcharset=' . $convcharset
35 . '&server=' . $server
36 . '&db=' . urlencode($db);
41 * Selects the database
43 PMA_mysql_select_db($db);
47 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
48 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
50 if (isset($selected_tbl) && is_array($selected_tbl)) {
51 $the_tables = $selected_tbl;
52 } else if (isset($table)) {
53 $the_tables[] = $table;
55 $multi_tables = (count($the_tables) > 1);
59 while (list($key, $table) = each($the_tables)) {
60 $tbl_list .= (empty($tbl_list) ?
'' : ', ')
61 . PMA_backquote(urldecode($table));
63 echo '<b>'. $strShowTables . ' : ' . $tbl_list . '</b>' . "\n";
67 $tables_cnt = count($the_tables);
71 while (list($key, $table) = each($the_tables)) {
72 $table = urldecode($table);
73 if ($counter +
1 >= $tables_cnt) {
76 $breakstyle = ' style="page-break-after: always;"';
79 echo '<div' . $breakstyle . '>' . "\n";
80 echo '<h1>' . $table . '</h1>' . "\n";
83 * Gets table informations
85 // The 'show table' statement works correct since 3.23.03
86 if (PMA_MYSQL_INT_VERSION
>= 32303) {
87 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
88 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
89 $showtable = PMA_mysql_fetch_array($result);
90 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
91 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
93 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
94 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
96 $num_rows = PMA_mysql_result($result, 0, 'count');
98 } // end display comments
100 mysql_free_result($result);
105 * Gets table keys and retains them
107 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
108 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
112 $indexes_info = array();
113 $indexes_data = array();
114 $pk_array = array(); // will be use to emphasis prim. keys in the table
116 while ($row = PMA_mysql_fetch_array($result)) {
117 // Backups the list of primary keys
118 if ($row['Key_name'] == 'PRIMARY') {
119 $primary .= $row['Column_name'] . ', ';
120 $pk_array[$row['Column_name']] = 1;
122 // Retains keys informations
123 if ($row['Key_name'] != $lastIndex ){
124 $indexes[] = $row['Key_name'];
125 $lastIndex = $row['Key_name'];
127 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
128 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
129 if (isset($row['Cardinality'])) {
130 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
132 // I don't know what does following column mean....
133 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
134 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
136 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
137 if (isset($row['Sub_part'])) {
138 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
143 mysql_free_result($result);
148 * Gets fields properties
150 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
151 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
152 $fields_cnt = mysql_num_rows($result);
154 // Check if we can use Relations (Mike Beck)
155 if (!empty($cfgRelation['relation'])) {
156 // Find which tables are related with the current one and write it in
158 $res_rel = PMA_getForeigners($db, $table);
160 if (count($res_rel) > 0) {
172 * Displays the comments of the table if MySQL >= 3.23
174 if (!empty($show_comment)) {
175 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
179 * Displays the table structure
183 <!-- TABLE INFORMATIONS
-->
184 <table width
="95%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
186 <th width
="50"><?php
echo $strField; ?
></th
>
187 <th width
="80"><?php
echo $strType; ?
></th
>
188 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
189 <th width
="40"><?php
echo $strNull; ?
></th
>
190 <th width
="70"><?php
echo $strDefault; ?
></th
>
191 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
195 echo ' <th>' . $strLinksTo . '</th>' . "\n";
197 if ($cfgRelation['commwork']) {
198 echo ' <th>' . $strComments . '</th>' . "\n";
205 while ($row = PMA_mysql_fetch_array($result)) {
206 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
209 $type = $row['Type'];
210 // reformat mysql query output - staybyte - 9. June 2001
211 // loic1: set or enum types: slashes single quotes inside options
212 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
213 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
214 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
217 $type_nowrap = ' nowrap="nowrap"';
219 $type = eregi_replace('BINARY', '', $type);
220 $type = eregi_replace('ZEROFILL', '', $type);
221 $type = eregi_replace('UNSIGNED', '', $type);
226 $binary = eregi('BINARY', $row['Type'], $test);
227 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
228 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
229 $strAttribute = ' ';
231 $strAttribute = 'BINARY';
234 $strAttribute = 'UNSIGNED';
237 $strAttribute = 'UNSIGNED ZEROFILL';
239 if (!isset($row['Default'])) {
240 if ($row['Null'] != '') {
241 $row['Default'] = '<i>NULL</i>';
244 $row['Default'] = htmlspecialchars($row['Default']);
246 $field_name = htmlspecialchars($row['Field']);
250 <td width
="50" class="print" nowrap
="nowrap">
252 if (isset($pk_array[$row['Field']])) {
253 echo ' <u>' . $field_name . '</u> ' . "\n";
255 echo ' ' . $field_name . ' ' . "\n";
259 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
260 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
261 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
262 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
263 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
267 echo ' <td class="print">';
268 if (isset($res_rel[$field_name])) {
269 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
271 echo ' </td>' . "\n";
273 if ($cfgRelation['commwork']) {
274 echo ' <td class="print">';
275 $comments = PMA_getComments($db, $table);
276 if (isset($comments[$field_name])) {
277 echo htmlspecialchars($comments[$field_name]);
279 echo ' </td>' . "\n";
285 mysql_free_result($result);
296 $index_count = (isset($indexes))
299 if ($index_count > 0) {
305  
;<big
><?php
echo $strIndexes . ' :'; ?
></big
>
306 <table bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
308 <th
><?php
echo $strKeyname; ?
></th
>
309 <th
><?php
echo $strType; ?
></th
>
310 <th
><?php
echo $strCardinality; ?
></th
>
311 <th colspan
="2"><?php
echo $strField; ?
></th
>
315 while (list($index_no, $index_name) = each($indexes)) {
316 $cell_bgd = (($index_no %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
317 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
320 . ' ' . htmlspecialchars($index_name) . "\n"
323 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
324 $index_type = 'FULLTEXT';
325 } else if ($index_name == 'PRIMARY') {
326 $index_type = 'PRIMARY';
327 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
328 $index_type = 'UNIQUE';
330 $index_type = 'INDEX';
333 . ' ' . $index_type . "\n"
337 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ?
$indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
340 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
344 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
345 echo ' <td class="print">' . "\n"
346 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
348 echo ' <td align="right" class="print">' . "\n"
349 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
351 echo ' </tr>' . "\n";
353 echo ' <td class="print" colspan="2">' . "\n"
354 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
356 echo ' </tr>' . "\n";
365 } // end display indexes
369 * Displays Space usage and row statistics
371 * staybyte - 9 June 2001
373 if ($cfg['ShowStats']) {
375 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
378 if (PMA_MYSQL_INT_VERSION
>= 32303 && $nonisam == FALSE) {
381 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
384 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
385 if ($mergetable == FALSE) {
386 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
388 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
389 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
390 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
394 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
396 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
398 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
405 <table border
="0" cellspacing
="0" cellpadding
="0">
409 <td
class="print" valign
="top">
410  
;<big
><?php
echo $strSpaceUsage . ' :'; ?
></big
>
411 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
413 <th
><?php
echo $strType; ?
></th
>
414 <th colspan
="2" align
="center"><?php
echo $strUsage; ?
></th
>
417 <td
class="print" style
="padding-right: 10px"><?php
echo $strData; ?
></td
>
418 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $data_size; ?
></td
>
419 <td
class="print"><?php
echo $data_unit; ?
></td
>
422 if (isset($index_size)) {
426 <td
class="print" style
="padding-right: 10px"><?php
echo $strIndex; ?
></td
>
427 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $index_size; ?
></td
>
428 <td
class="print"><?php
echo $index_unit; ?
></td
>
432 if (isset($free_size)) {
435 <tr style
="color: #bb0000">
436 <td
class="print" style
="padding-right: 10px"><?php
echo $strOverhead; ?
></td
>
437 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $free_size; ?
></td
>
438 <td
class="print"><?php
echo $free_unit; ?
></td
>
441 <td
class="print" style
="padding-right: 10px"><?php
echo $strEffective; ?
></td
>
442 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $effect_size; ?
></td
>
443 <td
class="print"><?php
echo $effect_unit; ?
></td
>
447 if (isset($tot_size) && $mergetable == FALSE) {
451 <td
class="print" style
="padding-right: 10px"><?php
echo $strTotalUC; ?
></td
>
452 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $tot_size; ?
></td
>
453 <td
class="print"><?php
echo $tot_unit; ?
></td
>
462 <td width
="20" class="print"> 
;</td
>
464 <!-- Rows Statistic
-->
466  
;<big
><?php
echo $strRowsStatistic . ' :'; ?
></big
>
467 <table width
=100% bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
469 <th
><?php
echo $strStatement; ?
></th
>
470 <th align
="center"><?php
echo $strValue; ?
></th
>
474 if (isset($showtable['Row_format'])) {
475 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
479 <td
class="print"><?php
echo ucfirst($strFormat); ?
></td
>
480 <td align
="<?php echo $cell_align_left; ?>" class="print" nowrap
="nowrap">
483 if ($showtable['Row_format'] == 'Fixed') {
485 } else if ($showtable['Row_format'] == 'Dynamic') {
488 echo $showtable['Row_format'];
496 if (isset($showtable['Rows'])) {
497 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
501 <td
class="print"><?php
echo ucfirst($strRows); ?
></td
>
502 <td align
="right" class="print" nowrap
="nowrap">
503 <?php
echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
508 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
509 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
513 <td
class="print"><?php
echo ucfirst($strRowLength); ?
> 
;ø
;</td
>
514 <td
class="print" nowrap
="nowrap">
515 <?php
echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
520 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
521 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
525 <td
class="print"><?php
echo ucfirst($strRowSize); ?
> 
;ø
;</td
>
526 <td align
="right" class="print" nowrap
="nowrap">
527 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
532 if (isset($showtable['Auto_increment'])) {
533 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
537 <td
class="print"><?php
echo ucfirst($strNext); ?
> 
;Autoindex
</td
>
538 <td align
="right" class="print" nowrap
="nowrap">
539 <?php
echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
552 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
553 } // end if ($cfg['ShowStats'])
559 unset($show_comment);
560 echo '<hr />' . "\n";
562 echo '</div>' . "\n";
569 * Displays the footer
573 <script type
="text/javascript" language
="javascript1.2">
577 document
.all
.print.style
.visibility
= 'hidden';
579 if (typeof(window
.print) != 'undefined') {
582 document
.all
.print.style
.visibility
= '';
587 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="Print" onclick="printPage()">' . "\n";
589 require('./footer.inc.php3');