From caba7800d170cdff14e0b0e9e5041043e3d15d4a Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Thu, 14 Nov 2024 17:06:41 -0700 Subject: [PATCH] Updated Call Flow Summary for outbound calls --- app/xml_cdr/resources/classes/xml_cdr.php | 93 ++++++++++++++++++----- app/xml_cdr/xml_cdr.php | 6 +- app/xml_cdr/xml_cdr_details.php | 33 +++++--- 3 files changed, 98 insertions(+), 34 deletions(-) diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index fa5f7c7cd9..2ea042a501 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -43,6 +43,7 @@ if (!class_exists('xml_cdr')) { public $domain_uuid; public $call_details; public $call_direction; + public $status; public $billsec; private $username; private $password; @@ -1141,8 +1142,18 @@ if (!class_exists('xml_cdr')) { //add new rows when callee_id_number exists $new_rows = 0; foreach ($call_flow_array as $key => $row) { + //for outbound calls update the times if the bridged_time to remove the call setup plus the ring time + if ($this->call_direction === 'outbound') { + if (isset($row["times"]["bridged_time"]) and $row["times"]["bridged_time"] > 0) { + //change the end time for the current row + $call_flow_array[$key]["times"]["profile_created_time"] = $row["times"]["bridged_time"]; + } + } + + //add a new row to the call summary if (!empty($row["caller_profile"]["destination_number"]) and !empty($row["caller_profile"]["callee_id_number"]) + and $this->call_direction !== 'outbound' and $row["caller_profile"]["destination_number"] !== $row["caller_profile"]["callee_id_number"]) { //build the base of the new_row array $new_row["caller_profile"]["destination_number"] = $row["caller_profile"]["callee_id_number"]; @@ -1195,6 +1206,7 @@ if (!class_exists('xml_cdr')) { $x = 0; $skip_row = false; if (!empty($call_flow_array)) { foreach ($call_flow_array as $row) { + //skip this row if ($skip_row) { $skip_row = false; @@ -1203,7 +1215,12 @@ if (!class_exists('xml_cdr')) { //get the application array if (!empty($destination_array) && !empty($row["caller_profile"]["destination_number"])) { - $app = $this->find_app($destination_array, urldecode($row["caller_profile"]["destination_number"])); + if ($this->call_direction == 'outbound') { + $app = $this->find_app($destination_array, urldecode($row["caller_profile"]["username"])); + } + else { + $app = $this->find_app($destination_array, urldecode($row["caller_profile"]["destination_number"])); + } } //call centers @@ -1233,11 +1250,11 @@ if (!class_exists('xml_cdr')) { //extensions if (!empty($app['application']) && $app['application'] == 'extensions') { - if ($this->billsec == 0) { - $app['status'] = 'missed'; + if (!empty($row["times"]["profile_created_time"]) && !empty($row["times"]["profile_end_time"]) && (floor($row["times"]["profile_end_time"] / 1000000) - floor($row["times"]["profile_created_time"] / 1000000)) > 0) { + $app['status'] = 'answered'; } else { - $app['status'] = 'answered'; + $app['status'] = 'missed'; } } @@ -1248,10 +1265,23 @@ if (!class_exists('xml_cdr')) { //outbound routes if ($this->call_direction == 'outbound') { - if (empty($app['application'])) { - $app['application'] = 'dialplans'; + $status = 'missed'; + if (!empty($row["times"]["answered_time"])) { + $status = 'answered'; + } + + if (!empty($row["caller_profile"]["username"])) { + //add to the application array + $app['application'] = 'extensions'; + $app['source'] = $row["caller_profile"]["username"]; + $app['status'] = $status; + $app['name'] = ''; + $app['label'] = 'extensions'; + } + elseif (empty($app['application'])) { + $app['application'] = 'diaplans'; $app['uuid'] = ''; - $app['status'] = ''; + $app['status'] = $status; $app['name'] = 'Outbound'; $app['label'] = 'Outbound'; } @@ -1309,12 +1339,10 @@ if (!class_exists('xml_cdr')) { } //debug - add the callee_id_number to the end of the status - if ( - isset($_REQUEST['debug']) && $_REQUEST['debug'] == 'true' + if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == 'true' && !empty($row["caller_profile"]["destination_number"]) && !empty($row["caller_profile"]["callee_id_number"]) - && $row["caller_profile"]["destination_number"] !== $row["caller_profile"]["callee_id_number"] - ) { + && $row["caller_profile"]["destination_number"] !== $row["caller_profile"]["callee_id_number"]) { $app['status'] .= ' ('.$row["caller_profile"]["callee_id_number"].')'; } @@ -1331,26 +1359,48 @@ if (!class_exists('xml_cdr')) { $text2 = $language2->get($this->setting->get('domain', 'language'), '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]["call_direction"] = $this->call_direction; + $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; + if ($this->call_direction == 'outbound') { + $call_flow_summary[$x]["source_uuid"] = ($app['uuid'] ?? ''); + $call_flow_summary[$x]["source_number"] = $app['source']; + $call_flow_summary[$x]["source_label"] = ($app['label'] ?? ''); + $call_flow_summary[$x]["source_url"] = $destination_url; + $call_flow_summary[$x]["source_name"] = $app['description'] ?? ''; + //$call_flow_summary[$x]["source_description"] = $app['description'] ?? ''; + $call_flow_summary[$x]["destination_uuid"] = ''; + $call_flow_summary[$x]["destination_number"] = ''; + $call_flow_summary[$x]["destination_label"] = ''; + $call_flow_summary[$x]["destination_url"] = ''; + $call_flow_summary[$x]["destination_description"] = ''; + } + else { + $call_flow_summary[$x]["source_uuid"] = ''; + $call_flow_summary[$x]["source_number"] = ''; + $call_flow_summary[$x]["source_label"] = ''; + $call_flow_summary[$x]["source_url"] = ''; + $call_flow_summary[$x]["destination_name"] = ($app['description'] ?? ''); + $call_flow_summary[$x]["destination_uuid"] = ($app['uuid'] ?? ''); + $call_flow_summary[$x]["destination_label"] = ($app['label'] ?? ''); + $call_flow_summary[$x]["destination_url"] = $destination_url; + //$call_flow_summary[$x]["destination_description"] = $app['description'] ?? ''; + } $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; //set the start and epoch - $profile_created_epoch = round($row['times']['profile_created_time'] / 1000000); - $profile_end_epoch = round($row['times']['profile_end_time'] / 1000000); + $profile_created_epoch = $row['times']['profile_created_time'] / 1000000; + $profile_end_epoch = $row['times']['profile_end_time'] / 1000000; //add the call flow times - $call_flow_summary[$x]["start_epoch"] = $profile_created_epoch; - $call_flow_summary[$x]["end_epoch"] = $profile_end_epoch; + $call_flow_summary[$x]["start_epoch"] = round($profile_created_epoch); + $call_flow_summary[$x]["end_epoch"] = round($profile_end_epoch); $call_flow_summary[$x]["start_stamp"] = date("Y-m-d H:i:s", $profile_created_epoch); $call_flow_summary[$x]["end_stamp"] = date("Y-m-d H:i:s", $profile_end_epoch); - $call_flow_summary[$x]["duration_seconds"] = $profile_end_epoch - $profile_created_epoch; + $call_flow_summary[$x]["duration_seconds"] = round($profile_end_epoch - $profile_created_epoch); $call_flow_summary[$x]["duration_formatted"] = gmdate("G:i:s",(int) $call_flow_summary[$x]["duration_seconds"]); unset($app); $x++; @@ -1358,6 +1408,9 @@ if (!class_exists('xml_cdr')) { } unset($x); + //set the last status to match the call detail record + $call_flow_summary[count($call_flow_summary)-1]['destination_status'] = $this->status; + //return the call flow summary array return $call_flow_summary; } diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index 7a38a156d5..2b59f228a3 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -40,6 +40,9 @@ exit; } +//connect to the database + $database = database::new(); + //set permissions $permission = array(); $permission['xml_cdr_view'] = permission_exists('xml_cdr_view'); @@ -145,7 +148,6 @@ } $sql .= "order by extension asc, number_alias asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; $extensions = $database->select($sql, $parameters, 'all'); } @@ -155,7 +157,6 @@ $sql .= "where domain_uuid = :domain_uuid "; $sql .= "order by ring_group_extension asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; $ring_groups = $database->select($sql, $parameters, 'all'); } @@ -165,7 +166,6 @@ $sql .= "where domain_uuid = :domain_uuid "; $sql .= "order by queue_extension asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; $call_center_queues = $database->select($sql, $parameters, 'all'); } diff --git a/app/xml_cdr/xml_cdr_details.php b/app/xml_cdr/xml_cdr_details.php index dc7077c84c..414b6f998a 100644 --- a/app/xml_cdr/xml_cdr_details.php +++ b/app/xml_cdr/xml_cdr_details.php @@ -37,12 +37,15 @@ exit; } +//connect to the database + $database = database::new(); + //add multi-lingual support $language = new text; $text = $language->get(); //add the settings object - $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); + $settings = new settings(["database" => $database, "domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); $transcribe_enabled = $settings->get('transcribe', 'enabled', false); $transcribe_engine = $settings->get('transcribe', 'engine', ''); $call_log_enabled = $settings->get('cdr', 'call_log_enabled', false); @@ -64,7 +67,6 @@ $parameters['domain_uuid'] = $domain_uuid; } $parameters['xml_cdr_uuid'] = $uuid; - $database = new database; $row = $database->select($sql, $parameters, 'row'); if (!empty($row) && is_array($row) && @sizeof($row) != 0) { $caller_id_name = trim($row["caller_id_name"] ?? ''); @@ -116,7 +118,6 @@ $p->add('xml_cdr_edit', 'temp'); //remove record_path, record_name and record_length - $database = new database; $database->app_name = 'xml_cdr'; $database->app_uuid = '4a085c51-7635-ff03-f67b-86e834422848'; $database->save($array, false); @@ -147,7 +148,6 @@ $parameters['domain_uuid'] = $domain_uuid; } $parameters['xml_cdr_uuid'] = $uuid; - $database = new database; $row = $database->select($sql, $parameters, 'row'); if (!empty($row) && is_array($row) && @sizeof($row) != 0) { $json_string = trim($row["json"] ?? ''); @@ -167,7 +167,6 @@ $parameters['domain_uuid'] = $domain_uuid; } $parameters['xml_cdr_uuid'] = $uuid; - $database = new database; $row = $database->select($sql, $parameters, 'row'); if (!empty($row) && is_array($row) && @sizeof($row) != 0) { $call_flow = trim($row["call_flow"] ?? ''); @@ -187,7 +186,7 @@ $parameters['domain_uuid'] = $domain_uuid; } $parameters['xml_cdr_uuid'] = $uuid; - $database = new database; + $row = $database->select($sql, $parameters, 'row'); if (!empty($row) && is_array($row) && @sizeof($row) != 0) { $log_content = $row["log_content"]; @@ -271,15 +270,18 @@ //build the call flow summary array $xml_cdr = new xml_cdr; $xml_cdr->domain_uuid = $_SESSION['domain_uuid']; - $xml_cdr->call_direction = $call_direction; - $xml_cdr->billsec = $billsec; + $xml_cdr->call_direction = $call_direction; //used to determine when the call is outbound + $xml_cdr->status = $status; //used to determine when the call is outbound if (empty($call_flow)) { + //get the call flow summary from the xml_cdr_json table $xml_cdr->call_details = $array; $call_flow_array = $xml_cdr->call_flow(); } else { + //get the call flow summary from the xml_cdr_flow table $call_flow_array = json_decode($call_flow, true); } + //prepares the raw call flow data to be displayed $call_flow_summary = $xml_cdr->call_flow_summary($call_flow_array); //debug information @@ -293,7 +295,6 @@ } $i++; } - view_array($call_flow_array, false); } //set the year, month and date @@ -498,6 +499,9 @@ echo "\n"; echo "\n"; echo " \n"; + if ($call_direction == 'outbound') { + echo " \n"; + } echo " \n"; echo " \n"; echo " \n"; @@ -509,8 +513,15 @@ foreach ($call_flow_summary as $row) { echo "\n"; echo " \n"; - echo " \n"; - echo " \n"; + if ($call_direction == 'outbound') { + echo " \n"; + echo " \n"; + echo " \n"; + } + else { + echo " \n"; + echo " \n"; + } echo " \n"; echo " \n"; echo " \n";
".$text['label-application']."".$text['label-source']."".$text['label-destination']."".$text['label-name']."".$text['label-start']."
".escape($row["application_label"])."".escape($row["destination_number"])."".escape($row["destination_name"])."".escape($row["source_number"])."".escape($row["destination_number"])."".escape($row["source_name"])."".escape($row["destination_number"])."".escape($row["destination_name"])."".escape($row["start_stamp"])."".escape($row["end_stamp"])."".escape($row["duration_formatted"])."