function handlePopupPortLink()
{
    assertPermission('depot', 'default');
    assertUIntArg('port');
    assertUIntArg('remote_port');
    assertStringArg('cable', TRUE);
    $port_info = getPortInfo($_REQUEST['port']);
    $remote_port_info = getPortInfo($_REQUEST['remote_port']);
    $POIFC = getPortOIFCompat();
    if (isset($_REQUEST['port_type']) and isset($_REQUEST['remote_port_type'])) {
        $type_local = $_REQUEST['port_type'];
        $type_remote = $_REQUEST['remote_port_type'];
    } else {
        $type_local = $port_info['oif_id'];
        $type_remote = $remote_port_info['oif_id'];
    }
    $matches = FALSE;
    $js_table = '';
    foreach ($POIFC as $pair) {
        if ($pair['type1'] == $type_local && $pair['type2'] == $type_remote) {
            $matches = TRUE;
            break;
        } else {
            $js_table .= "POIFC['{$pair['type1']}-{$pair['type2']}'] = 1;\n";
        }
    }
    if ($matches) {
        if ($port_info['oif_id'] != $type_local) {
            commitUpdatePortOIF($port_info['id'], $type_local);
        }
        if ($remote_port_info['oif_id'] != $type_remote) {
            commitUpdatePortOIF($remote_port_info['id'], $type_remote);
        }
        linkPorts($port_info['id'], $remote_port_info['id'], $_REQUEST['cable']);
        // patch cable?
        if (array_key_exists('heap_id', $_REQUEST)) {
            // Leave the compatibility constraints check up to the foreign keys.
            if (0 != ($heap_id = genericAssertion('heap_id', 'uint0'))) {
                $heaps = getPatchCableHeapSummary();
                if (commitModifyPatchCableAmount($heap_id, -1)) {
                    showSuccess('consumed a patch cable from ' . formatPatchCableHeapAsPlainText($heaps[$heap_id]));
                } else {
                    showError('failed to consume a patch cable');
                }
            }
        }
        showOneLiner(8, array(formatPortLink($port_info['object_id'], NULL, $port_info['id'], $port_info['name']), formatPort($remote_port_info)));
        addJS(<<<END
window.opener.location.reload(true);
window.close();
END
, TRUE);
        backupLogMessages();
    } else {
        // JS code to display port compatibility hint
        addJS(<<<END
POIFC = {};
{$js_table}
\$(document).ready(function () {
\t\$('select.porttype').change(onPortTypeChange);\t
\tonPortTypeChange();
});
function onPortTypeChange() {
\tvar key = \$('*[name=port_type]')[0].value + '-' + \$('*[name=remote_port_type]')[0].value;
\tif (POIFC[key] == 1)
\t{
\t\t\$('#hint-not-compat').hide();
\t\t\$('#hint-compat').show();
\t}
\telse
\t{
\t\t\$('#hint-compat').hide();
\t\t\$('#hint-not-compat').show();
\t}
}
END
, TRUE);
        addCSS(<<<END
.compat-hint {
\tdisplay: none;
\tfont-size: 125%;
}
.compat-hint#hint-compat {
\tcolor: green;
}
.compat-hint#hint-not-compat {
\tcolor: #804040;
}
END
, TRUE);
        // render port type editor form
        echo '<form method=GET>';
        echo '<input type=hidden name="module" value="popup">';
        echo '<input type=hidden name="helper" value="portlist">';
        echo '<input type=hidden name="port" value="' . $port_info['id'] . '">';
        echo '<input type=hidden name="remote_port" value="' . $remote_port_info['id'] . '">';
        echo '<input type=hidden name="cable" value="' . htmlspecialchars($_REQUEST['cable'], ENT_QUOTES) . '">';
        echo '<p>The ports you have selected are not compatible. Please select a compatible transceiver pair.';
        echo '<p>';
        echo formatPort($port_info) . ' ';
        if ($port_info['iif_id'] == 1) {
            echo formatPortIIFOIF($port_info);
            echo '<input type=hidden name="port_type" value="' . $port_info['oif_id'] . '">';
        } else {
            echo '<label>' . $port_info['iif_name'] . ' ';
            printSelect(getExistingPortTypeOptions($port_info), array('class' => 'porttype', 'name' => 'port_type'), $type_local);
            echo '</label>';
        }
        echo ' &mdash; ';
        if ($remote_port_info['iif_id'] == 1) {
            echo formatPortIIFOIF($remote_port_info);
            echo '<input type=hidden name="remote_port_type" value="' . $remote_port_info['oif_id'] . '">';
        } else {
            echo '<label>' . $remote_port_info['iif_name'] . ' ';
            printSelect(getExistingPortTypeOptions($remote_port_info), array('class' => 'porttype', 'name' => 'remote_port_type'), $type_remote);
            echo '</label>';
        }
        echo ' ' . formatPort($remote_port_info);
        echo '<p class="compat-hint" id="hint-not-compat">&#10005; Not compatible port types</p>';
        echo '<p class="compat-hint" id="hint-compat">&#10004; Compatible port types</p>';
        echo '<p><input type=submit name="do_link" value="Link">';
    }
}
Exemple #2
0
     redirectUser($_SERVER['SCRIPT_NAME'] . '?method=get_object&object_id=' . $_REQUEST['object_id']);
     break;
     // link a port
     //    UI equivalent: /index.php?module=popup&helper=portlist&port=<<ID>>&in_rack=off&in_rack=on&remote_port=<<ID>>&cable=<<>>&do_link=Link
     //    UI handler: ()
 // link a port
 //    UI equivalent: /index.php?module=popup&helper=portlist&port=<<ID>>&in_rack=off&in_rack=on&remote_port=<<ID>>&cable=<<>>&do_link=Link
 //    UI handler: ()
 case 'link_port':
     require_once 'inc/init.php';
     assertUIntArg('port');
     assertUIntArg('remote_port');
     assertStringArg('cable', TRUE);
     $port_info = getPortInfo($_REQUEST['port']);
     $remote_port_info = getPortInfo($_REQUEST['remote_port']);
     $POIFC = getPortOIFCompat();
     // (removed the ability to specify remote and local port types)
     $matches = FALSE;
     foreach ($POIFC as $pair) {
         if ($pair['type1'] == $port_info['oif_id'] && $pair['type2'] == $remote_port_info['oif_id']) {
             $matches = TRUE;
             break;
         }
     }
     if (!$matches) {
         $port_type = $port_info['oif_name'];
         $remote_port_type = $remote_port_info['oif_name'];
         throw new InvalidArgException('remote_port', $_REQUEST['remote_port'], "invalid argument: port types {$port_type} (local) and {$remote_port_type} (remote) can't be linked");
     }
     linkPorts($port_info['id'], $remote_port_info['id'], $_REQUEST['cable']);
     sendAPIResponse(array(), array('message' => 'ports linked successfully', 'local_object' => $port_info['object_id'], 'remote_object' => $remote_port_info['object_id'], 'local_port' => $_REQUEST['port'], 'remote_port' => $_REQUEST['remote_port']));
Exemple #3
0
function renderOIFCompatEditor()
{
    function printNewitemTR()
    {
        printOpFormIntro('add');
        echo '<tr><th class=tdleft>';
        printImageHREF('add', 'add pair', TRUE);
        echo '</th><th class=tdleft>';
        printSelect(getPortOIFOptions(), array('name' => 'type1'));
        echo '</th><th class=tdleft>';
        printSelect(getPortOIFOptions(), array('name' => 'type2'));
        echo '</th></tr></form>';
    }
    global $nextorder, $wdm_packs;
    startPortlet('WDM wideband receivers');
    echo '<table border=0 align=center cellspacing=0 cellpadding=5>';
    echo '<tr><th>&nbsp;</th><th>enable</th><th>disable</th></tr>';
    $order = 'odd';
    foreach ($wdm_packs as $codename => $packinfo) {
        echo "<tr class=row_{$order}><td class=tdleft>" . $packinfo['title'] . '</td><td>';
        echo getOpLink(array('op' => 'addPack', 'standard' => $codename), '', 'add');
        echo '</td><td>';
        echo getOpLink(array('op' => 'delPack', 'standard' => $codename), '', 'delete');
        echo '</td></tr>';
        $order = $nextorder[$order];
    }
    echo '</table>';
    finishPortlet();
    startPortlet('interface by interface');
    $last_left_oif_id = NULL;
    echo '<br><table class=cooltable align=center border=0 cellpadding=5 cellspacing=0>';
    echo '<tr><th>&nbsp;</th><th>From Interface</th><th>To Interface</th></tr>';
    if (getConfigVar('ADDNEW_AT_TOP') == 'yes') {
        printNewitemTR();
    }
    foreach (getPortOIFCompat() as $pair) {
        if ($last_left_oif_id != $pair['type1']) {
            $order = $nextorder[$order];
            $last_left_oif_id = $pair['type1'];
        }
        echo "<tr class=row_{$order}><td>";
        echo getOpLink(array('op' => 'del', 'type1' => $pair['type1'], 'type2' => $pair['type2']), '', 'delete', 'remove pair');
        echo "</td><td class=tdleft>{$pair['type1name']}</td><td class=tdleft>{$pair['type2name']}</td></tr>";
    }
    if (getConfigVar('ADDNEW_AT_TOP') != 'yes') {
        printNewitemTR();
    }
    echo '</table>';
    finishPortlet();
}
Exemple #4
0
function arePortTypesCompatible($oif1, $oif2)
{
    foreach (getPortOIFCompat() as $item) {
        if ($item['type1'] == $oif1 && $item['type2'] == $oif2) {
            return TRUE;
        }
    }
    return FALSE;
}