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');
21 * Defines the url to return to in case of error in a sql statement
24 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
26 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
31 * Selects the database and gets tables names
33 PMA_mysql_select_db($db);
34 $sql = 'SHOW TABLES FROM ' . PMA_backquote($db);
35 $rowset = mysql_query($sql);
37 while ($row = mysql_fetch_array($rowset)) {
38 if (PMA_MYSQL_INT_VERSION
>= 32303) {
39 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
42 $myfieldname = 'Tables in ' . htmlspecialchars($db);
44 $table = $row[$myfieldname];
45 $cfgRelation = PMA_getRelationsParam();
46 if ($cfgRelation['commwork']) {
47 $comments = PMA_getComments($db, $table);
51 echo '<div style="page-break-before: always">' . "\n";
53 echo '<h1>' . $table . '</h1>' . "\n";
56 * Gets table informations
58 // The 'show table' statement works correct since 3.23.03
59 if (PMA_MYSQL_INT_VERSION
>= 32303) {
60 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
61 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
62 $showtable = PMA_mysql_fetch_array($result);
63 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
64 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
66 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
67 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
69 $num_rows = PMA_mysql_result($result, 0, 'count');
71 } // end display comments
73 mysql_free_result($result);
78 * Gets table keys and retains them
80 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
81 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
85 $indexes_info = array();
86 $indexes_data = array();
87 $pk_array = array(); // will be use to emphasis prim. keys in the table
89 while ($row = PMA_mysql_fetch_array($result)) {
90 // Backups the list of primary keys
91 if ($row['Key_name'] == 'PRIMARY') {
92 $primary .= $row['Column_name'] . ', ';
93 $pk_array[$row['Column_name']] = 1;
95 // Retains keys informations
96 if ($row['Key_name'] != $lastIndex ){
97 $indexes[] = $row['Key_name'];
98 $lastIndex = $row['Key_name'];
100 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
101 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
102 if (isset($row['Cardinality'])) {
103 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
105 // I don't know what does following column mean....
106 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
107 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
109 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
110 if (isset($row['Sub_part'])) {
111 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
116 mysql_free_result($result);
121 * Gets fields properties
123 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
124 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
125 $fields_cnt = mysql_num_rows($result);
127 // Check if we can use Relations (Mike Beck)
128 if (!empty($cfgRelation['relation'])) {
129 // Find which tables are related with the current one and write it in
131 $res_rel = PMA_getForeigners($db, $table);
133 if (count($res_rel) > 0) {
145 * Displays the comments of the table if MySQL >= 3.23
147 if (!empty($show_comment)) {
148 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
152 * Displays the table structure
156 <!-- TABLE INFORMATIONS
-->
157 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse;background-color: white">
159 <th width
="50"><?php
echo $strField; ?
></th
>
160 <th width
="80"><?php
echo $strType; ?
></th
>
161 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
162 <th width
="40"><?php
echo $strNull; ?
></th
>
163 <th width
="70"><?php
echo $strDefault; ?
></th
>
164 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
168 echo ' <th>' . $strLinksTo . '</th>' . "\n";
170 if ($cfgRelation['commwork']) {
171 echo ' <th>' . $strComments . '</th>' . "\n";
178 while ($row = PMA_mysql_fetch_array($result)) {
179 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
182 $type = $row['Type'];
183 // reformat mysql query output - staybyte - 9. June 2001
184 // loic1: set or enum types: slashes single quotes inside options
185 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
186 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
187 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
194 $binary = eregi('BINARY', $row['Type'], $test);
195 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
196 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
197 $type_nowrap = ' nowrap="nowrap"';
198 $type = eregi_replace('BINARY', '', $type);
199 $type = eregi_replace('ZEROFILL', '', $type);
200 $type = eregi_replace('UNSIGNED', '', $type);
205 $strAttribute = ' ';
207 $strAttribute = 'BINARY';
210 $strAttribute = 'UNSIGNED';
213 $strAttribute = 'UNSIGNED ZEROFILL';
215 if (!isset($row['Default'])) {
216 if ($row['Null'] != '') {
217 $row['Default'] = '<i>NULL</i>';
220 $row['Default'] = htmlspecialchars($row['Default']);
222 $field_name = htmlspecialchars($row['Field']);
226 <td width
=50 class='print' nowrap
="nowrap">
229 if (isset($pk_array[$row['Field']])) {
230 echo ' <u>' . $field_name . '</u> ' . "\n";
232 echo ' ' . $field_name . ' ' . "\n";
236 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
237 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
238 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
239 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
240 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
244 echo ' <td class="print">';
245 if (isset($res_rel[$field_name])) {
246 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
248 echo ' </td>' . "\n";
250 if ($cfgRelation['commwork']) {
251 echo ' <td class="print">';
252 if (isset($comments[$field_name])) {
253 echo htmlspecialchars($comments[$field_name]);
255 echo ' </td>' . "\n";
261 mysql_free_result($result);
268 echo '</div>' . "\n";
275 * Displays the footer
279 <script type
="text/javascript" language
="javascript1.2">
283 document
.all
.print.style
.visibility
= 'hidden';
285 if (typeof(window
.print) != 'undefined') {
288 document
.all
.print.style
.visibility
= '';
293 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
295 require('./footer.inc.php3');