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 require('./libraries/transformations.lib.php3');
20 $cfgRelation = PMA_getRelationsParam();
24 * Defines the url to return to in case of error in a sql statement
27 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
29 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
34 * Selects the database
36 PMA_mysql_select_db($db);
40 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
41 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
43 if (isset($selected_tbl) && is_array($selected_tbl)) {
44 $the_tables = $selected_tbl;
45 } else if (isset($table)) {
46 $the_tables[] = $table;
48 $multi_tables = (count($the_tables) > 1);
52 while (list($key, $table) = each($the_tables)) {
53 $tbl_list .= (empty($tbl_list) ?
'' : ', ')
54 . PMA_backquote(urldecode($table));
56 echo '<b>'. $strShowTables . ' : ' . $tbl_list . '</b>' . "\n";
60 $tables_cnt = count($the_tables);
64 while (list($key, $table) = each($the_tables)) {
65 $table = urldecode($table);
66 if ($counter +
1 >= $tables_cnt) {
69 $breakstyle = ' style="page-break-after: always;"';
72 echo '<div' . $breakstyle . '>' . "\n";
73 echo '<h1>' . $table . '</h1>' . "\n";
76 * Gets table informations
78 // The 'show table' statement works correct since 3.23.03
79 if (PMA_MYSQL_INT_VERSION
>= 32303) {
80 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
81 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
82 $showtable = PMA_mysql_fetch_array($result);
83 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
84 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
86 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
87 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
89 $num_rows = PMA_mysql_result($result, 0, 'count');
91 } // end display comments
93 mysql_free_result($result);
98 * Gets table keys and retains them
100 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
101 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
105 $indexes_info = array();
106 $indexes_data = array();
107 $pk_array = array(); // will be use to emphasis prim. keys in the table
109 while ($row = PMA_mysql_fetch_array($result)) {
110 // Backups the list of primary keys
111 if ($row['Key_name'] == 'PRIMARY') {
112 $primary .= $row['Column_name'] . ', ';
113 $pk_array[$row['Column_name']] = 1;
115 // Retains keys informations
116 if ($row['Key_name'] != $lastIndex ){
117 $indexes[] = $row['Key_name'];
118 $lastIndex = $row['Key_name'];
120 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
121 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
122 if (isset($row['Cardinality'])) {
123 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
125 // I don't know what does following column mean....
126 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
127 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
129 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
130 if (isset($row['Sub_part'])) {
131 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
136 mysql_free_result($result);
141 * Gets fields properties
143 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
144 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
145 $fields_cnt = mysql_num_rows($result);
147 // Check if we can use Relations (Mike Beck)
148 if (!empty($cfgRelation['relation'])) {
149 // Find which tables are related with the current one and write it in
151 $res_rel = PMA_getForeigners($db, $table);
153 if (count($res_rel) > 0) {
165 * Displays the comments of the table if MySQL >= 3.23
167 if (!empty($show_comment)) {
168 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
172 * Displays the table structure
176 <!-- TABLE INFORMATIONS
-->
177 <table width
="95%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
179 <th width
="50"><?php
echo $strField; ?
></th
>
180 <th width
="80"><?php
echo $strType; ?
></th
>
181 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
182 <th width
="40"><?php
echo $strNull; ?
></th
>
183 <th width
="70"><?php
echo $strDefault; ?
></th
>
184 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
188 echo ' <th>' . $strLinksTo . '</th>' . "\n";
190 if ($cfgRelation['commwork']) {
191 echo ' <th>' . $strComments . '</th>' . "\n";
193 if ($cfgRelation['mimework']) {
194 echo ' <th>MIME</th>' . "\n";
201 while ($row = PMA_mysql_fetch_array($result)) {
202 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
205 $type = $row['Type'];
206 // reformat mysql query output - staybyte - 9. June 2001
207 // loic1: set or enum types: slashes single quotes inside options
208 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
209 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
210 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
217 $type_nowrap = ' nowrap="nowrap"';
218 $type = eregi_replace('BINARY', '', $type);
219 $type = eregi_replace('ZEROFILL', '', $type);
220 $type = eregi_replace('UNSIGNED', '', $type);
225 $binary = eregi('BINARY', $row['Type'], $test);
226 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
227 $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";
281 if ($cfgRelation['mimework']) {
282 $mime_map = PMA_getMIME($db, $table, true);
284 echo ' <td class="print">';
285 if (isset($mime_map[$field_name])) {
286 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
288 echo ' </td>' . "\n";
294 mysql_free_result($result);
305 $index_count = (isset($indexes))
308 if ($index_count > 0) {
314  
;<big
><?php
echo $strIndexes . ' :'; ?
></big
>
315 <table bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
317 <th
><?php
echo $strKeyname; ?
></th
>
318 <th
><?php
echo $strType; ?
></th
>
319 <th
><?php
echo $strCardinality; ?
></th
>
320 <th colspan
="2"><?php
echo $strField; ?
></th
>
324 while (list($index_no, $index_name) = each($indexes)) {
325 $cell_bgd = (($index_no %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
326 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
329 . ' ' . htmlspecialchars($index_name) . "\n"
332 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
333 $index_type = 'FULLTEXT';
334 } else if ($index_name == 'PRIMARY') {
335 $index_type = 'PRIMARY';
336 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
337 $index_type = 'UNIQUE';
339 $index_type = 'INDEX';
342 . ' ' . $index_type . "\n"
346 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ?
$indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
349 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
353 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
354 echo ' <td class="print">' . "\n"
355 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
357 echo ' <td align="right" class="print">' . "\n"
358 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
360 echo ' </tr>' . "\n";
362 echo ' <td class="print" colspan="2">' . "\n"
363 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
365 echo ' </tr>' . "\n";
374 } // end display indexes
378 * Displays Space usage and row statistics
380 * staybyte - 9 June 2001
382 if ($cfg['ShowStats']) {
384 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
387 if (PMA_MYSQL_INT_VERSION
>= 32303 && $nonisam == FALSE) {
390 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
393 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
394 if ($mergetable == FALSE) {
395 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
397 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
398 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
399 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
403 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
405 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
407 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
414 <table border
="0" cellspacing
="0" cellpadding
="0">
418 <td
class="print" valign
="top">
419  
;<big
><?php
echo $strSpaceUsage . ' :'; ?
></big
>
420 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
422 <th
><?php
echo $strType; ?
></th
>
423 <th colspan
="2" align
="center"><?php
echo $strUsage; ?
></th
>
426 <td
class="print" style
="padding-right: 10px"><?php
echo $strData; ?
></td
>
427 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $data_size; ?
></td
>
428 <td
class="print"><?php
echo $data_unit; ?
></td
>
431 if (isset($index_size)) {
435 <td
class="print" style
="padding-right: 10px"><?php
echo $strIndex; ?
></td
>
436 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $index_size; ?
></td
>
437 <td
class="print"><?php
echo $index_unit; ?
></td
>
441 if (isset($free_size)) {
444 <tr style
="color: #bb0000">
445 <td
class="print" style
="padding-right: 10px"><?php
echo $strOverhead; ?
></td
>
446 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $free_size; ?
></td
>
447 <td
class="print"><?php
echo $free_unit; ?
></td
>
450 <td
class="print" style
="padding-right: 10px"><?php
echo $strEffective; ?
></td
>
451 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $effect_size; ?
></td
>
452 <td
class="print"><?php
echo $effect_unit; ?
></td
>
456 if (isset($tot_size) && $mergetable == FALSE) {
460 <td
class="print" style
="padding-right: 10px"><?php
echo $strTotalUC; ?
></td
>
461 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $tot_size; ?
></td
>
462 <td
class="print"><?php
echo $tot_unit; ?
></td
>
471 <td width
="20" class="print"> 
;</td
>
473 <!-- Rows Statistic
-->
475  
;<big
><?php
echo $strRowsStatistic . ' :'; ?
></big
>
476 <table width
=100% bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
478 <th
><?php
echo $strStatement; ?
></th
>
479 <th align
="center"><?php
echo $strValue; ?
></th
>
483 if (isset($showtable['Row_format'])) {
484 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
488 <td
class="print"><?php
echo ucfirst($strFormat); ?
></td
>
489 <td align
="<?php echo $cell_align_left; ?>" class="print" nowrap
="nowrap">
492 if ($showtable['Row_format'] == 'Fixed') {
494 } else if ($showtable['Row_format'] == 'Dynamic') {
497 echo $showtable['Row_format'];
505 if (isset($showtable['Rows'])) {
506 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
510 <td
class="print"><?php
echo ucfirst($strRows); ?
></td
>
511 <td align
="right" class="print" nowrap
="nowrap">
512 <?php
echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
517 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
518 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
522 <td
class="print"><?php
echo ucfirst($strRowLength); ?
> 
;ø
;</td
>
523 <td
class="print" nowrap
="nowrap">
524 <?php
echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
529 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
530 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
534 <td
class="print"><?php
echo ucfirst($strRowSize); ?
> 
;ø
;</td
>
535 <td align
="right" class="print" nowrap
="nowrap">
536 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
541 if (isset($showtable['Auto_increment'])) {
542 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
546 <td
class="print"><?php
echo ucfirst($strNext); ?
> 
;Autoindex
</td
>
547 <td align
="right" class="print" nowrap
="nowrap">
548 <?php
echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
555 if (isset($showtable['Create_time'])) {
556 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
560 <td
class="print"><?php
echo $strStatCreateTime; ?
></td
>
561 <td align
="right" class="print" nowrap
="nowrap">
562 <?php
echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?
>
569 if (isset($showtable['Update_time'])) {
570 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
574 <td
class="print"><?php
echo $strStatUpdateTime; ?
></td
>
575 <td align
="right" class="print" nowrap
="nowrap">
576 <?php
echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?
>
583 if (isset($showtable['Check_time'])) {
584 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
588 <td
class="print"><?php
echo $strStatCheckTime; ?
></td
>
589 <td align
="right" class="print" nowrap
="nowrap">
590 <?php
echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?
>
603 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
604 } // end if ($cfg['ShowStats'])
610 unset($show_comment);
611 echo '<hr />' . "\n";
613 echo '</div>' . "\n";
620 * Displays the footer
624 <script type
="text/javascript" language
="javascript1.2">
628 document
.getElementById('print').style
.visibility
= 'hidden';
630 if (typeof(window
.print) != 'undefined') {
633 document
.getElementById('print').style
.visibility
= '';
638 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="Print" onclick="printPage()">' . "\n";
640 require('./footer.inc.php3');