From 76587065cccc948b67aa0aeee5544d1d57f709e7 Mon Sep 17 00:00:00 2001 From: Aldemir Akpinar Date: Wed, 17 Jan 2018 14:06:32 +0300 Subject: [PATCH] webui: New tab in "manage host dependencies" to clear all children of a parent (#8085) * Add dependency info for api * webui: new tab to clear children of a parent device * Fix travis CI errors --- .../forms/delete-host-dependency.inc.php | 33 +++- .../modal/manage_host_dependencies.inc.php | 146 ++++++++++++------ html/pages/device-dependencies.inc.php | 8 + 3 files changed, 137 insertions(+), 50 deletions(-) diff --git a/html/includes/forms/delete-host-dependency.inc.php b/html/includes/forms/delete-host-dependency.inc.php index 4ba304d851..82e2acd6c7 100644 --- a/html/includes/forms/delete-host-dependency.inc.php +++ b/html/includes/forms/delete-host-dependency.inc.php @@ -15,13 +15,34 @@ if (is_admin() === false) { $status = array('status' => 1, 'message' => 'You need to be admin'); } else { - if (!is_numeric($_POST['device_id'])) { - $status = array('status' => 1, 'message' => 'Wrong device id!'); - } else { - if (dbDelete('device_relationships', '`child_device_id` = ?', array($_POST['device_id']))) { - $status = array('status' => 0, 'message' => 'Device dependency has been deleted.'); + if ($_POST['device_id']) { + if (!is_numeric($_POST['device_id'])) { + $status = array('status' => 1, 'message' => 'Wrong device id!'); + } else { + if (dbDelete('device_relationships', '`child_device_id` = ?', array($_POST['device_id']))) { + $status = array('status' => 0, 'message' => 'Device dependency has been deleted.'); + } else { + $status = array('status' => 1, 'message' => 'Device dependency cannot be deleted.'); + } + } + } else if ($_POST['parent_ids']) { + $error = false; + foreach ($_POST['parent_ids'] as $parent) { + if (is_numeric($parent) && $parent != 0) { + if (!dbDelete('device_relationships', ' `parent_device_id` = ?', array($parent))) { + $error = true; + $status = array('status' => 1, 'message' => 'Device dependency cannot be deleted.'); + } + } else if ($parent == 0) { + $status = array('status' => 1, 'message' => 'No dependency to delete.'); + $error = true; + break; + } + } + + if (!$error) { + $status = array('status' => 0, 'message' => 'Device dependencies has been deleted'); } else { - $status = array('status' => 1, 'message' => 'Device Dependency cannot be deleted.'); } } } diff --git a/html/includes/modal/manage_host_dependencies.inc.php b/html/includes/modal/manage_host_dependencies.inc.php index 05e7044ae0..d29ce95cce 100644 --- a/html/includes/modal/manage_host_dependencies.inc.php +++ b/html/includes/modal/manage_host_dependencies.inc.php @@ -25,19 +25,34 @@ if (is_admin() === false) {