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-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-02 00:50:50 +02:00
|
|
|
//$this->xml = str_replace("{v_context}", $this->default_context, $this->xml);
|
2012-07-10 18:37:53 +02:00
|
|
|
$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);
|
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-01 22:33:55 +02:00
|
|
|
$this->dialplan_context = $row['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;
|
|
|
|
|
}
|
|
|
|
|
//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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-18 12:08:35 +01:00
|
|
|
|
2016-07-01 22:04:38 +02:00
|
|
|
?>
|