r1106 importing RackTables trunk
[racktables] / inc / pagehandlers.php
1 <?
2 /*
3 *
4 * This file is a library of page handlers for RackTables.
5 *
6 */
7
8 // This function assures that specified argument was passed
9 // and is a number greater than zero.
10 function assertUIntArg ($argname, $allow_zero = FALSE)
11 {
12 if (!isset ($_REQUEST[$argname]))
13 {
14 showError ("Parameter '${argname}' is missing.");
15 die();
16 }
17 if (!is_numeric ($_REQUEST[$argname]))
18 {
19 showError ("Parameter '${argname}' is not a number.");
20 die();
21 }
22 if ($_REQUEST[$argname] < 0)
23 {
24 showError ("Parameter '${argname}' is less than zero.");
25 die();
26 }
27 if (!$allow_zero and $_REQUEST[$argname] == 0)
28 {
29 showError ("Parameter '${argname}' is equal to zero.");
30 die();
31 }
32 }
33
34 // This function assures that specified argument was passed
35 // and is a non-empty string.
36 function assertStringArg ($argname, $ok_if_empty = FALSE)
37 {
38 if (!isset ($_REQUEST[$argname]))
39 {
40 showError ("Parameter '${argname}' is missing.");
41 die();
42 }
43 if (!is_string ($_REQUEST[$argname]))
44 {
45 showError ("Parameter '${argname}' is not a string.");
46 die();
47 }
48 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
49 {
50 showError ("Parameter '${argname}' is an empty string.");
51 die();
52 }
53 }
54
55 function assertBoolArg ($argname, $ok_if_empty = FALSE)
56 {
57 if (!isset ($_REQUEST[$argname]))
58 {
59 showError ("Parameter '${argname}' is missing.");
60 die();
61 }
62 if (!is_string ($_REQUEST[$argname]) or $_REQUEST[$argname] != 'on')
63 {
64 showError ("Parameter '${argname}' is not a string.");
65 die();
66 }
67 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
68 {
69 showError ("Parameter '${argname}' is an empty string.");
70 die();
71 }
72 }
73
74 function handler_row ($tabno)
75 {
76 assertUIntArg ('row_id');
77 switch ($tabno)
78 {
79 case 'default':
80 renderRow ($_REQUEST['row_id']);
81 break;
82 case 'newrack':
83 renderNewRackForm ($_REQUEST['row_id']);
84 break;
85 default:
86 showError ("Invalid tab '${tabno}' requested in handler_row().");
87 }
88 }
89
90 function handler_rack ($tabno)
91 {
92 assertUIntArg ('rack_id');
93 switch ($tabno)
94 {
95 case 'default':
96 // FIXME: add tab renderer instead of table generator
97 renderRackPage ($_REQUEST['rack_id']);
98 break;
99 case 'problems':
100 renderRackProblems ($_REQUEST['rack_id']);
101 break;
102 case 'design':
103 renderRackDesign ($_REQUEST['rack_id']);
104 break;
105 case 'edit':
106 renderEditRackForm ($_REQUEST['rack_id']);
107 break;
108 default:
109 showError ("Invalid tab '${tabno}' requested in handler_rack().");
110 }
111 }
112
113 function handler_object ($tabno)
114 {
115 assertUIntArg ('object_id');
116 switch ($tabno)
117 {
118 case 'default':
119 renderRackObject ($_REQUEST['object_id']);
120 break;
121 case 'rackspace':
122 renderRackSpaceForObject ($_REQUEST['object_id']);
123 break;
124 case 'ports':
125 renderPortsForObject ($_REQUEST['object_id']);
126 break;
127 case 'network':
128 renderNetworkForObject ($_REQUEST['object_id']);
129 break;
130 case 'edit':
131 renderEditObjectForm ($_REQUEST['object_id']);
132 break;
133 case 'portfwrd':
134 renderIPAddressPortForwarding($_REQUEST['object_id']);
135 break;
136 default:
137 showError ("Invalid tab '${tabno}' requested in handler_object().");
138 }
139 }
140
141 function handler_objects ($tabno)
142 {
143 switch ($tabno)
144 {
145 case 'default':
146 renderObjectGroupSummary();
147 break;
148 case 'newobj':
149 renderNewObjectForm();
150 break;
151 case 'newmulti':
152 renderAddMultipleObjectsForm();
153 break;
154 default:
155 showError ("Invalid tab '${tabno}' requested in handler_objects().");
156 }
157 }
158
159 function handler_objgroup ()
160 {
161 assertUIntArg ('group_id');
162 renderObjectGroup ($_REQUEST['group_id']);
163 }
164
165 function handler_rackspace ($tabno)
166 {
167 switch ($tabno)
168 {
169 case 'default':
170 renderRackspace();
171 break;
172 case 'history':
173 renderRackspaceHistory ();
174 break;
175 default:
176 showError ("Invalid tab '${tabno}' requested in handler_rackspace().");
177 }
178 }
179
180 function handler_ipv4space ($tabno)
181 {
182 switch ($tabno)
183 {
184 case 'default':
185 renderAddressspace();
186 break;
187 case 'newrange':
188 renderAddNewRange();
189 break;
190 default:
191 showError ("Invalid tab '${tabno}' requested in handler_ipv4space().");
192 }
193 }
194
195 function handler_iprange ($tabno)
196 {
197 switch ($tabno)
198 {
199 case 'default':
200 renderIPRange();
201 break;
202 case 'properties':
203 renderIPRangeProperties();
204 break;
205 default:
206 showError ("Invalid tab '${tabno}' requested in handler_iprange().");
207 }
208 }
209
210 function handler_ipaddress ($tabno)
211 {
212 switch ($tabno)
213 {
214 case 'default':
215 renderIPAddress();
216 break;
217 case 'properties':
218 renderIPAddressProperties();
219 break;
220 case 'assignment':
221 renderIPAddressAssignment();
222 break;
223 default:
224 showError ("Invalid tab '${tabno}' requested in handler_ipaddress().");
225 }
226 }
227
228 function handler_search ($tabno)
229 {
230 renderSearchResults();
231 }
232
233 function handler_config ($tabno)
234 {
235 switch ($tabno)
236 {
237 case 'default':
238 renderConfigMainpage();
239 break;
240 default:
241 showError ("Invalid tab '${tabno}' requested in handler_config().");
242 }
243 }
244
245 function handler_accounts ($tabno)
246 {
247 switch ($tabno)
248 {
249 case 'default':
250 renderAccounts();
251 break;
252 case 'edit':
253 renderAccountsEditForm();
254 break;
255 default:
256 showError ("Invalid tab '${tabno}' requested in handler_accounts().");
257 }
258 }
259
260 function handler_perms ($tabno)
261 {
262 switch ($tabno)
263 {
264 case 'default':
265 renderPermissions();
266 break;
267 case 'edit':
268 renderPermissionsEditForm();
269 break;
270 default:
271 showError ("Invalid tab '${tabno}' requested in handler_perms().");
272 }
273 }
274
275 function handler_ro ($tabno)
276 {
277 switch ($tabno)
278 {
279 case 'default':
280 renderReadonlyParameters();
281 break;
282 default:
283 showError ("Invalid tab '${tabno}' requested in handler_ro().");
284 }
285 }
286
287 function handler_ui ($tabno)
288 {
289 switch ($tabno)
290 {
291 case 'default':
292 renderUIConfig();
293 break;
294 default:
295 showError ("Invalid tab '${tabno}' requested in handler_ui().");
296 }
297 }
298
299 function handler_portmap ($tabno)
300 {
301 switch ($tabno)
302 {
303 case 'default':
304 renderPortMap (FALSE);
305 break;
306 case 'edit':
307 renderPortMap (TRUE);
308 break;
309 default:
310 showError ("Invalid tab '${tabno}' requested in handler_portmap().");
311 }
312 }
313
314 function handler_dict ($tabno)
315 {
316 switch ($tabno)
317 {
318 case 'default':
319 renderDictionary();
320 break;
321 case 'edit':
322 renderDictionaryEditor();
323 break;
324 case 'chapters':
325 renderChaptersEditor();
326 break;
327 default:
328 showError ("Invalid tab '${tabno}' requested in handler_dict().");
329 }
330 }
331
332 function handler_attrs ($tabno)
333 {
334 switch ($tabno)
335 {
336 case 'default':
337 renderAttributes();
338 break;
339 case 'editattrs':
340 renderEditAttributesForm ();
341 break;
342 case 'editmap':
343 renderEditAttrMapForm ();
344 break;
345 default:
346 showError ("Invalid tab '${tabno}' requested in handler_attrs().");
347 }
348 }
349
350 function handler_reports ($tabno)
351 {
352 switch ($tabno)
353 {
354 case 'default':
355 renderReportSummary();
356 break;
357 default:
358 showError ("Invalid tab '${tabno}' requested in handler_reports().");
359 }
360 }
361
362 ?>