Exemple #1
0
function addLotOfObjects()
{
    $taglist = genericAssertion('taglist', 'array0');
    assertUIntArg('global_type_id', TRUE);
    assertStringArg('namelist', TRUE);
    $global_type_id = $_REQUEST['global_type_id'];
    if ($global_type_id == 0 or !strlen($_REQUEST['namelist'])) {
        showError('Incomplete form has been ignored. Cheers.');
        return;
    } else {
        // The name extractor below was stolen from ophandlers.php:addMultiPorts()
        $names1 = explode("\n", $_REQUEST['namelist']);
        $names2 = array();
        foreach ($names1 as $line) {
            $parts = explode('\\r', $line);
            reset($parts);
            if (!strlen($parts[0])) {
                continue;
            } else {
                $names2[] = rtrim($parts[0]);
            }
        }
        foreach ($names2 as $name) {
            try {
                $object_id = commitAddObject($name, NULL, $global_type_id, '', $taglist);
                $info = spotEntity('object', $object_id);
                amplifyCell($info);
                showSuccess("added object " . formatPortLink($info['id'], $info['dname'], NULL, NULL));
            } catch (RTDatabaseError $e) {
                showError("Error creating object '{$name}': " . $e->getMessage());
                continue;
            }
        }
    }
}
Exemple #2
0
function renderDiscoveredNeighbors($object_id)
{
    global $tabno;
    $opcode_by_tabno = array('livecdp' => 'getcdpstatus', 'livelldp' => 'getlldpstatus');
    try {
        $neighbors = queryDevice($object_id, $opcode_by_tabno[$tabno]);
        $neighbors = sortPortList($neighbors);
    } catch (RTGatewayError $e) {
        showError($e->getMessage());
        return;
    }
    $mydevice = spotEntity('object', $object_id);
    amplifyCell($mydevice);
    // reindex by port name
    $myports = array();
    foreach ($mydevice['ports'] as $port) {
        if (mb_strlen($port['name'])) {
            $myports[$port['name']][] = $port;
        }
    }
    // scroll to selected port
    if (isset($_REQUEST['hl_port_id'])) {
        assertUIntArg('hl_port_id');
        $hl_port_id = intval($_REQUEST['hl_port_id']);
        addAutoScrollScript("port-{$hl_port_id}");
    }
    switchportInfoJS($object_id);
    // load JS code to make portnames interactive
    printOpFormIntro('importDPData');
    echo '<br><table cellspacing=0 cellpadding=5 align=center class=widetable>';
    echo '<tr><th colspan=2>local port</th><th></th><th>remote device</th><th colspan=2>remote port</th><th><input type="checkbox" checked id="cb-toggle"></th></tr>';
    $inputno = 0;
    foreach ($neighbors as $local_port => $remote_list) {
        $initial_row = TRUE;
        // if port has multiple neighbors, the first table row is initial
        // array of local ports with the name specified by DP
        $local_ports = isset($myports[$local_port]) ? $myports[$local_port] : array();
        foreach ($remote_list as $dp_neighbor) {
            $error_message = NULL;
            $link_matches = FALSE;
            $portinfo_local = NULL;
            $portinfo_remote = NULL;
            $variants = array();
            do {
                // once-cyle fake loop used only to break out of it
                if (!empty($local_ports)) {
                    $portinfo_local = $local_ports[0];
                }
                // find remote object by DP information
                $dp_remote_object_id = searchByMgmtHostname($dp_neighbor['device']);
                if (!$dp_remote_object_id) {
                    $dp_remote_object_id = lookupEntityByString('object', $dp_neighbor['device']);
                }
                if (!$dp_remote_object_id) {
                    $error_message = "No such neighbor <i>{$dp_neighbor['device']}</i>";
                    break;
                }
                $dp_remote_object = spotEntity('object', $dp_remote_object_id);
                amplifyCell($dp_remote_object);
                $dp_neighbor['port'] = shortenIfName($dp_neighbor['port'], NULL, $dp_remote_object['id']);
                // get list of ports that have name matching CDP portname
                $remote_ports = array();
                // list of remote (by DP info) ports
                foreach ($dp_remote_object['ports'] as $port) {
                    if ($port['name'] == $dp_neighbor['port']) {
                        $portinfo_remote = $port;
                        $remote_ports[] = $port;
                    }
                }
                // check if ports with such names exist on devices
                if (empty($local_ports)) {
                    $error_message = "No such local port <i>{$local_port}</i>";
                    break;
                }
                if (empty($remote_ports)) {
                    $error_message = "No such port on " . formatPortLink($dp_remote_object['id'], $dp_remote_object['name'], NULL, NULL);
                    break;
                }
                // determine match or mismatch of local link
                foreach ($local_ports as $portinfo_local) {
                    if ($portinfo_local['remote_id']) {
                        if ($portinfo_local['remote_object_id'] == $dp_remote_object_id and $portinfo_local['remote_name'] == $dp_neighbor['port']) {
                            // set $portinfo_remote to corresponding remote port
                            foreach ($remote_ports as $portinfo_remote) {
                                if ($portinfo_remote['id'] == $portinfo_local['remote_id']) {
                                    break;
                                }
                            }
                            $link_matches = TRUE;
                            unset($error_message);
                        } elseif ($portinfo_local['remote_object_id'] != $dp_remote_object_id) {
                            $error_message = "Remote device mismatch - port linked to " . formatLinkedPort($portinfo_local);
                        } else {
                            // ($portinfo_local['remote_name'] != $dp_neighbor['port'])
                            $error_message = "Remote port mismatch - port linked to " . formatPortLink($portinfo_local['remote_object_id'], NULL, $portinfo_local['remote_id'], $portinfo_local['remote_name']);
                        }
                        break 2;
                    }
                }
                // no local links found, try to search for remote links
                foreach ($remote_ports as $portinfo_remote) {
                    if ($portinfo_remote['remote_id']) {
                        $remote_link_html = formatLinkedPort($portinfo_remote);
                        $remote_port_html = formatPortLink($portinfo_remote['object_id'], NULL, $portinfo_remote['id'], $portinfo_remote['name']);
                        $error_message = "Remote port {$remote_port_html} is already linked to {$remote_link_html}";
                        break 2;
                    }
                }
                // no links found on both sides, search for a compatible port pair
                $port_types = array();
                foreach (array('left' => $local_ports, 'right' => $remote_ports) as $side => $port_list) {
                    foreach ($port_list as $portinfo) {
                        $tmp_types = $portinfo['iif_id'] == 1 ? array($portinfo['oif_id'] => $portinfo['oif_name']) : getExistingPortTypeOptions($portinfo['id']);
                        foreach ($tmp_types as $oif_id => $oif_name) {
                            $port_types[$side][$oif_id][] = array('id' => $oif_id, 'name' => $oif_name, 'portinfo' => $portinfo);
                        }
                    }
                }
                foreach ($port_types['left'] as $left_id => $left) {
                    foreach ($port_types['right'] as $right_id => $right) {
                        if (arePortTypesCompatible($left_id, $right_id)) {
                            foreach ($left as $left_port) {
                                foreach ($right as $right_port) {
                                    $variants[] = array('left' => $left_port, 'right' => $right_port);
                                }
                            }
                        }
                    }
                }
                if (!count($variants)) {
                    // no compatible ports found
                    $error_message = "Incompatible port types";
                }
            } while (FALSE);
            // do {
            $tr_class = $link_matches ? 'trok' : (isset($error_message) ? 'trerror' : 'trwarning');
            echo "<tr class=\"{$tr_class}\">";
            if ($initial_row) {
                $count = count($remote_list);
                $td_class = '';
                if (isset($hl_port_id) and $hl_port_id == $portinfo_local['id']) {
                    $td_class = "class='border_highlight'";
                }
                echo "<td rowspan=\"{$count}\" {$td_class} NOWRAP>" . ($portinfo_local ? formatPortLink($mydevice['id'], NULL, $portinfo_local['id'], $portinfo_local['name'], 'interactive-portname port-menu') : "<a class='interactive-portname port-menu nolink'>{$local_port}</a>") . ($count > 1 ? "<br> ({$count} neighbors)" : '') . '</td>';
                $initial_row = FALSE;
            }
            echo "<td>" . ($portinfo_local ? formatPortIIFOIF($portinfo_local) : '&nbsp;') . "</td>";
            echo "<td>" . formatIfTypeVariants($variants, "ports_{$inputno}") . "</td>";
            echo "<td>{$dp_neighbor['device']}</td>";
            echo "<td>" . ($portinfo_remote ? formatPortLink($dp_remote_object_id, NULL, $portinfo_remote['id'], $portinfo_remote['name']) : $dp_neighbor['port']) . "</td>";
            echo "<td>" . ($portinfo_remote ? formatPortIIFOIF($portinfo_remote) : '&nbsp;') . "</td>";
            echo "<td>";
            if (!empty($variants)) {
                echo "<input type=checkbox name=do_{$inputno} class='cb-makelink'>";
                $inputno++;
            }
            echo "</td>";
            if (isset($error_message)) {
                echo "<td style=\"background-color: white; border-top: none\">{$error_message}</td>";
            }
            echo "</tr>";
        }
    }
    if ($inputno) {
        echo "<input type=hidden name=nports value={$inputno}>";
        echo '<tr><td colspan=7 align=center>' . getImageHREF('CREATE', 'import selected', TRUE) . '</td></tr>';
    }
    echo '</table></form>';
    addJS(<<<END
\$(document).ready(function () {
\t\$('#cb-toggle').click(function (event) {
\t\tvar list = \$('.cb-makelink');
\t\tfor (var i in list) {
\t\t\tvar cb = list[i];
\t\t\tcb.checked = event.target.checked;
\t\t}
\t}).triggerHandler('click');
});
END
, TRUE);
}
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">';
    }
}
function CableReport()
{
    global $tableheader, $displaylinks;
    // Remote jQuery and DataTables files:
    echo '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.0/css/jquery.dataTables.css">';
    echo '<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-1.10.2.min.js"></script>';
    echo '<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>';
    // Local jQuery and DataTables files from DataTables-1.10.0 distribution zip:
    //echo '<link rel="stylesheet" type="text/css" href="/rt/extensions/cablereportv3/DataTables-1.10.0/media/css/jquery.dataTables.css">';
    //echo '<script type="text/javascript" charset="utf8" src="/rt/extensions/cablereportv3/DataTables-1.10.0/media/js/jquery.js"></script>';
    //echo '<script type="text/javascript" charset="utf8" src="/rt/extensions/cablereportv3/DataTables-1.10.0/media/js/jquery.dataTables.js"></script>';
    echo '<script>
                $(document).ready(function() {
                    $("#cablereport").dataTable({
                        "bPaginate": "true",
                        "bLengthChange": "false",
                        "sPaginationType": "full_numbers",
                        "aaSorting": [[ 0, "desc" ]],
                        "iDisplayLength": 20,
                        "stateSave": false,
                        "oLanguage": {
                                "sLengthMenu": \'Display <select>\'+
                                           \'<option value="10">10</option>\'+
                                           \'<option value="20">20</option>\'+
                                           \'<option value="30">30</option>\'+
                                           \'<option value="40">40</option>\'+
                                           \'<option value="50">50</option>\'+
                                           \'<option value="-1">All</option>\'+
                                           \'</select> records\'
                        }
                    });
                });
                </script>';
    echo "\n";
    echo '<div class=portlet>';
    echo '<h2>' . $tableheader . '</h2>';
    echo "\n";
    echo '<table id="cablereport" class="display">';
    echo "\n";
    echo '<thead><tr>';
    echo '<th>Cable ID</th>';
    echo '<th>Device 1</th>';
    echo '<th>Port 1</th>';
    echo '<th>Type 1</th>';
    echo '<th>Device 2</th>';
    echo '<th>Port 2</th>';
    echo '<th>Type 2</th>';
    echo '</tr></thead>';
    echo "\n";
    echo '<tbody>';
    echo "\n";
    $allports = fetchPortList('IF(la.porta, pa.id, pb.id) IS NOT NULL');
    $cid = 0;
    foreach ($allports as $port) {
        $allporttypes[$port['id']] = $port['oif_name'];
        if ($port['linked'] != 1) {
            continue;
        }
        if ($done[$port['id']] == 1) {
            continue;
        } else {
            $cid++;
            $cabletable[$cid]['cableid'] = $port['cableid'];
            if ($displaylinks == 1) {
                $cabletable[$cid]['device1'] = formatPortLink($port['object_id'], $port['object_name'], NULL, NULL);
                $cabletable[$cid]['port1'] = formatPortLink($port['object_id'], NULL, $port['id'], $port['name']);
            } else {
                $cabletable[$cid]['device1'] = $port['object_name'];
                $cabletable[$cid]['port1'] = $port['name'];
            }
            $cabletable[$cid]['port1id'] = $port['id'];
            $cabletable[$cid]['type1'] = $port['oif_name'];
            if ($displaylinks == 1) {
                $cabletable[$cid]['device2'] = formatPortLink($port['remote_object_id'], $port['remote_object_name'], NULL, NULL);
                $cabletable[$cid]['port2'] = formatPortLink($port['remote_object_id'], NULL, $port['remote_id'], $port['remote_name']);
            } else {
                $cabletable[$cid]['device2'] = $port['remote_object_name'];
                $cabletable[$cid]['port2'] = $port['remote_name'];
            }
            $cabletable[$cid]['port2id'] = $port['remote_id'];
            $cabletable[$cid]['type2'] = '';
            # missing from fetchPortList() add later from $allporttypes being created;
            $done[$port['remote_id']] = 1;
        }
    }
    foreach ($cabletable as $cable) {
        echo '<tr>';
        echo '<td>';
        echo $cable['cableid'];
        echo '</td><td>';
        echo $cable['device1'];
        echo '</td><td>';
        echo $cable['port1'];
        echo '</td><td>';
        echo $cable['type1'];
        echo '</td><td>';
        echo $cable['device2'];
        echo '</td><td>';
        echo $cable['port2'];
        echo '</td><td>';
        echo $allporttypes[$cable['port2id']];
        echo '</td>';
        echo '</tr>';
        echo "\n";
    }
    echo '</tbody></table><br/><br/>';
    echo 'ok-cablereport version 3.2';
    echo '</div>';
}
function renderCustomReport()
{
    # Get object list
    $phys_typelist = readChapter(CHAP_OBJTYPE, 'o');
    $attibutes = getAttrMap();
    $aTagList = getTagList();
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['csv'])) {
        header('Content-type: text/csv');
        header('Content-Disposition: attachment; filename=export_' . date("Ymdhis") . '.csv');
        header('Pragma: no-cache');
        header('Expires: 0');
        $outstream = fopen("php://output", "w");
        $aResult = getResult($_POST);
        // Get Result
        $_POST['name'] = validateColums($_POST);
        // Fix empty colums
        $csvDelimiter = isset($_POST['csvDelimiter']) ? $_POST['csvDelimiter'] : ',';
        /* Create Header */
        $aCSVRow = array();
        if (isset($_POST['sName']) && $_POST['sName']) {
            array_push($aCSVRow, "Name");
        }
        if (isset($_POST['label'])) {
            array_push($aCSVRow, "Label");
        }
        if (isset($_POST['type'])) {
            array_push($aCSVRow, "Type");
        }
        if (isset($_POST['asset_no'])) {
            array_push($aCSVRow, "Asset Tag");
        }
        if (isset($_POST['has_problems'])) {
            array_push($aCSVRow, "Has Problems");
        }
        if (isset($_POST['comment'])) {
            array_push($aCSVRow, "Comment");
        }
        if (isset($_POST['runs8021Q'])) {
            array_push($aCSVRow, "Runs 8021Q");
        }
        if (isset($_POST['location'])) {
            array_push($aCSVRow, "Location");
        }
        if (isset($_POST['MACs'])) {
            array_push($aCSVRow, "MACs");
        }
        if (isset($_POST['IPs'])) {
            array_push($aCSVRow, "IPs");
        }
        if (isset($_POST['attributeIDs'])) {
            foreach ($_POST['attributeIDs'] as $attributeID) {
                array_push($aCSVRow, $attibutes[$attributeID]['name']);
            }
        }
        if (isset($_POST['Tags'])) {
            array_push($aCSVRow, "Tags");
        }
        if (isset($_POST['Ports'])) {
            array_push($aCSVRow, "Ports");
        }
        if (isset($_POST['Containers'])) {
            array_push($aCSVRow, "Containers");
        }
        if (isset($_POST['Childs'])) {
            array_push($aCSVRow, "Child objects");
        }
        fputcsv($outstream, $aCSVRow, $csvDelimiter);
        /* Create data rows */
        foreach ($aResult as $Result) {
            $aCSVRow = array();
            if (isset($_POST['sName'])) {
                array_push($aCSVRow, $Result['name']);
            }
            if (isset($_POST['label'])) {
                array_push($aCSVRow, $Result['label']);
            }
            if (isset($_POST['type'])) {
                array_push($aCSVRow, $phys_typelist[$Result['objtype_id']]);
            }
            if (isset($_POST['asset_no'])) {
                array_push($aCSVRow, $Result['asset_no']);
            }
            if (isset($_POST['has_problems'])) {
                array_push($aCSVRow, $Result['has_problems']);
            }
            if (isset($_POST['comment'])) {
                array_push($aCSVRow, str_replace('&quot;', "'", $Result['comment']));
            }
            if (isset($_POST['runs8021Q'])) {
                array_push($aCSVRow, $Result['runs8021Q']);
            }
            if (isset($_POST['location'])) {
                array_push($aCSVRow, preg_replace('/<a[^>]*>(.*)<\\/a>/iU', '$1', getLocation($Result)));
            }
            if (isset($_POST['MACs'])) {
                $sTemp = '';
                foreach (getObjectPortsAndLinks($Result['id']) as $portNumber => $aPortDetails) {
                    if (trim($aPortDetails['l2address']) != '') {
                        $sTemp .= $aPortDetails['l2address'] . ' ';
                    }
                }
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['IPs'])) {
                $sTemp = '';
                foreach (getObjectIPv4AllocationList($Result['id']) as $key => $aDetails) {
                    if (function_exists('ip4_format')) {
                        $key = ip4_format($key);
                    }
                    if (trim($key) != '') {
                        $sTemp .= $key . ' ';
                    }
                }
                foreach (getObjectIPv6AllocationList($Result['id']) as $key => $aDetails) {
                    if (function_exists('ip6_format')) {
                        $key = ip6_format($key);
                    } else {
                        $key = new IPv6Address($key);
                    }
                    if (trim($key) != '') {
                        $sTemp .= $key . ' ';
                    }
                }
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['attributeIDs'])) {
                $attributes = getAttrValues($Result['id']);
                foreach ($_POST['attributeIDs'] as $attributeID) {
                    if (isset($attributes[$attributeID]['a_value'])) {
                        array_push($aCSVRow, $attributes[$attributeID]['a_value']);
                    } elseif ($attributes[$attributeID]['value'] != '' && $attributes[$attributeID]['type'] == 'date') {
                        array_push($aCSVRow, date("Y-m-d", $attributes[$attributeID]['value']));
                    } else {
                        array_push($aCSVRow, '');
                    }
                }
            }
            if (isset($_POST['Tags'])) {
                $sTemp = '';
                foreach ($Result['tags'] as $aTag) {
                    $sTemp .= $aTag['tag'] . ' ';
                }
                if (count($Result['itags']) > 0) {
                    $sTemp .= '(';
                    foreach ($Result['itags'] as $aTag) {
                        $sTemp .= $aTag['tag'] . ' ';
                    }
                    $sTemp .= ')';
                }
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['Ports'])) {
                $sTemp = '';
                foreach ($Result['portsLinks'] as $port) {
                    $sTemp .= $port['name'] . ': ' . $port['remote_object_name'];
                    if (trim($port['cableid']) != '') {
                        $sTemp .= ' Cable ID: ' . $port['cableid'];
                    }
                    $sTemp .= ' ';
                }
                $sTemp = trim($sTemp);
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['Containers'])) {
                $sTemp = '';
                foreach (getObjectContainerList($Result['id']) as $key => $aDetails) {
                    $sTemp .= trim($aDetails['container_name']) . ' ';
                }
                $sTemp = trim($sTemp);
                array_push($aCSVRow, $sTemp);
            }
            if (isset($_POST['Childs'])) {
                $sTemp = '';
                foreach (getObjectChildObjectList($Result['id']) as $key => $aDetails) {
                    $sTemp .= trim($aDetails['object_name']) . ' ';
                }
                $sTemp = trim($sTemp);
                array_push($aCSVRow, $sTemp);
            }
            fputcsv($outstream, $aCSVRow, $csvDelimiter);
        }
        fclose($outstream);
        exit(0);
        # Exit normally after send CSV to browser
    }
    echo '<h2>Custom report</h2><ul>';
    // Load stylesheet and jquery scripts
    addCSS('css/extensions/style.css');
    addJS('js/extensions/saveFormValues.js');
    addJS('js/extensions/jquery-latest.js');
    addJS('js/extensions/jquery.tablesorter.js');
    addJS('js/extensions/picnet.table.filter.min.js');
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        echo '<a href="#" class="show_hide">Show/hide search form</a><br/><br/>';
    }
    echo '<div class="searchForm">';
    echo '<form method="post" name="searchForm">';
    echo '<table class="searchTable">
            <tr>
              <th>Object Type</th>
              <th>Common Values</th>
              <th>Attributes</th>
              <th>Tags</th>
              <th>Misc</th>
            </tr>
            <tr>';
    echo '<td valign="top">
             <table class="searchTable">';
    $i = 0;
    foreach ($phys_typelist as $objectTypeID => $sName) {
        if ($i % 2) {
            echo '<tr class="odd">';
        } else {
            echo '<tr>';
        }
        echo '  <td>
                   <input type="checkbox" name="objectIDs[]" value="' . $objectTypeID . '"';
        if (isset($_POST['objectIDs']) && in_array($objectTypeID, $_POST['objectIDs'])) {
            echo ' checked="checked"';
        }
        echo '     > ' . $sName . '
                 </td>
               </tr>';
        $i++;
    }
    echo '  </table>
           </td>';
    echo '<td valign="top">
           <table class="searchTable">
             <tr><td><input type="checkbox" name="sName" value="1" ';
    if (isset($_POST['sName'])) {
        echo ' checked="checked"';
    }
    echo '> Name</td></tr>
             <tr class="odd"><td><input type="checkbox" name="label" value="1" ';
    if (isset($_POST['label'])) {
        echo ' checked="checked"';
    }
    echo '> Label</td></tr>
             <tr><td><input type="checkbox" name="type" value="1" ';
    if (isset($_POST['type'])) {
        echo ' checked="checked"';
    }
    echo '> Type</td></tr>
             <tr class="odd"><td><input type="checkbox" name="asset_no" value="1" ';
    if (isset($_POST['asset_no'])) {
        echo ' checked="checked"';
    }
    echo '> Asset Tag</td></tr>
             <tr><td><input type="checkbox" name="location" value="1" ';
    if (isset($_POST['location'])) {
        echo ' checked="checked"';
    }
    echo '> Location</td></tr>
             <tr class="odd"><td><input type="checkbox" name="has_problems" value="1" ';
    if (isset($_POST['has_problems'])) {
        echo ' checked="checked"';
    }
    echo '> Has Problems</td></tr>
             <tr><td><input type="checkbox" name="comment" value="1" ';
    if (isset($_POST['comment'])) {
        echo ' checked="checked"';
    }
    echo '> Comment</td></tr>
             <tr class="odd"><td><input type="checkbox" name="runs8021Q" value="1" ';
    if (isset($_POST['runs8021Q'])) {
        echo ' checked="checked"';
    }
    echo '> Runs 8021Q</td></tr>
             <tr><td><input type="checkbox" name="MACs" value="1" ';
    if (isset($_POST['MACs'])) {
        echo ' checked="checked"';
    }
    echo '> MACs</td></tr>
             <tr class="odd"><td><input type="checkbox" name="IPs" value="1" ';
    if (isset($_POST['IPs'])) {
        echo ' checked="checked"';
    }
    echo '> IPs</td></tr>
             <tr><td><input type="checkbox" name="Tags" value="1" ';
    if (isset($_POST['Tags'])) {
        echo ' checked="checked"';
    }
    echo '> Tags</td></tr>
             <tr class="odd"><td><input type="checkbox" name="Ports" value="1" ';
    if (isset($_POST['Ports'])) {
        echo ' checked="checked"';
    }
    echo '> Ports</td></tr>
             <tr><td><input type="checkbox" name="Containers" value="1" ';
    if (isset($_POST['Containers'])) {
        echo ' checked="checked"';
    }
    echo '> Containers</td></tr>
             <tr class="odd"><td><input type="checkbox" name="Childs" value="1" ';
    if (isset($_POST['Childs'])) {
        echo ' checked="checked"';
    }
    echo '> Child objects</td></tr>
           </table>
         </td>';
    echo '<td valign="top">
             <table class="searchTable">';
    $i = 0;
    foreach ($attibutes as $attributeID => $aRow) {
        if ($i % 2) {
            echo '<tr class="odd">';
        } else {
            echo '<tr>';
        }
        echo ' <td>
                <input type="checkbox" name="attributeIDs[]" value="' . $attributeID . '"';
        if (isset($_POST['attributeIDs']) && in_array($attributeID, $_POST['attributeIDs'])) {
            echo ' checked="checked"';
        }
        echo '> ' . $aRow['name'] . '
              </td>
             </tr>';
        $i++;
    }
    echo '  </table>
           </td>';
    echo '<td valign="top">
            <table class="searchTable">';
    $i = 0;
    foreach ($aTagList as $aTag) {
        echo '<tr ' . ($i % 2 ? 'class="odd"' : '') . '>
                <td>
                  <input type="checkbox" name="tag[' . $aTag['id'] . ']" value="1" ' . (isset($_POST['tag'][$aTag['id']]) ? 'checked="checked" ' : '') . '> ' . $aTag['tag'] . '
                </td>
              </tr>';
        $i++;
    }
    if (count($aTagList) < 1) {
        echo '<tr><td><i>No Tags available</i></td></tr>';
    }
    echo '  </table>
          </td>';
    echo '<td valign="top">
            <table class="searchTable">
              <tr><td><input type="checkbox" name="csv" value="1"> CSV Export</td></tr>
              <tr><td><input type="text" name="csvDelimiter" value="," size="1"> CSV Delimiter</td></tr>
              <tr class="odd"><td>Name Filter: <i>(Regular Expression)</i></td></tr>
              <tr><td><input type="text" name="name_preg" value="';
    if (isset($_POST['name_preg'])) {
        echo $_POST['name_preg'];
    }
    echo '" style="height: 11pt;"></td></tr>
              <tr class="odd"><td>Asset Tag Filter: <i>(Regular Expression)</i></td></tr>
              <tr><td><input type="text" name="tag_preg" value="';
    if (isset($_POST['tag_preg'])) {
        echo $_POST['tag_preg'];
    }
    echo '" style="height: 11pt;"></td></tr>
              <tr class="odd"><td>Comment Filter: <i>(Regular Expression)</i></td></tr>
              <tr><td><input type="text" name="comment_preg" value="';
    if (isset($_POST['comment_preg'])) {
        echo $_POST['comment_preg'];
    }
    echo '" style="height: 11pt;"></td></tr>
              <tr class="odd"><td>&nbsp;</td></tr>
              <tr>
                <td>
                  Save:
                  <input id="nameQuery" type="text" name="nameQuery" value="" style="height: 11pt; width:155px"/> <input type="button" value=" Ok " onclick="saveQuery();">
                  <br/>
                  Load:<br/>
                   <span id="loadButtons"></span>
                   <script type="text/javascript">
                     loadButtons();
                   </script>
                </td>
              </tr>
              <tr class="odd"><td>&nbsp;</td></tr>
              <tr><td align="right"><input type="submit" value=" Search "></td></tr>
            </table>
          </td>
        </tr>
      </table>';
    echo '</form>';
    echo '</div>';
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $aResult = getResult($_POST);
        // Get Result
        $_POST['sName'] = validateColums($_POST);
        // Fix empty colums
        if (count($aResult) > 0) {
            echo '<table  id="customTable" class="tablesorter">
               <thead>
                 <tr>';
            if (isset($_POST['sName']) && $_POST['sName']) {
                echo '<th>Name</th>';
            }
            if (isset($_POST['label'])) {
                echo '<th>Label</th>';
            }
            if (isset($_POST['type'])) {
                echo '<th>Type</th>';
            }
            if (isset($_POST['asset_no'])) {
                echo '<th>Asset Tag</th>';
            }
            if (isset($_POST['has_problems'])) {
                echo '<th>Has Problems</th>';
            }
            if (isset($_POST['comment'])) {
                echo '<th>Comment</th>';
            }
            if (isset($_POST['runs8021Q'])) {
                echo '<th>Runs 8021Q</th>';
            }
            if (isset($_POST['location'])) {
                echo '<th>Location</th>';
            }
            if (isset($_POST['MACs'])) {
                echo '<th>MACs</th>';
            }
            if (isset($_POST['IPs'])) {
                echo '<th>IPs</th>';
            }
            if (isset($_POST['attributeIDs'])) {
                foreach ($_POST['attributeIDs'] as $attributeID) {
                    echo '<th>' . $attibutes[$attributeID]['name'] . '</th>';
                }
            }
            if (isset($_POST['Tags'])) {
                echo '<th>Tags</th>';
            }
            if (isset($_POST['Ports'])) {
                echo '<th>Ports</th>';
            }
            if (isset($_POST['Containers'])) {
                echo '<th>Containers</th>';
            }
            if (isset($_POST['Childs'])) {
                echo '<th>Child objects</th>';
            }
            echo '  </tr>
              </thead>
              <tbody>';
            foreach ($aResult as $Result) {
                echo '<tr>';
                if (isset($_POST['sName'])) {
                    echo '<td>
                        <span class="object_' . str_replace('$', '', $Result['atags'][1]['tag']) . '">';
                    if (isset($Result['name'])) {
                        echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $Result['id'])) . '">' . $Result['name'] . '</a>';
                    } else {
                        echo '&nbsp;';
                    }
                    echo '  </span>
                       </td>';
                }
                if (isset($_POST['label'])) {
                    echo '<td>';
                    if (isset($Result['label'])) {
                        echo $Result['label'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['type'])) {
                    echo '<td>';
                    if (isset($Result['objtype_id'])) {
                        echo $phys_typelist[$Result['objtype_id']];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['asset_no'])) {
                    echo '<td>';
                    if (isset($Result['asset_no'])) {
                        echo $Result['asset_no'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['has_problems'])) {
                    echo '<td>';
                    if (isset($Result['has_problems'])) {
                        echo $Result['has_problems'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['comment'])) {
                    echo '<td>';
                    if (isset($Result['comment'])) {
                        echo makeLinksInText($Result['comment']);
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['runs8021Q'])) {
                    echo '<td>';
                    if (isset($Result['runs8021Q'])) {
                        echo $Result['runs8021Q'];
                    } else {
                        echo '&nbsp;';
                    }
                    echo '</td>';
                }
                if (isset($_POST['location'])) {
                    echo '<td>';
                    echo getLocation($Result);
                    echo '</td>';
                }
                if (isset($_POST['MACs'])) {
                    echo '<td>';
                    foreach (getObjectPortsAndLinks($Result['id']) as $portNumber => $aPortDetails) {
                        if (trim($aPortDetails['l2address']) != '') {
                            echo $aPortDetails['l2address'] . '<br/>';
                        }
                    }
                    echo '</td>';
                }
                if (isset($_POST['IPs'])) {
                    echo '<td>';
                    foreach (getObjectIPv4AllocationList($Result['id']) as $key => $aDetails) {
                        if (function_exists('ip4_format')) {
                            $key = ip4_format($key);
                        }
                        if (trim($key) != '') {
                            echo $key . '<br/>';
                        }
                    }
                    foreach (getObjectIPv6AllocationList($Result['id']) as $key => $aDetails) {
                        if (function_exists('ip6_format')) {
                            $key = ip6_format($key);
                        } else {
                            $key = new IPv6Address($key);
                        }
                        if (trim($key) != '') {
                            echo $key . '<br/>';
                        }
                    }
                    echo '</td>';
                }
                if (isset($_POST['attributeIDs'])) {
                    $attributes = getAttrValues($Result['id']);
                    foreach ($_POST['attributeIDs'] as $attributeID) {
                        echo '<td>';
                        if (isset($attributes[$attributeID]['a_value']) && $attributes[$attributeID]['a_value'] != '') {
                            echo $attributes[$attributeID]['a_value'];
                        } elseif ($attributes[$attributeID]['value'] != '' && $attributes[$attributeID]['type'] == 'date') {
                            echo date("Y-m-d", $attributes[$attributeID]['value']);
                        } else {
                            echo '&nbsp;';
                        }
                    }
                }
                if (isset($_POST['Tags'])) {
                    echo '<td>';
                    foreach ($Result['tags'] as $aTag) {
                        echo '<a href="' . makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cft[]' => $aTag['id'])) . '">' . $aTag['tag'] . '</a> ';
                    }
                    if (count($Result['itags']) > 0) {
                        echo '(';
                        foreach ($Result['itags'] as $aTag) {
                            echo '<a href="' . makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cft[]' => $aTag['id'])) . '">' . $aTag['tag'] . '</a> ';
                        }
                        echo ')';
                    }
                    echo '</td>';
                }
                if (isset($_POST['Ports'])) {
                    echo '<td>';
                    foreach ($Result['portsLinks'] as $port) {
                        echo $port['name'] . ': ';
                        if ($port['remote_object_name'] != 'unknown') {
                            echo formatPortLink($port['remote_object_id'], $port['remote_object_name'], $port['remote_id'], NULL);
                        } else {
                            echo $port['remote_object_name'];
                        }
                        if (trim($port['cableid']) != '') {
                            echo ' Cable ID: ' . $port['cableid'];
                        }
                        echo '<br/>';
                    }
                    echo '</td>';
                }
                if (isset($_POST['Containers'])) {
                    echo '<td>';
                    foreach (getObjectContainerList($Result['id']) as $key => $aDetails) {
                        echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $key)) . '">' . $aDetails['container_name'] . '</a><br/>';
                    }
                    echo '</td>';
                }
                if (isset($_POST['Childs'])) {
                    echo '<td>';
                    foreach (getObjectChildObjectList($Result['id']) as $key => $aDetails) {
                        echo '<a href="' . makeHref(array('page' => 'object', 'object_id' => $key)) . '">' . $aDetails['object_name'] . '</a><br/>';
                    }
                    echo '</td>';
                }
                echo '</tr>';
            }
            echo '  </tbody>
              </table>
              <script type="text/javascript">$(".searchForm").hide();</script>';
        } else {
            echo '<br/><br/><div align="center" style="font-size:10pt;"><i>No items found !!!</i></div><br/>';
        }
        echo '<script type="text/javascript">
               $(document).ready(function()
                 {
                   $.tablesorter.defaults.widgets = ["zebra"];
                   $("#customTable").tablesorter(
                     { headers: {
                     }, sortList: [[0,0]] }
                   );
                   $("#customTable").tableFilter();

                   $(".show_hide").show();

                   $(".show_hide").click(function(){
                     $(".searchForm").slideToggle(\'slow\');
                   });

                 }
                 );
            </script>';
    }
}
function linkmgmt_renderPopupPortSelectorbyName()
{
    $linktype = $_REQUEST['linktype'];
    $object_id = $_REQUEST['object_id'];
    $object = spotEntity('object', $object_id);
    $objectlist = linkmgmt_findSparePorts(NULL, NULL, $linktype, false, true, TRUE, false, $object_id);
    $objectname = $object['dname'];
    /* remove self from list */
    unset($objectlist[$object_id]);
    if (isset($_REQUEST['remote_object'])) {
        $remote_object = $_REQUEST['remote_object'];
    } else {
        /* choose first object from list */
        $keys = array_keys($objectlist);
        if (isset($keys[0])) {
            $remote_object = $keys[0];
        } else {
            $remote_object = NULL;
        }
    }
    if ($remote_object) {
        $filter['object_id'] = $remote_object;
        $link_list = linkmgmt_findSparePorts(NULL, $filter, $linktype, false, false, TRUE, false, $object_id);
    } else {
        $link_list = linkmgmt_findSparePorts(NULL, NULL, $linktype, false, false, TRUE, false, $object_id);
    }
    // display search form
    echo 'Link ' . $linktype . ' of ' . formatPortLink($object_id, $objectname, NULL, NULL) . ' Ports by Name to...';
    echo '<form method=POST>';
    echo '<table align="center"><tr><td>';
    startPortlet('Object list');
    $maxsize = getConfigVar('MAXSELSIZE');
    $objectcount = count($objectlist);
    echo 'Object name (count ports)<br>';
    echo getSelect($objectlist, array('name' => 'remote_object', 'size' => $objectcount <= $maxsize ? $objectcount : $maxsize), $remote_object, FALSE);
    echo '</td><td><input type=submit value="show ' . $linktype . ' ports>"></td>';
    finishPortlet();
    echo '<td>';
    // display results
    startPortlet('Possible Backend Link List');
    echo "Select links to create:<br>";
    if (empty($link_list)) {
        echo '(nothing found)';
    } else {
        $linkcount = count($link_list);
        $options = array('name' => 'link_list[]', 'size' => $linkcount <= $maxsize ? $linkcount : $maxsize, 'multiple' => 'multiple');
        echo getSelect($link_list, $options, NULL, FALSE);
        echo "<p>{$linktype} Cable ID: <input type=text id=cable name=cable>";
        echo "<p><input type='submit' value='Link {$linktype}' name='do_link'>";
    }
    finishPortlet();
    echo '</td></tr></table>';
    echo '</form>';
}
function copyLotOfObjects()
{
    global $dbxlink;
    $dbrollback = 0;
    if (!$dbxlink->beginTransaction()) {
        throw new RTDatabaseError("can not start transaction");
    }
    // do we need this ?
    $log = emptyLog();
    $taglist = isset($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
    assertUIntArg('global_type_id', TRUE);
    assertStringArg('namelist', TRUE);
    $global_type_id = $_REQUEST['global_type_id'];
    $source_object_id = $_REQUEST['object_id'];
    $source_object = spotEntity('object', $source_object_id);
    amplifyCell($source_object);
    // only call amplifyCell_object_Backend_Port if we have function linkmgmt_linkPorts from linkmgmt.php
    if (function_exists('amplifyCell_object_Backend_Port') && function_exists('linkmgmt_linkPorts')) {
        amplifyCell_object_Backend_Port($source_object);
    }
    if ($global_type_id == 0 or !strlen($_REQUEST['namelist'])) {
        // Log something reasonable with showError Here
        // We do not have names to copy our object to !
        // Pls check what makes $global_type_id == 0  an error
        $log = mergeLogs($log, oneLiner(186));
        return;
    }
    // The name extractor below was stolen from ophandlers.php:addMultiPorts()
    $names1 = explode("\n", $_REQUEST['namelist']);
    $names2 = array();
    foreach ($names1 as $line) {
        $parts = explode('\\r', $line);
        reset($parts);
        if (!strlen($parts[0])) {
            continue;
        } else {
            $names2[] = rtrim($parts[0]);
        }
    }
    foreach ($names2 as $name_or_csv) {
        $label = '';
        $asset_no = '';
        $object_name = '';
        $regexp = '/^\\"([^\\"]*)\\","([^\\"]*)\\","([^\\"]*)\\"/';
        $object_name_or_csv = htmlspecialchars_decode($name_or_csv, ENT_QUOTES);
        // error_log( "$regexp $object_name" );
        if (preg_match($regexp, $object_name_or_csv, $matches)) {
            $object_name = $matches[1];
            $label = $matches[2];
            $asset_no = $matches[3];
        } else {
            $object_name = $name_or_csv;
        }
        try {
            $object_id = commitAddObject($object_name, $label, $global_type_id, $asset_no, $taglist);
            if (!$object_id) {
                throw new RTDatabaseError("could not create {$object_name}");
            }
            $info = spotEntity('object', $object_id);
            amplifyCell($info);
            foreach ($source_object['ports'] as $source_port) {
                $update_port = 0;
                foreach ($info['ports'] as $new_port) {
                    if ($new_port['name'] == $source_port['name']) {
                        commitUpdatePort($object_id, $new_port['id'], $new_port['name'], $new_port['oif_id'], $source_port['label'], "");
                        $update_port = 1;
                    }
                }
                if ($update_port) {
                    true;
                } else {
                    commitAddPort($object_id, $source_port['name'], sprintf("%s-%s", $source_port['iif_id'], $source_port['oif_id']), $source_port['label'], "");
                }
            }
            // Copy Backendlinks only start if we ghave function linkmgmt_linkPorts from linkmgmt.php
            if (function_exists('amplifyCell_object_Backend_Port') && function_exists('linkmgmt_linkPorts')) {
                $info = spotEntity('object', $object_id);
                amplifyCell($info);
                amplifyCell_object_Backend_Port($info);
                /*	 showError( '<div align="left"><pre>\n===== Source Object ======\n\n' .
                				 		 varDumpToString ( $source_object ) .
                						'\n\n===== New Object ======\n\n' .
                						 varDumpToString ( $info )  .  '</pre></div>' );
                			*/
                $name_by_id = array();
                foreach ($info['BackendPorts'] as $new_be_port) {
                    $name_by_id[$new_be_port['name']] = $new_be_port['id'];
                }
                $linked_ports = array();
                foreach ($source_object['BackendPorts'] as $source_be_port) {
                    if ($source_be_port['object_id'] == $source_be_port['remote_object_id']) {
                        // We have a Port that has the own object as remote object we want to copy this type of Linko
                        // We have backend Links
                        $new_be_port_a = $name_by_id[$source_be_port['name']];
                        $new_be_port_b = $name_by_id[$source_be_port['remote_name']];
                        if ($new_be_port_a && $new_be_port_b && !array_key_exists($new_be_port_a, $linked_ports) && !array_key_exists($new_be_port_b, $linked_ports)) {
                            // error_log ( sprintf ('new_be_port_a %s // new_be_port_b %s // cableid %s', $new_be_port_a  , $new_be_port_b, $source_be_port['cableid'] ));
                            $ret_val = linkmgmt_linkPorts($new_be_port_a, $new_be_port_b, 'back', $source_be_port['cableid']);
                            // error_log ( sprintf (' linkmgmt_linkPorts ret val: "%s" ', $ret_val)) ;
                            if ($ret_val) {
                                throw new RTDatabaseError("could not copy Backend Links for {$object_name} because: {$ret_val}");
                            } else {
                                $linked_ports[$new_be_port_a] = True;
                                $linked_ports[$new_be_port_b] = True;
                            }
                        }
                    }
                }
            }
            // Copy attributes
            foreach (getAttrValues($source_object_id) as $record) {
                $value = $record['value'];
                switch ($record['type']) {
                    case 'uint':
                    case 'float':
                    case 'string':
                        $value = $record['value'];
                        break;
                    case 'dict':
                        $value = $record['key'];
                        break;
                    default:
                }
                if (permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id'])))) {
                    if (empty($value)) {
                        commitUpdateAttrValue($object_id, $record['id']);
                    } else {
                        commitUpdateAttrValue($object_id, $record['id'], $value);
                    }
                } else {
                    showError('Permission denied, "' . $record['name'] . '" can not be set');
                }
            }
            //$log = mergeLogs ($log, oneLiner (5, array ('<a href="' .
            //	makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) .
            //	'">' . $info['dname'] . '</a>'))
            //);
            showSuccess(sprintf("Copied Object %s ; new Object: %s", $source_object['name'], formatPortLink($object_id, $info['dname'], 1, '', '')));
        } catch (RTDatabaseError $e) {
            error_log("rolling back DB");
            $dbrollback = 1;
            $dbxlink->rollBack();
            $log = mergeLogs($log, oneLiner(147, array($object_name)));
            throw new RTDatabaseError($e->getMessage() . sprintf(' (%s)', $name_or_csv));
        }
    }
    if (!$dbrollback) {
        $dbxlink->commit();
    }
    // return buildWideRedirectURL ($log);
}
Exemple #8
0
function formatLinkedPort($port_info, $a_class = '')
{
    return formatPortLink($port_info['remote_object_id'], $port_info['remote_object_name'], $port_info['remote_id'], $port_info['remote_name'], $a_class);
}