From d39ee70b63357eb7b2a2df4396b52f23d0ab7c29 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Thu, 24 Apr 2014 09:32:36 +0000 Subject: [PATCH] When the Destination (DID) is deleted then remove the inbound route dialplan --- app/destinations/destination_delete.php | 54 +++++++++++++++++++------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/app/destinations/destination_delete.php b/app/destinations/destination_delete.php index 15d0bba6c4..469a812852 100644 --- a/app/destinations/destination_delete.php +++ b/app/destinations/destination_delete.php @@ -40,22 +40,52 @@ else { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } -if (count($_GET)>0) { - $id = check_str($_GET["id"]); -} +//get the ID + if (count($_GET) > 0) { + $id = check_str($_GET["id"]); + } -//delete the destination - if (strlen($id) > 0) { - $sql = "delete from v_destinations "; +//if no id then exit + if (isset($id)) { + echo "ID is required." + exit; + } + +//get the dialplan_uuid + $orm = new orm; + $orm->name('destinations'); + $orm->uuid($id); + $result = $orm->find()->get(); + foreach ($result as &$row) { + $dialplan_uuid = $row["dialplan_uuid"]; + } + unset ($prep_statement); + +//delete the dialplan + if (isset($dialplan_uuid)) { + $sql = "delete from v_dialplan_details "; $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and destination_uuid = '$id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); + $sql .= "and dialplan_uuid = '$id' "; + $db->exec(check_sql($sql)); + unset($sql); + + $sql = "delete from v_dialplan "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and dialplan_uuid = '$id' "; + $db->exec(check_sql($sql)); unset($sql); } -$_SESSION["message"] = $text['message-delete']; -header("Location: destinations.php"); -return; +//delete the destination + $sql = "delete from v_destinations "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "and destination_uuid = '$id' "; + $db->exec(check_sql($sql)); + unset($sql); + +//redirect the user + $_SESSION["message"] = $text['message-delete']; + header("Location: destinations.php"); + return; ?> \ No newline at end of file