Beispiel #1
0
function renderVLANIPLinks($some_id)
{
    function printNewItemTR($sname, $options, $extra = array())
    {
        if (!count($options)) {
            return;
        }
        printOpFormIntro('bind', $extra);
        echo '<tr><td>' . getOptionTree($sname, $options, array('tabindex' => 101));
        echo '</td><td>' . getImageHREF('ATTACH', 'bind', TRUE, 102) . '</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);
            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, which 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);
            # find out VLAN domains, where the current network already has a VLAN linked
            $except_domains = array();
            foreach ($netinfo['8021q'] as $item) {
                $except_domains[] = $item['domain_id'];
                $minuslines[] = array('net_id' => $netinfo['id'], 'domain_id' => $item['domain_id'], 'vlan_id' => $item['vlan_id']);
            }
            # offer VLANs from all other domains
            $plusoptions = getAllVLANOptions($except_domains);
            $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=trbusy><td>';
        switch ($pageno) {
            case 'vlan':
                renderCell(spotEntity($ip_ver . 'net', $item['net_id']));
                break;
            case 'ipv4net':
            case 'ipv6net':
                $vlaninfo = getVLANInfo($item['domain_id'] . '-' . $item['vlan_id']);
                echo formatVLANName($vlaninfo, 'markup long');
                break;
        }
        echo '</td><td><a href="';
        echo makeHrefProcess(array('id' => $some_id, 'op' => 'unbind', 'id' => $item['net_id'], 'vlan_ck' => $item['domain_id'] . '-' . $item['vlan_id']));
        echo '">' . getImageHREF('Cut', 'unbind') . '</a></td></tr>';
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewItemTR($select_name, $plusoptions, $extra);
    }
    echo '</table>';
}
Beispiel #2
0
function formatVLANName($vlaninfo, $context = 'markup long')
{
    switch ($context) {
        case 'option':
            $ret = $vlaninfo['vlan_id'];
            if ($vlaninfo['vlan_descr'] != '') {
                $ret .= ' ' . niftyString($vlaninfo['vlan_descr']);
            }
            return $ret;
        case 'label':
            $ret = $vlaninfo['vlan_id'];
            if ($vlaninfo['vlan_descr'] != '') {
                $ret .= ' <i>(' . niftyString($vlaninfo['vlan_descr']) . ')</i>';
            }
            return $ret;
        case 'plain long':
            $ret = 'VLAN' . $vlaninfo['vlan_id'];
            if ($vlaninfo['vlan_descr'] != '') {
                $ret .= ' (' . niftyString($vlaninfo['vlan_descr'], 20, FALSE) . ')';
            }
            return $ret;
        case 'hyperlink':
            $ret = '<a href="';
            $ret .= makeHref(array('page' => 'vlan', 'vlan_ck' => $vlaninfo['domain_id'] . '-' . $vlaninfo['vlan_id']));
            $ret .= '">' . formatVLANName($vlaninfo, 'markup long') . '</a>';
            return $ret;
        case 'markup long':
        default:
            $ret = 'VLAN' . $vlaninfo['vlan_id'];
            $ret .= ' @' . niftyString($vlaninfo['domain_descr']);
            if ($vlaninfo['vlan_descr'] != '') {
                $ret .= ' <i>(' . niftyString($vlaninfo['vlan_descr']) . ')</i>';
            }
            return $ret;
    }
}