avoid long delays
[phpmyadmin/crack.git] / db_datadict.php3
blob2c453fe447d4e9791ead75d01ff7139cd4c109cf
1 <?php
2 /* $Id$ */
5 /**
6 * Gets the variables sent or posted to this script, then displays headers
7 */
8 if (!isset($selected_tbl)) {
9 include('./libraries/grab_globals.lib.php3');
10 include('./header.inc.php3');
14 /**
15 * Gets the relations settings
17 require('./libraries/relation.lib.php3');
18 require('./libraries/transformations.lib.php3');
20 $cfgRelation = PMA_getRelationsParam();
23 /**
24 * Defines the url to return to in case of error in a sql statement
26 if (isset($table)) {
27 $err_url = 'tbl_properties.php3?' . PMA_generate_common_url($db, $table);
28 } else {
29 $err_url = 'db_details.php3?' . PMA_generate_common_url($db);
32 if ($cfgRelation['commwork']) {
33 $comment = PMA_getComments($db);
35 /**
36 * Displays DB comment
38 if (is_array($comment)) {
40 <!-- DB comment -->
41 <p><?php echo $strDBComment; ?> <i>
42 <?php echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?>
43 </i></p>
44 <?php
45 } // end if
48 /**
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);
54 $count = 0;
55 while ($row = mysql_fetch_array($rowset)) {
56 if (PMA_MYSQL_INT_VERSION >= 32303) {
57 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
59 else {
60 $myfieldname = 'Tables in ' . htmlspecialchars($db);
62 $table = $row[$myfieldname];
63 if ($cfgRelation['commwork']) {
64 $comments = PMA_getComments($db, $table);
67 if ($count != 0) {
68 echo '<div style="page-break-before: always">' . "\n";
70 echo '<h1>' . $table . '</h1>' . "\n";
72 /**
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'] : '');
82 } else {
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);
85 $showtable = array();
86 $num_rows = PMA_mysql_result($result, 0, 'count');
87 $show_comment = '';
88 } // end display comments
89 if ($result) {
90 mysql_free_result($result);
94 /**
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);
99 $primary = '';
100 $indexes = array();
101 $lastIndex = '';
102 $indexes_info = array();
103 $indexes_data = array();
104 $pk_array = array(); // will be use to emphasis prim. keys in the table
105 // view
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'];
131 } // end while
132 if ($result) {
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
147 // an array
148 $res_rel = PMA_getForeigners($db, $table);
150 if (count($res_rel) > 0) {
151 $have_rel = TRUE;
152 } else {
153 $have_rel = FALSE;
156 else {
157 $have_rel = FALSE;
158 } // end if
162 * Displays the comments of the table if MySQL >= 3.23
164 if (!empty($show_comment)) {
165 echo $strTableComments . '&nbsp;:&nbsp;' . $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">
175 <tr>
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>-->
182 <?php
183 echo "\n";
184 if ($have_rel) {
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";
194 </tr>
196 <?php
197 $i = 0;
198 while ($row = PMA_mysql_fetch_array($result)) {
199 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
200 $i++;
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]) . ')';
208 $type_nowrap = '';
210 $binary = 0;
211 $unsigned = 0;
212 $zerofill = 0;
213 } else {
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);
221 if (empty($type)) {
222 $type = '&nbsp;';
225 $strAttribute = '&nbsp;';
226 if ($binary) {
227 $strAttribute = 'BINARY';
229 if ($unsigned) {
230 $strAttribute = 'UNSIGNED';
232 if ($zerofill) {
233 $strAttribute = 'UNSIGNED ZEROFILL';
235 if (!isset($row['Default'])) {
236 if ($row['Null'] != '') {
237 $row['Default'] = '<i>NULL</i>';
239 } else {
240 $row['Default'] = htmlspecialchars($row['Default']);
242 $field_name = htmlspecialchars($row['Field']);
243 echo "\n";
245 <tr>
246 <td width=50 class='print' nowrap="nowrap">
247 <?php
248 echo "\n";
249 if (isset($pk_array[$row['Field']])) {
250 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
251 } else {
252 echo ' ' . $field_name . '&nbsp;' . "\n";
255 </td>
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); ?>&nbsp;</td>
259 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
260 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
261 <?php
262 echo "\n";
263 if ($have_rel) {
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 '&nbsp;</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 '&nbsp;</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 '&nbsp;</td>' . "\n";
287 </tr>
288 <?php
289 } // end while
290 mysql_free_result($result);
292 echo "\n";
294 </table>
296 <?php
297 echo '</div>' . "\n";
299 $count++;
300 } //ends main while
304 * Displays the footer
306 echo "\n";
308 <script type="text/javascript" language="javascript1.2">
309 <!--
310 function printPage()
312 document.all.print.style.visibility = 'hidden';
313 // Do print the page
314 if (typeof(window.print) != 'undefined') {
315 window.print();
317 document.all.print.style.visibility = '';
319 //-->
320 </script>
321 <?php
322 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
324 require('./footer.inc.php3');