Initial import.
[openemr.git] / interface / main / myadmin / tbl_printview.php
blob280f78c4da3942e6a212fda5195a5971a9dc5f5d
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');
13 // Check parameters
15 if (!isset($the_tables) || !is_array($the_tables)) {
16 $the_tables = array();
19 /**
20 * Gets the relations settings
22 require_once('./libraries/relation.lib.php');
23 require_once('./libraries/transformations.lib.php');
25 $cfgRelation = PMA_getRelationsParam();
28 /**
29 * Defines the url to return to in case of error in a sql statement
31 if (isset($table)) {
32 $err_url = 'tbl_properties.php?' . PMA_generate_common_url($db, $table);
33 } else {
34 $err_url = 'db_details.php?' . PMA_generate_common_url($db);
38 /**
39 * Selects the database
41 PMA_mysql_select_db($db);
44 /**
45 * Multi-tables printview thanks to Christophe Gesché from the "MySQL Form
46 * Generator for PHPMyAdmin" (http://sourceforge.net/projects/phpmysqlformgen/)
48 if (isset($selected_tbl) && is_array($selected_tbl)) {
49 $the_tables = $selected_tbl;
50 } else if (isset($table)) {
51 $the_tables[] = $table;
53 $multi_tables = (count($the_tables) > 1);
55 if ($multi_tables) {
56 $tbl_list = '';
57 foreach($the_tables AS $key => $table) {
58 $tbl_list .= (empty($tbl_list) ? '' : ', ')
59 . PMA_backquote(urldecode($table));
61 echo '<b>'. $strShowTables . '&nbsp;:&nbsp;' . $tbl_list . '</b>' . "\n";
62 echo '<hr />' . "\n";
63 } // end if
65 $tables_cnt = count($the_tables);
66 $counter = 0;
68 foreach($the_tables AS $key => $table) {
69 $table = urldecode($table);
70 if ($counter + 1 >= $tables_cnt) {
71 $breakstyle = '';
72 } else {
73 $breakstyle = ' style="page-break-after: always;"';
75 $counter++;
76 echo '<div' . $breakstyle . '>' . "\n";
77 echo '<h1>' . $table . '</h1>' . "\n";
79 /**
80 * Gets table informations
82 $local_query = 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\'';
83 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
84 $showtable = PMA_mysql_fetch_array($result);
85 $num_rows = (isset($showtable['Rows']) ? $showtable['Rows'] : 0);
86 $show_comment = (isset($showtable['Comment']) ? $showtable['Comment'] : '');
87 if ($result) {
88 mysql_free_result($result);
92 /**
93 * Gets table keys and retains them
95 $local_query = 'SHOW KEYS FROM ' . PMA_backquote($table);
96 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
97 $primary = '';
98 $indexes = array();
99 $lastIndex = '';
100 $indexes_info = array();
101 $indexes_data = array();
102 $pk_array = array(); // will be use to emphasis prim. keys in the table
103 // view
104 while ($row = PMA_mysql_fetch_array($result)) {
105 // Backups the list of primary keys
106 if ($row['Key_name'] == 'PRIMARY') {
107 $primary .= $row['Column_name'] . ', ';
108 $pk_array[$row['Column_name']] = 1;
110 // Retains keys informations
111 if ($row['Key_name'] != $lastIndex ){
112 $indexes[] = $row['Key_name'];
113 $lastIndex = $row['Key_name'];
115 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
116 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
117 if (isset($row['Cardinality'])) {
118 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
120 // I don't know what does following column mean....
121 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
122 $indexes_info[$row['Key_name']]['Comment'] = $row['Comment'];
124 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
125 if (isset($row['Sub_part'])) {
126 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
129 } // end while
130 if ($result) {
131 mysql_free_result($result);
136 * Gets fields properties
138 $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table);
139 $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url);
140 $fields_cnt = mysql_num_rows($result);
142 // Check if we can use Relations (Mike Beck)
143 if (!empty($cfgRelation['relation'])) {
144 // Find which tables are related with the current one and write it in
145 // an array
146 $res_rel = PMA_getForeigners($db, $table);
148 if (count($res_rel) > 0) {
149 $have_rel = TRUE;
150 } else {
151 $have_rel = FALSE;
154 else {
155 $have_rel = FALSE;
156 } // end if
160 * Displays the comments of the table if MySQL >= 3.23
162 if (!empty($show_comment)) {
163 echo $strTableComments . '&nbsp;:&nbsp;' . $show_comment . '<br /><br />';
167 * Displays the table structure
171 <!-- TABLE INFORMATIONS -->
172 <table width="95%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
173 <tr>
174 <th width="50"><?php echo $strField; ?></th>
175 <th width="80"><?php echo $strType; ?></th>
176 <!--<th width="50"><?php echo $strAttr; ?></th>-->
177 <th width="40"><?php echo $strNull; ?></th>
178 <th width="70"><?php echo $strDefault; ?></th>
179 <!--<th width="50"><?php echo $strExtra; ?></th>-->
180 <?php
181 echo "\n";
182 if ($have_rel) {
183 echo ' <th>' . $strLinksTo . '</th>' . "\n";
185 if ($cfgRelation['commwork']) {
186 echo ' <th>' . $strComments . '</th>' . "\n";
188 if ($cfgRelation['mimework']) {
189 echo ' <th>MIME</th>' . "\n";
192 </tr>
194 <?php
195 $i = 0;
196 while ($row = PMA_mysql_fetch_array($result)) {
197 $bgcolor = ($i % 2) ?$cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
198 $i++;
200 $type = $row['Type'];
201 // reformat mysql query output - staybyte - 9. June 2001
202 // loic1: set or enum types: slashes single quotes inside options
203 if (preg_match('@^(set|enum)\((.+)\)$@i', $type, $tmp)) {
204 $tmp[2] = substr(preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1);
205 $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
206 $type_nowrap = '';
208 $binary = 0;
209 $unsigned = 0;
210 $zerofill = 0;
211 } else {
212 $type_nowrap = ' nowrap="nowrap"';
213 $type = preg_replace('@BINARY@i', '', $type);
214 $type = preg_replace('@ZEROFILL@i', '', $type);
215 $type = preg_replace('@UNSIGNED@i', '', $type);
216 if (empty($type)) {
217 $type = '&nbsp;';
220 $binary = stristr($row['Type'], 'binary');
221 $unsigned = stristr($row['Type'], 'unsigned');
222 $zerofill = stristr($row['Type'], 'zerofill');
224 $strAttribute = '&nbsp;';
225 if ($binary) {
226 $strAttribute = 'BINARY';
228 if ($unsigned) {
229 $strAttribute = 'UNSIGNED';
231 if ($zerofill) {
232 $strAttribute = 'UNSIGNED ZEROFILL';
234 if (!isset($row['Default'])) {
235 if ($row['Null'] != '') {
236 $row['Default'] = '<i>NULL</i>';
238 } else {
239 $row['Default'] = htmlspecialchars($row['Default']);
241 $field_name = htmlspecialchars($row['Field']);
242 echo "\n";
244 <tr>
245 <td width="50" class="print" nowrap="nowrap">
246 <?php
247 if (isset($pk_array[$row['Field']])) {
248 echo ' <u>' . $field_name . '</u>&nbsp;' . "\n";
249 } else {
250 echo ' ' . $field_name . '&nbsp;' . "\n";
253 </td>
254 <td width="80" class="print"<?php echo $type_nowrap; ?>><?php echo $type; ?><bdo dir="ltr"></bdo></td>
255 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $strAttribute; ?></td>-->
256 <td width="40" class="print"><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
257 <td width="70" class="print" nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
258 <!--<td width="50" bgcolor="<?php echo $bgcolor; ?>" nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>-->
259 <?php
260 echo "\n";
261 if ($have_rel) {
262 echo ' <td class="print">';
263 if (isset($res_rel[$field_name])) {
264 echo htmlspecialchars($res_rel[$field_name]['foreign_table'] . ' -> ' . $res_rel[$field_name]['foreign_field'] );
266 echo '&nbsp;</td>' . "\n";
268 if ($cfgRelation['commwork']) {
269 echo ' <td class="print">';
270 $comments = PMA_getComments($db, $table);
271 if (isset($comments[$field_name])) {
272 echo htmlspecialchars($comments[$field_name]);
274 echo '&nbsp;</td>' . "\n";
276 if ($cfgRelation['mimework']) {
277 $mime_map = PMA_getMIME($db, $table, true);
279 echo ' <td class="print">';
280 if (isset($mime_map[$field_name])) {
281 echo htmlspecialchars(str_replace('_', '/', $mime_map[$field_name]['mimetype']));
283 echo '&nbsp;</td>' . "\n";
286 </tr>
287 <?php
288 } // end while
289 mysql_free_result($result);
291 echo "\n";
293 </table>
296 <?php
298 * Displays indexes
300 $index_count = (isset($indexes))
301 ? count($indexes)
302 : 0;
303 if ($index_count > 0) {
304 echo "\n";
306 <br /><br />
308 <!-- Indexes -->
309 &nbsp;<big><?php echo $strIndexes . '&nbsp;:'; ?></big>
310 <table bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
311 <tr>
312 <th><?php echo $strKeyname; ?></th>
313 <th><?php echo $strType; ?></th>
314 <th><?php echo $strCardinality; ?></th>
315 <th colspan="2"><?php echo $strField; ?></th>
316 </tr>
317 <?php
318 echo "\n";
319 foreach($indexes AS $index_no => $index_name) {
320 $cell_bgd = (($index_no % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);
321 $index_td = ' <td class="print" rowspan="' . count($indexes_info[$index_name]['Sequences']) . '">' . "\n";
322 echo ' <tr>' . "\n";
323 echo $index_td
324 . ' ' . htmlspecialchars($index_name) . "\n"
325 . ' </td>' . "\n";
327 if ($indexes_info[$index_name]['Comment'] == 'FULLTEXT') {
328 $index_type = 'FULLTEXT';
329 } else if ($index_name == 'PRIMARY') {
330 $index_type = 'PRIMARY';
331 } else if ($indexes_info[$index_name]['Non_unique'] == '0') {
332 $index_type = 'UNIQUE';
333 } else {
334 $index_type = 'INDEX';
336 echo $index_td
337 . ' ' . $index_type . "\n"
338 . ' </td>' . "\n";
340 echo $index_td
341 . ' ' . (isset($indexes_info[$index_name]['Cardinality']) ? $indexes_info[$index_name]['Cardinality'] : $strNone) . "\n"
342 . ' </td>' . "\n";
344 foreach($indexes_info[$index_name]['Sequences'] AS $row_no => $seq_index) {
345 if ($row_no > 0) {
346 echo ' <tr>' . "\n";
348 if (!empty($indexes_data[$index_name][$seq_index]['Sub_part'])) {
349 echo ' <td class="print">' . "\n"
350 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
351 . ' </td>' . "\n";
352 echo ' <td align="right" class="print">' . "\n"
353 . ' ' . $indexes_data[$index_name][$seq_index]['Sub_part'] . "\n"
354 . ' </td>' . "\n";
355 echo ' </tr>' . "\n";
356 } else {
357 echo ' <td class="print" colspan="2">' . "\n"
358 . ' ' . $indexes_data[$index_name][$seq_index]['Column_name'] . "\n"
359 . ' </td>' . "\n";
360 echo ' </tr>' . "\n";
362 } // end while
363 } // end while
364 echo "\n";
366 </table>
367 <?php
368 echo "\n";
369 } // end display indexes
373 * Displays Space usage and row statistics
375 * staybyte - 9 June 2001
377 if ($cfg['ShowStats']) {
378 $nonisam = FALSE;
379 if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
380 $nonisam = TRUE;
382 if ($nonisam == FALSE) {
383 // Gets some sizes
384 $mergetable = FALSE;
385 if (isset($showtable['Type']) && $showtable['Type'] == 'MRG_MyISAM') {
386 $mergetable = TRUE;
388 list($data_size, $data_unit) = PMA_formatByteDown($showtable['Data_length']);
389 if ($mergetable == FALSE) {
390 list($index_size, $index_unit) = PMA_formatByteDown($showtable['Index_length']);
392 if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
393 list($free_size, $free_unit) = PMA_formatByteDown($showtable['Data_free']);
394 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
395 } else {
396 unset($free_size);
397 unset($free_unit);
398 list($effect_size, $effect_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
400 list($tot_size, $tot_unit) = PMA_formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
401 if ($num_rows > 0) {
402 list($avg_size, $avg_unit) = PMA_formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
405 // Displays them
407 <br /><br />
409 <table border="0" cellspacing="0" cellpadding="0">
410 <tr>
412 <!-- Space usage -->
413 <td class="print" valign="top">
414 &nbsp;<big><?php echo $strSpaceUsage . '&nbsp;:'; ?></big>
415 <table width="100%" bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
416 <tr>
417 <th><?php echo $strType; ?></th>
418 <th colspan="2" align="center"><?php echo $strUsage; ?></th>
419 </tr>
420 <tr>
421 <td class="print" style="padding-right: 10px"><?php echo $strData; ?></td>
422 <td align="right" class="print" nowrap="nowrap"><?php echo $data_size; ?></td>
423 <td class="print"><?php echo $data_unit; ?></td>
424 </tr>
425 <?php
426 if (isset($index_size)) {
427 echo "\n";
429 <tr>
430 <td class="print" style="padding-right: 10px"><?php echo $strIndex; ?></td>
431 <td align="right" class="print" nowrap="nowrap"><?php echo $index_size; ?></td>
432 <td class="print"><?php echo $index_unit; ?></td>
433 </tr>
434 <?php
436 if (isset($free_size)) {
437 echo "\n";
439 <tr style="color: #bb0000">
440 <td class="print" style="padding-right: 10px"><?php echo $strOverhead; ?></td>
441 <td align="right" class="print" nowrap="nowrap"><?php echo $free_size; ?></td>
442 <td class="print"><?php echo $free_unit; ?></td>
443 </tr>
444 <tr>
445 <td class="print" style="padding-right: 10px"><?php echo $strEffective; ?></td>
446 <td align="right" class="print" nowrap="nowrap"><?php echo $effect_size; ?></td>
447 <td class="print"><?php echo $effect_unit; ?></td>
448 </tr>
449 <?php
451 if (isset($tot_size) && $mergetable == FALSE) {
452 echo "\n";
454 <tr>
455 <td class="print" style="padding-right: 10px"><?php echo $strTotalUC; ?></td>
456 <td align="right" class="print" nowrap="nowrap"><?php echo $tot_size; ?></td>
457 <td class="print"><?php echo $tot_unit; ?></td>
458 </tr>
459 <?php
461 echo "\n";
463 </table>
464 </td>
466 <td width="20" class="print">&nbsp;</td>
468 <!-- Rows Statistic -->
469 <td valign="top">
470 &nbsp;<big><?php echo $strRowsStatistic . '&nbsp;:'; ?></big>
471 <table width=100% bordercolorlight="black" border="border" style="border-collapse: collapse; background-color: white">
472 <tr>
473 <th><?php echo $strStatement; ?></th>
474 <th align="center"><?php echo $strValue; ?></th>
475 </tr>
476 <?php
477 $i = 0;
478 if (isset($showtable['Row_format'])) {
479 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
480 echo "\n";
482 <tr>
483 <td class="print"><?php echo ucfirst($strFormat); ?></td>
484 <td align="<?php echo $cell_align_left; ?>" class="print" nowrap="nowrap">
485 <?php
486 echo ' ';
487 if ($showtable['Row_format'] == 'Fixed') {
488 echo $strFixed;
489 } else if ($showtable['Row_format'] == 'Dynamic') {
490 echo $strDynamic;
491 } else {
492 echo $showtable['Row_format'];
494 echo "\n";
496 </td>
497 </tr>
498 <?php
500 if (isset($showtable['Rows'])) {
501 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
502 echo "\n";
504 <tr>
505 <td class="print"><?php echo ucfirst($strRows); ?></td>
506 <td align="right" class="print" nowrap="nowrap">
507 <?php echo number_format($showtable['Rows'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
508 </td>
509 </tr>
510 <?php
512 if (isset($showtable['Avg_row_length']) && $showtable['Avg_row_length'] > 0) {
513 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
514 echo "\n";
516 <tr>
517 <td class="print"><?php echo ucfirst($strRowLength); ?>&nbsp;&oslash;</td>
518 <td class="print" nowrap="nowrap">
519 <?php echo number_format($showtable['Avg_row_length'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
520 </td>
521 </tr>
522 <?php
524 if (isset($showtable['Data_length']) && $showtable['Rows'] > 0 && $mergetable == FALSE) {
525 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
526 echo "\n";
528 <tr>
529 <td class="print"><?php echo ucfirst($strRowSize); ?>&nbsp;&oslash;</td>
530 <td align="right" class="print" nowrap="nowrap">
531 <?php echo $avg_size . ' ' . $avg_unit . "\n"; ?>
532 </td>
533 </tr>
534 <?php
536 if (isset($showtable['Auto_increment'])) {
537 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
538 echo "\n";
540 <tr>
541 <td class="print"><?php echo ucfirst($strNext); ?>&nbsp;Autoindex</td>
542 <td align="right" class="print" nowrap="nowrap">
543 <?php echo number_format($showtable['Auto_increment'], 0, $number_decimal_separator, $number_thousands_separator) . "\n"; ?>
544 </td>
545 </tr>
546 <?php
548 echo "\n";
550 if (isset($showtable['Create_time'])) {
551 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
552 echo "\n";
554 <tr>
555 <td class="print"><?php echo $strStatCreateTime; ?></td>
556 <td align="right" class="print" nowrap="nowrap">
557 <?php echo PMA_localisedDate(strtotime($showtable['Create_time'])) . "\n"; ?>
558 </td>
559 </tr>
560 <?php
562 echo "\n";
564 if (isset($showtable['Update_time'])) {
565 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
566 echo "\n";
568 <tr>
569 <td class="print"><?php echo $strStatUpdateTime; ?></td>
570 <td align="right" class="print" nowrap="nowrap">
571 <?php echo PMA_localisedDate(strtotime($showtable['Update_time'])) . "\n"; ?>
572 </td>
573 </tr>
574 <?php
576 echo "\n";
578 if (isset($showtable['Check_time'])) {
579 $bgcolor = ((++$i%2) ? $cfg['BgcolorTwo'] : $cfg['BgcolorOne']);
580 echo "\n";
582 <tr>
583 <td class="print"><?php echo $strStatCheckTime; ?></td>
584 <td align="right" class="print" nowrap="nowrap">
585 <?php echo PMA_localisedDate(strtotime($showtable['Check_time'])) . "\n"; ?>
586 </td>
587 </tr>
588 <?php
590 echo "\n";
592 </table>
593 </td>
594 </tr>
595 </table>
597 <?php
598 } // end if ($nonisam == FALSE)
599 } // end if ($cfg['ShowStats'])
601 echo "\n";
602 if ($multi_tables) {
603 unset($ret_keys);
604 unset($num_rows);
605 unset($show_comment);
606 echo '<hr />' . "\n";
607 } // end if
608 echo '</div>' . "\n";
610 } // end while
615 * Displays the footer
617 echo "\n";
619 <script type="text/javascript" language="javascript1.2">
620 <!--
621 function printPage()
623 document.getElementById('print').style.visibility = 'hidden';
624 // Do print the page
625 if (typeof(window.print) != 'undefined') {
626 window.print();
628 document.getElementById('print').style.visibility = '';
630 //-->
631 </script>
632 <?php
633 echo '<br /><br />&nbsp;<input type="button" style="visibility: ; width: 100px; height: 25px" id="print" value="' . $strPrint . '" onclick="printPage()">' . "\n";
635 require_once('./footer.inc.php');