2016-04-26 03:30:23 +02:00
|
|
|
<?php
|
2020-02-07 18:59:05 +01:00
|
|
|
/*
|
|
|
|
|
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>
|
2024-02-21 19:23:58 +01:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2017 - 2023
|
2020-02-07 18:59:05 +01:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
2016-04-26 03:30:23 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* destinations
|
|
|
|
|
*/
|
2019-11-06 19:29:11 +01:00
|
|
|
class destinations {
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-13 20:17:14 +02:00
|
|
|
* declare public variables
|
2019-11-06 19:29:11 +01:00
|
|
|
*/
|
|
|
|
|
public $destinations;
|
2020-03-08 08:29:31 +01:00
|
|
|
public $domain_uuid;
|
2024-05-13 20:17:14 +02:00
|
|
|
public $start_stamp_begin;
|
|
|
|
|
public $start_stamp_end;
|
|
|
|
|
public $quick_select;
|
2019-11-06 19:29:11 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* declare private variables
|
|
|
|
|
*/
|
2020-03-08 08:29:31 +01:00
|
|
|
private $domain_name;
|
2019-11-06 19:29:11 +01:00
|
|
|
private $app_name;
|
|
|
|
|
private $app_uuid;
|
|
|
|
|
private $permission_prefix;
|
|
|
|
|
private $list_page;
|
|
|
|
|
private $table;
|
|
|
|
|
private $uuid_prefix;
|
2025-01-18 23:47:56 +01:00
|
|
|
private $database;
|
2024-03-29 05:13:01 +01:00
|
|
|
private $settings;
|
2019-11-06 19:29:11 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when the object is created
|
|
|
|
|
*/
|
2025-01-18 23:47:56 +01:00
|
|
|
public function __construct($setting_array = []) {
|
|
|
|
|
|
|
|
|
|
//open a database connection
|
|
|
|
|
if (empty($setting_array['database'])) {
|
|
|
|
|
$this->database = database::new();
|
|
|
|
|
} else {
|
|
|
|
|
$this->database = $setting_array['database'];
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
|
|
|
|
|
2025-01-18 23:47:56 +01:00
|
|
|
//get the settings object
|
|
|
|
|
if (empty($setting_array['settings'])) {
|
2024-04-02 17:43:16 +02:00
|
|
|
$this->settings = new settings();
|
2025-01-18 23:47:56 +01:00
|
|
|
} else {
|
|
|
|
|
$this->settings = $setting_array['settings'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//set the domain details
|
|
|
|
|
if (is_null($this->domain_uuid)) {
|
|
|
|
|
$this->domain_uuid = $_SESSION['domain_uuid'];
|
2024-04-02 17:43:16 +02:00
|
|
|
}
|
2024-01-03 02:54:22 +01:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//assign private variables
|
|
|
|
|
$this->app_name = 'destinations';
|
|
|
|
|
$this->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139';
|
|
|
|
|
$this->permission_prefix = 'destination_';
|
|
|
|
|
$this->list_page = 'destinations.php';
|
|
|
|
|
$this->table = 'destinations';
|
|
|
|
|
$this->uuid_prefix = 'destination_';
|
2017-12-21 09:36:36 +01:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
|
2020-10-10 08:03:04 +02:00
|
|
|
/**
|
|
|
|
|
* Convert destination number to a regular expression
|
|
|
|
|
* @var string $array destination_prefix, destination_trunk_prefix, destination_area_code, destination_number
|
|
|
|
|
*/
|
|
|
|
|
public function to_regex($array) {
|
|
|
|
|
|
|
|
|
|
if (isset($array['destination_prefix']) && isset($array['destination_trunk_prefix']) && isset($array['destination_area_code']) && isset($array['destination_number'])) {
|
|
|
|
|
$destination_regex = "(\+?".$array['destination_prefix'].$array['destination_area_code'].$array['destination_number']."\$|";
|
|
|
|
|
$destination_regex .= "^".$array['destination_trunk_prefix'].$array['destination_area_code'].$array['destination_number']."\$|";
|
|
|
|
|
$destination_regex .= "^".$array['destination_area_code'].$array['destination_number']."\$|";
|
|
|
|
|
$destination_regex .= "^".$array['destination_number']."\$)";
|
|
|
|
|
}
|
2021-12-08 21:49:15 +01:00
|
|
|
elseif (isset($array['destination_prefix']) && isset($array['destination_trunk_prefix']) && isset($array['destination_number'])) {
|
|
|
|
|
$destination_regex = "(\+?".$array['destination_prefix'].$array['destination_number']."\$|";
|
|
|
|
|
$destination_regex .= "^".$array['destination_trunk_prefix'].$array['destination_number']."\$|";
|
|
|
|
|
$destination_regex .= "^".$array['destination_number']."\$)";
|
|
|
|
|
}
|
2020-10-10 08:03:04 +02:00
|
|
|
elseif (isset($array['destination_prefix']) && isset($array['destination_area_code']) && isset($array['destination_number'])) {
|
|
|
|
|
$destination_regex = "(\+?".$array['destination_prefix'].$array['destination_area_code'].$array['destination_number']."\$|";
|
|
|
|
|
$destination_regex .= "^".$array['destination_area_code'].$array['destination_number']."\$|";
|
|
|
|
|
$destination_regex .= "^".$array['destination_number']."\$)";
|
|
|
|
|
}
|
|
|
|
|
elseif ((isset($array['destination_prefix']) && isset($array['destination_number'])) || isset($array['destination_number'])) {
|
|
|
|
|
|
|
|
|
|
//set the variables
|
2023-05-23 01:05:44 +02:00
|
|
|
$destination_prefix = $array['destination_prefix'] ?? null;
|
|
|
|
|
$destination_number = $array['destination_number'] ?? null;
|
|
|
|
|
$destination_regex = $array['destination_number'] ?? null;
|
2020-10-10 08:03:04 +02:00
|
|
|
|
|
|
|
|
//escape the plus
|
|
|
|
|
if (substr($destination_number, 0, 1) == "+") {
|
|
|
|
|
$destination_regex = "^\\+(".substr($destination_number, 1).")$";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add prefix
|
2023-05-05 18:46:37 +02:00
|
|
|
if (!empty($destination_prefix)) {
|
2021-12-08 21:49:15 +01:00
|
|
|
$destination_prefix = str_replace("+", "", $destination_prefix);
|
|
|
|
|
$plus = '\+?';
|
|
|
|
|
if (strlen($destination_prefix) == 1) {
|
2020-10-10 08:03:04 +02:00
|
|
|
$destination_prefix = $plus.$destination_prefix.'?';
|
|
|
|
|
}
|
|
|
|
|
else {
|
2021-12-08 21:49:15 +01:00
|
|
|
$destination_prefix = $plus.'(?:'.$destination_prefix.')?';
|
2020-10-10 08:03:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//convert N,X,Z syntax to regex
|
|
|
|
|
$destination_regex = str_ireplace("N", "[2-9]", $destination_regex);
|
|
|
|
|
$destination_regex = str_ireplace("X", "[0-9]", $destination_regex);
|
|
|
|
|
$destination_regex = str_ireplace("Z", "[1-9]", $destination_regex);
|
|
|
|
|
|
|
|
|
|
//add ^ to the start of the string if missing
|
|
|
|
|
if (substr($destination_regex, 0, 1) != "^") {
|
|
|
|
|
$destination_regex = "^".$destination_regex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add $ to the end of the string if missing
|
|
|
|
|
if (substr($destination_regex, -1) != "$") {
|
|
|
|
|
$destination_regex = $destination_regex."$";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add the round brackets
|
|
|
|
|
if (!strstr($destination_regex, '(')) {
|
|
|
|
|
if (strstr($destination_regex, '^')) {
|
|
|
|
|
$destination_regex = str_replace("^", "^".$destination_prefix."(", $destination_regex);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$destination_regex = '^('.$destination_regex;
|
|
|
|
|
}
|
|
|
|
|
if (strstr($destination_regex, '$')) {
|
|
|
|
|
$destination_regex = str_replace("$", ")$", $destination_regex);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$destination_regex = $destination_regex.')$';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $destination_regex;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
/**
|
|
|
|
|
* Build the destination select list
|
|
|
|
|
* @var string $destination_type can be ivr, dialplan, call_center_contact or bridge
|
|
|
|
|
* @var string $destination_name - current name
|
|
|
|
|
* @var string $destination_value - current value
|
|
|
|
|
*/
|
|
|
|
|
public function select($destination_type, $destination_name, $destination_value) {
|
|
|
|
|
|
|
|
|
|
//set the global variables
|
|
|
|
|
global $db_type;
|
|
|
|
|
|
2023-05-17 06:51:16 +02:00
|
|
|
//set defaults
|
|
|
|
|
$select_style = '';
|
|
|
|
|
$onchange = '';
|
|
|
|
|
|
2020-03-08 08:29:31 +01:00
|
|
|
//get the domain_name
|
|
|
|
|
$sql = "select domain_name from v_domains ";
|
|
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$parameters['domain_uuid'] = $this->domain_uuid;
|
2025-01-18 23:47:56 +01:00
|
|
|
$this->domain_name = $this->database->select($sql, $parameters, 'column');
|
2020-03-08 08:29:31 +01:00
|
|
|
|
2023-09-20 21:13:33 +02:00
|
|
|
//initialize variable
|
|
|
|
|
$response = '';
|
|
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//create a single destination select list
|
2023-05-17 06:51:16 +02:00
|
|
|
if (!empty($_SESSION['destinations']['select_mode']['text']) && $_SESSION['destinations']['select_mode']['text'] == 'default') {
|
2020-11-19 17:54:32 +01:00
|
|
|
//get the destinations
|
|
|
|
|
if (!is_array($this->destinations)) {
|
2019-11-06 19:29:11 +01:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//get the array from the app_config.php files
|
|
|
|
|
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
|
|
|
|
$x = 0;
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($config_list as $config_path) {
|
2020-11-19 17:54:32 +01:00
|
|
|
try {
|
2024-01-09 08:22:53 +01:00
|
|
|
include($config_path);
|
2020-11-19 17:54:32 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
2024-01-09 08:22:53 +01:00
|
|
|
//echo 'Caught exception: ', $e->getMessage(), "\n";
|
2020-11-19 17:54:32 +01:00
|
|
|
}
|
|
|
|
|
$x++;
|
2020-11-04 18:46:58 +01:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
$i = 0;
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($apps as $x => $app) {
|
|
|
|
|
if (isset($app['destinations'])) foreach ($app['destinations'] as $row) {
|
2020-11-19 17:54:32 +01:00
|
|
|
if (permission_exists($this->singular($row["name"])."_destinations")) {
|
|
|
|
|
$this->destinations[] = $row;
|
|
|
|
|
}
|
2020-01-21 17:43:19 +01:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
//put the array in order
|
|
|
|
|
if ($this->destinations !== null && is_array($this->destinations)) {
|
|
|
|
|
foreach ($this->destinations as $row) {
|
|
|
|
|
$option_groups[] = $row['label'];
|
|
|
|
|
}
|
|
|
|
|
array_multisort($option_groups, SORT_ASC, $this->destinations);
|
2020-02-07 18:59:05 +01:00
|
|
|
}
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//add the sql and data to the array
|
|
|
|
|
if ($this->destinations !== null && is_array($this->destinations)) {
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach ($this->destinations as $row) {
|
|
|
|
|
if ($row['type'] === 'sql') {
|
|
|
|
|
$table_name = preg_replace('#[^a-zA-Z0-9_]#', '', $row['name']);
|
|
|
|
|
if (isset($row['sql'])) {
|
|
|
|
|
if (is_array($row['sql'])) {
|
|
|
|
|
$sql = trim($row['sql'][$db_type])." ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql = trim($row['sql'])." ";
|
|
|
|
|
}
|
2020-02-07 18:59:05 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2020-11-19 17:54:32 +01:00
|
|
|
$field_count = count($row['field']);
|
|
|
|
|
$fields = '';
|
|
|
|
|
$c = 1;
|
|
|
|
|
foreach ($row['field'] as $key => $value) {
|
|
|
|
|
$key = preg_replace('#[^a-zA-Z0-9_]#', '', $key);
|
|
|
|
|
$value = preg_replace('#[^a-zA-Z0-9_]#', '', $value);
|
|
|
|
|
if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; }
|
|
|
|
|
$fields .= $value." as ".$key.$delimiter." ";
|
|
|
|
|
$c++;
|
|
|
|
|
}
|
|
|
|
|
$sql = "select ".$fields;
|
|
|
|
|
$sql .= " from v_".$table_name." ";
|
2020-02-07 18:59:05 +01:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
if (isset($row['where'])) {
|
|
|
|
|
$sql .= trim($row['where'])." ";
|
2020-02-07 18:59:05 +01:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
$sql .= "order by ".trim($row['order_by']);
|
|
|
|
|
$sql = str_replace("\${domain_uuid}", $this->domain_uuid, $sql);
|
2025-01-18 23:47:56 +01:00
|
|
|
$result = $this->database->select($sql, null, 'all');
|
2020-11-19 17:54:32 +01:00
|
|
|
|
|
|
|
|
$this->destinations[$x]['result']['sql'] = $sql;
|
|
|
|
|
$this->destinations[$x]['result']['data'] = $result;
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
if ($row['type'] === 'array') {
|
|
|
|
|
$this->destinations[$x] = $row;
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
$x++;
|
2020-06-18 18:44:16 +02:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
$this->destinations[$x]['type'] = 'array';
|
|
|
|
|
$this->destinations[$x]['label'] = 'other';
|
|
|
|
|
$this->destinations[$x]['name'] = 'dialplans';
|
|
|
|
|
$this->destinations[$x]['field']['name'] = "name";
|
|
|
|
|
$this->destinations[$x]['field']['destination'] = "destination";
|
|
|
|
|
$this->destinations[$x]['select_value']['dialplan'] = "transfer:\${destination}";
|
|
|
|
|
$this->destinations[$x]['select_value']['ivr'] = "menu-exec-app:transfer \${destination}";
|
|
|
|
|
$this->destinations[$x]['select_label'] = "\${name}";
|
|
|
|
|
$y = 0;
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['label'] = 'check_voicemail';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = '*98';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*98 XML ${context}';
|
|
|
|
|
$y++;
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['label'] = 'company_directory';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = '*411';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*411 XML ${context}';
|
|
|
|
|
$y++;
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['label'] = 'hangup';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'hangup';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['application'] = 'hangup';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '';
|
|
|
|
|
$y++;
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['label'] = 'record';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = '*732';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*732 XML ${context}';
|
|
|
|
|
$y++;
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
|
|
|
|
|
//remove special characters from the name
|
|
|
|
|
$destination_id = str_replace("]", "", $destination_name);
|
|
|
|
|
$destination_id = str_replace("[", "_", $destination_id);
|
|
|
|
|
|
|
|
|
|
//set the css style
|
|
|
|
|
$select_style = 'width: 200px;';
|
|
|
|
|
|
|
|
|
|
//add additional
|
|
|
|
|
if (if_group("superadmin")) {
|
2023-09-20 21:13:33 +02:00
|
|
|
$response .= "<script>\n";
|
2020-11-19 17:54:32 +01:00
|
|
|
$response .= "var Objs;\n";
|
|
|
|
|
$response .= "\n";
|
|
|
|
|
$response .= "function changeToInput".$destination_id."(obj){\n";
|
|
|
|
|
$response .= " tb=document.createElement('INPUT');\n";
|
|
|
|
|
$response .= " tb.type='text';\n";
|
|
|
|
|
$response .= " tb.name=obj.name;\n";
|
|
|
|
|
$response .= " tb.className='formfld';\n";
|
|
|
|
|
$response .= " tb.setAttribute('id', '".$destination_id."');\n";
|
|
|
|
|
$response .= " tb.setAttribute('style', '".$select_style."');\n";
|
2023-05-17 06:51:16 +02:00
|
|
|
if (!empty($onchange)) {
|
2020-11-19 17:54:32 +01:00
|
|
|
$response .= " tb.setAttribute('onchange', \"".$onchange."\");\n";
|
|
|
|
|
$response .= " tb.setAttribute('onkeyup', \"".$onchange."\");\n";
|
|
|
|
|
}
|
|
|
|
|
$response .= " tb.value=obj.options[obj.selectedIndex].value;\n";
|
|
|
|
|
$response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'hidden';\n";
|
|
|
|
|
$response .= " tbb=document.createElement('INPUT');\n";
|
|
|
|
|
$response .= " tbb.setAttribute('class', 'btn');\n";
|
|
|
|
|
$response .= " tbb.setAttribute('style', 'margin-left: 4px;');\n";
|
|
|
|
|
$response .= " tbb.type='button';\n";
|
|
|
|
|
$response .= " tbb.value=$('<div />').html('◁').text();\n";
|
|
|
|
|
$response .= " tbb.objs=[obj,tb,tbb];\n";
|
|
|
|
|
$response .= " tbb.onclick=function(){ Replace".$destination_id."(this.objs); }\n";
|
|
|
|
|
$response .= " obj.parentNode.insertBefore(tb,obj);\n";
|
|
|
|
|
$response .= " obj.parentNode.insertBefore(tbb,obj);\n";
|
|
|
|
|
$response .= " obj.parentNode.removeChild(obj);\n";
|
|
|
|
|
$response .= " Replace".$destination_id."(this.objs);\n";
|
|
|
|
|
$response .= "}\n";
|
|
|
|
|
$response .= "\n";
|
|
|
|
|
$response .= "function Replace".$destination_id."(obj){\n";
|
|
|
|
|
$response .= " obj[2].parentNode.insertBefore(obj[0],obj[2]);\n";
|
|
|
|
|
$response .= " obj[0].parentNode.removeChild(obj[1]);\n";
|
|
|
|
|
$response .= " obj[0].parentNode.removeChild(obj[2]);\n";
|
|
|
|
|
$response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n";
|
2023-05-17 06:51:16 +02:00
|
|
|
if (!empty($onchange)) {
|
2020-11-19 17:54:32 +01:00
|
|
|
$response .= " ".$onchange.";\n";
|
|
|
|
|
}
|
|
|
|
|
$response .= "}\n";
|
|
|
|
|
$response .= "</script>\n";
|
|
|
|
|
$response .= "\n";
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2016-04-26 03:30:23 +02:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//set default to false
|
|
|
|
|
$select_found = false;
|
2016-04-26 03:30:23 +02:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
$response .= " <select name='".$destination_name."' id='".$destination_id."' class='formfld' style='".$select_style."' onchange=\"".$onchange."\">\n";
|
|
|
|
|
$response .= " <option value=''></option>\n";
|
|
|
|
|
foreach ($this->destinations as $row) {
|
2016-04-26 03:30:23 +02:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
$name = $row['name'];
|
|
|
|
|
$label = $row['label'];
|
2023-05-17 06:51:16 +02:00
|
|
|
$destination = $row['field']['destination'] ?? '';
|
2016-04-26 03:30:23 +02:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//add multi-lingual support
|
|
|
|
|
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) {
|
|
|
|
|
$language2 = new text;
|
|
|
|
|
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name);
|
|
|
|
|
}
|
2016-04-26 03:30:23 +02:00
|
|
|
|
2023-05-17 06:51:16 +02:00
|
|
|
if (!empty($row['result']['data']) && !empty($row['select_value'][$destination_type])) {
|
2024-03-27 16:11:43 +01:00
|
|
|
$response .= " <optgroup label='".$text2['title-'.$name]."'>\n";
|
2020-11-19 17:54:32 +01:00
|
|
|
$label2 = $label;
|
|
|
|
|
foreach ($row['result']['data'] as $data) {
|
|
|
|
|
$select_value = $row['select_value'][$destination_type];
|
|
|
|
|
$select_label = $row['select_label'];
|
|
|
|
|
foreach ($row['field'] as $key => $value) {
|
|
|
|
|
if ($key == 'destination' and is_array($value)){
|
|
|
|
|
if ($value['type'] === 'csv') {
|
|
|
|
|
$array = explode($value['delimiter'], $data[$key]);
|
|
|
|
|
$select_value = str_replace("\${destination}", $array[0], $select_value);
|
|
|
|
|
$select_label = str_replace("\${destination}", $array[0], $select_label);
|
2016-04-26 03:30:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-11-19 17:54:32 +01:00
|
|
|
if (strpos($value,',') !== false) {
|
|
|
|
|
$keys = explode(",", $value);
|
|
|
|
|
foreach ($keys as $k) {
|
2023-05-05 18:46:37 +02:00
|
|
|
if (!empty($data[$k])) {
|
2020-11-19 17:54:32 +01:00
|
|
|
$select_value = str_replace("\${".$key."}", $data[$k], $select_value);
|
2023-05-05 18:46:37 +02:00
|
|
|
if (empty($data['label'])) {
|
2020-11-19 17:54:32 +01:00
|
|
|
$select_label = str_replace("\${".$key."}", $data[$k], $select_label);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$label = $data['label'];
|
|
|
|
|
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-05 18:46:37 +02:00
|
|
|
$select_value = str_replace("\${".$key."}", $data[$key] ?? '', $select_value ?? '');
|
|
|
|
|
if (empty($data['label'])) {
|
|
|
|
|
$select_label = str_replace("\${".$key."}", $data[$key] ?? '', $select_label ?? '');
|
2020-11-19 17:54:32 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$label = $data['label'];
|
|
|
|
|
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//application: hangup
|
2024-12-10 21:44:49 +01:00
|
|
|
if (!empty($data['application']) && $data['application'] === 'hangup') {
|
2020-11-19 17:54:32 +01:00
|
|
|
$select_value = str_replace("transfer", $data['application'], $select_value);
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2016-04-26 03:30:23 +02:00
|
|
|
}
|
2018-01-09 20:43:23 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
$select_value = str_replace("\${domain_name}", $this->domain_name, $select_value);
|
|
|
|
|
$select_value = str_replace("\${context}", $this->domain_name, $select_value);
|
|
|
|
|
$select_label = str_replace("\${domain_name}", $this->domain_name, $select_label);
|
|
|
|
|
$select_label = str_replace("\${context}", $this->domain_name, $select_label);
|
|
|
|
|
$select_label = str_replace("✉", 'email-icon', $select_label);
|
|
|
|
|
$select_label = escape(trim($select_label));
|
|
|
|
|
$select_label = str_replace('email-icon', '✉', $select_label);
|
|
|
|
|
if ($select_value == $destination_value) { $selected = "selected='selected' "; $select_found = true; } else { $selected = ''; }
|
|
|
|
|
if ($label2 == 'destinations') { $select_label = format_phone($select_label); }
|
|
|
|
|
$response .= " <option value='".escape($select_value)."' ".$selected.">".$select_label."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
$response .= " </optgroup>\n";
|
|
|
|
|
unset($text);
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2016-04-26 03:30:23 +02:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
if (!$select_found) {
|
2023-05-05 18:46:37 +02:00
|
|
|
$destination_label = str_replace(":", " ", $destination_value ?? '');
|
2020-11-19 17:54:32 +01:00
|
|
|
$destination_label = str_replace("menu-exec-app", "", $destination_label);
|
|
|
|
|
$destination_label = str_replace("transfer", "", $destination_label);
|
|
|
|
|
$destination_label = str_replace("XML ".$this->domain_name, "", $destination_label);
|
2023-05-17 06:51:16 +02:00
|
|
|
if (!empty($destination_value) || !empty($destination_label)) {
|
2020-11-19 17:54:32 +01:00
|
|
|
$response .= " <option value='".escape($destination_value)."' selected='selected'>".trim($destination_label)."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$response .= " </select>\n";
|
|
|
|
|
if (if_group("superadmin")) {
|
|
|
|
|
$response .= "<input type='button' id='btn_select_to_input_".$destination_id."' class='btn' name='' alt='back' onclick='changeToInput".$destination_id."(document.getElementById(\"".$destination_id."\"));this.style.visibility = \"hidden\";' value='◁'>";
|
2020-02-20 03:54:10 +01:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2020-11-19 17:54:32 +01:00
|
|
|
|
|
|
|
|
//create a dynamic destination select list
|
|
|
|
|
if ($_SESSION['destinations']['select_mode']['text'] == 'dynamic') {
|
|
|
|
|
|
|
|
|
|
//remove special characters from the name
|
|
|
|
|
$destination_id = str_replace("]", "", $destination_name);
|
|
|
|
|
$destination_id = str_replace("[", "_", $destination_id);
|
|
|
|
|
//$destination_id = preg_replace('/[^a-zA-Z_,.]/', '', $destination_name);
|
2023-05-18 00:03:36 +02:00
|
|
|
|
2025-03-12 20:55:47 +01:00
|
|
|
//send request for destinations
|
|
|
|
|
echo "<script type=\"text/javascript\">\n";
|
|
|
|
|
echo " function get_destinations(id, destination_type, action, search) {\n";
|
|
|
|
|
echo " var xhttp = new XMLHttpRequest();\n";
|
|
|
|
|
echo " xhttp.onreadystatechange = function() {\n";
|
|
|
|
|
echo " if (this.readyState == 4 && this.status == 200) {\n";
|
|
|
|
|
echo " document.getElementById(id).innerHTML = this.responseText;\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
echo " };\n";
|
|
|
|
|
echo " if (action) {\n";
|
|
|
|
|
echo " xhttp.open(\"GET\", \"/app/destinations/resources/destinations.php?destination_type=\"+destination_type+\"&action=\"+action, true);\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
echo " else {\n";
|
|
|
|
|
echo " xhttp.open(\"GET\", \"/app/destinations/resources/destinations.php?destination_type=\"+destination_type, true);\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
echo " xhttp.send();\n";
|
|
|
|
|
echo " }\n";
|
|
|
|
|
echo "</script>\n";
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//get the destinations
|
2024-02-21 19:23:58 +01:00
|
|
|
$destinations = $this->get($destination_type);
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//get the destination label
|
2024-02-21 19:23:58 +01:00
|
|
|
foreach($destinations as $key => $value) {
|
2020-11-19 17:54:32 +01:00
|
|
|
foreach($value as $k => $row) {
|
|
|
|
|
if ($destination_value == $row['destination']) {
|
|
|
|
|
$destination_key = $key;
|
|
|
|
|
$destination_label = $row['label'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//add the language object
|
|
|
|
|
$language2 = new text;
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//build the destination select list in html
|
2021-03-23 06:42:33 +01:00
|
|
|
$response .= " <select id='{$destination_id}_type' class='formfld' style='".$select_style."' onchange=\"get_destinations('".$destination_id."', '".$destination_type."', this.value);\">\n";
|
2020-11-19 17:54:32 +01:00
|
|
|
$response .= " <option value=''></option>\n";
|
2024-02-21 19:23:58 +01:00
|
|
|
foreach($destinations as $key => $value) {
|
2021-03-23 05:13:33 +01:00
|
|
|
$singular = $this->singular($key);
|
|
|
|
|
if (permission_exists("{$singular}_destinations")) {
|
2020-11-19 17:54:32 +01:00
|
|
|
//determine if selected
|
2023-09-20 21:13:33 +02:00
|
|
|
$selected = (isset($destination_key) && $key == $destination_key) ? "selected='selected'" : '';
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-11-19 17:54:32 +01:00
|
|
|
//add multi-lingual support
|
|
|
|
|
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$key."/app_languages.php")) {
|
2020-11-23 17:32:02 +01:00
|
|
|
$language2 = new text;
|
2020-11-19 17:54:32 +01:00
|
|
|
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$key);
|
2020-11-23 17:32:02 +01:00
|
|
|
$found = 'true';
|
|
|
|
|
}
|
|
|
|
|
if ($key == 'other') {
|
|
|
|
|
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/dialplans');
|
2020-11-19 17:54:32 +01:00
|
|
|
}
|
|
|
|
|
//add the application to the select list
|
2021-03-23 05:13:33 +01:00
|
|
|
$response .= " <option id='{$singular}' class='{$key}' value='".$key."' $selected>".$text2['title-'.$key]."</option>\n";
|
2020-11-19 17:54:32 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$response .= " </select>\n";
|
2023-09-09 00:05:19 +02:00
|
|
|
$response .= " <select id='".$destination_id."' name='".$destination_name."' class='formfld' style='".$select_style." min-width: 200px;'>\n";
|
2024-02-21 19:23:58 +01:00
|
|
|
foreach($destinations as $key => $value) {
|
2023-09-20 21:13:33 +02:00
|
|
|
if (isset($destination_key) && $key == $destination_key) {
|
2020-11-19 17:54:32 +01:00
|
|
|
foreach($value as $k => $row) {
|
2021-03-23 05:24:15 +01:00
|
|
|
$selected = ($row['destination'] == $destination_value) ? "selected='selected'" : '';
|
2023-09-20 22:49:27 +02:00
|
|
|
$uuid = isset($row[$this->singular($key).'_uuid']) ? $row[$this->singular($key).'_uuid'] : ($row['uuid'] ?? '');
|
2021-03-23 05:24:15 +01:00
|
|
|
$response .= " <option id='{$uuid}' value='".$row['destination']."' $selected>".$row['label']."</option>\n";
|
2020-11-19 17:54:32 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-23 05:13:33 +01:00
|
|
|
$response .= " </select>";
|
|
|
|
|
$response .= button::create([
|
|
|
|
|
'type'=>'button',
|
|
|
|
|
'icon'=>'external-link-alt',
|
|
|
|
|
'id'=>'btn_dest_go',
|
2023-09-20 21:13:33 +02:00
|
|
|
'title'=>$text2['button-edit'],
|
2021-03-23 06:42:33 +01:00
|
|
|
'onclick'=>"let types = document.getElementById('{$destination_id}_type').options; let opts = document.getElementById('{$destination_id}').options; if(opts[opts.selectedIndex].id && opts[opts.selectedIndex].id.length > 0) {window.open('/app/'+types[types.selectedIndex].className+'/'+types[types.selectedIndex].id+'_edit.php?id='+opts[opts.selectedIndex].id, '_blank');}"
|
2021-03-23 05:13:33 +01:00
|
|
|
])."\n";
|
2020-11-19 17:54:32 +01:00
|
|
|
|
|
|
|
|
//debug information
|
|
|
|
|
//echo $response;
|
|
|
|
|
//echo "destination_key $destination_key\n";
|
|
|
|
|
//echo "destination_id $destination_id\n";
|
|
|
|
|
//echo "destination_type $destination_type\n";
|
|
|
|
|
//echo "destination_name $destination_name\n";
|
|
|
|
|
//echo "destination_value $destination_value\n";
|
|
|
|
|
//exit;
|
|
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2016-04-26 03:30:23 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//return the formatted destinations
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
2017-12-21 09:36:36 +01:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
/**
|
|
|
|
|
* Get all the destinations
|
|
|
|
|
* @var string $destination_type can be ivr, dialplan, call_center_contact or bridge
|
|
|
|
|
*/
|
|
|
|
|
public function all($destination_type) {
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//set the global variables
|
|
|
|
|
global $db_type;
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2023-05-17 06:51:16 +02:00
|
|
|
//set default values
|
|
|
|
|
$destination_name = '';
|
|
|
|
|
$destination_id = '';
|
|
|
|
|
|
2020-03-08 08:29:31 +01:00
|
|
|
//get the domain_name
|
|
|
|
|
$sql = "select domain_name from v_domains ";
|
|
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$parameters['domain_uuid'] = $this->domain_uuid;
|
2025-01-18 23:47:56 +01:00
|
|
|
$this->domain_name = $this->database->select($sql, $parameters, 'column');
|
2020-03-08 08:29:31 +01:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//get the destinations
|
|
|
|
|
if (!is_array($this->destinations)) {
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//get the array from the app_config.php files
|
|
|
|
|
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
|
|
|
|
$x = 0;
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($config_list as $config_path) {
|
2020-11-04 18:46:58 +01:00
|
|
|
try {
|
2024-02-21 19:23:58 +01:00
|
|
|
include($config_path);
|
2020-11-04 18:46:58 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
2024-02-21 19:23:58 +01:00
|
|
|
//echo 'Caught exception: ', $e->getMessage(), "\n";
|
2020-11-04 18:46:58 +01:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
$i = 0;
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($apps as $x => $app) {
|
2019-11-06 19:29:11 +01:00
|
|
|
if (isset($app['destinations'])) {
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($app['destinations'] as $row) {
|
2019-11-06 19:29:11 +01:00
|
|
|
$this->destinations[] = $row;
|
|
|
|
|
}
|
2019-09-10 21:50:42 +02:00
|
|
|
}
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
2019-09-10 21:50:42 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//put the array in order
|
|
|
|
|
foreach ($this->destinations as $row) {
|
|
|
|
|
$option_groups[] = $row['label'];
|
|
|
|
|
}
|
|
|
|
|
array_multisort($option_groups, SORT_ASC, $this->destinations);
|
|
|
|
|
|
|
|
|
|
//add the sql and data to the array
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach ($this->destinations as $row) {
|
2020-06-18 18:44:16 +02:00
|
|
|
if ($row['type'] === 'sql') {
|
2019-11-06 19:29:11 +01:00
|
|
|
$table_name = preg_replace('#[^a-zA-Z0-9_]#', '', $row['name']);
|
|
|
|
|
if (isset($row['sql'])) {
|
|
|
|
|
if (is_array($row['sql'])) {
|
|
|
|
|
$sql = trim($row['sql'][$db_type])." ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql = trim($row['sql'])." ";
|
|
|
|
|
}
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-11-06 19:29:11 +01:00
|
|
|
$field_count = count($row['field']);
|
|
|
|
|
$fields = '';
|
|
|
|
|
$c = 1;
|
|
|
|
|
foreach ($row['field'] as $key => $value) {
|
|
|
|
|
$key = preg_replace('#[^a-zA-Z0-9_]#', '', $key);
|
|
|
|
|
$value = preg_replace('#[^a-zA-Z0-9_]#', '', $value);
|
|
|
|
|
if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; }
|
|
|
|
|
$fields .= $value." as ".$key.$delimiter." ";
|
|
|
|
|
$c++;
|
|
|
|
|
}
|
|
|
|
|
$sql = "select ".$fields;
|
|
|
|
|
$sql .= " from v_".$table_name." ";
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
if (isset($row['where'])) {
|
|
|
|
|
$sql .= trim($row['where'])." ";
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
$sql .= "order by ".trim($row['order_by']);
|
2020-03-08 08:29:31 +01:00
|
|
|
$sql = str_replace("\${domain_uuid}", $this->domain_uuid, $sql);
|
2025-01-18 23:47:56 +01:00
|
|
|
$result = $this->database->select($sql, null, 'all');
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
$this->destinations[$x]['result']['sql'] = $sql;
|
|
|
|
|
$this->destinations[$x]['result']['data'] = $result;
|
|
|
|
|
}
|
2020-06-18 18:44:16 +02:00
|
|
|
if ($row['type'] === 'array') {
|
|
|
|
|
$this->destinations[$x] = $row;
|
|
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
$x++;
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
2020-06-19 01:07:24 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
$this->destinations[$x]['type'] = 'array';
|
|
|
|
|
$this->destinations[$x]['label'] = 'other';
|
|
|
|
|
$this->destinations[$x]['name'] = 'dialplans';
|
|
|
|
|
$this->destinations[$x]['field']['name'] = "name";
|
|
|
|
|
$this->destinations[$x]['field']['destination'] = "destination";
|
|
|
|
|
$this->destinations[$x]['select_value']['dialplan'] = "transfer:\${destination}";
|
|
|
|
|
$this->destinations[$x]['select_value']['ivr'] = "menu-exec-app:transfer \${destination}";
|
|
|
|
|
$this->destinations[$x]['select_label'] = "\${name}";
|
2020-11-19 17:54:32 +01:00
|
|
|
$y=0;
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'check_voicemail';
|
2019-11-06 19:29:11 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*98 XML ${context}';
|
|
|
|
|
$y++;
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'company_directory';
|
2019-11-06 19:29:11 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*411 XML ${context}';
|
|
|
|
|
$y++;
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'hangup';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['application'] = 'hangup';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '';
|
|
|
|
|
$y++;
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'record';
|
2019-11-06 19:29:11 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*732 XML ${context}';
|
|
|
|
|
$y++;
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//remove special characters from the name
|
|
|
|
|
$destination_id = str_replace("]", "", $destination_name);
|
|
|
|
|
$destination_id = str_replace("[", "_", $destination_id);
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//set default to false
|
|
|
|
|
$select_found = false;
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
foreach ($this->destinations as $row) {
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
$name = $row['name'];
|
|
|
|
|
$label = $row['label'];
|
2023-05-17 06:51:16 +02:00
|
|
|
$destination = $row['field']['destination'] ?? '';
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//add multi-lingual support
|
|
|
|
|
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) {
|
|
|
|
|
$language2 = new text;
|
|
|
|
|
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name);
|
|
|
|
|
}
|
2018-10-16 08:33:43 +02:00
|
|
|
|
2023-05-17 06:51:16 +02:00
|
|
|
if (!empty($row['result']['data']) && !empty($row['select_value'][$destination_type])) {
|
2019-11-06 19:29:11 +01:00
|
|
|
$label2 = $label;
|
|
|
|
|
foreach ($row['result']['data'] as $data) {
|
|
|
|
|
$select_value = $row['select_value'][$destination_type];
|
|
|
|
|
$select_label = $row['select_label'];
|
|
|
|
|
foreach ($row['field'] as $key => $value) {
|
2023-05-18 00:03:36 +02:00
|
|
|
if (!empty($key) && $key == 'destination' && !empty($value) && is_array($value)){
|
2023-05-17 06:51:16 +02:00
|
|
|
if (!empty($value['type']) && $value['type'] == 'csv') {
|
2019-11-06 19:29:11 +01:00
|
|
|
$array = explode($value['delimiter'], $data[$key]);
|
|
|
|
|
$select_value = str_replace("\${destination}", $array[0], $select_value);
|
|
|
|
|
$select_label = str_replace("\${destination}", $array[0], $select_label);
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-11-06 19:29:11 +01:00
|
|
|
if (strpos($value,',') !== false) {
|
|
|
|
|
$keys = explode(",", $value);
|
|
|
|
|
foreach ($keys as $k) {
|
2023-05-05 18:46:37 +02:00
|
|
|
if (!empty($data[$k])) {
|
2019-11-06 19:29:11 +01:00
|
|
|
$select_value = str_replace("\${".$key."}", $data[$k], $select_value);
|
2023-05-05 18:46:37 +02:00
|
|
|
if (empty($data['label'])) {
|
2019-11-06 19:29:11 +01:00
|
|
|
$select_label = str_replace("\${".$key."}", $data[$k], $select_label);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$label = $data['label'];
|
|
|
|
|
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-05 18:46:37 +02:00
|
|
|
$select_value = str_replace("\${".$key."}", $data[$key] ?? '', $select_value);
|
|
|
|
|
if (empty($data['label'])) {
|
|
|
|
|
$select_label = str_replace("\${".$key."}", $data[$key] ?? '', $select_label);
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$label = $data['label'];
|
|
|
|
|
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//application: hangup
|
2023-05-05 18:46:37 +02:00
|
|
|
if (!empty($data['application'])) {
|
2019-11-06 19:29:11 +01:00
|
|
|
$select_value = str_replace("transfer", $data['application'], $select_value);
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 08:29:31 +01:00
|
|
|
$select_value = str_replace("\${domain_name}", $this->domain_name, $select_value);
|
|
|
|
|
$select_value = str_replace("\${context}", $this->domain_name, $select_value);
|
|
|
|
|
$select_label = str_replace("\${domain_name}", $this->domain_name, $select_label);
|
|
|
|
|
$select_label = str_replace("\${context}", $this->domain_name, $select_label);
|
2019-11-06 19:29:11 +01:00
|
|
|
$select_label = str_replace("✉", 'email-icon', $select_label);
|
|
|
|
|
$select_label = escape(trim($select_label));
|
|
|
|
|
$select_label = str_replace('email-icon', '✉', $select_label);
|
2023-05-17 06:51:16 +02:00
|
|
|
if (!empty($destination_value) && $select_value == $destination_value) { $selected = "selected='selected' "; $select_found = true; } else { $selected = ''; }
|
2019-11-06 19:29:11 +01:00
|
|
|
if ($label2 == 'destinations') { $select_label = format_phone($select_label); }
|
|
|
|
|
$array[$label][$select_label] = $select_value;
|
|
|
|
|
}
|
|
|
|
|
unset($text);
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
if (!$select_found) {
|
2023-05-17 06:51:16 +02:00
|
|
|
$destination_label = $destination_label ?? '';
|
|
|
|
|
$destination_value = $destination_value ?? '';
|
|
|
|
|
if(!empty($destination_value)) {
|
2023-05-05 18:46:37 +02:00
|
|
|
$destination_label = str_replace(":", " ", $destination_value);
|
2023-05-17 06:51:16 +02:00
|
|
|
}
|
|
|
|
|
$destination_label = str_replace("menu-exec-app", "", $destination_label);
|
2019-11-06 19:29:11 +01:00
|
|
|
$destination_label = str_replace("transfer", "", $destination_label);
|
2020-03-08 08:29:31 +01:00
|
|
|
$destination_label = str_replace("XML ".$this->domain_name, "", $destination_label);
|
2019-11-06 19:29:11 +01:00
|
|
|
$array[$label][$destination_label] = $destination_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//return the formatted destinations
|
|
|
|
|
return $array;
|
2018-10-16 08:33:43 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-23 18:46:28 +02:00
|
|
|
/**
|
|
|
|
|
* Get all the destinations
|
|
|
|
|
* @var string $destination_type can be ivr, dialplan, call_center_contact or bridge
|
|
|
|
|
*/
|
|
|
|
|
public function get($destination_type) {
|
|
|
|
|
|
|
|
|
|
//set the global variables
|
|
|
|
|
global $db_type;
|
|
|
|
|
|
|
|
|
|
//get the domain_name
|
|
|
|
|
$sql = "select domain_name from v_domains ";
|
|
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$parameters['domain_uuid'] = $this->domain_uuid;
|
2025-01-18 23:47:56 +01:00
|
|
|
$this->domain_name = $this->database->select($sql, $parameters, 'column');
|
2020-09-23 18:46:28 +02:00
|
|
|
|
|
|
|
|
//get the destinations
|
|
|
|
|
if (!is_array($this->destinations)) {
|
|
|
|
|
|
|
|
|
|
//get the array from the app_config.php files
|
|
|
|
|
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
|
|
|
|
$x = 0;
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($config_list as $config_path) {
|
2020-11-04 18:46:58 +01:00
|
|
|
try {
|
2020-11-19 17:54:32 +01:00
|
|
|
include($config_path);
|
2020-11-04 18:46:58 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
2020-11-19 17:54:32 +01:00
|
|
|
//echo 'Caught exception: ', $e->getMessage(), "\n";
|
2020-11-04 18:46:58 +01:00
|
|
|
}
|
2020-09-23 18:46:28 +02:00
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
$i = 0;
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($apps as $x => $app) {
|
2020-09-23 18:46:28 +02:00
|
|
|
if (isset($app['destinations'])) {
|
2024-08-22 20:41:10 +02:00
|
|
|
foreach ($app['destinations'] as $row) {
|
2020-09-23 18:46:28 +02:00
|
|
|
$this->destinations[] = $row;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//put the array in order
|
|
|
|
|
foreach ($this->destinations as $row) {
|
|
|
|
|
$option_groups[] = $row['label'];
|
|
|
|
|
}
|
|
|
|
|
array_multisort($option_groups, SORT_ASC, $this->destinations);
|
|
|
|
|
|
|
|
|
|
//add the sql and data to the array
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach ($this->destinations as $row) {
|
|
|
|
|
if ($row['type'] === 'sql') {
|
|
|
|
|
$table_name = preg_replace('#[^a-zA-Z0-9_]#', '', $row['name']);
|
|
|
|
|
if (isset($row['sql'])) {
|
|
|
|
|
if (is_array($row['sql'])) {
|
|
|
|
|
$sql = trim($row['sql'][$db_type])." ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql = trim($row['sql'])." ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$field_count = count($row['field']);
|
|
|
|
|
$fields = '';
|
|
|
|
|
$c = 1;
|
|
|
|
|
foreach ($row['field'] as $key => $value) {
|
|
|
|
|
$key = preg_replace('#[^a-zA-Z0-9_]#', '', $key);
|
|
|
|
|
$value = preg_replace('#[^a-zA-Z0-9_]#', '', $value);
|
|
|
|
|
if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; }
|
|
|
|
|
$fields .= $value." as ".$key.$delimiter." ";
|
|
|
|
|
$c++;
|
|
|
|
|
}
|
|
|
|
|
//$sql = "select * ";
|
|
|
|
|
$sql = "select ".$fields;
|
|
|
|
|
$sql .= " from v_".$table_name." ";
|
|
|
|
|
}
|
|
|
|
|
if (isset($row['where'])) {
|
|
|
|
|
$sql .= trim($row['where'])." ";
|
|
|
|
|
}
|
|
|
|
|
$sql .= "order by ".trim($row['order_by']);
|
|
|
|
|
$sql = str_replace("\${domain_uuid}", $this->domain_uuid, $sql);
|
2025-01-18 23:47:56 +01:00
|
|
|
$result = $this->database->select($sql, null, 'all');
|
2020-09-23 18:46:28 +02:00
|
|
|
|
|
|
|
|
$this->destinations[$x]['result']['sql'] = $sql;
|
|
|
|
|
$this->destinations[$x]['result']['data'] = $result;
|
|
|
|
|
}
|
|
|
|
|
if ($row['type'] === 'array') {
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x] = $row;
|
2020-09-23 18:46:28 +02:00
|
|
|
}
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->destinations[$x]['type'] = 'array';
|
|
|
|
|
$this->destinations[$x]['label'] = 'other';
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x]['name'] = 'other';
|
|
|
|
|
$this->destinations[$x]['field']['label'] = "label";
|
2020-09-23 18:46:28 +02:00
|
|
|
$this->destinations[$x]['field']['name'] = "name";
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x]['field']['extension'] = "extension";
|
2020-09-23 18:46:28 +02:00
|
|
|
$this->destinations[$x]['field']['destination'] = "destination";
|
|
|
|
|
$this->destinations[$x]['select_value']['dialplan'] = "transfer:\${destination}";
|
|
|
|
|
$this->destinations[$x]['select_value']['ivr'] = "menu-exec-app:transfer \${destination}";
|
|
|
|
|
$this->destinations[$x]['select_label'] = "\${name}";
|
|
|
|
|
$y = 0;
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'check_voicemail';
|
2020-09-29 19:43:48 +02:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['extension'] = '*98';
|
2020-09-23 18:46:28 +02:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*98 XML ${context}';
|
|
|
|
|
$y++;
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'company_directory';
|
2020-09-29 19:43:48 +02:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['extension'] = '*411';
|
2020-09-23 18:46:28 +02:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*411 XML ${context}';
|
|
|
|
|
$y++;
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'hangup';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['application'] = 'hangup';
|
|
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '';
|
|
|
|
|
$y++;
|
2020-11-23 17:32:02 +01:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['name'] = 'record';
|
2020-09-29 19:43:48 +02:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['extension'] = '*732';
|
2020-09-23 18:46:28 +02:00
|
|
|
$this->destinations[$x]['result']['data'][$y]['destination'] = '*732 XML ${context}';
|
|
|
|
|
$y++;
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-09-23 18:46:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//remove special characters from the name
|
2023-09-20 21:13:33 +02:00
|
|
|
$destination_id = str_replace("]", "", $destination_name ?? '');
|
2020-09-23 18:46:28 +02:00
|
|
|
$destination_id = str_replace("[", "_", $destination_id);
|
|
|
|
|
|
|
|
|
|
//set default to false
|
|
|
|
|
$select_found = false;
|
|
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
foreach ($this->destinations as $row) {
|
|
|
|
|
|
|
|
|
|
$name = $row['name'];
|
|
|
|
|
$label = $row['label'];
|
2023-09-20 22:49:27 +02:00
|
|
|
$destination = $row['field']['destination'] ?? null;
|
2020-09-23 18:46:28 +02:00
|
|
|
|
|
|
|
|
//add multi-lingual support
|
|
|
|
|
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) {
|
|
|
|
|
$language2 = new text;
|
|
|
|
|
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 19:23:58 +01:00
|
|
|
if (isset($row['result']) && isset($row['result']['data'][0]) && !empty($row['select_value'][$destination_type])) {
|
2020-09-23 18:46:28 +02:00
|
|
|
$label2 = $label;
|
|
|
|
|
foreach ($row['result']['data'] as $data) {
|
|
|
|
|
$select_value = $row['select_value'][$destination_type];
|
|
|
|
|
$select_label = $row['select_label'];
|
2020-11-23 17:32:02 +01:00
|
|
|
//echo $select_label." ".__line__." ".$name."<br />\n";
|
2020-09-23 18:46:28 +02:00
|
|
|
foreach ($row['field'] as $key => $value) {
|
|
|
|
|
if ($key == 'destination' and is_array($value)) {
|
|
|
|
|
if ($value['type'] == 'csv') {
|
|
|
|
|
$array = explode($value['delimiter'], $data[$key]);
|
|
|
|
|
$select_value = str_replace("\${destination}", $array[0], $select_value);
|
|
|
|
|
$select_label = str_replace("\${destination}", $array[0], $select_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (strpos($value,',') !== false) {
|
|
|
|
|
$keys = explode(",", $value);
|
|
|
|
|
foreach ($keys as $k) {
|
2023-05-05 18:46:37 +02:00
|
|
|
if (!empty($data[$k])) {
|
2020-09-23 18:46:28 +02:00
|
|
|
$select_value = str_replace("\${".$key."}", $data[$k], $select_value);
|
2023-05-05 18:46:37 +02:00
|
|
|
if (empty($data['label'])) {
|
2020-09-23 18:46:28 +02:00
|
|
|
$select_label = str_replace("\${".$key."}", $data[$k], $select_label);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-09-20 22:49:27 +02:00
|
|
|
$select_value = str_replace("\${".$key."}", ($data[$key] ?? ''), $select_value);
|
2023-05-05 18:46:37 +02:00
|
|
|
if (empty($data['label'])) {
|
2023-09-20 22:49:27 +02:00
|
|
|
$select_label = str_replace("\${".$key."}", ($data[$key] ?? ''), $select_label);
|
2020-09-23 18:46:28 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$select_label = str_replace("\${".$key."}", $text2['option-'.$label], $select_label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//application: hangup
|
2023-05-05 18:46:37 +02:00
|
|
|
if (!empty($data['application'])) {
|
2020-09-23 18:46:28 +02:00
|
|
|
$select_value = str_replace("transfer", $data['application'], $select_value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 17:32:02 +01:00
|
|
|
//view_array($data, false);
|
|
|
|
|
//echo "name ".$name."\n";
|
|
|
|
|
//echo "select_value ".$select_value."\n";
|
|
|
|
|
//echo "select_label ".$select_label."\n";
|
|
|
|
|
//echo "\n";
|
|
|
|
|
|
2020-09-23 18:46:28 +02:00
|
|
|
$select_value = str_replace("\${domain_name}", $this->domain_name, $select_value);
|
|
|
|
|
$select_value = str_replace("\${context}", $this->domain_name, $select_value);
|
|
|
|
|
$select_label = str_replace("\${domain_name}", $this->domain_name, $select_label);
|
|
|
|
|
$select_label = str_replace("\${context}", $this->domain_name, $select_label);
|
|
|
|
|
$select_label = str_replace("✉", 'email-icon', $select_label);
|
|
|
|
|
$select_label = escape(trim($select_label));
|
|
|
|
|
$select_label = str_replace('email-icon', '✉', $select_label);
|
2023-09-20 22:49:27 +02:00
|
|
|
if (isset($destination_value) && $select_value == $destination_value) { $selected = "true' "; } else { $selected = 'false'; }
|
2020-09-23 18:46:28 +02:00
|
|
|
if ($label2 == 'destinations') { $select_label = format_phone($select_label); }
|
|
|
|
|
|
|
|
|
|
$array[$name][$i] = $data;
|
|
|
|
|
$array[$name][$i]['label'] = $select_label;
|
|
|
|
|
//$array[$name][$i]['destination'] = $select_value;
|
|
|
|
|
//$array[$name][$i]['select_name'] = $select_name;
|
|
|
|
|
//$array[$name][$i]['select_value'] = $select_value;
|
|
|
|
|
//$array[$name][$i]['selected'] = $selected;
|
|
|
|
|
$array[$name][$i]['destination'] = $select_value;
|
2023-09-20 22:49:27 +02:00
|
|
|
$array[$name][$i]["extension"] = $data["extension"] ?? null;
|
2023-05-18 00:03:36 +02:00
|
|
|
|
2020-09-23 18:46:28 +02:00
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
unset($text);
|
|
|
|
|
}
|
2024-02-21 19:23:58 +01:00
|
|
|
//else {
|
|
|
|
|
// //add all main destination categories to the array
|
|
|
|
|
// if (!empty($row['select_value']) && !empty($row['select_value'][$destination_type])) {
|
|
|
|
|
// //add to the destination array if a matching destination type is found
|
|
|
|
|
// $array[$name] = [];
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// $array[$name] = [];
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2020-09-23 18:46:28 +02:00
|
|
|
}
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-09-23 18:46:28 +02:00
|
|
|
if (!$selected) {
|
|
|
|
|
$destination_label = str_replace(":", " ", $destination_value);
|
|
|
|
|
$destination_label = str_replace("menu-exec-app", "", $destination_label);
|
|
|
|
|
$destination_label = str_replace("transfer", "", $destination_label);
|
|
|
|
|
$destination_label = str_replace("XML ".$this->domain_name, "", $destination_label);
|
|
|
|
|
|
|
|
|
|
$array[$name][$i] = $row;
|
|
|
|
|
$array[$name][$i]['label'] = $destination_label;
|
|
|
|
|
//$array[$name][$i]['destination'] = $destination_value;
|
|
|
|
|
//$array[$name][$i]['select_name'] = $select_name;
|
|
|
|
|
//$array[$name][$i]['select_value'] = $select_value;
|
|
|
|
|
$array[$name][$i]['destination'] = $destination_value;
|
2020-11-23 17:32:02 +01:00
|
|
|
|
2020-09-23 18:46:28 +02:00
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//set the previous application name
|
|
|
|
|
$previous_application = $name;
|
|
|
|
|
|
|
|
|
|
//return the formatted destinations
|
|
|
|
|
return $array;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-30 07:45:55 +01:00
|
|
|
/**
|
|
|
|
|
* valid destination
|
|
|
|
|
*/
|
2020-06-19 01:07:24 +02:00
|
|
|
public function valid($destination, $type = 'dialplan') {
|
2022-05-03 17:46:26 +02:00
|
|
|
//allow an empty destination
|
|
|
|
|
if ($destination == ':') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get all of the $destinations
|
2020-06-25 00:42:03 +02:00
|
|
|
$destinations = $this->all($type);
|
2022-05-03 17:46:26 +02:00
|
|
|
|
|
|
|
|
//loop through destinations to validate them
|
2020-01-30 07:45:55 +01:00
|
|
|
foreach($destinations as $category => $array) {
|
|
|
|
|
if (is_array($array)) {
|
|
|
|
|
foreach ($array as $key => $value) {
|
|
|
|
|
if ($destination == $value) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
/**
|
|
|
|
|
* delete records
|
|
|
|
|
*/
|
|
|
|
|
public function delete($records) {
|
|
|
|
|
if (permission_exists($this->permission_prefix.'delete')) {
|
|
|
|
|
|
|
|
|
|
//add multi-lingual support
|
|
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
|
|
|
|
|
|
|
|
|
//validate the token
|
|
|
|
|
$token = new token;
|
|
|
|
|
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
|
|
|
|
message::add($text['message-invalid_token'],'negative');
|
|
|
|
|
header('Location: '.$this->list_page);
|
|
|
|
|
exit;
|
2018-01-09 20:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//delete multiple records
|
|
|
|
|
if (is_array($records) && @sizeof($records) != 0) {
|
|
|
|
|
|
|
|
|
|
//build the delete array
|
|
|
|
|
foreach ($records as $x => $record) {
|
2023-05-23 01:05:44 +02:00
|
|
|
if (!empty($record['checked'] ) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
2019-11-06 19:29:11 +01:00
|
|
|
|
|
|
|
|
//build delete array
|
|
|
|
|
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
|
|
|
|
|
|
|
|
|
//get the dialplan uuid and context
|
|
|
|
|
$sql = "select dialplan_uuid, destination_context from v_destinations ";
|
|
|
|
|
$sql .= "where destination_uuid = :destination_uuid ";
|
|
|
|
|
$parameters['destination_uuid'] = $record['uuid'];
|
2025-01-18 23:47:56 +01:00
|
|
|
$row = $this->database->select($sql, $parameters, 'row');
|
2019-11-06 19:29:11 +01:00
|
|
|
unset($sql, $parameters);
|
|
|
|
|
|
|
|
|
|
//include dialplan in array
|
|
|
|
|
if (is_uuid($row['dialplan_uuid'])) {
|
|
|
|
|
$array['dialplan_details'][$x]['dialplan_uuid'] = $row["dialplan_uuid"];
|
|
|
|
|
$array['dialplans'][$x]['dialplan_uuid'] = $row["dialplan_uuid"];
|
|
|
|
|
$destination_contexts[] = $row['destination_context'];
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 03:34:56 +02:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
2019-05-06 03:34:56 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//delete the checked rows
|
|
|
|
|
if (is_array($array) && @sizeof($array) != 0) {
|
|
|
|
|
|
|
|
|
|
//grant temporary permissions
|
2024-11-29 21:57:01 +01:00
|
|
|
$p = permissions::new();
|
2019-11-06 19:29:11 +01:00
|
|
|
$p->add('dialplan_delete', 'temp');
|
|
|
|
|
$p->add('dialplan_detail_delete', 'temp');
|
|
|
|
|
|
|
|
|
|
//execute delete
|
2025-01-18 23:47:56 +01:00
|
|
|
$this->database->app_name = $this->app_name;
|
|
|
|
|
$this->database->app_uuid = $this->app_uuid;
|
|
|
|
|
$this->database->delete($array);
|
2019-11-06 19:29:11 +01:00
|
|
|
unset($array);
|
|
|
|
|
|
|
|
|
|
//revoke temporary permissions
|
|
|
|
|
$p->delete('dialplan_delete', 'temp');
|
|
|
|
|
$p->delete('dialplan_detail_delete', 'temp');
|
|
|
|
|
|
|
|
|
|
//clear the cache
|
|
|
|
|
if (is_array($destination_contexts) && @sizeof($destination_contexts) != 0) {
|
|
|
|
|
$destination_contexts = array_unique($destination_contexts);
|
|
|
|
|
$cache = new cache;
|
|
|
|
|
foreach ($destination_contexts as $destination_context) {
|
|
|
|
|
$cache->delete("dialplan:".$destination_context);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-06 03:34:56 +02:00
|
|
|
|
2020-11-30 23:53:44 +01:00
|
|
|
//clear the destinations session array
|
2023-09-01 18:57:55 +02:00
|
|
|
if (isset($_SESSION['destinations'][$this->domain_uuid]['array'])) {
|
|
|
|
|
unset($_SESSION['destinations'][$this->domain_uuid]['array']);
|
2020-11-30 23:53:44 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
//set message
|
|
|
|
|
message::add($text['message-delete']);
|
2019-05-06 03:34:56 +02:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
}
|
|
|
|
|
unset($records);
|
|
|
|
|
|
|
|
|
|
}
|
2018-01-09 20:45:04 +01:00
|
|
|
}
|
2019-11-06 19:29:11 +01:00
|
|
|
} //method
|
|
|
|
|
|
2024-01-03 02:54:22 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* destination summary returns an array
|
|
|
|
|
*/
|
|
|
|
|
public function destination_summary() {
|
|
|
|
|
|
|
|
|
|
//set the time zone
|
2024-03-29 05:13:01 +01:00
|
|
|
if (!empty($this->settings->get('domain', 'time_zone'))) {
|
|
|
|
|
$time_zone = $this->settings->get('domain', 'time_zone');
|
2024-01-03 02:54:22 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$time_zone = date_default_timezone_get();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-09 01:44:09 +01:00
|
|
|
//set the time zone for php
|
|
|
|
|
date_default_timezone_set($time_zone);
|
|
|
|
|
|
2024-01-03 02:54:22 +01:00
|
|
|
//build the date range
|
2024-05-13 20:17:14 +02:00
|
|
|
if (!empty($this->start_stamp_begin) || !empty($this->start_stamp_end)) {
|
2024-01-03 02:54:22 +01:00
|
|
|
unset($this->quick_select);
|
|
|
|
|
if (strlen($this->start_stamp_begin) > 0 && !empty($this->start_stamp_end)) {
|
|
|
|
|
$sql_date_range = " and start_stamp between :start_stamp_begin::timestamptz and :start_stamp_end::timestamptz \n";
|
|
|
|
|
$parameters['start_stamp_begin'] = $this->start_stamp_begin.':00.000 '.$time_zone;
|
|
|
|
|
$parameters['start_stamp_end'] = $this->start_stamp_end.':59.999 '.$time_zone;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (!empty($this->start_stamp_begin)) {
|
|
|
|
|
$sql_date_range = "and start_stamp >= :start_stamp_begin::timestamptz \n";
|
|
|
|
|
$parameters['start_stamp_begin'] = $this->start_stamp_begin.':00.000 '.$time_zone;
|
|
|
|
|
}
|
|
|
|
|
if (!empty($this->start_stamp_end)) {
|
|
|
|
|
$sql_date_range .= "and start_stamp <= :start_stamp_end::timestamptz \n";
|
|
|
|
|
$parameters['start_stamp_end'] = $this->start_stamp_end.':59.999 '.$time_zone;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
switch ($this->quick_select) {
|
|
|
|
|
case 1: $sql_date_range = "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 week"))." ".$time_zone."'::timestamptz \n"; break; //last 7 days
|
|
|
|
|
case 2: $sql_date_range = "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 hour"))." ".$time_zone."'::timestamptz \n"; break; //last hour
|
|
|
|
|
case 3: $sql_date_range = "and start_stamp >= '".date('Y-m-d')." "."00:00:00.000 ".$time_zone."'::timestamptz \n"; break; //today
|
|
|
|
|
case 4: $sql_date_range = "and start_stamp between '".date('Y-m-d',strtotime("-1 day"))." "."00:00:00.000 ".$time_zone."'::timestamptz and '".date('Y-m-d',strtotime("-1 day"))." "."23:59:59.999 ".$time_zone."'::timestamptz \n"; break; //yesterday
|
|
|
|
|
case 5: $sql_date_range = "and start_stamp >= '".date('Y-m-d',strtotime("this week"))." "."00:00:00.000 ".$time_zone."' \n"; break; //this week
|
|
|
|
|
case 6: $sql_date_range = "and start_stamp >= '".date('Y-m-')."01 "."00:00:00.000 ".$time_zone."'::timestamptz \n"; break; //this month
|
|
|
|
|
case 7: $sql_date_range = "and start_stamp >= '".date('Y-')."01-01 "."00:00:00.000 ".$time_zone."'::timestamptz \n"; break; //this year
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//calculate the summary data
|
|
|
|
|
$sql = "select \n";
|
|
|
|
|
$sql .= "d.domain_uuid, \n";
|
|
|
|
|
$sql .= "n.domain_name, \n";
|
|
|
|
|
$sql .= "d.destination_uuid, \n";
|
|
|
|
|
$sql .= "d.dialplan_uuid, \n";
|
|
|
|
|
$sql .= "d.destination_type, \n";
|
|
|
|
|
$sql .= "d.destination_prefix, \n";
|
|
|
|
|
$sql .= "d.destination_number, \n";
|
|
|
|
|
|
|
|
|
|
//total_calls
|
|
|
|
|
$sql .= "count(*) \n";
|
|
|
|
|
$sql .= "filter ( \n";
|
|
|
|
|
$sql .= " where caller_destination in (d.destination_number, concat(d.destination_prefix, d.destination_number), concat('+', d.destination_prefix, d.destination_number)) \n";
|
2024-01-09 08:22:53 +01:00
|
|
|
$sql .= " and (cc_side is null or cc_side <> 'agent') \n"; //include regular calls and call center calls while excluding calls directly to agents
|
2024-01-03 02:54:22 +01:00
|
|
|
$sql .= ") \n";
|
|
|
|
|
$sql .= "as total_calls, \n";
|
|
|
|
|
|
|
|
|
|
//answered_calls
|
|
|
|
|
$sql .= "count(*) \n";
|
|
|
|
|
$sql .= "filter ( \n";
|
|
|
|
|
$sql .= " where caller_destination in (d.destination_number, concat(d.destination_prefix, d.destination_number), concat('+', d.destination_prefix, d.destination_number)) \n";
|
|
|
|
|
$sql .= " and billsec > 0 \n";
|
|
|
|
|
$sql .= ") \n";
|
|
|
|
|
$sql .= "as answered_calls, \n";
|
|
|
|
|
|
|
|
|
|
//unique_callers
|
2024-01-04 21:54:03 +01:00
|
|
|
$sql .= "count(distinct(c.caller_id_number)) \n";
|
2024-01-03 02:54:22 +01:00
|
|
|
$sql .= "filter ( \n";
|
|
|
|
|
$sql .= " where caller_destination in (d.destination_number, concat(d.destination_prefix, d.destination_number), concat('+', d.destination_prefix, d.destination_number)) \n";
|
|
|
|
|
$sql .= " and billsec > 0 \n";
|
|
|
|
|
$sql .= ") \n";
|
|
|
|
|
$sql .= "as unique_callers, \n";
|
|
|
|
|
|
|
|
|
|
//total_seconds
|
|
|
|
|
$sql .= "sum(billsec) \n";
|
|
|
|
|
$sql .= "filter ( \n";
|
|
|
|
|
$sql .= " where caller_destination in (d.destination_number, concat(d.destination_prefix, d.destination_number), concat('+', d.destination_prefix, d.destination_number)) \n";
|
|
|
|
|
$sql .= " and billsec > 0 \n";
|
|
|
|
|
$sql .= ") \n";
|
|
|
|
|
$sql .= "as total_seconds, \n";
|
|
|
|
|
|
|
|
|
|
$sql .= "d.destination_description \n";
|
|
|
|
|
|
|
|
|
|
$sql .= "from v_destinations as d, v_domains as n, \n";
|
|
|
|
|
$sql .= "( select \n";
|
|
|
|
|
$sql .= " domain_uuid, \n";
|
|
|
|
|
$sql .= " extension_uuid, \n";
|
|
|
|
|
$sql .= " caller_id_name, \n";
|
|
|
|
|
$sql .= " caller_id_number, \n";
|
|
|
|
|
$sql .= " caller_destination, \n";
|
|
|
|
|
$sql .= " destination_number, \n";
|
|
|
|
|
$sql .= " missed_call, \n";
|
|
|
|
|
$sql .= " answer_stamp, \n";
|
|
|
|
|
$sql .= " bridge_uuid, \n";
|
|
|
|
|
$sql .= " direction, \n";
|
|
|
|
|
$sql .= " start_stamp, \n";
|
|
|
|
|
$sql .= " hangup_cause, \n";
|
|
|
|
|
$sql .= " originating_leg_uuid, \n";
|
|
|
|
|
$sql .= " billsec, \n";
|
|
|
|
|
$sql .= " cc_side, \n";
|
|
|
|
|
$sql .= " sip_hangup_disposition \n";
|
|
|
|
|
$sql .= " from v_xml_cdr \n";
|
|
|
|
|
if (!(!empty($_GET['show']) && $_GET['show'] === 'all' && permission_exists('destination_summary_all'))) {
|
|
|
|
|
$sql .= " where domain_uuid = :domain_uuid \n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql .= " where true \n";
|
|
|
|
|
}
|
|
|
|
|
$sql .= " and direction = 'inbound' \n";
|
|
|
|
|
$sql .= " and caller_destination is not null \n";
|
2024-11-15 22:32:45 +01:00
|
|
|
$sql .= " and leg = 'a' \n";
|
2024-05-13 19:46:51 +02:00
|
|
|
$sql .= $sql_date_range ?? '';
|
2024-01-03 02:54:22 +01:00
|
|
|
$sql .= ") as c \n";
|
|
|
|
|
|
|
|
|
|
$sql .= "where \n";
|
|
|
|
|
$sql .= "d.domain_uuid = n.domain_uuid \n";
|
|
|
|
|
if (!(!empty($_GET['show']) && $_GET['show'] === 'all' && permission_exists('destination_summary_all'))) {
|
|
|
|
|
$sql .= "and d.domain_uuid = :domain_uuid \n";
|
|
|
|
|
}
|
|
|
|
|
$sql .= "and destination_type = 'inbound' \n";
|
|
|
|
|
$sql .= "and destination_enabled = 'true' \n";
|
|
|
|
|
$sql .= "group by d.domain_uuid, d.destination_uuid, d.dialplan_uuid, n.domain_name, d.destination_type, d.destination_prefix, d.destination_number \n";
|
|
|
|
|
$sql .= "order by destination_number asc \n";
|
|
|
|
|
if (!(!empty($_GET['show']) && $_GET['show'] === 'all' && permission_exists('destination_summary_all'))) {
|
|
|
|
|
$parameters['domain_uuid'] = $this->domain_uuid;
|
|
|
|
|
}
|
2025-01-18 23:47:56 +01:00
|
|
|
$summary = $this->database->select($sql, $parameters, 'all');
|
2024-01-03 02:54:22 +01:00
|
|
|
unset($parameters);
|
|
|
|
|
|
|
|
|
|
//if (!empty($this->start_stamp_begin) && !empty($this->start_stamp_end)) {
|
|
|
|
|
// view_array($summary);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//return the array
|
|
|
|
|
return $summary;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-01-21 21:14:03 +01:00
|
|
|
/**
|
|
|
|
|
* define singular function to convert a word in english to singular
|
|
|
|
|
*/
|
|
|
|
|
public function singular($word) {
|
|
|
|
|
//"-es" is used for words that end in "-x", "-s", "-z", "-sh", "-ch" in which case you add
|
|
|
|
|
if (substr($word, -2) == "es") {
|
|
|
|
|
if (substr($word, -4) == "sses") { // eg. 'addresses' to 'address'
|
|
|
|
|
return substr($word,0,-2);
|
|
|
|
|
}
|
|
|
|
|
elseif (substr($word, -3) == "ses") { // eg. 'databases' to 'database' (necessary!)
|
|
|
|
|
return substr($word,0,-1);
|
|
|
|
|
}
|
|
|
|
|
elseif (substr($word, -3) == "ies") { // eg. 'countries' to 'country'
|
|
|
|
|
return substr($word,0,-3)."y";
|
|
|
|
|
}
|
|
|
|
|
elseif (substr($word, -3, 1) == "x") {
|
|
|
|
|
return substr($word,0,-2);
|
|
|
|
|
}
|
|
|
|
|
elseif (substr($word, -3, 1) == "s") {
|
|
|
|
|
return substr($word,0,-2);
|
|
|
|
|
}
|
|
|
|
|
elseif (substr($word, -3, 1) == "z") {
|
|
|
|
|
return substr($word,0,-2);
|
|
|
|
|
}
|
|
|
|
|
elseif (substr($word, -4, 2) == "sh") {
|
|
|
|
|
return substr($word,0,-2);
|
|
|
|
|
}
|
|
|
|
|
elseif (substr($word, -4, 2) == "ch") {
|
|
|
|
|
return substr($word,0,-2);
|
2020-01-21 17:43:19 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return rtrim($word, "s");
|
|
|
|
|
}
|
2020-01-21 21:14:03 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return rtrim($word, "s");
|
|
|
|
|
}
|
|
|
|
|
} //method
|
2020-01-21 17:43:19 +01:00
|
|
|
|
2019-11-06 19:29:11 +01:00
|
|
|
} //class
|
2025-03-12 20:55:47 +01:00
|
|
|
|
2016-04-26 03:30:23 +02:00
|
|
|
/*
|
|
|
|
|
$obj = new destinations;
|
|
|
|
|
//$destinations = $obj->destinations;
|
|
|
|
|
echo $obj->select('ivr', 'example1', 'menu-exec-app:transfer 32 XML voip.fusionpbx.com');
|
|
|
|
|
echo $obj->select('ivr', 'example2', '');
|
|
|
|
|
echo $obj->select('ivr', 'example3', '');
|
|
|
|
|
echo $obj->select('ivr', 'example4', '');
|
|
|
|
|
echo $obj->select('ivr', 'example5', '');
|
|
|
|
|
echo $obj->select('ivr', 'example6', '');
|
|
|
|
|
*/
|