r3190 Tab redirection moved to index.php
[racktables] / index.php
1 <?php
2 ob_start();
3 try {
4 require 'inc/interface.php';
5 require 'inc/init.php';
6 $pageno = (isset ($_REQUEST['page'])) ? $_REQUEST['page'] : 'index';
7 // Special handling of tab number to substitute the "last" index where applicable.
8 // Always show explicitly requested tab, substitute the last used name in case
9 // it is awailable, fall back to the default one.
10
11 if (isset ($_REQUEST['tab'])) {
12 $tabno = $_REQUEST['tab'];
13 // check if we accidentaly got on a dynamic tab that shouldn't be shown for this object
14 if ( isset($trigger[$pageno][$tabno]) and !strlen($trigger[$pageno][$tabno] ()) ) {
15 $tabno = 'default';
16 $url = "index.php?page=$pageno&tab=$tabno&".urlizeGetParameters(array('page', 'tab'));
17 header('Location: '.$url);
18 exit();
19 }
20 } elseif (basename($_SERVER['PHP_SELF']) == 'index.php' and getConfigVar ('SHOW_LAST_TAB') == 'yes' and isset ($_SESSION['RTLT'][$pageno]))
21 {
22 $tabno = $_SESSION['RTLT'][$pageno];
23 $url = "index.php?page=$pageno&tab=$tabno&".urlizeGetParameters(array('page', 'tab'));
24 header('Location: '.$url);
25 exit();
26 }
27 else
28 $tabno = 'default';
29
30 // no ctx override is necessary
31 redirectIfNecessary();
32 fixContext();
33 if (!permitted())
34 renderAccessDenied();
35 // Only store the tab name after clearance is got. Any failure is unhandleable.
36 $_SESSION['RTLT'][$pageno] = $tabno;
37
38 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
39 echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
40 echo '<head><title>' . getTitle ($pageno) . "</title>\n";
41 echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
42 echo "<link rel=stylesheet type='text/css' href=pi.css />\n";
43 echo "<link rel=icon href='" . getFaviconURL() . "' type='image/x-icon' />";
44 printStyle();
45 ?>
46 <script language='javascript' type='text/javascript' src='js/racktables.js'></script>
47 <script language='javascript' type='text/javascript' src='js/jquery-1.3.1.min.js'></script>
48 <script language='javascript' type='text/javascript' src='js/live_validation.js'></script>
49 <script language='javascript' type='text/javascript' src='js/codepress/codepress.js'></script>
50 </head>
51 <body>
52 <table border=0 cellpadding=0 cellspacing=0 width='100%' height='100%' class=maintable>
53 <tr class=mainheader>
54 <td colspan=2>
55 <table width='100%' cellspacing=0 cellpadding=2 border=0>
56 <tr>
57 <td valign=top><a href='http://racktables.org/'><?php printImageHREF ('logo'); ?></a></td>
58 <td valign=top><div class=greeting><?php printGreeting(); ?></div></td>
59 </tr>
60 </table>
61 </td>
62 </tr>
63
64 <tr>
65 <td class="menubar" colspan=2>
66 <table border="0" width="100%" cellpadding="3" cellspacing="0">
67 <tr>
68 <?php showPathAndSearch ($pageno); ?>
69 </tr>
70 </table>
71 </td>
72 </tr>
73
74 <tr>
75 <?php
76 showTabs ($pageno, $tabno);
77 ?>
78 </tr>
79
80 <tr>
81 <td colspan=2>
82 <?php
83 if (isset ($tabhandler[$pageno][$tabno]))
84 {
85 if (isset ($page[$pageno]['bypass']) && isset ($page[$pageno]['bypass_type']))
86 {
87 switch ($page[$pageno]['bypass_type'])
88 {
89 case 'uint':
90 assertUIntArg ($page[$pageno]['bypass'], 'index');
91 break;
92 case 'uint0':
93 assertUIntArg ($page[$pageno]['bypass'], 'index', TRUE);
94 break;
95 case 'inet4':
96 assertIPv4Arg ($page[$pageno]['bypass'], 'index');
97 break;
98 case 'string':
99 assertStringArg ($page[$pageno]['bypass'], 'index');
100 break;
101 default:
102 throw new RuntimeException ('Dispatching error for bypass parameter');
103 }
104 showMessageOrError();
105 $tabhandler[$pageno][$tabno] ($_REQUEST[$page[$pageno]['bypass']]);
106 }
107 else
108 {
109 showMessageOrError();
110 $tabhandler[$pageno][$tabno] ();
111 }
112 }
113 elseif (isset ($page[$pageno]['handler']))
114 {
115 showMessageOrError();
116 $page[$pageno]['handler'] ($tabno);
117 }
118 else
119 throw new RuntimeException ("Failed to find handler for page '${pageno}', tab '${tabno}'");
120 ?>
121 </td>
122 </tr>
123 </table>
124 </body>
125 </html>
126 <?php
127 ob_end_flush();
128 } catch (Exception $e) {
129 ob_end_clean();
130 printException($e);
131 }