static function getPatchCandidates($DeviceID, $PortNum = null, $listports = null, $patchpanels = null, $scopelimit = null) { /* * $DeviceID = ID of the device that you are wanting to make a connection from * $PortNum(optional) = Port Number on the device you are wanting to connect, * mandatory if media enforcing is on * $listports(optional) = Any value will trigger this to kick back a list of * valid points that this port can connect to instead of the default list * of valid devices that it can connect to. */ global $dbh; global $config; global $person; $dev = new Device(); // make sure we have a real device first $dev->DeviceID = $DeviceID; if (!$dev->GetDevice()) { return false; } $mediaenforce = ""; if ($config->ParameterArray["MediaEnforce"] == 'enabled' && !is_null($PortNum)) { $dp = new DevicePorts(); $dp->DeviceID = $DeviceID; $dp->PortNumber = $PortNum; $dp->getPort(); $mt = new MediaTypes(); $mt->MediaID = $dp->MediaID; $mt->GetType(); $mediaenforce = " AND MediaID={$mt->MediaID}"; } elseif ($config->ParameterArray["MediaEnforce"] == 'enabled' && is_null($PortNum)) { // Media Type Enforcing is enabled and you didn't supply a port to match type on return false; } $limiter = ''; if (!is_null($scopelimit)) { $cab = new Cabinet(); $cab->CabinetID = $dev->Cabinet; $cab->GetCabinet(); switch ($scopelimit) { case 'cabinet': $limiter = " AND Cabinet={$dev->Cabinet}"; break; case 'row': $limiter = " AND Cabinet IN (SELECT CabinetID FROM fac_Cabinet WHERE CabRowID={$cab->CabRowID} AND CabRowID>0)"; break; case 'zone': $limiter = " AND Cabinet IN (SELECT CabinetID FROM fac_Cabinet WHERE ZoneID={$cab->ZoneID} AND ZoneID>0)"; break; case 'datacenter': $limiter = " AND Cabinet IN (SELECT CabinetID FROM fac_Cabinet WHERE DataCenterID={$cab->DataCenterID})"; break; default: break; } } $pp = ""; if (!is_null($patchpanels)) { $pp = ' AND DeviceType="Patch Panel"'; } $candidates = array(); if (is_null($listports)) { $currentperson = $person; if (!$currentperson->WriteAccess) { $groups = $currentperson->isMemberOf(); // list of groups the current user is member of $rights = null; foreach ($groups as $index => $DeptID) { if (is_null($rights)) { $rights = "Owner={$DeptID}"; } else { $rights .= " OR Owner={$DeptID}"; } } $rights = is_null($rights) ? null : " AND ({$rights})"; } else { $rights = null; } $cabinetID = $dev->GetDeviceCabinetID(); $sqlSameCabDevice = "SELECT * FROM fac_Device WHERE Ports>0 AND \r\n\t\t\t\tCabinet={$cabinetID} {$rights}{$pp}{$limiter} GROUP BY DeviceID ORDER BY Position \r\n\t\t\t\tDESC, Label ASC;"; $sqlDiffCabDevice = "SELECT * FROM fac_Device WHERE Ports>0 AND \r\n\t\t\t\tCabinet!={$cabinetID} {$rights}{$pp}{$limiter} GROUP BY DeviceID ORDER BY Label ASC;"; foreach (array($sqlSameCabDevice, $sqlDiffCabDevice) as $sql) { foreach ($dbh->query($sql) as $row) { // false to skip rights check we filtered using sql above $tmpDev = Device::RowToObject($row, false); $candidates[] = array("DeviceID" => $tmpDev->DeviceID, "Label" => $tmpDev->Label, "CabinetID" => $tmpDev->Cabinet); } } } else { $sql = "SELECT a.*, b.Cabinet as CabinetID FROM fac_Ports a, fac_Device b WHERE \r\n\t\t\t\tPorts>0 AND Cabinet>-1 AND a.DeviceID=b.DeviceID AND \r\n\t\t\t\ta.DeviceID!={$dev->DeviceID} AND ConnectedDeviceID IS NULL{$mediaenforce}{$pp};"; foreach ($dbh->query($sql) as $row) { $candidates[] = array("DeviceID" => $row["DeviceID"], "Label" => $row["Label"], "CabinetID" => $row["CabinetID"]); } } return $candidates; }
function ExportTemplate() { $this->MakeSafe(); //Get manufacturer name $manufacturer = new Manufacturer(); $manufacturer->ManufacturerID = $this->ManufacturerID; $manufacturer->GetManufacturerByID(); $fileContent = '<?xml version="1.0" encoding="UTF-8"?> <Template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="openDCIMdevicetemplate.xsd"> <ManufacturerName>' . $manufacturer->Name . '</ManufacturerName> <TemplateReg> <Model>' . $this->Model . '</Model> <Height>' . $this->Height . '</Height> <Weight>' . $this->Weight . '</Weight> <Wattage>' . $this->Wattage . '</Wattage> <DeviceType>' . $this->DeviceType . '</DeviceType> <PSCount>' . $this->PSCount . '</PSCount> <NumPorts>' . $this->NumPorts . '</NumPorts> <Notes>' . $this->Notes . '</Notes> <FrontPictureFile>' . $this->FrontPictureFile . '</FrontPictureFile> <RearPictureFile>' . $this->RearPictureFile . '</RearPictureFile> <SNMPVersion>' . $this->SNMPVersion . '</SNMPVersion> <ChassisSlots>' . $this->ChassisSlots . '</ChassisSlots> <RearChassisSlots>' . $this->RearChassisSlots . '</RearChassisSlots> </TemplateReg>'; //Slots for ($i = 1; $i <= $this->ChassisSlots; $i++) { $slot = new Slot(); $slot->TemplateID = $this->TemplateID; $slot->Position = $i; $slot->BackSide = False; $slot->GetSlot(); $fileContent .= ' <SlotReg> <Position>' . $slot->Position . '</Position> <BackSide>0</BackSide> <X>' . $slot->X . '</X> <Y>' . $slot->Y . '</Y> <W>' . $slot->W . '</W> <H>' . $slot->H . '</H> </SlotReg>'; } for ($i = 1; $i <= $this->RearChassisSlots; $i++) { $slot = new Slot(); $slot->TemplateID = $this->TemplateID; $slot->Position = $i; $slot->BackSide = True; $slot->GetSlot(); $fileContent .= ' <SlotReg> <Position>' . $slot->Position . '</Position> <BackSide>1</BackSide> <X>' . $slot->X . '</X> <Y>' . $slot->Y . '</Y> <W>' . $slot->W . '</W> <H>' . $slot->H . '</H> </SlotReg>'; } //Ports for ($i = 1; $i <= $this->NumPorts; $i++) { $tport = new TemplatePorts(); $tport->TemplateID = $this->TemplateID; $tport->PortNumber = $i; $tport->GetPort(); //Get media name $mt = new MediaTypes(); $mt->MediaID = $tport->MediaID; $mt->GetType(); //Get color name $cc = new ColorCoding(); $cc->ColorID = $tport->ColorID; $cc->GetCode(); $fileContent .= ' <PortReg> <PortNumber>' . $tport->PortNumber . '</PortNumber> <Label>' . $tport->Label . '</Label> <PortMedia>' . $mt->MediaType . '</PortMedia> <PortColor>' . $cc->Name . '</PortColor> <PortNotes>' . $tport->PortNotes . '</PortNotes> </PortReg>'; } //Pictures if ($this->FrontPictureFile != "" && file_exists("pictures/" . $this->FrontPictureFile)) { $im = file_get_contents("pictures/" . $this->FrontPictureFile); $fileContent .= ' <FrontPicture> ' . base64_encode($im) . ' </FrontPicture>'; } if ($this->RearPictureFile != "" && file_exists("pictures/" . $this->RearPictureFile)) { $im = file_get_contents("pictures/" . $this->RearPictureFile); $fileContent .= ' <RearPicture> ' . base64_encode($im) . ' </RearPicture>'; } //End of template $fileContent .= ' </Template>'; //download file download_file_from_string($fileContent, str_replace(' ', '', $manufacturer->Name . "-" . $this->Model) . ".xml"); return true; }
$cc->ColorID = $colorKey; $cc->GetCode(); $label = $cc->Name != "" ? $cc->Name : "Unset"; } elseif ($colorType == 2) { $mt = new MediaTypes(); $mt->MediaID = $colorKey; $mt->GetType(); $label = $mt->MediaType != "" ? $mt->MediaType : "Unset"; } else { $keys = explode(':', $colorKey); $cc = new ColorCoding(); $cc->ColorID = $keys[0]; $cc->GetCode(); $mt = new MediaTypes(); $mt->MediaID = $keys[1]; $mt->GetType(); $colorname = $cc->Name != "" ? $cc->Name : "Unset"; $mediatype = $mt->MediaType != "" ? $mt->MediaType : "Unset"; $label = $mediatype . "--" . $colorname; } $graphstr .= "\t\tinvis1 -- invis2 [color=" . $color . ",label=\"" . $label . "\"];\n"; } $graphstr .= "\t}\n}"; # safe format types. newer versions of graphviz also support pdf. maybe # we should add it when the ability is more prevalent. $formatTypes = array('svg', 'png', 'jpg', 'dot'); if (!isset($formatTypes[$_REQUEST['format']])) { exit; } $ft = $formatTypes[$_REQUEST['format']]; $header = "Content-Type: ";
$targetPort = new DevicePorts(); $color = new ColorCoding(); $mediaType = new MediaTypes(); if ($devPort->ConnectedDeviceID > 0 || $devPort->Notes != "") { $targetDev->DeviceID = $devPort->ConnectedDeviceID; $targetDev->GetDevice(); $targetPort->DeviceID = $targetDev->DeviceID; $targetPort->PortNumber = $devPort->ConnectedPort; $targetPort->getPort(); if ($targetPort->Label == '') { $targetPort->Label = $devPort->ConnectedDeviceID > 0 ? $devPort->ConnectedPort : ''; } $color->ColorID = $devPort->ColorID; $color->GetCode(); $mediaType->MediaID = $devPort->MediaID; $mediaType->GetType(); $sheet->getActiveSheet()->SetCellValue('A' . $row, '="' . $dev->Label . '"'); $sheet->getActiveSheet()->SetCellValue('B' . $row, '="' . $devPort->Label . '"'); $sheet->getActiveSheet()->SetCellValue('C' . $row, '="' . $targetDev->Label . '"'); $sheet->getActiveSheet()->SetCellValue('D' . $row, '="' . $targetPort->Label . '"'); $sheet->getActiveSheet()->SetCellValue('E' . $row, '="' . $devPort->Notes . '"'); $sheet->getActiveSheet()->SetCellValue('F' . $row, '="' . $mediaType->MediaType . '"'); $sheet->getActiveSheet()->SetCellValue('G' . $row, '="' . $color->Name . '"'); $row++; } if ($targetDev->DeviceType == "Patch Panel") { $path = DevicePorts::followPathToEndPoint($devPort->ConnectedDeviceID, $devPort->ConnectedPort); $pDev = new Device(); $tDev = new Device(); $pPort = new DevicePorts(); $tPort = new DevicePorts();