navigation and MaxDbList (work in progress)
[phpmyadmin/crack.git] / navigation.php
blobaae84e18949794bdd6c78ff4c1b54b48fc3542e3
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 = $GLOBALS['PMA_List_Database']->limit_offset = $_SESSION['navi_limit_offset'];
83 $GLOBALS['PMA_List_Database']->limit_count = $GLOBALS['cfg']['MaxDbList'];
85 // free the session file, for the other frames to be loaded
86 session_write_close();
88 /**
89 * the output compression library
91 require_once './libraries/ob.lib.php';
93 PMA_outBufferPre();
96 * selects the database if there is only one on current server
98 if ($GLOBALS['server'] && ! strlen($GLOBALS['db'])) {
99 $GLOBALS['db'] = $GLOBALS['PMA_List_Database']->getSingleItem();
102 $db_start = $GLOBALS['db'];
105 * the relation library
107 require_once './libraries/relation.lib.php';
108 $cfgRelation = PMA_getRelationsParam();
111 * garvin: For re-usability, moved http-headers to a seperate file.
112 * It can now be included by libraries/header.inc.php, querywindow.php.
114 require_once './libraries/header_http.inc.php';
116 if (! isset($_SESSION['navi_limit_offset'])) {
117 $_SESSION['navi_limit_offset'] = 0;
119 if (isset($_REQUEST['pos'])) {
120 $_SESSION['navi_limit_offset'] = (int) $_REQUEST['pos'];
122 $pos = $GLOBALS['PMA_List_Database']->limit_offset = $_SESSION['navi_limit_offset'];
123 $GLOBALS['PMA_List_Database']->limit_count = $GLOBALS['cfg']['MaxDbList'];
126 * Displays the frame
128 // xml declaration moves IE into quirks mode, making much trouble with CSS
129 /* echo '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?>'; */
131 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
132 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
133 <html xmlns="http://www.w3.org/1999/xhtml"
134 xml:lang="<?php echo $available_languages[$lang][2]; ?>"
135 lang="<?php echo $available_languages[$lang][2]; ?>"
136 dir="<?php echo $GLOBALS['text_dir']; ?>">
138 <head>
139 <link rel="icon" href="./favicon.ico" type="image/x-icon" />
140 <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
141 <title>phpMyAdmin</title>
142 <meta http-equiv="Content-Type"
143 content="text/html; charset=<?php echo $GLOBALS['charset']; ?>" />
144 <base target="frame_content" />
145 <link rel="stylesheet" type="text/css"
146 href="phpmyadmin.css.php?<?php echo PMA_generate_common_url('', ''); ?>&amp;js_frame=left&amp;nocache=<?php echo $_SESSION['PMA_Config']->getMtime(); ?>" />
147 <script type="text/javascript" src="js/navigation.js"></script>
148 <script type="text/javascript" src="js/functions.js"></script>
149 <script type="text/javascript">
150 // <![CDATA[
151 var image_minus = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_minus.png';
152 var image_plus = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_plus.png';
153 // ]]>
154 </script>
155 <?php
157 * remove horizontal scroll bar bug in IE 6 by forcing a vertical scroll bar
160 <!--[if IE 6]>
161 <style type="text/css">
162 /* <![CDATA[ */
163 html {
164 overflow-y: scroll;
166 /* ]]> */
167 </style>
168 <![endif]-->
169 </head>
171 <body id="body_leftFrame" onload="PMA_setFrameSize();" onresize="PMA_saveFrameSize();">
172 <?php
173 require './libraries/navigation_header.inc.php';
174 if (! $GLOBALS['server']) {
175 // no server selected
176 PMA_exitNavigationFrame();
177 } elseif (! $GLOBALS['PMA_List_Database']->count()) {
178 // no database available, so we break here
179 echo '<p>' . $GLOBALS['strNoDatabases'] . '</p>';
180 PMA_exitNavigationFrame();
181 } elseif ($GLOBALS['cfg']['LeftFrameLight'] && $GLOBALS['PMA_List_Database']->count() > 1) {
182 $list = $cfg['DisplayDatabasesList'];
183 if ($list === 'auto') {
184 if (empty($GLOBALS['db'])) {
185 $list = true;
186 } else {
187 $list = false;
190 if (!$list) {
191 // more than one database available and LeftFrameLight is true
192 // display db selectbox
194 // Light mode -> beginning of the select combo for databases
195 // Note: When javascript is active, the frameset will be changed from
196 // within navigation.php. With no JS (<noscript>) the whole frameset will
197 // be rebuilt with the new target frame.
200 <div id="databaseList">
201 <form method="post" action="index.php" target="_parent" id="left">
202 <label for="lightm_db"><?php echo $GLOBALS['strDatabase']; ?></label>
203 <?php
204 echo PMA_generate_common_hidden_inputs() . "\n";
205 echo $GLOBALS['PMA_List_Database']->getHtmlSelectGrouped(true) . "\n";
206 echo '<noscript>' . "\n"
207 .'<input type="submit" name="Go" value="' . $GLOBALS['strGo'] . '" />' . "\n"
208 .'</noscript>' . "\n"
209 .'</form>' . "\n"
210 .'</div>' . "\n";
211 } else {
212 echo $GLOBALS['PMA_List_Database']->getHtmlListGrouped(true) . "\n";
217 <div id="left_tableList">
218 <?php
219 // Don't display expansible/collapsible database info if:
220 // 1. $GLOBALS['server'] == 0 (no server selected)
221 // This is the case when there are multiple servers and
222 // '$GLOBALS['cfg']['ServerDefault'] = 0' is set. In that case, we want the welcome
223 // screen to appear with no database info displayed.
224 // 2. there is only one database available (ie either only one database exists
225 // or $GLOBALS['cfg']['Servers']['only_db'] is defined and is not an array)
226 // In this case, the database should not be collapsible/expandable
228 $img_plus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_plus.png"'
229 .' width="9" height="9" alt="+" />';
230 $img_minus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_minus.png"'
231 .' width="9" height="9" alt="-" />';
233 $href_left = '<a onclick="if (toggle(\'%d\')) return false;"'
234 .' href="navigation.php?%s" target="_self">';
236 $element_counter = 0;
238 if ($GLOBALS['cfg']['LeftFrameLight'] && strlen($GLOBALS['db'])) {
239 // show selected databasename as link to DefaultTabDatabase-page
240 // with table count in ()
241 $common_url_query = PMA_generate_common_url($GLOBALS['db']);
243 $db_tooltip = '';
245 if ($GLOBALS['cfg']['ShowTooltip']
246 && $GLOBALS['cfgRelation']['commwork']) {
247 $_db_tooltip = PMA_getComments($GLOBALS['db']);
248 if (is_array($_db_tooltip)) {
249 $db_tooltip = implode(' ', $_db_tooltip);
253 $disp_name = $GLOBALS['db'];
254 if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
255 $disp_name = $db_tooltip;
256 $disp_name_cut = $db_tooltip;
257 $db_tooltip = $GLOBALS['db'];
261 <p><a class="item"
262 href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . $common_url_query; ?>"
263 title="<?php echo htmlspecialchars($db_tooltip); ?>" >
264 <?php
265 if ($GLOBALS['text_dir'] === 'rtl') {
266 echo ' <bdo dir="ltr">(' . PMA_getTableCount($GLOBALS['db']) . ')</bdo> ';
268 echo htmlspecialchars($disp_name);
269 if ($GLOBALS['text_dir'] === 'ltr') {
270 echo ' <bdo dir="ltr">(' . PMA_getTableCount($GLOBALS['db']) . ')</bdo> ';
272 echo '</a></p>';
274 $table_list = PMA_getTableList($GLOBALS['db']);
275 if (count($table_list) > 0) {
276 PMA_displayTableList($table_list, true, '', $GLOBALS['db']);
277 } else {
278 echo $GLOBALS['strNoTablesFound'];
280 unset($table_list);
281 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
282 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
283 } else {
284 $common_url_query = PMA_generate_common_url();
285 PMA_displayDbList($GLOBALS['PMA_List_Database']->getGroupedDetails());
289 * displays collapsable db list
291 * @uses $_REQUEST['dbgroup']
292 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
293 * @uses $GLOBALS['strSelectADb']
294 * @uses strpos()
295 * @uses urlencode()
296 * @uses printf()
297 * @uses htmlspecialchars()
298 * @uses PMA_generate_common_url()
299 * @uses PMA_getTableList()
300 * @uses PMA_displayTableList()
301 * @global $element_counter
302 * @global $img_minus
303 * @global $img_plus
304 * @global $href_left
305 * @global $db_start
306 * @global $common_url_query
307 * @param array $ext_dblist extended db list
309 function PMA_displayDbList($ext_dblist) {
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']->getItems());
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>';
591 echo '<div>' . "\n";
592 $_url_params = array('pos' => $pos);
593 PMA_dbPageSelector($GLOBALS['PMA_List_Database']->count(), $pos, $_url_params, 'navigation.php', 'frame_navigation');
594 echo '</div>' . "\n";
595 PMA_exitNavigationFrame();