<?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)) {
  KEY `AttributeValue_IPv6-FK-map` (`object_tid`,`attr_id`),
  CONSTRAINT `AttributeValue_IPv6-FK-map` FOREIGN KEY (`object_tid`, `attr_id`) REFERENCES `AttributeMap` (`objtype_id`, `attr_id`),
  CONSTRAINT `AttributeValue_IPv6-FK-object` FOREIGN KEY (`net_id`) REFERENCES `IPv6Network` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO Dictionary (dict_key, chapter_id, dict_sticky, dict_value) VALUES
 (49000, 1, 'no', 'IPv4 network (dummy)'),
 (49001, 1, 'no', 'IPv6 network (dummy)');
*/
$page['flatip']['title'] = 'IP networks';
$page['flatip']['parent'] = 'index';
$tabhandler['flatip']['default'] = 'renderFlatIP';
registerHook('modifyEntitySummary', 'addAttributesToNetworkSummary', 'chain');
foreach (array('ipv4net', 'ipv6net') as $net_realm) {
    registerTabHandler($net_realm, 'properties', 'renderNetworkEditAttrs');
    registerOpHandler($net_realm, 'properties', 'updateAttrs', 'handleNetworkAttrsChange');
    registerOpHandler($net_realm, 'properties', 'clearSticker', 'handleNetworkStickerClear');
}
// Pseudo-object type ids.
// Network attributes are assigned to these object types.
$netobject_type_id = array('ipv4net' => 49000, 'ipv6net' => 49001);
// Special page 'flatip' handler that lists networks like the 'depot' page lists object.
// Lists both IP families on the same page.
// No network hierarchy is displayed, that's why 'flat'.
function renderFlatIP()
{
    if (isset($_REQUEST['attr_id']) && isset($_REQUEST['attr_value'])) {
        $params = array('attr_id' => $_REQUEST['attr_id'], 'attr_value' => $_REQUEST['attr_value']);
        $av = $_REQUEST['attr_value'];
        if ($av === 'NULL') {
            $av = NULL;
        }