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 (!isset($the_tables) ||
!is_array($the_tables)) {
16 $the_tables = array();
20 * Gets the relations settings
22 require('./libraries/relation.lib.php3');
23 require('./libraries/transformations.lib.php3');
25 $cfgRelation = PMA_getRelationsParam();
29 * Defines the url to return to in case of error in a sql statement
32 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
34 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
39 * Selects the database
41 PMA_mysql_select_db($db);
45 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
46 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
48 if (isset($selected_tbl) && is_array($selected_tbl)) {
49 $the_tables = $selected_tbl;
50 } else if (isset($table)) {
51 $the_tables[] = $table;
53 $multi_tables = (count($the_tables) > 1);
57 while (list($key, $table) = each($the_tables)) {
58 $tbl_list .= (empty($tbl_list) ?
'' : ', ')
59 . PMA_backquote(urldecode($table));
61 echo '<b>'. $strShowTables . ' : ' . $tbl_list . '</b>' . "\n";
65 $tables_cnt = count($the_tables);
69 while (list($key, $table) = each($the_tables)) {
70 $table = urldecode($table);
71 if ($counter +
1 >= $tables_cnt) {
74 $breakstyle = ' style="page-break-after: always;"';
77 echo '<div' . $breakstyle . '>' . "\n";
78 echo '<h1>' . $table . '</h1>' . "\n";
81 * Gets table informations
83 // The 'show table' statement works correct since 3.23.03
84 if (PMA_MYSQL_INT_VERSION
>= 32303) {
85 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
86 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
87 $showtable = PMA_mysql_fetch_array($result);
88 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
89 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
91 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
92 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
94 $num_rows = PMA_mysql_result($result, 0, 'count');
96 } // end display comments
98 mysql_free_result($result);
103 * Gets table keys and retains them
105 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
106 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
110 $indexes_info = array();
111 $indexes_data = array();
112 $pk_array = array(); // will be use to emphasis prim. keys in the table
114 while ($row = PMA_mysql_fetch_array($result)) {
115 // Backups the list of primary keys
116 if ($row['Key_name'] == 'PRIMARY') {
117 $primary .= $row['Column_name'] . ', ';
118 $pk_array[$row['Column_name']] = 1;
120 // Retains keys informations
121 if ($row['Key_name'] != $lastIndex ){
122 $indexes[] = $row['Key_name'];
123 $lastIndex = $row['Key_name'];
125 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
126 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
127 if (isset($row['Cardinality'])) {
128 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
130 // I don't know what does following column mean....
131 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
132 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
134 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
135 if (isset($row['Sub_part'])) {
136 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
141 mysql_free_result($result);
146 * Gets fields properties
148 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
149 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
150 $fields_cnt = mysql_num_rows($result);
152 // Check if we can use Relations (Mike Beck)
153 if (!empty($cfgRelation['relation'])) {
154 // Find which tables are related with the current one and write it in
156 $res_rel = PMA_getForeigners($db, $table);
158 if (count($res_rel) > 0) {
170 * Displays the comments of the table if MySQL >= 3.23
172 if (!empty($show_comment)) {
173 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
177 * Displays the table structure
181 <!-- TABLE INFORMATIONS
-->
182 <table width
="95%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
184 <th width
="50"><?php
echo $strField; ?
></th
>
185 <th width
="80"><?php
echo $strType; ?
></th
>
186 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
187 <th width
="40"><?php
echo $strNull; ?
></th
>
188 <th width
="70"><?php
echo $strDefault; ?
></th
>
189 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
193 echo ' <th>' . $strLinksTo . '</th>' . "\n";
195 if ($cfgRelation['commwork']) {
196 echo ' <th>' . $strComments . '</th>' . "\n";
198 if ($cfgRelation['mimework']) {
199 echo ' <th>MIME</th>' . "\n";
206 while ($row = PMA_mysql_fetch_array($result)) {
207 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
210 $type = $row['Type'];
211 // reformat mysql query output - staybyte - 9. June 2001
212 // loic1: set or enum types: slashes single quotes inside options
213 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
214 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
215 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
222 $type_nowrap = ' nowrap="nowrap"';
223 $type = eregi_replace('BINARY', '', $type);
224 $type = eregi_replace('ZEROFILL', '', $type);
225 $type = eregi_replace('UNSIGNED', '', $type);
230 $binary = eregi('BINARY', $row['Type'], $test);
231 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
232 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
234 $strAttribute = ' ';
236 $strAttribute = 'BINARY';
239 $strAttribute = 'UNSIGNED';
242 $strAttribute = 'UNSIGNED ZEROFILL';
244 if (!isset($row['Default'])) {
245 if ($row['Null'] != '') {
246 $row['Default'] = '<i>NULL</i>';
249 $row['Default'] = htmlspecialchars($row['Default']);
251 $field_name = htmlspecialchars($row['Field']);
255 <td width
="50" class="print" nowrap
="nowrap">
257 if (isset($pk_array[$row['Field']])) {
258 echo ' <u>' . $field_name . '</u> ' . "\n";
260 echo ' ' . $field_name . ' ' . "\n";
264 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
265 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
266 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
267 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
268 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
272 echo ' <td class="print">';
273 if (isset($res_rel[$field_name])) {
274 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
276 echo ' </td>' . "\n";
278 if ($cfgRelation['commwork']) {
279 echo ' <td class="print">';
280 $comments = PMA_getComments($db, $table);
281 if (isset($comments[$field_name])) {
282 echo htmlspecialchars($comments[$field_name]);
284 echo ' </td>' . "\n";
286 if ($cfgRelation['mimework']) {
287 $mime_map = PMA_getMIME($db, $table, true);
289 echo ' <td class="print">';
290 if (isset($mime_map[$field_name])) {
291 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
293 echo ' </td>' . "\n";
299 mysql_free_result($result);
310 $index_count = (isset($indexes))
313 if ($index_count > 0) {
319  
;<big
><?php
echo $strIndexes . ' :'; ?
></big
>
320 <table bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
322 <th
><?php
echo $strKeyname; ?
></th
>
323 <th
><?php
echo $strType; ?
></th
>
324 <th
><?php
echo $strCardinality; ?
></th
>
325 <th colspan
="2"><?php
echo $strField; ?
></th
>
329 while (list($index_no, $index_name) = each($indexes)) {
330 $cell_bgd = (($index_no %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
331 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
334 . ' ' . htmlspecialchars($index_name) . "\n"
337 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
338 $index_type = 'FULLTEXT';
339 } else if ($index_name == 'PRIMARY') {
340 $index_type = 'PRIMARY';
341 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
342 $index_type = 'UNIQUE';
344 $index_type = 'INDEX';
347 . ' ' . $index_type . "\n"
351 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ?
$indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
354 while (list($row_no, $seq_index) = each($indexes_info[$index_name]['Sequences'])) {
358 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
359 echo ' <td class="print">' . "\n"
360 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
362 echo ' <td align="right" class="print">' . "\n"
363 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
365 echo ' </tr>' . "\n";
367 echo ' <td class="print" colspan="2">' . "\n"
368 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
370 echo ' </tr>' . "\n";
379 } // end display indexes
383 * Displays Space usage and row statistics
385 * staybyte - 9 June 2001
387 if ($cfg['ShowStats']) {
389 if (isset($showtable['Type']) && !eregi('ISAM|HEAP', $showtable['Type'])) {
392 if (PMA_MYSQL_INT_VERSION
>= 32303 && $nonisam == FALSE) {
395 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
398 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
399 if ($mergetable == FALSE) {
400 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
402 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
403 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
404 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
408 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
410 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
412 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
419 <table border
="0" cellspacing
="0" cellpadding
="0">
423 <td
class="print" valign
="top">
424  
;<big
><?php
echo $strSpaceUsage . ' :'; ?
></big
>
425 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
427 <th
><?php
echo $strType; ?
></th
>
428 <th colspan
="2" align
="center"><?php
echo $strUsage; ?
></th
>
431 <td
class="print" style
="padding-right: 10px"><?php
echo $strData; ?
></td
>
432 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $data_size; ?
></td
>
433 <td
class="print"><?php
echo $data_unit; ?
></td
>
436 if (isset($index_size)) {
440 <td
class="print" style
="padding-right: 10px"><?php
echo $strIndex; ?
></td
>
441 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $index_size; ?
></td
>
442 <td
class="print"><?php
echo $index_unit; ?
></td
>
446 if (isset($free_size)) {
449 <tr style
="color: #bb0000">
450 <td
class="print" style
="padding-right: 10px"><?php
echo $strOverhead; ?
></td
>
451 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $free_size; ?
></td
>
452 <td
class="print"><?php
echo $free_unit; ?
></td
>
455 <td
class="print" style
="padding-right: 10px"><?php
echo $strEffective; ?
></td
>
456 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $effect_size; ?
></td
>
457 <td
class="print"><?php
echo $effect_unit; ?
></td
>
461 if (isset($tot_size) && $mergetable == FALSE) {
465 <td
class="print" style
="padding-right: 10px"><?php
echo $strTotalUC; ?
></td
>
466 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $tot_size; ?
></td
>
467 <td
class="print"><?php
echo $tot_unit; ?
></td
>
476 <td width
="20" class="print"> 
;</td
>
478 <!-- Rows Statistic
-->
480  
;<big
><?php
echo $strRowsStatistic . ' :'; ?
></big
>
481 <table width
=100% bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
483 <th
><?php
echo $strStatement; ?
></th
>
484 <th align
="center"><?php
echo $strValue; ?
></th
>
488 if (isset($showtable['Row_format'])) {
489 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
493 <td
class="print"><?php
echo ucfirst($strFormat); ?
></td
>
494 <td align
="<?php echo $cell_align_left; ?>" class="print" nowrap
="nowrap">
497 if ($showtable['Row_format'] == 'Fixed') {
499 } else if ($showtable['Row_format'] == 'Dynamic') {
502 echo $showtable['Row_format'];
510 if (isset($showtable['Rows'])) {
511 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
515 <td
class="print"><?php
echo ucfirst($strRows); ?
></td
>
516 <td align
="right" class="print" nowrap
="nowrap">
517 <?php
echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
522 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
523 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
527 <td
class="print"><?php
echo ucfirst($strRowLength); ?
> 
;ø
;</td
>
528 <td
class="print" nowrap
="nowrap">
529 <?php
echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
534 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
535 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
539 <td
class="print"><?php
echo ucfirst($strRowSize); ?
> 
;ø
;</td
>
540 <td align
="right" class="print" nowrap
="nowrap">
541 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
546 if (isset($showtable['Auto_increment'])) {
547 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
551 <td
class="print"><?php
echo ucfirst($strNext); ?
> 
;Autoindex
</td
>
552 <td align
="right" class="print" nowrap
="nowrap">
553 <?php
echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
560 if (isset($showtable['Create_time'])) {
561 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
565 <td
class="print"><?php
echo $strStatCreateTime; ?
></td
>
566 <td align
="right" class="print" nowrap
="nowrap">
567 <?php
echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?
>
574 if (isset($showtable['Update_time'])) {
575 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
579 <td
class="print"><?php
echo $strStatUpdateTime; ?
></td
>
580 <td align
="right" class="print" nowrap
="nowrap">
581 <?php
echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?
>
588 if (isset($showtable['Check_time'])) {
589 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
593 <td
class="print"><?php
echo $strStatCheckTime; ?
></td
>
594 <td align
="right" class="print" nowrap
="nowrap">
595 <?php
echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?
>
608 } // end if (PMA_MYSQL_INT_VERSION >= 32303 && $nonisam == FALSE)
609 } // end if ($cfg['ShowStats'])
615 unset($show_comment);
616 echo '<hr />' . "\n";
618 echo '</div>' . "\n";
625 * Displays the footer
629 <script type
="text/javascript" language
="javascript1.2">
633 document
.getElementById('print').style
.visibility
= 'hidden';
635 if (typeof(window
.print) != 'undefined') {
638 document
.getElementById('print').style
.visibility
= '';
643 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
645 require('./footer.inc.php3');