Another Acknowledgements page update (fix for previous commit)
[openemr.git] / phpmyadmin / db_datadict.php
blob9d35f504e7429f9c41f86b3f9cea21c923cba023
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
9 * Gets the variables sent or posted to this script, then displays headers
11 require_once './libraries/common.inc.php';
13 if (!isset($selected_tbl)) {
14 require_once './libraries/header.inc.php';
18 /**
19 * Gets the relations settings
21 require_once './libraries/relation.lib.php';
22 require_once './libraries/transformations.lib.php';
24 $cfgRelation = PMA_getRelationsParam();
26 /**
27 * Check parameters
29 PMA_checkParameters(array('db'));
31 /**
32 * Defines the url to return to in case of error in a sql statement
34 if (strlen($table)) {
35 $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table);
36 } else {
37 $err_url = 'db_sql.php?' . PMA_generate_common_url($db);
40 if ($cfgRelation['commwork']) {
41 $comment = PMA_getComments($db);
43 /**
44 * Displays DB comment
46 if (is_array($comment)) {
48 <p> <?php echo $strDBComment; ?>
49 <i><?php echo htmlspecialchars(implode(' ', $comment)); ?></i></p>
50 <?php
51 } // end if
54 /**
55 * Selects the database and gets tables names
57 PMA_DBI_select_db($db);
58 $rowset = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($db) . ';', null, PMA_DBI_QUERY_STORE);
60 $count = 0;
61 while ($row = PMA_DBI_fetch_assoc($rowset)) {
62 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
63 $table = $row[$myfieldname];
64 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
65 $comments = PMA_getComments($db, $table);
68 if ($count != 0) {
69 echo '<div style="page-break-before: always;">' . "\n";
70 } else {
71 echo '<div>' . "\n";
74 echo '<h2>' . $table . '</h2>' . "\n";
76 /**
77 * Gets table informations
79 // The 'show table' statement works correct since 3.23.03
80 $showtable = PMA_DBI_get_tables_full($db, $table);
81 $num_rows = (isset($showtable[$table]['TABLE_ROWS']) ? $showtable[$table]['TABLE_ROWS'] : 0);
82 $show_comment = (isset($showtable[$table]['TABLE_COMMENT']) ? $showtable[$table]['TABLE_COMMENT'] : '');
83 unset($showtable);
86 /**
87 * Gets table keys and retains them
90 PMA_DBI_select_db($db);
91 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
92 $primary = '';
93 $indexes = array();
94 $lastIndex = '';
95 $indexes_info = array();
96 $indexes_data = array();
97 $pk_array = array(); // will be use to emphasis prim. keys in the table
98 // view
99 while ($row = PMA_DBI_fetch_assoc($result)) {
100 // Backups the list of primary keys
101 if ($row['Key_name'] == 'PRIMARY') {
102 $primary .= $row['Column_name'] . ', ';
103 $pk_array[$row['Column_name']] = 1;
105 // Retains keys informations
106 if ($row['Key_name'] != $lastIndex){
107 $indexes[] = $row['Key_name'];
108 $lastIndex = $row['Key_name'];
110 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
111 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
112 if (isset($row['Cardinality'])) {
113 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
115 // I don't know what does following column mean....
116 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
118 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
120 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
121 if (isset($row['Sub_part'])) {
122 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
125 } // end while
126 if ($result) {
127 PMA_DBI_free_result($result);
132 * Gets fields properties
134 $result = PMA_DBI_query('SHOW FIELDS FROM ' . PMA_backquote($table) . ';', null, PMA_DBI_QUERY_STORE);
135 $fields_cnt = PMA_DBI_num_rows($result);
138 // We need this to correctly learn if a TIMESTAMP is NOT NULL, since
139 // SHOW FULL FIELDS or INFORMATION_SCHEMA incorrectly says NULL
140 // and SHOW CREATE TABLE says NOT NULL (tested
141 // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
143 $show_create_table = PMA_DBI_fetch_value(
144 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table),
145 0, 1);
146 $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
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;
159 } else {
160 $have_rel = FALSE;
161 } // end if
165 * Displays the comments of the table if MySQL >= 3.23
167 if (!empty($show_comment)) {
168 echo $strTableComments . ': ' . htmlspecialchars($show_comment) . '<br /><br />';
172 * Displays the table structure
176 <table width="100%" class="print">
177 <tr><th width="50"><?php echo $strField; ?></th>
178 <th width="80"><?php echo $strType; ?></th>
179 <?php /* <th width="50"><?php echo $strAttr; ?></th>*/ ?>
180 <th width="40"><?php echo $strNull; ?></th>
181 <th width="70"><?php echo $strDefault; ?></th>
182 <?php /* <th width="50"><?php echo $strExtra; ?></th>*/ ?>
183 <?php
184 if ($have_rel) {
185 echo ' <th>' . $strLinksTo . '</th>' . "\n";
187 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
188 echo ' <th>' . $strComments . '</th>' . "\n";
190 if ($cfgRelation['mimework']) {
191 echo ' <th>MIME</th>' . "\n";
194 </tr>
195 <?php
196 $odd_row = true;
197 while ($row = PMA_DBI_fetch_assoc($result)) {
199 $type = $row['Type'];
200 // reformat mysql query output - staybyte - 9. June 2001
201 // loic1: set or enum types: slashes single quotes inside options
202 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
203 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
204 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
205 $type_nowrap = '';
207 $binary = 0;
208 $unsigned = 0;
209 $zerofill = 0;
210 } else {
211 $binary = stristr($row['Type'], 'binary');
212 $unsigned = stristr($row['Type'], 'unsigned');
213 $zerofill = stristr($row['Type'], 'zerofill');
214 $type_nowrap = ' nowrap="nowrap"';
215 $type = preg_replace('@BINARY@i', '', $type);
216 $type = preg_replace('@ZEROFILL@i', '', $type);
217 $type = preg_replace('@UNSIGNED@i', '', $type);
218 if (empty($type)) {
219 $type = ' ';
222 $strAttribute = ' ';
223 if ($binary) {
224 $strAttribute = 'BINARY';
226 if ($unsigned) {
227 $strAttribute = 'UNSIGNED';
229 if ($zerofill) {
230 $strAttribute = 'UNSIGNED ZEROFILL';
232 if (!isset($row['Default'])) {
233 if ($row['Null'] != '' && $row['Null'] != 'NO') {
234 $row['Default'] = '<i>NULL</i>';
236 } else {
237 $row['Default'] = htmlspecialchars($row['Default']);
239 $field_name = htmlspecialchars($row['Field']);
241 // here, we have a TIMESTAMP that SHOW FULL FIELDS reports as having the
242 // NULL attribute, but SHOW CREATE TABLE says the contrary. Believe
243 // the latter.
245 * @todo merge this logic with the one in tbl_structure.php
246 * or move it in a function similar to PMA_DBI_get_columns_full()
247 * but based on SHOW CREATE TABLE because information_schema
248 * cannot be trusted in this case (MySQL bug)
250 if (!empty($analyzed_sql[0]['create_table_fields'][$field_name]['type']) && $analyzed_sql[0]['create_table_fields'][$field_name]['type'] == 'TIMESTAMP' && $analyzed_sql[0]['create_table_fields'][$field_name]['timestamp_not_null']) {
251 $row['Null'] = '';
254 <tr class="<?php echo $odd_row ? 'odd' : 'even'; $odd_row = ! $odd_row; ?>">
255 <td nowrap="nowrap">
256 <?php
257 if (isset($pk_array[$row['Field']])) {
258 echo '<u>' . $field_name . '</u>';
259 } else {
260 echo $field_name;
263 </td>
264 <td<?php echo $type_nowrap; ?> xml:lang="en" dir="ltr"><?php echo $type; ?></td>
265 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $strAttribute; ?></td>*/ ?>
266 <td><?php echo (($row['Null'] == '' || $row['Null'] == 'NO') ? $strNo : $strYes); ?></td>
267 <td nowrap="nowrap"><?php if (isset($row['Default'])) { echo $row['Default']; } ?></td>
268 <?php /* <td<?php echo $type_nowrap; ?>><?php echo $row['Extra']; ?></td>*/ ?>
269 <?php
270 if ($have_rel) {
271 echo ' <td>';
272 if (isset($res_rel[$field_name])) {
273 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field']);
275 echo '</td>' . "\n";
277 if ($cfgRelation['commwork'] || PMA_MYSQL_INT_VERSION >= 40100) {
278 echo ' <td>';
279 if (isset($comments[$field_name])) {
280 echo htmlspecialchars($comments[$field_name]);
282 echo '</td>' . "\n";
284 if ($cfgRelation['mimework']) {
285 $mime_map = PMA_getMIME($db, $table, true);
287 echo ' <td>';
288 if (isset($mime_map[$field_name])) {
289 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
291 echo '</td>' . "\n";
294 </tr>
295 <?php
296 } // end while
297 PMA_DBI_free_result($result);
298 $count++;
300 </table>
301 </div>
302 <?php
303 } //ends main while
306 * Displays the footer
309 <script type="text/javascript">
310 //<![CDATA[
311 function printPage()
313 document.getElementById('print').style.visibility = 'hidden';
314 // Do print the page
315 if (typeof(window.print) != 'undefined') {
316 window.print();
318 document.getElementById('print').style.visibility = '';
320 //]]>
321 </script>
322 <?php
323 echo '<br /><br /><input type="button" id="print" value="' . $strPrint . '" onclick="printPage()" />';
325 require_once './libraries/footer.inc.php';