bug 619097
[phpmyadmin/crack.git] / db_datadict.php3
blob6ed18c7647bc671ce2f6fdcb1c77b2f141ac8e4d
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');
20 /**
21 * Defines the url to return to in case of error in a sql statement
23 if (isset($table)) {
24 $err_url = 'tbl_properties.php3'
25 . '?lang=' . $lang
26 . '&amp;convcharset=' . $convcharset
27 . '&amp;server=' . $server
28 . '&amp;db=' . urlencode($db)
29 . '&amp;table=' . urlencode($table);
30 } else {
31 $err_url = 'db_details.php3'
32 . '?lang=' . $lang
33 . '&amp;convcharset=' . $convcharset
34 . '&amp;server=' . $server
35 . '&amp;db=' . urlencode($db);
39 /**
40 * Selects the database and gets tables names
42 PMA_mysql_select_db($db);
43 $sql = 'SHOW TABLES FROM ' . PMA_backquote($db);
44 $rowset = mysql_query($sql);
45 $count = 0;
46 while ($row = mysql_fetch_array($rowset)) {
47 if (PMA_MYSQL_INT_VERSION >= 32303) {
48 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
50 else {
51 $myfieldname = 'Tables in ' . htmlspecialchars($db);
53 $table = $row[$myfieldname];
54 $cfgRelation = PMA_getRelationsParam();
55 if ($cfgRelation['commwork']) {
56 $comments = PMA_getComments($db, $table);
59 if ($count != 0) {
60 echo '<div style="page-break-before: always">' . "\n";
62 echo '<h1>' . $table . '</h1>' . "\n";
64 /**
65 * Gets table informations
67 // The 'show table' statement works correct since 3.23.03
68 if (PMA_MYSQL_INT_VERSION >= 32303) {
69 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
70 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
71 $showtable = PMA_mysql_fetch_array($result);
72 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
73 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
74 } else {
75 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
76 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
77 $showtable = array();
78 $num_rows = PMA_mysql_result($result, 0, 'count');
79 $show_comment = '';
80 } // end display comments
81 if ($result) {
82 mysql_free_result($result);
86 /**
87 * Gets table keys and retains them
89 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
90 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
91 $primary = '';
92 $indexes = array();
93 $lastIndex = '';
94 $indexes_info = array();
95 $indexes_data = array();
96 $pk_array = array(); // will be use to emphasis prim. keys in the table
97 // view
98 while ($row = PMA_mysql_fetch_array($result)) {
99 // Backups the list of primary keys
100 if ($row['Key_name'] == 'PRIMARY') {
101 $primary .= $row['Column_name'] . ', ';
102 $pk_array[$row['Column_name']] = 1;
104 // Retains keys informations
105 if ($row['Key_name'] != $lastIndex ){
106 $indexes[] = $row['Key_name'];
107 $lastIndex = $row['Key_name'];
109 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
110 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
111 if (isset($row['Cardinality'])) {
112 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
114 // I don't know what does following column mean....
115 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
116 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
118 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
119 if (isset($row['Sub_part'])) {
120 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
123 } // end while
124 if ($result) {
125 mysql_free_result($result);
130 * Gets fields properties
132 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
133 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
134 $fields_cnt = mysql_num_rows($result);
136 // Check if we can use Relations (Mike Beck)
137 if (!empty($cfgRelation['relation'])) {
138 // Find which tables are related with the current one and write it in
139 // an array
140 $res_rel = PMA_getForeigners($db, $table);
142 if (count($res_rel) > 0) {
143 $have_rel = TRUE;
144 } else {
145 $have_rel = FALSE;
148 else {
149 $have_rel = FALSE;
150 } // end if
154 * Displays the comments of the table if MySQL >= 3.23
156 if (!empty($show_comment)) {
157 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
161 * Displays the table structure
165 <!-- TABLE INFORMATIONS -->
166 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse;background-color: white">
167 <tr>
168 <th width="50"><?php echo ucfirst($strField); ?></th>
169 <th width="50"><?php echo ucfirst($strType); ?></th>
170 <!--<th width="50"><?php echo ucfirst($strAttr); ?></th>-->
171 <th width="50"><?php echo ucfirst($strNull); ?></th>
172 <th width="50"><?php echo ucfirst($strDefault); ?></th>
173 <!--<th width="50"><?php echo ucfirst($strExtra); ?></th>-->
174 <?php
175 echo "\n";
176 if ($have_rel) {
177 echo ' <th width="50">' . ucfirst($strLinksTo) . '</th>' . "\n";
179 if ($cfgRelation['commwork']) {
180 echo ' <th width="400">' . ucfirst($strComments) . '</th>' . "\n";
183 </tr>
185 <?php
186 $i = 0;
187 while ($row = PMA_mysql_fetch_array($result)) {
188 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
189 $i++;
191 $type = $row['Type'];
192 // reformat mysql query output - staybyte - 9. June 2001
193 // loic1: set or enum types: slashes single quotes inside options
194 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
195 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
196 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
197 $type_nowrap = '';
198 } else {
199 $type_nowrap = ' nowrap="nowrap"';
201 $type = eregi_replace('BINARY', '', $type);
202 $type = eregi_replace('ZEROFILL', '', $type);
203 $type = eregi_replace('UNSIGNED', '', $type);
204 if (empty($type)) {
205 $type = '&nbsp;';
208 $binary = eregi('BINARY', $row['Type'], $test);
209 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
210 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
211 $strAttribute = '&nbsp;';
212 if ($binary) {
213 $strAttribute = 'BINARY';
215 if ($unsigned) {
216 $strAttribute = 'UNSIGNED';
218 if ($zerofill) {
219 $strAttribute = 'UNSIGNED ZEROFILL';
221 if (!isset($row['Default'])) {
222 if ($row['Null'] != '') {
223 $row['Default'] = '<i>NULL</i>';
225 } else {
226 $row['Default'] = htmlspecialchars($row['Default']);
228 $field_name = htmlspecialchars($row['Field']);
229 echo "\n";
231 <tr>
232 <td width=50 class='print' nowrap="nowrap">
233 <?php
234 echo "\n";
235 if (isset($pk_array[$row['Field']])) {
236 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
237 } else {
238 echo ' ' . $field_name . '&nbsp;' . "\n";
241 </td>
242 <td width="50" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
243 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
244 <td width="50" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
245 <td width="50" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
246 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
247 <?php
248 echo "\n";
249 if ($have_rel) {
250 echo ' <td width="50" class="print">';
251 if (isset($res_rel[$field_name])) {
252 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
254 echo '&nbsp;</td>' . "\n";
256 if ($cfgRelation['commwork']) {
257 echo ' <td width="400" class="print">';
258 if (isset($comments[$field_name])) {
259 echo htmlspecialchars($comments[$field_name]);
261 echo '&nbsp;</td>' . "\n";
264 </tr>
265 <?php
266 } // end while
267 mysql_free_result($result);
269 echo "\n";
271 </table>
273 <?php
274 echo '</div>' . "\n";
276 $count++;
277 } //ends main while
281 * Displays the footer
283 echo "\n";
285 <script type="text/javascript" language="javascript1.2">
286 <!--
287 function printPage()
289 document.all.print.style.visibility = 'hidden';
290 // Do print the page
291 if (typeof(window.print) != 'undefined') {
292 window.print();
294 document.all.print.style.visibility = '';
296 //-->
297 </script>
298 <?php
299 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
301 require('./footer.inc.php3');