6 * Gets the variables sent or posted to this script, then displays headers
8 if (!isset($selected_tbl)) {
9 require_once('./libraries/grab_globals.lib.php');
10 require_once('./header.inc.php');
15 if (!isset($the_tables) ||
!is_array($the_tables)) {
16 $the_tables = array();
20 * Gets the relations settings
22 require_once('./libraries/relation.lib.php');
23 require_once('./libraries/transformations.lib.php');
25 $cfgRelation = PMA_getRelationsParam();
29 * Defines the url to return to in case of error in a sql statement
32 $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
34 $err_url = 'db_details.php?' . 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 foreach($the_tables AS $key => $table) {
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);
68 foreach($the_tables AS $key => $table) {
69 $table = urldecode($table);
70 if ($counter +
1 >= $tables_cnt) {
73 $breakstyle = ' style="page-break-after: always;"';
76 echo '<div' . $breakstyle . '>' . "\n";
77 echo '<h1>' . $table . '</h1>' . "\n";
80 * Gets table informations
82 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
83 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
84 $showtable = PMA_mysql_fetch_array($result);
85 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
86 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
88 mysql_free_result($result);
93 * Gets table keys and retains them
95 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
96 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
100 $indexes_info = array();
101 $indexes_data = array();
102 $pk_array = array(); // will be use to emphasis prim. keys in the table
104 while ($row = PMA_mysql_fetch_array($result)) {
105 // Backups the list of primary keys
106 if ($row['Key_name'] == 'PRIMARY') {
107 $primary .= $row['Column_name'] . ', ';
108 $pk_array[$row['Column_name']] = 1;
110 // Retains keys informations
111 if ($row['Key_name'] != $lastIndex ){
112 $indexes[] = $row['Key_name'];
113 $lastIndex = $row['Key_name'];
115 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
116 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
117 if (isset($row['Cardinality'])) {
118 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
120 // I don't know what does following column mean....
121 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
122 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
124 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
125 if (isset($row['Sub_part'])) {
126 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
131 mysql_free_result($result);
136 * Gets fields properties
138 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
139 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
140 $fields_cnt = mysql_num_rows($result);
142 // Check if we can use Relations (Mike Beck)
143 if (!empty($cfgRelation['relation'])) {
144 // Find which tables are related with the current one and write it in
146 $res_rel = PMA_getForeigners($db, $table);
148 if (count($res_rel) > 0) {
160 * Displays the comments of the table if MySQL >= 3.23
162 if (!empty($show_comment)) {
163 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
167 * Displays the table structure
171 <!-- TABLE INFORMATIONS
-->
172 <table width
="95%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
174 <th width
="50"><?php
echo $strField; ?
></th
>
175 <th width
="80"><?php
echo $strType; ?
></th
>
176 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
177 <th width
="40"><?php
echo $strNull; ?
></th
>
178 <th width
="70"><?php
echo $strDefault; ?
></th
>
179 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
183 echo ' <th>' . $strLinksTo . '</th>' . "\n";
185 if ($cfgRelation['commwork']) {
186 echo ' <th>' . $strComments . '</th>' . "\n";
188 if ($cfgRelation['mimework']) {
189 echo ' <th>MIME</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 (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
204 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
205 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
212 $type_nowrap = ' nowrap="nowrap"';
213 $type = preg_replace('@BINARY@i', '', $type);
214 $type = preg_replace('@ZEROFILL@i', '', $type);
215 $type = preg_replace('@UNSIGNED@i', '', $type);
220 $binary = stristr($row['Type'], 'binary');
221 $unsigned = stristr($row['Type'], 'unsigned');
222 $zerofill = stristr($row['Type'], 'zerofill');
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";
276 if ($cfgRelation['mimework']) {
277 $mime_map = PMA_getMIME($db, $table, true);
279 echo ' <td class="print">';
280 if (isset($mime_map[$field_name])) {
281 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
283 echo ' </td>' . "\n";
289 mysql_free_result($result);
300 $index_count = (isset($indexes))
303 if ($index_count > 0) {
309  
;<big
><?php
echo $strIndexes . ' :'; ?
></big
>
310 <table bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
312 <th
><?php
echo $strKeyname; ?
></th
>
313 <th
><?php
echo $strType; ?
></th
>
314 <th
><?php
echo $strCardinality; ?
></th
>
315 <th colspan
="2"><?php
echo $strField; ?
></th
>
319 foreach($indexes AS $index_no => $index_name) {
320 $cell_bgd = (($index_no %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
321 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
324 . ' ' . htmlspecialchars($index_name) . "\n"
327 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
328 $index_type = 'FULLTEXT';
329 } else if ($index_name == 'PRIMARY') {
330 $index_type = 'PRIMARY';
331 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
332 $index_type = 'UNIQUE';
334 $index_type = 'INDEX';
337 . ' ' . $index_type . "\n"
341 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ?
$indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
344 foreach($indexes_info[$index_name]['Sequences'] AS $row_no => $seq_index) {
348 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
349 echo ' <td class="print">' . "\n"
350 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
352 echo ' <td align="right" class="print">' . "\n"
353 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
355 echo ' </tr>' . "\n";
357 echo ' <td class="print" colspan="2">' . "\n"
358 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
360 echo ' </tr>' . "\n";
369 } // end display indexes
373 * Displays Space usage and row statistics
375 * staybyte - 9 June 2001
377 if ($cfg['ShowStats']) {
379 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
382 if ($nonisam == FALSE) {
385 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
388 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
389 if ($mergetable == FALSE) {
390 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
392 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
393 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
394 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
398 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
400 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
402 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
409 <table border
="0" cellspacing
="0" cellpadding
="0">
413 <td
class="print" valign
="top">
414  
;<big
><?php
echo $strSpaceUsage . ' :'; ?
></big
>
415 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
417 <th
><?php
echo $strType; ?
></th
>
418 <th colspan
="2" align
="center"><?php
echo $strUsage; ?
></th
>
421 <td
class="print" style
="padding-right: 10px"><?php
echo $strData; ?
></td
>
422 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $data_size; ?
></td
>
423 <td
class="print"><?php
echo $data_unit; ?
></td
>
426 if (isset($index_size)) {
430 <td
class="print" style
="padding-right: 10px"><?php
echo $strIndex; ?
></td
>
431 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $index_size; ?
></td
>
432 <td
class="print"><?php
echo $index_unit; ?
></td
>
436 if (isset($free_size)) {
439 <tr style
="color: #bb0000">
440 <td
class="print" style
="padding-right: 10px"><?php
echo $strOverhead; ?
></td
>
441 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $free_size; ?
></td
>
442 <td
class="print"><?php
echo $free_unit; ?
></td
>
445 <td
class="print" style
="padding-right: 10px"><?php
echo $strEffective; ?
></td
>
446 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $effect_size; ?
></td
>
447 <td
class="print"><?php
echo $effect_unit; ?
></td
>
451 if (isset($tot_size) && $mergetable == FALSE) {
455 <td
class="print" style
="padding-right: 10px"><?php
echo $strTotalUC; ?
></td
>
456 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $tot_size; ?
></td
>
457 <td
class="print"><?php
echo $tot_unit; ?
></td
>
466 <td width
="20" class="print"> 
;</td
>
468 <!-- Rows Statistic
-->
470  
;<big
><?php
echo $strRowsStatistic . ' :'; ?
></big
>
471 <table width
=100% bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
473 <th
><?php
echo $strStatement; ?
></th
>
474 <th align
="center"><?php
echo $strValue; ?
></th
>
478 if (isset($showtable['Row_format'])) {
479 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
483 <td
class="print"><?php
echo ucfirst($strFormat); ?
></td
>
484 <td align
="<?php echo $cell_align_left; ?>" class="print" nowrap
="nowrap">
487 if ($showtable['Row_format'] == 'Fixed') {
489 } else if ($showtable['Row_format'] == 'Dynamic') {
492 echo $showtable['Row_format'];
500 if (isset($showtable['Rows'])) {
501 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
505 <td
class="print"><?php
echo ucfirst($strRows); ?
></td
>
506 <td align
="right" class="print" nowrap
="nowrap">
507 <?php
echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
512 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
513 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
517 <td
class="print"><?php
echo ucfirst($strRowLength); ?
> 
;ø
;</td
>
518 <td
class="print" nowrap
="nowrap">
519 <?php
echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
524 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
525 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
529 <td
class="print"><?php
echo ucfirst($strRowSize); ?
> 
;ø
;</td
>
530 <td align
="right" class="print" nowrap
="nowrap">
531 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
536 if (isset($showtable['Auto_increment'])) {
537 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
541 <td
class="print"><?php
echo ucfirst($strNext); ?
> 
;Autoindex
</td
>
542 <td align
="right" class="print" nowrap
="nowrap">
543 <?php
echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
550 if (isset($showtable['Create_time'])) {
551 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
555 <td
class="print"><?php
echo $strStatCreateTime; ?
></td
>
556 <td align
="right" class="print" nowrap
="nowrap">
557 <?php
echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?
>
564 if (isset($showtable['Update_time'])) {
565 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
569 <td
class="print"><?php
echo $strStatUpdateTime; ?
></td
>
570 <td align
="right" class="print" nowrap
="nowrap">
571 <?php
echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?
>
578 if (isset($showtable['Check_time'])) {
579 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
583 <td
class="print"><?php
echo $strStatCheckTime; ?
></td
>
584 <td align
="right" class="print" nowrap
="nowrap">
585 <?php
echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?
>
598 } // end if ($nonisam == FALSE)
599 } // end if ($cfg['ShowStats'])
605 unset($show_comment);
606 echo '<hr />' . "\n";
608 echo '</div>' . "\n";
615 * Displays the footer
619 <script type
="text/javascript" language
="javascript1.2">
623 document
.getElementById('print').style
.visibility
= 'hidden';
625 if (typeof(window
.print) != 'undefined') {
628 document
.getElementById('print').style
.visibility
= '';
633 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
635 require_once('./footer.inc.php');