bug #1533945, wrong table name in header (SELECT from query window)
[phpmyadmin/crack.git] / left.php
blobef39a462e201eb8b6171a39fd8487846c038fa87
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
4 /**
5 * the navigation frame - displays server, db and table selection tree
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 // xml declaration moves IE into quirks mode, making much trouble with CSS
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 <?php
108 * remove horizontal scroll bar bug in IE by forcing a vertical scroll bar
111 <!--[if IE 6]>
112 <style type="text/css">
113 /* <![CDATA[ */
114 html {
115 overflow-y: scroll;
117 /* ]]> */
118 </style>
119 <![endif]-->
120 </head>
122 <body id="body_leftFrame">
123 <?php
124 require './libraries/left_header.inc.php';
126 if ($num_dbs === 0) {
127 // no database available, so we break here
128 echo '<p>' . $strNoDatabases . '</p></body></html>';
131 * Close MySql connections
133 if (isset($controllink) && $controllink) {
134 @PMA_DBI_close($controllink);
136 if (isset($userlink) && $userlink) {
137 @PMA_DBI_close($userlink);
141 * Sends bufferized data
143 if ($GLOBALS['cfg']['OBGzip'] && isset($ob_mode) && $ob_mode) {
144 PMA_outBufferPost($ob_mode);
146 exit();
147 } elseif ($GLOBALS['cfg']['LeftFrameLight'] && $num_dbs > 1) {
148 // more than one database available and LeftFrameLight is true
149 // display db selectbox
151 // Light mode -> beginning of the select combo for databases
152 // Note: When javascript is active, the frameset will be changed from
153 // within left.php. With no JS (<noscript>) the whole frameset will
154 // be rebuilt with the new target frame.
157 <div id="databaseList">
158 <form method="post" action="index.php" target="_parent" id="left">
159 <label for="lightm_db"><?php echo $strDatabase; ?></label>
160 <?php
161 echo PMA_generate_common_hidden_inputs() . "\n";
162 echo PMA_getHtmlSelectDb($db) . "\n";
163 echo '<noscript>' . "\n"
164 .'<input type="submit" name="Go" value="' . $strGo . '" />' . "\n"
165 .'</noscript>' . "\n"
166 .'</form>' . "\n"
167 .'</div>' . "\n";
171 <div id="left_tableList">
172 <?php
173 // Don't display expansible/collapsible database info if:
174 // 1. $server == 0 (no server selected)
175 // This is the case when there are multiple servers and
176 // '$GLOBALS['cfg']['ServerDefault'] = 0' is set. In that case, we want the welcome
177 // screen to appear with no database info displayed.
178 // 2. there is only one database available (ie either only one database exists
179 // or $GLOBALS['cfg']['Servers']['only_db'] is defined and is not an array)
180 // In this case, the database should not be collapsible/expandable
182 $img_plus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_plus.png"'
183 .' width="9" height="9" alt="+" />';
184 $img_minus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_minus.png"'
185 .' width="9" height="9" alt="-" />';
187 $href_left = '<a onclick="if (toggle(\'%d\')) return false;"'
188 .' href="left.php?%s" target="_self">';
190 $element_counter = 0;
192 if ($GLOBALS['cfg']['LeftFrameLight'] && isset($db) && strlen($db)) {
193 // show selected databasename as link to DefaultTabDatabase-page
194 // with table count in ()
195 $common_url_query = PMA_generate_common_url($db);
197 $db_tooltip = '';
198 if ($GLOBALS['cfg']['ShowTooltip']
199 && $GLOBALS['cfgRelation']['commwork']) {
200 $_db_tooltip = PMA_getComments($db);
201 if (is_array($_db_tooltip)) {
202 $db_tooltip = implode(' ', $_db_tooltip);
206 $disp_name = $db;
207 if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
208 $disp_name = $db_tooltip;
209 $disp_name_cut = $db_tooltip;
210 $db_tooltip = $db;
214 <p><a class="item"
215 href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . $common_url_query; ?>"
216 title="<?php echo htmlspecialchars($db_tooltip); ?>" >
217 <?php
218 if ($GLOBALS['text_dir'] === 'rtl') {
219 echo ' <bdo dir="ltr">(' . PMA_getTableCount($db) . ')</bdo> ';
221 echo htmlspecialchars($disp_name);
222 if ($GLOBALS['text_dir'] === 'ltr') {
223 echo ' <bdo dir="ltr">(' . PMA_getTableCount($db) . ')</bdo> ';
225 echo '</a></p>';
227 $table_list = PMA_getTableList($db);
228 if (count($table_list) > 0) {
229 PMA_displayTableList($table_list, true, '', $db);
230 } else {
231 echo $strNoTablesFound;
233 unset($table_list);
234 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
235 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
236 } else {
237 $common_url_query = PMA_generate_common_url();
238 PMA_displayDbList(PMA_getDbList());
242 * displays collapsable db list
244 * @uses $_REQUEST['dbgroup']
245 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
246 * @uses $GLOBALS['strSelectADb']
247 * @uses strpos()
248 * @uses urlencode()
249 * @uses printf()
250 * @uses htmlspecialchars()
251 * @uses PMA_generate_common_url()
252 * @uses PMA_getTableList()
253 * @uses PMA_displayTableList()
254 * @global $element_counter
255 * @global $img_minus
256 * @global $img_plus
257 * @global $href_left
258 * @global $num_dbs
259 * @global $db_start
260 * @global $common_url_query
261 * @param array $ext_dblist extended db list
263 function PMA_displayDbList($ext_dblist) {
264 global $element_counter, $img_minus, $img_plus, $href_left, $num_dbs,
265 $db_start, $common_url_query;
267 // get table list, for all databases
268 // doing this in one step takes advantage of a single query with information_schema!
269 $tables_full = PMA_DBI_get_tables_full($GLOBALS['dblist']);
271 $url_dbgroup = '';
272 echo '<ul id="leftdatabaselist">';
273 $close_db_group = false;
274 foreach ($ext_dblist as $group => $db_group) {
275 if ($num_dbs > 1) {
276 if ($close_db_group) {
277 $url_dbgroup = '';
278 echo '</ul>';
279 echo '</li>';
280 $close_db_group = false;
282 if (count($db_group) > 1) {
283 $close_db_group = true;
284 $url_dbgroup = '&amp;dbgroup=' . urlencode($group);
285 $common_url_query = PMA_generate_common_url() . $url_dbgroup;
286 $element_counter++;
287 echo '<li class="dbgroup">';
288 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
289 || $db_start == $group || strpos($db_start, $group) === 0) {
290 // display + only if this db(group) is not preselected
291 printf($href_left, $element_counter, PMA_generate_common_url());
292 printf($img_minus, $element_counter);
293 } else {
294 printf($href_left, $element_counter, $common_url_query);
295 printf($img_plus, $element_counter);
297 echo '</a> ' . $group . "\n";
298 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
299 || $db_start == $group || strpos($db_start, $group) === 0) {
300 echo '<ul id="subel' . $element_counter . '">' . "\n";
301 } else {
302 echo '<ul id="subel' . $element_counter . '"'
303 .' style="display: none">' . "\n";
307 foreach ($db_group as $db) {
308 $common_url_query = PMA_generate_common_url($db['name']) . $url_dbgroup;
310 $element_counter++;
311 // Displays the database name
312 echo '<li>' . "\n";
314 if ($num_dbs > 1) {
315 // only with more than one db we need collapse ...
316 if ($db_start != $db['name'] || $db['num_tables'] < 1) {
317 // display + only if this db is not preselected
318 // or table count is 0
319 printf($href_left, $element_counter, $common_url_query);
320 printf($img_plus, $element_counter);
321 } else {
322 printf($href_left, $element_counter,
323 PMA_generate_common_url() . $url_dbgroup);
324 printf($img_minus, $element_counter);
326 echo '</a>';
328 // ... and we need to refresh both frames on db selection
330 <a class="item"
331 id="<?php echo htmlspecialchars($db['name']); ?>"
332 href="index.php?<?php echo $common_url_query; ?>"
333 target="_parent"
334 title="<?php echo htmlspecialchars($db['comment']); ?>"
335 onclick="
336 if (! toggle('<?php echo $element_counter; ?>', true))
337 window.parent.goTo('./left.php?<?php echo $common_url_query; ?>');
338 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
339 . '?' . $common_url_query; ?>', 'main');
340 return false;">
341 <?php
342 if ($GLOBALS['text_dir'] === 'rtl') {
343 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
345 echo htmlspecialchars($db['disp_name']);
346 if ($GLOBALS['text_dir'] === 'ltr') {
347 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
350 </a>
351 <?php
352 } else {
353 // with only 1 db available we dont need to refresh left frame
354 // on db selection, only phpmain
356 <a href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
357 . '?' . $common_url_query; ?>"
358 id="<?php echo htmlspecialchars($db['name']); ?>"
359 title="<?php echo htmlspecialchars($db['comment']); ?>">
360 <?php
361 if ($GLOBALS['text_dir'] === 'rtl') {
362 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
364 echo htmlspecialchars($db['disp_name']);
365 if ($GLOBALS['text_dir'] === 'ltr') {
366 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
369 </a>
370 <?php
372 if ($db['num_tables']) {
373 if (isset($tables_full[$db['name']])) {
374 $tables = PMA_getTableList($db['name'], $tables_full[$db['name']]);
375 } elseif (isset($tables_full[strtolower($db['name'])])) {
376 // on windows with lower_case_table_names = 1
377 // MySQL returns
378 // with SHOW DATABASES or information_schema.SCHEMATA: `Test`
379 // but information_schema.TABLES gives `test`
380 // bug #1436171
381 // sf.net/tracker/?func=detail&aid=1436171&group_id=23067&atid=377408
382 $tables = PMA_getTableList($db['name'], $tables_full[strtolower($db['name'])]);
383 } else {
384 $tables = PMA_getTableList($db['name']);
386 $child_visible =
387 (bool) ($num_dbs === 1 || $db_start == $db['name']);
388 PMA_displayTableList($tables, $child_visible, '', $db['name']);
389 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
390 // no tables and LeftFrameLight:
391 // display message no tables in selected db
392 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
394 echo '</li>' . "\n";
395 } // end foreach db
396 } // end foreach group
398 if ($close_db_group) {
399 $url_dbgroup = '';
400 echo '</ul>';
401 echo '</li>';
402 $close_db_group = false;
405 echo '</ul>' . "\n";
409 * display unordered list of tables
410 * calls itself recursively if table in given list
411 * is a list itself
413 * @uses is_array()
414 * @uses count()
415 * @uses urlencode()
416 * @uses strpos()
417 * @uses printf()
418 * @uses htmlspecialchars()
419 * @uses strlen()
420 * @uses is_array()
421 * @uses PMA_displayTableList()
422 * @uses $_REQUEST['tbl_group']
423 * @uses $GLOBALS['common_url_query']
424 * @uses $GLOBALS['table']
425 * @uses $GLOBALS['pmaThemeImage']
426 * @uses $GLOBALS['cfg']['LeftFrameTableSeparator']
427 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
428 * @uses $GLOBALS['cfg']['DefaultTabTable']
429 * @uses $GLOBALS['strRows']
430 * @uses $GLOBALS['strBrowse']
431 * @global $element_counter
432 * @global $img_minus
433 * @global $img_plus
434 * @global $href_left
435 * @param array $tables array of tables/tablegroups
436 * @param boolean $visible wether the list is visible or not
437 * @param string $tab_group_full full tab group name
438 * @param string $table_db db of this table
440 function PMA_displayTableList($tables, $visible = false,
441 $tab_group_full = '', $table_db = '')
443 if (! is_array($tables) || count($tables) === 0) {
444 return;
447 global $element_counter, $img_minus, $img_plus, $href_left;
448 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
450 if ($visible) {
451 echo '<ul id="subel' . $element_counter . '">';
452 } else {
453 echo '<ul id="subel' . $element_counter . '" style="display: none">';
455 foreach ($tables as $group => $table) {
456 if (isset($table['is' . $sep . 'group'])) {
457 $common_url_query = $GLOBALS['common_url_query']
458 . '&amp;tbl_group=' . urlencode($tab_group_full . $group);
460 $element_counter++;
461 echo '<li>' . "\n";
462 if ($visible &&
463 ((isset($_REQUEST['tbl_group'])
464 && (strpos($_REQUEST['tbl_group'], $group) === 0
465 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
467 (isset($GLOBALS['table'])
468 && strpos($GLOBALS['table'], $group) === 0))) {
469 printf($href_left, $element_counter,
470 $GLOBALS['common_url_query'] . '&amp;tbl_group=' . $tab_group_full);
471 printf($img_minus, $element_counter);
472 } else {
473 printf($href_left, $element_counter, $common_url_query);
474 printf($img_plus, $element_counter);
476 echo '</a>';
478 <a href="index.php?<?php echo $common_url_query; ?>"
479 target="_parent"
480 onclick="
481 if (! toggle('<?php echo $element_counter; ?>', true))
482 window.parent.goTo('./left.php?<?php echo $common_url_query; ?>');
483 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
484 . '?' . $common_url_query; ?>', 'main');
485 return false;">
486 <?php
487 if ($GLOBALS['text_dir'] === 'rtl') {
488 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
490 echo htmlspecialchars(substr($group, 0, strlen($group) - strlen($sep)));
491 if ($GLOBALS['text_dir'] === 'ltr') {
492 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
495 </a>
496 <?php
498 unset($table['is' . $sep . 'group']);
499 unset($table['tab' . $sep . 'group']);
500 unset($table['tab' . $sep . 'count']);
502 if ($visible &&
503 ((isset($_REQUEST['tbl_group'])
504 && (strpos($_REQUEST['tbl_group'], $group) === 0
505 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
507 (isset($GLOBALS['table'])
508 && strpos($GLOBALS['table'], $group) === 0))) {
509 PMA_displayTableList($table, true,
510 $tab_group_full . $group, $table_db);
511 } else {
512 PMA_displayTableList($table, false, '', $table_db);
514 echo '</li>' . "\n";
515 } elseif (is_array($table)) {
516 $href = $GLOBALS['cfg']['DefaultTabTable'] . '?'
517 .$GLOBALS['common_url_query'] . '&amp;table='
518 .urlencode($table['Name']);
519 echo '<li>' . "\n";
520 echo '<a title="' . $GLOBALS['strBrowse'] . ': '
521 . htmlspecialchars($table['Comment'])
522 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')"'
523 .' id="browse_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
524 .' href="sql.php?' . $GLOBALS['common_url_query']
525 .'&amp;table=' . urlencode($table['Name'])
526 .'&amp;goto=' . $GLOBALS['cfg']['DefaultTabTable']
527 . '" >'
528 .'<img class="icon"';
529 if ('VIEW' === strtoupper($table['Comment'])) {
530 echo ' src="' . $GLOBALS['pmaThemeImage'] . 's_views.png"';
531 } else {
532 echo ' src="' . $GLOBALS['pmaThemeImage'] . 'b_sbrowse.png"';
534 echo ' id="icon_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
535 .' width="10" height="10" alt="' . $GLOBALS['strBrowse'] . '" /></a>' . "\n"
536 .'<a href="' . $href . '" title="' . $table['Comment']
537 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')"'
538 .' id="' . htmlspecialchars($table_db . '.' . $table['Name']) . '">'
539 . htmlspecialchars($table['disp_name']) . '</a>';
540 echo '</li>' . "\n";
543 echo '</ul>';
546 </div>
547 </body>
548 </html>
549 <?php
551 * Close MySql connections
553 if (isset($controllink) && $controllink) {
554 @PMA_DBI_close($controllink);
556 if (isset($userlink) && $userlink) {
557 @PMA_DBI_close($userlink);
561 * Sends bufferized data
563 if ($GLOBALS['cfg']['OBGzip'] && isset($ob_mode) && $ob_mode) {
564 PMA_outBufferPost($ob_mode);