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 * Gets the relations settings
17 require_once('./libraries/relation.lib.php');
18 require_once('./libraries/transformations.lib.php');
20 $cfgRelation = PMA_getRelationsParam();
25 PMA_checkParameters(array('db'));
28 * Defines the url to return to in case of error in a sql statement
31 $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
33 $err_url = 'db_details.php?' . PMA_generate_common_url($db);
36 if ($cfgRelation['commwork']) {
37 $comment = PMA_getComments($db);
42 if (is_array($comment)) {
45 <p
><?php
echo $strDBComment; ?
> <i
>
46 <?php
echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?
>
53 * Selects the database and gets tables names
55 PMA_mysql_select_db($db);
56 $sql = 'SHOW TABLES FROM ' . PMA_backquote($db);
57 $rowset = @PMA_mysql_query
($sql);
63 while ($row = mysql_fetch_array($rowset)) {
64 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
65 $table = $row[$myfieldname];
66 if ($cfgRelation['commwork']) {
67 $comments = PMA_getComments($db, $table);
71 echo '<div style="page-break-before: always">' . "\n";
73 echo '<h1>' . $table . '</h1>' . "\n";
76 * Gets table informations
78 // The 'show table' statement works correct since 3.23.03
79 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
80 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
81 $showtable = PMA_mysql_fetch_array($result);
82 $num_rows = (isset($showtable['Rows']) ?
$showtable['Rows'] : 0);
83 $show_comment = (isset($showtable['Comment']) ?
$showtable['Comment'] : '');
85 mysql_free_result($result);
90 * Gets table keys and retains them
92 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
93 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
97 $indexes_info = array();
98 $indexes_data = array();
99 $pk_array = array(); // will be use to emphasis prim. keys in the table
101 while ($row = PMA_mysql_fetch_array($result)) {
102 // Backups the list of primary keys
103 if ($row['Key_name'] == 'PRIMARY') {
104 $primary .= $row['Column_name'] . ', ';
105 $pk_array[$row['Column_name']] = 1;
107 // Retains keys informations
108 if ($row['Key_name'] != $lastIndex ){
109 $indexes[] = $row['Key_name'];
110 $lastIndex = $row['Key_name'];
112 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
113 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
114 if (isset($row['Cardinality'])) {
115 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
117 // I don't know what does following column mean....
118 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
120 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
122 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
123 if (isset($row['Sub_part'])) {
124 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
129 mysql_free_result($result);
134 * Gets fields properties
136 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
137 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
138 $fields_cnt = mysql_num_rows($result);
140 // Check if we can use Relations (Mike Beck)
141 if (!empty($cfgRelation['relation'])) {
142 // Find which tables are related with the current one and write it in
144 $res_rel = PMA_getForeigners($db, $table);
146 if (count($res_rel) > 0) {
158 * Displays the comments of the table if MySQL >= 3.23
160 if (!empty($show_comment)) {
161 echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
165 * Displays the table structure
169 <!-- TABLE INFORMATIONS
-->
170 <table width
="100%" bordercolorlight
="black" border
="border" style
="border-collapse: collapse;background-color: white">
172 <th width
="50"><?php
echo $strField; ?
></th
>
173 <th width
="80"><?php
echo $strType; ?
></th
>
174 <!--<th width
="50"><?php
echo $strAttr; ?
></th
>-->
175 <th width
="40"><?php
echo $strNull; ?
></th
>
176 <th width
="70"><?php
echo $strDefault; ?
></th
>
177 <!--<th width
="50"><?php
echo $strExtra; ?
></th
>-->
181 echo ' <th>' . $strLinksTo . '</th>' . "\n";
183 if ($cfgRelation['commwork']) {
184 echo ' <th>' . $strComments . '</th>' . "\n";
186 if ($cfgRelation['mimework']) {
187 echo ' <th>MIME</th>' . "\n";
194 while ($row = PMA_mysql_fetch_array($result)) {
195 $bgcolor = ($i %
2) ?
$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
198 $type = $row['Type'];
199 // reformat mysql query output - staybyte - 9. June 2001
200 // loic1: set or enum types: slashes single quotes inside options
201 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
202 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
203 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
210 $binary = stristr($row['Type'], 'binary');
211 $unsigned = stristr($row['Type'], 'unsigned');
212 $zerofill = stristr($row['Type'], 'zerofill');
213 $type_nowrap = ' nowrap="nowrap"';
214 $type = preg_replace('@BINARY@i', '', $type);
215 $type = preg_replace('@ZEROFILL@i', '', $type);
216 $type = preg_replace('@UNSIGNED@i', '', $type);
221 $strAttribute = ' ';
223 $strAttribute = 'BINARY';
226 $strAttribute = 'UNSIGNED';
229 $strAttribute = 'UNSIGNED ZEROFILL';
231 if (!isset($row['Default'])) {
232 if ($row['Null'] != '') {
233 $row['Default'] = '<i>NULL</i>';
236 $row['Default'] = htmlspecialchars($row['Default']);
238 $field_name = htmlspecialchars($row['Field']);
242 <td width
=50 class='print' nowrap
="nowrap">
245 if (isset($pk_array[$row['Field']])) {
246 echo ' <u>' . $field_name . '</u> ' . "\n";
248 echo ' ' . $field_name . ' ' . "\n";
252 <td width
="80" class="print"<?php
echo $type_nowrap; ?
>><?php
echo $type; ?
><bdo dir
="ltr"></bdo
></td
>
253 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $strAttribute; ?
></td
>-->
254 <td width
="40" class="print"><?php
echo (($row['Null'] == '') ?
$strNo : $strYes); ?
> 
;</td
>
255 <td width
="70" class="print" nowrap
="nowrap"><?php
if (isset($row['Default'])) echo $row['Default']; ?
> 
;</td
>
256 <!--<td width
="50" bgcolor
="<?php echo $bgcolor; ?>" nowrap
="nowrap"><?php
echo $row['Extra']; ?
> 
;</td
>-->
260 echo ' <td class="print">';
261 if (isset($res_rel[$field_name])) {
262 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
264 echo ' </td>' . "\n";
266 if ($cfgRelation['commwork']) {
267 echo ' <td class="print">';
268 if (isset($comments[$field_name])) {
269 echo htmlspecialchars($comments[$field_name]);
271 echo ' </td>' . "\n";
273 if ($cfgRelation['mimework']) {
274 $mime_map = PMA_getMIME($db, $table, true);
276 echo ' <td class="print">';
277 if (isset($mime_map[$field_name])) {
278 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
280 echo ' </td>' . "\n";
286 mysql_free_result($result);
293 echo '</div>' . "\n";
300 * Displays the footer
304 <script type
="text/javascript" language
="javascript1.2">
308 document
.getElementById('print').style
.visibility
= 'hidden';
310 if (typeof(window
.print) != 'undefined') {
313 document
.getElementById('print').style
.visibility
= '';
318 echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
320 require_once('./footer.inc.php');