Rename db_* files to drop useless _details part.
[phpmyadmin/crack.git] / navigation.php
blob36aaebc8d63b8e165dc13f276a704c85c6177d00
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
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.lib.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_outBufferPost()
56 * @uses PMA_DBI_close()
57 * @access private only to be used in navigation.php
59 function PMA_exitNavigationFrame()
61 echo '</body></html>';
63 /**
64 * Close MySQL connections
66 if (isset($GLOBALS['controllink']) && $GLOBALS['controllink']) {
67 @PMA_DBI_close($GLOBALS['controllink']);
69 if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
70 @PMA_DBI_close($GLOBALS['userlink']);
73 /**
74 * Sends bufferized data
76 PMA_outBufferPost();
78 exit();
81 // free the session file, for the other frames to be loaded
82 session_write_close();
84 /**
85 * the output compression library
87 require_once './libraries/ob.lib.php';
89 PMA_outBufferPre();
92 * selects the database if there is only one on current server
94 if ($GLOBALS['server'] && ! strlen($GLOBALS['db'])) {
95 $GLOBALS['db'] = $GLOBALS['PMA_List_Database']->getSingleItem();
98 $db_start = $GLOBALS['db'];
101 * the relation library
103 require_once './libraries/relation.lib.php';
104 $cfgRelation = PMA_getRelationsParam();
107 * garvin: For re-usability, moved http-headers to a seperate file.
108 * It can now be included by libraries/header.inc.php, querywindow.php.
110 require_once './libraries/header_http.inc.php';
113 * Displays the frame
115 // xml declaration moves IE into quirks mode, making much trouble with CSS
116 /* echo '<?xml version="1.0" encoding="' . $GLOBALS['charset'] . '"?>'; */
118 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
119 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
120 <html xmlns="http://www.w3.org/1999/xhtml"
121 xml:lang="<?php echo $available_languages[$lang][2]; ?>"
122 lang="<?php echo $available_languages[$lang][2]; ?>"
123 dir="<?php echo $GLOBALS['text_dir']; ?>">
125 <head>
126 <link rel="icon" href="./favicon.ico" type="image/x-icon" />
127 <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" />
128 <title>phpMyAdmin</title>
129 <meta http-equiv="Content-Type"
130 content="text/html; charset=<?php echo $GLOBALS['charset']; ?>" />
131 <base target="frame_content" />
132 <link rel="stylesheet" type="text/css"
133 href="./css/phpmyadmin.css.php?<?php echo PMA_generate_common_url('', ''); ?>&amp;js_frame=left" />
134 <script type="text/javascript" src="js/navigation.js"></script>
135 <script type="text/javascript">
136 // <![CDATA[
137 var image_minus = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_minus.png';
138 var image_plus = '<?php echo $GLOBALS['pmaThemeImage']; ?>b_plus.png';
139 // ]]>
140 </script>
141 <?php
143 * remove horizontal scroll bar bug in IE 6 by forcing a vertical scroll bar
146 <!--[if IE 6]>
147 <style type="text/css">
148 /* <![CDATA[ */
149 html {
150 overflow-y: scroll;
152 /* ]]> */
153 </style>
154 <![endif]-->
155 </head>
157 <body id="body_leftFrame" onload="PMA_setFrameSize();" onresize="PMA_saveFrameSize();">
158 <?php
159 require './libraries/navigation_header.inc.php';
160 if (! $GLOBALS['server']) {
161 // no server selected
162 PMA_exitNavigationFrame();
163 } elseif (! $GLOBALS['PMA_List_Database']->count()) {
164 // no database available, so we break here
165 echo '<p>' . $GLOBALS['strNoDatabases'] . '</p>';
166 PMA_exitNavigationFrame();
167 } elseif ($GLOBALS['cfg']['LeftFrameLight'] && $GLOBALS['PMA_List_Database']->count() > 1) {
168 // more than one database available and LeftFrameLight is true
169 // display db selectbox
171 // Light mode -> beginning of the select combo for databases
172 // Note: When javascript is active, the frameset will be changed from
173 // within navigation.php. With no JS (<noscript>) the whole frameset will
174 // be rebuilt with the new target frame.
177 <div id="databaseList">
178 <form method="post" action="index.php" target="_parent" id="left">
179 <label for="lightm_db"><?php echo $GLOBALS['strDatabase']; ?></label>
180 <?php
181 echo PMA_generate_common_hidden_inputs() . "\n";
182 echo $GLOBALS['PMA_List_Database']->getHtmlSelectGrouped(true) . "\n";
183 echo '<noscript>' . "\n"
184 .'<input type="submit" name="Go" value="' . $GLOBALS['strGo'] . '" />' . "\n"
185 .'</noscript>' . "\n"
186 .'</form>' . "\n"
187 .'</div>' . "\n";
191 <div id="left_tableList">
192 <?php
193 // Don't display expansible/collapsible database info if:
194 // 1. $GLOBALS['server'] == 0 (no server selected)
195 // This is the case when there are multiple servers and
196 // '$GLOBALS['cfg']['ServerDefault'] = 0' is set. In that case, we want the welcome
197 // screen to appear with no database info displayed.
198 // 2. there is only one database available (ie either only one database exists
199 // or $GLOBALS['cfg']['Servers']['only_db'] is defined and is not an array)
200 // In this case, the database should not be collapsible/expandable
202 $img_plus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_plus.png"'
203 .' width="9" height="9" alt="+" />';
204 $img_minus = '<img class="icon" id="el%dImg" src="' . $pmaThemeImage . 'b_minus.png"'
205 .' width="9" height="9" alt="-" />';
207 $href_left = '<a onclick="if (toggle(\'%d\')) return false;"'
208 .' href="navigation.php?%s" target="_self">';
210 $element_counter = 0;
212 if ($GLOBALS['cfg']['LeftFrameLight'] && isset($GLOBALS['db']) && strlen($GLOBALS['db'])) {
213 // show selected databasename as link to DefaultTabDatabase-page
214 // with table count in ()
215 $common_url_query = PMA_generate_common_url($GLOBALS['db']);
217 $db_tooltip = '';
219 if ($GLOBALS['cfg']['ShowTooltip']
220 && $GLOBALS['cfgRelation']['commwork']) {
221 $_db_tooltip = PMA_getComments($GLOBALS['db']);
222 if (is_array($_db_tooltip)) {
223 $db_tooltip = implode(' ', $_db_tooltip);
227 $disp_name = $GLOBALS['db'];
228 if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
229 $disp_name = $db_tooltip;
230 $disp_name_cut = $db_tooltip;
231 $db_tooltip = $GLOBALS['db'];
235 <p><a class="item"
236 href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . $common_url_query; ?>"
237 title="<?php echo htmlspecialchars($db_tooltip); ?>" >
238 <?php
239 if ($GLOBALS['text_dir'] === 'rtl') {
240 echo ' <bdo dir="ltr">(' . PMA_getTableCount($GLOBALS['db']) . ')</bdo> ';
242 echo htmlspecialchars($disp_name);
243 if ($GLOBALS['text_dir'] === 'ltr') {
244 echo ' <bdo dir="ltr">(' . PMA_getTableCount($GLOBALS['db']) . ')</bdo> ';
246 echo '</a></p>';
248 $table_list = PMA_getTableList($GLOBALS['db']);
249 if (count($table_list) > 0) {
250 PMA_displayTableList($table_list, true, '', $GLOBALS['db']);
251 } else {
252 echo $GLOBALS['strNoTablesFound'];
254 unset($table_list);
255 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
256 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
257 } else {
258 $common_url_query = PMA_generate_common_url();
259 PMA_displayDbList($GLOBALS['PMA_List_Database']->getGroupedDetails());
263 * displays collapsable db list
265 * @uses $_REQUEST['dbgroup']
266 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
267 * @uses $GLOBALS['strSelectADb']
268 * @uses strpos()
269 * @uses urlencode()
270 * @uses printf()
271 * @uses htmlspecialchars()
272 * @uses PMA_generate_common_url()
273 * @uses PMA_getTableList()
274 * @uses PMA_displayTableList()
275 * @global $element_counter
276 * @global $img_minus
277 * @global $img_plus
278 * @global $href_left
279 * @global $db_start
280 * @global $common_url_query
281 * @param array $ext_dblist extended db list
283 function PMA_displayDbList($ext_dblist) {
284 global $element_counter, $img_minus, $img_plus, $href_left,
285 $db_start, $common_url_query;
287 // get table list, for all databases
288 // doing this in one step takes advantage of a single query with information_schema!
289 $tables_full = PMA_DBI_get_tables_full($GLOBALS['PMA_List_Database']->items);
291 $url_dbgroup = '';
292 echo '<ul id="leftdatabaselist">';
293 $close_db_group = false;
294 foreach ($ext_dblist as $group => $db_group) {
295 if ($GLOBALS['PMA_List_Database']->count() > 1) {
296 if ($close_db_group) {
297 $url_dbgroup = '';
298 echo '</ul>';
299 echo '</li>';
300 $close_db_group = false;
302 if (count($db_group) > 1) {
303 $close_db_group = true;
304 $url_dbgroup = '&amp;dbgroup=' . urlencode($group);
305 $common_url_query = PMA_generate_common_url() . $url_dbgroup;
306 $element_counter++;
307 echo '<li class="dbgroup">';
308 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
309 || $db_start == $group || strpos($db_start, $group) === 0) {
310 // display + only if this db(group) is not preselected
311 printf($href_left, $element_counter, PMA_generate_common_url());
312 printf($img_minus, $element_counter);
313 } else {
314 printf($href_left, $element_counter, $common_url_query);
315 printf($img_plus, $element_counter);
317 echo '</a> ' . $group . "\n";
318 if ((! empty($_REQUEST['dbgroup']) && $_REQUEST['dbgroup'] == $group)
319 || $db_start == $group || strpos($db_start, $group) === 0) {
320 echo '<ul id="subel' . $element_counter . '">' . "\n";
321 } else {
322 echo '<ul id="subel' . $element_counter . '"'
323 .' style="display: none">' . "\n";
327 foreach ($db_group as $db) {
328 $common_url_query = PMA_generate_common_url($db['name']) . $url_dbgroup;
330 $element_counter++;
331 // Displays the database name
332 echo '<li>' . "\n";
334 if ($GLOBALS['PMA_List_Database']->count() > 1) {
335 // only with more than one db we need collapse ...
336 if ($db_start != $db['name'] || $db['num_tables'] < 1) {
337 // display + only if this db is not preselected
338 // or table count is 0
339 printf($href_left, $element_counter, $common_url_query);
340 printf($img_plus, $element_counter);
341 } else {
342 printf($href_left, $element_counter,
343 PMA_generate_common_url() . $url_dbgroup);
344 printf($img_minus, $element_counter);
346 echo '</a>';
348 // ... and we need to refresh both frames on db selection
350 <a class="item"
351 id="<?php echo htmlspecialchars($db['name']); ?>"
352 href="index.php?<?php echo $common_url_query; ?>"
353 target="_parent"
354 title="<?php echo htmlspecialchars($db['comment']); ?>"
355 onclick="
356 if (! toggle('<?php echo $element_counter; ?>', true))
357 window.parent.goTo('./navigation.php?<?php echo $common_url_query; ?>');
358 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
359 . '?' . $common_url_query; ?>', 'main');
360 return false;">
361 <?php
362 if ($GLOBALS['text_dir'] === 'rtl') {
363 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
365 echo htmlspecialchars($db['disp_name']);
366 if ($GLOBALS['text_dir'] === 'ltr') {
367 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
370 </a>
371 <?php
372 } else {
373 // with only 1 db available we dont need to refresh left frame
374 // on db selection, only phpmain
376 <a href="<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
377 . '?' . $common_url_query; ?>"
378 id="<?php echo htmlspecialchars($db['name']); ?>"
379 title="<?php echo htmlspecialchars($db['comment']); ?>">
380 <?php
381 if ($GLOBALS['text_dir'] === 'rtl') {
382 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
384 echo htmlspecialchars($db['disp_name']);
385 if ($GLOBALS['text_dir'] === 'ltr') {
386 echo ' <bdo dir="ltr">(' . $db['num_tables'] . ')</bdo> ';
389 </a>
390 <?php
392 if ($db['num_tables']) {
393 if (isset($tables_full[$db['name']])) {
394 $tables = PMA_getTableList($db['name'], $tables_full[$db['name']]);
395 } elseif (isset($tables_full[strtolower($db['name'])])) {
396 // on windows with lower_case_table_names = 1
397 // MySQL returns
398 // with SHOW DATABASES or information_schema.SCHEMATA: `Test`
399 // but information_schema.TABLES gives `test`
400 // bug #1436171
401 // sf.net/tracker/?func=detail&aid=1436171&group_id=23067&atid=377408
402 $tables = PMA_getTableList($db['name'], $tables_full[strtolower($db['name'])]);
403 } else {
404 $tables = PMA_getTableList($db['name']);
406 $child_visible =
407 (bool) ($GLOBALS['PMA_List_Database']->count() === 1 || $db_start == $db['name']);
408 PMA_displayTableList($tables, $child_visible, '', $db['name']);
409 } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
410 // no tables and LeftFrameLight:
411 // display message no tables in selected db
412 echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
414 echo '</li>' . "\n";
415 } // end foreach db
416 } // end foreach group
418 if ($close_db_group) {
419 $url_dbgroup = '';
420 echo '</ul>';
421 echo '</li>';
422 $close_db_group = false;
425 echo '</ul>' . "\n";
429 * display unordered list of tables
430 * calls itself recursively if table in given list
431 * is a list itself
433 * @uses is_array()
434 * @uses count()
435 * @uses urlencode()
436 * @uses strpos()
437 * @uses printf()
438 * @uses htmlspecialchars()
439 * @uses strlen()
440 * @uses is_array()
441 * @uses PMA_displayTableList()
442 * @uses $_REQUEST['tbl_group']
443 * @uses $GLOBALS['common_url_query']
444 * @uses $GLOBALS['table']
445 * @uses $GLOBALS['pmaThemeImage']
446 * @uses $GLOBALS['cfg']['LeftFrameTableSeparator']
447 * @uses $GLOBALS['cfg']['DefaultTabDatabase']
448 * @uses $GLOBALS['cfg']['DefaultTabTable']
449 * @uses $GLOBALS['strRows']
450 * @uses $GLOBALS['strBrowse']
451 * @global integer the element counter
452 * @global string html code for '-' image
453 * @global string html code for '+' image
454 * @global string html code for self link
455 * @param array $tables array of tables/tablegroups
456 * @param boolean $visible wether the list is visible or not
457 * @param string $tab_group_full full tab group name
458 * @param string $table_db db of this table
460 function PMA_displayTableList($tables, $visible = false,
461 $tab_group_full = '', $table_db = '')
463 if (! is_array($tables) || count($tables) === 0) {
464 return;
467 global $element_counter, $img_minus, $img_plus, $href_left;
468 $sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
470 if ($visible) {
471 echo '<ul id="subel' . $element_counter . '">';
472 } else {
473 echo '<ul id="subel' . $element_counter . '" style="display: none">';
475 foreach ($tables as $group => $table) {
476 if (isset($table['is' . $sep . 'group'])) {
477 $common_url_query = $GLOBALS['common_url_query']
478 . '&amp;tbl_group=' . urlencode($tab_group_full . $group);
480 $element_counter++;
481 echo '<li>' . "\n";
482 if ($visible &&
483 ((isset($_REQUEST['tbl_group'])
484 && (strpos($_REQUEST['tbl_group'], $group) === 0
485 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
487 (isset($GLOBALS['table'])
488 && strpos($GLOBALS['table'], $group) === 0))) {
489 printf($href_left, $element_counter,
490 $GLOBALS['common_url_query'] . '&amp;tbl_group=' . $tab_group_full);
491 printf($img_minus, $element_counter);
492 } else {
493 printf($href_left, $element_counter, $common_url_query);
494 printf($img_plus, $element_counter);
496 echo '</a>';
498 <a href="index.php?<?php echo $common_url_query; ?>"
499 target="_parent"
500 onclick="
501 if (! toggle('<?php echo $element_counter; ?>', true))
502 window.parent.goTo('./navigation.php?<?php echo $common_url_query; ?>');
503 window.parent.goTo('./<?php echo $GLOBALS['cfg']['DefaultTabDatabase']
504 . '?' . $common_url_query; ?>', 'main');
505 return false;">
506 <?php
507 if ($GLOBALS['text_dir'] === 'rtl') {
508 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
510 echo htmlspecialchars(substr($group, 0, strlen($group) - strlen($sep)));
511 if ($GLOBALS['text_dir'] === 'ltr') {
512 echo ' <bdo dir="ltr">(' . $table['tab' . $sep . 'count'] . ')</bdo> ';
515 </a>
516 <?php
518 unset($table['is' . $sep . 'group']);
519 unset($table['tab' . $sep . 'group']);
520 unset($table['tab' . $sep . 'count']);
522 if ($visible &&
523 ((isset($_REQUEST['tbl_group'])
524 && (strpos($_REQUEST['tbl_group'], $group) === 0
525 || strpos($_REQUEST['tbl_group'], $sep . $group) !== false))
527 (isset($GLOBALS['table'])
528 && strpos($GLOBALS['table'], $group) === 0))) {
529 PMA_displayTableList($table, true,
530 $tab_group_full . $group, $table_db);
531 } else {
532 PMA_displayTableList($table, false, '', $table_db);
534 echo '</li>' . "\n";
535 } elseif (is_array($table)) {
536 $href = $GLOBALS['cfg']['DefaultTabTable'] . '?'
537 .$GLOBALS['common_url_query'] . '&amp;table='
538 .urlencode($table['Name']);
539 echo '<li>' . "\n";
540 echo '<a title="' . $GLOBALS['strBrowse'] . ': '
541 . htmlspecialchars($table['Comment'])
542 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')"'
543 .' id="browse_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
544 .' href="sql.php?' . $GLOBALS['common_url_query']
545 .'&amp;table=' . urlencode($table['Name'])
546 .'&amp;goto=' . $GLOBALS['cfg']['DefaultTabTable']
547 . '" >'
548 .'<img class="icon"';
549 if ('VIEW' === strtoupper($table['Comment'])) {
550 echo ' src="' . $GLOBALS['pmaThemeImage'] . 's_views.png"';
551 } else {
552 echo ' src="' . $GLOBALS['pmaThemeImage'] . 'b_sbrowse.png"';
554 echo ' id="icon_' . htmlspecialchars($table_db . '.' . $table['Name']) . '"'
555 .' width="10" height="10" alt="' . $GLOBALS['strBrowse'] . '" /></a>' . "\n"
556 .'<a href="' . $href . '" title="' . $table['Comment']
557 .' (' . PMA_formatNumber($table['Rows'], 0) . ' ' . $GLOBALS['strRows'] . ')"'
558 .' id="' . htmlspecialchars($table_db . '.' . $table['Name']) . '">'
559 . htmlspecialchars($table['disp_name']) . '</a>';
560 echo '</li>' . "\n";
563 echo '</ul>';
566 echo '</div>';
567 PMA_exitNavigationFrame();