Dashboard - Caller ID: Rework style to match other widgets.

This commit is contained in:
fusionate
2023-02-20 19:49:32 +00:00
parent e91f78bafe
commit 2c76741976
3 changed files with 224 additions and 73 deletions

View File

@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2017 - 2022
Portions created by the Initial Developer are Copyright (C) 2017-2023
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -89,6 +89,9 @@
$x++;
}
//create temp array for session update
$array_temp = $array;
//add the dialplan permission
$p = new permissions;
$p->add("extension_edit", "temp");
@@ -100,16 +103,19 @@
$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'];
if ($message['message'] == 'OK' && $message['code'] == '200') {
foreach ($array_temp['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++;
}
$x++;
}
}
unset($array_temp);
//remove the temporary permission
$p->delete("extension_edit", "temp");
@@ -128,108 +134,175 @@
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'];
$destinations = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
if (permission_exists('outbound_caller_id_select')) {
$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'];
$destinations = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
}
//determine stats
if (is_array($extensions) && @sizeof($extensions) != 0) {
foreach ($extensions as $row) {
if (is_numeric($row['outbound_caller_id_number'])) {
$stats['defined']++;
}
else {
$stats['undefined']++;
}
}
}
//set defaults
if ($stats['defined'] == null) { $stats['defined'] = 0; }
if ($stats['undefined'] == null) { $stats['undefined'] = 0; }
//set the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//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";
//caller id
echo "<div class='hud_box'>\n";
//doughnut chart
echo "<div style='display: flex; flex-wrap: wrap; justify-content: center; padding-bottom: 20px;' onclick=\"$('#hud_caller_id_details').slideToggle('fast');\">\n";
echo " <div style='width: 275px; height: 175px;'><canvas id='caller_id_chart'></canvas></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 "<script>\n";
echo " const caller_id_chart = new Chart(\n";
echo " document.getElementById('caller_id_chart').getContext('2d'),\n";
echo " {\n";
echo " type: 'doughnut',\n";
echo " data: {\n";
echo " labels: [\n";
echo " '".$text['label-defined'].": ".$stats['defined']."',\n";
echo " '".$text['label-undefined'].": ".$stats['undefined']."',\n";
echo " ],\n";
echo " datasets: [{\n";
echo " data: [\n";
echo " '".$stats['defined']."',\n";
echo " '".$stats['undefined']."',\n";
echo " 0.00001,\n";
echo " ],\n";
echo " backgroundColor: [\n";
echo " '".$_SESSION['dashboard']['caller_id_chart_color_defined']['text']."',\n";
echo " '".$_SESSION['dashboard']['caller_id_chart_color_undefined']['text']."',\n";
echo " ],\n";
echo " borderColor: '".$_SESSION['dashboard']['caller_id_chart_border_color']['text']."',\n";
echo " borderWidth: '".$_SESSION['dashboard']['caller_id_chart_border_width']['text']."',\n";
echo " cutout: chart_cutout,\n";
echo " }]\n";
echo " },\n";
echo " options: {\n";
echo " responsive: true,\n";
echo " maintainAspectRatio: false,\n";
echo " plugins: {\n";
echo " chart_counter: {\n";
echo " chart_text: '".$stats['undefined']."'\n";
echo " },\n";
echo " legend: {\n";
echo " position: 'right',\n";
echo " reverse: true,\n";
echo " labels: {\n";
echo " usePointStyle: true,\n";
echo " pointStyle: 'rect'\n";
echo " }\n";
echo " },\n";
echo " title: {\n";
echo " display: true,\n";
echo " text: '".$text['label-caller_id_number']."'\n";
echo " }\n";
echo " }\n";
echo " },\n";
echo " plugins: [chart_counter],\n";
echo " }\n";
echo " );\n";
echo "</script>\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";
//details
echo "<form id='form_list_caller_id' method='post' action='".PROJECT_PATH."/app/extensions/resources/dashboard/caller_id.php'>\n";
echo "<div class='hud_details hud_box' id='hud_caller_id_details' style='text-align: right;'>";
if (is_array($extensions) && @sizeof($extensions) != 0) {
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'collapse'=>false,'style'=>"position: absolute; margin-top: -35px; margin-left: -72px;"]);
}
echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
echo "<tr style='position: -webkit-sticky; position: sticky; z-index: 5; top: 0;'>\n";
echo "<th class='hud_heading'>".$text['label-extension']."</th>\n";
echo "<th class='hud_heading'>".$text['label-caller_id']."</th>\n";
if (!permission_exists('outbound_caller_id_select')) {
echo "<th class='hud_heading'>".$text['label-destination']."</th>\n";
}
echo " <th class='hide-sm-dn pct-30'>".$text['label-description']."</th>\n";
echo "</tr>\n";
//data
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'];
$tr_link = PROJECT_PATH."/app/extensions/extension_edit.php?id=".$row['extension_uuid'];
echo "<tr href='".$tr_link."'>\n";
echo " <td valign='top' class='".$row_style[$c]." hud_text'>";
echo "<a href='".$tr_link."' title=\"".$text['button-edit']."\">".escape($row['destination'])."</a>";
if (is_uuid($row['extension_uuid'])) {
echo " <input name='extensions[".$x."][extension_uuid]' type='hidden' value=\"".escape($row['extension_uuid'])."\">\n";
echo "<input type='hidden' name='extensions[".$x."][extension_uuid]' value=\"".escape($row['extension_uuid'])."\">\n";
}
echo " </td>\n";
//select caller id
if (permission_exists('outbound_caller_id_select')) {
//caller id select
echo " <td class='input'>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text input tr_link_void'>";
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";
echo "<select class='formfld' name='extensions[".$x."][outbound_caller_id]' id='outbound_caller_id_number_".$x."' style='width: 100%; min-width: 150px;'>\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";
}
if (strlen($field['destination_caller_id_number']) > 0) {
echo "<option value='".escape($field['destination_caller_id_name'])."@".escape($field['destination_caller_id_number'])."' ".($row['outbound_caller_id_number'] == $field['destination_caller_id_number'] ? "selected='selected'" : null).">".escape($field['destination_caller_id_name'])." ".escape($field['destination_caller_id_number'])."</option>\n";
}
}
echo " </select>\n";
echo "</select>\n";
}
echo " </td>\n";
echo "</td>\n";
}
//input caller id
else {
//caller id name and number inputs
echo " <td class='input'>\n";
echo " <input class='formfld' style='width: 70%;' 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='width: 70%;' type='text' name='extensions[".$x."][outbound_caller_id_number]' maxlength='255' value=\"".$row['outbound_caller_id_number']."\">\n";
echo " </td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text input tr_link_void'>";
echo " <input class='formfld' style='width: 100%; min-width: 80px;' type='text' name='extensions[".$x."][outbound_caller_id_name]' maxlength='255' value=\"".escape($row['outbound_caller_id_name'])."\">\n";
echo "</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text input tr_link_void'>";
echo " <input class='formfld' style='width: 100%; min-width: 80px;' 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++;
$c = ($c) ? 0 : 1;
}
unset($extensions);
}
unset($extensions);
echo "</table>\n";
echo "<br />\n";
echo "</div>";
$n++;
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
echo "<span class='hud_expander' onclick=\"$('#hud_caller_id_details').slideToggle('fast');\"><span class='fas fa-ellipsis-h'></span></span>";
echo "</div>\n";
}
?>
?>