From c7f83d32ed73a9b6ed7709e274ed8517202730a5 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Tue, 10 Jul 2012 16:37:53 +0000 Subject: [PATCH] Complete the support for the dialplan xml templates to support context. --- app/dialplan/app_defaults.php | 2 +- includes/classes/switch_dialplan.php | 35 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/app/dialplan/app_defaults.php b/app/dialplan/app_defaults.php index 1c6fd87198..00adde9592 100644 --- a/app/dialplan/app_defaults.php +++ b/app/dialplan/app_defaults.php @@ -63,7 +63,7 @@ $dialplan = new dialplan; $dialplan->domain_uuid = $domain_uuid; $dialplan->dialplan_order = $dialplan_order; - $dialplan->dialplan_context = $context; + $dialplan->default_context = $context; if ($display_type == "text") { $dialplan->display_type = 'text'; } diff --git a/includes/classes/switch_dialplan.php b/includes/classes/switch_dialplan.php index f59ef5bca9..cebc302e69 100644 --- a/includes/classes/switch_dialplan.php +++ b/includes/classes/switch_dialplan.php @@ -35,6 +35,7 @@ include "root.php"; public $xml; public $json; public $display_type; + public $default_context; //dialplans public $dialplan_name; @@ -222,6 +223,10 @@ include "root.php"; public function import() { if (strlen($this->xml) > 0) { + //replace the variables + $this->xml = str_replace("{v_context}", $this->default_context, $this->xml); + $this->xml = str_replace("{v_pin_number}", generate_password(8, 1), $this->xml); + $this->xml = str_replace("{v_switch_recordings_dir}", $_SESSION['switch']['recordings']['dir'], $this->xml); //convert the xml string to an xml object $xml = simplexml_load_string($this->xml); //convert to json @@ -233,29 +238,31 @@ include "root.php"; //convert to an array $dialplan = json_decode($json, true); } + //ensure the condition array uniform - if (!is_array($dialplan['condition'][0])) { - $tmp = $dialplan['condition']; - unset($dialplan['condition']); - $dialplan['condition'][0] = $tmp; + if (!is_array($dialplan['extension']['condition'][0])) { + $tmp = $dialplan['extension']['condition']; + unset($dialplan['extension']['condition']); + $dialplan['extension']['condition'][0] = $tmp; } //check if the dialplan app uuid exists - $this->app_uuid = $dialplan['@attributes']['app_uuid']; + $this->app_uuid = $dialplan['extension']['@attributes']['app_uuid']; if ($this->app_uuid_exists()) { //dialplan entry already exists do nothing } else { //get the attributes $this->dialplan_uuid = uuid(); - $this->dialplan_name = $dialplan['@attributes']['name']; + $this->dialplan_name = $dialplan['extension']['@attributes']['name']; + $this->dialplan_context = $dialplan['@attributes']['name']; if ($this->display_type == "text") { echo " ".$this->dialplan_name.": added\n"; } - if (strlen($dialplan['@attributes']['continue']) > 0) { - $this->dialplan_continue = $dialplan['@attributes']['continue']; + if (strlen($dialplan['extension']['@attributes']['continue']) > 0) { + $this->dialplan_continue = $dialplan['extension']['@attributes']['continue']; } - if (strlen($dialplan['@attributes']['enabled']) > 0) { - $this->dialplan_enabled = $dialplan['@attributes']['enabled']; + if (strlen($dialplan['extension']['@attributes']['enabled']) > 0) { + $this->dialplan_enabled = $dialplan['extension']['@attributes']['enabled']; } else { $this->dialplan_enabled = "true"; @@ -266,7 +273,7 @@ include "root.php"; $x = 0; $group = 0; $order = 5; - foreach ($dialplan['condition'] as &$row) { + foreach ($dialplan['extension']['condition'] as &$row) { unset($this->dialplan_detail_break); unset($this->dialplan_detail_inline); $this->dialplan_detail_tag = 'condition'; @@ -301,9 +308,6 @@ include "root.php"; $this->dialplan_detail_tag = 'action'; $this->dialplan_detail_type = $row2['@attributes']['application']; $this->dialplan_detail_data = $row2['@attributes']['data']; - $this->dialplan_detail_data = str_replace("{v_pin_number}", generate_password(8, 1), $this->dialplan_detail_data); - $this->dialplan_detail_data = str_replace("{v_context}", $this->dialplan_context, $this->dialplan_detail_data); - $this->dialplan_detail_data = str_replace("{v_switch_recordings_dir}", $_SESSION['switch']['recordings']['dir'], $this->dialplan_detail_data); if (strlen($row2['@attributes']['inline']) > 0) { $this->dialplan_detail_inline = $row2['@attributes']['inline']; } @@ -316,9 +320,6 @@ include "root.php"; $this->dialplan_detail_tag = 'anti-action'; $this->dialplan_detail_type = $row2['@attributes']['application']; $this->dialplan_detail_data = $row2['@attributes']['data']; - $this->dialplan_detail_data = str_replace("{v_pin_number}", generate_password(8, 1), $this->dialplan_detail_data); - $this->dialplan_detail_data = str_replace("{v_context}", $this->dialplan_context, $this->dialplan_detail_data); - $this->dialplan_detail_data = str_replace("{v_switch_recordings_dir}", $_SESSION['switch']['recordings']['dir'], $this->dialplan_detail_data); $this->dialplan_detail_group = $group; $this->dialplan_detail_order = $order; $this->dialplan_detail_add();