2012-06-04 16:58:40 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2016-04-29 23:49:36 +02:00
|
|
|
Copyright (C) 2010-2016
|
2012-06-04 16:58:40 +02:00
|
|
|
All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
include "root.php";
|
|
|
|
|
|
|
|
|
|
//define the dialplan class
|
|
|
|
|
if (!class_exists('dialplan')) {
|
|
|
|
|
class dialplan {
|
|
|
|
|
//variables
|
2016-04-15 06:34:10 +02:00
|
|
|
public $db;
|
2012-06-04 16:58:40 +02:00
|
|
|
public $result;
|
|
|
|
|
public $domain_uuid;
|
|
|
|
|
public $dialplan_uuid;
|
|
|
|
|
public $xml;
|
|
|
|
|
public $json;
|
|
|
|
|
public $display_type;
|
2012-07-10 18:37:53 +02:00
|
|
|
public $default_context;
|
2014-02-18 12:08:35 +01:00
|
|
|
public $bridges;
|
|
|
|
|
public $variables;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//dialplans
|
|
|
|
|
public $dialplan_name;
|
|
|
|
|
public $dialplan_continue;
|
|
|
|
|
public $dialplan_order;
|
|
|
|
|
public $dialplan_context;
|
2016-07-02 00:50:50 +02:00
|
|
|
public $dialplan_global;
|
2012-06-04 16:58:40 +02:00
|
|
|
public $dialplan_enabled;
|
|
|
|
|
public $dialplan_description;
|
|
|
|
|
|
|
|
|
|
//dialplan_details
|
|
|
|
|
public $dialplan_detail_tag;
|
|
|
|
|
public $dialplan_detail_order;
|
|
|
|
|
public $dialplan_detail_type;
|
|
|
|
|
public $dialplan_detail_data;
|
|
|
|
|
public $dialplan_detail_break;
|
|
|
|
|
public $dialplan_detail_inline;
|
|
|
|
|
public $dialplan_detail_group;
|
2016-09-29 20:09:54 +02:00
|
|
|
|
|
|
|
|
//xml
|
|
|
|
|
public $uuid;
|
|
|
|
|
public $context;
|
|
|
|
|
public $source;
|
|
|
|
|
public $destination;
|
|
|
|
|
public $is_empty;
|
|
|
|
|
public $array;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2016-04-15 06:34:10 +02:00
|
|
|
//class constructor
|
|
|
|
|
public function __construct() {
|
|
|
|
|
//connect to the database if not connected
|
|
|
|
|
if (!$this->db) {
|
|
|
|
|
require_once "resources/classes/database.php";
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->connect();
|
|
|
|
|
$this->db = $database->db;
|
|
|
|
|
}
|
2016-07-02 00:50:50 +02:00
|
|
|
|
|
|
|
|
//set the default value
|
|
|
|
|
$this->dialplan_global = false;
|
2016-04-15 06:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
public function dialplan_add() {
|
2016-04-15 06:34:10 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql = "insert into v_dialplans ";
|
|
|
|
|
$sql .= "(";
|
|
|
|
|
$sql .= "domain_uuid, ";
|
|
|
|
|
$sql .= "app_uuid, ";
|
|
|
|
|
$sql .= "dialplan_uuid, ";
|
|
|
|
|
$sql .= "dialplan_name, ";
|
2014-03-18 10:04:05 +01:00
|
|
|
$sql .= "dialplan_number, ";
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql .= "dialplan_continue, ";
|
|
|
|
|
$sql .= "dialplan_order, ";
|
|
|
|
|
$sql .= "dialplan_context, ";
|
|
|
|
|
$sql .= "dialplan_enabled, ";
|
|
|
|
|
$sql .= "dialplan_description ";
|
|
|
|
|
$sql .= ")";
|
|
|
|
|
$sql .= "values ";
|
|
|
|
|
$sql .= "(";
|
2016-07-02 00:50:50 +02:00
|
|
|
if ($this->dialplan_global) {
|
|
|
|
|
$sql .= "null, ";
|
2015-12-19 22:55:28 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2016-07-02 00:50:50 +02:00
|
|
|
$sql .= "'".check_str($this->domain_uuid)."', ";
|
2015-12-19 22:55:28 +01:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql .= "'".check_str($this->app_uuid)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_uuid)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_name)."', ";
|
2014-03-18 10:04:05 +01:00
|
|
|
$sql .= "'".check_str($this->dialplan_number)."', ";
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql .= "'".check_str($this->dialplan_continue)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_order)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_context)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_enabled)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_description)."' ";
|
|
|
|
|
$sql .= ")";
|
2016-04-15 06:34:10 +02:00
|
|
|
$this->db->exec(check_sql($sql));
|
2012-06-04 16:58:40 +02:00
|
|
|
unset($sql);
|
|
|
|
|
} //end function
|
|
|
|
|
|
|
|
|
|
public function dialplan_update() {
|
2016-04-15 06:34:10 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql = "update v_dialplans set ";
|
|
|
|
|
$sql .= "dialplan_name = '".check_str($this->dialplan_name)."', ";
|
|
|
|
|
if (strlen($this->dialplan_continue) > 0) {
|
|
|
|
|
$sql .= "dialplan_continue = '".check_str($this->dialplan_continue)."', ";
|
|
|
|
|
}
|
|
|
|
|
$sql .= "dialplan_order = '".check_str($this->dialplan_order)."', ";
|
|
|
|
|
$sql .= "dialplan_context = '".check_str($this->dialplan_context)."', ";
|
|
|
|
|
$sql .= "dialplan_enabled = '".check_str($this->dialplan_enabled)."', ";
|
|
|
|
|
$sql .= "dialplan_description = '".check_str($this->dialplan_description)."' ";
|
2015-12-19 22:55:28 +01:00
|
|
|
$sql .= "where (domain_uuid = '".check_str($this->domain_uuid)."' or domain_uuid is null) ";
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql .= "and dialplan_uuid = '".check_str($this->dialplan_uuid)."' ";
|
|
|
|
|
//echo "sql: ".$sql."<br />";
|
2016-04-15 06:34:10 +02:00
|
|
|
$this->db->query($sql);
|
2012-06-04 16:58:40 +02:00
|
|
|
unset($sql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function dialplan_detail_add() {
|
2016-04-15 06:34:10 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
$dialplan_detail_uuid = uuid();
|
|
|
|
|
$sql = "insert into v_dialplan_details ";
|
|
|
|
|
$sql .= "(";
|
|
|
|
|
$sql .= "dialplan_detail_uuid, ";
|
|
|
|
|
$sql .= "domain_uuid, ";
|
|
|
|
|
$sql .= "dialplan_uuid, ";
|
|
|
|
|
$sql .= "dialplan_detail_tag, ";
|
|
|
|
|
$sql .= "dialplan_detail_order, ";
|
|
|
|
|
$sql .= "dialplan_detail_type, ";
|
|
|
|
|
$sql .= "dialplan_detail_data, ";
|
|
|
|
|
$sql .= "dialplan_detail_break, ";
|
|
|
|
|
$sql .= "dialplan_detail_inline, ";
|
|
|
|
|
$sql .= "dialplan_detail_group ";
|
|
|
|
|
$sql .= ") ";
|
|
|
|
|
$sql .= "values ";
|
|
|
|
|
$sql .= "( ";
|
|
|
|
|
$sql .= "'".$dialplan_detail_uuid."', ";
|
2016-07-02 00:50:50 +02:00
|
|
|
if ($this->dialplan_global) {
|
2015-12-19 22:55:28 +01:00
|
|
|
$sql .= "null, ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql .= "'".check_str($this->domain_uuid)."', ";
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql .= "'".check_str($this->dialplan_uuid)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_detail_tag)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_detail_order)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_detail_type)."', ";
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_detail_data)."', ";
|
|
|
|
|
if (strlen($this->dialplan_detail_break) == 0) {
|
|
|
|
|
$sql .= "null, ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_detail_break)."', ";
|
|
|
|
|
}
|
|
|
|
|
if (strlen($this->dialplan_detail_inline) == 0) {
|
|
|
|
|
$sql .= "null, ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_detail_inline)."', ";
|
|
|
|
|
}
|
|
|
|
|
if (strlen($this->dialplan_detail_group) == 0) {
|
|
|
|
|
$sql .= "null ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql .= "'".check_str($this->dialplan_detail_group)."' ";
|
|
|
|
|
}
|
|
|
|
|
$sql .= ")";
|
|
|
|
|
//echo $sql."\n\n";
|
2016-04-15 06:34:10 +02:00
|
|
|
$this->db->exec(check_sql($sql));
|
2012-06-04 16:58:40 +02:00
|
|
|
unset($sql);
|
|
|
|
|
} //end function
|
|
|
|
|
|
|
|
|
|
public function dialplan_detail_update() {
|
2016-04-15 06:34:10 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql = "update v_dialplans set ";
|
|
|
|
|
$sql .= "dialplan_detail_order = '".check_str($this->dialplan_detail_order)."', ";
|
|
|
|
|
$sql .= "dialplan_detail_type = '".check_str($this->dialplan_detail_type)."', ";
|
|
|
|
|
$sql .= "dialplan_detail_data = '".check_str($this->dialplan_detail_data)."', ";
|
|
|
|
|
if (strlen($this->dialplan_detail_break) > 0) {
|
|
|
|
|
$sql .= "dialplan_detail_break = '".check_str($this->dialplan_detail_break)."', ";
|
|
|
|
|
}
|
|
|
|
|
if (strlen($this->dialplan_detail_inline) > 0) {
|
|
|
|
|
$sql .= "dialplan_detail_inline = '".check_str($this->dialplan_detail_inline)."', ";
|
|
|
|
|
}
|
|
|
|
|
if (strlen($this->dialplan_detail_group) > 0) {
|
|
|
|
|
$sql .= "dialplan_detail_group = '".check_str($this->dialplan_detail_group)."', ";
|
|
|
|
|
}
|
|
|
|
|
$sql .= "dialplan_detail_tag = '".check_str($this->dialplan_detail_tag)."' ";
|
2015-12-19 22:55:28 +01:00
|
|
|
$sql .= "where (domain_uuid = '".check_str($this->domain_uuid)."' or domain_uuid is null) ";
|
2012-06-04 16:58:40 +02:00
|
|
|
$sql .= "and dialplan_uuid = '".check_str($this->dialplan_uuid)."' ";
|
|
|
|
|
//echo "sql: ".$sql."<br />";
|
2016-04-15 06:34:10 +02:00
|
|
|
$this->db->query($sql);
|
2012-06-04 16:58:40 +02:00
|
|
|
unset($sql);
|
|
|
|
|
} //end function
|
|
|
|
|
|
|
|
|
|
public function restore_advanced_xml() {
|
|
|
|
|
$switch_dialplan_dir = $this->switch_dialplan_dir;
|
|
|
|
|
if (is_dir($switch_dialplan_dir)) {
|
2014-05-10 22:20:22 +02:00
|
|
|
//copy resources/templates/conf to the freeswitch conf dir
|
2014-10-23 20:03:33 +02:00
|
|
|
if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')){
|
|
|
|
|
$src_dir = "/usr/share/examples/fusionpbx/resources/templates/conf";
|
2014-05-10 22:20:22 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$src_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
//get the contents of the dialplan/default.xml
|
2014-05-10 23:42:35 +02:00
|
|
|
$file_default_path = $src_dir.'/dialplan/default.xml';
|
2012-06-04 16:58:40 +02:00
|
|
|
$file_default_contents = file_get_contents($file_default_path);
|
|
|
|
|
//prepare the file contents and the path
|
2015-07-02 11:14:35 +02:00
|
|
|
//replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number
|
|
|
|
|
$file_default_contents = str_replace("{v_domain}", $_SESSION['domain_name'], $file_default_contents);
|
|
|
|
|
//set the file path
|
|
|
|
|
$file_path = $switch_dialplan_dir.'/'.$_SESSION['domain_name'].'.xml';
|
2012-06-04 16:58:40 +02:00
|
|
|
//write the default dialplan
|
|
|
|
|
$fh = fopen($file_path,'w') or die('Unable to write to '.$file_path.'. Make sure the path exists and permissons are set correctly.');
|
|
|
|
|
fwrite($fh, $file_default_contents);
|
|
|
|
|
fclose($fh);
|
|
|
|
|
//set the message
|
|
|
|
|
$this->result['dialplan']['restore']['msg'] = "Default Restored";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function app_uuid_exists() {
|
2016-07-01 22:04:38 +02:00
|
|
|
$sql = "select domain_uuid from v_dialplans ";
|
|
|
|
|
$sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null) ";
|
|
|
|
|
$sql .= "and app_uuid = '".$this->app_uuid."' ";
|
|
|
|
|
$prep_statement = $this->db->prepare(check_sql($sql));
|
|
|
|
|
if ($prep_statement) {
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
if (count($result)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-07-01 22:04:38 +02:00
|
|
|
unset($sql, $prep_statement, $result);
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-04 18:34:24 +02:00
|
|
|
public function dialplan_exists() {
|
2016-07-01 21:02:31 +02:00
|
|
|
$sql = "select domain_uuid from v_dialplans ";
|
2015-12-19 22:55:28 +01:00
|
|
|
$sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null)";
|
2012-08-04 18:34:24 +02:00
|
|
|
$sql .= "and dialplan_uuid = '".$this->dialplan_uuid."' ";
|
2016-04-15 06:34:10 +02:00
|
|
|
$prep_statement = $this->db->prepare(check_sql($sql));
|
2012-08-04 18:34:24 +02:00
|
|
|
if ($prep_statement) {
|
|
|
|
|
$prep_statement->execute();
|
2016-07-01 21:02:31 +02:00
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
if (count($result)) {
|
2012-08-04 18:34:24 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-01 21:02:31 +02:00
|
|
|
unset($sql, $prep_statement, $result);
|
2012-08-04 18:34:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
public function import() {
|
|
|
|
|
if (strlen($this->xml) > 0) {
|
2012-07-10 18:37:53 +02:00
|
|
|
//replace the variables
|
2016-07-28 07:09:32 +02:00
|
|
|
$length = (is_numeric($_SESSION["security"]["pin_length"]["var"])) ? $_SESSION["security"]["pin_length"]["var"] : 8;
|
2016-07-02 00:50:50 +02:00
|
|
|
//$this->xml = str_replace("{v_context}", $this->default_context, $this->xml);
|
2016-07-28 07:09:32 +02:00
|
|
|
$this->xml = str_replace("{v_pin_number}", generate_password($length, 1), $this->xml);
|
2012-07-10 18:37:53 +02:00
|
|
|
$this->xml = str_replace("{v_switch_recordings_dir}", $_SESSION['switch']['recordings']['dir'], $this->xml);
|
2012-06-04 16:58:40 +02:00
|
|
|
//convert the xml string to an xml object
|
|
|
|
|
$xml = simplexml_load_string($this->xml);
|
|
|
|
|
//convert to json
|
|
|
|
|
$json = json_encode($xml);
|
|
|
|
|
//convert to an array
|
|
|
|
|
$dialplan = json_decode($json, true);
|
|
|
|
|
}
|
|
|
|
|
if (strlen($this->json) > 0) {
|
|
|
|
|
//convert to an array
|
|
|
|
|
$dialplan = json_decode($json, true);
|
|
|
|
|
}
|
2012-07-10 18:37:53 +02:00
|
|
|
|
2015-12-19 22:55:28 +01:00
|
|
|
//ensure the condition array is uniform
|
2013-05-22 03:02:11 +02:00
|
|
|
if (is_array($dialplan)) {
|
|
|
|
|
if (!is_array($dialplan['extension']['condition'][0])) {
|
|
|
|
|
$tmp = $dialplan['extension']['condition'];
|
|
|
|
|
unset($dialplan['extension']['condition']);
|
|
|
|
|
$dialplan['extension']['condition'][0] = $tmp;
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2016-07-01 21:02:31 +02:00
|
|
|
|
|
|
|
|
//get the app_uuid
|
2012-07-10 18:37:53 +02:00
|
|
|
$this->app_uuid = $dialplan['extension']['@attributes']['app_uuid'];
|
2016-07-01 21:02:31 +02:00
|
|
|
|
|
|
|
|
//get the list of domains
|
|
|
|
|
if (!isset($_SESSION['domains'])) {
|
|
|
|
|
$sql = "select * from v_domains; ";
|
|
|
|
|
$prep_statement = $this->db->prepare($sql);
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$_SESSION['domains'] = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
unset($sql, $prep_statement);
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2016-07-01 21:02:31 +02:00
|
|
|
|
|
|
|
|
//check if the dialplan app uuid exists
|
2016-07-02 00:50:50 +02:00
|
|
|
foreach ($_SESSION['domains'] as $domain) {
|
2016-07-01 21:02:31 +02:00
|
|
|
//get the domain_uuid
|
2016-07-02 00:50:50 +02:00
|
|
|
$this->domain_uuid = $domain['domain_uuid'];
|
2016-07-01 21:02:31 +02:00
|
|
|
|
|
|
|
|
//check if the dialplan exists
|
|
|
|
|
if (!$this->app_uuid_exists()) {
|
|
|
|
|
//start the transaction
|
|
|
|
|
$this->db->beginTransaction();
|
|
|
|
|
//get the attributes
|
|
|
|
|
$this->dialplan_uuid = uuid();
|
|
|
|
|
$this->dialplan_name = $dialplan['extension']['@attributes']['name'];
|
|
|
|
|
$this->dialplan_number = $dialplan['extension']['@attributes']['number'];
|
2016-07-02 01:58:24 +02:00
|
|
|
$this->dialplan_context = $domain['domain_name'];
|
2016-07-02 00:50:50 +02:00
|
|
|
$this->dialplan_global = false;
|
2016-07-01 21:02:31 +02:00
|
|
|
if (strlen($dialplan['extension']['@attributes']['global']) > 0) {
|
|
|
|
|
if ($dialplan['extension']['@attributes']['global'] == "true") {
|
2016-07-02 00:50:50 +02:00
|
|
|
$this->dialplan_global = true;
|
2016-07-01 22:33:55 +02:00
|
|
|
$this->dialplan_context = '${domain_name}';
|
2016-07-01 21:02:31 +02:00
|
|
|
}
|
2015-12-19 22:55:28 +01:00
|
|
|
}
|
2016-07-01 21:02:31 +02:00
|
|
|
if ($this->display_type == "text") {
|
|
|
|
|
echo " ".$this->dialplan_name.": added\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
2016-07-01 21:02:31 +02:00
|
|
|
if (strlen($dialplan['extension']['@attributes']['continue']) > 0) {
|
|
|
|
|
$this->dialplan_continue = $dialplan['extension']['@attributes']['continue'];
|
|
|
|
|
}
|
|
|
|
|
if (strlen($dialplan['extension']['@attributes']['enabled']) > 0) {
|
|
|
|
|
$this->dialplan_enabled = $dialplan['extension']['@attributes']['enabled'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$this->dialplan_enabled = "true";
|
|
|
|
|
}
|
|
|
|
|
$this->dialplan_description = '';
|
|
|
|
|
$this->dialplan_add();
|
|
|
|
|
//loop through the condition array
|
|
|
|
|
$x = 0;
|
|
|
|
|
$group = 0;
|
|
|
|
|
$order = 5;
|
2016-07-02 00:50:50 +02:00
|
|
|
if (isset($dialplan['extension']['condition'])) {
|
|
|
|
|
foreach ($dialplan['extension']['condition'] as &$row) {
|
2016-07-01 21:02:31 +02:00
|
|
|
unset($this->dialplan_detail_break);
|
|
|
|
|
unset($this->dialplan_detail_inline);
|
2016-07-02 00:50:50 +02:00
|
|
|
$this->dialplan_detail_tag = 'condition';
|
|
|
|
|
$this->dialplan_detail_type = $row['@attributes']['field'];
|
|
|
|
|
$this->dialplan_detail_data = $row['@attributes']['expression'];
|
|
|
|
|
$this->dialplan_detail_group = $group;
|
|
|
|
|
$this->dialplan_detail_order = $order;
|
|
|
|
|
if (strlen($row['@attributes']['break']) > 0) {
|
|
|
|
|
$this->dialplan_detail_break = $row['@attributes']['break'];
|
|
|
|
|
}
|
|
|
|
|
$this->dialplan_detail_add();
|
|
|
|
|
if (is_array($row['action']) || is_array($row['anti-action'])) {
|
|
|
|
|
$condition_self_closing_tag = false;
|
|
|
|
|
if (!is_array($row['action'][0])) {
|
|
|
|
|
if ($row['action']['@attributes']['application']) {
|
|
|
|
|
$tmp = $row['action'];
|
|
|
|
|
unset($row['action']);
|
|
|
|
|
$row['action'][0] = $tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!is_array($row['anti-action'][0])) {
|
|
|
|
|
if ($row['anti-action']['@attributes']['application']) {
|
|
|
|
|
$tmp = $row['anti-action'];
|
|
|
|
|
unset($row['anti-action']);
|
|
|
|
|
$row['anti-action'][0] = $tmp;
|
|
|
|
|
}
|
2016-07-01 21:02:31 +02:00
|
|
|
}
|
|
|
|
|
$order = $order + 5;
|
2016-07-02 00:50:50 +02:00
|
|
|
unset($this->dialplan_detail_break);
|
|
|
|
|
unset($this->dialplan_detail_inline);
|
|
|
|
|
if (isset($row['action'])) {
|
|
|
|
|
foreach ($row['action'] as &$row2) {
|
|
|
|
|
$this->dialplan_detail_tag = 'action';
|
|
|
|
|
$this->dialplan_detail_type = $row2['@attributes']['application'];
|
|
|
|
|
$this->dialplan_detail_data = $row2['@attributes']['data'];
|
|
|
|
|
if (strlen($row2['@attributes']['inline']) > 0) {
|
|
|
|
|
$this->dialplan_detail_inline = $row2['@attributes']['inline'];
|
|
|
|
|
}
|
|
|
|
|
$this->dialplan_detail_group = $group;
|
|
|
|
|
$this->dialplan_detail_order = $order;
|
|
|
|
|
$this->dialplan_detail_add();
|
|
|
|
|
$order = $order + 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isset($row['anti-action'])) {
|
|
|
|
|
foreach ($row['anti-action'] as &$row2) {
|
|
|
|
|
$this->dialplan_detail_tag = 'anti-action';
|
|
|
|
|
$this->dialplan_detail_type = $row2['@attributes']['application'];
|
|
|
|
|
$this->dialplan_detail_data = $row2['@attributes']['data'];
|
|
|
|
|
$this->dialplan_detail_group = $group;
|
|
|
|
|
$this->dialplan_detail_order = $order;
|
|
|
|
|
$this->dialplan_detail_add();
|
|
|
|
|
$order = $order + 5;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-01 21:02:31 +02:00
|
|
|
}
|
2016-07-02 00:50:50 +02:00
|
|
|
else {
|
|
|
|
|
$condition_self_closing_tag = true;
|
2016-07-01 21:02:31 +02:00
|
|
|
}
|
2016-07-02 00:50:50 +02:00
|
|
|
//if not a self closing tag then increment the group
|
|
|
|
|
if (!$condition_self_closing_tag) {
|
|
|
|
|
$group++;
|
|
|
|
|
}
|
|
|
|
|
$row['group'] = $group;
|
|
|
|
|
$order = $order + 5;
|
|
|
|
|
$x++;
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-07-01 21:02:31 +02:00
|
|
|
//end the transaction
|
|
|
|
|
$this->db->commit();
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-18 12:08:35 +01:00
|
|
|
|
|
|
|
|
public function outbound_routes($destination_number) {
|
|
|
|
|
|
|
|
|
|
//normalize the destination number
|
|
|
|
|
$destination_number = trim($destination_number);
|
|
|
|
|
|
|
|
|
|
//check the session array if it doesn't exist then build the array
|
|
|
|
|
if (!is_array($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) {
|
|
|
|
|
//get the outbound routes from the database
|
|
|
|
|
$sql = "select * from v_dialplans as d, v_dialplan_details as s ";
|
2015-11-27 19:25:06 +01:00
|
|
|
$sql .= "where ";
|
|
|
|
|
$sql .= "( ";
|
|
|
|
|
$sql .= "d.domain_uuid = '".$this->domain_uuid."' ";
|
|
|
|
|
$sql .= "or d.domain_uuid is null ";
|
|
|
|
|
$sql .= ") ";
|
2014-02-18 12:08:35 +01:00
|
|
|
$sql .= "and d.app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' ";
|
|
|
|
|
$sql .= "and d.dialplan_enabled = 'true' ";
|
|
|
|
|
$sql .= "and d.dialplan_uuid = s.dialplan_uuid ";
|
|
|
|
|
$sql .= "order by ";
|
|
|
|
|
$sql .= "d.dialplan_order asc, ";
|
|
|
|
|
$sql .= "d.dialplan_name asc, ";
|
|
|
|
|
$sql .= "d.dialplan_uuid asc, ";
|
|
|
|
|
$sql .= "s.dialplan_detail_group asc, ";
|
|
|
|
|
$sql .= "CASE s.dialplan_detail_tag ";
|
|
|
|
|
$sql .= "WHEN 'condition' THEN 1 ";
|
|
|
|
|
$sql .= "WHEN 'action' THEN 2 ";
|
|
|
|
|
$sql .= "WHEN 'anti-action' THEN 3 ";
|
|
|
|
|
$sql .= "ELSE 100 END, ";
|
|
|
|
|
$sql .= "s.dialplan_detail_order asc ";
|
2016-04-15 06:34:10 +02:00
|
|
|
$prep_statement = $this->db->prepare(check_sql($sql));
|
2014-02-18 12:08:35 +01:00
|
|
|
$prep_statement->execute();
|
|
|
|
|
$dialplans = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
2016-07-01 21:47:50 +02:00
|
|
|
unset($prep_statement, $sql);
|
2014-02-18 12:08:35 +01:00
|
|
|
$x = 0; $y = 0;
|
2016-04-29 23:49:36 +02:00
|
|
|
if (isset($dialplans)) foreach ($dialplans as &$row) {
|
2014-02-18 12:08:35 +01:00
|
|
|
//if the previous dialplan uuid has not been set then set it
|
|
|
|
|
if (!isset($previous_dialplan_uuid)) { $previous_dialplan_uuid = $row['dialplan_uuid']; }
|
|
|
|
|
|
|
|
|
|
//increment dialplan ordinal number
|
|
|
|
|
if ($previous_dialplan_uuid != $row['dialplan_uuid']) {
|
|
|
|
|
$x++; $y = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//build the array
|
|
|
|
|
$array[$x]['dialplan_uuid'] = $row['dialplan_uuid'];
|
|
|
|
|
$array[$x]['dialplan_context'] = $row['dialplan_context'];
|
|
|
|
|
$array[$x]['dialplan_name'] = $row['dialplan_name'];
|
|
|
|
|
$array[$x]['dialplan_continue'] = $row['dialplan_continue'];
|
|
|
|
|
$array[$x]['dialplan_order'] = $row['dialplan_order'];
|
|
|
|
|
$array[$x]['dialplan_enabled'] = $row['dialplan_enabled'];
|
|
|
|
|
$array[$x]['dialplan_description'] = $row['dialplan_description'];
|
|
|
|
|
if (strlen($row['dialplan_detail_uuid']) > 0) {
|
|
|
|
|
$array[$x]['dialplan_details'][$y]['dialplan_uuid'] = $row['dialplan_uuid'];
|
|
|
|
|
$array[$x]['dialplan_details'][$y]['dialplan_detail_uuid'] = $row['dialplan_detail_uuid'];
|
|
|
|
|
$array[$x]['dialplan_details'][$y]['dialplan_detail_tag'] = $row['dialplan_detail_tag'];
|
|
|
|
|
$array[$x]['dialplan_details'][$y]['dialplan_detail_type'] = $row['dialplan_detail_type'];
|
|
|
|
|
$array[$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row['dialplan_detail_data'];
|
|
|
|
|
$y++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//set the previous dialplan_uuid
|
|
|
|
|
$previous_dialplan_uuid = $row['dialplan_uuid'];
|
|
|
|
|
}
|
|
|
|
|
unset ($prep_statement);
|
|
|
|
|
//set the session array
|
|
|
|
|
$_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] = $array;
|
2016-09-29 20:09:54 +02:00
|
|
|
} //end if !is_array
|
2014-02-18 12:08:35 +01:00
|
|
|
//find the matching outbound routes
|
2016-04-29 23:49:36 +02:00
|
|
|
if (isset($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) foreach ($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] as $row) {
|
|
|
|
|
if (isset($row['dialplan_details'])) foreach ($row['dialplan_details'] as $field) {
|
2014-02-18 12:08:35 +01:00
|
|
|
if ($field['dialplan_detail_tag'] == "condition") {
|
|
|
|
|
if ($field['dialplan_detail_type'] == "destination_number") {
|
|
|
|
|
$dialplan_detail_data = $field['dialplan_detail_data'];
|
|
|
|
|
$pattern = '/'.$dialplan_detail_data.'/';
|
|
|
|
|
preg_match($pattern, $destination_number, $matches, PREG_OFFSET_CAPTURE);
|
|
|
|
|
if (count($matches) == 0) {
|
|
|
|
|
$regex_match = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$regex_match = true;
|
|
|
|
|
$regex_match_1 = $matches[1][0];
|
|
|
|
|
$regex_match_2 = $matches[2][0];
|
|
|
|
|
$regex_match_3 = $matches[3][0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($regex_match) {
|
|
|
|
|
//get the variables
|
|
|
|
|
if ($field[dialplan_detail_type] == "set" && $field[dialplan_detail_tag] == "action") {
|
2014-02-25 10:37:59 +01:00
|
|
|
//only set variables with values not variables
|
|
|
|
|
if (strpos($field[dialplan_detail_data], '$') === false) {
|
|
|
|
|
$this->variables .= $field[dialplan_detail_data].",";
|
|
|
|
|
}
|
2014-02-18 12:08:35 +01:00
|
|
|
}
|
|
|
|
|
//process the $x detail data variables
|
|
|
|
|
if ($field['dialplan_detail_tag'] == "action" && $field['dialplan_detail_type'] == "bridge" && $dialplan_detail_data != "\${enum_auto_route}") {
|
|
|
|
|
$dialplan_detail_data = $field['dialplan_detail_data'];
|
|
|
|
|
$dialplan_detail_data = str_replace("\$1", $regex_match_1, $dialplan_detail_data);
|
|
|
|
|
$dialplan_detail_data = str_replace("\$2", $regex_match_2, $dialplan_detail_data);
|
|
|
|
|
$dialplan_detail_data = str_replace("\$3", $regex_match_3, $dialplan_detail_data);
|
2016-03-11 12:49:17 +01:00
|
|
|
$this->bridges = $dialplan_detail_data;
|
2014-02-18 12:08:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-29 20:09:54 +02:00
|
|
|
} // end if isset
|
|
|
|
|
} // outbound_routes
|
|
|
|
|
|
|
|
|
|
//reads dialplan details from the database to build the xml
|
|
|
|
|
public function xml () {
|
|
|
|
|
|
|
|
|
|
//set the xml array and then concatenate the array to a string
|
|
|
|
|
/* $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; */
|
|
|
|
|
//$xml .= "<document type=\"freeswitch/xml\">\n";
|
|
|
|
|
//$xml .= " <section name=\"dialplan\" description=\"\">\n";
|
|
|
|
|
//$xml .= " <context name=\"" . $this->context . "\">\n";
|
|
|
|
|
|
|
|
|
|
//set defaults
|
|
|
|
|
$previous_dialplan_uuid = "";
|
|
|
|
|
$previous_dialplan_detail_group = "";
|
|
|
|
|
$dialplan_tag_status = "closed";
|
|
|
|
|
$condition_tag_status = "closed";
|
|
|
|
|
|
|
|
|
|
//get the dialplans from the dialplan_xml field in the dialplans table
|
|
|
|
|
if ($this->source == "dialplans") {
|
|
|
|
|
//get the data using a join between the dialplans and dialplan details tables
|
|
|
|
|
$sql = "select dialplan_uuid, dialplan_xml ";
|
|
|
|
|
$sql .= "from v_dialplans \n";
|
|
|
|
|
if (isset($this->uuid)) {
|
|
|
|
|
$sql .= "where dialplan_uuid = '".$this->uuid."' \n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (isset($this->context)) {
|
|
|
|
|
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
|
|
|
|
|
$sql .= "where dialplan_context = '" . $this->context . "' \n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql .= "where (dialplan_context = '" . $this->context . "' or dialplan_context = '\${domain_name}') \n";
|
|
|
|
|
}
|
|
|
|
|
$sql .= "and dialplan_enabled = 'true' \n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($this->is_empty == "dialplan_xml") {
|
|
|
|
|
$sql .= "and (p.dialplan_xml = '' or p.dialplan_xml is null) \n";
|
|
|
|
|
}
|
|
|
|
|
$sql .= "order by \n";
|
|
|
|
|
$sql .= "dialplan_context asc, \n";
|
|
|
|
|
$sql .= "dialplan_order asc \n";
|
|
|
|
|
//echo $sql;
|
|
|
|
|
$prep_statement = $this->db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$results = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
//echo $sql;
|
|
|
|
|
foreach ($results as $row) {
|
|
|
|
|
$dialplans[$row["dialplan_uuid"]] = $row["dialplan_xml"];
|
|
|
|
|
}
|
2014-02-18 12:08:35 +01:00
|
|
|
}
|
2016-09-29 20:09:54 +02:00
|
|
|
|
|
|
|
|
//get the dialplans from the dialplan details
|
|
|
|
|
if ($this->source == "details") {
|
|
|
|
|
|
|
|
|
|
//get the data using a join between the dialplans and dialplan details tables
|
|
|
|
|
$sql = "select ";
|
|
|
|
|
$sql .= "p.domain_uuid, p.dialplan_uuid, p.app_uuid, p.dialplan_context, p.dialplan_name, p.dialplan_number, \n";
|
|
|
|
|
$sql .= "p.dialplan_continue, p.dialplan_order, p.dialplan_enabled, p.dialplan_description, \n";
|
|
|
|
|
$sql .= "s.dialplan_detail_uuid, s.dialplan_detail_tag, s.dialplan_detail_type, s.dialplan_detail_data, \n";
|
|
|
|
|
$sql .= "s.dialplan_detail_break, s.dialplan_detail_inline, s.dialplan_detail_group, s.dialplan_detail_order \n";
|
|
|
|
|
$sql .= "from v_dialplans as p, v_dialplan_details as s \n";
|
|
|
|
|
$sql .= "where p.dialplan_uuid = s.dialplan_uuid \n";
|
|
|
|
|
if ($this->is_empty == "dialplan_xml") {
|
|
|
|
|
$sql .= "and (p.dialplan_xml = '' or p.dialplan_xml is null) \n";
|
|
|
|
|
}
|
|
|
|
|
if (isset($this->context)) {
|
|
|
|
|
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
|
|
|
|
|
$sql .= "and p.dialplan_context = '" . $this->context . "' \n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql .= "and (p.dialplan_context = '" . $this->context . "' or p.dialplan_context = '\${domain_name}') \n";
|
|
|
|
|
}
|
|
|
|
|
$sql .= "and p.dialplan_enabled = 'true' \n";
|
|
|
|
|
}
|
|
|
|
|
if (isset($this->uuid)) {
|
|
|
|
|
$sql .= "and p.dialplan_uuid = '".$this->uuid."' \n";
|
|
|
|
|
$sql .= "and s.dialplan_uuid = '".$this->uuid."' \n";
|
|
|
|
|
}
|
|
|
|
|
$sql .= "order by \n";
|
|
|
|
|
$sql .= "p.dialplan_order asc, \n";
|
|
|
|
|
$sql .= "p.dialplan_name asc, \n";
|
|
|
|
|
$sql .= "p.dialplan_uuid asc, \n";
|
|
|
|
|
$sql .= "s.dialplan_detail_group asc, \n";
|
|
|
|
|
$sql .= "CASE s.dialplan_detail_tag \n";
|
|
|
|
|
$sql .= "WHEN 'condition' THEN 1 \n";
|
|
|
|
|
$sql .= "WHEN 'action' THEN 2 \n";
|
|
|
|
|
$sql .= "WHEN 'anti-action' THEN 3 \n";
|
|
|
|
|
$sql .= "ELSE 100 END, \n";
|
|
|
|
|
$sql .= "s.dialplan_detail_order asc \n";
|
|
|
|
|
$prep_statement = $this->db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$results = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
|
|
|
|
|
//debug info
|
|
|
|
|
//echo "sql: $sql\n";
|
|
|
|
|
//echo "<pre>\n";
|
|
|
|
|
//print_r($results);
|
|
|
|
|
//echo "</pre>\n";
|
|
|
|
|
//exit;
|
|
|
|
|
|
|
|
|
|
//loop through the results to get the xml from the dialplan_xml field or from dialplan details table
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach ($results as $row) {
|
|
|
|
|
//clear flag pass
|
|
|
|
|
$pass = false;
|
|
|
|
|
|
|
|
|
|
//get the dialplan
|
|
|
|
|
$domain_uuid = $row["domain_uuid"];
|
|
|
|
|
$dialplan_uuid = $row["dialplan_uuid"];
|
|
|
|
|
//$app_uuid = $row["app_uuid"];
|
|
|
|
|
$this->context = $row["dialplan_context"];
|
|
|
|
|
$dialplan_name = $row["dialplan_name"];
|
|
|
|
|
//$dialplan_number = $row["dialplan_number"];
|
|
|
|
|
$dialplan_continue = $row["dialplan_continue"];
|
|
|
|
|
//$dialplan_order = $row["dialplan_order"];
|
|
|
|
|
//$dialplan_enabled = $row["dialplan_enabled"];
|
|
|
|
|
//$dialplan_description = $row["dialplan_description"];
|
|
|
|
|
|
|
|
|
|
//$get the dialplan details
|
|
|
|
|
//$dialplan_detail_uuid = $row["dialplan_detail_uuid"];
|
|
|
|
|
$dialplan_detail_tag = $row["dialplan_detail_tag"];
|
|
|
|
|
$dialplan_detail_type = $row["dialplan_detail_type"];
|
|
|
|
|
$dialplan_detail_data = $row["dialplan_detail_data"];
|
|
|
|
|
$dialplan_detail_break = $row["dialplan_detail_break"];
|
|
|
|
|
$dialplan_detail_inline = $row["dialplan_detail_inline"];
|
|
|
|
|
$dialplan_detail_group = $row["dialplan_detail_group"];
|
|
|
|
|
//$dialplan_detail_order = $row["dialplan_detail_order;
|
|
|
|
|
|
|
|
|
|
//remove $$ and replace with $
|
|
|
|
|
$dialplan_detail_data = str_replace("$$", "$", $dialplan_detail_data);
|
|
|
|
|
|
|
|
|
|
//get the dialplan detail inline
|
|
|
|
|
$detail_inline = "";
|
|
|
|
|
if ($dialplan_detail_inline) {
|
|
|
|
|
if (strlen($dialplan_detail_inline) > 0) {
|
|
|
|
|
$detail_inline = " inline=\"" . $dialplan_detail_inline . "\"";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//close the tags
|
|
|
|
|
if ($dialplan_tag_status != "closed") {
|
|
|
|
|
if (($previous_dialplan_uuid != $dialplan_uuid) || ($previous_dialplan_detail_group != $dialplan_detail_group)) {
|
|
|
|
|
if ($condition_tag_status != "closed") {
|
|
|
|
|
if ($condition_attribute && (strlen($condition_attribute) > 0)) {
|
|
|
|
|
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
|
|
|
|
|
$condition_attribute = "";
|
|
|
|
|
$condition_tag_status = "closed";
|
|
|
|
|
}
|
|
|
|
|
elseif ($condition && (strlen($condition) > 0)) {
|
|
|
|
|
$xml .= " ".$condition . "/>";
|
|
|
|
|
$condition = "";
|
|
|
|
|
$condition_tag_status = "closed";
|
|
|
|
|
}
|
|
|
|
|
elseif ($condition_tag_status != "closed") {
|
|
|
|
|
$xml .= " </condition>\n";
|
|
|
|
|
$condition_tag_status = "closed";
|
|
|
|
|
}
|
|
|
|
|
$condition_tag_status = "closed";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($previous_dialplan_uuid != $dialplan_uuid) {
|
|
|
|
|
$xml .= "</extension>\n";
|
|
|
|
|
|
|
|
|
|
//add to the dialplanss
|
|
|
|
|
$dialplans[$previous_dialplan_uuid] = $xml;
|
|
|
|
|
$xml = '';
|
|
|
|
|
|
|
|
|
|
$dialplan_tag_status = "closed";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//open the tags
|
|
|
|
|
if ($dialplan_tag_status == "closed") {
|
|
|
|
|
$xml = '';
|
|
|
|
|
$xml .= "<extension name=\"" . $dialplan_name . "\" continue=\"" . $dialplan_continue . "\" uuid=\"" . $dialplan_uuid . "\">\n";
|
|
|
|
|
$dialplan_tag_status = "open";
|
|
|
|
|
$first_action = true;
|
|
|
|
|
$condition = "";
|
|
|
|
|
$condition_attribute = "";
|
|
|
|
|
}
|
|
|
|
|
if ($dialplan_detail_tag == "condition") {
|
|
|
|
|
//determine the type of condition
|
|
|
|
|
if ($dialplan_detail_type == "hour") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "minute") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "minute-of-day") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "mday") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "mweek") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "mon") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "time-of-day") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "yday") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "year") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "wday") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($dialplan_detail_type == "week") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
elseif ($ialplan_detail_type == "date-time") {
|
|
|
|
|
$condition_type = 'time';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$condition_type = 'default';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// finalize any previous pending condition statements
|
|
|
|
|
if ($condition_tag_status == "open") {
|
|
|
|
|
if (strlen($condition) > 0) {
|
|
|
|
|
$xml .= $condition . "/>\n";
|
|
|
|
|
$condition = '';
|
|
|
|
|
$condition_tag_status = "closed";
|
|
|
|
|
}
|
|
|
|
|
elseif (strlen($condition_attribute) > 0 && $condition_tag_status == "open") {
|
|
|
|
|
// previous condition(s) must have been of type time
|
|
|
|
|
// do not finalize if new condition is also of type time
|
|
|
|
|
if ($condition_type != 'time') {
|
|
|
|
|
// note: condition_break here is value from the previous loop
|
|
|
|
|
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
|
|
|
|
|
$condition_attribute = '';
|
|
|
|
|
$condition_tag_status = "closed";
|
|
|
|
|
}
|
|
|
|
|
//else {
|
|
|
|
|
// $xml .= " </condition>\n";
|
|
|
|
|
// $condition_tag_status = "closed";
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get the condition break attribute
|
|
|
|
|
$condition_break = "";
|
|
|
|
|
if ($dialplan_detail_break) {
|
|
|
|
|
if (strlen($dialplan_detail_break) > 0) {
|
|
|
|
|
$condition_break = " break=\"" . $dialplan_detail_break . "\"";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//condition tag but leave off the ending
|
|
|
|
|
if ($condition_type == "default") {
|
|
|
|
|
$condition = " <condition field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break;
|
|
|
|
|
}
|
|
|
|
|
elseif ($condition_type == "time") {
|
|
|
|
|
if ($condition_attribute) {
|
|
|
|
|
$condition_attribute = $condition_attribute . $dialplan_detail_type . "=\"" . $dialplan_detail_data . "\" ";
|
|
|
|
|
} else {
|
|
|
|
|
$condition_attribute = $dialplan_detail_type . "=\"" . $dialplan_detail_data . "\" ";
|
|
|
|
|
}
|
|
|
|
|
$condition = ""; //prevents a duplicate time condition
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$condition = " <condition field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break;
|
|
|
|
|
}
|
|
|
|
|
$condition_tag_status = "open";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($dialplan_detail_tag == "action" || $dialplan_detail_tag == "anti-action") {
|
|
|
|
|
if ($condition_tag_status == "open") {
|
|
|
|
|
if ($condition_attribute && (strlen($condition_attribute) > 0)) {
|
|
|
|
|
$xml .= " <condition " . $condition_attribute . $condition_break . ">\n";
|
|
|
|
|
$condition_attribute = "";
|
|
|
|
|
}
|
|
|
|
|
elseif ($condition && (strlen($condition) > 0)) {
|
|
|
|
|
$xml .= $condition . ">\n";
|
|
|
|
|
$condition = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
|
|
|
|
|
if ($dialplan_detail_tag == "action") {
|
|
|
|
|
if ($first_action) {
|
|
|
|
|
//get the domains
|
|
|
|
|
if (!isset($domains)) {
|
|
|
|
|
$sql = "select * from v_domains; \n";
|
|
|
|
|
$prep_statement = $this->db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
foreach($result as $row) {
|
|
|
|
|
$domains[$row['domain_uuid']] = $row['domain_name'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//add the call direction and domain name and uuid
|
|
|
|
|
$xml .= " <action application=\"set\" data=\"call_direction=inbound\" inline=\"true\"/>\n";
|
|
|
|
|
if ($domain_uuid != null and $domain_uuid != '') {
|
|
|
|
|
$domain_name = $domains[$domain_uuid];
|
|
|
|
|
$xml .= " <action application=\"set\" data=\"domain_uuid=" . $domain_uuid . "\" inline=\"true\"/>\n";
|
|
|
|
|
}
|
|
|
|
|
if ($domain_name != null and $domain_name != '') {
|
|
|
|
|
$xml .= " <action application=\"set\" data=\"domain_name=" . $domain_name . "\" inline=\"true\"/>\n";
|
|
|
|
|
}
|
|
|
|
|
$first_action = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($dialplan_detail_tag == "action") {
|
|
|
|
|
$xml .= " <action application=\"" . $dialplan_detail_type . "\" data=\"" . $dialplan_detail_data . "\"" . $detail_inline . "/>\n";
|
|
|
|
|
}
|
|
|
|
|
if ($dialplan_detail_tag == "anti-action") {
|
|
|
|
|
$xml .= " <anti-action application=\"" . $dialplan_detail_type . "\" data=\"" . $dialplan_detail_data . "\"" . $detail_inline . "/>\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//save the previous values
|
|
|
|
|
$previous_dialplan_uuid = $dialplan_uuid;
|
|
|
|
|
$previous_dialplan_detail_group = $dialplan_detail_group;
|
|
|
|
|
|
|
|
|
|
//increment the x
|
|
|
|
|
$x++;
|
|
|
|
|
|
|
|
|
|
//set flag pass
|
|
|
|
|
$pass = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prevent partial dialplan (pass=nil may be error in sql or empty resultset)
|
|
|
|
|
if ($pass == false) {
|
2016-09-29 21:12:00 +02:00
|
|
|
if (count($results)) {
|
2016-09-29 20:09:54 +02:00
|
|
|
echo 'error while build context: ' . $this->context;
|
2016-09-29 21:12:00 +02:00
|
|
|
}
|
2016-09-29 20:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//close the extension tag if it was left open
|
|
|
|
|
if ($dialplan_tag_status == "open") {
|
|
|
|
|
if ($condition_tag_status == "open") {
|
|
|
|
|
if ($condition_attribute and (strlen($condition_attribute) > 0)) {
|
|
|
|
|
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
|
|
|
|
|
}
|
|
|
|
|
elseif ($condition && (strlen($condition) > 0)) {
|
|
|
|
|
$xml .= $condition . "/>\n";
|
|
|
|
|
} else {
|
|
|
|
|
$xml .= " </condition>\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$xml .= "</extension>\n";
|
|
|
|
|
|
|
|
|
|
//add to the dialplans array
|
|
|
|
|
$dialplans[$dialplan_uuid] = $xml;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//set the xml array and then concatenate the array to a string
|
|
|
|
|
//$xml .= " </context>\n";
|
|
|
|
|
///$xml .= " </section>\n";
|
|
|
|
|
//$xml .= "</document>\n";
|
|
|
|
|
|
|
|
|
|
} //end if source = details
|
|
|
|
|
|
|
|
|
|
//return the array
|
|
|
|
|
if ($this->destination == "array") {
|
|
|
|
|
return $dialplans;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//save the dialplan xml
|
|
|
|
|
if ($this->destination == "database") {
|
|
|
|
|
foreach ($dialplans as $key => $value) {
|
|
|
|
|
$sql = "update v_dialplans ";
|
|
|
|
|
//$sql .= "set dialplan_xml = ':xml' ";
|
|
|
|
|
$sql .= "set dialplan_xml = '".check_str($value)."' ";
|
|
|
|
|
//$sql .= "where dialplan_uuid=:dialplan_uuid ";
|
|
|
|
|
$sql .= "where dialplan_uuid = '$key';";
|
|
|
|
|
//$prep_statement = $this->db->prepare(check_sql($sql));
|
|
|
|
|
//$prep_statement->bindParam(':xml', $value );
|
|
|
|
|
//$prep_statement->bindParam(':dialplan_uuid', $key);
|
|
|
|
|
//$prep_statement->execute();
|
|
|
|
|
//$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
//print_r($result);
|
|
|
|
|
unset($prep_statement);
|
|
|
|
|
$this->db->query($sql);
|
|
|
|
|
unset($sql);
|
|
|
|
|
}
|
|
|
|
|
//return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 12:08:35 +01:00
|
|
|
}
|
2016-09-29 20:09:54 +02:00
|
|
|
} // end class
|
|
|
|
|
} // class_exists
|
2014-02-18 12:08:35 +01:00
|
|
|
|
2016-07-01 22:04:38 +02:00
|
|
|
?>
|