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'];
125 if (PMA_MYSQL_INT_VERSION
>= 32300) {
126 // rabus: The 'Comment' field was added in MySQL 3.23.0.
127 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
130 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
131 if (isset($row['Sub_part'])) {
132 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
137 mysql_free_result($result);
142 * Gets fields properties
144 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
145 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
146 $fields_cnt = mysql_num_rows($result);
148 // Check if we can use Relations (Mike Beck)
149 if (!empty($cfgRelation['relation'])) {
150 // Find which tables are related with the current one and write it in
152 $res_rel = PMA_getForeigners($db, $table);
154 if (count($res_rel) > 0) {
166 * Displays the comments of the table if MySQL >= 3.23
168 if (!empty($show_comment)) {
169 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
173 * Displays the table structure
177 <!-- TABLE INFORMATIONS
-->
178 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse;background-color: white">
180 <th width
="50"><?php
echo $strField; ?
></th
>
181 <th width
="80"><?php
echo $strType; ?
></th
>
182 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
183 <th width
="40"><?php
echo $strNull; ?
></th
>
184 <th width
="70"><?php
echo $strDefault; ?
></th
>
185 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
189 echo ' <th>' . $strLinksTo . '</th>' . "\n";
191 if ($cfgRelation['commwork']) {
192 echo ' <th>' . $strComments . '</th>' . "\n";
194 if ($cfgRelation['mimework']) {
195 echo ' <th>MIME</th>' . "\n";
202 while ($row = PMA_mysql_fetch_array($result)) {
203 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
206 $type = $row['Type'];
207 // reformat mysql query output - staybyte - 9. June 2001
208 // loic1: set or enum types: slashes single quotes inside options
209 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
210 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
211 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
218 $binary = eregi('BINARY', $row['Type'], $test);
219 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
220 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
221 $type_nowrap = ' nowrap="nowrap"';
222 $type = eregi_replace('BINARY', '', $type);
223 $type = eregi_replace('ZEROFILL', '', $type);
224 $type = eregi_replace('UNSIGNED', '', $type);
229 $strAttribute = ' ';
231 $strAttribute = 'BINARY';
234 $strAttribute = 'UNSIGNED';
237 $strAttribute = 'UNSIGNED ZEROFILL';
239 if (!isset($row['Default'])) {
240 if ($row['Null'] != '') {
241 $row['Default'] = '<i>NULL</i>';
244 $row['Default'] = htmlspecialchars($row['Default']);
246 $field_name = htmlspecialchars($row['Field']);
250 <td width
=50 class='print' nowrap
="nowrap">
253 if (isset($pk_array[$row['Field']])) {
254 echo ' <u>' . $field_name . '</u> ' . "\n";
256 echo ' ' . $field_name . ' ' . "\n";
260 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
261 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
262 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
263 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
264 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
268 echo ' <td class="print">';
269 if (isset($res_rel[$field_name])) {
270 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
272 echo ' </td>' . "\n";
274 if ($cfgRelation['commwork']) {
275 echo ' <td class="print">';
276 if (isset($comments[$field_name])) {
277 echo htmlspecialchars($comments[$field_name]);
279 echo ' </td>' . "\n";
281 if ($cfgRelation['mimework']) {
282 $mime_map = PMA_getMIME($db, $table, true);
284 echo ' <td class="print">';
285 if (isset($mime_map[$field_name])) {
286 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
288 echo ' </td>' . "\n";
294 mysql_free_result($result);
301 echo '</div>' . "\n";
308 * Displays the footer
312 <script type
="text/javascript" language
="javascript1.2">
316 document
.all
.print.style
.visibility
= 'hidden';
318 if (typeof(window
.print) != 'undefined') {
321 document
.all
.print.style
.visibility
= '';
326 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
328 require('./footer.inc.php3');