From 7f5d7e3e93bf46a672a91c16675e2775b0df6ca2 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Mon, 26 May 2014 17:00:29 +0000 Subject: [PATCH] Improve the duplicate test used on dialplan -> destinations --- app/destinations/destination_edit.php | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/destinations/destination_edit.php b/app/destinations/destination_edit.php index feba7bdb53..d7fda770c2 100644 --- a/app/destinations/destination_edit.php +++ b/app/destinations/destination_edit.php @@ -78,15 +78,27 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { if (strlen($destination_context) == 0) { $msg .= $text['message-required']." ".$text['label-destination_context']."
\n"; } if (strlen($destination_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-destination_enabled']."
\n"; } + //get the current destination_number + $sql = "select count(*) as num_rows from v_destinations "; + $sql .= "where destination_number = '".$destination_number."' "; + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + $db_destination_number = $row['destination_number']; + } + //check for duplicates - $sql = "select count(*) as num_rows from v_destinations "; - $sql .= "where destination_number = '".$destination_number."' "; - $prep_statement = $db->prepare($sql); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] > 0) { - $msg .= $text['message-duplicate']."
\n"; + if ($action == "add" || $destination_number != $db_destination_number) { + $sql = "select count(*) as num_rows from v_destinations "; + $sql .= "where destination_number = '".$destination_number."' "; + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] > 0) { + $msg .= $text['message-duplicate']."
\n"; + } } }