Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / libraries / tbl_info.inc.php
blob30a7aec8d1995a4435c37c7f9586e814778448e0
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
7 if (! defined('PHPMYADMIN')) {
8 exit;
11 /**
14 require_once './libraries/Table.class.php';
16 /**
17 * extracts table properties from create statement
19 * @todo this should be recoded as functions,
20 * to avoid messing with global variables
23 /**
24 * requirements
26 require_once './libraries/common.inc.php';
28 // Check parameters
29 PMA_checkParameters(array('db', 'table'));
31 /**
32 * Defining global variables, in case this script is included by a function.
33 * This is necessary because this script can be included by libraries/header.inc.php.
35 global $showtable, $tbl_is_view, $tbl_type, $show_comment, $tbl_collation,
36 $table_info_num_rows, $auto_increment;
38 /**
39 * Gets table informations
41 // Seems we need to do this in MySQL 5.0.2,
42 // otherwise error #1046, no database selected
43 PMA_DBI_select_db($GLOBALS['db']);
45 // The 'show table' statement works correct since 3.23.03
46 $table_info_result = PMA_DBI_query(
47 'SHOW TABLE STATUS LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], true) . '\';',
48 null, PMA_DBI_QUERY_STORE);
50 // need this test because when we are creating a table, we get 0 rows
51 // from the SHOW TABLE query
52 // and we don't want to mess up the $tbl_type coming from the form
54 if ($table_info_result && PMA_DBI_num_rows($table_info_result) > 0) {
55 $showtable = PMA_DBI_fetch_assoc($table_info_result);
56 PMA_DBI_free_result($table_info_result);
57 unset($table_info_result);
59 if (!isset($showtable['Type']) && isset($showtable['Engine'])) {
60 $showtable['Type'] =& $showtable['Engine'];
62 if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) {
63 $tbl_is_view = true;
64 $tbl_type = $GLOBALS['strView'];
65 $show_comment = null;
66 } else {
67 $tbl_is_view = false;
68 $tbl_type = isset($showtable['Type'])
69 ? strtoupper($showtable['Type'])
70 : '';
71 // a new comment could be coming from tbl_operations.php
72 // and we want to show it in the header
73 if (isset($submitcomment) && isset($comment)) {
74 $show_comment = $comment;
75 } else {
76 $show_comment = isset($showtable['Comment'])
77 ? $showtable['Comment']
78 : '';
81 $tbl_collation = empty($showtable['Collation'])
82 ? ''
83 : $showtable['Collation'];
85 if (null === $showtable['Rows']) {
86 $showtable['Rows'] = PMA_Table::countRecords($GLOBALS['db'],
87 $showtable['Name'], true, true);
89 $table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
90 $auto_increment = isset($showtable['Auto_increment'])
91 ? $showtable['Auto_increment']
92 : '';
94 $create_options = isset($showtable['Create_options'])
95 ? explode(' ', $showtable['Create_options'])
96 : array();
98 // export create options by its name as variables into gloabel namespace
99 // f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
100 unset($pack_keys);
101 foreach ($create_options as $each_create_option) {
102 $each_create_option = explode('=', $each_create_option);
103 if (isset($each_create_option[1])) {
104 $$each_create_option[0] = $each_create_option[1];
107 // we need explicit DEFAULT value here (different from '0')
108 $pack_keys = (!isset($pack_keys) || strlen($pack_keys) == 0) ? 'DEFAULT' : $pack_keys;
109 unset($create_options, $each_create_option);
110 } // end if