unneeded double line in navi when no page selector is displayed
[phpmyadmin/crack.git] / navigation.php
blobccd431344b195431627a79b8875b91b44eb8c367
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * the navigation frame - displays server, db and table selection tree
6 * @version $Id$
7 * @uses $GLOBALS['PMA_List_Database']
8 * @uses $GLOBALS['server']
9 * @uses $GLOBALS['db']
10 * @uses $GLOBALS['table']
11 * @uses $GLOBALS['available_languages']
12 * @uses $GLOBALS['lang']
13 * @uses $GLOBALS['text_dir']
14 * @uses $GLOBALS['charset']
15 * @uses $GLOBALS['pmaThemeImage']
16 * @uses $GLOBALS['strNoDatabases']
17 * @uses $GLOBALS['strDatabase']
18 * @uses $GLOBALS['strGo']
19 * @uses $GLOBALS['strSelectADb']
20 * @uses $GLOBALS['strNoTablesFound']
21 * @uses $GLOBALS['cfg']['LeftFrameLight']
22 * @uses $GLOBALS['cfg']['ShowTooltip']
23 * @uses $GLOBALS['cfg']['ShowTooltipAliasDB']
24 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
25 * @uses $GLOBALS['cfgRelation']['commwork']) {
26 * @uses PMA_List_Database::getSingleItem()
27 * @uses PMA_List_Database::count()
28 * @uses PMA_List_Database::getHtmlSelectGrouped()
29 * @uses PMA_List_Database::getGroupedDetails()
30 * @uses PMA_generate_common_url()
31 * @uses PMA_generate_common_hidden_inputs()
32 * @uses PMA_getComments();
33 * @uses PMA_getTableCount()
34 * @uses PMA_getTableList()
35 * @uses PMA_getRelationsParam()
36 * @uses PMA_outBufferPre()
37 * @uses session_write_close()
38 * @uses strlen()
39 * @uses session_write_close()
40 * @uses is_array()
41 * @uses implode()
42 * @uses htmlspecialchars()
45 /**
46 * Gets a core script and starts output buffering work
48 require_once './libraries/common.inc.php';
50 /**
51 * finish and cleanup navigation.php script execution
53 * @uses $GLOBALS['controllink'] to close it
54 * @uses $GLOBALS['userlink'] to close it
55 * @uses PMA_DBI_close()
56 * @access private only to be used in navigation.php
58 function PMA_exitNavigationFrame()
60 echo '</body></html>';
62 /**
63 * Close MySQL connections
65 if (isset($GLOBALS['controllink']) && $GLOBALS['controllink']) {
66 @PMA_DBI_close($GLOBALS['controllink']);
68 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
69 @PMA_DBI_close($GLOBALS['userlink']);
72 exit;
75 // keep the offset of the db list in session before closing it
76 if (! isset($_SESSION['navi_limit_offset'])) {
77 $_SESSION['navi_limit_offset'] = 0;
79 if (isset($_REQUEST['pos'])) {
80 $_SESSION['navi_limit_offset'] = (int) $_REQUEST['pos'];
82 $pos = $_SESSION['navi_limit_offset'];
84 // free the session file, for the other frames to be loaded
85 session_write_close();
87 /**
88 * the output compression library
90 require_once './libraries/ob.lib.php';
92 PMA_outBufferPre();
95 * selects the database if there is only one on current server
97 if ($GLOBALS['server'] && ! strlen($GLOBALS['db'])) {
98 $GLOBALS['db'] = $GLOBALS['PMA_List_Database']->getSingleItem();
101 $db_start = $GLOBALS['db'];
104 * the relation library
106 require_once './libraries/relation.lib.php';
107 $cfgRelation = PMA_getRelationsParam();
110 * garvin: For re-usability, moved http-headers to a seperate file.
111 * It can now be included by libraries/header.inc.php, querywindow.php.
113 require_once './libraries/header_http.inc.php';
115 if (! isset($_SESSION['navi_limit_offset'])) {
116 $_SESSION['navi_limit_offset'] = 0;
118 if (isset($_REQUEST['pos'])) {
119 $_SESSION['navi_limit_offset'] = (int) $_REQUEST['pos'];
121 $pos = $_SESSION['navi_limit_offset'];
124 * Displays the frame
126 // xml declaration moves IE into quirks mode, making much trouble with CSS
127 /* echo '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?>'; */
129 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
130 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
131 <html xmlns="http://www.w3.org/1999/xhtml"
132 xml:lang="<?php echo $available_languages[$lang][2]; ?>"
133 lang="<?php echo $available_languages[$lang][2]; ?>"
134 dir="<?php echo $GLOBALS['text_dir']; ?>">
136 <head>
137 <link rel="icon" href="./favicon.ico" type="image/x-icon" />
138 <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
139 <title>phpMyAdmin</title>
140 <meta http-equiv="Content-Type"
141 content="text/html; charset=<?php echo $GLOBALS['charset']; ?>" />
142 <base target="frame_content" />
143 <link rel="stylesheet" type="text/css"
144 href="phpmyadmin.css.php?<?php echo PMA_generate_common_url('', ''); ?>&amp;js_frame=left&amp;nocache=<?php echo $_SESSION['PMA_Config']->getMtime(); ?>" />
145 <script type="text/javascript" src="js/navigation.js"></script>
146 <script type="text/javascript" src="js/functions.js"></script>
147 <script type="text/javascript">
148 // <![CDATA[
149 var image_minus = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_minus.png';
150 var image_plus = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_plus.png';
151 // ]]>
152 </script>
153 <?php
155 * remove horizontal scroll bar bug in IE 6 by forcing a vertical scroll bar
158 <!--[if IE 6]>
159 <style type="text/css">
160 /* <![CDATA[ */
161 html {
162 overflow-y: scroll;
164 /* ]]> */
165 </style>
166 <![endif]-->
167 </head>
169 <body id="body_leftFrame" onload="PMA_setFrameSize();" onresize="PMA_saveFrameSize();">
170 <?php
171 require './libraries/navigation_header.inc.php';
172 if (! $GLOBALS['server']) {
173 // no server selected
174 PMA_exitNavigationFrame();
175 } elseif (! $GLOBALS['PMA_List_Database']->count()) {
176 // no database available, so we break here
177 echo '<p>' . $GLOBALS['strNoDatabases'] . '</p>';
178 PMA_exitNavigationFrame();
179 } elseif ($GLOBALS['cfg']['LeftFrameLight'] && $GLOBALS['PMA_List_Database']->count() > 1) {
180 $list = $cfg['DisplayDatabasesList'];
181 if ($list === 'auto') {
182 if (empty($GLOBALS['db'])) {
183 $list = true;
184 } else {
185 $list = false;
188 if (!$list) {
189 // more than one database available and LeftFrameLight is true
190 // display db selectbox
192 // Light mode -> beginning of the select combo for databases
193 // Note: When javascript is active, the frameset will be changed from
194 // within navigation.php. With no JS (<noscript>) the whole frameset will
195 // be rebuilt with the new target frame.
198 <div id="databaseList">
199 <form method="post" action="index.php" target="_parent" id="left">
200 <label for="lightm_db"><?php echo $GLOBALS['strDatabase']; ?></label>
201 <?php
202 echo PMA_generate_common_hidden_inputs() . "\n";
203 echo $GLOBALS['PMA_List_Database']->getHtmlSelectGrouped(true, $_SESSION['navi_limit_offset'], $GLOBALS['cfg']['MaxDbList']) . "\n";
204 echo '<noscript>' . "\n"
205 .'<input type="submit" name="Go" value="' . $GLOBALS['strGo'] . '" />' . "\n"
206 .'</noscript>' . "\n"
207 .'</form>' . "\n"
208 .'</div>' . "\n";
209 } else {
210 echo $GLOBALS['PMA_List_Database']->getHtmlListGrouped(true, $_SESSION['navi_limit_offset'], $GLOBALS['cfg']['MaxDbList']) . "\n";
215 <div id="left_tableList">
216 <?php
217 // Don't display expansible/collapsible database info if:
218 // 1. $GLOBALS['server'] == 0 (no server selected)
219 // This is the case when there are multiple servers and
220 // '$GLOBALS['cfg']['ServerDefault'] = 0' is set. In that case, we want the welcome
221 // screen to appear with no database info displayed.
222 // 2. there is only one database available (ie either only one database exists
223 // or $GLOBALS['cfg']['Servers']['only_db'] is defined and is not an array)
224 // In this case, the database should not be collapsible/expandable
226 $img_plus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_plus.png"'
227 .' width="9" height="9" alt="+" />';
228 $img_minus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_minus.png"'
229 .' width="9" height="9" alt="-" />';
231 $href_left = '<a onclick="if (toggle(\'%d\')) return false;"'
232 .' href="navigation.php?%s" target="_self">';
234 $element_counter = 0;
236 if ($GLOBALS['cfg']['LeftFrameLight'] && strlen($GLOBALS['db'])) {
237 // show selected databasename as link to DefaultTabDatabase-page
238 // with table count in ()
239 $common_url_query = PMA_generate_common_url($GLOBALS['db']);
241 $db_tooltip = '';
243 if ($GLOBALS['cfg']['ShowTooltip']
244 && $GLOBALS['cfgRelation']['commwork']) {
245 $_db_tooltip = PMA_getComments($GLOBALS['db']);
246 if (is_array($_db_tooltip)) {
247 $db_tooltip = implode(' ', $_db_tooltip);
251 $disp_name = $GLOBALS['db'];
252 if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
253 $disp_name = $db_tooltip;
254 $disp_name_cut = $db_tooltip;
255 $db_tooltip = $GLOBALS['db'];
259 <p><a class="item"
260 href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . $common_url_query; ?>"
261 title="<?php echo htmlspecialchars($db_tooltip); ?>" >
262 <?php
263 if ($GLOBALS['text_dir'] === 'rtl') {
264 echo ' <bdo dir="ltr">(' . PMA_getTableCount($GLOBALS['db']) . ')</bdo> ';
266 echo htmlspecialchars($disp_name);
267 if ($GLOBALS['text_dir'] === 'ltr') {
268 echo ' <bdo dir="ltr">(' . PMA_getTableCount($GLOBALS['db']) . ')</bdo> ';
270 echo '</a></p>';
272 $table_list = PMA_getTableList($GLOBALS['db']);
273 if (count($table_list) > 0) {
274 PMA_displayTableList($table_list, true, '', $GLOBALS['db']);
275 } else {
276 echo $GLOBALS['strNoTablesFound'];
278 unset($table_list);
279 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
280 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
281 } else {
282 $common_url_query = PMA_generate_common_url();
283 PMA_displayDbList($GLOBALS['PMA_List_Database']->getGroupedDetails($_SESSION['navi_limit_offset'],$GLOBALS['cfg']['MaxDbList']), $_SESSION['navi_limit_offset'],$GLOBALS['cfg']['MaxDbList']);
287 * displays collapsable db list
289 * @uses $_REQUEST['dbgroup']
290 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
291 * @uses $GLOBALS['strSelectADb']
292 * @uses strpos()
293 * @uses urlencode()
294 * @uses printf()
295 * @uses htmlspecialchars()
296 * @uses PMA_generate_common_url()
297 * @uses PMA_getTableList()
298 * @uses PMA_displayTableList()
299 * @global $element_counter
300 * @global $img_minus
301 * @global $img_plus
302 * @global $href_left
303 * @global $db_start
304 * @global $common_url_query
305 * @param array $ext_dblist extended db list
306 * @param integer $offset
307 * @param integer $count
309 function PMA_displayDbList($ext_dblist, $offset, $count) {
310 global $element_counter, $img_minus, $img_plus, $href_left,
311 $db_start, $common_url_query;
313 // get table list, for all databases
314 // doing this in one step takes advantage of a single query with information_schema!
315 $tables_full = PMA_DBI_get_tables_full($GLOBALS['PMA_List_Database']->getLimitedItems($offset, $count));
317 $url_dbgroup = '';
318 echo '<ul id="leftdatabaselist">';
319 $close_db_group = false;
320 foreach ($ext_dblist as $group => $db_group) {
321 if ($GLOBALS['PMA_List_Database']->count() > 1) {
322 if ($close_db_group) {
323 $url_dbgroup = '';
324 echo '</ul>';
325 echo '</li>';
326 $close_db_group = false;
328 if (count($db_group) > 1) {
329 $close_db_group = true;
330 $url_dbgroup = '&amp;dbgroup=' . urlencode($group);
331 $common_url_query = PMA_generate_common_url() . $url_dbgroup;
332 $element_counter++;
333 echo '<li class="dbgroup">';
334 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
335 || $db_start == $group || strpos($db_start, $group) === 0) {
336 // display + only if this db(group) is not preselected
337 printf($href_left, $element_counter, PMA_generate_common_url());
338 printf($img_minus, $element_counter);
339 } else {
340 printf($href_left, $element_counter, $common_url_query);
341 printf($img_plus, $element_counter);
343 echo '</a> ' . $group . "\n";
344 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
345 || $db_start == $group || strpos($db_start, $group) === 0) {
346 echo '<ul id="subel' . $element_counter . '">' . "\n";
347 } else {
348 echo '<ul id="subel' . $element_counter . '"'
349 .' style="display: none">' . "\n";
353 foreach ($db_group as $db) {
354 $common_url_query = PMA_generate_common_url($db['name']) . $url_dbgroup;
356 $element_counter++;
357 // Displays the database name
358 echo '<li>' . "\n";
360 if ($GLOBALS['PMA_List_Database']->count() > 1) {
361 // only with more than one db we need collapse ...
362 if ($db_start != $db['name'] || $db['num_tables'] < 1) {
363 // display + only if this db is not preselected
364 // or table count is 0
365 printf($href_left, $element_counter, $common_url_query);
366 printf($img_plus, $element_counter);
367 } else {
368 printf($href_left, $element_counter,
369 PMA_generate_common_url() . $url_dbgroup);
370 printf($img_minus, $element_counter);
372 echo '</a>';
374 // ... and we need to refresh both frames on db selection
376 <a class="item"
377 id="<?php echo htmlspecialchars($db['name']); ?>"
378 href="index.php?<?php echo $common_url_query; ?>"
379 target="_parent"
380 title="<?php echo htmlspecialchars($db['comment']); ?>"
381 onclick="
382 if (! toggle('<?php echo $element_counter; ?>', true))
383 window.parent.goTo('./navigation.php?<?php echo $common_url_query; ?>');
384 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
385 . '?' . $common_url_query; ?>', 'main');
386 return false;">
387 <?php
388 if ($GLOBALS['text_dir'] === 'rtl') {
389 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
391 echo htmlspecialchars($db['disp_name']);
392 if ($GLOBALS['text_dir'] === 'ltr') {
393 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
396 </a>
397 <?php
398 } else {
399 // with only 1 db available we dont need to refresh left frame
400 // on db selection, only phpmain
402 <a href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
403 . '?' . $common_url_query; ?>"
404 id="<?php echo htmlspecialchars($db['name']); ?>"
405 title="<?php echo htmlspecialchars($db['comment']); ?>">
406 <?php
407 if ($GLOBALS['text_dir'] === 'rtl') {
408 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
410 echo htmlspecialchars($db['disp_name']);
411 if ($GLOBALS['text_dir'] === 'ltr') {
412 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
415 </a>
416 <?php
418 if ($db['num_tables']) {
419 if (isset($tables_full[$db['name']])) {
420 $tables = PMA_getTableList($db['name'], $tables_full[$db['name']]);
421 } elseif (isset($tables_full[strtolower($db['name'])])) {
422 // on windows with lower_case_table_names = 1
423 // MySQL returns
424 // with SHOW DATABASES or information_schema.SCHEMATA: `Test`
425 // but information_schema.TABLES gives `test`
426 // bug #1436171
427 // sf.net/tracker/?func=detail&aid=1436171&group_id=23067&atid=377408
428 $tables = PMA_getTableList($db['name'], $tables_full[strtolower($db['name'])]);
429 } else {
430 $tables = PMA_getTableList($db['name']);
432 $child_visible =
433 (bool) ($GLOBALS['PMA_List_Database']->count() === 1 || $db_start == $db['name']);
434 PMA_displayTableList($tables, $child_visible, '', $db['name']);
435 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
436 // no tables and LeftFrameLight:
437 // display message no tables in selected db
438 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
440 echo '</li>' . "\n";
441 } // end foreach db
442 } // end foreach group
444 if ($close_db_group) {
445 $url_dbgroup = '';
446 echo '</ul>';
447 echo '</li>';
448 $close_db_group = false;
451 echo '</ul>' . "\n";
455 * display unordered list of tables
456 * calls itself recursively if table in given list
457 * is a list itself
459 * @uses is_array()
460 * @uses count()
461 * @uses urlencode()
462 * @uses strpos()
463 * @uses printf()
464 * @uses htmlspecialchars()
465 * @uses strlen()
466 * @uses is_array()
467 * @uses PMA_displayTableList()
468 * @uses $_REQUEST['tbl_group']
469 * @uses $GLOBALS['common_url_query']
470 * @uses $GLOBALS['table']
471 * @uses $GLOBALS['pmaThemeImage']
472 * @uses $GLOBALS['cfg']['LeftFrameTableSeparator']
473 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
474 * @uses $GLOBALS['cfg']['DefaultTabTable']
475 * @uses $GLOBALS['strRows']
476 * @uses $GLOBALS['strBrowse']
477 * @global integer the element counter
478 * @global string html code for '-' image
479 * @global string html code for '+' image
480 * @global string html code for self link
481 * @param array $tables array of tables/tablegroups
482 * @param boolean $visible wether the list is visible or not
483 * @param string $tab_group_full full tab group name
484 * @param string $table_db db of this table
486 function PMA_displayTableList($tables, $visible = false,
487 $tab_group_full = '', $table_db = '')
489 if (! is_array($tables) || count($tables) === 0) {
490 return;
493 global $element_counter, $img_minus, $img_plus, $href_left;
494 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
496 if ($visible) {
497 echo '<ul id="subel' . $element_counter . '">';
498 } else {
499 echo '<ul id="subel' . $element_counter . '" style="display: none">';
501 foreach ($tables as $group => $table) {
502 if (isset($table['is' . $sep . 'group'])) {
503 $common_url_query = $GLOBALS['common_url_query']
504 . '&amp;tbl_group=' . urlencode($tab_group_full . $group);
506 $element_counter++;
507 echo '<li>' . "\n";
508 if ($visible
509 && ((isset($_REQUEST['tbl_group'])
510 && (strpos($_REQUEST['tbl_group'], $group) === 0
511 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
512 || strpos($GLOBALS['table'], $group) === 0)) {
513 printf($href_left, $element_counter,
514 $GLOBALS['common_url_query'] . '&amp;tbl_group=' . $tab_group_full);
515 printf($img_minus, $element_counter);
516 } else {
517 printf($href_left, $element_counter, $common_url_query);
518 printf($img_plus, $element_counter);
520 echo '</a>';
522 <a href="index.php?<?php echo $common_url_query; ?>"
523 target="_parent"
524 onclick="
525 if (! toggle('<?php echo $element_counter; ?>', true))
526 window.parent.goTo('./navigation.php?<?php echo $common_url_query; ?>');
527 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
528 . '?' . $common_url_query; ?>', 'main');
529 return false;">
530 <?php
531 if ($GLOBALS['text_dir'] === 'rtl') {
532 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
534 echo htmlspecialchars(substr($group, 0, strlen($group) - strlen($sep)));
535 if ($GLOBALS['text_dir'] === 'ltr') {
536 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
539 </a>
540 <?php
542 unset($table['is' . $sep . 'group']);
543 unset($table['tab' . $sep . 'group']);
544 unset($table['tab' . $sep . 'count']);
546 if ($visible &&
547 ((isset($_REQUEST['tbl_group'])
548 && (strpos($_REQUEST['tbl_group'], $group) === 0
549 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
550 || strpos($GLOBALS['table'], $group) === 0)) {
551 PMA_displayTableList($table, true,
552 $tab_group_full . $group, $table_db);
553 } else {
554 PMA_displayTableList($table, false, '', $table_db);
556 echo '</li>' . "\n";
557 } elseif (is_array($table)) {
558 $href = $GLOBALS['cfg']['DefaultTabTable'] . '?'
559 .$GLOBALS['common_url_query'] . '&amp;table='
560 .urlencode($table['Name']);
561 echo '<li>' . "\n";
562 echo '<a title="' . $GLOBALS['strBrowse'] . ': '
563 . htmlspecialchars($table['Comment'])
564 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')"'
565 .' id="browse_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
566 .' href="sql.php?' . $GLOBALS['common_url_query']
567 .'&amp;table=' . urlencode($table['Name'])
568 .'&amp;goto=' . $GLOBALS['cfg']['DefaultTabTable']
569 . '" >'
570 .'<img class="icon"';
571 if ('VIEW' === strtoupper($table['Comment'])) {
572 echo ' src="' . $GLOBALS['pmaThemeImage'] . 's_views.png"';
573 } else {
574 echo ' src="' . $GLOBALS['pmaThemeImage'] . 'b_sbrowse.png"';
576 echo ' id="icon_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
577 .' width="10" height="10" alt="' . $GLOBALS['strBrowse'] . '" /></a>' . "\n"
578 .'<a href="' . $href . '" title="' . htmlspecialchars($table['Comment']
579 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows']) . ')"'
580 .' id="' . htmlspecialchars($table_db . '.' . $table['Name']) . '">'
581 // preserve spaces in table name
582 . str_replace(' ', '&nbsp;', htmlspecialchars($table['disp_name'])) . '</a>';
583 echo '</li>' . "\n";
586 echo '</ul>';
589 echo '</div>' . "\n";
591 $_url_params = array('pos' => $pos);
592 PMA_dbPageSelector($GLOBALS['PMA_List_Database']->count(), $pos, $_url_params, 'navigation.php', 'frame_navigation');
593 PMA_exitNavigationFrame();