Fix reading database list with MySQL wildcards (bug #1487613).
[phpmyadmin/last10db.git] / left.php
blob9616b2f0760b820fed265da80f96a275a330f051
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4 /**
5 * display db and table selection
6 */
8 /**
9 * Gets a core script and starts output buffering work
11 require_once('./libraries/common.lib.php');
13 // free the session file, for the other frames to be loaded
14 session_write_close();
16 require_once('./libraries/ob.lib.php');
17 if ($GLOBALS['cfg']['OBGzip']) {
18 $ob_mode = PMA_outBufferModeGet();
19 if ($ob_mode) {
20 PMA_outBufferPre($ob_mode);
24 require_once('./libraries/bookmark.lib.php');
25 require_once('./libraries/relation.lib.php');
26 $cfgRelation = PMA_getRelationsParam();
28 /**
29 * Get the list and number of available databases.
30 * Skipped if no server selected: in this case no database should be displayed
31 * before the user choose among available ones at the welcome screen.
33 if ($server > 0) {
34 // this function is defined in "common.lib.php"
35 // it defines $num_dbs and $dblist
36 PMA_availableDatabases();
38 if ((! isset($db) || ! strlen($db)) && count($dblist) === 1) {
39 reset($dblist);
40 $db = current($dblist);
42 } else {
43 $num_dbs = 0;
46 $db = isset($db) ? $db : '';
47 $table = isset($table) ? $table : '';
48 $db_start = $db;
51 // garvin: For re-usability, moved http-headers
52 // to a seperate file. It can now be included by libraries/header.inc.php,
53 // querywindow.php.
55 require_once('./libraries/header_http.inc.php');
57 /**
58 * Displays the frame
60 // remove vertical scroll bar bug in ie
61 echo '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?>';
63 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
64 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
65 <html xmlns="http://www.w3.org/1999/xhtml"
66 xml:lang="<?php echo $available_languages[$lang][2]; ?>"
67 lang="<?php echo $available_languages[$lang][2]; ?>"
68 dir="<?php echo $text_dir; ?>">
70 <head>
71 <link rel="icon" href="./favicon.ico" type="image/x-icon" />
72 <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
73 <title>phpMyAdmin</title>
74 <meta http-equiv="Content-Type"
75 content="text/html; charset=<?php echo $charset; ?>" />
76 <base target="frame_content" />
77 <link rel="stylesheet" type="text/css"
78 href="./css/phpmyadmin.css.php?<?php echo PMA_generate_common_url('', ''); ?>&amp;js_frame=left" />
79 <script type="text/javascript" language="javascript">
80 //<![CDATA[
81 function toggle(id, only_open) {
82 var el = document.getElementById('subel' + id);
83 if (! el) {
84 return false;
87 var img = document.getElementById('el' + id + 'Img');
89 if (el.style.display == 'none' || only_open) {
90 el.style.display = '';
91 if (img) {
92 img.src = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_minus.png';
93 img.alt = '-';
95 } else {
96 el.style.display = 'none';
97 if (img) {
98 img.src = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_plus.png';
99 img.alt = '+';
102 return true;
104 //]]>
105 </script>
106 </head>
108 <body id="body_leftFrame">
109 <?php
110 require './libraries/left_header.inc.php';
112 if ($num_dbs === 0) {
113 // no database available, so we break here
114 echo '<p>' . $strNoDatabases . '</p></body></html>';
117 * Close MySql connections
119 if (isset($controllink) && $controllink) {
120 @PMA_DBI_close($controllink);
122 if (isset($userlink) && $userlink) {
123 @PMA_DBI_close($userlink);
127 * Sends bufferized data
129 if ($GLOBALS['cfg']['OBGzip'] && isset($ob_mode) && $ob_mode) {
130 PMA_outBufferPost($ob_mode);
132 exit();
133 } elseif ($GLOBALS['cfg']['LeftFrameLight'] && $num_dbs > 1) {
134 // more than one database available and LeftFrameLight is true
135 // display db selectbox
137 // Light mode -> beginning of the select combo for databases
138 // Note: When javascript is active, the frameset will be changed from
139 // within left.php. With no JS (<noscript>) the whole frameset will
140 // be rebuilt with the new target frame.
143 <div id="databaseList">
144 <form method="post" action="index.php" target="_parent" id="left">
145 <label for="lightm_db"><?php echo $strDatabase; ?></label>
146 <?php
147 echo PMA_generate_common_hidden_inputs() . "\n";
148 echo PMA_getHtmlSelectDb($db) . "\n";
149 echo '<noscript>' . "\n"
150 .'<input type="submit" name="Go" value="' . $strGo . '" />' . "\n"
151 .'</noscript>' . "\n"
152 .'</form>' . "\n"
153 .'</div>' . "\n";
157 <div id="left_tableList">
158 <?php
159 // Don't display expansible/collapsible database info if:
160 // 1. $server == 0 (no server selected)
161 // This is the case when there are multiple servers and
162 // '$GLOBALS['cfg']['ServerDefault'] = 0' is set. In that case, we want the welcome
163 // screen to appear with no database info displayed.
164 // 2. there is only one database available (ie either only one database exists
165 // or $GLOBALS['cfg']['Servers']['only_db'] is defined and is not an array)
166 // In this case, the database should not be collapsible/expandable
168 $img_plus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_plus.png"'
169 .' width="9" height="9" alt="+" />';
170 $img_minus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_minus.png"'
171 .' width="9" height="9" alt="-" />';
173 $href_left = '<a onclick="if (toggle(\'%d\')) return false;"'
174 .' href="left.php?%s" target="_self">';
176 $element_counter = 0;
178 if ($GLOBALS['cfg']['LeftFrameLight'] && isset($db) && strlen($db)) {
179 // show selected databasename as link to DefaultTabDatabase-page
180 // with table count in ()
181 $common_url_query = PMA_generate_common_url($db);
183 $db_tooltip = '';
184 if ($GLOBALS['cfg']['ShowTooltip']
185 && $GLOBALS['cfgRelation']['commwork']) {
186 $_db_tooltip = PMA_getComments($db);
187 if (is_array($_db_tooltip)) {
188 $db_tooltip = implode(' ', $_db_tooltip);
192 $disp_name = $db;
193 if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
194 $disp_name = $db_tooltip;
195 $disp_name_cut = $db_tooltip;
196 $db_tooltip = $db;
200 <p><a class="item"
201 href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . $common_url_query; ?>"
202 title="<?php echo htmlspecialchars($db_tooltip); ?>" >
203 <?php
204 if ($GLOBALS['text_dir'] === 'rtl') {
205 echo ' <bdo dir="ltr">(' . PMA_getTableCount($db) . ')</bdo> ';
207 echo htmlspecialchars($disp_name);
208 if ($GLOBALS['text_dir'] === 'ltr') {
209 echo ' <bdo dir="ltr">(' . PMA_getTableCount($db) . ')</bdo> ';
211 echo '</a></p>';
213 $table_list = PMA_getTableList($db);
214 if (count($table_list) > 0) {
215 PMA_displayTableList($table_list, true, '', $db);
216 } else {
217 echo $strNoTablesFound;
219 unset($table_list);
220 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
221 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
222 } else {
223 $common_url_query = PMA_generate_common_url();
224 PMA_displayDbList(PMA_getDbList());
228 * displays collapsable db list
230 * @uses $_REQUEST['dbgroup']
231 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
232 * @uses $GLOBALS['strSelectADb']
233 * @uses strpos()
234 * @uses urlencode()
235 * @uses printf()
236 * @uses htmlspecialchars()
237 * @uses PMA_generate_common_url()
238 * @uses PMA_getTableList()
239 * @uses PMA_displayTableList()
240 * @global $element_counter
241 * @global $img_minus
242 * @global $img_plus
243 * @global $href_left
244 * @global $num_dbs
245 * @global $db_start
246 * @global $common_url_query
247 * @param array $ext_dblist extended db list
249 function PMA_displayDbList($ext_dblist) {
250 global $element_counter, $img_minus, $img_plus, $href_left, $num_dbs,
251 $db_start, $common_url_query;
253 // get table list, for all databases
254 // doing this in one step takes advantage of a single query with information_schema!
255 $tables_full = PMA_DBI_get_tables_full($GLOBALS['dblist']);
257 $url_dbgroup = '';
258 echo '<ul id="leftdatabaselist">';
259 $close_db_group = false;
260 foreach ($ext_dblist as $group => $db_group) {
261 if ($num_dbs > 1) {
262 if ($close_db_group) {
263 $url_dbgroup = '';
264 echo '</ul>';
265 echo '</li>';
266 $close_db_group = false;
268 if (count($db_group) > 1) {
269 $close_db_group = true;
270 $url_dbgroup = '&amp;dbgroup=' . urlencode($group);
271 $common_url_query = PMA_generate_common_url() . $url_dbgroup;
272 $element_counter++;
273 echo '<li class="dbgroup">';
274 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
275 || $db_start == $group || strpos($db_start, $group) === 0) {
276 // display + only if this db(group) is not preselected
277 printf($href_left, $element_counter, PMA_generate_common_url());
278 printf($img_minus, $element_counter);
279 } else {
280 printf($href_left, $element_counter, $common_url_query);
281 printf($img_plus, $element_counter);
283 echo '</a> ' . $group . "\n";
284 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
285 || $db_start == $group || strpos($db_start, $group) === 0) {
286 echo '<ul id="subel' . $element_counter . '">' . "\n";
287 } else {
288 echo '<ul id="subel' . $element_counter . '"'
289 .' style="display: none">' . "\n";
293 foreach ($db_group as $db) {
294 $common_url_query = PMA_generate_common_url($db['name']) . $url_dbgroup;
296 $element_counter++;
297 // Displays the database name
298 echo '<li>' . "\n";
300 if ($num_dbs > 1) {
301 // only with more than one db we need collapse ...
302 if ($db_start != $db['name'] || $db['num_tables'] < 1) {
303 // display + only if this db is not preselected
304 // or table count is 0
305 printf($href_left, $element_counter, $common_url_query);
306 printf($img_plus, $element_counter);
307 } else {
308 printf($href_left, $element_counter,
309 PMA_generate_common_url() . $url_dbgroup);
310 printf($img_minus, $element_counter);
312 echo '</a>';
314 // ... and we need to refresh both frames on db selection
316 <a class="item"
317 id="<?php echo htmlspecialchars($db['name']); ?>"
318 href="index.php?<?php echo $common_url_query; ?>"
319 target="_parent"
320 title="<?php echo htmlspecialchars($db['comment']); ?>"
321 onclick="
322 if (! toggle('<?php echo $element_counter; ?>', true))
323 window.parent.goTo('./left.php?<?php echo $common_url_query; ?>');
324 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
325 . '?' . $common_url_query; ?>', 'main');
326 return false;">
327 <?php
328 if ($GLOBALS['text_dir'] === 'rtl') {
329 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
331 echo htmlspecialchars($db['disp_name']);
332 if ($GLOBALS['text_dir'] === 'ltr') {
333 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
336 </a>
337 <?php
338 } else {
339 // with only 1 db available we dont need to refresh left frame
340 // on db selection, only phpmain
342 <a href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
343 . '?' . $common_url_query; ?>"
344 id="<?php echo htmlspecialchars($db['name']); ?>"
345 title="<?php echo htmlspecialchars($db['comment']); ?>">
346 <?php
347 if ($GLOBALS['text_dir'] === 'rtl') {
348 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
350 echo htmlspecialchars($db['disp_name']);
351 if ($GLOBALS['text_dir'] === 'ltr') {
352 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
355 </a>
356 <?php
358 if ($db['num_tables']) {
359 if (isset($tables_full[$db['name']])) {
360 $tables = PMA_getTableList($db['name'], $tables_full[$db['name']]);
361 } elseif (isset($tables_full[strtolower($db['name'])])) {
362 // on windows with lower_case_table_names = 1
363 // MySQL returns
364 // with SHOW DATABASES or information_schema.SCHEMATA: `Test`
365 // but information_schema.TABLES gives `test`
366 // bug #1436171
367 // sf.net/tracker/?func=detail&aid=1436171&group_id=23067&atid=377408
368 $tables = PMA_getTableList($db['name'], $tables_full[strtolower($db['name'])]);
369 } else {
370 $tables = PMA_getTableList($db['name']);
372 $child_visible =
373 (bool) ($num_dbs === 1 || $db_start == $db['name']);
374 PMA_displayTableList($tables, $child_visible, '', $db['name']);
375 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
376 // no tables and LeftFrameLight:
377 // display message no tables in selected db
378 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
380 echo '</li>' . "\n";
381 } // end foreach db
382 } // end foreach group
384 if ($close_db_group) {
385 $url_dbgroup = '';
386 echo '</ul>';
387 echo '</li>';
388 $close_db_group = false;
391 echo '</ul>' . "\n";
395 * display unordered list of tables
396 * calls itself recursively if table in given list
397 * is a list itself
399 * @uses is_array()
400 * @uses count()
401 * @uses urlencode()
402 * @uses strpos()
403 * @uses printf()
404 * @uses htmlspecialchars()
405 * @uses strlen()
406 * @uses is_array()
407 * @uses PMA_displayTableList()
408 * @uses $_REQUEST['tbl_group']
409 * @uses $GLOBALS['common_url_query']
410 * @uses $GLOBALS['table']
411 * @uses $GLOBALS['pmaThemeImage']
412 * @uses $GLOBALS['cfg']['LeftFrameTableSeparator']
413 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
414 * @uses $GLOBALS['cfg']['DefaultTabTable']
415 * @uses $GLOBALS['strRows']
416 * @uses $GLOBALS['strBrowse']
417 * @global $element_counter
418 * @global $img_minus
419 * @global $img_plus
420 * @global $href_left
421 * @param array $tables array of tables/tablegroups
422 * @param boolean $visible wether the list is visible or not
423 * @param string $tab_group_full full tab group name
424 * @param string $table_db db of this table
426 function PMA_displayTableList($tables, $visible = false,
427 $tab_group_full = '', $table_db = '')
429 if (! is_array($tables) || count($tables) === 0) {
430 return;
433 global $element_counter, $img_minus, $img_plus, $href_left;
434 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
436 if ($visible) {
437 echo '<ul id="subel' . $element_counter . '">';
438 } else {
439 echo '<ul id="subel' . $element_counter . '" style="display: none">';
441 foreach ($tables as $group => $table) {
442 if (isset($table['is' . $sep . 'group'])) {
443 $common_url_query = $GLOBALS['common_url_query']
444 . '&amp;tbl_group=' . urlencode($tab_group_full . $group);
446 $element_counter++;
447 echo '<li>' . "\n";
448 if ($visible &&
449 ((isset($_REQUEST['tbl_group'])
450 && (strpos($_REQUEST['tbl_group'], $group) === 0
451 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
453 (isset($GLOBALS['table'])
454 && strpos($GLOBALS['table'], $group) === 0))) {
455 printf($href_left, $element_counter,
456 $GLOBALS['common_url_query'] . '&amp;tbl_group=' . $tab_group_full);
457 printf($img_minus, $element_counter);
458 } else {
459 printf($href_left, $element_counter, $common_url_query);
460 printf($img_plus, $element_counter);
462 echo '</a>';
464 <a href="index.php?<?php echo $common_url_query; ?>"
465 target="_parent"
466 onclick="
467 if (! toggle('<?php echo $element_counter; ?>', true))
468 window.parent.goTo('./left.php?<?php echo $common_url_query; ?>');
469 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
470 . '?' . $common_url_query; ?>', 'main');
471 return false;">
472 <?php
473 if ($GLOBALS['text_dir'] === 'rtl') {
474 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
476 echo htmlspecialchars(substr($group, 0, strlen($group) - strlen($sep)));
477 if ($GLOBALS['text_dir'] === 'ltr') {
478 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
481 </a>
482 <?php
484 unset($table['is' . $sep . 'group']);
485 unset($table['tab' . $sep . 'group']);
486 unset($table['tab' . $sep . 'count']);
488 if ($visible &&
489 ((isset($_REQUEST['tbl_group'])
490 && (strpos($_REQUEST['tbl_group'], $group) === 0
491 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
493 (isset($GLOBALS['table'])
494 && strpos($GLOBALS['table'], $group) === 0))) {
495 PMA_displayTableList($table, true,
496 $tab_group_full . $group, $table_db);
497 } else {
498 PMA_displayTableList($table, false, '', $table_db);
500 echo '</li>' . "\n";
501 } elseif (is_array($table)) {
502 $href = $GLOBALS['cfg']['DefaultTabTable'] . '?'
503 .$GLOBALS['common_url_query'] . '&amp;table='
504 .urlencode($table['Name']);
505 echo '<li>' . "\n";
506 echo '<a title="' . $GLOBALS['strBrowse'] . ': '
507 . htmlspecialchars($table['Comment'])
508 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')"'
509 .' id="browse_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
510 .' href="sql.php?' . $GLOBALS['common_url_query']
511 .'&amp;table=' . urlencode($table['Name'])
512 .'&amp;goto=' . $GLOBALS['cfg']['DefaultTabTable']
513 . '" >'
514 .'<img class="icon"';
515 if ('VIEW' === strtoupper($table['Comment'])) {
516 echo ' src="' . $GLOBALS['pmaThemeImage'] . 's_views.png"';
517 } else {
518 echo ' src="' . $GLOBALS['pmaThemeImage'] . 'b_sbrowse.png"';
520 echo ' id="icon_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
521 .' width="10" height="10" alt="' . $GLOBALS['strBrowse'] . '" /></a>' . "\n"
522 .'<a href="' . $href . '" title="' . $table['Comment']
523 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')"'
524 .' id="' . htmlspecialchars($table_db . '.' . $table['Name']) . '">'
525 . htmlspecialchars($table['disp_name']) . '</a>';
526 echo '</li>' . "\n";
529 echo '</ul>';
532 </div>
533 </body>
534 </html>
535 <?php
537 * Close MySql connections
539 if (isset($controllink) && $controllink) {
540 @PMA_DBI_close($controllink);
542 if (isset($userlink) && $userlink) {
543 @PMA_DBI_close($userlink);
547 * Sends bufferized data
549 if ($GLOBALS['cfg']['OBGzip'] && isset($ob_mode) && $ob_mode) {
550 PMA_outBufferPost($ob_mode);