Fix for the Open in New Window in Patient/Client->Patients search gui, take 2.
[openemr.git] / phpmyadmin / libraries / db_info.inc.php
blobadc5465272844b1fec2daef9fb826771bf8b4cab
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Gets the list of the table in the current db and informations about these
5 * tables if possible
7 * fills tooltip arrays and provides $tables, $num_tables, $is_show_stats
8 * and $db_is_information_schema
10 * staybyte: speedup view on locked tables - 11 June 2001
12 * @uses PMA_MYSQL_INT_VERSION
13 * @uses $cfg['ShowStats']
14 * @uses $cfg['ShowTooltip']
15 * @uses $cfg['ShowTooltipAliasTB']
16 * @uses $cfg['SkipLockedTables']
17 * @uses $GLOBALS['db']
18 * @uses PMA_fillTooltip()
19 * @uses PMA_checkParameters()
20 * @uses PMA_escape_mysql_wildcards()
21 * @uses PMA_DBI_query()
22 * @uses PMA_backquote()
23 * @uses PMA_DBI_num_rows()
24 * @uses PMA_DBI_fetch_row()
25 * @uses PMA_DBI_fetch_assoc()
26 * @uses PMA_DBI_free_result()
27 * @uses PMA_DBI_get_tables_full()
28 * @uses PMA_isValid()
29 * @uses preg_match()
30 * @uses preg_quote()
31 * @uses uksort()
32 * @uses strnatcasecmp()
33 * @uses count()
34 * @uses addslashes()
35 * @version $Id$
37 if (! defined('PHPMYADMIN')) {
38 exit;
41 /**
42 * requirements
44 require_once './libraries/common.inc.php';
46 /**
47 * limits for table list
49 if (! isset($_SESSION['userconf']['table_limit_offset'])) {
50 $_SESSION['userconf']['table_limit_offset'] = 0;
52 if (isset($_REQUEST['pos'])) {
53 $_SESSION['userconf']['table_limit_offset'] = (int) $_REQUEST['pos'];
55 $pos = $_SESSION['userconf']['table_limit_offset'];
57 /**
58 * fills given tooltip arrays
60 * @uses $cfg['ShowTooltipAliasTB']
61 * @uses $GLOBALS['strStatCreateTime']
62 * @uses PMA_localisedDate()
63 * @uses strtotime()
64 * @param array $tooltip_truename tooltip data
65 * @param array $tooltip_aliasname tooltip data
66 * @param array $table tabledata
68 function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
70 if (empty($table['Comment'])) {
71 $table['Comment'] = $table['Name'];
72 } else {
73 // why?
74 $table['Comment'] .= ' ';
77 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
78 && $GLOBALS['cfg']['ShowTooltipAliasTB'] != 'nested') {
79 $tooltip_truename[$table['Name']] = $table['Comment'];
80 $tooltip_aliasname[$table['Name']] = $table['Name'];
81 } else {
82 $tooltip_truename[$table['Name']] = $table['Name'];
83 $tooltip_aliasname[$table['Name']] = $table['Comment'];
86 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
87 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCreateTime']
88 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
91 if (! empty($table['Update_time'])) {
92 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatUpdateTime']
93 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
96 if (! empty($table['Check_time'])) {
97 $tooltip_aliasname[$table['Name']] .= ', ' . $GLOBALS['strStatCheckTime']
98 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
102 PMA_checkParameters(array('db'));
105 * @global bool whether to display extended stats
107 $is_show_stats = $cfg['ShowStats'];
110 * @global bool whether selected db is information_schema
112 $db_is_information_schema = false;
114 if (PMA_MYSQL_INT_VERSION >= 50002 && $db == 'information_schema') {
115 $is_show_stats = false;
116 $db_is_information_schema = true;
120 * @global array information about tables in db
122 $tables = array();
124 // When used in Nested table group mode, only show tables matching the given groupname
125 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
126 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
127 } else {
128 $tbl_group_sql = '';
131 if ($cfg['ShowTooltip']) {
132 $tooltip_truename = array();
133 $tooltip_aliasname = array();
136 // Special speedup for newer MySQL Versions (in 4.0 format changed)
137 if (true === $cfg['SkipLockedTables']) {
138 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
140 // Blending out tables in use
141 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
142 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
143 // if in use memorize tablename
144 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
145 $sot_cache[$tmp[0]] = true;
148 PMA_DBI_free_result($db_info_result);
150 if (isset($sot_cache)) {
151 $db_info_result = PMA_DBI_query(
152 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
153 null, PMA_DBI_QUERY_STORE);
154 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
155 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
156 if (!isset($sot_cache[$tmp[0]])) {
157 $sts_result = PMA_DBI_query(
158 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
159 . ' LIKE \'' . addslashes($tmp[0]) . '\';');
160 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
161 PMA_DBI_free_result($sts_result);
162 unset($sts_result);
164 if (!isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
165 $sts_tmp['Type'] =& $sts_tmp['Engine'];
168 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
169 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
170 continue;
173 if ($cfg['ShowTooltip']) {
174 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
177 $tables[$sts_tmp['Name']] = $sts_tmp;
178 } else { // table in use
179 $tables[$tmp[0]] = array('Name' => $tmp[0]);
182 if ($GLOBALS['cfg']['NaturalOrder']) {
183 uksort($tables, 'strnatcasecmp');
186 $sot_ready = true;
187 } elseif ($db_info_result) {
188 PMA_DBI_free_result($db_info_result);
190 unset($sot_cache);
192 unset($tmp);
193 } elseif ($db_info_result) {
194 PMA_DBI_free_result($db_info_result);
198 if (! isset($sot_ready)) {
199 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
200 // only tables for selected group
201 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true);
202 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
203 // only tables for selected group,
204 // but grouping is done on comment ...
205 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment');
206 } else {
207 // all tables in db
208 // - get the total number of tables
209 $tables = PMA_DBI_get_tables($db);
210 $total_num_tables = count($tables);
211 if (isset($sub_part) && $sub_part == '_export') {
212 // (don't fetch only a subset if we are coming from db_export.php,
213 // because I think it's too risky to display only a subset of the
214 // table names when exporting a db)
217 * @todo Page selector for table names?
219 $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false);
220 } else {
221 // fetch the details for a possible limited subset
222 $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true);
226 if ($cfg['ShowTooltip']) {
227 foreach ($tables as $each_table) {
228 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
234 * @global int count of tables in db
236 $num_tables = count($tables);
237 if (! isset($total_num_tables)) {
238 $total_num_tables = $num_tables;
242 * cleanup
244 unset($each_table, $tbl_group_sql, $db_info_result);
247 * Displays top menu links
249 require './libraries/db_links.inc.php';