mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Update extension caller_id so it would work better with the dashboard
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
The Initial Developer of the Original Code is
|
The Initial Developer of the Original Code is
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
Portions created by the Initial Developer are Copyright (C) 2017 - 2019
|
Portions created by the Initial Developer are Copyright (C) 2017 - 2021
|
||||||
the Initial Developer. All Rights Reserved.
|
the Initial Developer. All Rights Reserved.
|
||||||
|
|
||||||
Contributor(s):
|
Contributor(s):
|
||||||
@@ -29,207 +29,201 @@
|
|||||||
require_once "resources/require.php";
|
require_once "resources/require.php";
|
||||||
require_once "resources/check_auth.php";
|
require_once "resources/check_auth.php";
|
||||||
|
|
||||||
|
|
||||||
//check permissions
|
//check permissions
|
||||||
if (permission_exists('extension_caller_id')) {
|
if (permission_exists('extension_caller_id')) {
|
||||||
//access granted
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
echo "access denied";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
//add multi-lingual support
|
//add multi-lingual support
|
||||||
$language = new text;
|
$language = new text;
|
||||||
$text = $language->get($_SESSION['domain']['language']['code'], 'app/extensions');
|
$text = $language->get($_SESSION['domain']['language']['code'], 'app/extensions');
|
||||||
|
|
||||||
//add or update the database
|
//add or update the database
|
||||||
if (is_array($_POST['extensions']) && @sizeof($_POST['extensions']) != 0) {
|
if (is_array($_POST['extensions']) && @sizeof($_POST['extensions']) != 0) {
|
||||||
|
|
||||||
//validate the token
|
//validate the token
|
||||||
$token = new token;
|
$token = new token;
|
||||||
if (!$token->validate('/app/extensions/extension_dashboard.php')) {
|
if (!$token->validate($_SERVER["DOCUMENT_ROOT"].'/extensions/resources/dashboard/caller_id.php')) {
|
||||||
message::add($text['message-invalid_token'],'negative');
|
message::add($text['message-invalid_token'],'negative');
|
||||||
header('Location: /core/user_settings/user_dashboard.php');
|
header('Location: /core/dashboard/');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
//build a new array to make sure it only contains what the user is allowed to change
|
//build a new array to make sure it only contains what the user is allowed to change
|
||||||
$x=0;
|
$x=0;
|
||||||
foreach ($_POST['extensions'] as $row) {
|
foreach ($_POST['extensions'] as $row) {
|
||||||
//loop through the extensions
|
//loop through the extensions
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach ($_SESSION['user']['extension'] as $field) {
|
foreach ($_SESSION['user']['extension'] as $field) {
|
||||||
if ($field['extension_uuid'] == $row['extension_uuid']) {
|
if ($field['extension_uuid'] == $row['extension_uuid']) {
|
||||||
//set as found
|
//set as found
|
||||||
$found = true;
|
$found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//build the array on what is allowed.
|
||||||
|
if ($found) {
|
||||||
|
if (permission_exists('outbound_caller_id_select')) {
|
||||||
|
$caller_id = explode('@', $row['outbound_caller_id']);
|
||||||
|
$outbound_caller_id_name = $caller_id[0];
|
||||||
|
$outbound_caller_id_number = $caller_id[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$outbound_caller_id_name = $row['outbound_caller_id_name'];
|
||||||
|
$outbound_caller_id_number = $row['outbound_caller_id_number'];
|
||||||
|
}
|
||||||
|
$array['extensions'][$x]['extension_uuid'] = $row['extension_uuid'];
|
||||||
|
$array['extensions'][$x]['outbound_caller_id_name'] = $outbound_caller_id_name;
|
||||||
|
if (is_numeric($outbound_caller_id_number)) {
|
||||||
|
$array['extensions'][$x]['outbound_caller_id_number'] = $outbound_caller_id_number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//increment the row id
|
||||||
|
$x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//add the dialplan permission
|
||||||
|
$p = new permissions;
|
||||||
|
$p->add("extension_edit", "temp");
|
||||||
|
|
||||||
|
//save to the data
|
||||||
|
$database = new database;
|
||||||
|
$database->app_name = 'extensions';
|
||||||
|
$database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
|
||||||
|
$database->save($array);
|
||||||
|
$message = $database->message;
|
||||||
|
|
||||||
|
//update the session array
|
||||||
|
foreach ($array['extensions'] as $row) {
|
||||||
|
$x=0;
|
||||||
|
foreach ($_SESSION['user']['extension'] as $field) {
|
||||||
|
if ($field['extension_uuid'] == $row['extension_uuid']) {
|
||||||
|
$_SESSION['user']['extension'][$x]['outbound_caller_id_name'] = $row['outbound_caller_id_name'];
|
||||||
|
$_SESSION['user']['extension'][$x]['outbound_caller_id_number'] = $row['outbound_caller_id_number'];
|
||||||
|
}
|
||||||
|
$x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//build the array on what is allowed.
|
//remove the temporary permission
|
||||||
if ($found) {
|
$p->delete("extension_edit", "temp");
|
||||||
if (permission_exists('outbound_caller_id_select')) {
|
|
||||||
$caller_id = explode('@', $row['outbound_caller_id']);
|
//clear the cache
|
||||||
$outbound_caller_id_name = $caller_id[0];
|
$cache = new cache;
|
||||||
$outbound_caller_id_number = $caller_id[1];
|
foreach($_SESSION['user']['extension'] as $field) {
|
||||||
|
$cache->delete("directory:".$field['destination']."@".$field['user_context']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the message
|
||||||
|
message::add($text['message-update']);
|
||||||
|
|
||||||
|
//redirect the browser
|
||||||
|
header("Location: /core/dashboard/");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//set the sub array index
|
||||||
|
$x = "999";
|
||||||
|
|
||||||
|
//get the extensions
|
||||||
|
$extensions = $_SESSION['user']['extension'];
|
||||||
|
|
||||||
|
//get the destinations
|
||||||
|
$sql = "select destination_caller_id_name, destination_caller_id_number from v_destinations ";
|
||||||
|
$sql .= "where domain_uuid = :domain_uuid ";
|
||||||
|
$sql .= "and destination_type = 'inbound' ";
|
||||||
|
$sql .= "order by destination_caller_id_name asc, destination_caller_id_number asc";
|
||||||
|
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
||||||
|
$database = new database;
|
||||||
|
$destinations = $database->select($sql, $parameters, 'all');
|
||||||
|
unset($sql, $parameters);
|
||||||
|
|
||||||
|
//create token
|
||||||
|
$object = new token;
|
||||||
|
$token = $object->create($_SERVER["DOCUMENT_ROOT"].'/extensions/resources/dashboard/caller_id.php');
|
||||||
|
|
||||||
|
//show the content
|
||||||
|
echo "<div class='action_bar sub'>\n";
|
||||||
|
echo " <div class='heading'><b>".$text['label-caller_id_number']."</b></div>\n";
|
||||||
|
echo " <div class='actions'>\n";
|
||||||
|
echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'collapse'=>false,'onclick'=>"list_form_submit('form_list_extension_caller_id');"]);
|
||||||
|
echo " </div>\n";
|
||||||
|
echo " <div style='clear: both;'></div>\n";
|
||||||
|
echo "</div>\n";
|
||||||
|
|
||||||
|
echo "<form id='form_list_extension_caller_id' method='post' action='/app/extensions/resources/dashboard/caller_id.php'>\n";
|
||||||
|
|
||||||
|
echo "<table class='list'>\n";
|
||||||
|
echo "<tr class='list-header'>\n";
|
||||||
|
echo " <th>".$text['label-extension']."</th>\n";
|
||||||
|
echo " <th>".$text['label-caller_id']."</th>\n";
|
||||||
|
if (!permission_exists('outbound_caller_id_select')) {
|
||||||
|
echo " <th>".$text['label-destination']."</th>\n";
|
||||||
|
}
|
||||||
|
echo " <th class='hide-sm-dn pct-30'>".$text['label-description']."</th>\n";
|
||||||
|
echo "</tr>\n";
|
||||||
|
|
||||||
|
if (is_array($extensions) && @sizeof($extensions) != 0) {
|
||||||
|
$x = 0;
|
||||||
|
foreach ($extensions as $row) {
|
||||||
|
//determine whether to hide the element
|
||||||
|
if (is_uuid($device_key_uuid)) {
|
||||||
|
$element['hidden'] = false;
|
||||||
|
$element['visibility'] = "visibility:visible;";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$outbound_caller_id_name = $row['outbound_caller_id_name'];
|
$element['hidden'] = true;
|
||||||
$outbound_caller_id_number = $row['outbound_caller_id_number'];
|
$element['visibility'] = "visibility:hidden;";
|
||||||
}
|
}
|
||||||
$array['extensions'][$x]['extension_uuid'] = $row['extension_uuid'];
|
|
||||||
$array['extensions'][$x]['outbound_caller_id_name'] = $outbound_caller_id_name;
|
echo "<tr class='list-row'>\n";
|
||||||
if (is_numeric($outbound_caller_id_number)) {
|
echo " <td>\n";
|
||||||
$array['extensions'][$x]['outbound_caller_id_number'] = $outbound_caller_id_number;
|
echo " ".$row['destination'];
|
||||||
|
if (is_uuid($row['extension_uuid'])) {
|
||||||
|
echo " <input name='extensions[".$x."][extension_uuid]' type='hidden' value=\"".escape($row['extension_uuid'])."\">\n";
|
||||||
|
}
|
||||||
|
echo " </td>\n";
|
||||||
|
if (permission_exists('outbound_caller_id_select')) {
|
||||||
|
//caller id select
|
||||||
|
echo " <td class='input'>\n";
|
||||||
|
if (count($destinations) > 0) {
|
||||||
|
echo " <select name='extensions[".$x."][outbound_caller_id]' id='outbound_caller_id_number' class='formfld'>\n";
|
||||||
|
echo " <option value=''></option>\n";
|
||||||
|
foreach ($destinations as &$field) {
|
||||||
|
if(strlen($field['destination_caller_id_number']) > 0) {
|
||||||
|
if ($row['outbound_caller_id_number'] == $field['destination_caller_id_number']) {
|
||||||
|
echo " <option value='".escape($field['destination_caller_id_name'])."@".escape($field['destination_caller_id_number'])."' selected='selected'>".escape($field['destination_caller_id_name'])." ".escape($field['destination_caller_id_number'])."</option>\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo " <option value='".escape($field['destination_caller_id_name'])."@".escape($field['destination_caller_id_number'])."'>".escape($field['destination_caller_id_name'])." ".escape($field['destination_caller_id_number'])."</option>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo " </select>\n";
|
||||||
}
|
}
|
||||||
|
echo " </td>\n";
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
//increment the row id
|
//caller id name and number inputs
|
||||||
$x++;
|
echo " <td class='input'>\n";
|
||||||
}
|
echo " <input class='formfld' style='min-width: 50px; max-width: 100px;' type='text' name='extensions[".$x."][outbound_caller_id_name]' maxlength='255' value=\"".escape($row['outbound_caller_id_name'])."\">\n";
|
||||||
|
echo " </td>\n";
|
||||||
//add the dialplan permission
|
echo " <td class='input'>\n";
|
||||||
$p = new permissions;
|
echo " <input class='formfld' style='min-width: 50px; max-width: 100px;' type='text' name='extensions[".$x."][outbound_caller_id_number]' maxlength='255' value=\"".$row['outbound_caller_id_number']."\">\n";
|
||||||
$p->add("extension_edit", "temp");
|
echo " </td>\n";
|
||||||
|
|
||||||
//save to the data
|
|
||||||
$database = new database;
|
|
||||||
$database->app_name = 'extensions';
|
|
||||||
$database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
|
|
||||||
$database->save($array);
|
|
||||||
$message = $database->message;
|
|
||||||
|
|
||||||
//update the session array
|
|
||||||
foreach ($array['extensions'] as $row) {
|
|
||||||
$x=0;
|
|
||||||
foreach ($_SESSION['user']['extension'] as $field) {
|
|
||||||
if ($field['extension_uuid'] == $row['extension_uuid']) {
|
|
||||||
$_SESSION['user']['extension'][$x]['outbound_caller_id_name'] = $row['outbound_caller_id_name'];
|
|
||||||
$_SESSION['user']['extension'][$x]['outbound_caller_id_number'] = $row['outbound_caller_id_number'];
|
|
||||||
}
|
}
|
||||||
|
echo " <td class='description overflow hide-sm-dn'>\n";
|
||||||
|
echo " ".$row['description'];
|
||||||
|
echo " </td>\n";
|
||||||
|
echo "</tr>\n";
|
||||||
$x++;
|
$x++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unset($extensions);
|
||||||
|
|
||||||
//remove the temporary permission
|
echo "</table>\n";
|
||||||
$p->delete("extension_edit", "temp");
|
echo "<br />\n";
|
||||||
|
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
|
||||||
//clear the cache
|
echo "</form>\n";
|
||||||
$cache = new cache;
|
|
||||||
foreach($_SESSION['user']['extension'] as $field) {
|
|
||||||
$cache->delete("directory:".$field['destination']."@".$field['user_context']);
|
|
||||||
}
|
|
||||||
|
|
||||||
//set the message
|
|
||||||
message::add($text['message-update']);
|
|
||||||
|
|
||||||
//redirect the browser
|
|
||||||
header("Location: /core/user_settings/user_dashboard.php");
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//set the sub array index
|
|
||||||
$x = "999";
|
|
||||||
|
|
||||||
//get the extensions
|
|
||||||
$extensions = $_SESSION['user']['extension'];
|
|
||||||
|
|
||||||
//get the destinations
|
|
||||||
$sql = "select destination_caller_id_name, destination_caller_id_number from v_destinations ";
|
|
||||||
$sql .= "where domain_uuid = :domain_uuid ";
|
|
||||||
$sql .= "and destination_type = 'inbound' ";
|
|
||||||
$sql .= "order by destination_caller_id_name asc, destination_caller_id_number asc";
|
|
||||||
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
|
||||||
$database = new database;
|
|
||||||
$destinations = $database->select($sql, $parameters, 'all');
|
|
||||||
unset($sql, $parameters);
|
|
||||||
|
|
||||||
//create token
|
|
||||||
$object = new token;
|
|
||||||
$token = $object->create('/app/extensions/extension_dashboard.php');
|
|
||||||
|
|
||||||
//show the content
|
|
||||||
echo "<div class='action_bar sub'>\n";
|
|
||||||
echo " <div class='heading'><b>".$text['label-caller_id_number']."</b></div>\n";
|
|
||||||
echo " <div class='actions'>\n";
|
|
||||||
echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'collapse'=>false,'onclick'=>"list_form_submit('form_list_extension_caller_id');"]);
|
|
||||||
echo " </div>\n";
|
|
||||||
echo " <div style='clear: both;'></div>\n";
|
|
||||||
echo "</div>\n";
|
|
||||||
|
|
||||||
echo "<form id='form_list_extension_caller_id' method='post' action='".PROJECT_PATH."/app/extensions/extension_dashboard.php'>\n";
|
|
||||||
|
|
||||||
echo "<table class='list'>\n";
|
|
||||||
echo "<tr class='list-header'>\n";
|
|
||||||
echo " <th>".$text['label-extension']."</th>\n";
|
|
||||||
echo " <th>".$text['label-caller_id']."</th>\n";
|
|
||||||
if (!permission_exists('outbound_caller_id_select')) {
|
|
||||||
echo " <th>".$text['label-destination']."</th>\n";
|
|
||||||
}
|
|
||||||
echo " <th class='hide-sm-dn pct-30'>".$text['label-description']."</th>\n";
|
|
||||||
echo "</tr>\n";
|
|
||||||
|
|
||||||
if (is_array($extensions) && @sizeof($extensions) != 0) {
|
|
||||||
$x = 0;
|
|
||||||
foreach ($extensions as $row) {
|
|
||||||
//determine whether to hide the element
|
|
||||||
if (is_uuid($device_key_uuid)) {
|
|
||||||
$element['hidden'] = false;
|
|
||||||
$element['visibility'] = "visibility:visible;";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$element['hidden'] = true;
|
|
||||||
$element['visibility'] = "visibility:hidden;";
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "<tr class='list-row'>\n";
|
|
||||||
echo " <td>\n";
|
|
||||||
echo " ".$row['destination'];
|
|
||||||
if (is_uuid($row['extension_uuid'])) {
|
|
||||||
echo " <input name='extensions[".$x."][extension_uuid]' type='hidden' value=\"".escape($row['extension_uuid'])."\">\n";
|
|
||||||
}
|
|
||||||
echo " </td>\n";
|
|
||||||
if (permission_exists('outbound_caller_id_select')) {
|
|
||||||
//caller id select
|
|
||||||
echo " <td class='input'>\n";
|
|
||||||
if (count($destinations) > 0) {
|
|
||||||
echo " <select name='extensions[".$x."][outbound_caller_id]' id='outbound_caller_id_number' class='formfld'>\n";
|
|
||||||
echo " <option value=''></option>\n";
|
|
||||||
foreach ($destinations as &$field) {
|
|
||||||
if(strlen($field['destination_caller_id_number']) > 0) {
|
|
||||||
if ($row['outbound_caller_id_number'] == $field['destination_caller_id_number']) {
|
|
||||||
echo " <option value='".escape($field['destination_caller_id_name'])."@".escape($field['destination_caller_id_number'])."' selected='selected'>".escape($field['destination_caller_id_name'])." ".escape($field['destination_caller_id_number'])."</option>\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
echo " <option value='".escape($field['destination_caller_id_name'])."@".escape($field['destination_caller_id_number'])."'>".escape($field['destination_caller_id_name'])." ".escape($field['destination_caller_id_number'])."</option>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
echo " </select>\n";
|
|
||||||
}
|
|
||||||
echo " </td>\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//caller id name and number inputs
|
|
||||||
echo " <td class='input'>\n";
|
|
||||||
echo " <input class='formfld' style='min-width: 50px; max-width: 100px;' type='text' name='extensions[".$x."][outbound_caller_id_name]' maxlength='255' value=\"".escape($row['outbound_caller_id_name'])."\">\n";
|
|
||||||
echo " </td>\n";
|
|
||||||
echo " <td class='input'>\n";
|
|
||||||
echo " <input class='formfld' style='min-width: 50px; max-width: 100px;' type='text' name='extensions[".$x."][outbound_caller_id_number]' maxlength='255' value=\"".$row['outbound_caller_id_number']."\">\n";
|
|
||||||
echo " </td>\n";
|
|
||||||
}
|
|
||||||
echo " <td class='description overflow hide-sm-dn'>\n";
|
|
||||||
echo " ".$row['description'];
|
|
||||||
echo " </td>\n";
|
|
||||||
echo "</tr>\n";
|
|
||||||
$x++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($extensions);
|
|
||||||
|
|
||||||
echo "</table>\n";
|
|
||||||
echo "<br />\n";
|
|
||||||
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
|
|
||||||
echo "</form>\n";
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user