r1112 + initial code for dynamic tabs and triggers
[racktables] / inc / navigation.php
CommitLineData
e673ee24
DO
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';
641fe9b0
DO
55$tab['object']['switchvlans'] = 'VLANs';
56$trigger['object']['switchvlans'] = 'trigger_switchvlans';
e673ee24
DO
57$ophandler['object']['ports']['addPort'] = 'addPortForObject';
58$ophandler['object']['ports']['delPort'] = 'delPortFromObject';
59$ophandler['object']['ports']['editPort'] = 'editPortForObject';
60$ophandler['object']['ports']['linkPort'] = 'linkPortForObject';
61$ophandler['object']['ports']['unlinkPort'] = 'unlinkPortForObject';
62$ophandler['object']['ports']['addMultiPorts'] = 'addMultiPorts';
63$ophandler['object']['ports']['useup'] = 'useupPort';
64$ophandler['object']['network']['editAddressFromObject'] = 'editAddressFromObject';
65$ophandler['object']['network']['addAddrFObj'] = 'addAddressToObject';
66$ophandler['object']['network']['delAddrFObj'] = 'delAddressFromObject';
67$ophandler['object']['edit']['del'] = 'resetAttrValue';
68$ophandler['object']['edit']['upd'] = 'updateAttrValue';
69$ophandler['object']['portfwrd']['forwardPorts'] = 'addPortForwarding';
70$ophandler['object']['portfwrd']['delPortForwarding'] = 'delPortForwarding';
71$ophandler['object']['portfwrd']['updPortForwarding'] = 'updPortForwarding';
641fe9b0 72$ophandler['object']['switchvlans']['submit'] = 'updateVLANMembership';
e673ee24
DO
73
74$page['ipv4space']['title'] = 'static_title';
75$page['ipv4space']['handler'] = 'handler_ipv4space';
76$page['ipv4space']['parent'] = 'index';
77$tab['ipv4space']['default'] = 'Browse';
78$tab['ipv4space']['newrange'] = 'Manage ranges';
79$ophandler['ipv4space']['newrange']['addRange'] = 'addNewrange';
80$ophandler['ipv4space']['newrange']['delRange'] = 'delRange';
81
82$page['iprange']['title'] = 'dynamic_title_iprange';
83$page['iprange']['handler'] = 'handler_iprange';
84$page['iprange']['parent'] = 'ipv4space';
85$page['iprange']['bypass'] = 'id';
86$tab['iprange']['default'] = 'Browse';
87$tab['iprange']['properties'] = 'Properties';
88$ophandler['iprange']['properties']['editRange'] = 'editRange';
89
90$page['ipaddress']['title'] = 'dynamic_title_ipaddress';
91$page['ipaddress']['handler'] = 'handler_ipaddress';
92$page['ipaddress']['parent'] = 'iprange';
93$page['ipaddress']['bypass'] = 'ip';
94$tab['ipaddress']['default'] = 'Browse';
95$tab['ipaddress']['properties'] = 'Properties';
96$tab['ipaddress']['assignment'] = 'Allocation';
97$ophandler['ipaddress']['properties']['editAddress'] = 'editAddress';
98$ophandler['ipaddress']['assignment']['delIpAssignment'] = 'delIpAssignment';
99$ophandler['ipaddress']['assignment']['editBondForAddress'] = 'editIpAssignment';
100$ophandler['ipaddress']['assignment']['bindObjectToIp'] = 'addIpAssignment';
101
102$page['search']['title'] = 'dynamic_title_search';
103$page['search']['handler'] = 'handler_search';
104$page['search']['parent'] = 'index';
105$page['search']['bypass'] = 'q';
106
107$page['config']['title'] = 'static_title';
108$page['config']['handler'] = 'handler_config';
109$page['config']['parent'] = 'index';
110
111$page['accounts']['title'] = 'static_title';
112$page['accounts']['handler'] = 'handler_accounts';
113$page['accounts']['parent'] = 'config';
114$tab['accounts']['default'] = 'View';
115$tab['accounts']['edit'] = 'Change';
116$ophandler['accounts']['edit']['updateAccount'] = 'updateUserAccount';
117$ophandler['accounts']['edit']['createAccount'] = 'createUserAccount';
118$ophandler['accounts']['edit']['disableAccount'] = 'disableUserAccount';
119$ophandler['accounts']['edit']['enableAccount'] = 'enableUserAccount';
120
121$page['perms']['title'] = 'static_title';
122$page['perms']['handler'] = 'handler_perms';
123$page['perms']['parent'] = 'config';
124$tab['perms']['default'] = 'View';
125$tab['perms']['edit'] = 'Change';
126$ophandler['perms']['edit']['revoke'] = 'revokePermission';
127$ophandler['perms']['edit']['grant'] = 'grantPermission';
128
129$page['portmap']['title'] = 'static_title';
130$page['portmap']['handler'] = 'handler_portmap';
131$page['portmap']['parent'] = 'config';
132$tab['portmap']['default'] = 'View';
133$tab['portmap']['edit'] = 'Change';
134$ophandler['portmap']['edit']['save'] = 'savePortMap';
135
136$page['attrs']['title'] = 'static_title';
137$page['attrs']['handler'] = 'handler_attrs';
138$page['attrs']['parent'] = 'config';
139$tab['attrs']['default'] = 'View';
140$tab['attrs']['editattrs'] = 'Edit attributes';
141$tab['attrs']['editmap'] = 'Edit map';
142$ophandler['attrs']['editattrs']['add'] = 'createAttribute';
143$ophandler['attrs']['editattrs']['upd'] = 'changeAttribute';
144$ophandler['attrs']['editattrs']['del'] = 'deleteAttribute';
145$ophandler['attrs']['editmap']['add'] = 'supplementAttrMap';
146$ophandler['attrs']['editmap']['del'] = 'reduceAttrMap';
147
148$page['dict']['title'] = 'static_title';
149$page['dict']['handler'] = 'handler_dict';
150$page['dict']['parent'] = 'config';
151$tab['dict']['default'] = 'View';
152$tab['dict']['edit'] = 'Edit words';
153$tab['dict']['chapters'] = 'Manage chapters';
154$ophandler['dict']['edit']['del'] = 'reduceDictionary';
155$ophandler['dict']['edit']['upd'] = 'updateDictionary';
156$ophandler['dict']['edit']['add'] = 'supplementDictionary';
157$ophandler['dict']['chapters']['del'] = 'delChapter';
158$ophandler['dict']['chapters']['upd'] = 'updateChapter';
159$ophandler['dict']['chapters']['add'] = 'addChapter';
160
161$page['ui']['title'] = 'static_title';
162$page['ui']['handler'] = 'handler_ui';
163$page['ui']['parent'] = 'config';
164
165$page['ro']['title'] = 'static_title';
166$page['ro']['handler'] = 'handler_ro';
167$page['ro']['parent'] = 'config';
168
169$page['reports']['title'] = 'static_title';
170$page['reports']['handler'] = 'handler_reports';
171$page['reports']['parent'] = 'index';
172$tab['reports']['default'] = 'View';
173
174// This function returns array if page numbers leading to the target page
175// plus page number of target page itself. The first element is the target
176// page number and the last element is the index page number.
177function getPath ($targetno)
178{
179 global $page;
180 $path = array();
181 // Recursion breaks at first parentless page.
182 if (!isset ($page[$targetno]['parent']))
183 $path = array ($targetno);
184 else
185 {
186 $path = getPath ($page[$targetno]['parent']);
187 $path[] = $targetno;
188 }
189 return $path;
190}
191
192function showPathAndSearch ($pageno)
193{
194 global $root, $page, $enterprise;
195 // Path.
196 echo "<td class=activemenuitem width='99%'>${enterprise} RackTables";
197 if (isset ($page[$pageno]['title']))
198 {
199 $path = getPath ($pageno);
200 foreach ($path as $dummy => $no)
201 {
202 $title = $page[$no]['title']($no);
203 echo ": <a href='${root}?page=${no}";
204 foreach ($title['params'] as $param_name => $param_value)
205 echo "&${param_name}=${param_value}";
206 echo "'>" .$title['name'] . "</a>";
207 }
208 }
209 echo "</td>";
210 // Search form.
211 echo "<td><table border=0 cellpadding=0 cellspacing=0><tr><td>Search:</td>";
212 echo "<form method=get action='${root}'><td>";
213 echo '<input type=hidden name=page value=search>';
214 // This input will be the first, if we don't add ports or addresses.
215 echo "<input type=text name=q size=20 tabindex=1000></td></form></tr></table></td>";
216}
217
218function getTitle ($pageno, $tabno)
219{
220 global $page, $enterprise;
221 if (isset ($page[$pageno]['title']))
222 {
223 $ret = $page[$pageno]['title']($pageno);
224 $ret = $ret['name'];
225 }
226 else
227 $ret = $enterprise;
228 return $ret;
229}
230
231function showTabs ($pageno, $tabno)
232{
641fe9b0 233 global $tab, $root, $page, $remote_username, $trigger;
e673ee24
DO
234 if (!isset ($tab[$pageno]['default']))
235 return;
236 echo "<td><div class=greynavbar><ul id=foldertab style='margin-bottom: 0px; padding-top: 10px;'>";
237 foreach ($tab[$pageno] as $tabidx => $tabtitle)
238 {
239 // Hide forbidden tabs.
240 if (authorized ($remote_username, $pageno, $tabidx) == FALSE)
241 continue;
641fe9b0
DO
242 // Dynamic tabs should only be shown in certain cases (trigger exists and returns true).
243 if
244 (
245 isset ($trigger[$pageno][$tabidx]) &&
246 $trigger[$pageno][$tabidx] () != TRUE
247 )
248 continue;
e673ee24
DO
249 echo '<li><a' . (($tabidx == $tabno) ? ' class=current' : '');
250 echo " href='${root}?page=${pageno}&tab=${tabidx}";
251 if (isset ($page[$pageno]['bypass']) and isset ($_REQUEST[$page[$pageno]['bypass']]))
252 {
253 $bpname = $page[$pageno]['bypass'];
254 $bpval = $_REQUEST[$bpname];
255 echo "&${bpname}=${bpval}";
256 }
257 echo "'>${tabtitle}</a></li>\n";
258 }
259 echo "</ul></div></td>\n";
260}
261
262// This function returns pages, which are direct children of the requested
263// page and are accessible by the current user.
264function getDirectChildPages ($pageno)
265{
266 global $page, $remote_username;
267 $children = array();
268 foreach ($page as $cpageno => $cpage)
269 if
270 (
271 isset ($cpage['parent']) and
272 $cpage['parent'] == $pageno and
273 authorized ($remote_username, $cpageno, 'default') == TRUE
274 )
275 $children[$cpageno] = $cpage;
276 return $children;
277}
278
279function getAllChildPages ($parent)
280{
281 global $page;
282 // Array pointer is global, so if we don't create local copies of
283 // the global array, we can't advance any more after nested call
284 // of getAllChildPages returns.
285 $mypage = $page;
286 $mykids = array();
287 foreach ($mypage as $ctitle => $cpage)
288 if (isset ($cpage['parent']) and $cpage['parent'] == $parent)
289 $mykids[] = array ('title' => $ctitle, 'kids' => getAllChildPages ($ctitle));
290 return $mykids;
291}
292
293?>