diff --git a/classes/DevicePorts.class.php b/classes/DevicePorts.class.php
index dc1cbf110..183789211 100644
--- a/classes/DevicePorts.class.php
+++ b/classes/DevicePorts.class.php
@@ -641,5 +641,30 @@ function LooseSearch($indexedbyid=false){
return $this->Search($indexedbyid,true);
}
+ // Returns the device at the end of the path
+ function GetEndPathDevice($deviceID, $portNumber){
+ global $dbh;
+
+ $path = DevicePorts::followPathToEndPoint($deviceID,$portNumber);
+
+ $dev= new Device;
+
+ foreach($path as $p){
+ $tempP = new DevicePorts;
+ $tempP->DeviceID = $p->ConnectedDeviceID;
+ $tempP->PortNumber = $p->ConnectedPort;
+ $tempP->getPort();
+ if(in_array($tempP,$path)){
+ $dev->DeviceID = $p->DeviceID;
+ $dev->GetDevice();
+ }
+ }
+ if($dev->DeviceID == null){
+ $dev = null;
+ }
+
+ return $dev;
+ }
+
}
?>
diff --git a/devices.php b/devices.php
index 865601201..97d227462 100644
--- a/devices.php
+++ b/devices.php
@@ -550,6 +550,92 @@ function updatedevice($devid){
echo json_encode($wattage);
exit;
}
+
+ //GetPotentialPathsToDelete
+ if(isset($_POST['getpptd']))
+ {
+ function GetPotentialPathsToDelete($DeviceID)
+ {
+ // Data type being made [DeviceID(int),portNumber(int),Label(String),Status(enum-int)]
+ //Status Enum
+ // Check=0
+ // Unchecked = 1
+ // ForceCheck=2
+ // ForceUnChecked=3
+
+ $pathsToRemove = array();
+ $dev = new Device;
+ $dev->DeviceID=$DeviceID;
+ $dev->GetDevice();
+ $numPorts = $dev->Ports;
+ $startPortNum = 1;
+ if($dev->DeviceType == "Chassis"){
+ $childDevices = $dev->GetDeviceChildren();
+ foreach($childDevices as $device){
+ $childPaths = json_decode(GetPotentialPathsToDelete($device->DeviceID));
+ foreach($childPaths as $cp){
+ array_push($pathsToRemove,$cp);
+ }
+ }
+ }
+ else if ($dev->DeviceType == "Patch Panel"){
+ $startPortNum = $numPorts *-1;
+ }
+
+ if($dev->DeviceType != "Chasis")
+ {
+ for($portNumber = $startPortNum; $portNumber <= $numPorts; $portNumber++){
+ if($dev->DeviceType == "Patch Panel" && $portNumber == 0){$portNumber++;}
+ $enddev = DevicePorts::GetEndPathDevice($dev->DeviceID,$portNumber);
+ $paths = DevicePorts::followPathToEndPoint($dev->DeviceID,$portNumber);
+ $pp = new DevicePorts;//previous path
+ foreach($paths as $path){
+ $tp = new DevicePorts;
+ $tp->DeviceID=$path->ConnectedDeviceID;
+ $tp->PortNumber=$path->ConnectedPort;
+ $tp->getPort();
+ $conDev=new Device;
+ $conDev->DeviceID=$path->ConnectedDeviceID;
+ $conDev->GetDevice();
+ $startDev = new Device;
+ $startDev->DeviceID=$path->DeviceID;
+ $startDev->getDevice();
+
+ if( $path->ConnectedPort != null && $tp->DeviceID != null && $tp != $pp){
+ // By default all front connections are checked and uncheckable
+ // Change to 1 if it is wanted to be unchecked but checkable
+ $enumval = 0;
+ //Check if connection is coming from the device
+ // Make it required
+ if($dev->DeviceID == $startDev->DeviceID )
+ {$enumval=2;}
+ // Is a connection you will never remove by accident (ex a permanant connection)
+ // This example will never allow you to choose a back link to remove only front connections
+ // But it will still show rear connections but the checkboxs will be disabled
+ // Add conditions to not be able to remove a path here
+ else if($path->PortNumber<0)
+ {$enumval=3;}
+
+ array_push($pathsToRemove,array(
+ $startDev->DeviceID,
+ intval($path->PortNumber),
+ $startDev->Label." | ".$path->Label.($path->PortNumber<0?"(Rear)":"")." -> ".$conDev->Label." | ".$tp->Label.($path->PortNumber<0?"(Rear)":"")."",
+ $enumval
+ ));
+
+ $pp=$path;
+ }
+ }
+ }
+ }
+
+ return json_encode($pathsToRemove);
+ }
+ header('Content-Type: application/json');
+ echo GetPotentialPathsToDelete($_POST['getpptd']);
+ exit;
+ }
+
// END AJAX
// Not really AJAX calls since there's no return, but special actions
@@ -580,6 +666,22 @@ function updatedevice($devid){
$copyerr=__("This device is a copy of an existing device. Remember to set the new location before saving.");
$childList=array();
+ // Delete selected paths when deleting a device
+ // pci is a list of all the selected paths the user wanted to remove
+ // pic[0] = DeviceID pci[1] = PortNumber
+ if(isset($_REQUEST['pci'])&& $_REQUEST['pci'] != null)
+ {
+ foreach($_REQUEST['pci'] as $port)
+ {
+ $path = new DevicePorts();
+ $path->DeviceID=$port[0];
+ $path->PortNumber=$port[1];
+ $path->getPort();
+ $path->removeConnection();
+ }
+ exit;
+ }
+
// This page was called from somewhere so let's do stuff.
// If this page wasn't called then present a blank record for device creation.
if(isset($_REQUEST['action'])||isset($_REQUEST['DeviceID'])){
@@ -1668,26 +1770,85 @@ function parseusage(u){
$('#InstallDate').datepicker("setDate",d);
}
});
- // Delete device confirmation dialog
+
+ //Delete device confirmation dialog
$('button[value="Delete"]').click(function(e){
- var form=$(this).parents('form');
+ var form=$(this).parents('form');
var btn=$(this);
-
- dialog.dialog({
- resizable: false,
- modal: true,
- buttons: {
-
- $(this).dialog("destroy");
- form.append('');
- form.validationEngine("detach");
- form.submit();
+ var pwc=[];//paths with connection
+ // Will be up to date if path is added or removed
+ var answer = $.ajax({
+ url: "",
+ method: "POST",
+ data: {getpptd:$('#DeviceID').val()}
+ }).done(function (data){
+ pwc = data;
+ var pathList=document.getElementById("deleteselectedpaths");
+ for (i = 0; i < pwc.length; i++) {
+ pathList.insertAdjacentHTML("beforeend", ""+pwc[i][2]+"
");
+ //add checked
+ document.getElementById(pwc[i][0]+","+pwc[i][1]).disabled = pwc[i][3]>0?true:false;
+ }
+ $('#deleteselectedpaths').removeClass('hide').dialog({
+ title: "Select paths to delete",
+ modal: true,
+ width: 'auto',
+ buttons: {
+ 'Delete device and selected paths': function(){
+ var checked = $("#deleteselectedpaths :checkbox:checked");
+ var pci = [];
+ var index =0;
+ $.each(checked,function(index,value){
+ // Port connection Info
+ pci[index] = value.id.split(",");
+ index++;
+ });
+
+ // Create excel sheet
+ if(pci.length != 0)
+ {
+ // Info for excel sheet here because it might be deleted before it can read
+ var exceldata=[];
+ var jndex=0;
+ $.each(pwc,function (indexc, valuec){
+ $.each(pci,function(indexi,valuei){
+ if(valuei[0] == valuec[0] && valuei[1] == valuec[1] )
+ {
+ exceldata[jndex]=valuec[2];
+ jndex++;
+ }
+ });
+ });
+
+ $('