added known limitation
[phpmyadmin/crack.git] / navigation.php
blobb5aabdc3164f33222e3579a4bd2f25836b04e2a4
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 // free the session file, for the other frames to be loaded
76 session_write_close();
78 /**
79 * the output compression library
81 require_once './libraries/ob.lib.php';
83 PMA_outBufferPre();
86 * selects the database if there is only one on current server
88 if ($GLOBALS['server'] && ! strlen($GLOBALS['db'])) {
89 $GLOBALS['db'] = $GLOBALS['PMA_List_Database']->getSingleItem();
92 $db_start = $GLOBALS['db'];
94 /**
95 * the relation library
97 require_once './libraries/relation.lib.php';
98 $cfgRelation = PMA_getRelationsParam();
101 * garvin: For re-usability, moved http-headers to a seperate file.
102 * It can now be included by libraries/header.inc.php, querywindow.php.
104 require_once './libraries/header_http.inc.php';
107 * Displays the frame
109 // xml declaration moves IE into quirks mode, making much trouble with CSS
110 /* echo '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?>'; */
112 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
113 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
114 <html xmlns="http://www.w3.org/1999/xhtml"
115 xml:lang="<?php echo $available_languages[$lang][2]; ?>"
116 lang="<?php echo $available_languages[$lang][2]; ?>"
117 dir="<?php echo $GLOBALS['text_dir']; ?>">
119 <head>
120 <link rel="icon" href="./favicon.ico" type="image/x-icon" />
121 <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
122 <title>phpMyAdmin</title>
123 <meta http-equiv="Content-Type"
124 content="text/html; charset=<?php echo $GLOBALS['charset']; ?>" />
125 <base target="frame_content" />
126 <link rel="stylesheet" type="text/css"
127 href="phpmyadmin.css.php?<?php echo PMA_generate_common_url('', ''); ?>&amp;js_frame=left&amp;nocache=<?php echo $_SESSION['PMA_Config']->getMtime(); ?>" />
128 <script type="text/javascript" src="js/navigation.js"></script>
129 <script type="text/javascript">
130 // <![CDATA[
131 var image_minus = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_minus.png';
132 var image_plus = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_plus.png';
133 // ]]>
134 </script>
135 <?php
137 * remove horizontal scroll bar bug in IE 6 by forcing a vertical scroll bar
140 <!--[if IE 6]>
141 <style type="text/css">
142 /* <![CDATA[ */
143 html {
144 overflow-y: scroll;
146 /* ]]> */
147 </style>
148 <![endif]-->
149 </head>
151 <body id="body_leftFrame" onload="PMA_setFrameSize();" onresize="PMA_saveFrameSize();">
152 <?php
153 require './libraries/navigation_header.inc.php';
154 if (! $GLOBALS['server']) {
155 // no server selected
156 PMA_exitNavigationFrame();
157 } elseif (! $GLOBALS['PMA_List_Database']->count()) {
158 // no database available, so we break here
159 echo '<p>' . $GLOBALS['strNoDatabases'] . '</p>';
160 PMA_exitNavigationFrame();
161 } elseif ($GLOBALS['cfg']['LeftFrameLight'] && $GLOBALS['PMA_List_Database']->count() > 1) {
162 $list = $cfg['DisplayDatabasesList'];
163 if ($list === 'auto') {
164 if (empty($GLOBALS['db'])) {
165 $list = true;
166 } else {
167 $list = false;
170 if (!$list) {
171 // more than one database available and LeftFrameLight is true
172 // display db selectbox
174 // Light mode -> beginning of the select combo for databases
175 // Note: When javascript is active, the frameset will be changed from
176 // within navigation.php. With no JS (<noscript>) the whole frameset will
177 // be rebuilt with the new target frame.
180 <div id="databaseList">
181 <form method="post" action="index.php" target="_parent" id="left">
182 <label for="lightm_db"><?php echo $GLOBALS['strDatabase']; ?></label>
183 <?php
184 echo PMA_generate_common_hidden_inputs() . "\n";
185 echo $GLOBALS['PMA_List_Database']->getHtmlSelectGrouped(true) . "\n";
186 echo '<noscript>' . "\n"
187 .'<input type="submit" name="Go" value="' . $GLOBALS['strGo'] . '" />' . "\n"
188 .'</noscript>' . "\n"
189 .'</form>' . "\n"
190 .'</div>' . "\n";
191 } else {
192 echo $GLOBALS['PMA_List_Database']->getHtmlListGrouped(true) . "\n";
197 <div id="left_tableList">
198 <?php
199 // Don't display expansible/collapsible database info if:
200 // 1. $GLOBALS['server'] == 0 (no server selected)
201 // This is the case when there are multiple servers and
202 // '$GLOBALS['cfg']['ServerDefault'] = 0' is set. In that case, we want the welcome
203 // screen to appear with no database info displayed.
204 // 2. there is only one database available (ie either only one database exists
205 // or $GLOBALS['cfg']['Servers']['only_db'] is defined and is not an array)
206 // In this case, the database should not be collapsible/expandable
208 $img_plus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_plus.png"'
209 .' width="9" height="9" alt="+" />';
210 $img_minus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_minus.png"'
211 .' width="9" height="9" alt="-" />';
213 $href_left = '<a onclick="if (toggle(\'%d\')) return false;"'
214 .' href="navigation.php?%s" target="_self">';
216 $element_counter = 0;
218 if ($GLOBALS['cfg']['LeftFrameLight'] && strlen($GLOBALS['db'])) {
219 // show selected databasename as link to DefaultTabDatabase-page
220 // with table count in ()
221 $common_url_query = PMA_generate_common_url($GLOBALS['db']);
223 $db_tooltip = '';
225 if ($GLOBALS['cfg']['ShowTooltip']
226 && $GLOBALS['cfgRelation']['commwork']) {
227 $_db_tooltip = PMA_getComments($GLOBALS['db']);
228 if (is_array($_db_tooltip)) {
229 $db_tooltip = implode(' ', $_db_tooltip);
233 $disp_name = $GLOBALS['db'];
234 if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
235 $disp_name = $db_tooltip;
236 $disp_name_cut = $db_tooltip;
237 $db_tooltip = $GLOBALS['db'];
241 <p><a class="item"
242 href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . $common_url_query; ?>"
243 title="<?php echo htmlspecialchars($db_tooltip); ?>" >
244 <?php
245 if ($GLOBALS['text_dir'] === 'rtl') {
246 echo ' <bdo dir="ltr">(' . PMA_getTableCount($GLOBALS['db']) . ')</bdo> ';
248 echo htmlspecialchars($disp_name);
249 if ($GLOBALS['text_dir'] === 'ltr') {
250 echo ' <bdo dir="ltr">(' . PMA_getTableCount($GLOBALS['db']) . ')</bdo> ';
252 echo '</a></p>';
254 $table_list = PMA_getTableList($GLOBALS['db']);
255 if (count($table_list) > 0) {
256 PMA_displayTableList($table_list, true, '', $GLOBALS['db']);
257 } else {
258 echo $GLOBALS['strNoTablesFound'];
260 unset($table_list);
261 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
262 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
263 } else {
264 $common_url_query = PMA_generate_common_url();
265 PMA_displayDbList($GLOBALS['PMA_List_Database']->getGroupedDetails());
269 * displays collapsable db list
271 * @uses $_REQUEST['dbgroup']
272 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
273 * @uses $GLOBALS['strSelectADb']
274 * @uses strpos()
275 * @uses urlencode()
276 * @uses printf()
277 * @uses htmlspecialchars()
278 * @uses PMA_generate_common_url()
279 * @uses PMA_getTableList()
280 * @uses PMA_displayTableList()
281 * @global $element_counter
282 * @global $img_minus
283 * @global $img_plus
284 * @global $href_left
285 * @global $db_start
286 * @global $common_url_query
287 * @param array $ext_dblist extended db list
289 function PMA_displayDbList($ext_dblist) {
290 global $element_counter, $img_minus, $img_plus, $href_left,
291 $db_start, $common_url_query;
293 // get table list, for all databases
294 // doing this in one step takes advantage of a single query with information_schema!
295 $tables_full = PMA_DBI_get_tables_full($GLOBALS['PMA_List_Database']->items);
297 $url_dbgroup = '';
298 echo '<ul id="leftdatabaselist">';
299 $close_db_group = false;
300 foreach ($ext_dblist as $group => $db_group) {
301 if ($GLOBALS['PMA_List_Database']->count() > 1) {
302 if ($close_db_group) {
303 $url_dbgroup = '';
304 echo '</ul>';
305 echo '</li>';
306 $close_db_group = false;
308 if (count($db_group) > 1) {
309 $close_db_group = true;
310 $url_dbgroup = '&amp;dbgroup=' . urlencode($group);
311 $common_url_query = PMA_generate_common_url() . $url_dbgroup;
312 $element_counter++;
313 echo '<li class="dbgroup">';
314 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
315 || $db_start == $group || strpos($db_start, $group) === 0) {
316 // display + only if this db(group) is not preselected
317 printf($href_left, $element_counter, PMA_generate_common_url());
318 printf($img_minus, $element_counter);
319 } else {
320 printf($href_left, $element_counter, $common_url_query);
321 printf($img_plus, $element_counter);
323 echo '</a> ' . $group . "\n";
324 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
325 || $db_start == $group || strpos($db_start, $group) === 0) {
326 echo '<ul id="subel' . $element_counter . '">' . "\n";
327 } else {
328 echo '<ul id="subel' . $element_counter . '"'
329 .' style="display: none">' . "\n";
333 foreach ($db_group as $db) {
334 $common_url_query = PMA_generate_common_url($db['name']) . $url_dbgroup;
336 $element_counter++;
337 // Displays the database name
338 echo '<li>' . "\n";
340 if ($GLOBALS['PMA_List_Database']->count() > 1) {
341 // only with more than one db we need collapse ...
342 if ($db_start != $db['name'] || $db['num_tables'] < 1) {
343 // display + only if this db is not preselected
344 // or table count is 0
345 printf($href_left, $element_counter, $common_url_query);
346 printf($img_plus, $element_counter);
347 } else {
348 printf($href_left, $element_counter,
349 PMA_generate_common_url() . $url_dbgroup);
350 printf($img_minus, $element_counter);
352 echo '</a>';
354 // ... and we need to refresh both frames on db selection
356 <a class="item"
357 id="<?php echo htmlspecialchars($db['name']); ?>"
358 href="index.php?<?php echo $common_url_query; ?>"
359 target="_parent"
360 title="<?php echo htmlspecialchars($db['comment']); ?>"
361 onclick="
362 if (! toggle('<?php echo $element_counter; ?>', true))
363 window.parent.goTo('./navigation.php?<?php echo $common_url_query; ?>');
364 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
365 . '?' . $common_url_query; ?>', 'main');
366 return false;">
367 <?php
368 if ($GLOBALS['text_dir'] === 'rtl') {
369 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
371 echo htmlspecialchars($db['disp_name']);
372 if ($GLOBALS['text_dir'] === 'ltr') {
373 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
376 </a>
377 <?php
378 } else {
379 // with only 1 db available we dont need to refresh left frame
380 // on db selection, only phpmain
382 <a href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
383 . '?' . $common_url_query; ?>"
384 id="<?php echo htmlspecialchars($db['name']); ?>"
385 title="<?php echo htmlspecialchars($db['comment']); ?>">
386 <?php
387 if ($GLOBALS['text_dir'] === 'rtl') {
388 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
390 echo htmlspecialchars($db['disp_name']);
391 if ($GLOBALS['text_dir'] === 'ltr') {
392 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
395 </a>
396 <?php
398 if ($db['num_tables']) {
399 if (isset($tables_full[$db['name']])) {
400 $tables = PMA_getTableList($db['name'], $tables_full[$db['name']]);
401 } elseif (isset($tables_full[strtolower($db['name'])])) {
402 // on windows with lower_case_table_names = 1
403 // MySQL returns
404 // with SHOW DATABASES or information_schema.SCHEMATA: `Test`
405 // but information_schema.TABLES gives `test`
406 // bug #1436171
407 // sf.net/tracker/?func=detail&aid=1436171&group_id=23067&atid=377408
408 $tables = PMA_getTableList($db['name'], $tables_full[strtolower($db['name'])]);
409 } else {
410 $tables = PMA_getTableList($db['name']);
412 $child_visible =
413 (bool) ($GLOBALS['PMA_List_Database']->count() === 1 || $db_start == $db['name']);
414 PMA_displayTableList($tables, $child_visible, '', $db['name']);
415 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
416 // no tables and LeftFrameLight:
417 // display message no tables in selected db
418 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
420 echo '</li>' . "\n";
421 } // end foreach db
422 } // end foreach group
424 if ($close_db_group) {
425 $url_dbgroup = '';
426 echo '</ul>';
427 echo '</li>';
428 $close_db_group = false;
431 echo '</ul>' . "\n";
435 * display unordered list of tables
436 * calls itself recursively if table in given list
437 * is a list itself
439 * @uses is_array()
440 * @uses count()
441 * @uses urlencode()
442 * @uses strpos()
443 * @uses printf()
444 * @uses htmlspecialchars()
445 * @uses strlen()
446 * @uses is_array()
447 * @uses PMA_displayTableList()
448 * @uses $_REQUEST['tbl_group']
449 * @uses $GLOBALS['common_url_query']
450 * @uses $GLOBALS['table']
451 * @uses $GLOBALS['pmaThemeImage']
452 * @uses $GLOBALS['cfg']['LeftFrameTableSeparator']
453 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
454 * @uses $GLOBALS['cfg']['DefaultTabTable']
455 * @uses $GLOBALS['strRows']
456 * @uses $GLOBALS['strBrowse']
457 * @global integer the element counter
458 * @global string html code for '-' image
459 * @global string html code for '+' image
460 * @global string html code for self link
461 * @param array $tables array of tables/tablegroups
462 * @param boolean $visible wether the list is visible or not
463 * @param string $tab_group_full full tab group name
464 * @param string $table_db db of this table
466 function PMA_displayTableList($tables, $visible = false,
467 $tab_group_full = '', $table_db = '')
469 if (! is_array($tables) || count($tables) === 0) {
470 return;
473 global $element_counter, $img_minus, $img_plus, $href_left;
474 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
476 if ($visible) {
477 echo '<ul id="subel' . $element_counter . '">';
478 } else {
479 echo '<ul id="subel' . $element_counter . '" style="display: none">';
481 foreach ($tables as $group => $table) {
482 if (isset($table['is' . $sep . 'group'])) {
483 $common_url_query = $GLOBALS['common_url_query']
484 . '&amp;tbl_group=' . urlencode($tab_group_full . $group);
486 $element_counter++;
487 echo '<li>' . "\n";
488 if ($visible
489 && ((isset($_REQUEST['tbl_group'])
490 && (strpos($_REQUEST['tbl_group'], $group) === 0
491 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
492 || strpos($GLOBALS['table'], $group) === 0)) {
493 printf($href_left, $element_counter,
494 $GLOBALS['common_url_query'] . '&amp;tbl_group=' . $tab_group_full);
495 printf($img_minus, $element_counter);
496 } else {
497 printf($href_left, $element_counter, $common_url_query);
498 printf($img_plus, $element_counter);
500 echo '</a>';
502 <a href="index.php?<?php echo $common_url_query; ?>"
503 target="_parent"
504 onclick="
505 if (! toggle('<?php echo $element_counter; ?>', true))
506 window.parent.goTo('./navigation.php?<?php echo $common_url_query; ?>');
507 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
508 . '?' . $common_url_query; ?>', 'main');
509 return false;">
510 <?php
511 if ($GLOBALS['text_dir'] === 'rtl') {
512 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
514 echo htmlspecialchars(substr($group, 0, strlen($group) - strlen($sep)));
515 if ($GLOBALS['text_dir'] === 'ltr') {
516 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
519 </a>
520 <?php
522 unset($table['is' . $sep . 'group']);
523 unset($table['tab' . $sep . 'group']);
524 unset($table['tab' . $sep . 'count']);
526 if ($visible &&
527 ((isset($_REQUEST['tbl_group'])
528 && (strpos($_REQUEST['tbl_group'], $group) === 0
529 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
530 || strpos($GLOBALS['table'], $group) === 0)) {
531 PMA_displayTableList($table, true,
532 $tab_group_full . $group, $table_db);
533 } else {
534 PMA_displayTableList($table, false, '', $table_db);
536 echo '</li>' . "\n";
537 } elseif (is_array($table)) {
538 $href = $GLOBALS['cfg']['DefaultTabTable'] . '?'
539 .$GLOBALS['common_url_query'] . '&amp;table='
540 .urlencode($table['Name']);
541 echo '<li>' . "\n";
542 echo '<a title="' . $GLOBALS['strBrowse'] . ': '
543 . htmlspecialchars($table['Comment'])
544 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')"'
545 .' id="browse_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
546 .' href="sql.php?' . $GLOBALS['common_url_query']
547 .'&amp;table=' . urlencode($table['Name'])
548 .'&amp;goto=' . $GLOBALS['cfg']['DefaultTabTable']
549 . '" >'
550 .'<img class="icon"';
551 if ('VIEW' === strtoupper($table['Comment'])) {
552 echo ' src="' . $GLOBALS['pmaThemeImage'] . 's_views.png"';
553 } else {
554 echo ' src="' . $GLOBALS['pmaThemeImage'] . 'b_sbrowse.png"';
556 echo ' id="icon_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
557 .' width="10" height="10" alt="' . $GLOBALS['strBrowse'] . '" /></a>' . "\n"
558 .'<a href="' . $href . '" title="' . htmlspecialchars($table['Comment']
559 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows']) . ')"'
560 .' id="' . htmlspecialchars($table_db . '.' . $table['Name']) . '">'
561 // preserve spaces in table name
562 . str_replace(' ', '&nbsp;', htmlspecialchars($table['disp_name'])) . '</a>';
563 echo '</li>' . "\n";
566 echo '</ul>';
569 echo '</div>';
570 PMA_exitNavigationFrame();