// option with constraint in RackCode.
function getNarrowObjectList ($varname = '')
{
- $ret = array();
- global $dbxlink;
- $query =
- "select RackObject.id as id, RackObject.name as name, dict_value as objtype_name, " .
- "objtype_id from " .
- "RackObject inner join Dictionary on objtype_id=dict_key join Chapter on Chapter.id = Dictionary.chapter_id " .
- "where Chapter.name = 'RackObjectType' " .
- "order by objtype_id, name";
- $result = useSelectBlade ($query, __FUNCTION__);
- // Fetch everything at once to unblock result buffer and enable
- // loadEntityTags(), which will be called soon.
- $buffer = $result->fetchAll (PDO::FETCH_ASSOC);
- unset ($result);
- foreach ($buffer as $row)
- $ret[$row['id']] = displayedName ($row);
+ $wideList = listCells ('object');
if (strlen ($varname) and strlen (getConfigVar ($varname)))
{
global $parseCache;
$parseCache[$varname] = spotPayload (getConfigVar ($varname), 'SYNT_EXPR');
if ($parseCache[$varname]['result'] != 'ACK')
return array();
- $ret = filterEntityList ($ret, 'object', $parseCache[$varname]['load']);
+ $wideList = filterCellList ($wideList, $parseCache[$varname]['load']);
}
+ $ret = array();
+ foreach ($wideList as $cell)
+ $ret[$cell['id']] = $cell['dname'];
return $ret;
}
// For a given realm return a list of entity records, each with
-// enough information for judgeEntityRecord() to execute.
+// enough information for judgeCell() to execute.
function listCells ($realm, $parent_id = 0)
{
global $SQLSchema;
{
if ($objectData['name'] != '')
return $objectData['name'];
- elseif (considerConfiguredConstraint ('object', $objectData['id'], 'NAMEWARN_LISTSRC'))
- return "ANONYMOUS " . $objectData['objtype_name'];
+ // handle transition of argument type
+ if (isset ($objectData['realm']))
+ {
+ if (considerConfiguredConstraint ($objectData, 'NAMEWARN_LISTSRC'))
+ return "ANONYMOUS " . $objectData['objtype_name'];
+ else
+ return "[${objectData['objtype_name']}]";
+ }
else
- return "[${objectData['objtype_name']}]";
+ {
+ if (considerConfiguredConstraint (spotEntity ('object', $objectData['id']), 'NAMEWARN_LISTSRC'))
+ return "ANONYMOUS " . $objectData['objtype_name'];
+ else
+ return "[${objectData['objtype_name']}]";
+ }
}
// This function finds height of solid rectangle of atoms, which are all
// Take a list of records and filter against given RackCode expression. Return
// the original list intact, if there was no filter requested, but return an
// empty list, if there was an error.
-function filterEntityList ($list_in, $realm, $expression = array())
-{
- if ($expression === NULL)
- return array();
- if (!count ($expression))
- return $list_in;
- $list_out = array();
- foreach ($list_in as $item_key => $item_value)
- if (TRUE === judgeEntity ($realm, $item_key, $expression))
- $list_out[$item_key] = $item_value;
- return $list_out;
-}
-
function filterCellList ($list_in, $expression = array())
{
if ($expression === NULL)
return $list_out;
}
-// Tell, if the given expression is true for the given entity.
-function judgeEntity ($realm, $id, $expression)
-{
- $item_explicit_tags = loadEntityTags ($realm, $id);
- global $pTable;
- return eval_expression
- (
- $expression,
- array_merge
- (
- $item_explicit_tags,
- getImplicitTags ($item_explicit_tags),
- generateEntityAutoTags ($realm, $id)
- ),
- $pTable,
- TRUE
- );
-}
-
-// Idem, but use complete record instead of key.
+// Tell, if the given expression is true for the given entity. Take complete record on input.
function judgeCell ($cell, $expression)
{
global $pTable;
);
}
-// If the requested predicate exists, return its [last] definition.
-// Otherwise return NULL (to signal filterEntityList() about error).
-// Also detect "not set" option selected.
-function interpretPredicate ($pname)
-{
- if ($pname == '_')
- return array();
- global $pTable;
- if (isset ($pTable[$pname]))
- return $pTable[$pname];
- return NULL;
-}
-
// Tell, if a constraint from config option permits given record.
-function considerConfiguredConstraint ($entity_realm, $entity_id, $varname)
+function considerConfiguredConstraint ($cell, $varname)
{
if (!strlen (getConfigVar ($varname)))
return TRUE; // no restriction
$parseCache[$varname] = spotPayload (getConfigVar ($varname), 'SYNT_EXPR');
if ($parseCache[$varname]['result'] != 'ACK')
return FALSE; // constraint set, but cannot be used due to compilation error
- return judgeEntity ($entity_realm, $entity_id, $parseCache[$varname]['load']);
+ return judgeCell ($cell, $parseCache[$varname]['load']);
}
// Return list of records in the given realm, which conform to
echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
if (!empty ($info['name']))
echo "<tr><th width='50%' class=tdright>Common name:</th><td class=tdleft>${info['name']}</td></tr>\n";
- elseif (considerConfiguredConstraint ('object', $object_id, 'NAMEWARN_LISTSRC'))
+ // FIXME: don't call spotEntity() each time, do it once in the beginning.
+ elseif (considerConfiguredConstraint (spotEntity ('object', $object_id), 'NAMEWARN_LISTSRC'))
echo "<tr><td colspan=2 class=msg_error>Common name is missing.</td></tr>\n";
echo "<tr><th width='50%' class=tdright>Object type:</th><td class=tdleft><a href='";
echo makeHref (array (
echo "'>${info['objtype_name']}</a></td></tr>\n";
if (!empty ($info['asset_no']))
echo "<tr><th width='50%' class=tdright>Asset tag:</th><td class=tdleft>${info['asset_no']}</td></tr>\n";
- elseif (considerConfiguredConstraint ('object', $object_id, 'ASSETWARN_LISTSRC'))
+ // FIXME: ditto
+ elseif (considerConfiguredConstraint (spotEntity ('object', $object_id), 'ASSETWARN_LISTSRC'))
echo "<tr><td colspan=2 class=msg_error>Asset tag is missing.</td></tr>\n";
if (!empty ($info['label']))
echo "<tr><th width='50%' class=tdright>Visible label:</th><td class=tdleft>${info['label']}</td></tr>\n";
function trigger_isloadbalancer ()
{
assertUIntArg ('object_id', __FUNCTION__);
- return considerConfiguredConstraint ('object', $_REQUEST['object_id'], 'IPV4LB_LISTSRC') ? 'std' : '';
+ return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4LB_LISTSRC') ? 'std' : '';
}
function trigger_ipv4 ()
if (count (getObjectIPv4Allocations ($_REQUEST['object_id'])))
return 'std';
// Only hide the tab, if there are no addresses allocated.
- return considerConfiguredConstraint ('object', $_REQUEST['object_id'], 'IPV4OBJ_LISTSRC') ? 'std' : '';
+ return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4OBJ_LISTSRC') ? 'std' : '';
}
function trigger_natv4 ()
{
assertUIntArg ('object_id', __FUNCTION__);
- return considerConfiguredConstraint ('object', $_REQUEST['object_id'], 'IPV4NAT_LISTSRC') ? 'std' : '';
+ return considerConfiguredConstraint (spotEntity ('object', $_REQUEST['object_id']), 'IPV4NAT_LISTSRC') ? 'std' : '';
}
function trigger_poolrscount ()