From ac7fb36b9f87397064db4ff10fbc40eaa28a15b1 Mon Sep 17 00:00:00 2001 From: wilpig Date: Fri, 17 May 2013 21:43:45 -0500 Subject: [PATCH] Update SQL methods. Moved IP address field out of esx options to primary device options. #164 close #189 --- assets.inc.php | 56 ++++++++++++++++++++++++-------------------------- config.inc.php | 11 +++++----- devices.php | 8 ++++---- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/assets.inc.php b/assets.inc.php index dccc1ebdf..528c33d96 100644 --- a/assets.inc.php +++ b/assets.inc.php @@ -1025,48 +1025,48 @@ function MoveToStorage( $db ) { } } - function UpdateDevice( $db ) { + function UpdateDevice($db=null){ + global $dbh; // Stupid User Tricks #417 - A user could change a device that has connections (switch or patch panel) to one that doesn't // Stupid User Tricks #148 - A user could change a device that has children (chassis) to one that doesn't // // As a "safety mechanism" we simply won't allow updates if you try to change a chassis IF it has children // For the switch and panel connections, though, we drop any defined connections - $tmpDev = new Device(); - $tmpDev->DeviceID = $this->DeviceID; - $tmpDev->GetDevice( $db ); + $tmpDev=new Device(); + $tmpDev->DeviceID=$this->DeviceID; + $tmpDev->GetDevice($db); - if ( $tmpDev->DeviceType == "Chassis" && $tmpDev->DeviceType != $this->DeviceType ) { + if($tmpDev->DeviceType == "Chassis" && $tmpDev->DeviceType != $this->DeviceType){ // SUT #148 - Previously defined chassis is no longer a chassis // If it has children, return with no update - $childList = $this->GetDeviceChildren( $db ); - if ( sizeof( $childList ) > 0 ) { - $this->GetDevice( $db ); + $childList=$this->GetDeviceChildren($db); + if(sizeof($childList)>0){ + $this->GetDevice($db); return; } } - if ( ( $tmpDev->DeviceType == "Switch" || $tmpDev->DeviceType == "Patch Panel" ) && $tmpDev->DeviceType != $this->DeviceType ) { + if(($tmpDev->DeviceType=="Switch" || $tmpDev->DeviceType=="PatchPanel") && $tmpDev->DeviceType!=$this->DeviceType){ // SUT #417 - Changed a Switch or Patch Panel to something else (even if you change a switch to a Patch Panel, the connections are different) - if ( $tmpDev->DeviceType == "Switch" ) { - $tmpSw = new SwitchConnection(); - $tmpSw->SwitchDeviceID = $tmpDev->DeviceID; - $tmpSw->DropSwitchConnections( $db ); - $tmpSw->DropEndpointConnections( $db ); + if($tmpDev->DeviceType=="Switch"){ + $tmpSw=new SwitchConnection(); + $tmpSw->SwitchDeviceID=$tmpDev->DeviceID; + $tmpSw->DropSwitchConnections($db); + $tmpSw->DropEndpointConnections($db); } - if ( $tmpDev->DeviceType == "Patch Panel" ) { - $tmpPan = new PatchConnetion(); - $tmpPan->DropPanelConnections( $db ); - $tmpPan->DropEndpointConnections( $db ); + if($tmpDev->DeviceType=="PatchPanel"){ + $tmpPan=new PatchConnetion(); + $tmpPan->DropPanelConnections($db); + $tmpPan->DropEndpointConnections($db); } } // Force all uppercase for labels - // - $this->Label = transform( $this->Label ); - $this->SerialNo = transform( $this->SerialNo ); - $this->AssetTag = transform( $this->AssetTag ); + $this->Label=transform($this->Label); + $this->SerialNo=transform($this->SerialNo); + $this->AssetTag=transform($this->AssetTag); //Keep weird values out of DeviceType if(!in_array($this->DeviceType,array('Server','Appliance','StorageArray','Switch','Chassis','PatchPanel','PhysicalInfrastructure'))){ @@ -1074,9 +1074,8 @@ function UpdateDevice( $db ) { } // You can't update what doesn't exist, so check for existing record first and retrieve the current location - $select_sql = "select * from fac_Device where DeviceID=\"" . $this->DeviceID . "\""; - $result=mysql_query($select_sql,$db); - if($row=mysql_fetch_array($result)){ + $select_sql = "SELECT * FROM fac_Device WHERE DeviceID=\"$this->DeviceID\";"; + foreach($dbh->query($select_sql) as $row){ // If you changed cabinets then the power connections need to be removed if($row["Cabinet"]!=$this->Cabinet){ $powercon=new PowerConnection(); @@ -1096,11 +1095,10 @@ function UpdateDevice( $db ) { WarrantyExpire=\"".date("Y-m-d", strtotime($this->WarrantyExpire))."\", Notes=\"$this->Notes\", Reservation=\"$this->Reservation\" WHERE DeviceID=$this->DeviceID;"; } - - if(!$result=mysql_query($update_sql,$db)){ - // Error occurred - return -1; + if(!$dbh->exec($update_sql)){ + return false; } + return 0; } diff --git a/config.inc.php b/config.inc.php index 6c654a809..ca77a2cca 100644 --- a/config.inc.php +++ b/config.inc.php @@ -55,12 +55,11 @@ function UpdateConfig($db){ static function RevertToDefault($db, $parameter){ global $dbh; - if ($parameter=='none'){ - $sql='update fac_Config set Value=DefaultVal'; - } - else{ - $sql='update fac_Config set Value=DefaultVal where Parameter = \''.$parameter.'\''; - } + if($parameter=='none'){ + $sql='UPDATE fac_Config SET Value=DefaultVal;'; + }else{ + $sql="UPDATE fac_Config SET Value=DefaultVal WHERE Parameter=\"$parameter\";"; + } $dbh->query($sql); return; diff --git a/devices.php b/devices.php index dc79b276c..45db421cb 100644 --- a/devices.php +++ b/devices.php @@ -1113,6 +1113,10 @@ function setPreferredLayout() { +
+
+
+
@@ -1380,10 +1384,6 @@ function setPreferredLayout() {
-
-
-
-