Beispiel #1
0
{
    header('Content-Type: application/json');
    echo json_encode($array);
    exit;
}
if (isset($_POST['dc'])) {
    $cab = new Cabinet();
    $cab->DataCenterID = $_POST['dc'];
    displayjson($cab->ListCabinetsByDC());
}
if (isset($_POST['cab'])) {
    $dev = new Device();
    $dev->Cabinet = $_POST['cab'];
    // Filter devices by rights
    $devs = array();
    foreach ($dev->ViewDevicesByCabinet(true) as $d) {
        if ($d->Rights == "Write") {
            $devs[] = $d;
        }
    }
    displayjson($devs);
}
if (isset($_POST['dev'])) {
    $dp = new DevicePorts();
    $dp->DeviceID = $_POST['dev'];
    $dev = new Device();
    $dev->DeviceID = $dp->DeviceID;
    $dev->GetDevice();
    $ports = $dev->Rights == "Write" ? $dp->getPorts() : array();
    displayjson($ports);
}
Beispiel #2
0
</form>
</div> <!-- END .center -->
</div> <!-- END .main -->
</div> <!-- END .page -->
</body>
</html>';
} else {
    $cab = new Cabinet();
    $dev = new Device();
    $datacenter->DataCenterID = $_REQUEST["datacenterid"];
    $datacenter->GetDataCenter();
    $cab->DataCenterID = $datacenter->DataCenterID;
    $cabList = $cab->ListCabinetsByDC();
    header('Content-type: text/xml');
    header('Cache-Control: no-store, NO-CACHE');
    header('Content-Disposition: attachment; filename="opendcim.xml"');
    print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<datacenter>\n\n\t<ID>{$datacenter->DataCenterID}</ID>\n\t<Name>{$datacenter->Name}</Name>\n\t<Size>{$datacenter->SquareFootage}</Size>\n";
    foreach ($cabList as $cabRow) {
        print "\t<cabinet>\n\t\t<ID>{$cabRow->CabinetID}</ID>\n\t\t<Location>{$cabRow->Location}</Location>\n\t\t<Height>{$cabRow->CabinetHeight}</Height>\n\t\t<FrontEdge>{$cabRow->FrontEdge}</FrontEdge>\n\t\t<MapX1>{$cabRow->MapX1}</MapX1>\n\t\t<MapY1>{$cabRow->MapY1}</MapY1>\n\t\t<MapX2>{$cabRow->MapX2}</MapX2>\n\t\t<MapY2>{$cabRow->MapY2}</MapY2>\n";
        $dev->Cabinet = $cabRow->CabinetID;
        $devList = $dev->ViewDevicesByCabinet();
        $totalWatts = 0;
        foreach ($devList as $devRow) {
            $power = $devRow->GetDeviceTotalPower();
            $totalWatts += $power;
            print "\t\t<Device>\n\t\t\t<ID>{$devRow->DeviceID}</ID>\n\t\t\t<Label>{$devRow->Label}</Label>\n\t\t\t<Position>{$devRow->Position}</Position>\n\t\t\t<Height>{$devRow->Height}</Height>\n\t\t\t<Watts>{$power}</Watts>\n\t\t</Device>\n";
        }
        print "\t\t<TotalWatts>{$totalWatts}</TotalWatts>\n\t</cabinet>\n";
    }
    print "</datacenter>\n";
}
/**
 * Compute the full inventory on devices in the data centers and return the data
 *   center summary statistics
 *
 * @param PHPExcel_Worksheet $worksheet
 * @param array $DProps properties defined for the Excel document
 * @return (array|array|array|boolean)[]
 *      statistics array, device inventory, cabinet inventory
 */
function computeSheetBodyDCInventory($DProps)
{
    global $person;
    global $sessID;
    $dc = new DataCenter();
    $cab = new Cabinet();
    $device = new Device();
    $invData = array();
    $invCab = array();
    $sheetColumns = $DProps['DC Inventory']['Columns'];
    $cabinetColumns = $DProps['Rack Inventory']['Columns'];
    $devTemplates = DeviceTemplate::getTemplateListIndexedbyID();
    $deptList = Department::GetDepartmentListIndexedbyID();
    $contactList = $person->GetUserList('indexed');
    $limitedUser = false;
    $dcList = $dc->GetDCList();
    $Stats = array();
    // A little code to update the counter
    $percentDone = 0;
    $sectionMaxPercent = 40;
    $incrementalPercent = 1 / sizeof($dcList) * $sectionMaxPercent;
    foreach ($dcList as $dc) {
        $dcContainerList = $dc->getContainerList();
        $dcStats = array();
        $cab->DataCenterID = $dc->DataCenterID;
        $dcStats['Fl_Spc'] = $dc->SquareFootage;
        $dcStats['DesignPower'] = $dc->MaxkW;
        $dcStats['Watts'] = 0;
        $dcStats['Rk_Num'] = 0;
        $dcStats['Rk_UtT'] = 0;
        $dcStats['Rk_UtU'] = 0;
        $dcStats['Rk_UtE'] = 0;
        $dcStats['Rk_Res'] = 0;
        $cabList = $cab->ListCabinetsByDC();
        if (count($cabList) == 0) {
            // empty data center room
            $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
            $devSpec['DC Name'] = $dc->Name;
            $invData[] = $devSpec;
        } else {
            foreach ($cabList as $cab) {
                if (!$person->ReadAccess and $cab->AssignedTo == 0 or $cab->AssignedTo > 0 and !$person->canRead($cab->AssignedTo)) {
                    // User is not allowed to see anything in here
                    $limitedUser = true;
                    continue;
                }
                $zoneName = getZoneName($cab);
                $rowName = getRowName($cab);
                addRackStat($invCab, $cab, $cabinetColumns, $dc, $dcContainerList);
                $cab_height = $cab->CabinetHeight;
                if (mb_strtoupper($cab->Model) == 'RESERVED') {
                    $dcStats['Rk_Res']++;
                } else {
                    $dcStats['Rk_Num']++;
                }
                $dcStats['Rk_UtT'] += $cab_height;
                $device->Cabinet = $cab->CabinetID;
                $device_list = $device->ViewDevicesByCabinet();
                // empty cabinet
                if (count($device_list) == 0 && $cab->CabinetHeight > 0) {
                    $dcStats['Rk_UtE'] += $cab_height;
                    $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
                    $devSpec['Zone'] = $zoneName;
                    $devSpec['Row'] = $rowName;
                    $devSpec['DC Name'] = $dc->Name;
                    $devSpec['Cabinet'] = $cab->Location;
                    $devSpec['Position'] = 1;
                    $devSpec['Height'] = $cab->CabinetHeight;
                    $devSpec['Device'] = '__EMPTY';
                    $invData[] = $devSpec;
                } else {
                    usort($device_list, 'cmpDevPos');
                    $low_idx = 1;
                    foreach ($device_list as $dev) {
                        if ($low_idx < $dev->Position) {
                            // range of empty slots
                            if ($dev->Position <= $cab_height) {
                                $height = $dev->Position - $low_idx;
                            } else {
                                $height = $cab_height - $low_idx + 1;
                            }
                            if ($height > 0) {
                                $dcStats['Rk_UtE'] += $height;
                                $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
                                ${$devSpec}['Zone'] = $zoneName;
                                $devSpec['Row'] = $rowName;
                                $devSpec['DC Name'] = $dc->Name;
                                $devSpec['Cabinet'] = $cab->Location;
                                $devSpec['Position'] = $low_idx;
                                $devSpec['Height'] = $height;
                                $devSpec['Device'] = '__EMPTY';
                                $invData[] = $devSpec;
                            }
                            $low_idx = $dev->Position;
                        }
                        // device in cabinet
                        $reserved = $dev->Reservation ? 'reserved' : null;
                        list($manufacturer, $model) = getDeviceTemplateName($devTemplates, $dev);
                        $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
                        $devSpec['DevID'] = $dev->DeviceID;
                        $devSpec['Zone'] = $zoneName;
                        $devSpec['Row'] = $rowName;
                        $devSpec['DC Name'] = $dc->Name;
                        $devSpec['Cabinet'] = $cab->Location;
                        $devSpec['Position'] = $dev->Position;
                        $devSpec['Half Depth'] = getDeviceDepthPos($dev);
                        $devSpec['Height'] = $dev->Height;
                        $devSpec['Device'] = $dev->Label;
                        $devSpec['Parent Device'] = null;
                        $devSpec['Manufacturer'] = $manufacturer;
                        $devSpec['Model'] = $model;
                        $devSpec['Device Type'] = $dev->DeviceType;
                        $devSpec['Asset Number'] = $dev->AssetTag;
                        $devSpec['Serial No.'] = $dev->SerialNo;
                        $devSpec['Install Date'] = $dev->InstallDate;
                        $devSpec['Warranty End'] = $dev->WarrantyExpire;
                        $devSpec['Owner'] = getOwnerName($dev, $deptList);
                        $devSpec['Power (W)'] = $dev->NominalWatts;
                        $devSpec['Reservation'] = $reserved;
                        $devSpec['Contact'] = getContactName($contactList, $dev->PrimaryContact);
                        $devSpec['Tags'] = getTagsString($dev);
                        $devSpec['Notes'] = html_entity_decode(strip_tags($dev->Notes), ENT_COMPAT, 'UTF-8');
                        $invData[] = $devSpec;
                        $dcStats['Watts'] += $dev->NominalWatts;
                        // devices can be installed at the same position and
                        // could be of different height; count only the free
                        // rack units which are not covered by any device
                        if ($low_idx == $dev->Position) {
                            $low_idx += $dev->Height;
                            $dcStats['Rk_UtU'] += $dev->Height;
                        } else {
                            $rest_height = $dev->Position + $dev->Height - $low_idx;
                            $rest_height = $rest_height > 0 ? $rest_height : 0;
                            $low_idx += $rest_height;
                            $dcStats['Rk_UtU'] += $rest_height;
                        }
                        if ($dev->DeviceType == 'Chassis') {
                            list($watts, $invData) = computeDeviceChildren($sheetColumns, $invData, $dev, $dc->Name, $cab, $devTemplates, $deptList, $contactList, $dcContainerList);
                            $dcStats['Watts'] += $watts;
                        }
                    }
                    if ($low_idx <= $cab->CabinetHeight) {
                        // empty range at the top of the cabinet, $low_idx is
                        // the potentially free location
                        $height = $cab->CabinetHeight - $low_idx + 1;
                        $dcStats['Rk_UtE'] += $height;
                        $devSpec = makeEmptySpec($sheetColumns, $dcContainerList);
                        $devSpec['Zone'] = $zoneName;
                        $devSpec['Row'] = $rowName;
                        $devSpec['DC Name'] = $dc->Name;
                        $devSpec['Cabinet'] = $cab->Location;
                        $devSpec['Position'] = $low_idx;
                        $devSpec['Height'] = $height;
                        $devSpec['Device'] = '__EMPTY';
                        $invData[] = $devSpec;
                    }
                }
            }
        }
        assignStatsVal($Stats, $dc, $dcStats);
        $percentDone += $incrementalPercent;
        JobQueue::updatePercentage($sessID, $percentDone);
    }
    return array($Stats, $invData, $invCab, $limitedUser);
}
Beispiel #4
0
 function DeleteCabinet()
 {
     global $dbh;
     /* Need to delete all devices and CDUs first */
     $tmpDev = new Device();
     $tmpCDU = new PowerDistribution();
     $tmpDev->Cabinet = $this->CabinetID;
     $devList = $tmpDev->ViewDevicesByCabinet();
     foreach ($devList as &$delDev) {
         $delDev->DeleteDevice();
     }
     $tmpCDU->CabinetID = $this->CabinetID;
     $cduList = $tmpCDU->GetPDUbyCabinet();
     foreach ($cduList as &$delCDU) {
         $delCDU->DeletePDU();
     }
     $sql = "DELETE FROM fac_Cabinet WHERE CabinetID={$this->CabinetID};";
     if (!$dbh->exec($sql)) {
         $info = $dbh->errorInfo();
         error_log("PDO Error::DeleteCabinet: {$info[2]} SQL={$sql}");
         return false;
     }
     class_exists('LogActions') ? LogActions::LogThis($this) : '';
     return true;
 }
Beispiel #5
0
$pdf = new PDF();
$pdf->SetLeftMargin(5);
$pdf->SetRightMargin(5);
include_once "loadfonts.php";
$cab->CabinetID = $_REQUEST['cabinetid'];
$cab->GetCabinet();
$device->Cabinet = $cab->CabinetID;
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFillColor(224, 235, 255);
$fill = 0;
$cabmessage = __("Cabinet Location") . ': ' . $cab->Location;
$pdf->SetFont($config->ParameterArray['PDFfont'], 'B', 10);
$pdf->Cell(0, 5, $cabmessage, 0, 1, 'C', 0);
$pdf->SetFont($config->ParameterArray['PDFfont'], '', 10);
$deviceList = $device->ViewDevicesByCabinet();
$headerTags = array(__("Label"), __("SerialNo"), __("AssetTag"), __("Position"), __("Rack Units"), __("#Ports"), __("#PS"), __("PowerConnection1"), __("PowerConnection2"), __("DeviceType"));
$cellWidths = array(45, 40, 20, 18, 20, 15, 10, 35, 35, 50);
$maxval = count($headerTags);
for ($col = 0; $col < $maxval; $col++) {
    $pdf->Cell($cellWidths[$col], 7, $headerTags[$col], 1, 0, 'C', 1);
}
$pdf->Ln();
function printRow($devRow, $pport, $pdf, $templ, $fill, $cellWidths, $pdu, $mfg)
{
    global $fill;
    $pport->DeviceID = $devRow->DeviceID;
    $connList = $pport->getPorts();
    $pdf->Cell($cellWidths[0], 6, $devRow->Label, 'LBRT', 0, 'L', $fill);
    $pdf->Cell($cellWidths[1], 6, $devRow->SerialNo, 'LBRT', 0, 'L', $fill);
    $pdf->Cell($cellWidths[2], 6, $devRow->AssetTag, 'LBRT', 0, 'L', $fill);