Example #1
0
function renderRackspace()
{
    // Handle the location filter
    @session_start();
    if (isset($_REQUEST['changeLocationFilter'])) {
        unset($_SESSION['locationFilter']);
    }
    if (isset($_REQUEST['location_id'])) {
        $_SESSION['locationFilter'] = $_REQUEST['location_id'];
    }
    if (!isset($_SESSION['locationFilter'])) {
        $_SESSION['locationFilter'] = array_keys(listCells('location'));
    }
    // Add all locations to the filter
    session_commit();
    $found_racks = array();
    $rows = array();
    $cellfilter = getCellFilter();
    $rackCount = 0;
    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);
    }
    echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
    if (!renderEmptyResults($cellfilter, 'racks', $rackCount)) {
        // generate thumb gallery
        global $nextorder;
        $rackwidth = getRackImageWidth();
        // Zero value effectively disables the limit.
        $maxPerRow = getConfigVar('RACKS_PER_ROW');
        $order = 'odd';
        if (count($rows)) {
            echo '<table border=0 cellpadding=10 class=cooltable>';
            echo '<tr><th class=tdleft>Location</th><th class=tdleft>Row</th><th class=tdleft>Racks</th></tr>';
            foreach ($rows as $row) {
                $location_id = $row['location_id'];
                $row_id = $row['row_id'];
                $row_name = $row['row_name'];
                $rackList = $row['racks'];
                if ($location_id != '' and !in_array($location_id, $_SESSION['locationFilter']) or !count($rackList) and count($cellfilter['expression'])) {
                    continue;
                }
                $rackListIdx = 0;
                echo "<tr class=row_{$order}><th class=tdleft>";
                if ($location_id) {
                    echo "<a href='" . makeHref(array('page' => 'location', 'location_id' => $location_id)) . "{$cellfilter['urlextra']}'>{$row['location_name']}</a>";
                }
                echo "</th><th class=tdleft><a href='" . makeHref(array('page' => 'row', 'row_id' => $row_id)) . "{$cellfilter['urlextra']}'>{$row_name}</a></th>";
                echo "<th class=tdleft><table border=0 cellspacing=5><tr>";
                if (!count($rackList)) {
                    echo "<td>(empty row)</td>";
                } else {
                    foreach ($rackList as $rack) {
                        if ($rackListIdx > 0 and $maxPerRow > 0 and $rackListIdx % $maxPerRow == 0) {
                            echo '</tr></table></th></tr>';
                            echo "<tr class=row_{$order}><th class=tdleft></th><th class=tdleft>{$row_name} (continued)";
                            echo "</th><th class=tdleft><table border=0 cellspacing=5><tr>";
                        }
                        echo "<td align=center valign=bottom><a href='" . makeHref(array('page' => 'rack', 'rack_id' => $rack['id'])) . "'>";
                        echo "<img border=0 width={$rackwidth} height=";
                        echo getRackImageHeight($rack['height']);
                        echo " title='{$rack['height']} units'";
                        echo "src='?module=image&img=minirack&rack_id={$rack['id']}'>";
                        echo "<br>{$rack['name']}</a></td>";
                        $rackListIdx++;
                    }
                }
                $order = $nextorder[$order];
                echo "</tr></table></th></tr>\n";
            }
            echo "</table>\n";
        } else {
            echo "<h2>No rows found</h2>\n";
        }
    }
    echo '</td><td class=pcright width="25%">';
    renderCellFilterPortlet($cellfilter, 'rack', $found_racks);
    echo "<br>\n";
    renderLocationFilterPortlet();
    echo "</td></tr></table>\n";
}
Example #2
0
function renderRackspace()
{
    // Handle the location filter
    @session_start();
    if (isset($_REQUEST['changeLocationFilter'])) {
        unset($_SESSION['locationFilter']);
    }
    if (isset($_REQUEST['location_id'])) {
        $_SESSION['locationFilter'] = $_REQUEST['location_id'];
    }
    session_commit();
    echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
    $found_racks = array();
    $cellfilter = getCellFilter();
    if (!($cellfilter['is_empty'] && !isset($_SESSION['locationFilter']) && renderEmptyResults($cellfilter, 'racks', getEntitiesCount('rack')))) {
        $rows = array();
        $rackCount = 0;
        foreach (getAllRows() as $row_id => $rowInfo) {
            $rackList = applyCellFilter('rack', $cellfilter, $row_id);
            $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);
        }
        if (!renderEmptyResults($cellfilter, 'racks', $rackCount)) {
            // generate thumb gallery
            global $nextorder;
            $rackwidth = getRackImageWidth();
            // Zero value effectively disables the limit.
            $maxPerRow = getConfigVar('RACKS_PER_ROW');
            $order = 'odd';
            if (!count($rows)) {
                echo "<h2>No rows found</h2>\n";
            } else {
                echo '<table border=0 cellpadding=10 class=cooltable>';
                echo '<tr><th class=tdleft>Location</th><th class=tdleft>Row</th><th class=tdleft>Racks</th></tr>';
                foreach ($rows as $row) {
                    $location_id = $row['location_id'];
                    $row_id = $row['row_id'];
                    $row_name = $row['row_name'];
                    $rackList = $row['racks'];
                    if ($location_id != '' and isset($_SESSION['locationFilter']) and !in_array($location_id, $_SESSION['locationFilter']) or empty($rackList) and !$cellfilter['is_empty']) {
                        continue;
                    }
                    $rackListIdx = 0;
                    echo "<tr class=row_{$order}><th class=tdleft>";
                    $locationIdx = 0;
                    $locationTree = '';
                    while ($location_id) {
                        if ($locationIdx == 20) {
                            showWarning("Warning: There is likely a circular reference in the location tree.  Investigate location {$location_id}.");
                            break;
                        }
                        $parentLocation = spotEntity('location', $location_id);
                        $locationTree = "&raquo; <a href='" . makeHref(array('page' => 'location', 'location_id' => $parentLocation['id'])) . "{$cellfilter['urlextra']}'>{$parentLocation['name']}</a> " . $locationTree;
                        $location_id = $parentLocation['parent_id'];
                        $locationIdx++;
                    }
                    $locationTree = substr($locationTree, 8);
                    echo $locationTree;
                    echo "</th><th class=tdleft><a href='" . makeHref(array('page' => 'row', 'row_id' => $row_id)) . "{$cellfilter['urlextra']}'>{$row_name}</a></th>";
                    echo "<th class=tdleft><table border=0 cellspacing=5><tr>";
                    if (!count($rackList)) {
                        echo '<td>(empty row)</td>';
                    } else {
                        foreach ($rackList as $rack) {
                            if ($rackListIdx > 0 and $maxPerRow > 0 and $rackListIdx % $maxPerRow == 0) {
                                echo '</tr></table></th></tr>';
                                echo "<tr class=row_{$order}><th class=tdleft></th><th class=tdleft>{$row_name} (continued)";
                                echo "</th><th class=tdleft><table border=0 cellspacing=5><tr>";
                            }
                            echo "<td align=center valign=bottom><a href='" . makeHref(array('page' => 'rack', 'rack_id' => $rack['id'])) . "'>";
                            echo "<img border=0 width={$rackwidth} height=";
                            echo getRackImageHeight($rack['height']);
                            echo " title='{$rack['height']} units'";
                            echo "src='?module=image&img=minirack&rack_id={$rack['id']}'>";
                            echo "<br>{$rack['name']}</a></td>";
                            $rackListIdx++;
                        }
                    }
                    $order = $nextorder[$order];
                    echo "</tr></table></th></tr>\n";
                }
                echo "</table>\n";
            }
        }
    }
    echo '</td><td class=pcright width="25%">';
    renderCellFilterPortlet($cellfilter, 'rack', $found_racks);
    echo "<br>\n";
    renderLocationFilterPortlet();
    echo "</td></tr></table>\n";
}
function renderRackspace()
{
    // Handle the location filter
    startSession();
    if (isset($_REQUEST['changeLocationFilter'])) {
        unset($_SESSION['locationFilter']);
    }
    if (isset($_REQUEST['location_id'])) {
        $_SESSION['locationFilter'] = $_REQUEST['location_id'];
    }
    session_commit();
    echo "<table class=objview border=0 width='100%'><tr><td class=pcleft>";
    $found_racks = array();
    $cellfilter = getCellFilter();
    if (!($cellfilter['is_empty'] && !isset($_SESSION['locationFilter']) && renderEmptyResults($cellfilter, 'racks', getEntitiesCount('rack')))) {
        $rows = array();
        $rackCount = 0;
        foreach (listCells('row') as $row_id => $rowInfo) {
            $rackList = applyCellFilter('rack', $cellfilter, $row_id);
            $found_racks = array_merge($found_racks, $rackList);
            $location_id = $rowInfo['location_id'];
            $locationIdx = 0;
            // contains location names in the form of 'grandparent parent child', used for sorting
            $locationTree = '';
            // contains location names as well as links
            $hrefLocationTree = '';
            while ($location_id) {
                if ($locationIdx == 20) {
                    showWarning("Warning: There is likely a circular reference in the location tree.  Investigate location {$location_id}.");
                    break;
                }
                $parentLocation = spotEntity('location', $location_id);
                $locationTree = sprintf('%s %s', $parentLocation['name'], $locationTree);
                $hrefLocationTree = "&raquo; <a href='" . makeHref(array('page' => 'location', 'location_id' => $parentLocation['id'])) . "{$cellfilter['urlextra']}'>{$parentLocation['name']}</a> " . $hrefLocationTree;
                $location_id = $parentLocation['parent_id'];
                $locationIdx++;
            }
            $hrefLocationTree = substr($hrefLocationTree, 8);
            $rows[] = array('location_id' => $rowInfo['location_id'], 'location_tree' => $locationTree, 'href_location_tree' => $hrefLocationTree, 'row_id' => $row_id, 'row_name' => $rowInfo['name'], 'racks' => $rackList);
            $rackCount += count($rackList);
        }
        // sort by location, then by row
        usort($rows, 'rackspaceCmp');
        if (!renderEmptyResults($cellfilter, 'racks', $rackCount)) {
            // generate thumb gallery
            global $nextorder;
            // Zero value effectively disables the limit.
            $maxPerRow = getConfigVar('RACKS_PER_ROW');
            $order = 'odd';
            if (!count($rows)) {
                echo "<h2>No rows found</h2>\n";
            } else {
                echo '<table border=0 cellpadding=10 class=cooltable>';
                echo '<tr><th class=tdleft>Location</th><th class=tdleft>Row</th><th class=tdleft>Racks</th></tr>';
                foreach ($rows as $row) {
                    $rackList = $row['racks'];
                    if ($location_id != '' and isset($_SESSION['locationFilter']) and !in_array($location_id, $_SESSION['locationFilter']) or empty($rackList) and !$cellfilter['is_empty']) {
                        continue;
                    }
                    $rackListIdx = 0;
                    echo "<tr class=row_{$order}><th class=tdleft>{$row['href_location_tree']}</th>";
                    echo "<th class=tdleft><a href='" . makeHref(array('page' => 'row', 'row_id' => $row['row_id'])) . "{$cellfilter['urlextra']}'>{$row['row_name']}</a></th>";
                    echo "<th class=tdleft><table border=0 cellspacing=5><tr>";
                    if (!count($rackList)) {
                        echo '<td>(empty row)</td>';
                    } else {
                        foreach ($rackList as $rack) {
                            if ($rackListIdx > 0 and $maxPerRow > 0 and $rackListIdx % $maxPerRow == 0) {
                                echo '</tr></table></th></tr>';
                                echo "<tr class=row_{$order}><th class=tdleft></th><th class=tdleft>{$row['row_name']} (continued)";
                                echo "</th><th class=tdleft><table border=0 cellspacing=5><tr>";
                            }
                            echo '<td align=center valign=bottom>' . getRackThumbLink($rack) . '</td>';
                            $rackListIdx++;
                        }
                    }
                    $order = $nextorder[$order];
                    echo "</tr></table></th></tr>\n";
                }
                echo "</table>\n";
            }
        }
    }
    echo '</td><td class=pcright width="25%">';
    renderCellFilterPortlet($cellfilter, 'rack', $found_racks);
    echo "<br>\n";
    renderLocationFilterPortlet();
    echo "</td></tr></table>\n";
}