From 651ba35ac49ad6064183a78d6bbc6b1b09a24906 Mon Sep 17 00:00:00 2001 From: wilpig Date: Wed, 3 Jul 2013 22:52:15 -0500 Subject: [PATCH 1/2] Moving some of the port methods around and corrected a JS timing bug with the datacenter menu tree. #191 --- assets.inc.php | 98 +++++++++++++++++++++++++++----------------------- devices.php | 15 +++++--- rowview.php | 19 ++++++---- 3 files changed, 78 insertions(+), 54 deletions(-) diff --git a/assets.inc.php b/assets.inc.php index abcacd412..66d444229 100644 --- a/assets.inc.php +++ b/assets.inc.php @@ -1038,6 +1038,8 @@ function CreateDevice( $db = null ) { $this->DeviceID = $dbh->lastInsertId(); + DevicePorts::createPorts($dev->DeviceID); + (class_exists('LogActions'))?LogActions::LogThis($this):''; return $this->DeviceID; @@ -1902,6 +1904,53 @@ function createPort() { return true; } + static function createPorts($DeviceID){ + $dev=New Device; + $dev->DeviceID=$DeviceID; + if(!$dev->GetDevice()){return false;} + + // Build the DevicePorts from the existing info in the following priority: + // - Existing switchconnection table + // - SNMP data (if it exists) + // - Placeholders + if($dev->DeviceType=="Switch"){ + $swCon=new SwitchConnection(); + $swCon->SwitchDeviceID=$dev->DeviceID; + + $nameList=SwitchInfo::getPortNames($dev->DeviceID); + $aliasList=SwitchInfo::getPortAlias($dev->DeviceID); + + for( $n=0; $n<$dev->Ports; $n++ ){ + $i=$n+1; + $portList[$i]=new DevicePorts(); + $portList[$i]->DeviceID=$dev->DeviceID; + $portList[$i]->PortNumber=$i; + $portList[$i]->Label=@$nameList[$n]; + $portList[$i]->Notes=@$aliasList[$n]; + + $portList[$i]->CreatePort(); + } + }else{ + for( $n=0; $n<$dev->Ports; $n++ ){ + $i=$n+1; + $portList[$i]=new DevicePorts(); + $portList[$i]->DeviceID=$dev->DeviceID; + $portList[$i]->PortNumber=$i; + + $portList[$n]->CreatePort(); + if($dev->DeviceType=="Patch Panel"){ + $i=$i*-1; + $portList[$i]=new DevicePorts(); + $portList[$i]->DeviceID=$dev->DeviceID; + $portList[$i]->PortNumber=$i; + + $portList[$i]->CreatePort(); + } + } + } + return $portList; + } + function updatePort() { global $dbh; @@ -2110,61 +2159,22 @@ static function getPatchCandidates($DeviceID,$PortNum=null,$listports=null,$patc static function getPortList($DeviceID){ global $dbh; - if(intval($DeviceID) <1){ - return false; - } - - $dev = new Device(); - $dev->DeviceID = $DeviceID; + $dev=new Device(); + $dev->DeviceID=$DeviceID; if(!$dev->GetDevice()){ return false; // This device doesn't exist } $sql="SELECT * FROM fac_Ports WHERE DeviceID=$dev->DeviceID;"; - $portList = array(); - + $portList=array(); foreach($dbh->query($sql) as $row){ $portList[$row['PortNumber']]=DevicePorts::RowToObject($row); } if( sizeof($portList)==0 && $dev->DeviceType!="Physical Infrastructure" ){ - // Build the DevicePorts from the existing info in the following priority: - // - Existing switchconnection table - // - SNMP data (if it exists) - // - Placeholders - if($dev->DeviceType=="Switch"){ - $swCon=new SwitchConnection(); - $swCon->SwitchDeviceID=$dev->DeviceID; - - $nameList=SwitchInfo::getPortNames($dev->DeviceID); - $aliasList=SwitchInfo::getPortAlias($dev->DeviceID); - - for( $n=0; $n<$dev->Ports; $n++ ){ - $portList[$n]=new DevicePorts(); - $portList[$n]->DeviceID=$dev->DeviceID; - $portList[$n]->PortNumber=$n+1; - $portList[$n]->Label=@$nameList[$n]; - - $swCon->SwitchPortNumber=$n+1; - if($swCon->GetConnectionRecord()){ - $portList[$n]->Notes=$swCon->Notes; - }else{ - $portList[$n]->Notes=$aliasList[$n]; - } - - $portList[$n]->CreatePort(); - } - }else{ - for( $n=0; $n<$dev->Ports; $n++ ){ - $portList[$n]=new DevicePorts(); - $portList[$n]->DeviceID=$dev->DeviceID; - $portList[$n]->PortNumber=$n+1; - $portList[$n]->Label=@$nameList[$n]; - - $portList[$n]->CreatePort(); - } - } + // somehow this device doesn't have ports so make them now + $portList=DevicePorts::createPorts($dev->DeviceID); } return $portList; diff --git a/devices.php b/devices.php index 5361984ea..53963a395 100644 --- a/devices.php +++ b/devices.php @@ -1629,10 +1629,17 @@ function setPreferredLayout() { diff --git a/rowview.php b/rowview.php index 4c94cd4d3..7ed88dcb7 100644 --- a/rowview.php +++ b/rowview.php @@ -373,12 +373,19 @@ function get_cabinet_owner_color($cabinet, &$deptswithcolor) {
From 25f313ce6b86072f44b61042f7210e087a8e1765 Mon Sep 17 00:00:00 2001 From: wilpig Date: Thu, 4 Jul 2013 04:11:44 -0500 Subject: [PATCH 2/2] I think i've built into the UpdateDevice method all the possible scenarios that a S.U.T. could create. Moving back to the UI portion. #191 --- assets.inc.php | 74 ++++++++++++++++++++++++++++++++++++++++++-------- devices.php | 46 +++++++++++++++---------------- 2 files changed, 85 insertions(+), 35 deletions(-) diff --git a/assets.inc.php b/assets.inc.php index 66d444229..4c9ab3520 100644 --- a/assets.inc.php +++ b/assets.inc.php @@ -1038,7 +1038,7 @@ function CreateDevice( $db = null ) { $this->DeviceID = $dbh->lastInsertId(); - DevicePorts::createPorts($dev->DeviceID); + DevicePorts::createPorts($this->DeviceID); (class_exists('LogActions'))?LogActions::LogThis($this):''; @@ -1204,20 +1204,70 @@ function UpdateDevice() { return; } } + + // If we made it to a device update and the number of ports available don't match the device, just fix it. + if($tmpDev->Ports!=$this->Ports){ + if($tmpDev->Ports>$this->Ports){ // old device has more ports + for($n=$this->Ports; $n<$tmpDev->Ports; $n++){ + $p=new DevicePorts; + $p->DeviceID=$this->DeviceID; + $p->PortNumber=$n+1; + $p->removePort(); + if($this->DeviceType=='Patch Panel'){ + $p->PortNumber=$p->PortNumber*-1; + $p->removePort(); + } + } + }else{ // new device has more ports + for($n=$tmpDev->Ports; $n<$this->Ports; ++$n){ + $p=new DevicePorts; + $p->DeviceID=$this->DeviceID; + $p->PortNumber=$n+1; + $p->createPort(); + if($this->DeviceType=='Patch Panel'){ + $p->PortNumber=$p->PortNumber*-1; + $p->createPort(); + } + } + + } + } if(($tmpDev->DeviceType=="Switch" || $tmpDev->DeviceType=="Patch Panel") && $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(); - $tmpSw->DropEndpointConnections(); + DevicePorts::removeConnections($this->DeviceID); } - if($tmpDev->DeviceType=="Patch Panel"){ - $tmpPan=new PatchConnetion(); - $tmpPan->DropPanelConnections(); - $tmpPan->DropEndpointConnections(); + DevicePorts::removeConnections($this->DeviceID); + $p=new DevicePorts(); + $p->DeviceID=$this->DeviceID; + $ports=$p->getPorts(); + foreach($ports as $i => $port){ + if($port->PortNumber<0){ + $port->removePort(); + } + } + } + } + if($this->DeviceType == "Patch Panel" && $tmpDev->DeviceType != $this->DeviceType){ + // This asshole just changed a switch or something into a patch panel. Make the rear ports. + $p=new DevicePorts(); + $p->DeviceID=$this->DeviceID; + if($tmpDev->Ports!=$this->Ports && $tmpDev->Ports<$this->Ports){ + // since we just made the new rear ports up there only make the first few, hopefully. + for($n=1;$n<=$tmpDev->Ports;$n++){ + $i=$n*-1; + $p->PortNumber=$i; + $p->createPort(); + } + }else{ + // make a rear port to match every front port + $ports=$p->getPorts(); + foreach($ports as $i => $port){ + $port->PortNumber=$port->PortNumber*-1; + $port->createPort(); + } } } @@ -1928,7 +1978,7 @@ static function createPorts($DeviceID){ $portList[$i]->Label=@$nameList[$n]; $portList[$i]->Notes=@$aliasList[$n]; - $portList[$i]->CreatePort(); + $portList[$i]->createPort(); } }else{ for( $n=0; $n<$dev->Ports; $n++ ){ @@ -1937,14 +1987,14 @@ static function createPorts($DeviceID){ $portList[$i]->DeviceID=$dev->DeviceID; $portList[$i]->PortNumber=$i; - $portList[$n]->CreatePort(); + $portList[$i]->createPort(); if($dev->DeviceType=="Patch Panel"){ $i=$i*-1; $portList[$i]=new DevicePorts(); $portList[$i]->DeviceID=$dev->DeviceID; $portList[$i]->PortNumber=$i; - $portList[$i]->CreatePort(); + $portList[$i]->createPort(); } } } diff --git a/devices.php b/devices.php index 53963a395..bcc053bb1 100644 --- a/devices.php +++ b/devices.php @@ -302,10 +302,6 @@ $pwrConnection->DeviceID=($dev->ParentDevice>0)?$dev->ParentDevice:$dev->DeviceID; $pwrCords=$pwrConnection->GetConnectionsByDevice($facDB); - $portList=DevicePorts::getPortList($dev->DeviceID); - $mediaTypes=MediaTypes::GetMediaTypeList(); - $colorCodes=ColorCoding::GetCodeList(); - if($dev->DeviceType=='Switch'){ $linkList = SwitchInfo::getPortStatus( $dev->DeviceID ); } @@ -314,6 +310,11 @@ $patchList=array(); $panelList=array(); } + // ports apply to copied devices under the new model + $portList=DevicePorts::getPortList($dev->DeviceID); + $mediaTypes=MediaTypes::GetMediaTypeList(); + $colorCodes=ColorCoding::GetCodeList(); + } $cab->CabinetID=$dev->Cabinet; $cab->GetCabinet($facDB); @@ -822,20 +823,21 @@ function refreshswitch(devid,names){ console.log('how would they manage to trigger this condition? I mean really.'); }else{ //S.U.T. present options to remove ports - $('div.switch').css('position','relative'); - var h=$('div.switch > div:first-child + div > div:first-child').outerHeight(); + var row=$('.switch > div:first-child > div:first-child').parent('div'); var icon=$('').addClass('ui-icon').addClass('status').addClass('down'); + $('
').prependTo(row); $('.switch div:first-child[id^=sp]').each(function(){ + row=$(this).parent('div'); // this idea is crap and needs to be thought out better but it's time to go home so i'm submitting since it won't break anything - $('
',{'id': 'kp'+$(this).text()}).css({ - 'position': 'absolute', - 'left': -(h + 3)+'px', - 'top' : ((h * parseInt($(this).text())) + (h-16) )+'px', - 'border' : 0 - }).outerHeight(h).outerWidth(h).append(icon.clone()).appendTo($('div.switch')); + $('
',{'id': 'kp'+$(this).text()}).append(icon.clone()).click({row: row},deletethis).prependTo(row); }); } }); + function deletethis(e){ + console.log(e.data.row); + + + } $('#reservation').change(function(){ if(!$(this).prop("checked")){ var d=new Date(); @@ -1543,23 +1545,21 @@ function setPreferredLayout() {".__("Color Code")."
\n"; - for ( $n = 0; $n < sizeof( $portList ); $n++ ) { - $i = $n + 1; // The "port number" starting at 1 - + foreach($portList as $i => $port){ $tmpDev=new Device(); - $tmpDev->DeviceID=$portList[$i]->ConnectedDeviceID; - $tmpDev->GetDevice($facDB); + $tmpDev->DeviceID=$port->ConnectedDeviceID; + $tmpDev->GetDevice(); - $mt=(isset($mediaTypes[$portList[$i]->MediaID]))?$mediaTypes[$portList[$i]->MediaID]->MediaType:''; - $cc=(isset($colorCodes[$portList[$i]->ColorID]))?$colorCodes[$portList[$i]->ColorID]->Name:''; + $mt=(isset($mediaTypes[$port->MediaID]))?$mediaTypes[$port->MediaID]->MediaType:''; + $cc=(isset($colorCodes[$port->ColorID]))?$colorCodes[$port->ColorID]->Name:''; // the data attribute is used to store the previous value of the connection print "\t\t\t\t
$i
-
{$portList[$i]->Label}
- -
ConnectedPort}\">{$portList[$i]->ConnectedPort}
-
Notes}\">{$portList[$i]->Notes}
"; +
{$port->Label}
+ +
ConnectedPort}\">{$port->ConnectedPort}
+
Notes}\">{$port->Notes}
"; if($dev->DeviceType=='Switch'){print "\t\t\t\t
";} print "\t\t\t\t
$mt
$cc