diff --git a/misc.inc.php b/misc.inc.php index c8d82ae4e..ceb2a519f 100644 --- a/misc.inc.php +++ b/misc.inc.php @@ -1009,6 +1009,7 @@ function buildnavmenu($ma,&$tl){ $samenu[__("Power Management")][]=''.__("Edit Power Panels").''; $samenu[__("Path Connections")][]=''.__("View Path Connection").''; $samenu[__("Path Connections")][]=''.__("Make Path Connection").''; + $samenu[__("Path Connections")][]=''.__("Make Rear Connection").''; $samenu[]=''.__("Edit Configuration").''; } if( AUTHENTICATION == "LDAP" ) { diff --git a/rear_connection.php b/rear_connection.php new file mode 100644 index 000000000..d21982b3d --- /dev/null +++ b/rear_connection.php @@ -0,0 +1,498 @@ +GetDCList(); + $idnum=''; + + if(!is_null($id)){ + if($id=="dc-front"){ + $idnum=1; + }elseif($id=="dc-rear"){ + $idnum=2; + } + $id=" name=\"$id\" id=\"$id\""; + } + + $dcpicklist="'; + + return $dcpicklist; + } + + function portNumberIsInPortArray($portNumber, $array){ + foreach($array as $port){ + if($port->PortNumber == $portNumber){ + return true; + } + } + return false; + } + + // AJAX - Start + + function displayjson($array){ + header('Content-Type: application/json'); + echo json_encode($array); + exit; + } + + if(isset($_POST['dc'])){ + $cab=new Cabinet(); + $cab->DataCenterID=$_POST['dc']; + + displayjson($cab->ListCabinetsByDC()); + } + + if(isset($_POST['cab'])){ + $dev=new Device(); + $dev->Cabinet=$_POST['cab']; + + // Filter devices by rights and only show the Patch Panel + $devs=array(); + foreach($dev->ViewDevicesByCabinet(true) as $d){ + if($d->Rights=="Write" && $d->DeviceType=="Patch Panel"){ + $devs[]=$d; + } + } + displayjson($devs); + } + + if(isset($_POST['dev'])){ + $dp=new DevicePorts(); + $dp->DeviceID=$_POST['dev']; + $dev=new Device(); + $dev->DeviceID=$dp->DeviceID; + $dev->GetDevice(); + $ports=($dev->Rights=="Write")?$dp->getAvailableRearPorts():array(); + displayjson($ports); + } + + if(isset($_POST['actionValidation'])){ + $status = array(); + if(!(isset($_POST['devid1']) && $_POST['devid1']!=0)){ + $status[]=__("Initial device unspecified"); + } + if(!isset($_POST['port1']) || $_POST['port1']==''){ + $status[]=__("Initial device port unspecified"); + } + if(!(isset($_POST['devid2']) && $_POST['devid2']!=0)){ + $status[]=__("Final device unspecified"); + } + if(!isset($_POST['port2']) || $_POST['port2']==''){ + $status[]=__("Final device unspecified"); + } + if(!isset($_POST['numberOfPorts']) || $_POST['numberOfPorts']==''){ + $status[]=__("Number of ports not specified"); + } + if(empty($status)){ + //Getting number of connection to make + $numberOfPath = $_POST['numberOfPorts']; + $port1Number = intval($_POST['port1']); + $port2Number = intval($_POST['port2']); + + //INITIAL DEVICE + $dev=new Device(); + $dev->DeviceID=intval($_POST['devid1']); + $dev->GetDevice(); + + //FINAL DEVICE + $finDev=new Device(); + $finDev->DeviceID=intval($_POST['devid2']); + $finDev->GetDevice(); + + $dp=new DevicePorts(); + $dp->DeviceID=$dev->DeviceID; + + $portsDevArray = $dp->getAvailableRearPorts(); + + $dp->DeviceID = $finDev->DeviceID; + + $portsFinDevArray = $dp->getAvailableRearPorts(); + + $port1=new DevicePorts(); + $port2=new DevicePorts(); + + $port1->DeviceID=$dev->DeviceID; + $port2->DeviceID=$finDev->DeviceID; + + $port1NumberOfRearPorts = $port1->getNumberOfRearPorts(); + $port2NumberOfRearPorts = $port2->getNumberOfRearPorts(); + + //Temp port to do the testings of overriding ports + $tempPort1 = $port1Number; + $tempPort2 = $port2Number; + + $hasExceedInit = false; + $hasExceedFinal = false; + //Validate if we override used ports or if we exceed the port number. + for($i = 0; $i < $numberOfPath; $i++){ + + if($hasExceedInit = abs($tempPort1) == $port1NumberOfRearPorts + 1){ + $status[] = "Exceed initial"; + + } + if($hasExceedFinal = abs($tempPort2) == $port2NumberOfRearPorts + 1){ + $status[] = "Exceed final"; + } + + if($hasExceedFinal || $hasExceedInit){ + break; + } + + if(!portNumberIsInPortArray($tempPort1, $portsDevArray)){ + $status[] = "Override init"; + } + if(!portNumberIsInPortArray($tempPort2, $portsFinDevArray)){ + $status[] = "Override final"; + } + + $tempPort1--; + $tempPort2--; + } + + } + + //Return the error code. + displayjson($status); + } + + // AJAX - End + + if(!$person->SiteAdmin){ + // No soup for you. + header('Location: '.redirect()); + exit; + } + + //This is executed after the validation, but it is always good to do a double validation of the requiered fields. + if(isset($_POST['create_connection_after_validation'])){ + if((isset($_POST['devid1']) && $_POST['devid1']!=0) + && isset($_POST['port1']) && $_POST['port1']!='' + && (isset($_POST['devid2']) && $_POST['devid2']!=0) + && (isset($_POST['port2']) && $_POST['port2']!='') + && isset($_POST['numberOfPorts']) && $_POST['numberOfPorts']!=''){ + + //Getting number of connection to make + $numberOfPath = $_POST['numberOfPorts']; + $port1Number = intval($_POST['port1']); + $port2Number = intval($_POST['port2']); + + //INITIAL DEVICE + $dev=new Device(); + $dev->DeviceID=intval($_POST['devid1']); + + //FINAL DEVICE + $finDev=new Device(); + $finDev->DeviceID=intval($_POST['devid2']); + + $connectionMaker = new RearConnectionMaker($dev->DeviceID, $finDev->DeviceID, $port1Number, $port2Number, $numberOfPath); + $connectionMaker->MakeConnections(); + $additionalInfo = $connectionMaker->GetTable(); + + } else { + if(!(isset($_POST['devid1']) && $_POST['devid1']!=0)){ + $status=__("Initial device unspecified"); + }elseif(!isset($_POST['port1']) || $_POST['port1']==''){ + $status=__("Initial device port unspecified"); + }elseif(!(isset($_POST['devid2']) && $_POST['devid2']!=0)){ + $status=__("Final device unspecified"); + }elseif(!isset($_POST['port2']) || $_POST['port2']==''){ + $status=__("Final device port unspecified"); + }elseif(!isset($_POST['numberOfPorts']) || $_POST['numberOfPorts']==''){ + $status=__("Number of ports not specified"); + }else{ + $status=__("Unknown Error"); + } + } + } + + //We send the output table we want to show to JQuery so we can show it without refreshing the page. + if(isset($_POST['create_connection_after_validation'])){ + displayjson($additionalInfo); + } +?> + + +
+ + + + +