r2748 - trigger_snmpportfinder(): quick fix after previous changeset
[racktables] / inc / triggers.php
1 <?php
2 /*
3 *
4 * This file is a library of tab triggers for RackTables.
5 *
6 */
7
8 // Triggers may be optionally referred by some tabs of a page.
9 // In case they are defined, the given tab is only displayed if
10 // the trigger returned CSS class name. In certain cases, a key is necessary
11 // to decide (the 'bypass' hint of a page), and in some cases,
12 // other data can be used.
13
14 // This trigger filters out everything except switches with known-good
15 // software.
16 // FIXME: That's a bit of hardcoding at the moment, but
17 // let's thinks about fixing it later.
18 function trigger_livevlans ()
19 {
20 assertUIntArg ('object_id', __FUNCTION__);
21 $object_id = $_REQUEST['object_id'];
22 $object = getObjectInfo ($object_id, FALSE);
23 if ($object['objtype_id'] != 8)
24 return '';
25 $values = getAttrValues ($object_id);
26 foreach ($values as $record)
27 {
28 if ($record['id'] != 4) // SW type
29 continue;
30 // Cisco IOS 12.0
31 // Cisco IOS 12.1
32 // Cisco IOS 12.2
33 if (in_array ($record['key'], array (244, 251, 252)))
34 return 'std';
35 else
36 return '';
37 }
38 return '';
39 }
40
41 // SNMP port finder tab trigger. At the moment we decide on showing it
42 // for pristine switches only. Once a user has begun
43 // filling the data in, we stop showing the tab.
44 function trigger_snmpportfinder ()
45 {
46 assertUIntArg ('object_id', __FUNCTION__);
47 $object = spotEntity ('object', $_REQUEST['object_id']);
48 if ($object['objtype_id'] != 8)
49 return '';
50 return count (getObjectPortsAndLinks ($_REQUEST['object_id'])) ? '' : 'attn';
51 }
52
53 function trigger_isloadbalancer ()
54 {
55 assertUIntArg ('object_id', __FUNCTION__);
56 return considerConfiguredConstraint ('object', $_REQUEST['object_id'], 'IPV4LB_LISTSRC') ? 'std' : '';
57 }
58
59 function trigger_ipv4 ()
60 {
61 assertUIntArg ('object_id', __FUNCTION__);
62 if (count (getObjectIPv4Allocations ($_REQUEST['object_id'])))
63 return 'std';
64 // Only hide the tab, if there are no addresses allocated.
65 return considerConfiguredConstraint ('object', $_REQUEST['object_id'], 'IPV4OBJ_LISTSRC') ? 'std' : '';
66 }
67
68 function trigger_natv4 ()
69 {
70 assertUIntArg ('object_id', __FUNCTION__);
71 return considerConfiguredConstraint ('object', $_REQUEST['object_id'], 'IPV4NAT_LISTSRC') ? 'std' : '';
72 }
73
74 function trigger_poolrscount ()
75 {
76 assertUIntArg ('pool_id', __FUNCTION__);
77 $poolInfo = spotEntity ('ipv4rspool', $_REQUEST['pool_id']);
78 amplifyCell ($poolInfo);
79 return count ($poolInfo['rslist']) ? 'std' : '';
80 }
81
82 function trigger_autoports ()
83 {
84 assertUIntArg ('object_id', __FUNCTION__);
85 if (count (getObjectPortsAndLinks ($_REQUEST['object_id'])))
86 return '';
87 $info = spotEntity ('object', $_REQUEST['object_id']);
88 return count (getAutoPorts ($info['objtype_id'])) ? 'attn' : '';
89 }
90
91 function trigger_tags ()
92 {
93 global $taglist;
94 return count ($taglist) ? 'std' : '';
95 }
96
97 function trigger_passwdchange ()
98 {
99 global $user_auth_src;
100 return $user_auth_src == 'database' ? 'std' : '';
101 }
102
103 function trigger_localreports ()
104 {
105 global $localreports;
106 return count ($localreports) ? 'std' : '';
107 }
108
109 function trigger_file_editText ()
110 {
111 assertUIntArg ('file_id', __FUNCTION__);
112 $fileInfo = getFileInfo ($_REQUEST['file_id']);
113 return ($fileInfo['type'] == 'text/plain') ? 'std' : '';
114 }
115
116 ?>