Change Mail Address
[racktables-contribs] / mandatory_attr.php
1 <?php
2
3 define ('MANDATORY_ATTR_ID', 3); # FQDN
4 define ('MANDATORY_FOR_LISTSRC', '{requires FQDN}'); # RackCode
5
6 registerOpHandler ('object', 'edit', 'update', 'requireMandatoryAttrWithValue');
7 registerOpHandler ('object', 'edit', 'clearSticker', 'requireMandatoryAttrWithoutValue');
8
9 function requireMandatoryAttrWithValue()
10 {
11 return requireMandatoryAttrGeneric (MANDATORY_FOR_LISTSRC, MANDATORY_ATTR_ID, getAttrNewValue (MANDATORY_ATTR_ID));
12 }
13
14 function requireMandatoryAttrWithoutValue()
15 {
16 return requireMandatoryAttrGeneric (MANDATORY_FOR_LISTSRC, MANDATORY_ATTR_ID, NULL);
17 }
18
19 function getAttrNewValue ($attr_id)
20 {
21 $num_attrs = genericAssertion ('num_attrs', 'uint0');
22 for ($i = 0; $i < $num_attrs; $i++)
23 if ($attr_id == genericAssertion ("${i}_attr_id", 'uint'))
24 return genericAssertion ("${i}_value", 'string0');
25 return NULL;
26 }
27
28 function requireMandatoryAttrGeneric ($listsrc, $attr_id, $newval)
29 {
30 $object_id = getBypassValue();
31 $attrs = getAttrValues ($object_id);
32 if
33 (
34 array_key_exists ($attr_id, $attrs) &&
35 considerGivenConstraint (spotEntity ('object', $object_id), $listsrc) &&
36 ! mb_strlen ($newval)
37 )
38 {
39 showError ('Mandatory attribute "' . $attrs[$attr_id]['name'] . '" not set');
40 stopOpPropagation();
41 }
42 return '';
43 }