Add new class methods called call_flow and call_flow_summary

This commit is contained in:
FusionPBX
2023-10-17 16:21:17 -06:00
committed by GitHub
parent aee8664098
commit 7c98190bde
3 changed files with 301 additions and 307 deletions

View File

@@ -46,50 +46,45 @@
$uuid = $_REQUEST["id"];
}
//get the destination select list
$destination = new destinations;
$destination_array = $destination->get('dialplan');
//get the next ordinal id for the array
$id = count($destination_array);
//get the destinations from the database
$sql = "select * from v_destinations ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$destinations = $database->select($sql, $parameters, 'all');
if (!empty($destinations)) {
foreach($destinations as $row) {
$destination_array['destinations'][$id]['application'] = 'destinations';
$destination_array['destinations'][$id]['destination_uuid'] = $row["destination_uuid"];
$destination_array['destinations'][$id]['uuid'] = $row["destination_uuid"];
$destination_array['destinations'][$id]['dialplan_uuid'] = $row["dialplan_uuid"];
$destination_array['destinations'][$id]['destination_type'] = $row["destination_type"];
$destination_array['destinations'][$id]['destination_prefix'] = $row["destination_prefix"];
$destination_array['destinations'][$id]['destination_number'] = $row["destination_number"];
$destination_array['destinations'][$id]['extension'] = $row["destination_prefix"] . $row["destination_number"];
$destination_array['destinations'][$id]['destination_trunk_prefix'] = $row["destination_trunk_prefix"];
$destination_array['destinations'][$id]['destination_area_code'] = $row["destination_area_code"];
$destination_array['destinations'][$id]['context'] = $row["destination_context"];
$destination_array['destinations'][$id]['label'] = $row["destination_description"];
$destination_array['destinations'][$id]['destination_enabled'] = $row["destination_enabled"];
$destination_array['destinations'][$id]['name'] = $row["destination_description"];
$destination_array['destinations'][$id]['description'] = $row["destination_description"];
//$destination_array[$id]['destination_caller_id_name'] = $row["destination_caller_id_name"];
//$destination_array[$id]['destination_caller_id_number'] = $row["destination_caller_id_number"];
$id++;
}
}
unset($sql, $parameters, $row);
//add a function to return the find_app
function find_app($destination_array, $detail_action) {
//add the destinations to the destination array
$sql = "select * from v_destinations ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$destinations = $database->select($sql, $parameters, 'all');
if (!empty($destinations)) {
foreach($destinations as $row) {
$destination_array['destinations'][$id]['application'] = 'destinations';
$destination_array['destinations'][$id]['destination_uuid'] = $row["destination_uuid"];
$destination_array['destinations'][$id]['uuid'] = $row["destination_uuid"];
$destination_array['destinations'][$id]['dialplan_uuid'] = $row["dialplan_uuid"];
$destination_array['destinations'][$id]['destination_type'] = $row["destination_type"];
$destination_array['destinations'][$id]['destination_prefix'] = $row["destination_prefix"];
$destination_array['destinations'][$id]['destination_number'] = $row["destination_number"];
$destination_array['destinations'][$id]['extension'] = $row["destination_prefix"] . $row["destination_number"];
$destination_array['destinations'][$id]['destination_trunk_prefix'] = $row["destination_trunk_prefix"];
$destination_array['destinations'][$id]['destination_area_code'] = $row["destination_area_code"];
$destination_array['destinations'][$id]['context'] = $row["destination_context"];
$destination_array['destinations'][$id]['label'] = $row["destination_description"];
$destination_array['destinations'][$id]['destination_enabled'] = $row["destination_enabled"];
$destination_array['destinations'][$id]['name'] = $row["destination_description"];
$destination_array['destinations'][$id]['description'] = $row["destination_description"];
//$destination_array[$id]['destination_caller_id_name'] = $row["destination_caller_id_name"];
//$destination_array[$id]['destination_caller_id_number'] = $row["destination_caller_id_number"];
$id++;
}
}
unset($sql, $parameters, $row);
$result = '';
if (!empty($destination_array)) {
foreach($destination_array as $application => $row) {
if (!empty($row)) {
foreach ($row as $key => $value) {
//find matching destinations
if ($application == 'destinations') {
if ('+'.$value['destination_prefix'].$value['destination_number'] == $detail_action
or $value['destination_prefix'].$value['destination_number'] == $detail_action
@@ -104,6 +99,8 @@
}
}
}
//find all other matching actions
if ($value['extension'] == $detail_action) {
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$application."/app_languages.php")) {
$value['application'] = $application;
@@ -139,6 +136,7 @@
$start_stamp = trim($row["start_stamp"]);
$xml_string = trim($row["xml"] ?? '');
$json_string = trim($row["json"]);
$call_flow = trim($row["call_flow"]);
$direction = trim($row["direction"]);
$call_direction = trim($row["direction"]);
$status = trim($row["status"]);
@@ -213,199 +211,36 @@
$outbound_caller_id_name = urldecode($array["variables"]["outbound_caller_id_name"]);
$outbound_caller_id_number = urldecode($array["variables"]["outbound_caller_id_number"]);
//normalize the array
if (!isset($array["callflow"][0])) {
$tmp = $array["callflow"];
unset($array["callflow"]);
$array["callflow"][0] = $tmp;
}
//set the time zone
if (isset($_SESSION['domain']['time_zone']['name'])) {
date_default_timezone_set($_SESSION['domain']['time_zone']['name']);
}
//reverse the array to put events in chronological order
$array["callflow"] = array_reverse($array["callflow"]);
//add the profile end time to the call flow array
$i = 0;
foreach ($array["callflow"] as $row) {
//set the profile end time
if (isset($array["callflow"][$i+1]["times"]["profile_created_time"])) {
$array["callflow"][$i]["times"]["profile_end_time"] = $array["callflow"][$i+1]["times"]["profile_created_time"];
}
else {
$array["callflow"][$i]["times"]["profile_end_time"] = $end_epoch * 1000000;
}
$i++;
//build the call flow summary array
$xml_cdr = new xml_cdr;
$xml_cdr->call_direction = $call_direction;
if (empty($call_flow)) {
$xml_cdr->call_details = $array;
$call_flow_array = $xml_cdr->call_flow();
}
//format the times in the call flow array and add the profile duration
$i = 0;
foreach ($array["callflow"] as $row) {
foreach ($row["times"] as $name => $value) {
if ($value > 0) {
$array["callflow"][$i]["times"]["profile_duration_seconds"] = round(((int) $array["callflow"][$i]["times"]["profile_end_time"])/1000000 - ((int) $array["callflow"][$i]["times"]["profile_created_time"])/1000000);
$array["callflow"][$i]["times"]["profile_duration_formatted"] = gmdate("G:i:s", (int) $array["callflow"][$i]["times"]["profile_duration_seconds"]);
$array["callflow"][$i]["times"][$name.'stamp'] = date("Y-m-d H:i:s", (int) $value/1000000);
}
}
$i++;
else {
$call_flow_array = json_decode($call_flow, true);
}
$call_flow_summary = $xml_cdr->call_flow_summary($call_flow_array);
//debug information
if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == 'true') {
view_array($array["callflow"], false);
}
//count the callflow array
$callflow_count = 0;
if (!empty($array["callflow"])) {
$callflow_count = count($array["callflow"]);
}
//add the final call flow destination to the call flow array
//when call_direction is inbound
//when destination_number is not same as the last row
//when last destination is not voicemail *99ext
//count the array $i-1 finds the last record
//count the array $i is the next record
/*
if ($call_direction == 'inbound') {
//count the array
$i = $callflow_count;
//get the application array
if (!empty($array["callflow"][$i-1]["caller_profile"]["destination_number"])) {
$app = find_app($destination_array, $array["callflow"][$i-1]["caller_profile"]["destination_number"]);
}
//add last row to the array
if (!empty($array["callflow"])
&& $array["callflow"][$i-1]["destination_number"] != $destination_number
&& $app["application"] != 'conferences'
&& substr($array["callflow"][$i-1]["caller_profile"]["destination_number"], 0, 3) != '*99') {
$array["callflow"][$i]["caller_profile"]["destination_number"] = $destination_number;
$array["callflow"][$i]["caller_profile"]["network_addr"] = $network_address;
$array["callflow"][$i]["caller_profile"]["caller_id_name"] = $caller_id_name;
$array["callflow"][$i]["caller_profile"]["caller_id_number"] = $caller_id_number;
//$array["callflow"][$i]["times"]["profile_created_time"] = ($end_epoch - $duration) * 1000000;
$array["callflow"][$i]["times"]["end_stamp"] = $end_epoch * 1000000;
$array["callflow"][$i]["times"]["hangup_time"] = $end_epoch * 1000000;
$callflow_count++;
$i = 0;
foreach ($call_flow_array as $row) {
foreach ($row["times"] as $name => $value) {
if ($value > 0) {
$call_flow_array[$i]["times"][$name.'stamp'] = date("Y-m-d H:i:s", (int) $value/1000000);
}
}
$i++;
}
view_array($call_flow_array, false);
}
*/
//build the call summary array
$x = 0;
if (!empty($array["callflow"])) {
foreach ($array["callflow"] as $row) {
//get the application array
$app = find_app($destination_array, urldecode($row["caller_profile"]["destination_number"]));
//call centers
if ($app['application'] == 'call_centers') {
if (isset($row["caller_profile"]["transfer_source"])) {
$app['status'] = 'Answered'; //Out
}
else {
$app['status'] = 'Waited'; //In
}
}
//conferences
if ($app['application'] == 'conferences') {
$app['status'] = 'Answered';
}
//destinations
if ($app['application'] == 'destinations') {
$app['status'] = 'Routed';
}
//extensions
if ($app['application'] == 'extensions') {
if ($billsec == 0) {
$app['status'] = 'Missed';
}
else {
$app['status'] = 'Answered';
}
}
//outbound routes
if ($call_direction == 'outbound') {
$app['application'] = 'dialplans';
$app['uuid'] = '';
$app['status'] = '';
$app['name'] = 'Outbound';
$app['label'] = 'Outbound';
}
//ring groups
if ($app['application'] == 'ring_groups') {
$app['status'] = 'Waited';
}
//time conditions
if ($app['application'] == 'time_conditions') {
$app['status'] = 'Routed';
}
//valet park
if (substr($row["caller_profile"]["destination_number"], 0, 4) == 'park'
or (substr($row["caller_profile"]["destination_number"], 0, 3) == '*59'
&& strlen($row["caller_profile"]["destination_number"]) == 5)) {
$app['application'] = 'dialplans';
$app['uuid'] = '46ae6d82-bb83-46a3-901d-33d0724347dd';
$app['status'] = '---';
$app['name'] = 'Park';
$app['label'] = 'Park';
}
//voicemails
if ($app['application'] == 'voicemails') {
$app['status'] = 'Answered';
}
//build the application urls
$destination_url = "/app/".$app['application']."/".$destination->singular($app['application'])."_edit.php?id=".$app["uuid"];
$application_url = "/app/".$app['application']."/".$app['application'].".php";
if ($app['application'] == 'call_centers') {
$destination_url = "/app/".$app['application']."/".$destination->singular($app['application'])."_queue_edit.php?id=".$app['uuid'];
$application_url = "/app/".$app['application']."/".$destination->singular($app['application'])."_queues.php";
}
//add the application and destination details
$language2 = new text;
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$app['application']);
$call_flow_summary[$x]["application_name"] = $app['application'];
$call_flow_summary[$x]["application_label"] = trim($text2['title-'.$app['application']]);
$call_flow_summary[$x]["application_url"] = $application_url;
$call_flow_summary[$x]["destination_uuid"] = $app['uuid'];
$call_flow_summary[$x]["destination_name"] = $app['name'];
$call_flow_summary[$x]["destination_url"] = $destination_url;
$call_flow_summary[$x]["destination_number"] = $row["caller_profile"]["destination_number"];
$call_flow_summary[$x]["destination_label"] = $app['label'];
$call_flow_summary[$x]["destination_status"] = $app['status'];
$call_flow_summary[$x]["destination_description"] = $app['description'];
//$call_flow_summary[$x]["application"] = $app;
//add the call flow times
$call_flow_summary[$x]["start_epoch"] = round($row['times']['profile_created_time'] / 1000000);
$call_flow_summary[$x]["end_epoch"] = round($row['times']['profile_end_time'] / 1000000);
$call_flow_summary[$x]["start_stamp"] = $row['times']['profile_created_timestamp'];
$call_flow_summary[$x]["end_stamp"] = $row['times']['profile_end_timestamp'];
$call_flow_summary[$x]["duration_seconds"] = $row['times']['profile_duration_seconds'];
$call_flow_summary[$x]["duration_formatted"] = $row['times']['profile_duration_formatted'];
unset($app);
$x++;
}
}
unset($x);
//set the year, month and date
$tmp_year = date("Y", strtotime($start_stamp));
@@ -466,8 +301,7 @@
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<br />\n";
echo "<br />\n";
echo "<br /><br />\n";
//show the content
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
@@ -477,6 +311,7 @@
echo "</tr>\n";
echo "</table>\n";
//show the call summary - vertical
if ($_SESSION['cdr']['summary_style']['text'] == 'vertical') {
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
@@ -496,6 +331,7 @@
echo "<br /><br />\n";
}
//show the call summary - horizontal
if ($_SESSION['cdr']['summary_style']['text'] == 'horizontal') {
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<th>".$text['label-direction']."</th>\n";
@@ -510,7 +346,6 @@
echo "<th align='center'>".$text['label-status']."</th>\n";
echo "<th>".$text['label-hangup_cause']."</th>\n";
echo "</tr>\n";
echo "<tr >\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href='xml_cdr_details.php?id=".urlencode($uuid)."'>".escape($direction)."</a></td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$language."</td>\n";
@@ -549,27 +384,23 @@
echo "<br /><br />\n";
}
echo "</table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td align='left'><b>".$text['label-call_flow_summary']."</b>&nbsp;</td>\n";
echo "<td></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<th>".$text['label-application']."</th>\n";
echo "<th>".$text['label-destination']."</th>\n";
echo "<th>".$text['label-name']."</th>\n";
echo "<th>".$text['label-start']."</th>\n";
echo "<th>".$text['label-end']."</th>\n";
echo "<th>".$text['label-status']."</th>\n";
echo "<th>".$text['label-duration']."</th>\n";
echo "</tr>\n";
//show the call flow summary
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <td align='left'><b>".$text['label-call_flow_summary']."</b>&nbsp;</td>\n";
echo " <td></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <th>".$text['label-application']."</th>\n";
echo " <th>".$text['label-destination']."</th>\n";
echo " <th>".$text['label-name']."</th>\n";
echo " <th>".$text['label-start']."</th>\n";
echo " <th>".$text['label-end']."</th>\n";
echo " <th>".$text['label-status']."</th>\n";
echo " <th>".$text['label-duration']."</th>\n";
echo "</tr>\n";
$i = 1;
foreach ($call_flow_summary as $row) {
echo "<tr >\n";
@@ -598,18 +429,17 @@
if (!empty($array["call-stats"]) && is_array($array["call-stats"])) {
if (!empty($array["call-stats"]['audio']) && is_array($array["call-stats"]['audio'])) {
foreach ($array["call-stats"]['audio'] as $audio_direction => $stat) {
echo " <table width='95%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td><b>".$text['label-call-stats'].": ".$audio_direction."</b>&nbsp;</td>\n";
echo " <td>&nbsp;</td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "<table width='95%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <td><b>".$text['label-call-stats'].": ".$audio_direction."</b>&nbsp;</td>\n";
echo " <td>&nbsp;</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <th width='30%'>".$text['label-name']."</th>\n";
echo " <th width='70%'>".$text['label-value']."</th>\n";
echo " </tr>\n";
echo "<tr>\n";
echo " <th width='30%'>".$text['label-name']."</th>\n";
echo " <th width='70%'>".$text['label-value']."</th>\n";
echo "</tr>\n";
foreach ($stat as $key => $value) {
if (!empty($value) && is_array($value)) {
echo "<tr >\n";
@@ -644,15 +474,11 @@
}
$c = $c ? 0 : 1;
}
echo " <tr>\n";
echo " <td colspan='2'><br /><br /></td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<br /><br />\n";
}
}
}
echo "</table>";
echo "<br /><br />\n";
//channel data loop
$c = 0;
@@ -664,7 +490,6 @@
echo "<td></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<th width='30%'>".$text['label-name']."</th>\n";
@@ -695,7 +520,6 @@
echo "<td></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<th width='30%'>".$text['label-name']."</th>\n";
@@ -748,7 +572,7 @@
echo "</table>";
echo "<br /><br />\n";
//app_log
//application log
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
@@ -773,6 +597,7 @@
$app_name = $row["app_name"];
$app_data = urldecode($row["app_data"]);
}
//multiple apps
else {
$app_name = $row["@attributes"]["app_name"];
@@ -792,8 +617,8 @@
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
if (is_array($array["callflow"])) {
foreach ($array["callflow"] as $row) {
if (is_array($call_flow_array)) {
foreach ($call_flow_array as $row) {
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo " <td align='left'>\n";
@@ -805,7 +630,6 @@
echo " <td>&nbsp;</td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <th width='30%'>".$text['label-name']."</th>\n";
@@ -833,7 +657,6 @@
echo " <td>&nbsp;</td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <th width='30%'>".$text['label-name']."</th>\n";
@@ -895,7 +718,6 @@
echo " <td>&nbsp;</td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <th width='30%'>".$text['label-name']."</th>\n";
@@ -975,7 +797,6 @@
echo " <td><b>".$text['label-call-flow-5']."</b>&nbsp;</td>\n";
echo " <td></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <th width='30%'>".$text['label-name']."</th>\n";
echo " <th width='70%'>".$text['label-value']."</th>\n";
@@ -990,11 +811,6 @@
$c = $c ? 0 : 1;
}
}
echo " <tr>\n";
echo " <td colspan='2'><br /><br /></td>\n";
echo " </tr>\n";
echo " </table>";
echo " <br /><br />\n";