2021-11-10 02:42:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
2022-10-11 00:35:14 +02:00
|
|
|
//includes files
|
2023-06-15 19:28:23 +02:00
|
|
|
require_once dirname(__DIR__, 4) . "/resources/require.php";
|
2023-02-23 15:50:16 +01:00
|
|
|
require_once "resources/check_auth.php";
|
2021-11-10 02:42:14 +01:00
|
|
|
|
|
|
|
|
//check permisions
|
|
|
|
|
if (permission_exists('xml_cdr_view')) {
|
|
|
|
|
//access granted
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add multi-lingual support
|
|
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get($_SESSION['domain']['language']['code'], 'core/user_settings');
|
|
|
|
|
|
2022-09-12 16:59:28 +02:00
|
|
|
//create assigned extensions array
|
|
|
|
|
if (is_array($_SESSION['user']['extension'])) {
|
|
|
|
|
foreach ($_SESSION['user']['extension'] as $assigned_extension) {
|
|
|
|
|
$assigned_extensions[$assigned_extension['extension_uuid']] = $assigned_extension['user'];
|
|
|
|
|
}
|
2021-11-10 07:23:18 +01:00
|
|
|
}
|
2023-02-23 15:50:16 +01:00
|
|
|
unset($assigned_extension);
|
2021-11-10 07:23:18 +01:00
|
|
|
|
2022-09-12 16:59:28 +02:00
|
|
|
//if also viewing system status, show more recent calls (more room avaialble)
|
2023-05-11 00:32:44 +02:00
|
|
|
$recent_limit = isset($selected_blocks) && is_array($selected_blocks) && in_array('counts', $selected_blocks) ? 10 : 5;
|
2021-11-10 07:23:18 +01:00
|
|
|
|
2024-02-20 22:48:24 +01:00
|
|
|
//set the sql time format
|
|
|
|
|
$sql_time_format = 'DD Mon HH12:MI am';
|
|
|
|
|
if (!empty($_SESSION['domain']['time_format']['text'])) {
|
|
|
|
|
$sql_time_format = $_SESSION['domain']['time_format']['text'] == '12h' ? "DD Mon HH12:MI am" : "DD Mon HH24:MI";
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-12 16:59:28 +02:00
|
|
|
//get the recent calls from call detail records
|
2021-11-10 07:23:18 +01:00
|
|
|
$sql = "
|
|
|
|
|
select
|
2024-02-20 22:48:24 +01:00
|
|
|
status,
|
2021-11-10 07:23:18 +01:00
|
|
|
direction,
|
|
|
|
|
start_stamp,
|
2024-02-20 22:48:24 +01:00
|
|
|
to_char(timezone(:time_zone, start_stamp), '".$sql_time_format."') as start_date_time,
|
2021-11-10 07:23:18 +01:00
|
|
|
caller_id_name,
|
|
|
|
|
caller_id_number,
|
|
|
|
|
destination_number,
|
|
|
|
|
answer_stamp,
|
|
|
|
|
bridge_uuid,
|
|
|
|
|
sip_hangup_disposition
|
|
|
|
|
from
|
|
|
|
|
v_xml_cdr
|
|
|
|
|
where
|
|
|
|
|
domain_uuid = :domain_uuid ";
|
2023-10-13 22:25:02 +02:00
|
|
|
if (!permission_exists('xml_cdr_domain')) {
|
|
|
|
|
if (!empty($assigned_extensions)) {
|
|
|
|
|
$x = 0;
|
|
|
|
|
foreach ($assigned_extensions as $assigned_extension_uuid => $assigned_extension) {
|
|
|
|
|
$sql_where_array[] = "extension_uuid = :extension_uuid_".$x;
|
|
|
|
|
$parameters['extension_uuid_'.$x] = $assigned_extension_uuid;
|
|
|
|
|
$x++;
|
|
|
|
|
}
|
|
|
|
|
if (!empty($sql_where_array)) {
|
|
|
|
|
$sql .= "and (".implode(' or ', $sql_where_array).") ";
|
|
|
|
|
}
|
|
|
|
|
unset($sql_where_array);
|
2021-11-10 02:42:14 +01:00
|
|
|
}
|
2023-10-13 22:25:02 +02:00
|
|
|
else {
|
|
|
|
|
$sql .= "and false \n";
|
2021-11-10 07:23:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-04-22 20:16:30 +02:00
|
|
|
$sql .= "and hangup_cause <> 'LOSE_RACE' ";
|
2024-02-20 22:48:24 +01:00
|
|
|
$sql .= "and start_epoch > ".(time() - 86400)." ";
|
|
|
|
|
$sql .= "order by start_epoch desc ";
|
|
|
|
|
$sql .= "limit :recent_limit ";
|
|
|
|
|
$parameters['recent_limit'] = $recent_limit;
|
2023-08-01 22:33:39 +02:00
|
|
|
$parameters['time_zone'] = isset($_SESSION['domain']['time_zone']['name']) ? $_SESSION['domain']['time_zone']['name'] : date_default_timezone_get();
|
2021-11-10 07:23:18 +01:00
|
|
|
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
2022-11-08 17:40:12 +01:00
|
|
|
if (!isset($database)) { $database = new database; }
|
2021-11-10 07:23:18 +01:00
|
|
|
$result = $database->select($sql, $parameters, 'all');
|
2023-05-11 06:22:21 +02:00
|
|
|
$num_rows = !empty($result) ? sizeof($result) : 0;
|
2021-11-10 07:23:18 +01:00
|
|
|
|
2022-09-12 16:59:28 +02:00
|
|
|
//define row styles
|
2021-11-10 07:23:18 +01:00
|
|
|
$c = 0;
|
|
|
|
|
$row_style["0"] = "row_style0";
|
|
|
|
|
$row_style["1"] = "row_style1";
|
|
|
|
|
|
2022-09-12 16:59:28 +02:00
|
|
|
//recent calls
|
|
|
|
|
echo "<div class='hud_box'>\n";
|
|
|
|
|
|
2024-05-08 17:54:18 +02:00
|
|
|
echo "<div class='hud_container' ".($dashboard_details_state == "disabled" ?: "onclick=\"$('#hud_recent_calls_details').slideToggle('fast'); toggle_grid_row_end('".$dashboard_name."')\"").">\n";
|
|
|
|
|
echo " <span class='hud_title' onclick=\"document.location.href='".PROJECT_PATH."/app/xml_cdr/xml_cdr.php';\">".$text['label-recent_calls']."</span>\n";
|
2021-11-10 07:23:18 +01:00
|
|
|
|
2024-04-19 00:57:45 +02:00
|
|
|
if ($dashboard_chart_type == "doughnut") {
|
|
|
|
|
//add doughnut chart
|
|
|
|
|
?>
|
2024-04-24 22:14:24 +02:00
|
|
|
|
2024-05-08 17:54:18 +02:00
|
|
|
<div class='hud_chart'><canvas id='recent_calls_chart'></canvas></div>
|
2024-04-24 22:14:24 +02:00
|
|
|
|
2024-04-19 00:57:45 +02:00
|
|
|
<script>
|
|
|
|
|
const recent_calls_chart = new Chart(
|
|
|
|
|
document.getElementById('recent_calls_chart').getContext('2d'),
|
|
|
|
|
{
|
|
|
|
|
type: 'doughnut',
|
|
|
|
|
data: {
|
|
|
|
|
datasets: [{
|
|
|
|
|
data: ['<?php echo $num_rows; ?>', 0.00001],
|
|
|
|
|
backgroundColor: [
|
|
|
|
|
'<?php echo $_SESSION['dashboard']['recent_calls_chart_main_background_color']['text']; ?>',
|
|
|
|
|
'<?php echo $_SESSION['dashboard']['recent_calls_chart_sub_background_color']['text']; ?>'
|
|
|
|
|
],
|
|
|
|
|
borderColor: '<?php echo $_SESSION['dashboard']['recent_calls_chart_border_color']['text']; ?>',
|
|
|
|
|
borderWidth: '<?php echo $_SESSION['dashboard']['recent_calls_chart_border_width']['text']; ?>'
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
plugins: {
|
|
|
|
|
chart_number: {
|
|
|
|
|
text: '<?php echo $num_rows; ?>'
|
|
|
|
|
}
|
2023-01-06 21:18:53 +01:00
|
|
|
}
|
2024-04-19 00:57:45 +02:00
|
|
|
},
|
|
|
|
|
plugins: [{
|
|
|
|
|
id: 'chart_number',
|
|
|
|
|
beforeDraw(chart, args, options){
|
|
|
|
|
const {ctx, chartArea: {top, right, bottom, left, width, height} } = chart;
|
2024-04-24 22:14:24 +02:00
|
|
|
ctx.font = chart_text_size + ' ' + chart_text_font;
|
2024-04-19 00:57:45 +02:00
|
|
|
ctx.textBaseline = 'middle';
|
|
|
|
|
ctx.textAlign = 'center';
|
|
|
|
|
ctx.fillStyle = '<?php echo $dashboard_number_text_color; ?>';
|
|
|
|
|
ctx.fillText(options.text, width / 2, top + (height / 2));
|
|
|
|
|
ctx.save();
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
</script>
|
|
|
|
|
<?php
|
|
|
|
|
}
|
|
|
|
|
if ($dashboard_chart_type == "none") {
|
2024-05-08 17:54:18 +02:00
|
|
|
echo "<span class='hud_stat'>".$num_rows."</span>";
|
2024-04-19 00:57:45 +02:00
|
|
|
}
|
2024-04-24 22:14:24 +02:00
|
|
|
echo "</div>\n";
|
2021-11-10 07:23:18 +01:00
|
|
|
|
2024-05-08 17:54:18 +02:00
|
|
|
if ($dashboard_details_state != 'disabled') {
|
|
|
|
|
echo "<div class='hud_details hud_box' id='hud_recent_calls_details'>";
|
|
|
|
|
echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
if ($num_rows > 0) {
|
|
|
|
|
echo "<th class='hud_heading'> </th>\n";
|
|
|
|
|
}
|
|
|
|
|
echo "<th class='hud_heading' width='100%'>".$text['label-cid_number']."</th>\n";
|
|
|
|
|
echo "<th class='hud_heading'>".$text['label-date_time']."</th>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
if ($num_rows > 0) {
|
|
|
|
|
$theme_cdr_images_exist = (
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_inbound_answered.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_inbound_voicemail.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_inbound_cancelled.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_inbound_failed.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_outbound_answered.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_outbound_cancelled.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_outbound_failed.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_local_answered.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_local_voicemail.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_local_cancelled.png") &&
|
|
|
|
|
file_exists($theme_image_path."icon_cdr_local_failed.png")
|
|
|
|
|
) ? true : false;
|
|
|
|
|
|
|
|
|
|
foreach ($result as $index => $row) {
|
|
|
|
|
$start_date_time = str_replace('/0','/', ltrim($row['start_date_time'], '0'));
|
|
|
|
|
if (!empty($_SESSION['domain']['time_format']) && $_SESSION['domain']['time_format']['text'] == '12h') {
|
|
|
|
|
$start_date_time = str_replace(' 0',' ', $start_date_time);
|
|
|
|
|
}
|
2024-05-02 15:32:53 +02:00
|
|
|
|
2024-05-08 17:54:18 +02:00
|
|
|
//determine name
|
|
|
|
|
$cdr_name = ($row['direction'] == 'inbound' || ($row['direction'] == 'local' && !empty($assigned_extensions) && is_array($assigned_extensions) && in_array($row['destination_number'], $assigned_extensions))) ? $row['caller_id_name'] : $row['destination_number'];
|
|
|
|
|
//determine number to display
|
|
|
|
|
if ($row['direction'] == 'inbound' || ($row['direction'] == 'local' && !empty($assigned_extensions) && is_array($assigned_extensions) && in_array($row['destination_number'], $assigned_extensions))) {
|
|
|
|
|
$cdr_number = (is_numeric($row['caller_id_number'])) ? format_phone($row['caller_id_number']) : $row['caller_id_number'];
|
|
|
|
|
$dest = $row['caller_id_number'];
|
|
|
|
|
}
|
|
|
|
|
else if ($row['direction'] == 'outbound' || ($row['direction'] == 'local' && !empty($assigned_extensions) && is_array($assigned_extensions) && in_array($row['caller_id_number'], $assigned_extensions))) {
|
|
|
|
|
$cdr_number = (is_numeric($row['destination_number'])) ? format_phone($row['destination_number']) : $row['destination_number'];
|
|
|
|
|
$dest = $row['destination_number'];
|
|
|
|
|
}
|
|
|
|
|
//set click-to-call variables
|
|
|
|
|
if (permission_exists('click_to_call_call')) {
|
|
|
|
|
$tr_link = "onclick=\"send_cmd('".PROJECT_PATH."/app/click_to_call/click_to_call.php".
|
|
|
|
|
"?src_cid_name=".urlencode($cdr_name ?? '').
|
|
|
|
|
"&src_cid_number=".urlencode($cdr_number ?? '').
|
|
|
|
|
"&dest_cid_name=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_name'] ?? '').
|
|
|
|
|
"&dest_cid_number=".urlencode($_SESSION['user']['extension'][0]['outbound_caller_id_number'] ?? '').
|
|
|
|
|
"&src=".urlencode($_SESSION['user']['extension'][0]['user'] ?? '').
|
|
|
|
|
"&dest=".urlencode($dest ?? '').
|
|
|
|
|
"&rec=".(isset($_SESSION['click_to_call']['record']['boolean']) ? $_SESSION['click_to_call']['record']['boolean'] : "false").
|
|
|
|
|
"&ringback=".(isset($_SESSION['click_to_call']['ringback']['text']) ? $_SESSION['click_to_call']['ringback']['text'] : "us-ring").
|
|
|
|
|
"&auto_answer=".(isset($_SESSION['click_to_call']['auto_answer']['boolean']) ? $_SESSION['click_to_call']['auto_answer']['boolean'] : "true").
|
|
|
|
|
"');\" ".
|
|
|
|
|
"style='cursor: pointer;'";
|
|
|
|
|
}
|
|
|
|
|
echo "<tr ".$tr_link.">\n";
|
|
|
|
|
//determine call result and appropriate icon
|
|
|
|
|
echo "<td valign='middle' class='".$row_style[$c]."' style='cursor: help; padding: 0 0 0 6px;'>\n";
|
|
|
|
|
if ($theme_cdr_images_exist) {
|
|
|
|
|
$call_result = $row['status'];
|
|
|
|
|
if (isset($row['direction'])) {
|
|
|
|
|
echo "<img src='".PROJECT_PATH."/themes/".$_SESSION['domain']['template']['name']."/images/icon_cdr_".$row['direction']."_".$call_result.".png' width='16' style='border: none;' title='".$text['label-'.$row['direction']].": ".$text['label-'.$call_result]."'>\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td valign='top' class='".$row_style[$c]." hud_text' nowrap='nowrap'><a href='javascript:void(0);' ".(!empty($cdr_name) ? "title=\"".$cdr_name."\"" : null).">".($cdr_number ?? '')."</a></td>\n";
|
|
|
|
|
echo "<td valign='top' class='".$row_style[$c]." hud_text' nowrap='nowrap'>".$start_date_time."</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
2024-05-02 15:32:53 +02:00
|
|
|
|
2024-05-08 17:54:18 +02:00
|
|
|
unset($cdr_name, $cdr_number);
|
|
|
|
|
$c = ($c) ? 0 : 1;
|
2024-05-02 15:32:53 +02:00
|
|
|
}
|
2021-11-10 02:42:14 +01:00
|
|
|
}
|
2024-05-08 17:54:18 +02:00
|
|
|
unset($sql, $parameters, $result, $num_rows, $index, $row);
|
2021-11-10 07:23:18 +01:00
|
|
|
|
2024-05-08 17:54:18 +02:00
|
|
|
echo "</table>\n";
|
|
|
|
|
echo "<span style='display: block; margin: 6px 0 7px 0;'><a href='".PROJECT_PATH."/app/xml_cdr/xml_cdr.php'>".$text['label-view_all']."</a></span>\n";
|
|
|
|
|
echo "</div>";
|
2021-11-10 07:23:18 +01:00
|
|
|
|
2024-05-08 17:54:18 +02:00
|
|
|
echo "<span class='hud_expander' onclick=\"$('#hud_recent_calls_details').slideToggle('fast'); toggle_grid_row_end('".$dashboard_name."')\"><span class='fas fa-ellipsis-h'></span></span>";
|
|
|
|
|
}
|
2021-11-10 07:23:18 +01:00
|
|
|
echo "</div>\n";
|
2021-11-10 02:42:14 +01:00
|
|
|
|
2024-02-20 22:48:24 +01:00
|
|
|
?>
|