Exemple #1
0
 function updatePort($fasttrack = false)
 {
     global $dbh;
     $oldport = new DevicePorts();
     // originating port prior to modification
     $oldport->DeviceID = $this->DeviceID;
     $oldport->PortNumber = $this->PortNumber;
     $oldport->getPort();
     $tmpport = new DevicePorts();
     // connecting to here
     $tmpport->DeviceID = $this->ConnectedDeviceID;
     $tmpport->PortNumber = $this->ConnectedPort;
     $tmpport->getPort();
     $dev = new Device();
     $dev->DeviceID = $this->DeviceID;
     $dev->GetDevice();
     // This is gonna be a hack for updating a port when we don't want a recursion loop
     // I'll likely remove the makeConnection method after this
     if (!$fasttrack) {
         $oldtmpport = new DevicePorts();
         // used for logging
         $oldtmpport->DeviceID = $oldport->ConnectedDeviceID;
         $oldtmpport->PortNumber = $oldport->ConnectedPort;
         $oldtmpport->getPort();
         //check rights before we go any further
         $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;
             $tmpport->MediaID = $this->MediaID;
             $tmpport->ColorID = $this->ColorID;
             $tmpport->updatePort(true);
             // The three lines above were added to sync media and color types with the connection
             //			DevicePorts::makeConnection($tmpport,$this);
         }
     }
     // update port
     $sql = "UPDATE fac_Ports SET MediaID={$this->MediaID}, ColorID={$this->ColorID}, \r\n\t\t\tPortNotes=\"{$this->PortNotes}\", ConnectedDeviceID={$this->ConnectedDeviceID}, \r\n\t\t\tLabel=\"{$this->Label}\", ConnectedPort={$this->ConnectedPort}, \r\n\t\t\tNotes=\"{$this->Notes}\" WHERE DeviceID={$this->DeviceID} AND \r\n\t\t\tPortNumber={$this->PortNumber};";
     if (!$dbh->query($sql)) {
         $info = $dbh->errorInfo();
         error_log("updatePort::PDO Error: {$info[2]} SQL={$sql}");
         return false;
     }
     // If this is a patch panel and a front port then set the label on the rear
     // to match only after a successful update, done above.
     if ($dev->DeviceType == "Patch Panel" && $this->PortNumber > 0 && $this->Label != $oldport->Label) {
         $pport = new DevicePorts();
         $pport->DeviceID = $this->DeviceID;
         $pport->PortNumber = -$this->PortNumber;
         $pport->getPort();
         $pport->Label = $this->Label;
         $pport->updateLabel();
     }
     // two logs, because we probably modified two devices
     class_exists('LogActions') ? LogActions::LogThis($this, $oldport) : '';
     if (!$fasttrack) {
         class_exists('LogActions') ? LogActions::LogThis($tmpport, $oldtmpport) : '';
     }
     return true;
 }
Exemple #2
0
                $port->updateLabel();
            }
        }
        echo json_encode(SwitchInfo::getPortNames($_POST['refreshswitch']));
    } elseif (isset($_POST['Notes'])) {
        $dev->DeviceID = $_POST['refreshswitch'];
        $dev->GetDevice();
        // This function should be hidden if they don't have rights, but just in case
        if ($dev->Rights == "Write") {
            foreach (SwitchInfo::getPortAlias($_POST['refreshswitch']) as $PortNumber => $Notes) {
                $port = new DevicePorts();
                $port->DeviceID = $_POST['refreshswitch'];
                $port->PortNumber = $PortNumber;
                $port->getPort();
                $port->Notes = $Notes;
                $port->updatePort();
            }
        }
        echo json_encode(SwitchInfo::getPortAlias($_POST['refreshswitch']));
    } else {
        echo json_encode(SwitchInfo::getPortStatus($_POST['refreshswitch']));
    }
    exit;
}
if (isset($_POST["currwatts"]) && isset($_POST['pduid']) && $_POST['pduid'] > 0) {
    $pdu = new PowerDistribution();
    $pdu->PDUID = $_POST['pduid'];
    $wattage->Wattage = 'Err';
    $wattage->LastRead = 'Err';
    if ($pdu->GetPDU()) {
        $cab->CabinetID = $pdu->CabinetID;