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_DBI_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 $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\';');
83 $showtable = PMA_DBI_fetch_assoc($result);
84 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
85 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
86 PMA_DBI_free_result($result);
90 * Gets table keys and retains them
92 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
96 $indexes_info = array();
97 $indexes_data = array();
98 $pk_array = array(); // will be use to emphasis prim. keys in the table
100 while ($row = PMA_DBI_fetch_assoc($result)) {
101 // Backups the list of primary keys
102 if ($row['Key_name'] == 'PRIMARY') {
103 $primary .= $row['Column_name'] . ', ';
104 $pk_array[$row['Column_name']] = 1;
106 // Retains keys informations
107 if ($row['Key_name'] != $lastIndex ){
108 $indexes[] = $row['Key_name'];
109 $lastIndex = $row['Key_name'];
111 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
112 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
113 if (isset($row['Cardinality'])) {
114 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
116 // I don't know what does following column mean....
117 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
118 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
120 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
121 if (isset($row['Sub_part'])) {
122 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
127 PMA_DBI_free_result($result);
132 * Gets fields properties
134 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE
);
135 $fields_cnt = PMA_DBI_num_rows($result);
137 // Check if we can use Relations (Mike Beck)
138 if (!empty($cfgRelation['relation'])) {
139 // Find which tables are related with the current one and write it in
141 $res_rel = PMA_getForeigners($db, $table);
143 if (count($res_rel) > 0) {
155 * Displays the comments of the table if MySQL >= 3.23
157 if (!empty($show_comment)) {
158 echo $strTableComments . ': ' . $show_comment . '<br /><br />';
162 * Displays the table structure
166 <!-- TABLE INFORMATIONS
-->
167 <table width
="95%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
169 <th width
="50"><?php
echo $strField; ?
></th
>
170 <th width
="80"><?php
echo $strType; ?
></th
>
171 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
172 <th width
="40"><?php
echo $strNull; ?
></th
>
173 <th width
="70"><?php
echo $strDefault; ?
></th
>
174 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
178 echo ' <th>' . $strLinksTo . '</th>' . "\n";
180 if ($cfgRelation['commwork']) {
181 echo ' <th>' . $strComments . '</th>' . "\n";
183 if ($cfgRelation['mimework']) {
184 echo ' <th>MIME</th>' . "\n";
191 while ($row = PMA_DBI_fetch_assoc($result)) {
192 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
195 $type = $row['Type'];
196 // reformat mysql query output - staybyte - 9. June 2001
197 // loic1: set or enum types: slashes single quotes inside options
198 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
199 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
200 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
207 $type_nowrap = ' nowrap="nowrap"';
208 $type = preg_replace('@BINARY@i', '', $type);
209 $type = preg_replace('@ZEROFILL@i', '', $type);
210 $type = preg_replace('@UNSIGNED@i', '', $type);
215 $binary = stristr($row['Type'], 'binary');
216 $unsigned = stristr($row['Type'], 'unsigned');
217 $zerofill = stristr($row['Type'], 'zerofill');
219 $strAttribute = ' ';
221 $strAttribute = 'BINARY';
224 $strAttribute = 'UNSIGNED';
227 $strAttribute = 'UNSIGNED ZEROFILL';
229 if (!isset($row['Default'])) {
230 if ($row['Null'] != '') {
231 $row['Default'] = '<i>NULL</i>';
234 $row['Default'] = htmlspecialchars($row['Default']);
236 $field_name = htmlspecialchars($row['Field']);
240 <td width
="50" class="print" nowrap
="nowrap">
242 if (isset($pk_array[$row['Field']])) {
243 echo ' <u>' . $field_name . '</u> ' . "\n";
245 echo ' ' . $field_name . ' ' . "\n";
249 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
250 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
251 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
252 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
253 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
257 echo ' <td class="print">';
258 if (isset($res_rel[$field_name])) {
259 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
261 echo ' </td>' . "\n";
263 if ($cfgRelation['commwork']) {
264 echo ' <td class="print">';
265 $comments = PMA_getComments($db, $table);
266 if (isset($comments[$field_name])) {
267 echo htmlspecialchars($comments[$field_name]);
269 echo ' </td>' . "\n";
271 if ($cfgRelation['mimework']) {
272 $mime_map = PMA_getMIME($db, $table, true);
274 echo ' <td class="print">';
275 if (isset($mime_map[$field_name])) {
276 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
278 echo ' </td>' . "\n";
284 PMA_DBI_free_result($result);
295 $index_count = (isset($indexes))
298 if ($index_count > 0) {
304  
;<big
><?php
echo $strIndexes . ':'; ?
></big
>
305 <table bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
307 <th
><?php
echo $strKeyname; ?
></th
>
308 <th
><?php
echo $strType; ?
></th
>
309 <th
><?php
echo $strCardinality; ?
></th
>
310 <th colspan
="2"><?php
echo $strField; ?
></th
>
314 foreach ($indexes AS $index_no => $index_name) {
315 $cell_bgd = (($index_no %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
316 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
319 . ' ' . htmlspecialchars($index_name) . "\n"
322 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
323 $index_type = 'FULLTEXT';
324 } else if ($index_name == 'PRIMARY') {
325 $index_type = 'PRIMARY';
326 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
327 $index_type = 'UNIQUE';
329 $index_type = 'INDEX';
332 . ' ' . $index_type . "\n"
336 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ?
$indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
339 foreach ($indexes_info[$index_name]['Sequences'] AS $row_no => $seq_index) {
343 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
344 echo ' <td class="print">' . "\n"
345 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
347 echo ' <td align="right" class="print">' . "\n"
348 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
350 echo ' </tr>' . "\n";
352 echo ' <td class="print" colspan="2">' . "\n"
353 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
355 echo ' </tr>' . "\n";
364 } // end display indexes
368 * Displays Space usage and row statistics
370 * staybyte - 9 June 2001
372 if ($cfg['ShowStats']) {
374 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
377 if ($nonisam == FALSE) {
380 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
383 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
384 if ($mergetable == FALSE) {
385 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
387 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
388 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
389 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length'] - $showtable['Data_free']);
393 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
395 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] +
$showtable['Index_length']);
397 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] +
$showtable['Index_length']) / $showtable['Rows'], 6, 1);
404 <table border
="0" cellspacing
="0" cellpadding
="0">
408 <td
class="print" valign
="top">
409  
;<big
><?php
echo $strSpaceUsage . ':'; ?
></big
>
410 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
412 <th
><?php
echo $strType; ?
></th
>
413 <th colspan
="2" align
="center"><?php
echo $strUsage; ?
></th
>
416 <td
class="print" style
="padding-right: 10px"><?php
echo $strData; ?
></td
>
417 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $data_size; ?
></td
>
418 <td
class="print"><?php
echo $data_unit; ?
></td
>
421 if (isset($index_size)) {
425 <td
class="print" style
="padding-right: 10px"><?php
echo $strIndex; ?
></td
>
426 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $index_size; ?
></td
>
427 <td
class="print"><?php
echo $index_unit; ?
></td
>
431 if (isset($free_size)) {
434 <tr style
="color: #bb0000">
435 <td
class="print" style
="padding-right: 10px"><?php
echo $strOverhead; ?
></td
>
436 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $free_size; ?
></td
>
437 <td
class="print"><?php
echo $free_unit; ?
></td
>
440 <td
class="print" style
="padding-right: 10px"><?php
echo $strEffective; ?
></td
>
441 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $effect_size; ?
></td
>
442 <td
class="print"><?php
echo $effect_unit; ?
></td
>
446 if (isset($tot_size) && $mergetable == FALSE) {
450 <td
class="print" style
="padding-right: 10px"><?php
echo $strTotalUC; ?
></td
>
451 <td align
="right" class="print" nowrap
="nowrap"><?php
echo $tot_size; ?
></td
>
452 <td
class="print"><?php
echo $tot_unit; ?
></td
>
461 <td width
="20" class="print"> 
;</td
>
463 <!-- Rows Statistic
-->
465  
;<big
><?php
echo $strRowsStatistic . ':'; ?
></big
>
466 <table width
=100% bordercolorlight
="black" border
="border" style
="border-collapse: collapse; background-color: white">
468 <th
><?php
echo $strStatement; ?
></th
>
469 <th align
="center"><?php
echo $strValue; ?
></th
>
473 if (isset($showtable['Row_format'])) {
474 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
478 <td
class="print"><?php
echo ucfirst($strFormat); ?
></td
>
479 <td align
="<?php echo $cell_align_left; ?>" class="print" nowrap
="nowrap">
482 if ($showtable['Row_format'] == 'Fixed') {
484 } else if ($showtable['Row_format'] == 'Dynamic') {
487 echo $showtable['Row_format'];
495 if (isset($showtable['Rows'])) {
496 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
500 <td
class="print"><?php
echo ucfirst($strRows); ?
></td
>
501 <td align
="right" class="print" nowrap
="nowrap">
502 <?php
echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
507 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
508 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
512 <td
class="print"><?php
echo ucfirst($strRowLength); ?
> 
;ø
;</td
>
513 <td
class="print" nowrap
="nowrap">
514 <?php
echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
519 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
520 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
524 <td
class="print"><?php
echo ucfirst($strRowSize); ?
> 
;ø
;</td
>
525 <td align
="right" class="print" nowrap
="nowrap">
526 <?php
echo $avg_size . ' ' . $avg_unit . "\n"; ?
>
531 if (isset($showtable['Auto_increment'])) {
532 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
536 <td
class="print"><?php
echo ucfirst($strNext); ?
> 
;Autoindex
</td
>
537 <td align
="right" class="print" nowrap
="nowrap">
538 <?php
echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?
>
545 if (isset($showtable['Create_time'])) {
546 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
550 <td
class="print"><?php
echo $strStatCreateTime; ?
></td
>
551 <td align
="right" class="print" nowrap
="nowrap">
552 <?php
echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?
>
559 if (isset($showtable['Update_time'])) {
560 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
564 <td
class="print"><?php
echo $strStatUpdateTime; ?
></td
>
565 <td align
="right" class="print" nowrap
="nowrap">
566 <?php
echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?
>
573 if (isset($showtable['Check_time'])) {
574 $bgcolor = ((++
$i%2
) ?
$cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
578 <td
class="print"><?php
echo $strStatCheckTime; ?
></td
>
579 <td align
="right" class="print" nowrap
="nowrap">
580 <?php
echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?
>
593 } // end if ($nonisam == FALSE)
594 } // end if ($cfg['ShowStats'])
600 unset($show_comment);
601 echo '<hr />' . "\n";
603 echo '</div>' . "\n";
610 * Displays the footer
614 <script type
="text/javascript" language
="javascript1.2">
618 document
.getElementById('print').style
.visibility
= 'hidden';
620 if (typeof(window
.print) != 'undefined') {
623 document
.getElementById('print').style
.visibility
= '';
628 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
630 require_once('./footer.inc.php');