Beispiel #1
0
function renderCell($cell)
{
    switch ($cell['realm']) {
        case 'user':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            printImageHREF('USER');
            echo '</td><td>' . mkA($cell['user_name'], 'user', $cell['user_id']) . '</td></tr>';
            if (strlen($cell['user_realname'])) {
                echo "<tr><td><strong>" . niftyString($cell['user_realname']) . "</strong></td></tr>";
            } else {
                echo "<tr><td class=sparenetwork>no name</td></tr>";
            }
            echo '<td>';
            if (!isset($cell['etags'])) {
                $cell['etags'] = getExplicitTagsOnly(loadEntityTags('user', $cell['user_id']));
            }
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        case 'file':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            switch ($cell['type']) {
                case 'text/plain':
                    printImageHREF('text file');
                    break;
                case 'image/jpeg':
                case 'image/png':
                case 'image/gif':
                    printImageHREF('image file');
                    break;
                default:
                    printImageHREF('empty file');
                    break;
            }
            echo "</td><td>";
            echo mkA('<strong>' . niftyString($cell['name']) . '</strong>', 'file', $cell['id']);
            echo "</td><td rowspan=3 valign=top>";
            if (isset($cell['links']) and count($cell['links'])) {
                printf("<small>%s</small>", serializeFileLinks($cell['links']));
            }
            echo "</td></tr><tr><td>";
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo '</td></tr><tr><td>';
            if (isolatedPermission('file', 'download', $cell)) {
                // FIXME: reuse renderFileDownloader()
                echo "<a href='?module=download&file_id={$cell['id']}'>";
                printImageHREF('download', 'Download file');
                echo '</a>&nbsp;';
            }
            echo formatFileSize($cell['size']);
            echo "</td></tr></table>";
            break;
        case 'ipv4vs':
        case 'ipvs':
        case 'ipv4rspool':
            renderSLBEntityCell($cell);
            break;
        case 'ipv4net':
        case 'ipv6net':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            printImageHREF('NET');
            echo '</td><td>' . mkA("{$cell['ip']}/{$cell['mask']}", $cell['realm'], $cell['id']);
            echo getRenderedIPNetCapacity($cell);
            echo '</td></tr>';
            echo "<tr><td>";
            if (strlen($cell['name'])) {
                echo "<strong>" . niftyString($cell['name']) . "</strong>";
            } else {
                echo "<span class=sparenetwork>no name</span>";
            }
            // render VLAN
            renderNetVLAN($cell);
            echo "</td></tr>";
            echo '<tr><td>';
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        case 'rack':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            $thumbwidth = getRackImageWidth();
            $thumbheight = getRackImageHeight($cell['height']);
            echo "<img border=0 width={$thumbwidth} height={$thumbheight} title='{$cell['height']} units' ";
            echo "src='?module=image&img=minirack&rack_id={$cell['id']}'>";
            echo "</td><td>";
            echo mkA('<strong>' . niftyString($cell['name']) . '</strong>', 'rack', $cell['id']);
            echo "</td></tr><tr><td>";
            echo niftyString($cell['comment']);
            echo "</td></tr><tr><td>";
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        case 'location':
            echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
            printImageHREF('LOCATION');
            echo "</td><td>";
            echo mkA('<strong>' . niftyString($cell['name']) . '</strong>', 'location', $cell['id']);
            echo "</td></tr><tr><td>";
            echo niftyString($cell['comment']);
            echo "</td></tr><tr><td>";
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        case 'object':
            echo "<table class='slbcell vscell'><tr><td rowspan=2 width='5%'>";
            printImageHREF('OBJECT');
            echo '</td><td>';
            echo mkA('<strong>' . niftyString($cell['dname']) . '</strong>', 'object', $cell['id']);
            echo '</td></tr><tr><td>';
            echo count($cell['etags']) ? "<small>" . serializeTags($cell['etags']) . "</small>" : '&nbsp;';
            echo "</td></tr></table>";
            break;
        default:
            throw new InvalidArgException('realm', $cell['realm']);
    }
}
Beispiel #2
0
function rebuildTagChainForEntity($realm, $entity_id, $extrachain = array(), $replace = FALSE)
{
    // Put the current explicit sub-chain into a buffer and merge all tags from
    // the extra chain, which aren't there yet.
    $oldchain = array();
    $newchain = array();
    foreach (loadEntityTags($realm, $entity_id) as $oldtag) {
        $oldchain[$oldtag['id']] = $oldtag;
    }
    $tmpchain = $replace ? array() : $oldchain;
    foreach ($extrachain as $extratag) {
        $tmpchain[$extratag['id']] = $extratag;
    }
    // minimize the working buffer
    foreach (getExplicitTagsOnly($tmpchain) as $taginfo) {
        $newchain[$taginfo['id']] = $taginfo;
    }
    $result = FALSE;
    foreach (array_diff(array_keys($oldchain), array_keys($newchain)) as $tag_id) {
        deleteTagForEntity($realm, $entity_id, $tag_id);
        $result = TRUE;
    }
    foreach (array_diff(array_keys($newchain), array_keys($oldchain)) as $tag_id) {
        addTagForEntity($realm, $entity_id, $tag_id);
        $result = TRUE;
    }
    return $result;
}
/**
 * getResult Function
 *
 * Call Racktables API to get Objects and filter the result if required
 *
 * @param array $post
 * @return array Result
 */
function getResult($post)
{
    $sFilter = '';
    if (isset($post['objectIDs'])) {
        foreach ($post['objectIDs'] as $sFilterValue) {
            $sFilter .= '{$typeid_' . $sFilterValue . '} or ';
        }
        $sFilter = substr($sFilter, 0, -4);
        $sFilter = '(' . $sFilter . ')';
    }
    $aResult = scanRealmByText('object', $sFilter);
    // Add tags
    $aTemp = array();
    foreach ($aResult as $Result) {
        $Result['tags'] = loadEntityTags('object', $Result['id']);
        $Result['itags'] = getImplicitTags($Result['tags']);
        array_push($aTemp, $Result);
    }
    $aResult = $aTemp;
    // Search / Filter by name
    if (isset($post['name_preg']) && $post['name_preg'] != '') {
        $aTemp = array();
        foreach ($aResult as $Result) {
            if (preg_match('/' . $post['name_preg'] . '/', $Result['name'])) {
                array_push($aTemp, $Result);
            }
        }
        $aResult = $aTemp;
    }
    // Search / Filter by tag
    if (isset($post['tag_preg']) && $post['tag_preg'] != '') {
        $aTemp = array();
        foreach ($aResult as $Result) {
            if (preg_match('/' . $post['tag_preg'] . '/', $Result['asset_no'])) {
                array_push($aTemp, $Result);
            }
        }
        $aResult = $aTemp;
    }
    // Search / Filter by comment
    if (isset($post['comment_preg']) && $post['comment_preg'] != '') {
        $aTemp = array();
        foreach ($aResult as $Result) {
            if (preg_match('/' . $post['comment_preg'] . '/', $Result['comment'])) {
                array_push($aTemp, $Result);
            }
        }
        $aResult = $aTemp;
    }
    // Tags
    if (isset($post['tag']) && count($post['tag']) > 0) {
        $aTemp = array();
        $aSearchTags = array_keys($post['tag']);
        foreach ($aResult as $Result) {
            foreach ($Result['tags'] as $aTag) {
                if (in_array($aTag['id'], $aSearchTags)) {
                    array_push($aTemp, $Result);
                }
            }
            foreach ($Result['itags'] as $aTag) {
                if (in_array($aTag['id'], $aSearchTags)) {
                    array_push($aTemp, $Result);
                }
            }
        }
        $aResult = $aTemp;
    }
    // Ports - Load port data if necessary
    if (isset($post['Ports'])) {
        $aTemp = array();
        foreach ($aResult as $Result) {
            $Result['portsLinks'] = getObjectPortsAndLinks($Result['id']);
            foreach ($Result['portsLinks'] as $i => $port) {
                $Result['portsLinks'][$i]['remote_object_name'] = 'unknown';
                if (!is_null($port['remote_object_id'])) {
                    $remote_object = spotEntity('object', intval($port['remote_object_id']));
                    $Result['portsLinks'][$i]['remote_object_name'] = $remote_object['name'];
                }
            }
            array_push($aTemp, $Result);
        }
        $aResult = $aTemp;
    }
    return $aResult;
}