Make sure the IVR Menu dialplan entry is created if it doesn't exist.

This commit is contained in:
Mark Crane
2012-08-04 16:34:24 +00:00
parent 12373f8fc8
commit ef5466821b
3 changed files with 68 additions and 26 deletions

View File

@@ -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

View File

@@ -24,6 +24,7 @@
Mark J Crane <markjcrane@fusionpbx.com>
*/
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