Example #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']);
    }
}
function getWattsPerRow()
{
    // assertions
    // find the needed attributes
    global $nextorder;
    // Was this function called with a specific row_id?
    if (isset($_REQUEST['row_id'])) {
        assertStringArg('row_id');
        $row_toshow = $_REQUEST['row_id'];
    } else {
        $row_toshow = -1;
    }
    //from renderRackspace(), interface.php:151
    $found_racks = array();
    $rows = array();
    $cellfilter = getCellFilter();
    $rackCount = 0;
    $order = 'odd';
    // get rackspace information
    foreach (getAllRows() as $row_id => $rowInfo) {
        $rackList = filterCellList(listCells('rack', $row_id), $cellfilter['expression']);
        $found_racks = array_merge($found_racks, $rackList);
        $rows[] = array('location_id' => $rowInfo['location_id'], 'location_name' => $rowInfo['location_name'], 'row_id' => $row_id, 'row_name' => $rowInfo['name'], 'racks' => $rackList);
        $rackCount += count($rackList);
    }
    // Main layout starts.
    echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
    // Left portlet with list of rows.
    echo "<tr><td class=pcleft width='50%'>";
    startPortlet('Rack Rows (' . count($rows) . ')');
    echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
    foreach ($rows as $row) {
        $row_id = $row['row_id'];
        $row_name = $row['row_name'];
        $row_location = $row['location_name'];
        $rackList = $row['racks'];
        echo "<tr class=row_{$order}><td width='20%'></td><td class=tdleft>";
        if (!count($rackList)) {
            echo "{$row_location} - {$row_name} (empty row)";
        } else {
            echo "<a href='" . makeHref(array('page' => 'reports', 'tab' => 'watts_per_row', 'row_id' => $row_id)) . "'>{$row_location} - {$row_name}</a>";
        }
        echo "<td><tr>\n";
        $order = $nextorder[$order];
    }
    echo "</td></tr>\n";
    echo "</table><br>\n";
    finishPortlet();
    echo "</td><td class=pcright>";
    // Right Portlet: Draw the racks in the selected row
    if ($row_toshow > -1) {
        $rowInfo = getRowInfo($row_toshow);
        $cellfilter = getCellFilter();
        $rackList = filterCellList(listCells('rack', $row_toshow), $cellfilter['expression']);
        $rackwidth = getRackImageWidth() * getConfigVar('ROW_SCALE');
        // Maximum number of racks per row is proportionally less, but at least 1.
        $maxPerRow = max(floor(getConfigVar('RACKS_PER_ROW') / getConfigVar('ROW_SCALE')), 1);
        $rackListIdx = 0;
        $rowTotalWattage = 0;
        $order = 'odd';
        startPortlet('Racks within ' . $rowInfo['name'] . ' (' . count($rackList) . ')');
        echo "<table border=0 cellspacing=5 align='center'><tr>";
        foreach ($rackList as $rack) {
            $rackTotalWattage = 0;
            // see renderRack(), interface.php:311
            $rackData = spotEntity('rack', $rack['id']);
            amplifyCell($rackData);
            $objectChildren = getEntityRelatives('children', 'object', $objectData['id']);
            foreach ($rackData['mountedObjects'] as $object) {
                $objectData = spotEntity('object', $object);
                amplifyCell($objectData);
                foreach (getAttrValues($objectData['id']) as $record) {
                    if ($record['name'] == 'Wattage consumption') {
                        $rackTotalWattage += $record['value'];
                    }
                }
            }
            if ($rackListIdx % $maxPerRow == 0) {
                echo $rackListIdx > 0 ? '</tr><tr>' : '<tr>';
            }
            echo "<td align=center class=row_{$order}><a href='" . makeHref(array('page' => 'rack', 'rack_id' => $rack['id'])) . "'>";
            echo "<img border=0 width={$rackwidth} height=" . getRackImageHeight($rack['height']) * getConfigVar('ROW_SCALE');
            echo " title='{$rack['height']} units'";
            echo "src='?module=image&img=minirack&rack_id={$rack['id']}'>";
            echo "<br>{$rack['name']} ({$rackTotalWattage})</a></td>";
            $order = $nextorder[$order];
            $rackListIdx++;
            $rowTotalWattage += $rackTotalWattage;
        }
        echo "</tr><tr><td align=center colspan=";
        print count($rackList);
        echo "><br><b>The row total for attribute Wattage consuption is:  {$rowTotalWattage}</b></td>\n";
        echo "</tr></table>\n";
        finishPortlet();
    }
    echo "</td></tr></table>";
}