1 | <?php
|
---|
2 | /* $Id: db_datadict.php,v 2.5 2003/12/22 19:35:28 lem9 Exp $ */
|
---|
3 |
|
---|
4 |
|
---|
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');
|
---|
11 | }
|
---|
12 |
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Gets the relations settings
|
---|
16 | */
|
---|
17 | require_once('./libraries/relation.lib.php');
|
---|
18 | require_once('./libraries/transformations.lib.php');
|
---|
19 |
|
---|
20 | $cfgRelation = PMA_getRelationsParam();
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Check parameters
|
---|
24 | */
|
---|
25 | PMA_checkParameters(array('db'));
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Defines the url to return to in case of error in a sql statement
|
---|
29 | */
|
---|
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);
|
---|
34 | }
|
---|
35 |
|
---|
36 | if ($cfgRelation['commwork']) {
|
---|
37 | $comment = PMA_getComments($db);
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Displays DB comment
|
---|
41 | */
|
---|
42 | if (is_array($comment)) {
|
---|
43 | ?>
|
---|
44 | <!-- DB comment -->
|
---|
45 | <p><?php echo $strDBComment; ?> <i>
|
---|
46 | <?php echo htmlspecialchars(implode(' ', $comment)) . "\n"; ?>
|
---|
47 | </i></p>
|
---|
48 | <?php
|
---|
49 | } // end if
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Selects the database and gets tables names
|
---|
54 | */
|
---|
55 | PMA_mysql_select_db($db);
|
---|
56 | $sql = 'SHOW TABLES FROM ' . PMA_backquote($db);
|
---|
57 | $rowset = @PMA_mysql_query($sql);
|
---|
58 |
|
---|
59 | if (!$rowset) {
|
---|
60 | exit();
|
---|
61 | }
|
---|
62 | $count = 0;
|
---|
63 | while ($row = mysql_fetch_array($rowset)) {
|
---|
64 | $myfieldname = 'Tables_in_' . htmlspecialchars($db);
|
---|
65 | $table = $row[$myfieldname];
|
---|
66 | if ($cfgRelation['commwork']) {
|
---|
67 | $comments = PMA_getComments($db, $table);
|
---|
68 | }
|
---|
69 |
|
---|
70 | if ($count != 0) {
|
---|
71 | echo '<div style="page-break-before: always">' . "\n";
|
---|
72 | }
|
---|
73 | echo '<h1>' . $table . '</h1>' . "\n";
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Gets table informations
|
---|
77 | */
|
---|
78 | // The 'show table' statement works correct since 3.23.03
|
---|
79 | $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
|
---|
80 | $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
|
---|
81 | $showtable = PMA_mysql_fetch_array($result);
|
---|
82 | $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
|
---|
83 | $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
|
---|
84 | if ($result) {
|
---|
85 | mysql_free_result($result);
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Gets table keys and retains them
|
---|
91 | */
|
---|
92 | $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
|
---|
93 | $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
|
---|
94 | $primary = '';
|
---|
95 | $indexes = array();
|
---|
96 | $lastIndex = '';
|
---|
97 | $indexes_info = array();
|
---|
98 | $indexes_data = array();
|
---|
99 | $pk_array = array(); // will be use to emphasis prim. keys in the table
|
---|
100 | // view
|
---|
101 | while ($row = PMA_mysql_fetch_array($result)) {
|
---|
102 | // Backups the list of primary keys
|
---|
103 | if ($row['Key_name'] == 'PRIMARY') {
|
---|
104 | $primary .= $row['Column_name'] . ', ';
|
---|
105 | $pk_array[$row['Column_name']] = 1;
|
---|
106 | }
|
---|
107 | // Retains keys informations
|
---|
108 | if ($row['Key_name'] != $lastIndex ){
|
---|
109 | $indexes[] = $row['Key_name'];
|
---|
110 | $lastIndex = $row['Key_name'];
|
---|
111 | }
|
---|
112 | $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
|
---|
113 | $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
|
---|
114 | if (isset($row['Cardinality'])) {
|
---|
115 | $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
|
---|
116 | }
|
---|
117 | // I don't know what does following column mean....
|
---|
118 | // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
|
---|
119 |
|
---|
120 | $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
|
---|
121 |
|
---|
122 | $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
|
---|
123 | if (isset($row['Sub_part'])) {
|
---|
124 | $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
|
---|
125 | }
|
---|
126 |
|
---|
127 | } // end while
|
---|
128 | if ($result) {
|
---|
129 | mysql_free_result($result);
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Gets fields properties
|
---|
135 | */
|
---|
136 | $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
|
---|
137 | $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
|
---|
138 | $fields_cnt = mysql_num_rows($result);
|
---|
139 |
|
---|
140 | // Check if we can use Relations (Mike Beck)
|
---|
141 | if (!empty($cfgRelation['relation'])) {
|
---|
142 | // Find which tables are related with the current one and write it in
|
---|
143 | // an array
|
---|
144 | $res_rel = PMA_getForeigners($db, $table);
|
---|
145 |
|
---|
146 | if (count($res_rel) > 0) {
|
---|
147 | $have_rel = TRUE;
|
---|
148 | } else {
|
---|
149 | $have_rel = FALSE;
|
---|
150 | }
|
---|
151 | }
|
---|
152 | else {
|
---|
153 | $have_rel = FALSE;
|
---|
154 | } // end if
|
---|
155 |
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Displays the comments of the table if MySQL >= 3.23
|
---|
159 | */
|
---|
160 | if (!empty($show_comment)) {
|
---|
161 | echo $strTableComments . ' : ' . $show_comment . '<br /><br />';
|
---|
162 | }
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Displays the table structure
|
---|
166 | */
|
---|
167 | ?>
|
---|
168 |
|
---|
169 | <!-- TABLE INFORMATIONS -->
|
---|
170 | <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse;background-color: white">
|
---|
171 | <tr>
|
---|
172 | <th width="50"><?php echo $strField; ?></th>
|
---|
173 | <th width="80"><?php echo $strType; ?></th>
|
---|
174 | <!--<th width="50"><?php echo $strAttr; ?></th>-->
|
---|
175 | <th width="40"><?php echo $strNull; ?></th>
|
---|
176 | <th width="70"><?php echo $strDefault; ?></th>
|
---|
177 | <!--<th width="50"><?php echo $strExtra; ?></th>-->
|
---|
178 | <?php
|
---|
179 | echo "\n";
|
---|
180 | if ($have_rel) {
|
---|
181 | echo ' <th>' . $strLinksTo . '</th>' . "\n";
|
---|
182 | }
|
---|
183 | if ($cfgRelation['commwork']) {
|
---|
184 | echo ' <th>' . $strComments . '</th>' . "\n";
|
---|
185 | }
|
---|
186 | if ($cfgRelation['mimework']) {
|
---|
187 | echo ' <th>MIME</th>' . "\n";
|
---|
188 | }
|
---|
189 | ?>
|
---|
190 | </tr>
|
---|
191 |
|
---|
192 | <?php
|
---|
193 | $i = 0;
|
---|
194 | while ($row = PMA_mysql_fetch_array($result)) {
|
---|
195 | $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
|
---|
196 | $i++;
|
---|
197 |
|
---|
198 | $type = $row['Type'];
|
---|
199 | // reformat mysql query output - staybyte - 9. June 2001
|
---|
200 | // loic1: set or enum types: slashes single quotes inside options
|
---|
201 | if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
|
---|
202 | $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
|
---|
203 | $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
|
---|
204 | $type_nowrap = '';
|
---|
205 |
|
---|
206 | $binary = 0;
|
---|
207 | $unsigned = 0;
|
---|
208 | $zerofill = 0;
|
---|
209 | } else {
|
---|
210 | $binary = stristr($row['Type'], 'binary');
|
---|
211 | $unsigned = stristr($row['Type'], 'unsigned');
|
---|
212 | $zerofill = stristr($row['Type'], 'zerofill');
|
---|
213 | $type_nowrap = ' nowrap="nowrap"';
|
---|
214 | $type = preg_replace('@BINARY@i', '', $type);
|
---|
215 | $type = preg_replace('@ZEROFILL@i', '', $type);
|
---|
216 | $type = preg_replace('@UNSIGNED@i', '', $type);
|
---|
217 | if (empty($type)) {
|
---|
218 | $type = ' ';
|
---|
219 | }
|
---|
220 | }
|
---|
221 | $strAttribute = ' ';
|
---|
222 | if ($binary) {
|
---|
223 | $strAttribute = 'BINARY';
|
---|
224 | }
|
---|
225 | if ($unsigned) {
|
---|
226 | $strAttribute = 'UNSIGNED';
|
---|
227 | }
|
---|
228 | if ($zerofill) {
|
---|
229 | $strAttribute = 'UNSIGNED ZEROFILL';
|
---|
230 | }
|
---|
231 | if (!isset($row['Default'])) {
|
---|
232 | if ($row['Null'] != '') {
|
---|
233 | $row['Default'] = '<i>NULL</i>';
|
---|
234 | }
|
---|
235 | } else {
|
---|
236 | $row['Default'] = htmlspecialchars($row['Default']);
|
---|
237 | }
|
---|
238 | $field_name = htmlspecialchars($row['Field']);
|
---|
239 | echo "\n";
|
---|
240 | ?>
|
---|
241 | <tr>
|
---|
242 | <td width=50 class='print' nowrap="nowrap">
|
---|
243 | <?php
|
---|
244 | echo "\n";
|
---|
245 | if (isset($pk_array[$row['Field']])) {
|
---|
246 | echo ' <u>' . $field_name . '</u> ' . "\n";
|
---|
247 | } else {
|
---|
248 | echo ' ' . $field_name . ' ' . "\n";
|
---|
249 | }
|
---|
250 | ?>
|
---|
251 | </td>
|
---|
252 | <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
|
---|
253 | <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
|
---|
254 | <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?> </td>
|
---|
255 | <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?> </td>
|
---|
256 | <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?> </td>-->
|
---|
257 | <?php
|
---|
258 | echo "\n";
|
---|
259 | if ($have_rel) {
|
---|
260 | echo ' <td class="print">';
|
---|
261 | if (isset($res_rel[$field_name])) {
|
---|
262 | echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
|
---|
263 | }
|
---|
264 | echo ' </td>' . "\n";
|
---|
265 | }
|
---|
266 | if ($cfgRelation['commwork']) {
|
---|
267 | echo ' <td class="print">';
|
---|
268 | if (isset($comments[$field_name])) {
|
---|
269 | echo htmlspecialchars($comments[$field_name]);
|
---|
270 | }
|
---|
271 | echo ' </td>' . "\n";
|
---|
272 | }
|
---|
273 | if ($cfgRelation['mimework']) {
|
---|
274 | $mime_map = PMA_getMIME($db, $table, true);
|
---|
275 |
|
---|
276 | echo ' <td class="print">';
|
---|
277 | if (isset($mime_map[$field_name])) {
|
---|
278 | echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
|
---|
279 | }
|
---|
280 | echo ' </td>' . "\n";
|
---|
281 | }
|
---|
282 | ?>
|
---|
283 | </tr>
|
---|
284 | <?php
|
---|
285 | } // end while
|
---|
286 | mysql_free_result($result);
|
---|
287 |
|
---|
288 | echo "\n";
|
---|
289 | ?>
|
---|
290 | </table>
|
---|
291 |
|
---|
292 | <?php
|
---|
293 | echo '</div>' . "\n";
|
---|
294 |
|
---|
295 | $count++;
|
---|
296 | } //ends main while
|
---|
297 |
|
---|
298 |
|
---|
299 | /**
|
---|
300 | * Displays the footer
|
---|
301 | */
|
---|
302 | echo "\n";
|
---|
303 | ?>
|
---|
304 | <script type="text/javascript" language="javascript1.2">
|
---|
305 | <!--
|
---|
306 | function printPage()
|
---|
307 | {
|
---|
308 | document.getElementById('print').style.visibility = 'hidden';
|
---|
309 | // Do print the page
|
---|
310 | if (typeof(window.print) != 'undefined') {
|
---|
311 | window.print();
|
---|
312 | }
|
---|
313 | document.getElementById('print').style.visibility = '';
|
---|
314 | }
|
---|
315 | //-->
|
---|
316 | </script>
|
---|
317 | <?php
|
---|
318 | echo '<br /><br /> <input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
|
---|
319 |
|
---|
320 | require_once('./footer.inc.php');
|
---|
321 | ?>
|
---|