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