function renderNetVLAN($cell)
{
    if (empty($cell['8021q'])) {
        return;
    }
    $links = array();
    foreach ($cell['8021q'] as $vi) {
        $vlan_info = getVlanRow("{$vi['domain_id']}-{$vi['vlan_id']}");
        $links[] = formatVLANAsShortLink($vlan_info);
    }
    $noun = count($cell['8021q']) > 1 ? 'VLANs' : 'VLAN';
    echo "<div class='vlan'><strong><small>{$noun}</small> " . implode(', ', $links) . '</strong></div>';
}
Пример #2
0
function renderVLANIPLinks($some_id)
{
    function printNewItemTR($sname, $options, $extra = array())
    {
        if (!count($options)) {
            return;
        }
        printOpFormIntro('bind', $extra);
        echo '<tr><td>' . getOptionTree($sname, $options);
        echo '</td><td>' . getImageHREF('ATTACH', 'bind', TRUE) . '</td></tr></form>';
    }
    global $pageno, $tabno;
    echo '<table cellspacing=0 cellpadding=5 align=center class=widetable>';
    echo '<tr>';
    // fill $minuslines, $plusoptions, $select_name
    $minuslines = array();
    $plusoptions = array();
    $extra = array();
    switch ($pageno) {
        case 'vlan':
            $ip_ver = $tabno == 'ipv6' ? 'ipv6' : 'ipv4';
            echo '<th>' . getImageHREF('net') . '</th>';
            $vlan = getVLANInfo($some_id);
            $domainclass = array($vlan['domain_id'] => 'trbusy');
            foreach ($vlan[$ip_ver . "nets"] as $net_id) {
                $minuslines[] = array('net_id' => $net_id, 'domain_id' => $vlan['domain_id'], 'vlan_id' => $vlan['vlan_id']);
            }
            // Any VLAN can link to any network that isn't yet linked to current domain.
            // get free IP nets
            $netlist_func = $ip_ver == 'ipv6' ? 'getVLANIPv6Options' : 'getVLANIPv4Options';
            foreach ($netlist_func($vlan['domain_id']) as $net_id) {
                $netinfo = spotEntity($ip_ver . 'net', $net_id);
                if (considerConfiguredConstraint($netinfo, 'VLANIPV4NET_LISTSRC')) {
                    $plusoptions['other'][$net_id] = $netinfo['ip'] . '/' . $netinfo['mask'] . ' ' . $netinfo['name'];
                }
            }
            $select_name = 'id';
            $extra = array('vlan_ck' => $vlan['domain_id'] . '-' . $vlan['vlan_id']);
            break;
        case 'ipv4net':
        case 'ipv6net':
            echo '<th>VLAN</th>';
            $netinfo = spotEntity($pageno, $some_id);
            $reuse_domain = considerConfiguredConstraint($netinfo, '8021Q_MULTILINK_LISTSRC');
            # For each of the domains linked to the network produce class name based on
            # number of VLANs linked and the current "reuse" setting.
            $domainclass = array();
            foreach (array_count_values(reduceSubarraysToColumn($netinfo['8021q'], 'domain_id')) as $domain_id => $vlan_count) {
                $domainclass[$domain_id] = $vlan_count == 1 ? 'trbusy' : ($reuse_domain ? 'trwarning' : 'trerror');
            }
            # Depending on the setting and the currently linked VLANs reduce the list of new
            # options by either particular VLANs or whole domains.
            $except = array();
            foreach ($netinfo['8021q'] as $item) {
                if ($reuse_domain) {
                    $except[$item['domain_id']][] = $item['vlan_id'];
                } elseif (!array_key_exists($item['domain_id'], $except)) {
                    $except[$item['domain_id']] = range(VLAN_MIN_ID, VLAN_MAX_ID);
                }
                $minuslines[] = array('net_id' => $netinfo['id'], 'domain_id' => $item['domain_id'], 'vlan_id' => $item['vlan_id']);
            }
            $plusoptions = getAllVLANOptions($except);
            $select_name = 'vlan_ck';
            $extra = array('id' => $netinfo['id']);
            break;
    }
    echo '<th>&nbsp;</th></tr>';
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewItemTR($select_name, $plusoptions, $extra);
    }
    foreach ($minuslines as $item) {
        echo '<tr class=' . $domainclass[$item['domain_id']] . '><td>';
        switch ($pageno) {
            case 'vlan':
                renderCell(spotEntity($ip_ver . 'net', $item['net_id']));
                break;
            case 'ipv4net':
            case 'ipv6net':
                $vlaninfo = getVlanRow($item['domain_id'] . '-' . $item['vlan_id']);
                echo formatVLANAsRichText($vlaninfo);
                break;
        }
        echo '</td><td>';
        echo getOpLink(array('id' => $some_id, 'op' => 'unbind', 'id' => $item['net_id'], 'vlan_ck' => $item['domain_id'] . '-' . $item['vlan_id']), '', 'Cut', 'unbind');
        echo '</td></tr>';
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItemTR($select_name, $plusoptions, $extra);
    }
    echo '</table>';
}