Skip to content

Commit

Permalink
Update SQL methods. Moved IP address field out of esx options to prim…
Browse files Browse the repository at this point in the history
…ary device options. opendcim#164 close opendcim#189
  • Loading branch information
wilpig committed May 18, 2013
1 parent b533a39 commit ac7fb36
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
56 changes: 27 additions & 29 deletions assets.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1025,58 +1025,57 @@ 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'))){
$this->DeviceType="Server";
}

// 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();
Expand All @@ -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;
}

Expand Down
11 changes: 5 additions & 6 deletions config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,10 @@ function setPreferredLayout() {<?php if(isset($_COOKIE["layout"]) && strtolower(
<div><input type="text" name="assettag" id="assettag" size="20" value="'.$dev->AssetTag.'">
<button class="hide" type="button" onclick="getScan(\'assettag\')">',__("Scan Barcode"),'</button></div>
</div>
<div>
<div><label for="primaryip">'.__("Primary IP").'</label></div>
<div><input type="text" name="primaryip" id="primaryip" size="20" value="'.$dev->PrimaryIP.'"></div>
</div>
<div>
<div><label for="mfgdate">'.__("Manufacture Date").'</label></div>
<div><input type="text" class="validate[optional,custom[date]] datepicker" name="mfgdate" id="mfgdate" value="'.(($dev->MfgDate>'0000-00-00 00:00:00')?date('m/d/Y',strtotime($dev->MfgDate)):"").'">
Expand Down Expand Up @@ -1380,10 +1384,6 @@ function setPreferredLayout() {<?php if(isset($_COOKIE["layout"]) && strtolower(
<div><label for="esx">'.__("ESX Server?").'</label></div>
<div><select name="esx" id="esx"><option value="1"'.(($dev->ESX==1)?" selected":"").'>'.__("True").'</option><option value="0"'.(($dev->ESX==0)?" selected":"").'>'.__("False").'</option></select></div>
</div>
<div>
<div><label for="primaryip">'.__("Primary IP").'</label></div>
<div><input type="text" name="primaryip" id="primaryip" size="20" value="'.$dev->PrimaryIP.'"></div>
</div>
<div>
<div><label for="snmpcommunity">'.__("SNMP Read Only Community").'</label></div>
<div><input type="text" name="snmpcommunity" id="snmpcommunity" size="40" value="'.$dev->SNMPCommunity.'"></div>
Expand Down

0 comments on commit ac7fb36

Please sign in to comment.