From ef5466821ba1a9daa352bdf8adc9d8ba0e2a837e Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Sat, 4 Aug 2012 16:34:24 +0000 Subject: [PATCH] Make sure the IVR Menu dialplan entry is created if it doesn't exist. --- app/ivr_menu/v_ivr_menu_edit.php | 2 - includes/classes/switch_dialplan.php | 19 ++++++++ includes/classes/switch_ivr_menu.php | 73 +++++++++++++++++++--------- 3 files changed, 68 insertions(+), 26 deletions(-) diff --git a/app/ivr_menu/v_ivr_menu_edit.php b/app/ivr_menu/v_ivr_menu_edit.php index 7b77ab72be..24ed555dc6 100644 --- a/app/ivr_menu/v_ivr_menu_edit.php +++ b/app/ivr_menu/v_ivr_menu_edit.php @@ -199,8 +199,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //add the data if ($action == "add" && permission_exists('ivr_menu_add')) { - $ivr->ivr_menu_uuid = uuid(); - $ivr->dialplan_uuid = uuid(); $ivr->add(); //synchronize the xml config diff --git a/includes/classes/switch_dialplan.php b/includes/classes/switch_dialplan.php index cebc302e69..0691e12f7e 100644 --- a/includes/classes/switch_dialplan.php +++ b/includes/classes/switch_dialplan.php @@ -221,6 +221,25 @@ include "root.php"; unset($prep_statement, $result); } + public function dialplan_exists() { + global $db; + $sql = "select count(*) as num_rows from v_dialplans "; + $sql .= "where domain_uuid = '".$this->domain_uuid."' "; + $sql .= "and dialplan_uuid = '".$this->dialplan_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] > 0) { + return true; + } + else { + return false; + } + } + unset($prep_statement, $result); + } + public function import() { if (strlen($this->xml) > 0) { //replace the variables diff --git a/includes/classes/switch_ivr_menu.php b/includes/classes/switch_ivr_menu.php index effab34c98..87cf000c0a 100644 --- a/includes/classes/switch_ivr_menu.php +++ b/includes/classes/switch_ivr_menu.php @@ -24,6 +24,7 @@ Mark J Crane */ include "root.php"; +require_once "includes/classes/switch_dialplan.php"; //define the directory class class switch_ivr_menu { @@ -159,8 +160,11 @@ include "root.php"; //add the ivr menu if (strlen($this->ivr_menu_option_action) == 0) { - if (strlen($this->ivr_menu_extension) > 0) { + //ensure the dialplan_uuid has a uuid + if (strlen($this->dialplan_uuid) == 0) { + $this->dialplan_uuid = uuid(); + } //add the dialplan $database = new database; if ($this->db) { @@ -248,7 +252,7 @@ include "root.php"; } //add the ivr menu - $ivr_menu_uuid = uuid(); + $this->ivr_menu_uuid = uuid(); $database = new database; if ($this->db) { $database->db = $this->db; @@ -288,7 +292,6 @@ include "root.php"; //add the ivr menu option if (strlen($this->ivr_menu_option_action) > 0) { - $ivr_menu_uuid = uuid(); $database = new database; if ($this->db) { $database->db = $this->db; @@ -357,7 +360,9 @@ include "root.php"; } //update the ivr menu - $ivr_menu_uuid = uuid(); + if (strlen($this->dialplan_uuid) == 0) { + $this->dialplan_uuid = uuid(); + } $database = new database; $database->table = "v_ivr_menus"; $database->fields['ivr_menu_uuid'] = $this->ivr_menu_uuid; @@ -394,8 +399,14 @@ include "root.php"; $database->where[1]['operator'] = '='; $database->update(); - if (strlen($this->ivr_menu_extension) > 0) { - //update the dialplan + //check to see if the dialplan entry exists + $dialplan = new dialplan; + $dialplan->domain_uuid = $_SESSION["domain_uuid"]; + $dialplan->dialplan_uuid = $this->dialplan_uuid; + $dialplan_exists = $dialplan->dialplan_exists(); + + //if the dialplan entry does not exist then add it + if (!$dialplan_exists) { $database = new database; $database->table = "v_dialplans"; $database->fields['dialplan_name'] = $this->ivr_menu_name; @@ -406,25 +417,40 @@ include "root.php"; $database->fields['app_uuid'] = $this->app_uuid; $database->fields['domain_uuid'] = $this->domain_uuid; $database->fields['dialplan_uuid'] = $this->dialplan_uuid; - $database->where[0]['name'] = 'domain_uuid'; - $database->where[0]['value'] = $this->domain_uuid; - $database->where[0]['operator'] = '='; - $database->where[1]['name'] = 'dialplan_uuid'; - $database->where[1]['value'] = $this->dialplan_uuid; - $database->where[1]['operator'] = '='; - $database->delete(); $database->add(); + } + //if the dialplan entry exists then update it + if ($dialplan_exists && strlen($this->ivr_menu_extension) > 0) { + //update the dialplan + $database = new database; + $database->table = "v_dialplans"; + $database->fields['dialplan_name'] = $this->ivr_menu_name; + $database->fields['dialplan_order'] = '333'; + $database->fields['dialplan_context'] = $_SESSION['context']; + $database->fields['dialplan_enabled'] = $this->ivr_menu_enabled; + $database->fields['dialplan_description'] = $this->ivr_menu_description; + $database->fields['app_uuid'] = $this->app_uuid; + $database->fields['domain_uuid'] = $this->domain_uuid; + $database->fields['dialplan_uuid'] = $this->dialplan_uuid; + $database->where[0]['name'] = 'domain_uuid'; + $database->where[0]['value'] = $this->domain_uuid; + $database->where[0]['operator'] = '='; + $database->where[1]['name'] = 'dialplan_uuid'; + $database->where[1]['value'] = $this->dialplan_uuid; + $database->where[1]['operator'] = '='; + $database->update(); - //delete the old dialplan details to prepare for new details - $database = new database; - $database->table = "v_dialplan_details"; - $database->where[0]['name'] = 'domain_uuid'; - $database->where[0]['value'] = $this->domain_uuid; - $database->where[0]['operator'] = '='; - $database->where[1]['name'] = 'dialplan_uuid'; - $database->where[1]['value'] = $this->dialplan_uuid; - $database->where[1]['operator'] = '='; - $database->delete(); + //delete the old dialplan details to prepare for new details + $database = new database; + $database->table = "v_dialplan_details"; + $database->where[0]['name'] = 'domain_uuid'; + $database->where[0]['value'] = $this->domain_uuid; + $database->where[0]['operator'] = '='; + $database->where[1]['name'] = 'dialplan_uuid'; + $database->where[1]['value'] = $this->dialplan_uuid; + $database->where[1]['operator'] = '='; + $database->delete(); + } //add the dialplan details $detail_data = '^'.$this->ivr_menu_extension.'$'; @@ -494,7 +520,6 @@ include "root.php"; $database->fields['dialplan_detail_order'] = '030'; $database->add(); } - } } //update the ivr menu option