patch #1198492, current version check
[phpmyadmin/crack.git] / db_datadict.php
blob5ee1af9779038063de22de665cf2173f6d50678e
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 require_once('./libraries/grab_globals.lib.php');
10 require_once('./header.inc.php');
14 /**
15 * Gets the relations settings
17 require_once('./libraries/relation.lib.php');
18 require_once('./libraries/transformations.lib.php');
20 $cfgRelation = PMA_getRelationsParam();
22 /**
23 * Check parameters
25 PMA_checkParameters(array('db'));
27 /**
28 * Defines the url to return to in case of error in a sql statement
30 if (isset($table)) {
31 $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
32 } else {
33 $err_url = 'db_details.php?' . PMA_generate_common_url($db);
36 if ($cfgRelation['commwork']) {
37 $comment = PMA_getComments($db);
39 /**
40 * Displays DB comment
42 if (is_array($comment)) {
44 <!-- DB comment -->
45 <p><?php echo $strDBComment; ?> <i>
46 <?php echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?>
47 </i></p>
48 <?php
49 } // end if
52 /**
53 * Selects the database and gets tables names
55 PMA_DBI_select_db($db);
56 $rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE);
58 $count = 0;
59 while ($row = PMA_DBI_fetch_assoc($rowset)) {
60 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
61 $table = $row[$myfieldname];
62 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
63 $comments = PMA_getComments($db, $table);
66 if ($count != 0) {
67 echo '<div style="page-break-before: always;">' . "\n";
68 } else {
69 echo '<div>' . "\n";
72 echo '<h2>' . $table . '</h2>' . "\n";
74 /**
75 * Gets table informations
77 // The 'show table' statement works correct since 3.23.03
78 $result = PMA_DBI_query('SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'', NULL, PMA_DBI_QUERY_STORE);
79 $showtable = PMA_DBI_fetch_assoc($result);
80 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
81 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
82 PMA_DBI_free_result($result);
85 /**
86 * Gets table keys and retains them
89 PMA_DBI_select_db($db);
90 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
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_DBI_fetch_assoc($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'];
117 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
119 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
120 if (isset($row['Sub_part'])) {
121 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
124 } // end while
125 if ($result) {
126 PMA_DBI_free_result($result);
131 * Gets fields properties
133 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', NULL, PMA_DBI_QUERY_STORE);
134 $fields_cnt = PMA_DBI_num_rows($result);
135 // Check if we can use Relations (Mike Beck)
136 if (!empty($cfgRelation['relation'])) {
137 // Find which tables are related with the current one and write it in
138 // an array
139 $res_rel = PMA_getForeigners($db, $table);
141 if (count($res_rel) > 0) {
142 $have_rel = TRUE;
143 } else {
144 $have_rel = FALSE;
147 else {
148 $have_rel = FALSE;
149 } // end if
153 * Displays the comments of the table if MySQL >= 3.23
155 if (!empty($show_comment)) {
156 echo $strTableComments . ':&nbsp;' . $show_comment . '<br /><br />';
160 * Displays the table structure
164 <!-- TABLE INFORMATIONS -->
165 <table width="100%" style="border: 1px solid black; border-collapse: collapse; background-color: white;">
166 <tr>
167 <th width="50"><?php echo $strField; ?></th>
168 <th width="80"><?php echo $strType; ?></th>
169 <!--<th width="50"><?php echo $strAttr; ?></th>-->
170 <th width="40"><?php echo $strNull; ?></th>
171 <th width="70"><?php echo $strDefault; ?></th>
172 <!--<th width="50"><?php echo $strExtra; ?></th>-->
173 <?php
174 echo "\n";
175 if ($have_rel) {
176 echo ' <th>' . $strLinksTo . '</th>' . "\n";
178 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
179 echo ' <th>' . $strComments . '</th>' . "\n";
181 if ($cfgRelation['mimework']) {
182 echo ' <th>MIME</th>' . "\n";
185 </tr>
187 <?php
188 $i = 0;
189 while ($row = PMA_DBI_fetch_assoc($result)) {
190 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
191 $i++;
193 $type = $row['Type'];
194 // reformat mysql query output - staybyte - 9. June 2001
195 // loic1: set or enum types: slashes single quotes inside options
196 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
197 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
198 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
199 $type_nowrap = '';
201 $binary = 0;
202 $unsigned = 0;
203 $zerofill = 0;
204 } else {
205 $binary = stristr($row['Type'], 'binary');
206 $unsigned = stristr($row['Type'], 'unsigned');
207 $zerofill = stristr($row['Type'], 'zerofill');
208 $type_nowrap = ' nowrap="nowrap"';
209 $type = preg_replace('@BINARY@i', '', $type);
210 $type = preg_replace('@ZEROFILL@i', '', $type);
211 $type = preg_replace('@UNSIGNED@i', '', $type);
212 if (empty($type)) {
213 $type = '&nbsp;';
216 $strAttribute = '&nbsp;';
217 if ($binary) {
218 $strAttribute = 'BINARY';
220 if ($unsigned) {
221 $strAttribute = 'UNSIGNED';
223 if ($zerofill) {
224 $strAttribute = 'UNSIGNED ZEROFILL';
226 if (!isset($row['Default'])) {
227 if ($row['Null'] != '') {
228 $row['Default'] = '<i>NULL</i>';
230 } else {
231 $row['Default'] = htmlspecialchars($row['Default']);
233 $field_name = htmlspecialchars($row['Field']);
234 echo "\n";
236 <tr>
237 <td width=50 class='print' nowrap="nowrap">
238 <?php
239 echo "\n";
240 if (isset($pk_array[$row['Field']])) {
241 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
242 } else {
243 echo ' ' . $field_name . '&nbsp;' . "\n";
246 </td>
247 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
248 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
249 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
250 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
251 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
252 <?php
253 echo "\n";
254 if ($have_rel) {
255 echo ' <td class="print">';
256 if (isset($res_rel[$field_name])) {
257 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
259 echo '&nbsp;</td>' . "\n";
261 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
262 echo ' <td class="print">';
263 if (isset($comments[$field_name])) {
264 echo htmlspecialchars($comments[$field_name]);
266 echo '&nbsp;</td>' . "\n";
268 if ($cfgRelation['mimework']) {
269 $mime_map = PMA_getMIME($db, $table, true);
271 echo ' <td class="print">';
272 if (isset($mime_map[$field_name])) {
273 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
275 echo '&nbsp;</td>' . "\n";
278 </tr>
279 <?php
280 } // end while
281 PMA_DBI_free_result($result);
283 echo "\n";
285 </table>
287 <?php
288 echo '</div>' . "\n";
290 $count++;
291 } //ends main while
295 * Displays the footer
297 echo "\n";
299 <script type="text/javascript" language="javascript1.2">
300 <!--
301 function printPage()
303 document.getElementById('print').style.visibility = 'hidden';
304 // Do print the page
305 if (typeof(window.print) != 'undefined') {
306 window.print();
308 document.getElementById('print').style.visibility = '';
310 //-->
311 </script>
312 <?php
313 echo '<br /><br />&nbsp;<input type="button" style="width: 100px; height: 25px;" id="print" value="' . $strPrint . '" onclick="printPage()" />' . "\n";
315 require_once('./footer.inc.php');