function importDPData() { global $sic, $dbxlink; assertUIntArg('nports'); $nignored = $ndone = 0; for ($i = 0; $i < $sic['nports']; $i++) { if (array_key_exists("do_{$i}", $sic)) { $params = array(); assertStringArg("ports_{$i}"); foreach (explode(',', $_REQUEST["ports_{$i}"]) as $item) { $pair = explode(':', $item); if (count($pair) != 2) { continue; } $params[$pair[0]] = $pair[1]; } if (!isset($params['a_id']) || !isset($params['b_id']) || !intval($params['a_id']) || !intval($params['b_id'])) { throw new InvalidArgException("ports_{$i}", $_REQUEST["ports_{$i}"], "can not unpack port ids"); } $porta = getPortInfo($params['a_id']); $portb = getPortInfo($params['b_id']); if ($porta['linked'] or $portb['linked'] or $porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id']) { $nignored++; continue; } $oif_a = intval(@$params['a_oif']); // these parameters are optional $oif_b = intval(@$params['b_oif']); $dbxlink->beginTransaction(); try { if ($oif_a) { commitUpdatePortOIF($params['a_id'], $oif_a); $porta['oif_id'] = $oif_a; } if ($oif_b) { commitUpdatePortOIF($params['b_id'], $oif_b); $portb['oif_id'] = $oif_b; } if (arePortsCompatible($porta, $portb)) { linkPorts($params['a_id'], $params['b_id']); $ndone++; $dbxlink->commit(); } else { $dbxlink->rollback(); $nignored++; } } catch (RTDatabaseError $e) { $dbxlink->rollBack(); $nignored++; } } } showFuncMessage(__FUNCTION__, 'OK', array($nignored, $ndone)); }
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 ' — '; 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">✕ Not compatible port types</p>'; echo '<p class="compat-hint" id="hint-compat">✔ Compatible port types</p>'; echo '<p><input type=submit name="do_link" value="Link">'; } }