fixed inactivity timeout failure
[openemr.git] / interface / main / myadmin / db_datadict.php
blob025e39bfd10b092b3df7991599542d62b0d2f5fc
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_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 $myfieldname = 'Tables_in_' . htmlspecialchars($db);
65 $table = $row[$myfieldname];
66 if ($cfgRelation['commwork']) {
67 $comments = PMA_getComments($db, $table);
70 if ($count != 0) {
71 echo '<div style="page-break-before: always">' . "\n";
73 echo '<h1>' . $table . '</h1>' . "\n";
75 /**
76 * Gets table informations
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);
89 /**
90 * Gets table keys and retains them
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;
107 // Retains keys informations
108 if ($row['Key_name'] != $lastIndex ){
109 $indexes[] = $row['Key_name'];
110 $lastIndex = $row['Key_name'];
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'];
117 // I don't know what does following column mean....
118 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
120 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
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'];
127 } // end while
128 if ($result) {
129 mysql_free_result($result);
134 * Gets fields properties
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);
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);
146 if (count($res_rel) > 0) {
147 $have_rel = TRUE;
148 } else {
149 $have_rel = FALSE;
152 else {
153 $have_rel = FALSE;
154 } // end if
158 * Displays the comments of the table if MySQL >= 3.23
160 if (!empty($show_comment)) {
161 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
165 * Displays the table structure
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";
183 if ($cfgRelation['commwork']) {
184 echo ' <th>' . $strComments . '</th>' . "\n";
186 if ($cfgRelation['mimework']) {
187 echo ' <th>MIME</th>' . "\n";
190 </tr>
192 <?php
193 $i = 0;
194 while ($row = PMA_mysql_fetch_array($result)) {
195 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
196 $i++;
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 = '';
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 = '&nbsp;';
221 $strAttribute = '&nbsp;';
222 if ($binary) {
223 $strAttribute = 'BINARY';
225 if ($unsigned) {
226 $strAttribute = 'UNSIGNED';
228 if ($zerofill) {
229 $strAttribute = 'UNSIGNED ZEROFILL';
231 if (!isset($row['Default'])) {
232 if ($row['Null'] != '') {
233 $row['Default'] = '<i>NULL</i>';
235 } else {
236 $row['Default'] = htmlspecialchars($row['Default']);
238 $field_name = htmlspecialchars($row['Field']);
239 echo "\n";
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>&nbsp;' . "\n";
247 } else {
248 echo ' ' . $field_name . '&nbsp;' . "\n";
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); ?>&nbsp;</td>
255 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
256 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</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']);
264 echo '&nbsp;</td>' . "\n";
266 if ($cfgRelation['commwork']) {
267 echo ' <td class="print">';
268 if (isset($comments[$field_name])) {
269 echo htmlspecialchars($comments[$field_name]);
271 echo '&nbsp;</td>' . "\n";
273 if ($cfgRelation['mimework']) {
274 $mime_map = PMA_getMIME($db, $table, true);
276 echo ' <td class="print">';
277 if (isset($mime_map[$field_name])) {
278 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
280 echo '&nbsp;</td>' . "\n";
283 </tr>
284 <?php
285 } // end while
286 mysql_free_result($result);
288 echo "\n";
290 </table>
292 <?php
293 echo '</div>' . "\n";
295 $count++;
296 } //ends main while
300 * Displays the footer
302 echo "\n";
304 <script type="text/javascript" language="javascript1.2">
305 <!--
306 function printPage()
308 document.getElementById('print').style.visibility = 'hidden';
309 // Do print the page
310 if (typeof(window.print) != 'undefined') {
311 window.print();
313 document.getElementById('print').style.visibility = '';
315 //-->
316 </script>
317 <?php
318 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
320 require_once('./footer.inc.php');