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