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);
32 if ($cfgRelation['commwork']) {
33 $comment = PMA_getComments($db);
38 if (is_array($comment)) {
41 <p
><?php
echo $strDBComment; ?
> <i
>
42 <?php
echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?
>
49 * Selects the database and gets tables names
51 PMA_mysql_select_db($db);
52 $sql = 'SHOW TABLES FROM ' . PMA_backquote($db);
53 $rowset = mysql_query($sql);
55 while ($row = mysql_fetch_array($rowset)) {
56 if (PMA_MYSQL_INT_VERSION
>= 32303) {
57 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
60 $myfieldname = 'Tables in ' . htmlspecialchars($db);
62 $table = $row[$myfieldname];
63 if ($cfgRelation['commwork']) {
64 $comments = PMA_getComments($db, $table);
68 echo '<div style="page-break-before: always">' . "\n";
70 echo '<h1>' . $table . '</h1>' . "\n";
73 * Gets table informations
75 // The 'show table' statement works correct since 3.23.03
76 if (PMA_MYSQL_INT_VERSION
>= 32303) {
77 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
78 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
79 $showtable = PMA_mysql_fetch_array($result);
80 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
81 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
83 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
84 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
86 $num_rows = PMA_mysql_result($result, 0, 'count');
88 } // end display comments
90 mysql_free_result($result);
95 * Gets table keys and retains them
97 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
98 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
102 $indexes_info = array();
103 $indexes_data = array();
104 $pk_array = array(); // will be use to emphasis prim. keys in the table
106 while ($row = PMA_mysql_fetch_array($result)) {
107 // Backups the list of primary keys
108 if ($row['Key_name'] == 'PRIMARY') {
109 $primary .= $row['Column_name'] . ', ';
110 $pk_array[$row['Column_name']] = 1;
112 // Retains keys informations
113 if ($row['Key_name'] != $lastIndex ){
114 $indexes[] = $row['Key_name'];
115 $lastIndex = $row['Key_name'];
117 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
118 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
119 if (isset($row['Cardinality'])) {
120 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
122 // I don't know what does following column mean....
123 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
124 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
126 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
127 if (isset($row['Sub_part'])) {
128 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
133 mysql_free_result($result);
138 * Gets fields properties
140 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
141 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
142 $fields_cnt = mysql_num_rows($result);
144 // Check if we can use Relations (Mike Beck)
145 if (!empty($cfgRelation['relation'])) {
146 // Find which tables are related with the current one and write it in
148 $res_rel = PMA_getForeigners($db, $table);
150 if (count($res_rel) > 0) {
162 * Displays the comments of the table if MySQL >= 3.23
164 if (!empty($show_comment)) {
165 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
169 * Displays the table structure
173 <!-- TABLE INFORMATIONS
-->
174 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse;background-color: white">
176 <th width
="50"><?php
echo $strField; ?
></th
>
177 <th width
="80"><?php
echo $strType; ?
></th
>
178 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
179 <th width
="40"><?php
echo $strNull; ?
></th
>
180 <th width
="70"><?php
echo $strDefault; ?
></th
>
181 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
185 echo ' <th>' . $strLinksTo . '</th>' . "\n";
187 if ($cfgRelation['commwork']) {
188 echo ' <th>' . $strComments . '</th>' . "\n";
190 if ($cfgRelation['mimework']) {
191 echo ' <th>MIME</th>' . "\n";
198 while ($row = PMA_mysql_fetch_array($result)) {
199 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
202 $type = $row['Type'];
203 // reformat mysql query output - staybyte - 9. June 2001
204 // loic1: set or enum types: slashes single quotes inside options
205 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
206 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
207 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
214 $binary = eregi('BINARY', $row['Type'], $test);
215 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
216 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
217 $type_nowrap = ' nowrap="nowrap"';
218 $type = eregi_replace('BINARY', '', $type);
219 $type = eregi_replace('ZEROFILL', '', $type);
220 $type = eregi_replace('UNSIGNED', '', $type);
225 $strAttribute = ' ';
227 $strAttribute = 'BINARY';
230 $strAttribute = 'UNSIGNED';
233 $strAttribute = 'UNSIGNED ZEROFILL';
235 if (!isset($row['Default'])) {
236 if ($row['Null'] != '') {
237 $row['Default'] = '<i>NULL</i>';
240 $row['Default'] = htmlspecialchars($row['Default']);
242 $field_name = htmlspecialchars($row['Field']);
246 <td width
=50 class='print' nowrap
="nowrap">
249 if (isset($pk_array[$row['Field']])) {
250 echo ' <u>' . $field_name . '</u> ' . "\n";
252 echo ' ' . $field_name . ' ' . "\n";
256 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
257 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
258 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
259 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
260 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
264 echo ' <td class="print">';
265 if (isset($res_rel[$field_name])) {
266 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
268 echo ' </td>' . "\n";
270 if ($cfgRelation['commwork']) {
271 echo ' <td class="print">';
272 if (isset($comments[$field_name])) {
273 echo htmlspecialchars($comments[$field_name]);
275 echo ' </td>' . "\n";
277 if ($cfgRelation['mimework']) {
278 $mime_map = PMA_getMIME($db, $table, true);
280 echo ' <td class="print">';
281 if (isset($mime_map[$field_name])) {
282 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
284 echo ' </td>' . "\n";
290 mysql_free_result($result);
297 echo '</div>' . "\n";
304 * Displays the footer
308 <script type
="text/javascript" language
="javascript1.2">
312 document
.all
.print.style
.visibility
= 'hidden';
314 if (typeof(window
.print) != 'undefined') {
317 document
.all
.print.style
.visibility
= '';
322 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
324 require('./footer.inc.php3');