$pp->DeviceID = $deviceid; foreach ($app->request->get() as $prop => $val) { $pp->{$prop} = $val; } if ($pp->PortNumber) { if (!$pp->getPort()) { $response['error'] = true; } // This is to cut down on api calls to get the connected device and port names if ($pp->ConnectedDeviceID) { $dev = new Device(); $dpp = new PowerPorts(); $dev->DeviceID = $dpp->DeviceID = $pp->ConnectedDeviceID; $dpp->PortNumber = $pp->ConnectedPort; $dev->GetDevice(); $dpp->getPort(); $pp->ConnectedDeviceLabel = $dev->Label; $pp->ConnectedPortLabel = $dpp->Label; } $response['powerport'][$pp->PortNumber] = $pp; } else { $response['powerport'] = $pp->getPorts(); } echoResponse(200, $response); }); // // URL: /api/v1/colorcode // Method: GET // Params: none // Returns: All defined color codes //
} //HTML content condensed for PHP logic clarity. // If $pwrCords is null then we're creating a device record. Skip power checking. if (!is_null($pwrCords) && (isset($_POST['action']) && $_POST['action'] != 'Child' || !isset($_POST['action'])) && !in_array($dev->DeviceType, array('Physical Infrastructure', 'Patch Panel'))) { print "\t\t<div>\n\t\t\t<div><a id=\"power\">{$chassis} " . __("Power Connections") . "</a></div>\r\n\t\t\t<div><div class=\"table border power\">\r\n\t\t\t\t<div>\r\n\t\t\t\t\t<div class=\"delete\" style=\"display: none;\"></div>\r\n\t\t\t\t\t<div>#</div>\r\n\t\t\t\t\t<div id=\"ppcn\">" . __("Port Name") . "</div>\r\n\t\t\t\t\t<div>" . __("Device") . "</div>\r\n\t\t\t\t\t<div>" . __("Device Port") . "</div>\r\n\t\t\t\t\t<div>" . __("Notes") . "</div>\r\n<!--\t\t\t\t<div>" . __("Panel") . "</div> -->\r\n\t\t\t\t</div>\n"; foreach ($pwrCords as $i => $cord) { $tmppdu = new Device(); $tmppdu->DeviceID = $cord->ConnectedDeviceID; $tmppdu->GetDevice(); // $panel->PanelID=$pdu->PanelID; // $panel->getPanel(); $tmpcord = new PowerPorts(); if ($cord->ConnectedDeviceID > 0 && !is_null($cord->ConnectedDeviceID)) { $tmpcord->DeviceID = $cord->ConnectedDeviceID; $tmpcord->PortNumber = $cord->ConnectedPort; $tmpcord->getPort(); } else { $cord->ConnectedDeviceID = 0; $cord->ConnectedPort = 0; } print "\t\t\t\t<div data-port={$i}>\r\n\t\t\t\t\t<div>{$i}</div>\r\n\t\t\t\t\t<div data-default=\"{$cord->Label}\">{$cord->Label}</div>\r\n\t\t\t\t\t<div data-default={$cord->ConnectedDeviceID}><a href=\"devices.php?DeviceID={$cord->ConnectedDeviceID}\">{$tmppdu->Label}</a></div>\r\n\t\t\t\t\t<div data-default={$cord->ConnectedPort}>{$tmpcord->Label}</div>\r\n\t\t\t\t\t<div data-default=\"{$cord->Notes}\">{$cord->Notes}</div>\r\n\t\t\t\t</div>\n"; } $connectioncontrols = $dev->DeviceID > 0 && !empty($portList) ? ' <span style="display: inline-block; vertical-align: super;">' . __("Limit device selection to") . ':</span> <div id="connection-limiter" data-role="controlgroup" data-type="horizontal"> <input type="radio" name="connection-limiter" id="radio-choice-1" value="row" /> <label for="radio-choice-1">Row</label> <input type="radio" name="connection-limiter" id="radio-choice-2" value="zone" /> <label for="radio-choice-2">Zone</label> <input type="radio" name="connection-limiter" id="radio-choice-3" value="datacenter" /> <label for="radio-choice-3">Datacenter</label>
function updatePort() { global $dbh; $oldport = new PowerPorts(); // originating port prior to modification $oldport->DeviceID = $this->DeviceID; $oldport->PortNumber = $this->PortNumber; $oldport->getPort(); $tmpport = new PowerPorts(); // connecting to here $tmpport->DeviceID = $this->ConnectedDeviceID; $tmpport->PortNumber = $this->ConnectedPort; $tmpport->getPort(); $oldtmpport = new PowerPorts(); // used for logging $oldtmpport->DeviceID = $oldport->ConnectedDeviceID; $oldtmpport->PortNumber = $oldport->ConnectedPort; $oldtmpport->getPort(); //check rights before we go any further $dev = new Device(); $dev->DeviceID = $this->DeviceID; $dev->GetDevice(); $replacingdev = new Device(); $replacingdev->DeviceID = $oldport->ConnectedDeviceID; $replacingdev->GetDevice(); $connecteddev = new Device(); $connecteddev->DeviceID = $this->ConnectedDeviceID; $connecteddev->GetDevice(); $rights = false; $rights = $dev->Rights == "Write" ? true : $rights; $rights = $replacingdev->Rights == "Write" ? true : $rights; $rights = $connecteddev->Rights == "Write" ? true : $rights; if (!$rights) { return false; } $this->MakeSafe(); // Quick sanity check so we aren't depending on the user $this->Label = $this->Label == "" ? $this->PortNumber : $this->Label; // clear previous connection $oldport->removeConnection(); $tmpport->removeConnection(); if ($this->ConnectedDeviceID == 0 || $this->PortNumber == 0 || $this->ConnectedPort == 0) { // when any of the above equal 0 this is a delete request // skip making any new connections but go ahead and update the device // reload tmpport with data from the other device $tmpport->DeviceID = $oldport->ConnectedDeviceID; $tmpport->PortNumber = $oldport->ConnectedPort; $tmpport->getPort(); } else { // make new connection $tmpport->ConnectedDeviceID = $this->DeviceID; $tmpport->ConnectedPort = $this->PortNumber; $tmpport->Notes = $this->Notes; PowerPorts::makeConnection($tmpport, $this); } // update port $sql = "UPDATE fac_PowerPorts SET ConnectedDeviceID={$this->ConnectedDeviceID},\n\t\t\tLabel=\"{$this->Label}\", ConnectedPort={$this->ConnectedPort}, \n\t\t\tNotes=\"{$this->Notes}\" WHERE DeviceID={$this->DeviceID} AND \n\t\t\tPortNumber={$this->PortNumber};"; if (!$dbh->query($sql)) { $info = $dbh->errorInfo(); error_log("updatePort::PDO Error: {$info[2]} SQL={$sql}"); return false; } // two logs, because we probably modified two devices class_exists('LogActions') ? LogActions::LogThis($this, $oldport) : ''; class_exists('LogActions') ? LogActions::LogThis($tmpport, $oldtmpport) : ''; return true; }
*/ $pport = new PowerPorts(); $pport->DeviceID = $dev->DeviceID; $pportList = $pport->getPorts(); // Make power cable labels based on the number of power supplies foreach ($pportList as $powerPort) { $sheet->getActiveSheet()->SetCellValue('A' . $row, $dev->Label); $sheet->getActiveSheet()->SetCellValue('B' . $row, $powerPort->Label); if ($powerPort->ConnectedDeviceID > 0) { $targetDev = new Device(); $targetPort = new PowerPorts(); $targetDev->DeviceID = $powerPort->ConnectedDeviceID; $targetDev->GetDevice(); $targetPort->DeviceID = $targetDev->DeviceID; $targetPort->PortNumber = $powerPort->ConnectedPort; $targetPort->getPort(); $sheet->getActiveSheet()->SetCellValue('C' . $row, $targetDev->Label); $sheet->getActiveSheet()->SetCellValue('D' . $row, $targetPort->Label); $sheet->getActiveSheet()->SetCellValue('H' . $row, __("Power Connection")); } $row++; } foreach ($portList as $devPort) { // These are created inside the loop, because they need to be clean instances each time $targetDev = new Device(); $targetPort = new DevicePorts(); $color = new ColorCoding(); $mediaType = new MediaTypes(); if ($devPort->ConnectedDeviceID > 0 || $devPort->Notes != "") { $targetDev->DeviceID = $devPort->ConnectedDeviceID; $targetDev->GetDevice();