r1106 importing RackTables trunk
[racktables] / inc / ophandlers.php
CommitLineData
e673ee24
DO
1<?
2/*
3*
4* This file is a library of operation handlers for RackTables.
5*
6*/
7
8function addPortForwarding ()
9{
10 global $root, $pageno, $tabno;
11
12 $object_id = $_REQUEST['object_id'];
13 $localip = $_REQUEST['localip'];
14 $remoteip = $_REQUEST['remoteip'];
15 $localport = $_REQUEST['localport'];
16 $remoteport = $_REQUEST['remoteport'];
17 $proto = $_REQUEST['proto'];
18 $mode = $_REQUEST['mode'];
19 $description = $_REQUEST['description'];
20
21 $retpage="${root}?page=${pageno}&tab=${tabno}&object_id=$object_id";
22
23
24 $error=newPortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto, $description);
25
26 if ($error == '')
27 return "${retpage}&message=".urlencode('Port forwarding successfully added.');
28 else
29 {
30 return "${retpage}&error=".urlencode($error);
31 }
32
33}
34
35function delPortForwarding ()
36{
37 global $root, $pageno, $tabno;
38
39 $object_id = $_REQUEST['object_id'];
40 $localip = $_REQUEST['localip'];
41 $remoteip = $_REQUEST['remoteip'];
42 $localport = $_REQUEST['localport'];
43 $remoteport = $_REQUEST['remoteport'];
44 $proto = $_REQUEST['proto'];
45 $mode = $_REQUEST['mode'];
46
47 $retpage="${root}?page=${pageno}&tab=${tabno}&object_id=$object_id";
48
49 $error=deletePortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto);
50 if ($error == '')
51 return "${retpage}&message=".urlencode('Port forwarding successfully deleted.');
52 else
53 {
54 return "${retpage}&error=".urlencode($error);
55 }
56
57}
58
59function updPortForwarding ()
60{
61 global $root, $pageno, $tabno;
62
63 $object_id = $_REQUEST['object_id'];
64 $localip = $_REQUEST['localip'];
65 $remoteip = $_REQUEST['remoteip'];
66 $localport = $_REQUEST['localport'];
67 $remoteport = $_REQUEST['remoteport'];
68 $proto = $_REQUEST['proto'];
69 $description = $_REQUEST['description'];
70
71 $retpage="${root}?page=${pageno}&tab=${tabno}&object_id=$object_id";
72
73 $error=updatePortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto, $description);
74 if ($error == '')
75 return "${retpage}&message=".urlencode('Port forwarding successfully updated.');
76 else
77 {
78 return "${retpage}&error=".urlencode($error);
79 }
80
81}
82
83
84
85function addPortForObject ()
86{
87 global $root, $pageno, $tabno;
88
89 $object_id = $_REQUEST['object_id'];
90 $port_name = $_REQUEST['port_name'];
91 $port_l2address = $_REQUEST['port_l2address'];
92 $port_label = $_REQUEST['port_label'];
93 $port_type_id = $_REQUEST['port_type_id'];
94
95
96 if ($port_name == '')
97 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode('Port name cannot be empty');
98 else
99 {
100 $error = commitAddPort ($object_id, $port_name, $port_type_id, $port_label, $port_l2address);
101 if ($error != '')
102 {
103 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
104 }
105 else
106 {
107 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name added successfully");
108 }
109 }
110
111}
112
113function editPortForObject ()
114{
115 global $root, $pageno, $tabno;
116
117 assertUIntArg ('port_id');
118 assertUIntArg ('object_id');
119 assertStringArg ('name');
120 $port_id = $_REQUEST['port_id'];
121 $object_id = $_REQUEST['object_id'];
122 $port_name = $_REQUEST['name'];
123 $port_l2address = $_REQUEST['l2address'];
124 $port_label = $_REQUEST['label'];
125 if (isset ($_REQUEST['reservation_comment']) and !empty ($_REQUEST['reservation_comment']))
126 $port_rc = '"' . $_REQUEST['reservation_comment'] . '"';
127 else
128 $port_rc = 'NULL';
129
130 if ($port_name == '')
131 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode('Port name cannot be empty');
132 else
133 {
134 $error = commitUpdatePort ($port_id, $port_name, $port_label, $port_l2address, $port_rc);
135 if ($error != '')
136 {
137 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
138 }
139 else
140 {
141 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name updated successfully");
142 }
143 }
144
145}
146
147function delPortFromObject ()
148{
149 global $root, $pageno, $tabno;
150
151 $port_id = $_REQUEST['port_id'];
152 $port_name = $_REQUEST['port_name'];
153 $object_id = $_REQUEST['object_id'];
154 $error = delObjectPort($port_id);
155
156 if ($error != '')
157 {
158 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
159 }
160 else
161 {
162 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name deleted successfully");
163 }
164}
165
166function linkPortForObject ()
167{
168 global $root, $pageno, $tabno;
169
170 $port_id = $_REQUEST['port_id'];
171 $remote_port_id = $_REQUEST['remote_port_id'];
172 $object_id = $_REQUEST['object_id'];
173 $port_name = $_REQUEST['port_name'];
174 $remote_port_name = $_REQUEST['remote_port_name'];
175 $remote_object_name = $_REQUEST['remote_object_name'];
176
177 $error = linkPorts($port_id, $remote_port_id);
178 if ($error != '')
179 {
180 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
181 }
182 else
183 {
184 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name successfully linked with port $remote_port_name at object $remote_object_name");
185 }
186}
187
188function unlinkPortForObject ()
189{
190 global $root, $pageno, $tabno;
191
192 $port_id = $_REQUEST['port_id'];
193 $object_id = $_REQUEST['object_id'];
194 $port_name = $_REQUEST['port_name'];
195 $remote_port_name = $_REQUEST['remote_port_name'];
196 $remote_object_name = $_REQUEST['remote_object_name'];
197
198 $error = unlinkPort($port_id);
199 if ($error != '')
200 {
201 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
202 }
203 else
204 {
205 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name successfully unlinked from port $remote_port_name at object $remote_object_name");
206 }
207}
208
209function addMultiPorts ()
210{
211 global $root, $pageno, $tabno;
212 // Parse data.
213 assertStringArg ('format');
214 assertStringArg ('input');
215 assertUIntArg ('port_type');
216 assertUIntArg ('object_id');
217 $format = $_REQUEST['format'];
218 $port_type = $_REQUEST['port_type'];
219 $object_id = $_REQUEST['object_id'];
220 // Input lines are escaped, so we have to explode and to chop by 2-char
221 // \n and \r respectively.
222 $lines1 = explode ('\n', $_REQUEST['input']);
223 foreach ($lines1 as $line)
224 {
225 $parts = explode ('\r', $line);
226 reset ($parts);
227 if (empty ($parts[0]))
228 continue;
229 else
230 $lines2[] = rtrim ($parts[0]);
231 }
232 $ports = array();
233 foreach ($lines2 as $line)
234 {
235 switch ($format)
236 {
237 case 'fisxii':
238 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
239 list ($slot, $port) = explode ('/', $words[0]);
240 $ports[] = array
241 (
242 'name' => "e ${slot}/${port}",
243 'l2address' => $words[8],
244 'label' => "slot ${slot} port ${port}"
245 );
246 break;
247 case 'c3600asy':
248 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', trim (substr ($line, 3))));
249/*
250How Async Lines are Numbered in Cisco 3600 Series Routers
251http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
252
253Understanding 16- and 32-Port Async Network Modules
254http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
255*/
256 $async = $words[0];
257 $slot = floor (($async - 1) / 32);
258 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
259 $cable = $async - $slot * 32 - $octalgroup * 8;
260 $og_label[0] = 'async 0-7';
261 $og_label[1] = 'async 8-15';
262 $og_label[2] = 'async 16-23';
263 $og_label[3] = 'async 24-31';
264 $ports[] = array
265 (
266 'name' => "async ${async}",
267 'l2address' => '',
268 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
269 );
270 break;
271 case 'fiwg':
272 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
273 $ifnumber = $words[0] * 1;
274 $ports[] = array
275 (
276 'name' => "e ${ifnumber}",
277 'l2address' => "${words[8]}",
278 'label' => "${ifnumber}"
279 );
280 break;
281 default:
282 return
283 "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" .
284 urlencode('Cannot process submitted data: unknown format code.');
285 break;
286 }
287 }
288 // Create ports, if they don't exist.
289 $added_count = $updated_count = $error_count = 0;
290 foreach ($ports as $port)
291 {
292 $port_id = getPortID ($object_id, $port['name']);
293 if ($port_id === NULL)
294 {
295 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
296 if ($result == '')
297 $added_count++;
298 else
299 $error_count++;
300 }
301 else
302 {
303 $result = commitUpdatePort ($port_id, $port['name'], $port['label'], $port['l2address']);
304 if ($result == '')
305 $updated_count++;
306 else
307 $error_count++;
308 }
309 }
310 return
311 "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" .
312 urlencode("Added ${added_count} ports, updated ${updated_count} ports, encountered ${error_count} errors.");
313}
314
315function editAddressFromObject ()
316{
317 global $root;
318
319 $ip = $_REQUEST['ip'];
320 $object_id = $_REQUEST['object_id'];
321 $name = $_REQUEST['bond_name'];
322 $type = $_REQUEST['bond_type'];
323 $error = updateBond($ip, $object_id, $name, $type);
324 if ($error != '')
325 {
326 return "${root}?page=object&tab=network&object_id=$object_id&error=".urlencode($error);
327 }
328 else
329 {
330 return "${root}?page=object&tab=network&object_id=$object_id&message=".urlencode("Interface successfully updated");
331 }
332}
333
334function delAddressFromObject ()
335{
336 global $root;
337
338 $ip = $_REQUEST['ip'];
339 $object_id = $_REQUEST['object_id'];
340 $error = unbindIpFromObject($ip, $object_id);
341 if ($error != '')
342 {
343 return "${root}?page=object&tab=network&object_id=$object_id&error=".urlencode($error);
344 }
345 else
346 {
347 return "${root}?page=object&tab=network&object_id=$object_id&message=".urlencode("Interface successfully deleted");
348 }
349}
350
351function delIpAssignment ()
352{
353 global $root;
354
355 $ip = $_REQUEST['ip'];
356 $object_id = $_REQUEST['object_id'];
357 $error = unbindIpFromObject($ip, $object_id);
358 if ($error != '')
359 {
360 return "${root}?page=ipaddress&tab=assignment&ip=$ip&error=".urlencode($error);
361 }
362 else
363 {
364 return "${root}?page=ipaddress&tab=assignment&ip=$ip&message=".urlencode("Interface successfully deleted");
365 }
366}
367
368function editIpAssignment ()
369{
370 global $root;
371
372 $ip = $_REQUEST['ip'];
373 $object_id = $_REQUEST['object_id'];
374 $name = $_REQUEST['bond_name'];
375 $type = $_REQUEST['bond_type'];
376 $error = updateBond($ip, $object_id, $name, $type);
377
378 if ($error != '')
379 {
380 return "${root}?page=ipaddress&tab=assignment&ip=$ip&error=".urlencode($error);
381 }
382 else
383 {
384 return "${root}?page=ipaddress&tab=assignment&ip=$ip&message=".urlencode("Interface successfully updated");
385 }
386}
387
388function addIpAssignment ()
389{
390 global $root;
391
392 $ip = $_REQUEST['ip'];
393 $object_id = $_REQUEST['object_id'];
394 $name = $_REQUEST['bond_name'];
395 $type = $_REQUEST['bond_type'];
396 $error = bindIpToObject($ip, $object_id, $name, $type);
397 if ($error != '')
398 {
399 return "${root}?page=ipaddress&tab=assignment&ip=$ip&error=".urlencode($error);
400 }
401 else
402 {
403 return "${root}?page=ipaddress&tab=assignment&ip=$ip&message=".urlencode("Interface successfully added");
404 }
405}
406
407function addNewRange ()
408{
409 global $root, $pageno, $tabno;
410
411 $ip = $_REQUEST['ip'];
412 $mask = $_REQUEST['mask'];
413 $name = $_REQUEST['name'];
414 $error = addRange($ip, $mask, $name);
415 if ($error != '')
416 {
417 return "${root}?page=${pageno}&tab=${tabno}&error=".urlencode($error);
418 }
419 else
420 {
421 return "${root}?page=${pageno}&tab=${tabno}&message=".urlencode("Range successfully added");
422 }
423}
424
425function editRange ()
426{
427 global $root, $pageno, $tabno;
428
429 $id = $_REQUEST['id'];
430 $name = $_REQUEST['name'];
431 $error = updateRange($id, $name);
432 if ($error != '')
433 {
434 return "${root}?page=${pageno}&tab=${tabno}&id=$id&error=".urlencode($error);
435 }
436 else
437 {
438 return "${root}?page=${pageno}&tab=${tabno}&id=$id&message=".urlencode("Range updated");
439 }
440
441}
442
443function delRange ()
444{
445 global $root, $pageno, $tabno;
446
447 $id = $_REQUEST['id'];
448 $error = commitDeleteRange ($id);
449 if ($error != '')
450 {
451 return "${root}?page=${pageno}&tab=${tabno}&error=".urlencode($error);
452 }
453 else
454 {
455 return "${root}?page=${pageno}&tab=${tabno}&message=".urlencode("Range deleted");
456 }
457
458}
459
460function editAddress ()
461{
462 global $root, $pageno, $tabno;
463
464 $ip = $_REQUEST['ip'];
465 $name = $_REQUEST['name'];
466 if (isset ($_REQUEST['reserved']))
467 $reserved = $_REQUEST['reserved'];
468 else
469 $reserved = 'off';
470 $error = updateAddress($ip, $name, $reserved=='on'?'yes':'no');
471 if ($error != '')
472 {
473 return "${root}?page=${pageno}&tab=${tabno}&ip=$ip&error=".urlencode($error);
474 }
475 else
476 {
477 return "${root}?page=${pageno}&tab=${tabno}&ip=$ip&message=".urlencode("Address updated");
478 }
479
480}
481
482function addAddressToObject ()
483{
484 global $root, $pageno, $tabno;
485
486 $ip = $_REQUEST['ip'];
487 $object_id = $_REQUEST['object_id'];
488 $name = $_REQUEST['name'];
489 $type = $_REQUEST['type'];
490 $error = bindIpToObject($ip, $object_id, $name, $type);
491 if ($error != '')
492 {
493 return "${root}?page=${pageno}&tab=${tabno}&object_id=$object_id&error=".urlencode($error);
494 }
495 else
496 {
497 return "${root}?page=$pageno&tab=${tabno}&object_id=$object_id&message=".urlencode("Interface successfully added");
498 }
499}
500
501function createUserAccount ()
502{
503 global $root, $pageno, $tabno;
504 assertStringArg ('username');
505 assertStringArg ('realname', TRUE);
506 assertStringArg ('password');
507 $username = $_REQUEST['username'];
508 $password = hash (PASSWORD_HASH, $_REQUEST['password']);
509 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
510 if ($result == TRUE)
511 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("User account ${username} created.");
512 else
513 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error creating user account ${username}.");
514}
515
516function updateUserAccount ()
517{
518 global $root, $pageno, $tabno;
519 assertUIntArg ('id');
520 assertStringArg ('username');
521 assertStringArg ('realname', TRUE);
522 assertStringArg ('password');
523 // We might be asked to change username, so use user ID only.
524 $id = $_REQUEST['id'];
525 $username = $_REQUEST['username'];
526 $new_password = $_REQUEST['password'];
527 $old_hash = getHashByID ($id);
528 if ($old_hash == NULL)
529 {
530 showError ('getHashByID() failed in updateUserAccount()');
531 return;
532 }
533 // Update user password only if provided password is not the same as current password hash.
534 if ($new_password != $old_hash)
535 $new_password = hash (PASSWORD_HASH, $new_password);
536 $result = commitUpdateUserAccount ($_REQUEST['id'], $username, $_REQUEST['realname'], $new_password);
537 if ($result == TRUE)
538 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("User account ${username} updated.");
539 else
540 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error updating user account ${username}.");
541}
542
543function enableUserAccount ()
544{
545 global $root, $pageno, $tabno;
546 assertUIntArg ('id');
547 $id = $_REQUEST['id'];
548 $result = commitEnableUserAccount ($id, 'yes');
549 if ($result == TRUE)
550 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("User account enabled.");
551 else
552 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error enabling user account.");
553}
554
555function disableUserAccount ()
556{
557 global $root, $pageno, $tabno;
558 assertUIntArg ('id');
559 $id = $_REQUEST['id'];
560 if ($id == 1)
561 $result = FALSE;
562 else
563 $result = commitEnableUserAccount ($id, 'no');
564 if ($result == TRUE)
565 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("User account disabled.");
566 else
567 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error disabling user account.");
568}
569
570function revokePermission ()
571{
572 global $root, $pageno, $tabno;
573 assertUIntArg ('access_userid', TRUE);
574 assertStringArg ('access_page');
575 assertStringArg ('access_tab');
576 $result = commitRevokePermission
577 (
578 $_REQUEST['access_userid'],
579 $_REQUEST['access_page'],
580 $_REQUEST['access_tab']
581 );
582 if ($result == TRUE)
583 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Revoke successfull.");
584 else
585 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error revoking permission.");
586}
587
588function grantPermission ()
589{
590 global $root, $pageno, $tabno;
591 assertUIntArg ('access_userid', TRUE);
592 assertStringArg ('access_page');
593 assertStringArg ('access_tab');
594 assertStringArg ('access_value');
595 $result = commitGrantPermission
596 (
597 $_REQUEST['access_userid'],
598 $_REQUEST['access_page'],
599 $_REQUEST['access_tab'],
600 $_REQUEST['access_value']
601 );
602 if ($result == TRUE)
603 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Grant successfull.");
604 else
605 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error granting permission.");
606}
607
608// This function find differences in users's submit and PortCompat table
609// and modifies database accordingly.
610function savePortMap ()
611{
612 global $root, $pageno, $tabno;
613 $ptlist = getPortTypes();
614 $oldCompat = getPortCompat();
615 $newCompat = array();
616 foreach (array_keys ($ptlist) as $leftKey)
617 foreach (array_keys ($ptlist) as $rightKey)
618 if (isset ($_REQUEST["atom_${leftKey}_${rightKey}"]))
619 $newCompat[] = array ('type1' => $leftKey, 'type2' => $rightKey);
620 // Build the new matrix from user's submit and compare it to
621 // the old matrix. Those pairs which appear on
622 // new matrix only, have to be stored in PortCompat table. Those who appear
623 // on the old matrix only, should be removed from PortCompat table.
624 // Those present in both matrices should be skipped.
625 $oldCompatTable = buildPortCompatMatrixFromList ($ptlist, $oldCompat);
626 $newCompatTable = buildPortCompatMatrixFromList ($ptlist, $newCompat);
627 $error_count = $success_count = 0;
628 foreach (array_keys ($ptlist) as $type1)
629 foreach (array_keys ($ptlist) as $type2)
630 if ($oldCompatTable[$type1][$type2] != $newCompatTable[$type1][$type2])
631 switch ($oldCompatTable[$type1][$type2])
632 {
633 case TRUE: // new value is FALSE
634 if (removePortCompat ($type1, $type2) === TRUE)
635 $success_count++;
636 else
637 $error_count++;
638 break;
639 case FALSE: // new value is TRUE
640 if (addPortCompat ($type1, $type2) === TRUE)
641 $success_count++;
642 else
643 $error_count++;
644 break;
645 default:
646 showError ('oldCompatTable is invalid in savePortMap()');
647 break;
648 }
649 return
650 "${root}?page=${pageno}&tab=${tabno}&" .
651 ($error_count == 0 ? 'message' : 'error') .
652 "=" . urlencode ("${error_count} failures and ${success_count} successfull changes.");
653}
654
655function deleteDictWord ()
656{
657 global $root, $pageno, $tabno;
658 return
659 "${root}?page=${pageno}&tab=${tabno}&" .
660 "error=" . urlencode ('Dragon ate this word!');
661}
662
663function updateDictionary ()
664{
665 global $root, $pageno, $tabno;
666 assertUIntArg ('chapter_no');
667 assertUIntArg ('dict_key');
668 assertStringArg ('dict_value');
669 if (commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']) === TRUE)
670 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Update succeeded.');
671 else
672 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Update failed!");
673}
674
675function supplementDictionary ()
676{
677 global $root, $pageno, $tabno;
678 assertUIntArg ('chapter_no');
679 assertStringArg ('dict_value');
680 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
681 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Supplement succeeded.');
682 else
683 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Supplement failed!");
684}
685
686function reduceDictionary ()
687{
688 global $root, $pageno, $tabno;
689 assertUIntArg ('chapter_no');
690 assertUIntArg ('dict_key');
691 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
692 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Reduction succeeded.');
693 else
694 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Reduction failed!");
695}
696
697function addChapter ()
698{
699 global $root, $pageno, $tabno;
700 assertStringArg ('chapter_name');
701 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
702 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Chapter was added.');
703 else
704 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error adding chapter.');
705}
706
707function updateChapter ()
708{
709 global $root, $pageno, $tabno;
710 assertUIntArg ('chapter_no');
711 assertStringArg ('chapter_name');
712 if (commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']) === TRUE)
713 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Chapter was updated.');
714 else
715 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error updating chapter.');
716}
717
718function delChapter ()
719{
720 global $root, $pageno, $tabno;
721 assertUIntArg ('chapter_no');
722 if (commitDeleteChapter ($_REQUEST['chapter_no']))
723 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Chapter was deleted.');
724 else
725 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error deleting chapter.');
726}
727
728function changeAttribute ()
729{
730 global $root, $pageno, $tabno;
731 assertUIntArg ('attr_id');
732 assertStringArg ('attr_name');
733 if (commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
734 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Rename successful.');
735 else
736 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error renaming attribute.');
737}
738
739function createAttribute ()
740{
741 global $root, $pageno, $tabno;
742 assertStringArg ('attr_name');
743 assertStringArg ('attr_type');
744 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
745 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Attribute '${_REQUEST['attr_name']}' created.");
746 else
747 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error creating attribute.');
748}
749
750function deleteAttribute ()
751{
752 global $root, $pageno, $tabno;
753 assertUIntArg ('attr_id');
754 if (commitDeleteAttribute ($_REQUEST['attr_id']))
755 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Attribute was deleted.');
756 else
757 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error deleting attribute.');
758}
759
760function supplementAttrMap ()
761{
762 global $root, $pageno, $tabno;
763 assertUIntArg ('attr_id');
764 assertUIntArg ('objtype_id');
765 assertUIntArg ('chapter_no');
766 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $_REQUEST['chapter_no']) === TRUE)
767 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Supplement succeeded.');
768 else
769 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Supplement failed!");
770}
771
772function reduceAttrMap ()
773{
774 global $root, $pageno, $tabno;
775 assertUIntArg ('attr_id');
776 assertUIntArg ('objtype_id');
777 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) === TRUE)
778 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Reduction succeeded.');
779 else
780 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Reduction failed!");
781}
782
783function resetAttrValue ()
784{
785 global $root, $pageno, $tabno;
786 assertUIntArg ('attr_id');
787 assertUIntArg ('object_id');
788 $object_id = $_REQUEST['object_id'];
789 if (commitResetAttrValue ($object_id, $_REQUEST['attr_id']) === TRUE)
790 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('Reset succeeded.');
791 else
792 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Reset failed!");
793}
794
795function updateAttrValue ()
796{
797 global $root, $pageno, $tabno;
798 assertUIntArg ('attr_id');
799 assertUIntArg ('object_id');
800 // The value could be uint/float, but we don't know ATM. Let SQL
801 // server check this and complain.
802 assertStringArg ('value');
803 $object_id = $_REQUEST['object_id'];
804 if (commitUpdateAttrValue ($object_id, $_REQUEST['attr_id'], $_REQUEST['value']) === TRUE)
805 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('Update succeeded.');
806 else
807 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Update failed!");
808}
809
810function useupPort ()
811{
812 global $root, $pageno, $tabno;
813 assertUIntArg ('port_id');
814 assertUIntArg ('object_id');
815 $object_id = $_REQUEST['object_id'];
816 if (commitUseupPort ($_REQUEST['port_id']) === TRUE)
817 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('Reservation removed.');
818 else
819 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Error removing reservation!");
820}
821
822?>