update
[phpmyadmin/crack.git] / db_datadict.php3
blobfd3d07a6b6e254e6b9ecb17b2535a99f3a681abb
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'];
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'];
135 } // end while
136 if ($result) {
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
151 // an array
152 $res_rel = PMA_getForeigners($db, $table);
154 if (count($res_rel) > 0) {
155 $have_rel = TRUE;
156 } else {
157 $have_rel = FALSE;
160 else {
161 $have_rel = FALSE;
162 } // end if
166 * Displays the comments of the table if MySQL >= 3.23
168 if (!empty($show_comment)) {
169 echo $strTableComments . '&nbsp;:&nbsp;' . $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">
179 <tr>
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>-->
186 <?php
187 echo "\n";
188 if ($have_rel) {
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";
198 </tr>
200 <?php
201 $i = 0;
202 while ($row = PMA_mysql_fetch_array($result)) {
203 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
204 $i++;
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]) . ')';
212 $type_nowrap = '';
214 $binary = 0;
215 $unsigned = 0;
216 $zerofill = 0;
217 } else {
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);
225 if (empty($type)) {
226 $type = '&nbsp;';
229 $strAttribute = '&nbsp;';
230 if ($binary) {
231 $strAttribute = 'BINARY';
233 if ($unsigned) {
234 $strAttribute = 'UNSIGNED';
236 if ($zerofill) {
237 $strAttribute = 'UNSIGNED ZEROFILL';
239 if (!isset($row['Default'])) {
240 if ($row['Null'] != '') {
241 $row['Default'] = '<i>NULL</i>';
243 } else {
244 $row['Default'] = htmlspecialchars($row['Default']);
246 $field_name = htmlspecialchars($row['Field']);
247 echo "\n";
249 <tr>
250 <td width=50 class='print' nowrap="nowrap">
251 <?php
252 echo "\n";
253 if (isset($pk_array[$row['Field']])) {
254 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
255 } else {
256 echo ' ' . $field_name . '&nbsp;' . "\n";
259 </td>
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); ?>&nbsp;</td>
263 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
264 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
265 <?php
266 echo "\n";
267 if ($have_rel) {
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 '&nbsp;</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 '&nbsp;</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 '&nbsp;</td>' . "\n";
291 </tr>
292 <?php
293 } // end while
294 mysql_free_result($result);
296 echo "\n";
298 </table>
300 <?php
301 echo '</div>' . "\n";
303 $count++;
304 } //ends main while
308 * Displays the footer
310 echo "\n";
312 <script type="text/javascript" language="javascript1.2">
313 <!--
314 function printPage()
316 document.all.print.style.visibility = 'hidden';
317 // Do print the page
318 if (typeof(window.print) != 'undefined') {
319 window.print();
321 document.all.print.style.visibility = '';
323 //-->
324 </script>
325 <?php
326 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
328 require('./footer.inc.php3');