r1106 importing RackTables trunk
[racktables] / inc / navigation.php
1 <?
2 /*
3 *
4 * This file implements generic navigation for RackTables.
5 *
6 */
7
8 $page['index']['title'] = 'static_title';
9 $page['index']['handler'] = 'renderIndex';
10
11 $page['rackspace']['title'] = 'static_title';
12 $page['rackspace']['handler'] = 'handler_rackspace';
13 $page['rackspace']['parent'] = 'index';
14 $tab['rackspace']['default'] = 'Browse';
15 $tab['rackspace']['history'] = 'History';
16
17 $page['objects']['title'] = 'static_title';
18 $page['objects']['handler'] = 'handler_objects';
19 $page['objects']['parent'] = 'index';
20 $tab['objects']['default'] = 'View';
21 $tab['objects']['newobj'] = 'Add an object';
22 $tab['objects']['newmulti'] = 'Add multiple objects';
23
24 $page['row']['title'] = 'dynamic_title_row';
25 $page['row']['handler'] = 'handler_row';
26 $page['row']['bypass'] = 'row_id';
27 $page['row']['parent'] = 'rackspace';
28 $tab['row']['default'] = 'View';
29 $tab['row']['newrack'] = 'Add new rack';
30
31 $page['rack']['title'] = 'dynamic_title_rack';
32 $page['rack']['handler'] = 'handler_rack';
33 $page['rack']['bypass'] = 'rack_id';
34 $page['rack']['parent'] = 'row';
35 $tab['rack']['default'] = 'View';
36 $tab['rack']['edit'] = 'Properties';
37 $tab['rack']['design'] = 'Design';
38 $tab['rack']['problems'] = 'Problems';
39
40 $page['objgroup']['title'] = 'dynamic_title_objgroup';
41 $page['objgroup']['handler'] = 'handler_objgroup';
42 $page['objgroup']['bypass'] = 'group_id';
43 $page['objgroup']['parent'] = 'objects';
44
45 $page['object']['title'] = 'dynamic_title_object';
46 $page['object']['handler'] = 'handler_object';
47 $page['object']['bypass'] = 'object_id';
48 $page['object']['parent'] = 'objgroup';
49 $tab['object']['default'] = 'View';
50 $tab['object']['edit'] = 'Properties';
51 $tab['object']['rackspace'] = 'Rackspace';
52 $tab['object']['ports'] = 'Ports';
53 $tab['object']['network'] = 'IPv4';
54 $tab['object']['portfwrd'] = 'Port Forwarding';
55 $ophandler['object']['ports']['addPort'] = 'addPortForObject';
56 $ophandler['object']['ports']['delPort'] = 'delPortFromObject';
57 $ophandler['object']['ports']['editPort'] = 'editPortForObject';
58 $ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
59 $ophandler['object']['ports']['unlinkPort'] = 'unlinkPortForObject';
60 $ophandler['object']['ports']['addMultiPorts'] = 'addMultiPorts';
61 $ophandler['object']['ports']['useup'] = 'useupPort';
62 $ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObject';
63 $ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
64 $ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
65 $ophandler['object']['edit']['del'] = 'resetAttrValue';
66 $ophandler['object']['edit']['upd'] = 'updateAttrValue';
67 $ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
68 $ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
69 $ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
70
71 $page['ipv4space']['title'] = 'static_title';
72 $page['ipv4space']['handler'] = 'handler_ipv4space';
73 $page['ipv4space']['parent'] = 'index';
74 $tab['ipv4space']['default'] = 'Browse';
75 $tab['ipv4space']['newrange'] = 'Manage ranges';
76 $ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
77 $ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
78
79 $page['iprange']['title'] = 'dynamic_title_iprange';
80 $page['iprange']['handler'] = 'handler_iprange';
81 $page['iprange']['parent'] = 'ipv4space';
82 $page['iprange']['bypass'] = 'id';
83 $tab['iprange']['default'] = 'Browse';
84 $tab['iprange']['properties'] = 'Properties';
85 $ophandler['iprange']['properties']['editRange'] = 'editRange';
86
87 $page['ipaddress']['title'] = 'dynamic_title_ipaddress';
88 $page['ipaddress']['handler'] = 'handler_ipaddress';
89 $page['ipaddress']['parent'] = 'iprange';
90 $page['ipaddress']['bypass'] = 'ip';
91 $tab['ipaddress']['default'] = 'Browse';
92 $tab['ipaddress']['properties'] = 'Properties';
93 $tab['ipaddress']['assignment'] = 'Allocation';
94 $ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
95 $ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
96 $ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
97 $ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
98
99 $page['search']['title'] = 'dynamic_title_search';
100 $page['search']['handler'] = 'handler_search';
101 $page['search']['parent'] = 'index';
102 $page['search']['bypass'] = 'q';
103
104 $page['config']['title'] = 'static_title';
105 $page['config']['handler'] = 'handler_config';
106 $page['config']['parent'] = 'index';
107
108 $page['accounts']['title'] = 'static_title';
109 $page['accounts']['handler'] = 'handler_accounts';
110 $page['accounts']['parent'] = 'config';
111 $tab['accounts']['default'] = 'View';
112 $tab['accounts']['edit'] = 'Change';
113 $ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
114 $ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
115 $ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
116 $ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
117
118 $page['perms']['title'] = 'static_title';
119 $page['perms']['handler'] = 'handler_perms';
120 $page['perms']['parent'] = 'config';
121 $tab['perms']['default'] = 'View';
122 $tab['perms']['edit'] = 'Change';
123 $ophandler['perms']['edit']['revoke'] = 'revokePermission';
124 $ophandler['perms']['edit']['grant'] = 'grantPermission';
125
126 $page['portmap']['title'] = 'static_title';
127 $page['portmap']['handler'] = 'handler_portmap';
128 $page['portmap']['parent'] = 'config';
129 $tab['portmap']['default'] = 'View';
130 $tab['portmap']['edit'] = 'Change';
131 $ophandler['portmap']['edit']['save'] = 'savePortMap';
132
133 $page['attrs']['title'] = 'static_title';
134 $page['attrs']['handler'] = 'handler_attrs';
135 $page['attrs']['parent'] = 'config';
136 $tab['attrs']['default'] = 'View';
137 $tab['attrs']['editattrs'] = 'Edit attributes';
138 $tab['attrs']['editmap'] = 'Edit map';
139 $ophandler['attrs']['editattrs']['add'] = 'createAttribute';
140 $ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
141 $ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
142 $ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
143 $ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
144
145 $page['dict']['title'] = 'static_title';
146 $page['dict']['handler'] = 'handler_dict';
147 $page['dict']['parent'] = 'config';
148 $tab['dict']['default'] = 'View';
149 $tab['dict']['edit'] = 'Edit words';
150 $tab['dict']['chapters'] = 'Manage chapters';
151 $ophandler['dict']['edit']['del'] = 'reduceDictionary';
152 $ophandler['dict']['edit']['upd'] = 'updateDictionary';
153 $ophandler['dict']['edit']['add'] = 'supplementDictionary';
154 $ophandler['dict']['chapters']['del'] = 'delChapter';
155 $ophandler['dict']['chapters']['upd'] = 'updateChapter';
156 $ophandler['dict']['chapters']['add'] = 'addChapter';
157
158 $page['ui']['title'] = 'static_title';
159 $page['ui']['handler'] = 'handler_ui';
160 $page['ui']['parent'] = 'config';
161
162 $page['ro']['title'] = 'static_title';
163 $page['ro']['handler'] = 'handler_ro';
164 $page['ro']['parent'] = 'config';
165
166 $page['reports']['title'] = 'static_title';
167 $page['reports']['handler'] = 'handler_reports';
168 $page['reports']['parent'] = 'index';
169 $tab['reports']['default'] = 'View';
170
171 // This function returns array if page numbers leading to the target page
172 // plus page number of target page itself. The first element is the target
173 // page number and the last element is the index page number.
174 function getPath ($targetno)
175 {
176 global $page;
177 $path = array();
178 // Recursion breaks at first parentless page.
179 if (!isset ($page[$targetno]['parent']))
180 $path = array ($targetno);
181 else
182 {
183 $path = getPath ($page[$targetno]['parent']);
184 $path[] = $targetno;
185 }
186 return $path;
187 }
188
189 function showPathAndSearch ($pageno)
190 {
191 global $root, $page, $enterprise;
192 // Path.
193 echo "<td class=activemenuitem width='99%'>${enterprise} RackTables";
194 if (isset ($page[$pageno]['title']))
195 {
196 $path = getPath ($pageno);
197 foreach ($path as $dummy => $no)
198 {
199 $title = $page[$no]['title']($no);
200 echo ": <a href='${root}?page=${no}";
201 foreach ($title['params'] as $param_name => $param_value)
202 echo "&${param_name}=${param_value}";
203 echo "'>" .$title['name'] . "</a>";
204 }
205 }
206 echo "</td>";
207 // Search form.
208 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
209 echo "<form method=get action='${root}'><td>";
210 echo '<input type=hidden name=page value=search>';
211 // This input will be the first, if we don't add ports or addresses.
212 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
213 }
214
215 function getTitle ($pageno, $tabno)
216 {
217 global $page, $enterprise;
218 if (isset ($page[$pageno]['title']))
219 {
220 $ret = $page[$pageno]['title']($pageno);
221 $ret = $ret['name'];
222 }
223 else
224 $ret = $enterprise;
225 return $ret;
226 }
227
228 function showTabs ($pageno, $tabno)
229 {
230 global $tab, $root, $page, $remote_username;
231 if (!isset ($tab[$pageno]['default']))
232 return;
233 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
234 foreach ($tab[$pageno] as $tabidx => $tabtitle)
235 {
236 // Hide forbidden tabs.
237 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
238 continue;
239 echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
240 echo " href='${root}?page=${pageno}&tab=${tabidx}";
241 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
242 {
243 $bpname = $page[$pageno]['bypass'];
244 $bpval = $_REQUEST[$bpname];
245 echo "&${bpname}=${bpval}";
246 }
247 echo "'>${tabtitle}</a></li>\n";
248 }
249 echo "</ul></div></td>\n";
250 }
251
252 // This function returns pages, which are direct children of the requested
253 // page and are accessible by the current user.
254 function getDirectChildPages ($pageno)
255 {
256 global $page, $remote_username;
257 $children = array();
258 foreach ($page as $cpageno => $cpage)
259 if
260 (
261 isset ($cpage['parent']) and
262 $cpage['parent'] == $pageno and
263 authorized ($remote_username, $cpageno, 'default') == TRUE
264 )
265 $children[$cpageno] = $cpage;
266 return $children;
267 }
268
269 function getAllChildPages ($parent)
270 {
271 global $page;
272 // Array pointer is global, so if we don't create local copies of
273 // the global array, we can't advance any more after nested call
274 // of getAllChildPages returns.
275 $mypage = $page;
276 $mykids = array();
277 foreach ($mypage as $ctitle => $cpage)
278 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
279 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
280 return $mykids;
281 }
282
283 ?>