aspect ratio
[phpmyadmin/crack.git] / db_datadict.php3
blobe02d2ac08a5d377696a5a05f8283a9e73246a2c1
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();
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.php3?' . PMA_generate_common_url($db, $table);
32 } else {
33 $err_url = 'db_details.php3?' . 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_mysql_select_db($db);
56 $sql = 'SHOW TABLES FROM ' . PMA_backquote($db);
57 $rowset = @PMA_mysql_query($sql);
59 if (!$rowset) {
60 exit();
62 $count = 0;
63 while ($row = mysql_fetch_array($rowset)) {
64 if (PMA_MYSQL_INT_VERSION >= 32303) {
65 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
67 else {
68 $myfieldname = 'Tables in ' . htmlspecialchars($db);
70 $table = $row[$myfieldname];
71 if ($cfgRelation['commwork']) {
72 $comments = PMA_getComments($db, $table);
75 if ($count != 0) {
76 echo '<div style="page-break-before: always">' . "\n";
78 echo '<h1>' . $table . '</h1>' . "\n";
80 /**
81 * Gets table informations
83 // The 'show table' statement works correct since 3.23.03
84 if (PMA_MYSQL_INT_VERSION >= 32303) {
85 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
86 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
87 $showtable = PMA_mysql_fetch_array($result);
88 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
89 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
90 } else {
91 $local_query = 'SELECT COUNT(*) AS count FROM ' . PMA_backquote($table);
92 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
93 $showtable = array();
94 $num_rows = PMA_mysql_result($result, 0, 'count');
95 $show_comment = '';
96 } // end display comments
97 if ($result) {
98 mysql_free_result($result);
103 * Gets table keys and retains them
105 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
106 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
107 $primary = '';
108 $indexes = array();
109 $lastIndex = '';
110 $indexes_info = array();
111 $indexes_data = array();
112 $pk_array = array(); // will be use to emphasis prim. keys in the table
113 // view
114 while ($row = PMA_mysql_fetch_array($result)) {
115 // Backups the list of primary keys
116 if ($row['Key_name'] == 'PRIMARY') {
117 $primary .= $row['Column_name'] . ', ';
118 $pk_array[$row['Column_name']] = 1;
120 // Retains keys informations
121 if ($row['Key_name'] != $lastIndex ){
122 $indexes[] = $row['Key_name'];
123 $lastIndex = $row['Key_name'];
125 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
126 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
127 if (isset($row['Cardinality'])) {
128 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
130 // I don't know what does following column mean....
131 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
133 if (PMA_MYSQL_INT_VERSION >= 32300) {
134 // rabus: The 'Comment' field was added in MySQL 3.23.0.
135 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
138 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
139 if (isset($row['Sub_part'])) {
140 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
143 } // end while
144 if ($result) {
145 mysql_free_result($result);
150 * Gets fields properties
152 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
153 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
154 $fields_cnt = mysql_num_rows($result);
156 // Check if we can use Relations (Mike Beck)
157 if (!empty($cfgRelation['relation'])) {
158 // Find which tables are related with the current one and write it in
159 // an array
160 $res_rel = PMA_getForeigners($db, $table);
162 if (count($res_rel) > 0) {
163 $have_rel = TRUE;
164 } else {
165 $have_rel = FALSE;
168 else {
169 $have_rel = FALSE;
170 } // end if
174 * Displays the comments of the table if MySQL >= 3.23
176 if (!empty($show_comment)) {
177 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
181 * Displays the table structure
185 <!-- TABLE INFORMATIONS -->
186 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse;background-color: white">
187 <tr>
188 <th width="50"><?php echo $strField; ?></th>
189 <th width="80"><?php echo $strType; ?></th>
190 <!--<th width="50"><?php echo $strAttr; ?></th>-->
191 <th width="40"><?php echo $strNull; ?></th>
192 <th width="70"><?php echo $strDefault; ?></th>
193 <!--<th width="50"><?php echo $strExtra; ?></th>-->
194 <?php
195 echo "\n";
196 if ($have_rel) {
197 echo ' <th>' . $strLinksTo . '</th>' . "\n";
199 if ($cfgRelation['commwork']) {
200 echo ' <th>' . $strComments . '</th>' . "\n";
202 if ($cfgRelation['mimework']) {
203 echo ' <th>MIME</th>' . "\n";
206 </tr>
208 <?php
209 $i = 0;
210 while ($row = PMA_mysql_fetch_array($result)) {
211 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
212 $i++;
214 $type = $row['Type'];
215 // reformat mysql query output - staybyte - 9. June 2001
216 // loic1: set or enum types: slashes single quotes inside options
217 if (eregi('^(set|enum)\((.+)\)$', $type, $tmp)) {
218 $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1);
219 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
220 $type_nowrap = '';
222 $binary = 0;
223 $unsigned = 0;
224 $zerofill = 0;
225 } else {
226 $binary = eregi('BINARY', $row['Type'], $test);
227 $unsigned = eregi('UNSIGNED', $row['Type'], $test);
228 $zerofill = eregi('ZEROFILL', $row['Type'], $test);
229 $type_nowrap = ' nowrap="nowrap"';
230 $type = eregi_replace('BINARY', '', $type);
231 $type = eregi_replace('ZEROFILL', '', $type);
232 $type = eregi_replace('UNSIGNED', '', $type);
233 if (empty($type)) {
234 $type = '&nbsp;';
237 $strAttribute = '&nbsp;';
238 if ($binary) {
239 $strAttribute = 'BINARY';
241 if ($unsigned) {
242 $strAttribute = 'UNSIGNED';
244 if ($zerofill) {
245 $strAttribute = 'UNSIGNED ZEROFILL';
247 if (!isset($row['Default'])) {
248 if ($row['Null'] != '') {
249 $row['Default'] = '<i>NULL</i>';
251 } else {
252 $row['Default'] = htmlspecialchars($row['Default']);
254 $field_name = htmlspecialchars($row['Field']);
255 echo "\n";
257 <tr>
258 <td width=50 class='print' nowrap="nowrap">
259 <?php
260 echo "\n";
261 if (isset($pk_array[$row['Field']])) {
262 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
263 } else {
264 echo ' ' . $field_name . '&nbsp;' . "\n";
267 </td>
268 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
269 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
270 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
271 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
272 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
273 <?php
274 echo "\n";
275 if ($have_rel) {
276 echo ' <td class="print">';
277 if (isset($res_rel[$field_name])) {
278 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
280 echo '&nbsp;</td>' . "\n";
282 if ($cfgRelation['commwork']) {
283 echo ' <td class="print">';
284 if (isset($comments[$field_name])) {
285 echo htmlspecialchars($comments[$field_name]);
287 echo '&nbsp;</td>' . "\n";
289 if ($cfgRelation['mimework']) {
290 $mime_map = PMA_getMIME($db, $table, true);
292 echo ' <td class="print">';
293 if (isset($mime_map[$field_name])) {
294 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
296 echo '&nbsp;</td>' . "\n";
299 </tr>
300 <?php
301 } // end while
302 mysql_free_result($result);
304 echo "\n";
306 </table>
308 <?php
309 echo '</div>' . "\n";
311 $count++;
312 } //ends main while
316 * Displays the footer
318 echo "\n";
320 <script type="text/javascript" language="javascript1.2">
321 <!--
322 function printPage()
324 document.all.print.style.visibility = 'hidden';
325 // Do print the page
326 if (typeof(window.print) != 'undefined') {
327 window.print();
329 document.all.print.style.visibility = '';
331 //-->
332 </script>
333 <?php
334 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" name="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
336 require('./footer.inc.php3');