Skip to content

Commit

Permalink
Merge pull request #1 from samilliken/master
Browse files Browse the repository at this point in the history
Samiliken
  • Loading branch information
jomigom committed Jul 4, 2013
2 parents 8623f36 + 25f313c commit 6b4bac0
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 85 deletions.
164 changes: 112 additions & 52 deletions assets.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,8 @@ function CreateDevice( $db = null ) {

$this->DeviceID = $dbh->lastInsertId();

DevicePorts::createPorts($this->DeviceID);

(class_exists('LogActions'))?LogActions::LogThis($this):'';

return $this->DeviceID;
Expand Down Expand Up @@ -1202,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();
}
}
}

Expand Down Expand Up @@ -1902,6 +1954,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[$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();
}
}
}
return $portList;
}

function updatePort() {
global $dbh;

Expand Down Expand Up @@ -2110,61 +2209,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;
Expand Down
61 changes: 34 additions & 27 deletions devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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);
Expand Down Expand Up @@ -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=$('<span>').addClass('ui-icon').addClass('status').addClass('down');
$('<div>').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
$('<div>',{'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'));
$('<div>',{'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();
Expand Down Expand Up @@ -1543,23 +1545,21 @@ function setPreferredLayout() {<?php if(isset($_COOKIE["layout"]) && strtolower(
<div>".__("Color Code")."</div>
</div>\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<div>
<div id=\"sp$i\">$i</div>
<div id=\"spn$i\">{$portList[$i]->Label}</div>
<div id=\"d$i\" data-default=\"{$portList[$i]->ConnectedDeviceID}\"><a href=\"devices.php?deviceid={$portList[$i]->ConnectedDeviceID}\">$tmpDev->Label</a></div>
<div id=\"dp$i\" data-default=\"{$portList[$i]->ConnectedPort}\">{$portList[$i]->ConnectedPort}</div>
<div id=\"n$i\" data-default=\"{$portList[$i]->Notes}\">{$portList[$i]->Notes}</div>";
<div id=\"spn$i\">{$port->Label}</div>
<div id=\"d$i\" data-default=\"{$port->ConnectedDeviceID}\"><a href=\"devices.php?deviceid={$port->ConnectedDeviceID}\">$tmpDev->Label</a></div>
<div id=\"dp$i\" data-default=\"{$port->ConnectedPort}\">{$port->ConnectedPort}</div>
<div id=\"n$i\" data-default=\"{$port->Notes}\">{$port->Notes}</div>";
if($dev->DeviceType=='Switch'){print "\t\t\t\t<div id=\"st$i\"><span class=\"ui-icon status {$linkList[$i]}\"></span></div>";}
print "\t\t\t\t<div id=\"mt$i\">$mt</div>
<div id=\"cc$i\">$cc</div>
Expand Down Expand Up @@ -1629,10 +1629,17 @@ function setPreferredLayout() {<?php if(isset($_COOKIE["layout"]) && strtolower(
</div><!-- END div.page -->
<script type="text/javascript">
$(document).ready(function() {
// wait half a second after the page loads then open the tree
setTimeout(function(){
expandToItem('datacenters','cab<?php echo $cab->CabinetID;?>');
},500);
// Don't attempt to open the datacenter tree until it is loaded
function opentree(){
if($('#datacenters .bullet').length==0){
setTimeout(function(){
opentree();
},500);
}else{
expandToItem('datacenters','cab<?php echo $cab->CabinetID;?>');
}
}
opentree();
});
</script>

Expand Down
19 changes: 13 additions & 6 deletions rowview.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,19 @@ function get_cabinet_owner_color($cabinet, &$deptswithcolor) {
<div class="clear"></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
// wait half a second after the page loads then open the tree
setTimeout(function(){
expandToItem('datacenters','cab<?php echo $cab->CabinetID;?>');
},500);
});
$(document).ready(function() {
// Don't attempt to open the datacenter tree until it is loaded
function opentree(){
if($('#datacenters .bullet').length==0){
setTimeout(function(){
opentree();
},500);
}else{
expandToItem('datacenters','cab<?php echo $cab->CabinetID;?>');
}
}
opentree();
});
</script>
</body>
</html>

0 comments on commit 6b4bac0

Please sign in to comment.