r1425 + handle arrays appropriately
[racktables] / inc / navigation.php
CommitLineData
b325120a 1<?php
e673ee24
DO
2/*
3*
4* This file implements generic navigation for RackTables.
5*
6*/
7
83dd1b15
DO
8$page = array();
9$tab = array();
10$helptab = array();
11$trigger = array();
12$ophandler = array();
81bab70c 13$tabhandler = array();
83dd1b15 14
e673ee24
DO
15$page['index']['title'] = 'static_title';
16$page['index']['handler'] = 'renderIndex';
17
18$page['rackspace']['title'] = 'static_title';
19$page['rackspace']['handler'] = 'handler_rackspace';
20$page['rackspace']['parent'] = 'index';
21$tab['rackspace']['default'] = 'Browse';
22$tab['rackspace']['history'] = 'History';
9b0cf84f
DO
23$tab['rackspace']['firstrow'] = 'Click me!';
24$trigger['rackspace']['firstrow'] = 'trigger_emptyRackspace';
e673ee24
DO
25
26$page['objects']['title'] = 'static_title';
27$page['objects']['handler'] = 'handler_objects';
28$page['objects']['parent'] = 'index';
29$tab['objects']['default'] = 'View';
30$tab['objects']['newobj'] = 'Add an object';
31$tab['objects']['newmulti'] = 'Add multiple objects';
32
33$page['row']['title'] = 'dynamic_title_row';
34$page['row']['handler'] = 'handler_row';
35$page['row']['bypass'] = 'row_id';
36$page['row']['parent'] = 'rackspace';
37$tab['row']['default'] = 'View';
38$tab['row']['newrack'] = 'Add new rack';
39
40$page['rack']['title'] = 'dynamic_title_rack';
41$page['rack']['handler'] = 'handler_rack';
42$page['rack']['bypass'] = 'rack_id';
43$page['rack']['parent'] = 'row';
44$tab['rack']['default'] = 'View';
45$tab['rack']['edit'] = 'Properties';
46$tab['rack']['design'] = 'Design';
47$tab['rack']['problems'] = 'Problems';
beee6141
DO
48$helptab['rack']['design'] = 'rackspace';
49$helptab['rack']['problems'] = 'rackspace';
e673ee24
DO
50
51$page['objgroup']['title'] = 'dynamic_title_objgroup';
52$page['objgroup']['handler'] = 'handler_objgroup';
53$page['objgroup']['bypass'] = 'group_id';
54$page['objgroup']['parent'] = 'objects';
55
56$page['object']['title'] = 'dynamic_title_object';
e673ee24 57$page['object']['bypass'] = 'object_id';
3bebaebd 58$page['object']['bypass_type'] = 'uint';
e673ee24
DO
59$page['object']['parent'] = 'objgroup';
60$tab['object']['default'] = 'View';
61$tab['object']['edit'] = 'Properties';
62$tab['object']['rackspace'] = 'Rackspace';
63$tab['object']['ports'] = 'Ports';
64$tab['object']['network'] = 'IPv4';
737f9ac1 65$tab['object']['portfwrd'] = 'NATv4';
a684aa6f 66$tab['object']['switchvlans'] = 'Live VLANs';
9c67f713 67$tab['object']['snmpportfinder'] = 'SNMP port finder';
3ee1252b 68$tab['object']['lvsconfig'] = 'LVS configuration';
e45a78d7
DO
69$tabhandler['object']['default'] = 'renderRackObject';
70$tabhandler['object']['edit'] = 'renderEditObjectForm';
71$tabhandler['object']['rackspace'] = 'renderRackSpaceForObject';
72$tabhandler['object']['ports'] = 'renderPortsForObject';
73$tabhandler['object']['network'] = 'renderNetworkForObject';
74$tabhandler['object']['portfwrd'] = 'renderIPAddressPortForwarding';
75$tabhandler['object']['switchvlans'] = 'renderVLANMembership';
76$tabhandler['object']['snmpportfinder'] = 'renderSNMPPortFinder';
3ee1252b 77$tabhandler['object']['lvsconfig'] = 'renderLVSConfig';
bdd05c5d 78$helptab['object']['network'] = 'nets';
150fdd66 79$helptab['object']['ports'] = 'ports';
bdd05c5d
DO
80$helptab['object']['portfwrd'] = 'nets';
81$helptab['object']['rackspace'] = 'rackspace';
641fe9b0 82$trigger['object']['switchvlans'] = 'trigger_switchvlans';
9c67f713 83$trigger['object']['snmpportfinder'] = 'trigger_snmpportfinder';
e673ee24
DO
84$ophandler['object']['ports']['addPort'] = 'addPortForObject';
85$ophandler['object']['ports']['delPort'] = 'delPortFromObject';
86$ophandler['object']['ports']['editPort'] = 'editPortForObject';
87$ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
88$ophandler['object']['ports']['unlinkPort'] = 'unlinkPortForObject';
89$ophandler['object']['ports']['addMultiPorts'] = 'addMultiPorts';
90$ophandler['object']['ports']['useup'] = 'useupPort';
91$ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObject';
92$ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
93$ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
94$ophandler['object']['edit']['del'] = 'resetAttrValue';
0dfb8a2a 95$ophandler['object']['edit']['upd'] = 'updateAttrValues';
e673ee24
DO
96$ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
97$ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
98$ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
641fe9b0 99$ophandler['object']['switchvlans']['submit'] = 'updateVLANMembership';
e673ee24
DO
100
101$page['ipv4space']['title'] = 'static_title';
102$page['ipv4space']['handler'] = 'handler_ipv4space';
103$page['ipv4space']['parent'] = 'index';
104$tab['ipv4space']['default'] = 'Browse';
105$tab['ipv4space']['newrange'] = 'Manage ranges';
bdd05c5d
DO
106$helptab['ipv4space']['default'] = 'nets';
107$helptab['ipv4space']['newrange'] = 'nets';
e673ee24
DO
108$ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
109$ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
110
111$page['iprange']['title'] = 'dynamic_title_iprange';
112$page['iprange']['handler'] = 'handler_iprange';
113$page['iprange']['parent'] = 'ipv4space';
114$page['iprange']['bypass'] = 'id';
115$tab['iprange']['default'] = 'Browse';
116$tab['iprange']['properties'] = 'Properties';
bdd05c5d
DO
117$helptab['iprange']['default'] = 'nets';
118$helptab['iprange']['properties'] = 'nets';
e673ee24
DO
119$ophandler['iprange']['properties']['editRange'] = 'editRange';
120
121$page['ipaddress']['title'] = 'dynamic_title_ipaddress';
122$page['ipaddress']['handler'] = 'handler_ipaddress';
123$page['ipaddress']['parent'] = 'iprange';
124$page['ipaddress']['bypass'] = 'ip';
125$tab['ipaddress']['default'] = 'Browse';
126$tab['ipaddress']['properties'] = 'Properties';
127$tab['ipaddress']['assignment'] = 'Allocation';
bdd05c5d
DO
128$helptab['ipaddress']['default'] = 'nets';
129$helptab['ipaddress']['properties'] = 'nets';
130$helptab['ipaddress']['assignment'] = 'nets';
e673ee24
DO
131$ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
132$ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
133$ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
134$ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
135
136$page['search']['title'] = 'dynamic_title_search';
137$page['search']['handler'] = 'handler_search';
138$page['search']['parent'] = 'index';
139$page['search']['bypass'] = 'q';
140
141$page['config']['title'] = 'static_title';
142$page['config']['handler'] = 'handler_config';
143$page['config']['parent'] = 'index';
144
145$page['accounts']['title'] = 'static_title';
146$page['accounts']['handler'] = 'handler_accounts';
147$page['accounts']['parent'] = 'config';
148$tab['accounts']['default'] = 'View';
149$tab['accounts']['edit'] = 'Change';
150$ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
151$ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
152$ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
153$ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
154
155$page['perms']['title'] = 'static_title';
156$page['perms']['handler'] = 'handler_perms';
157$page['perms']['parent'] = 'config';
158$tab['perms']['default'] = 'View';
159$tab['perms']['edit'] = 'Change';
160$ophandler['perms']['edit']['revoke'] = 'revokePermission';
161$ophandler['perms']['edit']['grant'] = 'grantPermission';
162
163$page['portmap']['title'] = 'static_title';
164$page['portmap']['handler'] = 'handler_portmap';
165$page['portmap']['parent'] = 'config';
166$tab['portmap']['default'] = 'View';
167$tab['portmap']['edit'] = 'Change';
168$ophandler['portmap']['edit']['save'] = 'savePortMap';
169
170$page['attrs']['title'] = 'static_title';
171$page['attrs']['handler'] = 'handler_attrs';
172$page['attrs']['parent'] = 'config';
173$tab['attrs']['default'] = 'View';
174$tab['attrs']['editattrs'] = 'Edit attributes';
175$tab['attrs']['editmap'] = 'Edit map';
176$ophandler['attrs']['editattrs']['add'] = 'createAttribute';
177$ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
178$ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
179$ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
180$ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
181
182$page['dict']['title'] = 'static_title';
183$page['dict']['handler'] = 'handler_dict';
184$page['dict']['parent'] = 'config';
185$tab['dict']['default'] = 'View';
186$tab['dict']['edit'] = 'Edit words';
187$tab['dict']['chapters'] = 'Manage chapters';
188$ophandler['dict']['edit']['del'] = 'reduceDictionary';
189$ophandler['dict']['edit']['upd'] = 'updateDictionary';
190$ophandler['dict']['edit']['add'] = 'supplementDictionary';
191$ophandler['dict']['chapters']['del'] = 'delChapter';
192$ophandler['dict']['chapters']['upd'] = 'updateChapter';
193$ophandler['dict']['chapters']['add'] = 'addChapter';
194
195$page['ui']['title'] = 'static_title';
196$page['ui']['handler'] = 'handler_ui';
197$page['ui']['parent'] = 'config';
0a1b1268 198$tab['ui']['default'] = 'View';
4fe32e78 199$tab['ui']['edit'] = 'Change';
b07f617c 200$tab['ui']['reset'] = 'Reset';
4fe32e78 201$ophandler['ui']['edit']['upd'] = 'updateUI';
b07f617c 202$ophandler['ui']['reset']['go'] = 'resetUIConfig';
e673ee24
DO
203
204$page['reports']['title'] = 'static_title';
205$page['reports']['handler'] = 'handler_reports';
206$page['reports']['parent'] = 'index';
207$tab['reports']['default'] = 'View';
208
ae545907
DO
209$page['help']['title'] = 'static_title';
210$page['help']['handler'] = 'handler_help';
211$page['help']['parent'] = 'index';
beee6141 212$tab['help']['default'] = 'Welcome';
51ef5041 213$tab['help']['quickstart'] = 'Quick start';
beee6141
DO
214$tab['help']['workflow'] = 'Workflow';
215$tab['help']['rackspace'] = 'Rackspace';
216$tab['help']['objects'] = 'Objects';
bdd05c5d 217$tab['help']['nets'] = 'Networking';
0a1b1268
DO
218$tab['help']['auth'] = '[ User accounts & permissions ]';
219$tab['help']['dict'] = '[ Dictionary ]';
beee6141 220$tab['help']['ports'] = 'Ports and links';
0a1b1268 221$tab['help']['hacking'] = '[ Hacker\'s guide ]';
ae545907 222
e673ee24
DO
223// This function returns array if page numbers leading to the target page
224// plus page number of target page itself. The first element is the target
225// page number and the last element is the index page number.
226function getPath ($targetno)
227{
228 global $page;
229 $path = array();
230 // Recursion breaks at first parentless page.
231 if (!isset ($page[$targetno]['parent']))
232 $path = array ($targetno);
233 else
234 {
235 $path = getPath ($page[$targetno]['parent']);
236 $path[] = $targetno;
237 }
238 return $path;
239}
240
241function showPathAndSearch ($pageno)
242{
9c0b0016 243 global $root, $page;
e673ee24 244 // Path.
73635d32 245 echo "<td class=activemenuitem width='99%'>" . getConfigVar ('enterprise');
e673ee24
DO
246 if (isset ($page[$pageno]['title']))
247 {
248 $path = getPath ($pageno);
249 foreach ($path as $dummy => $no)
250 {
251 $title = $page[$no]['title']($no);
252 echo ": <a href='${root}?page=${no}";
253 foreach ($title['params'] as $param_name => $param_value)
254 echo "&${param_name}=${param_value}";
255 echo "'>" .$title['name'] . "</a>";
256 }
257 }
258 echo "</td>";
259 // Search form.
260 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
261 echo "<form method=get action='${root}'><td>";
262 echo '<input type=hidden name=page value=search>';
263 // This input will be the first, if we don't add ports or addresses.
264 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
265}
266
267function getTitle ($pageno, $tabno)
268{
9c0b0016
DO
269 global $page;
270 if (!isset ($page[$pageno]['title']))
271 return getConfigVar ('enterprise');
272 $tmp = $page[$pageno]['title']($pageno);
273 return $tmp['name'];
e673ee24
DO
274}
275
276function showTabs ($pageno, $tabno)
277{
641fe9b0 278 global $tab, $root, $page, $remote_username, $trigger;
e673ee24
DO
279 if (!isset ($tab[$pageno]['default']))
280 return;
281 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
282 foreach ($tab[$pageno] as $tabidx => $tabtitle)
283 {
284 // Hide forbidden tabs.
285 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
286 continue;
641fe9b0
DO
287 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
288 if
289 (
290 isset ($trigger[$pageno][$tabidx]) &&
291 $trigger[$pageno][$tabidx] () != TRUE
292 )
293 continue;
e673ee24
DO
294 echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
295 echo " href='${root}?page=${pageno}&tab=${tabidx}";
296 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
297 {
298 $bpname = $page[$pageno]['bypass'];
299 $bpval = $_REQUEST[$bpname];
300 echo "&${bpname}=${bpval}";
301 }
302 echo "'>${tabtitle}</a></li>\n";
303 }
ae9a3784 304 lookupHelpTopic ($pageno, $tabno);
e673ee24
DO
305 echo "</ul></div></td>\n";
306}
307
308// This function returns pages, which are direct children of the requested
309// page and are accessible by the current user.
310function getDirectChildPages ($pageno)
311{
312 global $page, $remote_username;
313 $children = array();
314 foreach ($page as $cpageno => $cpage)
315 if
316 (
317 isset ($cpage['parent']) and
318 $cpage['parent'] == $pageno and
319 authorized ($remote_username, $cpageno, 'default') == TRUE
320 )
321 $children[$cpageno] = $cpage;
322 return $children;
323}
324
325function getAllChildPages ($parent)
326{
327 global $page;
328 // Array pointer is global, so if we don't create local copies of
329 // the global array, we can't advance any more after nested call
330 // of getAllChildPages returns.
331 $mypage = $page;
332 $mykids = array();
333 foreach ($mypage as $ctitle => $cpage)
334 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
335 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
336 return $mykids;
337}
338
339?>