2017-06-13 07:09:36 +02:00
< ? php
/*
FusionPBX
Version : MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 ( the " License " ); you may not use this file except in compliance with
the License . You may obtain a copy of the License at
http :// www . mozilla . org / MPL /
2019-09-16 16:00:30 +02:00
Software distributed under the License is distributed on an " AS IS " basis ,
2017-06-13 07:09:36 +02:00
WITHOUT WARRANTY OF ANY KIND , either express or implied . See the License
for the specific language governing rights and limitations under the
License .
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane < markjcrane @ fusionpbx . com >
2023-05-19 01:44:36 +02:00
Portions created by the Initial Developer are Copyright ( C ) 2016 - 2023
2017-06-13 07:09:36 +02:00
the Initial Developer . All Rights Reserved .
Contributor ( s ) :
Mark J Crane < markjcrane @ fusionpbx . com >
*/
/**
* xml_cdr class provides methods for adding cdr records to the database
*
* @ method boolean add
*/
if ( ! class_exists ( 'xml_cdr' )) {
class xml_cdr {
2017-06-22 07:46:17 +02:00
/**
* define variables
*/
2017-06-13 07:09:36 +02:00
public $db ;
public $array ;
public $fields ;
2023-09-18 22:59:21 +02:00
public $setting ;
2023-10-23 23:15:58 +02:00
public $domain_uuid ;
2023-10-18 00:21:17 +02:00
public $call_details ;
public $call_direction ;
2023-10-19 05:26:25 +02:00
public $billsec ;
2023-09-18 22:59:21 +02:00
private $username ;
private $password ;
2023-10-18 00:21:17 +02:00
private $json ;
2017-06-13 07:09:36 +02:00
2017-06-22 07:46:17 +02:00
/**
* user summary
*/
2023-10-23 23:15:58 +02:00
2017-06-13 07:09:36 +02:00
public $quick_select ;
public $start_stamp_begin ;
public $start_stamp_end ;
public $include_internal ;
public $extensions ;
2019-10-22 09:43:55 +02:00
/**
* delete method
*/
private $app_name ;
private $app_uuid ;
private $permission_prefix ;
private $list_page ;
private $table ;
private $uuid_prefix ;
2023-05-19 01:44:36 +02:00
/**
* Used by read_files , xml_array , and save methods
*/
public $file ;
2017-06-13 07:09:36 +02:00
/**
* Called when the object is created
*/
public function __construct () {
//connect to the database if not connected
if ( ! $this -> db ) {
$database = new database ;
$database -> connect ();
$this -> db = $database -> db ;
}
2019-10-22 09:43:55 +02:00
2023-09-18 22:59:21 +02:00
//get the email queue settings
$this -> setting = new settings ();
2019-10-22 09:43:55 +02:00
//assign private variables (for delete method)
2023-06-30 01:25:20 +02:00
$this -> app_name = 'xml_cdr' ;
$this -> app_uuid = '4a085c51-7635-ff03-f67b-86e834422848' ;
$this -> permission_prefix = 'xml_cdr_' ;
$this -> list_page = 'xml_cdr.php' ;
$this -> table = 'xml_cdr' ;
$this -> uuid_prefix = 'xml_cdr_' ;
2017-06-13 07:09:36 +02:00
}
/**
* cdr process logging
*/
public function log ( $message ) {
2023-02-21 18:38:25 +01:00
2021-05-26 22:29:46 +02:00
//save the log if enabled is true
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'log' , 'enabled' ) == 'true' ) {
2021-05-26 22:29:46 +02:00
//save the log to the php error log
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'log' , 'type' ) == 'error_log' ) {
2023-06-30 01:25:20 +02:00
error_log ( $message );
2021-05-26 22:29:46 +02:00
}
//save the log to the syslog server
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'log' , 'type' ) == 'syslog' ) {
2021-05-26 22:29:46 +02:00
openlog ( " XML CDR " , LOG_PID | LOG_PERROR , LOG_LOCAL0 );
2023-06-30 01:25:20 +02:00
syslog ( LOG_WARNING , $message );
2021-05-26 22:29:46 +02:00
closelog ();
}
//save the log to the file system
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'log' , 'text' ) == 'file' ) {
$fp = fopen ( $this -> setting -> get ( 'server' , 'temp' ) . '/xml_cdr.log' , 'a+' );
2021-05-26 22:29:46 +02:00
if ( ! $fp ) {
return ;
}
fwrite ( $fp , $message );
fclose ( $fp );
2017-06-13 07:09:36 +02:00
}
2021-05-26 22:29:46 +02:00
}
2017-06-13 07:09:36 +02:00
}
/**
* cdr fields in the database schema
*/
public function fields () {
2018-10-18 06:08:20 +02:00
$this -> fields [] = " xml_cdr_uuid " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " domain_uuid " ;
2023-12-10 07:07:36 +01:00
$this -> fields [] = " provider_uuid " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " extension_uuid " ;
2021-08-01 03:25:23 +02:00
$this -> fields [] = " sip_call_id " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " domain_name " ;
$this -> fields [] = " accountcode " ;
$this -> fields [] = " direction " ;
$this -> fields [] = " default_language " ;
$this -> fields [] = " context " ;
2023-10-18 00:21:17 +02:00
$this -> fields [] = " call_flow " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " xml " ;
$this -> fields [] = " json " ;
2019-03-17 07:55:09 +01:00
$this -> fields [] = " missed_call " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " caller_id_name " ;
$this -> fields [] = " caller_id_number " ;
$this -> fields [] = " caller_destination " ;
$this -> fields [] = " destination_number " ;
$this -> fields [] = " source_number " ;
$this -> fields [] = " start_epoch " ;
$this -> fields [] = " start_stamp " ;
$this -> fields [] = " answer_stamp " ;
$this -> fields [] = " answer_epoch " ;
$this -> fields [] = " end_epoch " ;
$this -> fields [] = " end_stamp " ;
$this -> fields [] = " duration " ;
$this -> fields [] = " mduration " ;
$this -> fields [] = " billsec " ;
$this -> fields [] = " billmsec " ;
$this -> fields [] = " bridge_uuid " ;
$this -> fields [] = " read_codec " ;
$this -> fields [] = " read_rate " ;
$this -> fields [] = " write_codec " ;
$this -> fields [] = " write_rate " ;
$this -> fields [] = " remote_media_ip " ;
$this -> fields [] = " network_addr " ;
2017-10-15 19:35:55 +02:00
$this -> fields [] = " record_path " ;
$this -> fields [] = " record_name " ;
2022-12-04 02:36:42 +01:00
$this -> fields [] = " record_length " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " leg " ;
Improved Missed Call accuracy, cdr statistics, and hide duplicated CDRs from Enterprise Ring Groups
Changes
--------
- Improve CDR Import Logic so that missed_call column is more accurate to the "missed" status. It would previously mark unanswered outbound calls as "missed". These are their own category of call.
- Don't mark the CDRs of the "legs" of an Enterprise Ring Group call as missed, only the originating_leg will be marked (one missed call per call) - We could also just "skip" importing these call legs. Simultaneous ring groups don't have these duplicated CDRs for every ringing phone. The "Skip" approach might make most of the rest of this work irrelevant.
- Create `originating_leg_uuid` column in v_xml_cdr and import it into the database during CDR imports so it is available for filtering Enterprise Ring Group calls out of CDRs and reports.
- Move logic that hides the agent leg of CC calls, LOSE_RACE calls, and the Enterprise Leg hiding code from xml_cdr.php into xml_cdr_inc.php into the SQL query WHERE clause so the CDR page looks more consistent. The logic is the same, but these calls are now excluded from the query result entirely instead of having to "skip" rendering them in the list on the xml_cdr.php page.
- Improved CDR statistics page to use the missed_call variable instead of relying upon billsec and answer_stamp/answer_epoch. Added the same logic as the xml_cdr pages to the query so it excludes enterprise ring group call legs.
- Laid the query groundwork in xml_cdr_statistics to report on Average TTA (No UI changes yet to include that statistic)
Retroactive Changes
---------------------
There are a few changes going back in time to bring everything in line with this better reporting accuracy:
- If you want the populated the `originating_leg_uuid column` in `v_xml_cdr`, it will rely upon having the `json` column and not having deleted the data from it like I know some people do for space saving.
- If you don't have the json column, you are mostly out of luck for hiding the duplicate legs of Enterprise ring group calls. It might be possible, but it isn't going to be easy.
- On Newer Versions of postgres, this works:
```
UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid WHERE json->'variables'->>'originating_leg_uuid' IS NOT NULL;
```
- For some reason on postgres 9.4, I had to UPDATE every single record because I couldn't get it to allow the json syntax properly after the WHERE. This is fine, it doesn't change the end result it just means it has to run the UPDATE on every record, which will take a while
```
UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid;
```
- To remove the `missed_call = true` on all your previous outbound records so that they don't show up when you filter on missed (outbound unanswered calls can be accurately listed with TTA max 0 and direction outbound)
```
UPDATE v_xml_cdr SET missed_call = false WHERE direction = 'outbound' AND missed_call = true;
```
2021-02-18 14:51:48 +01:00
$this -> fields [] = " originating_leg_uuid " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " pdd_ms " ;
$this -> fields [] = " rtp_audio_in_mos " ;
$this -> fields [] = " last_app " ;
$this -> fields [] = " last_arg " ;
2021-02-22 04:09:37 +01:00
$this -> fields [] = " voicemail_message " ;
2021-05-09 21:52:42 +02:00
$this -> fields [] = " call_center_queue_uuid " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " cc_side " ;
$this -> fields [] = " cc_member_uuid " ;
$this -> fields [] = " cc_queue_joined_epoch " ;
$this -> fields [] = " cc_queue " ;
$this -> fields [] = " cc_member_session_uuid " ;
2018-01-30 01:25:40 +01:00
$this -> fields [] = " cc_agent_uuid " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " cc_agent " ;
$this -> fields [] = " cc_agent_type " ;
2018-01-30 01:25:40 +01:00
$this -> fields [] = " cc_agent_bridged " ;
$this -> fields [] = " cc_queue_answered_epoch " ;
$this -> fields [] = " cc_queue_terminated_epoch " ;
2020-07-03 00:27:54 +02:00
$this -> fields [] = " cc_queue_canceled_epoch " ;
$this -> fields [] = " cc_cancel_reason " ;
2018-01-30 01:25:40 +01:00
$this -> fields [] = " cc_cause " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " waitsec " ;
$this -> fields [] = " conference_name " ;
$this -> fields [] = " conference_uuid " ;
$this -> fields [] = " conference_member_id " ;
$this -> fields [] = " digits_dialed " ;
$this -> fields [] = " pin_number " ;
2023-10-24 23:58:13 +02:00
$this -> fields [] = " status " ;
2017-06-13 07:09:36 +02:00
$this -> fields [] = " hangup_cause " ;
$this -> fields [] = " hangup_cause_q850 " ;
$this -> fields [] = " sip_hangup_disposition " ;
2023-09-18 22:59:21 +02:00
if ( ! empty ( $this -> setting -> get ( 'cdr' , 'field' ))) {
foreach ( $this -> setting -> get ( 'cdr' , 'field' ) as $field ) {
2023-09-08 17:33:54 +02:00
$field_name = end ( explode ( ',' , $field ));
2021-05-08 03:08:11 +02:00
$this -> fields [] = $field_name ;
2017-06-13 07:09:36 +02:00
}
}
2023-02-09 02:43:25 +01:00
$this -> fields = array_unique ( $this -> fields );
2017-06-13 07:09:36 +02:00
}
/**
* save to the database
*/
public function save () {
$this -> fields ();
$field_count = sizeof ( $this -> fields );
//$field_count = sizeof($this->fields);
2023-06-30 01:25:20 +02:00
if ( ! empty ( $this -> array )) {
2019-09-03 22:32:33 +02:00
foreach ( $this -> array as $row ) {
2020-12-11 04:03:53 +01:00
//build the array
2019-09-03 22:32:33 +02:00
if ( isset ( $this -> fields )) {
foreach ( $this -> fields as $field ) {
2019-09-13 08:36:24 +02:00
$field = preg_replace ( '#[^a-zA-Z0-9_\-]#' , '' , $field );
2023-05-05 18:46:37 +02:00
if ( isset ( $row [ $field ]) && ! empty ( $row [ $field ])) {
2020-12-11 04:03:53 +01:00
$array [ 'xml_cdr' ][ 0 ][ $field ] = $row [ $field ];
2019-09-03 22:32:33 +02:00
}
}
2017-06-13 07:09:36 +02:00
}
2020-12-11 04:03:53 +01:00
2023-05-19 01:44:36 +02:00
//set the directory
2023-09-18 22:59:21 +02:00
if ( ! empty ( $this -> setting -> get ( 'switch' , 'log' ))) {
$xml_cdr_dir = $this -> setting -> get ( 'switch' , 'log' ) . '/xml_cdr' ;
2023-05-19 01:44:36 +02:00
}
2020-12-11 04:03:53 +01:00
//add the temporary permission
$p = new permissions ;
$p -> add ( " xml_cdr_add " , " temp " );
$p -> add ( " xml_cdr_edit " , " temp " );
//save the call details record to the database
2019-09-13 08:36:24 +02:00
$database = new database ;
2020-12-11 04:03:53 +01:00
$database -> app_name = 'xml_cdr' ;
$database -> app_uuid = '4a085c51-7635-ff03-f67b-86e834422848' ;
2023-06-30 01:25:20 +02:00
//$database->domain_uuid = $domain_uuid;
2023-05-19 01:44:36 +02:00
$response = $database -> save ( $array , false );
if ( $response [ 'code' ] == '200' ) {
//saved to the database successfully delete the database file
if ( ! empty ( $xml_cdr_dir )) {
if ( file_exists ( $xml_cdr_dir . '/' . $this -> file )) {
unlink ( $xml_cdr_dir . '/' . $this -> file );
}
}
}
else {
//move the file to a failed directory
if ( ! empty ( $xml_cdr_dir )) {
if ( ! file_exists ( $xml_cdr_dir . '/failed' )) {
if ( ! mkdir ( $xml_cdr_dir . '/failed' , 0660 , true )) {
2023-09-18 22:59:21 +02:00
die ( 'Failed to create ' . $xml_cdr_dir . '/failed' );
2023-05-19 01:44:36 +02:00
}
}
rename ( $xml_cdr_dir . '/' . $this -> file , $xml_cdr_dir . '/failed/' . $this -> file );
}
//send an error message
echo 'failed file moved to ' . $xml_cdr_dir . '/failed/' . $this -> file ;
}
2021-05-26 22:29:46 +02:00
2023-06-30 01:25:20 +02:00
//clear the array
unset ( $this -> array );
2023-02-21 18:38:25 +01:00
//debug results
2021-05-26 22:29:46 +02:00
$this -> log ( print_r ( $database -> message , true ));
2020-12-11 04:03:53 +01:00
//remove the temporary permission
$p -> delete ( " xml_cdr_add " , " temp " );
$p -> delete ( " xml_cdr_edit " , " temp " );
unset ( $array );
2017-06-13 07:09:36 +02:00
}
}
2019-09-13 08:36:24 +02:00
2017-06-13 07:09:36 +02:00
}
/**
* process method converts the xml cdr and adds it to the database
*/
public function xml_array ( $key , $leg , $xml_string ) {
2023-06-30 01:25:20 +02:00
//xml string is empty
if ( empty ( $xml_string )) {
return false ;
}
2017-06-13 07:09:36 +02:00
//fix the xml by escaping the contents of <sip_full_XXX>
2023-06-30 01:25:20 +02:00
if ( defined ( 'STDIN' )) {
2017-06-13 07:09:36 +02:00
$xml_string = preg_replace_callback ( " /<([^><]+)>(.*?[><].*?)< \ / \ g1>/ " ,
function ( $matches ) {
return '<' . $matches [ 1 ] . '>' .
str_replace ( " > " , " > " ,
str_replace ( " < " , " < " , $matches [ 2 ])
) .
'</' . $matches [ 1 ] . '>' ;
},
$xml_string
);
}
2023-06-30 01:25:20 +02:00
//remove invalid numeric xml tags
$xml_string = preg_replace ( '/<\/?\d+>/' , '' , $xml_string );
2019-12-23 19:20:43 +01:00
2023-06-30 01:25:20 +02:00
//disable xml entities
if ( PHP_VERSION_ID < 80000 ) { libxml_disable_entity_loader ( true ); }
//load the string into an xml object
$xml = simplexml_load_string ( $xml_string , 'SimpleXMLElement' , LIBXML_NOCDATA );
if ( $xml === false ) {
//set the directory
2023-09-18 22:59:21 +02:00
if ( ! empty ( $this -> setting -> get ( 'switch' , 'log' ))) {
$xml_cdr_dir = $this -> setting -> get ( 'switch' , 'log' ) . '/xml_cdr' ;
2023-06-30 01:25:20 +02:00
}
//failed to load the XML, move the XML file to the failed directory
if ( ! empty ( $xml_cdr_dir )) {
if ( ! file_exists ( $xml_cdr_dir . '/failed' )) {
if ( ! mkdir ( $xml_cdr_dir . '/failed' , 0660 , true )) {
die ( 'Failed to create ' . $xml_cdr_dir . '/failed' );
}
}
rename ( $xml_cdr_dir . '/' . $this -> file , $xml_cdr_dir . '/failed/' . $this -> file );
}
//return without saving the invalid xml
return false ;
2017-06-13 07:09:36 +02:00
}
2018-01-09 19:11:03 +01:00
//check for duplicate call uuid's
2018-01-09 19:01:10 +01:00
$duplicate_uuid = false ;
2019-09-03 22:32:33 +02:00
$uuid = urldecode ( $xml -> variables -> uuid );
2023-05-19 01:44:36 +02:00
if ( $uuid != null && is_uuid ( $uuid )) {
2019-09-13 08:11:37 +02:00
$sql = " select count(xml_cdr_uuid) " ;
$sql .= " from v_xml_cdr " ;
$sql .= " where xml_cdr_uuid = :xml_cdr_uuid " ;
$parameters [ 'xml_cdr_uuid' ] = $uuid ;
$database = new database ;
$count = $database -> select ( $sql , $parameters , 'column' );
if ( $count > 0 ) {
2023-05-19 01:44:36 +02:00
//duplicate uuid detected
2019-09-13 08:11:37 +02:00
$duplicate_uuid = true ;
2023-05-19 01:44:36 +02:00
//remove the file as the record already exists in the database
2023-09-18 22:59:21 +02:00
if ( ! empty ( $this -> setting -> get ( 'switch' , 'log' ))) {
$xml_cdr_dir = $this -> setting -> get ( 'switch' , 'log' ) . '/xml_cdr' ;
2023-05-19 01:44:36 +02:00
if ( file_exists ( $xml_cdr_dir . '/' . $this -> file )) {
unlink ( $xml_cdr_dir . '/' . $this -> file );
}
}
2019-09-13 08:11:37 +02:00
}
unset ( $sql , $parameters );
2017-06-13 07:09:36 +02:00
}
2023-08-26 00:05:33 +02:00
//set the call_direction
if ( isset ( $xml -> variables -> call_direction )) {
$call_direction = urldecode ( $xml -> variables -> call_direction );
}
//set the accountcode
if ( isset ( $xml -> variables -> accountcode )) {
$accountcode = urldecode ( $xml -> variables -> accountcode );
}
2018-01-09 19:11:03 +01:00
//process data if the call detail record is not a duplicate
2019-09-13 08:11:37 +02:00
if ( $duplicate_uuid == false && is_uuid ( $uuid )) {
2022-08-23 21:13:34 +02:00
//get the caller ID from call flow caller profile
$i = 0 ;
foreach ( $xml -> callflow as $row ) {
if ( $i == 0 ) {
$caller_id_name = urldecode ( $row -> caller_profile -> caller_id_name );
$caller_id_number = urldecode ( $row -> caller_profile -> caller_id_number );
}
$i ++ ;
}
unset ( $i );
//get the caller ID from variables
if ( ! isset ( $caller_id_number ) && isset ( $xml -> variables -> caller_id_name )) {
2022-03-15 21:43:55 +01:00
$caller_id_name = urldecode ( $xml -> variables -> caller_id_name );
}
2022-08-23 21:13:34 +02:00
if ( ! isset ( $caller_id_number ) && isset ( $xml -> variables -> caller_id_number )) {
2022-03-15 21:43:55 +01:00
$caller_id_number = urldecode ( $xml -> variables -> caller_id_number );
}
if ( ! isset ( $caller_id_number ) && isset ( $xml -> variables -> sip_from_user )) {
$caller_id_number = urldecode ( $xml -> variables -> sip_from_user );
}
2022-01-05 01:50:51 +01:00
2022-03-15 21:33:44 +01:00
//if the origination caller id name and number are set then use them
if ( isset ( $xml -> variables -> origination_caller_id_name )) {
$caller_id_name = urldecode ( $xml -> variables -> origination_caller_id_name );
}
if ( isset ( $xml -> variables -> origination_caller_id_number )) {
$caller_id_number = urldecode ( $xml -> variables -> origination_caller_id_number );
}
2022-01-05 01:50:51 +01:00
//if the call is outbound use the external caller ID
2022-01-18 19:52:26 +01:00
if ( isset ( $xml -> variables -> effective_caller_id_name )) {
2020-05-06 05:32:33 +02:00
$caller_id_name = urldecode ( $xml -> variables -> effective_caller_id_name );
2018-01-09 19:01:10 +01:00
}
2023-02-21 18:38:25 +01:00
2022-08-16 08:00:43 +02:00
if ( isset ( $xml -> variables -> origination_caller_id_name )) {
$caller_id_name = urldecode ( $xml -> variables -> origination_caller_id_name );
}
2023-02-21 18:38:25 +01:00
2022-08-16 08:00:43 +02:00
if ( isset ( $xml -> variables -> origination_caller_id_number )) {
$caller_id_number = urldecode ( $xml -> variables -> origination_caller_id_number );
}
2023-02-21 18:38:25 +01:00
2023-08-26 00:05:33 +02:00
if ( urldecode ( $call_direction ) == 'outbound' && isset ( $xml -> variables -> effective_caller_id_number )) {
2020-05-06 05:32:33 +02:00
$caller_id_number = urldecode ( $xml -> variables -> effective_caller_id_number );
}
2022-01-05 01:50:51 +01:00
//if the sip_from_domain and domain_name are not the same then original call direction was inbound
//when an inbound call is forward the call_direction is set to inbound and then updated to outbound
//use sip_from_display and sip_from_user to get the original caller ID instead of the updated caller ID info from the forward
2023-02-21 18:38:25 +01:00
if ( isset ( $xml -> variables -> sip_from_domain ) && urldecode ( $xml -> variables -> sip_from_domain ) != urldecode ( $xml -> variables -> domain_name )) {
2022-01-18 20:05:32 +01:00
if ( isset ( $xml -> variables -> sip_from_display )) {
$caller_id_name = urldecode ( $xml -> variables -> sip_from_display );
}
if ( isset ( $xml -> variables -> sip_from_user )) {
$caller_id_number = urldecode ( $xml -> variables -> sip_from_user );
}
2022-01-05 01:50:51 +01:00
}
2020-05-06 05:32:33 +02:00
//get the values from the callflow.
$i = 0 ;
foreach ( $xml -> callflow as $row ) {
if ( $i == 0 ) {
$context = urldecode ( $row -> caller_profile -> context );
$destination_number = urldecode ( $row -> caller_profile -> destination_number );
$network_addr = urldecode ( $row -> caller_profile -> network_addr );
}
$i ++ ;
2018-01-09 19:01:10 +01:00
}
2020-05-06 05:32:33 +02:00
unset ( $i );
2018-01-09 19:11:03 +01:00
//if last_sent_callee_id_number is set use it for the destination_number
2023-05-05 18:46:37 +02:00
if ( ! empty ( $xml -> variables -> last_sent_callee_id_number )) {
2018-01-09 19:11:03 +01:00
$destination_number = urldecode ( $xml -> variables -> last_sent_callee_id_number );
2017-10-21 01:54:49 +02:00
}
2018-01-09 19:11:03 +01:00
2020-04-17 20:53:50 +02:00
//remove the provider prefix
if ( isset ( $xml -> variables -> provider_prefix ) && isset ( $destination_number )) {
$provider_prefix = $xml -> variables -> provider_prefix ;
if ( $provider_prefix == substr ( $destination_number , 0 , strlen ( $provider_prefix ))) {
$destination_number = substr ( $destination_number , strlen ( $provider_prefix ), strlen ( $destination_number ));
}
}
2022-03-15 21:33:44 +01:00
//get the caller_destination
if ( isset ( $xml -> variables -> caller_destination ) ) {
$caller_destination = urldecode ( $xml -> variables -> caller_destination );
}
if ( isset ( $xml -> variables -> sip_h_caller_destination ) ) {
$caller_destination = urldecode ( $xml -> variables -> sip_h_caller_destination );
}
2022-03-15 21:50:28 +01:00
if ( ! isset ( $caller_destination ) && isset ( $xml -> variables -> dialed_user )) {
$caller_destination = urldecode ( $xml -> variables -> dialed_user );
}
2022-03-15 21:33:44 +01:00
2019-03-17 07:55:09 +01:00
//set missed calls
2022-08-04 23:37:12 +02:00
if ( isset ( $xml -> variables -> missed_call )) {
2022-08-05 21:19:35 +02:00
//marked as missed
2022-08-04 20:50:29 +02:00
$missed_call = $xml -> variables -> missed_call ;
}
2024-02-06 23:24:46 +01:00
if ( isset ( $xml -> variables -> billsec ) && $xml -> variables -> billsec > 0 ) {
//answered call
$missed_call = 'false' ;
}
if ( isset ( $xml -> variables -> cc_side ) && $xml -> variables -> cc_side == 'agent' ) {
//call center
$missed_call = 'false' ;
}
2023-12-20 21:59:33 +01:00
if ( isset ( $xml -> variables -> fax_success )) {
2022-08-05 21:19:35 +02:00
//fax server
2022-08-05 03:09:23 +02:00
$missed_call = 'false' ;
}
2023-12-20 21:59:33 +01:00
if ( isset ( $xml -> variables -> hangup_cause ) && $xml -> variables -> hangup_cause == 'LOSE_RACE' ) {
2022-08-05 21:19:35 +02:00
//ring group or multi destination bridge statement
2022-08-05 03:09:23 +02:00
$missed_call = 'false' ;
}
2023-12-20 21:59:33 +01:00
if ( isset ( $xml -> variables -> hangup_cause ) && $xml -> variables -> hangup_cause == 'NO_ANSWER' && isset ( $xml -> variables -> originating_leg_uuid )) {
2022-08-05 21:19:35 +02:00
//ring group or multi destination bridge statement
2022-08-05 03:09:23 +02:00
$missed_call = 'false' ;
}
2023-12-20 21:59:33 +01:00
if ( isset ( $xml -> variables -> destination_number ) && substr ( $xml -> variables -> destination_number , 0 , 3 ) == '*99' ) {
2022-08-05 21:19:35 +02:00
//voicemail
2022-08-05 23:05:49 +02:00
$missed_call = 'true' ;
}
2024-02-06 23:24:46 +01:00
if ( isset ( $xml -> variables -> voicemail_answer_stamp ) && ! empty ( $xml -> variables -> voicemail_answer_stamp )) {
2022-08-05 23:05:49 +02:00
//voicemail
$missed_call = 'true' ;
2022-08-05 21:19:35 +02:00
}
2023-12-27 19:37:36 +01:00
if ( isset ( $xml -> variables -> cc_side ) && $xml -> variables -> cc_side == 'member'
2023-12-20 21:59:33 +01:00
&& isset ( $xml -> variables -> cc_cause ) && $xml -> variables -> cc_cause == 'cancel' ) {
2023-12-20 21:49:48 +01:00
//call center
2021-06-15 20:20:04 +02:00
$missed_call = 'true' ;
}
2023-01-28 22:49:35 +01:00
2023-08-26 00:05:33 +02:00
//read the bridge statement variables
if ( isset ( $xml -> variables -> last_app )) {
if ( urldecode ( $xml -> variables -> last_app ) == 'bridge' ) {
//get the variables from inside the { and } brackets
preg_match ( '/^\{([^}]+)\}/' , urldecode ( $xml -> variables -> last_arg ), $matches );
//create a variables array from the comma delimitted string
$bridge_variables = explode ( " , " , $matches [ 1 ]);
//set bridge variables as variables
$x = 0 ;
if ( ! empty ( $bridge_variables )) {
foreach ( $bridge_variables as $variable ) {
$pairs = explode ( " = " , $variable );
$name = $pairs [ 0 ];
$$name = $pairs [ 1 ];
$x ++ ;
}
}
}
}
2023-01-27 18:18:35 +01:00
//get the last bridge_uuid from the call to preserve previous behavior
foreach ( $xml -> variables -> bridge_uuids as $bridge ) {
$last_bridge = urldecode ( $bridge );
}
2019-03-17 07:55:09 +01:00
2023-10-24 23:58:13 +02:00
//determine the call status
$failed_array = array (
" CALL_REJECTED " ,
" CHAN_NOT_IMPLEMENTED " ,
" DESTINATION_OUT_OF_ORDER " ,
" EXCHANGE_ROUTING_ERROR " ,
" INCOMPATIBLE_DESTINATION " ,
" INVALID_NUMBER_FORMAT " ,
" MANDATORY_IE_MISSING " ,
" NETWORK_OUT_OF_ORDER " ,
" NORMAL_TEMPORARY_FAILURE " ,
" NORMAL_UNSPECIFIED " ,
" NO_ROUTE_DESTINATION " ,
" RECOVERY_ON_TIMER_EXPIRE " ,
" REQUESTED_CHAN_UNAVAIL " ,
" SUBSCRIBER_ABSENT " ,
" SYSTEM_SHUTDOWN " ,
" UNALLOCATED_NUMBER "
);
if ( $xml -> variables -> billsec > 0 ) {
$status = 'answered' ;
}
2023-10-25 17:37:17 +02:00
if ( $xml -> variables -> hangup_cause == 'NO_ANSWER' ) {
$status = 'no_answer' ;
}
2023-10-24 23:58:13 +02:00
if ( $missed_call == 'true' ) {
$status = 'missed' ;
}
if ( substr ( $destination_number , 0 , 3 ) == '*99' ) {
$status = 'voicemail' ;
}
2024-02-20 20:47:10 +01:00
if ( isset ( $xml -> variables -> voicemail_message_seconds ) && $xml -> variables -> voicemail_message_seconds > 0 ) {
2024-02-06 23:24:46 +01:00
$status = 'voicemail' ;
}
2023-10-24 23:58:13 +02:00
if ( $xml -> variables -> hangup_cause == 'ORIGINATOR_CANCEL' ) {
$status = 'cancelled' ;
}
if ( $xml -> variables -> hangup_cause == 'USER_BUSY' ) {
$status = 'busy' ;
}
if ( in_array ( $xml -> variables -> hangup_cause , $failed_array )) {
$status = 'failed' ;
}
2023-12-27 19:37:36 +01:00
if ( ! isset ( $status ) && in_array ( $xml -> variables -> last_bridge_hangup_cause , $failed_array )) {
$status = 'failed' ;
}
2023-12-27 21:08:15 +01:00
if ( $xml -> variables -> cc_side == 'agent' && $xml -> variables -> billsec == 0 ) {
$status = 'no_answer' ;
}
if ( ! isset ( $status ) && $xml -> variables -> billsec == 0 ) {
$status = 'no_answer' ;
}
2023-10-24 23:58:13 +02:00
2023-12-10 07:07:36 +01:00
//set the provider id
if ( isset ( $xml -> variables -> provider_uuid )) {
$this -> array [ $key ][ 'provider_uuid' ] = urldecode ( $xml -> variables -> provider_uuid );
}
2018-01-09 19:11:03 +01:00
//misc
2023-06-30 01:25:20 +02:00
$key = 0 ;
2019-09-03 22:32:33 +02:00
$uuid = urldecode ( $xml -> variables -> uuid );
2018-10-18 06:08:20 +02:00
$this -> array [ $key ][ 'xml_cdr_uuid' ] = $uuid ;
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'destination_number' ] = $destination_number ;
2021-08-01 03:25:23 +02:00
$this -> array [ $key ][ 'sip_call_id' ] = urldecode ( $xml -> variables -> sip_call_id );
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'source_number' ] = urldecode ( $xml -> variables -> effective_caller_id_number );
$this -> array [ $key ][ 'user_context' ] = urldecode ( $xml -> variables -> user_context );
$this -> array [ $key ][ 'network_addr' ] = urldecode ( $xml -> variables -> sip_network_ip );
$this -> array [ $key ][ 'missed_call' ] = $missed_call ;
$this -> array [ $key ][ 'caller_id_name' ] = $caller_id_name ;
$this -> array [ $key ][ 'caller_id_number' ] = $caller_id_number ;
2022-03-15 21:33:44 +01:00
$this -> array [ $key ][ 'caller_destination' ] = $caller_destination ;
2023-08-26 00:05:33 +02:00
$this -> array [ $key ][ 'accountcode' ] = urldecode ( $accountcode );
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'default_language' ] = urldecode ( $xml -> variables -> default_language );
2023-01-27 18:18:35 +01:00
$this -> array [ $key ][ 'bridge_uuid' ] = urldecode ( $xml -> variables -> bridge_uuid ) ? : $last_bridge ;
2019-09-03 22:32:33 +02:00
//$this->array[$key]['digits_dialed'] = urldecode($xml->variables->digits_dialed);
$this -> array [ $key ][ 'sip_hangup_disposition' ] = urldecode ( $xml -> variables -> sip_hangup_disposition );
$this -> array [ $key ][ 'pin_number' ] = urldecode ( $xml -> variables -> pin_number );
2023-10-24 23:58:13 +02:00
$this -> array [ $key ][ 'status' ] = $status ;
2020-07-03 00:27:54 +02:00
2018-01-09 19:11:03 +01:00
//time
2021-05-26 17:11:09 +02:00
$start_epoch = urldecode ( $xml -> variables -> start_epoch );
$this -> array [ $key ][ 'start_epoch' ] = $start_epoch ;
2022-01-05 01:50:51 +01:00
$this -> array [ $key ][ 'start_stamp' ] = is_numeric ( $start_epoch ) ? date ( 'c' , $start_epoch ) : null ;
2021-05-26 17:11:09 +02:00
$answer_epoch = urldecode ( $xml -> variables -> answer_epoch );
$this -> array [ $key ][ 'answer_epoch' ] = $answer_epoch ;
2022-01-05 01:50:51 +01:00
$this -> array [ $key ][ 'answer_stamp' ] = is_numeric ( $answer_epoch ) ? date ( 'c' , $answer_epoch ) : null ;
2021-05-26 17:11:09 +02:00
$end_epoch = urldecode ( $xml -> variables -> end_epoch );
$this -> array [ $key ][ 'end_epoch' ] = $end_epoch ;
2022-01-05 01:50:51 +01:00
$this -> array [ $key ][ 'end_stamp' ] = is_numeric ( $end_epoch ) ? date ( 'c' , $end_epoch ) : null ;
2023-10-24 23:58:13 +02:00
$this -> array [ $key ][ 'duration' ] = urldecode ( $xml -> variables -> billsec );
$this -> array [ $key ][ 'mduration' ] = urldecode ( $xml -> variables -> billmsec );
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'billsec' ] = urldecode ( $xml -> variables -> billsec );
$this -> array [ $key ][ 'billmsec' ] = urldecode ( $xml -> variables -> billmsec );
2020-07-03 00:27:54 +02:00
2018-01-09 19:11:03 +01:00
//codecs
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'read_codec' ] = urldecode ( $xml -> variables -> read_codec );
$this -> array [ $key ][ 'read_rate' ] = urldecode ( $xml -> variables -> read_rate );
$this -> array [ $key ][ 'write_codec' ] = urldecode ( $xml -> variables -> write_codec );
$this -> array [ $key ][ 'write_rate' ] = urldecode ( $xml -> variables -> write_rate );
$this -> array [ $key ][ 'remote_media_ip' ] = urldecode ( $xml -> variables -> remote_media_ip );
$this -> array [ $key ][ 'hangup_cause' ] = urldecode ( $xml -> variables -> hangup_cause );
$this -> array [ $key ][ 'hangup_cause_q850' ] = urldecode ( $xml -> variables -> hangup_cause_q850 );
2020-07-03 00:27:54 +02:00
2020-07-03 02:02:19 +02:00
//store the call direction
2023-08-26 00:05:33 +02:00
$this -> array [ $key ][ 'direction' ] = urldecode ( $call_direction );
2023-02-21 18:38:25 +01:00
2018-01-09 19:11:03 +01:00
//call center
2023-05-19 07:41:21 +02:00
if ( $xml -> variables -> cc_member_uuid == '_undef_' ) { $xml -> variables -> cc_member_uuid = '' ; }
if ( $xml -> variables -> cc_member_session_uuid == '_undef_' ) { $xml -> variables -> cc_member_session_uuid = '' ; }
if ( $xml -> variables -> cc_agent_uuid == '_undef_' ) { $xml -> variables -> cc_agent_uuid = '' ; }
if ( $xml -> variables -> call_center_queue_uuid == '_undef_' ) { $xml -> variables -> call_center_queue_uuid = '' ; }
if ( $xml -> variables -> cc_queue_joined_epoch == '_undef_' ) { $xml -> variables -> cc_queue_joined_epoch = '' ; }
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'cc_side' ] = urldecode ( $xml -> variables -> cc_side );
$this -> array [ $key ][ 'cc_member_uuid' ] = urldecode ( $xml -> variables -> cc_member_uuid );
2022-05-05 18:43:44 +02:00
$this -> array [ $key ][ 'cc_queue' ] = urldecode ( $xml -> variables -> cc_queue );
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'cc_member_session_uuid' ] = urldecode ( $xml -> variables -> cc_member_session_uuid );
2020-07-03 00:48:07 +02:00
$this -> array [ $key ][ 'cc_agent_uuid' ] = urldecode ( $xml -> variables -> cc_agent_uuid );
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'cc_agent' ] = urldecode ( $xml -> variables -> cc_agent );
$this -> array [ $key ][ 'cc_agent_type' ] = urldecode ( $xml -> variables -> cc_agent_type );
2020-07-03 00:48:07 +02:00
$this -> array [ $key ][ 'cc_agent_bridged' ] = urldecode ( $xml -> variables -> cc_agent_bridged );
2023-06-09 02:47:17 +02:00
$this -> array [ $key ][ 'cc_queue_joined_epoch' ] = urldecode ( $xml -> variables -> cc_queue_joined_epoch );
2020-07-03 00:48:07 +02:00
$this -> array [ $key ][ 'cc_queue_answered_epoch' ] = urldecode ( $xml -> variables -> cc_queue_answered_epoch );
$this -> array [ $key ][ 'cc_queue_terminated_epoch' ] = urldecode ( $xml -> variables -> cc_queue_terminated_epoch );
$this -> array [ $key ][ 'cc_queue_canceled_epoch' ] = urldecode ( $xml -> variables -> cc_queue_canceled_epoch );
$this -> array [ $key ][ 'cc_cancel_reason' ] = urldecode ( $xml -> variables -> cc_cancel_reason );
$this -> array [ $key ][ 'cc_cause' ] = urldecode ( $xml -> variables -> cc_cause );
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'waitsec' ] = urldecode ( $xml -> variables -> waitsec );
2020-07-03 02:02:19 +02:00
if ( urldecode ( $xml -> variables -> cc_side ) == 'agent' ) {
$this -> array [ $key ][ 'direction' ] = 'inbound' ;
}
2021-05-09 21:52:42 +02:00
$this -> array [ $key ][ 'cc_queue' ] = urldecode ( $xml -> variables -> cc_queue );
$this -> array [ $key ][ 'call_center_queue_uuid' ] = urldecode ( $xml -> variables -> call_center_queue_uuid );
2020-07-03 00:27:54 +02:00
2018-01-09 19:11:03 +01:00
//app info
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'last_app' ] = urldecode ( $xml -> variables -> last_app );
$this -> array [ $key ][ 'last_arg' ] = urldecode ( $xml -> variables -> last_arg );
2020-07-03 00:27:54 +02:00
2021-02-22 04:09:37 +01:00
//voicemail message success
2024-02-06 23:24:46 +01:00
if ( ! empty ( $xml -> variables -> voicemail_answer_stamp ) && $xml -> variables -> voicemail_message_seconds > 0 ){
2021-02-22 04:09:37 +01:00
$this -> array [ $key ][ 'voicemail_message' ] = " true " ;
}
else { //if ($xml->variables->voicemail_action == "save") {
$this -> array [ $key ][ 'voicemail_message' ] = " false " ;
}
2018-01-09 19:11:03 +01:00
//conference
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'conference_name' ] = urldecode ( $xml -> variables -> conference_name );
$this -> array [ $key ][ 'conference_uuid' ] = urldecode ( $xml -> variables -> conference_uuid );
$this -> array [ $key ][ 'conference_member_id' ] = urldecode ( $xml -> variables -> conference_member_id );
2020-07-03 00:27:54 +02:00
2018-01-09 19:11:03 +01:00
//call quality
2019-09-03 22:32:33 +02:00
$rtp_audio_in_mos = urldecode ( $xml -> variables -> rtp_audio_in_mos );
2023-05-05 18:46:37 +02:00
if ( ! empty ( $rtp_audio_in_mos )) {
2018-01-09 19:11:03 +01:00
$this -> array [ $key ][ 'rtp_audio_in_mos' ] = $rtp_audio_in_mos ;
2017-06-13 07:09:36 +02:00
}
2018-01-09 19:11:03 +01:00
//store the call leg
$this -> array [ $key ][ 'leg' ] = $leg ;
Improved Missed Call accuracy, cdr statistics, and hide duplicated CDRs from Enterprise Ring Groups
Changes
--------
- Improve CDR Import Logic so that missed_call column is more accurate to the "missed" status. It would previously mark unanswered outbound calls as "missed". These are their own category of call.
- Don't mark the CDRs of the "legs" of an Enterprise Ring Group call as missed, only the originating_leg will be marked (one missed call per call) - We could also just "skip" importing these call legs. Simultaneous ring groups don't have these duplicated CDRs for every ringing phone. The "Skip" approach might make most of the rest of this work irrelevant.
- Create `originating_leg_uuid` column in v_xml_cdr and import it into the database during CDR imports so it is available for filtering Enterprise Ring Group calls out of CDRs and reports.
- Move logic that hides the agent leg of CC calls, LOSE_RACE calls, and the Enterprise Leg hiding code from xml_cdr.php into xml_cdr_inc.php into the SQL query WHERE clause so the CDR page looks more consistent. The logic is the same, but these calls are now excluded from the query result entirely instead of having to "skip" rendering them in the list on the xml_cdr.php page.
- Improved CDR statistics page to use the missed_call variable instead of relying upon billsec and answer_stamp/answer_epoch. Added the same logic as the xml_cdr pages to the query so it excludes enterprise ring group call legs.
- Laid the query groundwork in xml_cdr_statistics to report on Average TTA (No UI changes yet to include that statistic)
Retroactive Changes
---------------------
There are a few changes going back in time to bring everything in line with this better reporting accuracy:
- If you want the populated the `originating_leg_uuid column` in `v_xml_cdr`, it will rely upon having the `json` column and not having deleted the data from it like I know some people do for space saving.
- If you don't have the json column, you are mostly out of luck for hiding the duplicate legs of Enterprise ring group calls. It might be possible, but it isn't going to be easy.
- On Newer Versions of postgres, this works:
```
UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid WHERE json->'variables'->>'originating_leg_uuid' IS NOT NULL;
```
- For some reason on postgres 9.4, I had to UPDATE every single record because I couldn't get it to allow the json syntax properly after the WHERE. This is fine, it doesn't change the end result it just means it has to run the UPDATE on every record, which will take a while
```
UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid;
```
- To remove the `missed_call = true` on all your previous outbound records so that they don't show up when you filter on missed (outbound unanswered calls can be accurately listed with TTA max 0 and direction outbound)
```
UPDATE v_xml_cdr SET missed_call = false WHERE direction = 'outbound' AND missed_call = true;
```
2021-02-18 14:51:48 +01:00
//store the originating leg uuid
$this -> array [ $key ][ 'originating_leg_uuid' ] = urldecode ( $xml -> variables -> originating_leg_uuid );
2018-01-09 19:11:03 +01:00
//store post dial delay, in milliseconds
2023-10-31 03:29:56 +01:00
$this -> array [ $key ][ 'pdd_ms' ] = urldecode (( int ) $xml -> variables -> progress_mediamsec ) + ( int ) urldecode ( $xml -> variables -> progressmsec );
2018-01-09 19:11:03 +01:00
//get break down the date to year, month and day
2021-05-26 17:11:09 +02:00
$start_stamp = urldecode ( $xml -> variables -> start_stamp );
2020-08-11 18:39:27 +02:00
$start_time = strtotime ( $start_stamp );
$start_year = date ( " Y " , $start_time );
$start_month = date ( " M " , $start_time );
$start_day = date ( " d " , $start_time );
2018-01-09 19:11:03 +01:00
//get the domain values from the xml
2019-09-03 22:32:33 +02:00
$domain_name = urldecode ( $xml -> variables -> domain_name );
$domain_uuid = urldecode ( $xml -> variables -> domain_uuid );
2018-01-09 19:11:03 +01:00
//get the domain name
2023-05-05 18:46:37 +02:00
if ( empty ( $domain_name )) {
2019-09-13 02:28:34 +02:00
$domain_name = urldecode ( $xml -> variables -> dialed_domain );
}
2023-05-05 18:46:37 +02:00
if ( empty ( $domain_name )) {
2019-09-13 02:28:34 +02:00
$domain_name = urldecode ( $xml -> variables -> sip_invite_domain );
}
2023-05-05 18:46:37 +02:00
if ( empty ( $domain_name )) {
2019-09-03 22:32:33 +02:00
$domain_name = urldecode ( $xml -> variables -> sip_req_host );
2017-06-13 07:09:36 +02:00
}
2023-05-05 18:46:37 +02:00
if ( empty ( $domain_name )) {
2019-09-03 22:32:33 +02:00
$presence_id = urldecode ( $xml -> variables -> presence_id );
2023-05-05 18:46:37 +02:00
if ( ! empty ( $presence_id )) {
Improved Missed Call accuracy, cdr statistics, and hide duplicated CDRs from Enterprise Ring Groups
Changes
--------
- Improve CDR Import Logic so that missed_call column is more accurate to the "missed" status. It would previously mark unanswered outbound calls as "missed". These are their own category of call.
- Don't mark the CDRs of the "legs" of an Enterprise Ring Group call as missed, only the originating_leg will be marked (one missed call per call) - We could also just "skip" importing these call legs. Simultaneous ring groups don't have these duplicated CDRs for every ringing phone. The "Skip" approach might make most of the rest of this work irrelevant.
- Create `originating_leg_uuid` column in v_xml_cdr and import it into the database during CDR imports so it is available for filtering Enterprise Ring Group calls out of CDRs and reports.
- Move logic that hides the agent leg of CC calls, LOSE_RACE calls, and the Enterprise Leg hiding code from xml_cdr.php into xml_cdr_inc.php into the SQL query WHERE clause so the CDR page looks more consistent. The logic is the same, but these calls are now excluded from the query result entirely instead of having to "skip" rendering them in the list on the xml_cdr.php page.
- Improved CDR statistics page to use the missed_call variable instead of relying upon billsec and answer_stamp/answer_epoch. Added the same logic as the xml_cdr pages to the query so it excludes enterprise ring group call legs.
- Laid the query groundwork in xml_cdr_statistics to report on Average TTA (No UI changes yet to include that statistic)
Retroactive Changes
---------------------
There are a few changes going back in time to bring everything in line with this better reporting accuracy:
- If you want the populated the `originating_leg_uuid column` in `v_xml_cdr`, it will rely upon having the `json` column and not having deleted the data from it like I know some people do for space saving.
- If you don't have the json column, you are mostly out of luck for hiding the duplicate legs of Enterprise ring group calls. It might be possible, but it isn't going to be easy.
- On Newer Versions of postgres, this works:
```
UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid WHERE json->'variables'->>'originating_leg_uuid' IS NOT NULL;
```
- For some reason on postgres 9.4, I had to UPDATE every single record because I couldn't get it to allow the json syntax properly after the WHERE. This is fine, it doesn't change the end result it just means it has to run the UPDATE on every record, which will take a while
```
UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid;
```
- To remove the `missed_call = true` on all your previous outbound records so that they don't show up when you filter on missed (outbound unanswered calls can be accurately listed with TTA max 0 and direction outbound)
```
UPDATE v_xml_cdr SET missed_call = false WHERE direction = 'outbound' AND missed_call = true;
```
2021-02-18 14:51:48 +01:00
$presence_array = explode ( $presence_id , '%40' );
2018-01-09 19:11:03 +01:00
$domain_name = $presence_array [ 1 ];
}
}
//dynamic cdr fields
2023-09-18 22:59:21 +02:00
if ( ! empty ( $this -> setting -> get ( 'cdr' , 'field' ))) {
foreach ( $this -> setting -> get ( 'cdr' , 'field' ) as $field ) {
2018-01-09 19:11:03 +01:00
$fields = explode ( " , " , $field );
$field_name = end ( $fields );
$this -> fields [] = $field_name ;
2023-02-21 18:38:25 +01:00
if ( ! isset ( $this -> array [ $key ][ $field_name ])) {
2023-02-09 02:43:25 +01:00
if ( count ( $fields ) == 1 ) {
$this -> array [ $key ][ $field_name ] = urldecode ( $xml -> variables -> { $fields [ 0 ]});
}
if ( count ( $fields ) == 2 ) {
$this -> array [ $key ][ $field_name ] = urldecode ( $xml -> { $fields [ 0 ]} -> { $fields [ 1 ]});
}
if ( count ( $fields ) == 3 ) {
$this -> array [ $key ][ $field_name ] = urldecode ( $xml -> { $fields [ 0 ]} -> { $fields [ 1 ]} -> { $fields [ 2 ]});
}
if ( count ( $fields ) == 4 ) {
$this -> array [ $key ][ $field_name ] = urldecode ( $xml -> { $fields [ 0 ]} -> { $fields [ 1 ]} -> { $fields [ 2 ]} -> { $fields [ 3 ]});
}
if ( count ( $fields ) == 5 ) {
$this -> array [ $key ][ $field_name ] = urldecode ( $xml -> { $fields [ 0 ]} -> { $fields [ 1 ]} -> { $fields [ 2 ]} -> { $fields [ 3 ]} -> { $fields [ 4 ]});
}
2018-01-09 19:01:10 +01:00
}
}
2017-06-13 07:09:36 +02:00
}
2018-01-09 19:11:03 +01:00
//send the domain name to the cdr log
2021-05-26 22:29:46 +02:00
//$this->log("\ndomain_name is `$domain_name`;\ndomain_uuid is '$domain_uuid'\n");
2018-01-09 19:11:03 +01:00
//get the domain_uuid with the domain_name
2023-05-05 18:46:37 +02:00
if ( empty ( $domain_uuid )) {
2018-01-09 19:11:03 +01:00
$sql = " select domain_uuid from v_domains " ;
2023-05-05 18:46:37 +02:00
if ( empty ( $domain_name ) && $context != 'public' && $context != 'default' ) {
2019-09-04 07:01:19 +02:00
$sql .= " where domain_name = :context " ;
$parameters [ 'context' ] = $context ;
2018-01-09 19:01:10 +01:00
}
2018-01-09 19:11:03 +01:00
else {
2019-09-04 07:01:19 +02:00
$sql .= " where domain_name = :domain_name " ;
$parameters [ 'domain_name' ] = $domain_name ;
2018-01-09 19:11:03 +01:00
}
2019-09-04 07:01:19 +02:00
$database = new database ;
$domain_uuid = $database -> select ( $sql , $parameters , 'column' );
unset ( $parameters );
2018-01-09 19:11:03 +01:00
}
//set values in the database
2023-05-05 18:46:37 +02:00
if ( ! empty ( $domain_uuid )) {
2018-01-09 19:11:03 +01:00
$this -> array [ $key ][ 'domain_uuid' ] = $domain_uuid ;
}
2023-05-05 18:46:37 +02:00
if ( ! empty ( $domain_name )) {
2018-01-09 19:11:03 +01:00
$this -> array [ $key ][ 'domain_name' ] = $domain_name ;
}
//get the recording details
2023-08-10 17:05:42 +02:00
if ( isset ( $xml -> variables -> record_path ) && isset ( $xml -> variables -> record_name )) {
2018-01-09 19:11:03 +01:00
$record_path = urldecode ( $xml -> variables -> record_path );
$record_name = urldecode ( $xml -> variables -> record_name );
2020-03-10 17:43:58 +01:00
if ( isset ( $xml -> variables -> record_seconds )) {
$record_length = urldecode ( $xml -> variables -> record_seconds );
}
else {
$record_length = urldecode ( $xml -> variables -> duration );
}
2018-01-09 19:11:03 +01:00
}
2023-08-10 17:05:42 +02:00
elseif ( isset ( $xml -> variables -> cc_record_filename )) {
$record_path = dirname ( urldecode ( $xml -> variables -> cc_record_filename ));
$record_name = basename ( urldecode ( $xml -> variables -> cc_record_filename ));
$record_length = urldecode ( $xml -> variables -> record_seconds );
}
2019-02-18 21:30:17 +01:00
elseif ( ! isset ( $record_path ) && urldecode ( $xml -> variables -> last_app ) == " record_session " ) {
$record_path = dirname ( urldecode ( $xml -> variables -> last_arg ));
$record_name = basename ( urldecode ( $xml -> variables -> last_arg ));
2018-01-09 19:11:03 +01:00
$record_length = urldecode ( $xml -> variables -> record_seconds );
2017-06-13 07:09:36 +02:00
}
2023-05-05 18:46:37 +02:00
elseif ( ! empty ( $xml -> variables -> sofia_record_file )) {
2018-01-09 19:11:03 +01:00
$record_path = dirname ( urldecode ( $xml -> variables -> sofia_record_file ));
$record_name = basename ( urldecode ( $xml -> variables -> sofia_record_file ));
$record_length = urldecode ( $xml -> variables -> record_seconds );
2018-01-09 19:01:10 +01:00
}
2023-05-05 18:46:37 +02:00
elseif ( ! empty ( $xml -> variables -> api_on_answer )) {
2018-01-09 19:11:03 +01:00
$command = str_replace ( " \n " , " " , urldecode ( $xml -> variables -> api_on_answer ));
$parts = explode ( " " , $command );
if ( $parts [ 0 ] == " uuid_record " ) {
$recording = $parts [ 3 ];
$record_path = dirname ( $recording );
$record_name = basename ( $recording );
$record_length = urldecode ( $xml -> variables -> duration );
2017-06-13 07:09:36 +02:00
}
2018-01-09 19:11:03 +01:00
}
2023-05-05 18:46:37 +02:00
elseif ( ! empty ( $xml -> variables -> conference_recording )) {
2022-06-09 19:04:07 +02:00
$conference_recording = urldecode ( $xml -> variables -> conference_recording );
$record_path = dirname ( $conference_recording );
$record_name = basename ( $conference_recording );
$record_length = urldecode ( $xml -> variables -> duration );
}
2023-05-05 18:46:37 +02:00
elseif ( ! empty ( $xml -> variables -> current_application_data )) {
2018-01-09 19:11:03 +01:00
$commands = explode ( " , " , urldecode ( $xml -> variables -> current_application_data ));
foreach ( $commands as $command ) {
$cmd = explode ( " = " , $command );
if ( $cmd [ 0 ] == " api_on_answer " ) {
$a = explode ( " ] " , $cmd [ 1 ]);
$command = str_replace ( " ' " , " " , $a [ 0 ]);
$parts = explode ( " " , $command );
if ( $parts [ 0 ] == " uuid_record " ) {
$recording = $parts [ 3 ];
$record_path = dirname ( $recording );
$record_name = basename ( $recording );
$record_length = urldecode ( $xml -> variables -> duration );
}
}
2017-06-13 07:09:36 +02:00
}
2018-01-09 19:11:03 +01:00
}
2023-10-18 00:21:17 +02:00
2023-08-10 17:05:42 +02:00
//check to see if file exists with the default file name and path
2023-08-04 21:53:37 +02:00
if ( empty ( $record_name )) {
2023-09-18 22:59:21 +02:00
$path = $this -> setting -> get ( 'switch' , 'recordings' ) . '/' . $domain_name . '/archive/' . $start_year . '/' . $start_month . '/' . $start_day ;
2019-02-18 21:30:17 +01:00
if ( file_exists ( $path . '/' . $uuid . '.wav' )) {
$record_path = $path ;
$record_name = $uuid . '.wav' ;
$record_length = urldecode ( $xml -> variables -> duration );
} elseif ( file_exists ( $path . '/' . $uuid . '.mp3' )) {
$record_path = $path ;
$record_name = $uuid . '.mp3' ;
$record_length = urldecode ( $xml -> variables -> duration );
}
}
2019-09-13 08:11:37 +02:00
2023-08-10 17:05:42 +02:00
//last check - check to see if file exists with the bridge_uuid for the file name and path
2023-08-04 21:53:37 +02:00
if ( empty ( $record_name )) {
2023-08-10 17:05:42 +02:00
$bridge_uuid = urldecode ( $xml -> variables -> bridge_uuid ) ? : $last_bridge ;
2023-09-18 22:59:21 +02:00
$path = $this -> setting -> get ( 'switch' , 'recordings' ) . '/' . $domain_name . '/archive/' . $start_year . '/' . $start_month . '/' . $start_day ;
2019-04-21 01:05:40 +02:00
if ( file_exists ( $path . '/' . $bridge_uuid . '.wav' )) {
$record_path = $path ;
$record_name = $bridge_uuid . '.wav' ;
$record_length = urldecode ( $xml -> variables -> duration );
} elseif ( file_exists ( $path . '/' . $bridge_uuid . '.mp3' )) {
$record_path = $path ;
$record_name = $bridge_uuid . '.mp3' ;
$record_length = urldecode ( $xml -> variables -> duration );
}
}
2019-09-13 08:11:37 +02:00
2020-12-11 04:03:53 +01:00
//debug information
//echo "line: ".__line__;
//echo "record_path: ".$record_path."\n";
//echo "record_name: ".$record_name."\n";
//echo "record_length: ".$record_length."\n";
//exit;
2023-03-15 21:48:26 +01:00
//add the call record path, name and length to the database
if ( isset ( $record_path ) && isset ( $record_name ) && file_exists ( $record_path . '/' . $record_name )) {
2022-12-04 02:36:42 +01:00
$this -> array [ $key ][ 'record_path' ] = $record_path ;
$this -> array [ $key ][ 'record_name' ] = $record_name ;
2023-03-15 21:48:26 +01:00
if ( isset ( $record_length )) {
$this -> array [ $key ][ 'record_length' ] = $record_length ;
}
else {
$this -> array [ $key ][ 'record_length' ] = urldecode ( $xml -> variables -> duration );
}
2022-12-04 02:36:42 +01:00
}
2023-10-18 00:21:17 +02:00
//save the xml object to json
$this -> json = json_encode ( $xml );
2018-01-09 19:11:03 +01:00
//save to the database in xml format
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'cdr' , 'format' ) == " xml " && $this -> setting -> get ( 'cdr' , 'storage' ) == " db " ) {
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'xml' ] = $xml_string ;
2018-01-09 19:11:03 +01:00
}
//save to the database in json format
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'cdr' , 'format' ) == " json " && $this -> setting -> get ( 'cdr' , 'storage' ) == " db " ) {
2023-10-18 00:21:17 +02:00
$this -> array [ $key ][ 'json' ] = $this -> json ;
2018-01-09 19:11:03 +01:00
}
2023-10-18 00:21:17 +02:00
//build the call detail array with json decode
$this -> call_details = json_decode ( $this -> json , true );
//get the call flow json
$this -> array [ $key ][ 'call_flow' ] = json_encode ( $this -> call_flow ());
2019-10-07 23:44:05 +02:00
//get the extension_uuid and then add it to the database fields array
2020-12-21 19:13:55 +01:00
if ( isset ( $xml -> variables -> extension_uuid )) {
2019-09-03 22:32:33 +02:00
$this -> array [ $key ][ 'extension_uuid' ] = urldecode ( $xml -> variables -> extension_uuid );
2018-01-09 19:11:03 +01:00
}
2019-10-07 23:44:05 +02:00
else {
2020-12-21 19:13:55 +01:00
if ( isset ( $domain_uuid ) && isset ( $xml -> variables -> dialed_user )) {
2019-10-07 23:44:05 +02:00
$sql = " select extension_uuid from v_extensions " ;
$sql .= " where domain_uuid = :domain_uuid " ;
$sql .= " and (extension = :dialed_user or number_alias = :dialed_user) " ;
$parameters [ 'domain_uuid' ] = $domain_uuid ;
$parameters [ 'dialed_user' ] = $xml -> variables -> dialed_user ;
$database = new database ;
$extension_uuid = $database -> select ( $sql , $parameters , 'column' );
$this -> array [ $key ][ 'extension_uuid' ] = $extension_uuid ;
unset ( $parameters );
}
2020-12-21 19:13:55 +01:00
if ( isset ( $domain_uuid ) && isset ( $xml -> variables -> referred_by_user )) {
2019-10-08 07:49:24 +02:00
$sql = " select extension_uuid from v_extensions " ;
$sql .= " where domain_uuid = :domain_uuid " ;
$sql .= " and (extension = :referred_by_user or number_alias = :referred_by_user) " ;
$parameters [ 'domain_uuid' ] = $domain_uuid ;
$parameters [ 'referred_by_user' ] = $xml -> variables -> referred_by_user ;
$database = new database ;
$extension_uuid = $database -> select ( $sql , $parameters , 'column' );
$this -> array [ $key ][ 'extension_uuid' ] = $extension_uuid ;
unset ( $parameters );
}
2020-12-21 19:13:55 +01:00
if ( isset ( $domain_uuid ) && isset ( $xml -> variables -> last_sent_callee_id_number )) {
2019-10-08 07:49:24 +02:00
$sql = " select extension_uuid from v_extensions " ;
$sql .= " where domain_uuid = :domain_uuid " ;
2020-12-21 19:13:55 +01:00
$sql .= " and (extension = :last_sent_callee_id_number or number_alias = :last_sent_callee_id_number) " ;
2019-10-08 07:49:24 +02:00
$parameters [ 'domain_uuid' ] = $domain_uuid ;
2020-12-15 18:42:47 +01:00
$parameters [ 'last_sent_callee_id_number' ] = $xml -> variables -> last_sent_callee_id_number ;
2019-10-08 07:49:24 +02:00
$database = new database ;
$extension_uuid = $database -> select ( $sql , $parameters , 'column' );
$this -> array [ $key ][ 'extension_uuid' ] = $extension_uuid ;
unset ( $parameters );
}
2019-10-07 23:44:05 +02:00
}
2018-01-09 19:11:03 +01:00
2023-06-30 01:25:20 +02:00
//store xml cdr on the file system as a file
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'cdr' , 'storage' ) == " dir " && $error != " true " ) {
2023-05-05 18:46:37 +02:00
if ( ! empty ( $uuid )) {
2023-09-18 22:59:21 +02:00
$tmp_dir = $this -> setting -> get ( 'switch' , 'log' ) . '/xml_cdr/archive/' . $start_year . '/' . $start_month . '/' . $start_day ;
2018-01-09 19:01:10 +01:00
if ( ! file_exists ( $tmp_dir )) {
2021-12-03 03:03:55 +01:00
mkdir ( $tmp_dir , 0770 , true );
2018-01-09 19:01:10 +01:00
}
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'cdr' , 'format' ) == " xml " ) {
2018-01-09 19:01:10 +01:00
$tmp_file = $uuid . '.xml' ;
$fh = fopen ( $tmp_dir . '/' . $tmp_file , 'w' );
fwrite ( $fh , $xml_string );
}
else {
$tmp_file = $uuid . '.json' ;
$fh = fopen ( $tmp_dir . '/' . $tmp_file , 'w' );
fwrite ( $fh , json_encode ( $xml ));
}
fclose ( $fh );
2018-01-09 19:11:03 +01:00
}
2019-09-13 08:11:37 +02:00
}
unset ( $error );
2018-01-09 19:11:03 +01:00
2023-06-30 01:25:20 +02:00
//save data to the database
$this -> save ();
//debug
2021-05-26 22:29:46 +02:00
//GLOBAL $insert_time,$insert_count;
//$insert_time+=microtime(true)-$time5_insert; //add this current query.
//$insert_count++;
2018-01-09 19:11:03 +01:00
} //if ($duplicate_uuid == false)
} //function xml_array
2017-06-13 07:09:36 +02:00
2023-10-18 00:21:17 +02:00
/**
* Build a call flow array based on call details .
*
* This method constructs an array that represents the call flow , utilizing the provided call_details array . Reverses the array to put the events in chronological order and adds profile end times .
*
* @ return array The call flow array .
*/
public function call_flow () {
//save the call flow to the database
if ( isset ( $this -> call_details [ 'callflow' ])) {
//set the call flow array
$call_flow_array = $this -> call_details [ 'callflow' ];
//normalize the array
if ( ! isset ( $call_flow_array [ 0 ])) {
$tmp = $call_flow_array ;
unset ( $call_flow_array );
$call_flow_array [ 0 ] = $tmp ;
}
//reverse the array to put events in chronological order
$call_flow_array = array_reverse ( $call_flow_array );
//add the profile end time to the call flow array
$i = 0 ;
foreach ( $call_flow_array as $row ) {
//set the profile end time
if ( isset ( $call_flow_array [ $i + 1 ][ " times " ][ " profile_created_time " ])) {
$call_flow_array [ $i ][ " times " ][ " profile_end_time " ] = $call_flow_array [ $i + 1 ][ " times " ][ " profile_created_time " ];
}
else {
$call_flow_array [ $i ][ " times " ][ " profile_end_time " ] = urldecode ( $this -> call_details [ 'variables' ][ 'end_uepoch' ]);
}
$i ++ ;
}
//format the times in the call flow array and add the profile duration
$i = 0 ;
foreach ( $call_flow_array as $row ) {
foreach ( $row [ " times " ] as $name => $value ) {
if ( $value > 0 ) {
$call_flow_array [ $i ][ " times " ][ " profile_duration_seconds " ] = round ((( int ) $call_flow_array [ $i ][ " times " ][ " profile_end_time " ]) / 1000000 - (( int ) $call_flow_array [ $i ][ " times " ][ " profile_created_time " ]) / 1000000 );
$call_flow_array [ $i ][ " times " ][ " profile_duration_formatted " ] = gmdate ( " G:i:s " , ( int ) $call_flow_array [ $i ][ " times " ][ " profile_duration_seconds " ]);
}
}
$i ++ ;
}
//add the call_flow to the array
return $call_flow_array ;
}
}
/**
* Build a call flow summary array based on call summary
*
* This method constructs an array that represents the call flow summary using the call flow array array . The call flow summary array contains a simplified view of the call flow .
*
* @ return array The call flow summary array .
*/
public function call_flow_summary ( $call_flow_array ) {
//set the time zone
if ( ! empty ( $this -> setting -> get ( 'domain' , 'time_zone' ))) {
$time_zone = $this -> setting -> get ( 'domain' , 'time_zone' );
}
else {
$time_zone = date_default_timezone_get ();
}
//get the destination select list
$destination = new destinations ;
$destination_array = $destination -> get ( 'dialplan' );
2023-12-10 07:07:36 +01:00
//add new rows when callee_id_number exists
2023-10-21 06:16:48 +02:00
$new_rows = 0 ;
foreach ( $call_flow_array as $key => $row ) {
2023-12-10 07:07:36 +01:00
if ( ! empty ( $row [ " caller_profile " ][ " destination_number " ])
2023-10-21 06:16:48 +02:00
and ! empty ( $row [ " caller_profile " ][ " callee_id_number " ])
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 " ];
$new_row [ " caller_profile " ][ " caller_id_name " ] = $row [ " caller_profile " ][ " callee_id_name " ];
$new_row [ " caller_profile " ][ " caller_id_number " ] = $row [ " caller_profile " ][ " caller_id_number " ];
$new_row [ 'times' ][ " profile_created_time " ] = $row [ " times " ][ " profile_created_time " ];
$new_row [ 'times' ][ " profile_end_time " ] = $row [ " times " ][ " profile_end_time " ];
//update the times if the transfer_time exists. The order of this is important add new row needs to be set before this code
if ( isset ( $row [ " times " ][ " transfer_time " ]) and $row [ " times " ][ " transfer_time " ] > 0 ) {
//change the end time for the current row
$call_flow_array [ $key + $new_rows ][ " times " ][ " profile_end_time " ] = $row [ " times " ][ " transfer_time " ];
//change the created time for the new row
$new_row [ 'times' ][ " profile_created_time " ] = $row [ " times " ][ " transfer_time " ];
}
//update the times if the bridged_time exists. The order of this is important add new row needs to be set before this code, and transfer_time needs to be before bridge_time
if ( isset ( $row [ " times " ][ " bridged_time " ]) and $row [ " times " ][ " bridged_time " ] > 0 ) {
//change the end time for the current row
$call_flow_array [ $key + $new_rows ][ " times " ][ " profile_end_time " ] = $row [ " times " ][ " bridged_time " ];
//change the created time for the new row
$new_row [ 'times' ][ " profile_created_time " ] = $row [ " times " ][ " bridged_time " ];
}
//increment the new row id
$new_rows ++ ;
//insert the new row into the array without overwriting an existing row
array_splice ( $call_flow_array , $key + $new_rows , 0 , [ $new_row ]);
//clean up
unset ( $new_row );
}
$i ++ ;
}
2023-10-25 19:13:20 +02:00
//format the times in the call flow array
2023-10-19 05:26:25 +02:00
$i = 0 ;
2023-10-21 06:16:48 +02:00
foreach ( $call_flow_array as $key => $row ) {
2023-10-19 05:26:25 +02:00
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 ++ ;
}
2023-10-18 00:21:17 +02:00
//build the call flow summary
2023-10-21 06:16:48 +02:00
$x = 0 ; $skip_row = false ;
2023-10-18 00:21:17 +02:00
if ( ! empty ( $call_flow_array )) {
foreach ( $call_flow_array as $row ) {
2023-10-21 06:16:48 +02:00
//skip this row
if ( $skip_row ) {
$skip_row = false ;
continue ;
}
2023-10-18 00:21:17 +02:00
//get the application array
2023-10-20 04:02:55 +02:00
if ( ! empty ( $destination_array ) && ! empty ( $row [ " caller_profile " ][ " destination_number " ])) {
2023-10-23 23:15:58 +02:00
$app = $this -> find_app ( $destination_array , urldecode ( $row [ " caller_profile " ][ " destination_number " ]));
2023-10-20 04:02:55 +02:00
}
2023-10-18 00:21:17 +02:00
//call centers
if ( $app [ 'application' ] == 'call_centers' ) {
if ( isset ( $row [ " caller_profile " ][ " transfer_source " ])) {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'answered' ; //Out
2023-10-18 00:21:17 +02:00
}
else {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'waited' ; //In
2023-10-18 00:21:17 +02:00
}
}
2023-10-21 18:40:31 +02:00
//call flows
if ( $app [ 'application' ] == 'call_flows' ) {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'routed' ;
2023-10-21 18:40:31 +02:00
}
2023-10-18 00:21:17 +02:00
//conferences
if ( $app [ 'application' ] == 'conferences' ) {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'answered' ;
2023-10-18 00:21:17 +02:00
}
//destinations
if ( $app [ 'application' ] == 'destinations' ) {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'routed' ;
2023-10-18 00:21:17 +02:00
}
//extensions
if ( $app [ 'application' ] == 'extensions' ) {
2023-10-19 05:26:25 +02:00
if ( $this -> billsec == 0 ) {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'missed' ;
2023-10-18 00:21:17 +02:00
}
else {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'answered' ;
2023-10-18 00:21:17 +02:00
}
}
2023-10-22 04:57:11 +02:00
//ivr menus
if ( $app [ 'application' ] == 'ivr_menus' ) {
$app [ 'status' ] = 'routed' ;
}
2023-10-18 00:21:17 +02:00
//outbound routes
if ( $this -> call_direction == 'outbound' ) {
2023-10-24 00:13:07 +02:00
if ( empty ( $app [ 'application' ])) {
$app [ 'application' ] = 'dialplans' ;
$app [ 'uuid' ] = '' ;
$app [ 'status' ] = '' ;
$app [ 'name' ] = 'Outbound' ;
$app [ 'label' ] = 'Outbound' ;
}
2023-10-18 00:21:17 +02:00
}
//ring groups
if ( $app [ 'application' ] == 'ring_groups' ) {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'waited' ;
2023-10-18 00:21:17 +02:00
}
//time conditions
if ( $app [ 'application' ] == 'time_conditions' ) {
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'routed' ;
2023-10-18 00:21:17 +02:00
}
//valet park
2023-12-10 07:07:36 +01:00
if ( ! empty ( $row [ " caller_profile " ][ " destination_number " ])
2023-10-21 06:16:48 +02:00
and ( substr ( $row [ " caller_profile " ][ " destination_number " ], 0 , 4 ) == 'park'
2023-12-10 07:07:36 +01:00
or ( substr ( $row [ " caller_profile " ][ " destination_number " ], 0 , 3 ) == '*59'
2023-10-21 06:16:48 +02:00
and strlen ( $row [ " caller_profile " ][ " destination_number " ]) == 5 ))) {
2023-10-20 03:49:51 +02:00
//add items to the app array
2023-10-18 00:21:17 +02:00
$app [ 'application' ] = 'dialplans' ;
$app [ 'uuid' ] = '46ae6d82-bb83-46a3-901d-33d0724347dd' ;
$app [ 'name' ] = 'Park' ;
$app [ 'label' ] = 'Park' ;
2023-10-20 03:49:51 +02:00
//set the call park status
if ( strpos ( $row [ " caller_profile " ][ " transfer_source " ], 'park+' ) !== false ) {
//$app['status'] = 'In';
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'parked' ;
2023-10-21 06:16:48 +02:00
//skip the next row
$skip_row = true ;
2023-10-20 03:49:51 +02:00
}
else {
//$app['status'] = 'Out';
2023-10-21 21:26:26 +02:00
$app [ 'status' ] = 'unparked' ;
2023-10-20 03:49:51 +02:00
}
}
//conference
if ( $app [ 'application' ] == 'conferences' ) {
2023-10-25 19:23:38 +02:00
$skip_row = true ;
2023-10-18 00:21:17 +02:00
}
//voicemails
if ( $app [ 'application' ] == 'voicemails' ) {
2024-02-06 23:24:46 +01:00
$app [ 'status' ] = 'voicemail' ;
2023-10-18 00:21:17 +02:00
}
2023-10-21 06:16:48 +02:00
//debug - add the callee_id_number to the end of the status
2023-12-10 07:07:36 +01:00
if ( isset ( $_REQUEST [ 'debug' ]) && $_REQUEST [ 'debug' ] == 'true' && ! empty ( $row [ " caller_profile " ][ " destination_number " ])
2023-10-21 06:16:48 +02:00
and ! empty ( $row [ " caller_profile " ][ " callee_id_number " ])
and $row [ " caller_profile " ][ " destination_number " ] !== $row [ " caller_profile " ][ " callee_id_number " ]) {
$app [ 'status' ] .= ' (' . $row [ " caller_profile " ][ " callee_id_number " ] . ')' ;
}
2023-10-18 00:21:17 +02:00
//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 ;
2023-10-23 23:15:58 +02:00
$text2 = $language2 -> get ( $this -> setting -> get ( 'domain' , 'language' ), 'app/' . $app [ 'application' ]);
2023-10-18 00:21:17 +02:00
$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;
//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 );
//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_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 );
2023-10-25 19:13:20 +02:00
$call_flow_summary [ $x ][ " duration_seconds " ] = $profile_end_epoch - $profile_created_epoch ;
$call_flow_summary [ $x ][ " duration_formatted " ] = gmdate ( " G:i:s " ,( int ) $call_flow_summary [ $x ][ " duration_seconds " ]);
2023-10-18 00:21:17 +02:00
unset ( $app );
$x ++ ;
}
}
unset ( $x );
//return the call flow summary array
return $call_flow_summary ;
}
2023-10-23 23:15:58 +02:00
//add a function to return the find_app
public 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' ] = $this -> 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
2023-12-10 07:07:36 +01:00
or $value [ 'destination_number' ] == $detail_action
2023-10-23 23:15:58 +02:00
or $value [ 'destination_trunk_prefix' ] . $value [ 'destination_number' ] == $detail_action
or '+' . $value [ 'destination_prefix' ] . $value [ 'destination_area_code' ] . $value [ 'destination_number' ] == $detail_action
or $value [ 'destination_prefix' ] . $value [ 'destination_area_code' ] . $value [ 'destination_number' ] == $detail_action
or $value [ 'destination_area_code' ] . $value [ 'destination_number' ] == $detail_action ) {
if ( file_exists ( $_SERVER [ " PROJECT_ROOT " ] . " /app/ " . $application . " /app_languages.php " )) {
$value [ 'application' ] = $application ;
return $value ;
}
}
}
//find all other matching actions
2023-10-25 18:41:03 +02:00
if ( ! empty ( $value [ 'extension' ]) && $value [ 'extension' ] == $detail_action or preg_match ( '/^' . preg_quote ( $value [ 'extension' ]) . '$/' , $detail_action )) {
2023-10-23 23:15:58 +02:00
if ( file_exists ( $_SERVER [ " PROJECT_ROOT " ] . " /app/ " . $application . " /app_languages.php " )) {
$value [ 'application' ] = $application ;
return $value ;
}
}
}
}
}
}
}
2017-06-13 07:09:36 +02:00
/**
* get xml from the filesystem and save it to the database
*/
public function read_files () {
2023-09-18 22:59:21 +02:00
$xml_cdr_dir = $this -> setting -> get ( 'switch' , 'log' ) . '/xml_cdr' ;
2017-06-13 07:09:36 +02:00
$dir_handle = opendir ( $xml_cdr_dir );
$x = 0 ;
while ( $file = readdir ( $dir_handle )) {
if ( $file != '.' && $file != '..' ) {
2023-06-30 01:25:20 +02:00
//used to test a single file
//$file = 'a_aa76e0af-461e-4d46-be23-433260307ede.cdr.xml';
//process the XML files
2017-06-13 07:09:36 +02:00
if ( ! is_dir ( $xml_cdr_dir . '/' . $file ) ) {
//get the leg of the call and the file prefix
if ( substr ( $file , 0 , 2 ) == " a_ " ) {
$leg = " a " ;
$file_prefix = substr ( $file , 2 , 1 );
}
else {
$leg = " b " ;
$file_prefix = substr ( $file , 0 , 1 );
}
//set the limit
if ( isset ( $_SERVER [ " argv " ][ 1 ]) && is_numeric ( $_SERVER [ " argv " ][ 1 ])) {
$limit = $_SERVER [ " argv " ][ 1 ];
}
else {
$limit = 1 ;
}
//filter for specific files based on the file prefix
if ( isset ( $_SERVER [ " argv " ][ 2 ])) {
if ( strpos ( $_SERVER [ " argv " ][ 2 ], $file_prefix ) !== FALSE ) {
$import = true ;
}
else {
$import = false ;
}
}
else {
$import = true ;
}
2020-04-29 00:11:06 +02:00
//import the call detail files are less than 3 mb - 3 million bytes
2023-06-30 01:25:20 +02:00
if ( $import && filesize ( $xml_cdr_dir . '/' . $file ) <= 3000000 ) {
2017-06-13 07:09:36 +02:00
//get the xml cdr string
2023-10-16 17:55:20 +02:00
$call_details = file_get_contents ( $xml_cdr_dir . '/' . $file );
2017-06-13 07:09:36 +02:00
2023-05-19 01:44:36 +02:00
//set the file
$this -> file = $file ;
2020-04-07 00:11:31 +02:00
//decode the xml string
2023-10-16 17:55:20 +02:00
if ( substr ( $call_details , 0 , 1 ) == '%' ) {
$call_details = urldecode ( $call_details );
}
2020-04-07 00:11:31 +02:00
2017-06-13 07:09:36 +02:00
//parse the xml and insert the data into the db
2023-10-16 17:55:20 +02:00
$this -> xml_array ( $x , $leg , $call_details );
2017-06-13 07:09:36 +02:00
2020-04-29 00:11:06 +02:00
//increment the value
$x ++ ;
2017-06-13 07:09:36 +02:00
}
2023-06-30 01:25:20 +02:00
//move the files that are too large to the failed directory
if ( $import && filesize ( $xml_cdr_dir . '/' . $file ) >= 3000000 ) {
if ( ! empty ( $xml_cdr_dir )) {
if ( ! file_exists ( $xml_cdr_dir . '/failed' )) {
if ( ! mkdir ( $xml_cdr_dir . '/failed' , 0660 , true )) {
die ( 'Failed to create ' . $xml_cdr_dir . '/failed' );
}
}
rename ( $xml_cdr_dir . '/' . $file , $xml_cdr_dir . '/failed/' . $file );
}
}
2017-06-13 07:09:36 +02:00
//if limit exceeded exit the loop
if ( $limit == $x ) {
//echo "limit: $limit count: $x if\n";
break ;
}
}
}
}
2023-06-30 01:25:20 +02:00
//close the directory handle
2017-06-13 07:09:36 +02:00
closedir ( $dir_handle );
}
//$this->read_files();
/**
* read the call detail records from the http post
*/
public function post () {
if ( isset ( $_POST [ " cdr " ])) {
2021-05-26 22:29:46 +02:00
2017-06-13 07:09:36 +02:00
//debug method
2021-05-26 22:29:46 +02:00
//$this->log($_POST["cdr"]);
2017-06-13 07:09:36 +02:00
//authentication for xml cdr http post
if ( ! defined ( 'STDIN' )) {
2023-09-25 20:55:20 +02:00
if ( $this -> setting -> get ( 'cdr' , 'http_enabled' ) == " true " ) {
2017-06-13 07:09:36 +02:00
//get the contents of xml_cdr.conf.xml
2023-09-18 22:59:21 +02:00
$conf_xml_string = file_get_contents ( $this -> setting -> get ( 'switch' , 'conf' ) . '/autoload_configs/xml_cdr.conf.xml' );
2017-06-13 07:09:36 +02:00
//parse the xml to get the call detail record info
try {
2019-12-23 19:20:43 +01:00
//disable xml entities
libxml_disable_entity_loader ( true );
//load the string into an xml object
$conf_xml = simplexml_load_string ( $conf_xml_string , 'SimpleXMLElement' , LIBXML_NOCDATA );
2017-06-13 07:09:36 +02:00
}
catch ( Exception $e ) {
echo $e -> getMessage ();
}
2023-09-25 20:55:20 +02:00
if ( isset ( $conf_xml -> settings -> param )) {
foreach ( $conf_xml -> settings -> param as $row ) {
if ( $row -> attributes () -> name == " cred " ) {
$auth_array = explode ( " : " , $row -> attributes () -> value );
//echo "username: ".$auth_array[0]."<br />\n";
//echo "password: ".$auth_array[1]."<br />\n";
}
if ( $row -> attributes () -> name == " url " ) {
//check name is equal to url
}
2017-06-13 07:09:36 +02:00
}
}
}
}
//if http enabled is set to false then deny access
if ( ! defined ( 'STDIN' )) {
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'cdr' , 'http_enabled' ) == " false " ) {
2023-09-25 20:55:20 +02:00
openlog ( 'FusionPBX' , LOG_NDELAY , LOG_AUTH );
syslog ( LOG_WARNING , '[' . $_SERVER [ 'REMOTE_ADDR' ] . '] XML CDR import default setting http_enabled is not enabled. Line: ' . __line__ );
closelog ();
echo " access denied \n " ;
2017-06-13 07:09:36 +02:00
return ;
}
}
//check for the correct username and password
if ( ! defined ( 'STDIN' )) {
2023-09-18 22:59:21 +02:00
if ( $this -> setting -> get ( 'cdr' , 'http_enabled' ) == " true " ) {
2017-06-13 07:09:36 +02:00
if ( $auth_array [ 0 ] == $_SERVER [ " PHP_AUTH_USER " ] && $auth_array [ 1 ] == $_SERVER [ " PHP_AUTH_PW " ]) {
2023-09-25 20:55:20 +02:00
//echo "access granted\n";
2023-09-18 22:59:21 +02:00
$this -> username = $auth_array [ 0 ];
$this -> password = $auth_array [ 1 ];
2017-06-13 07:09:36 +02:00
}
else {
2023-09-25 20:55:20 +02:00
openlog ( 'FusionPBX' , LOG_NDELAY , LOG_AUTH );
syslog ( LOG_WARNING , '[' . $_SERVER [ 'REMOTE_ADDR' ] . '] XML CDR import username or password failed. Line: ' . __line__ );
closelog ();
echo " access denied \n " ;
2017-06-13 07:09:36 +02:00
return ;
}
}
}
//loop through all attribues
//foreach($xml->settings->param[1]->attributes() as $a => $b) {
2023-09-25 20:55:20 +02:00
// echo $a,'="',$b,"\"\n";
2017-06-13 07:09:36 +02:00
//}
//get the http post variable
$xml_string = trim ( $_POST [ " cdr " ]);
//get the leg of the call
if ( substr ( $_REQUEST [ 'uuid' ], 0 , 2 ) == " a_ " ) {
$leg = " a " ;
}
else {
$leg = " b " ;
}
//log the xml cdr
2021-05-26 22:29:46 +02:00
$this -> log ( " HTTP POST \n " );
2017-06-13 07:09:36 +02:00
//parse the xml and insert the data into the database
$this -> xml_array ( 0 , $leg , $xml_string );
}
}
//$this->post();
/**
* user summary returns an array
*/
public function user_summary () {
2021-05-10 19:34:47 +02:00
//set the time zone
2023-09-18 22:59:21 +02:00
if ( ! empty ( $this -> setting -> get ( 'domain' , 'time_zone' ))) {
$time_zone = $this -> setting -> get ( 'domain' , 'time_zone' );
2021-05-10 19:34:47 +02:00
}
else {
$time_zone = date_default_timezone_get ();
}
2017-06-13 07:09:36 +02:00
//build the date range
2023-05-29 20:30:07 +02:00
if (( ! empty ( $this -> start_stamp_begin ) && strlen ( $this -> start_stamp_begin ) > 0 ) || ! empty ( $this -> start_stamp_end )) {
2017-06-13 07:09:36 +02:00
unset ( $this -> quick_select );
2023-05-05 18:46:37 +02:00
if ( strlen ( $this -> start_stamp_begin ) > 0 && ! empty ( $this -> start_stamp_end )) {
2021-05-10 19:34:47 +02:00
$sql_date_range = " and start_stamp between :start_stamp_begin::timestamptz and :start_stamp_end::timestamptz \n " ;
$parameters [ 'start_stamp_begin' ] = $this -> start_stamp_begin . ':00.000 ' . $time_zone ;
$parameters [ 'start_stamp_end' ] = $this -> start_stamp_end . ':59.999 ' . $time_zone ;
2017-06-13 07:09:36 +02:00
}
else {
2023-05-05 18:46:37 +02:00
if ( ! empty ( $this -> start_stamp_begin )) {
2023-02-21 18:38:25 +01:00
$sql_date_range = " and start_stamp >= :start_stamp_begin::timestamptz \n " ;
2021-05-10 19:34:47 +02:00
$parameters [ 'start_stamp_begin' ] = $this -> start_stamp_begin . ':00.000 ' . $time_zone ;
2020-07-16 17:54:10 +02:00
}
2023-05-05 18:46:37 +02:00
if ( ! empty ( $this -> start_stamp_end )) {
2023-02-21 18:38:25 +01:00
$sql_date_range .= " and start_stamp <= :start_stamp_end::timestamptz \n " ;
2021-05-10 19:34:47 +02:00
$parameters [ 'start_stamp_end' ] = $this -> start_stamp_end . ':59.999 ' . $time_zone ;
2020-07-16 17:54:10 +02:00
}
2017-06-13 07:09:36 +02:00
}
}
else {
switch ( $this -> quick_select ) {
2021-05-10 19:34:47 +02:00
case 1 : $sql_date_range = " and start_stamp >= ' " . date ( 'Y-m-d H:i:s.000' , strtotime ( " -1 week " )) . " " . $time_zone . " '::timestamptz \n " ; break ; //last 7 days
case 2 : $sql_date_range = " and start_stamp >= ' " . date ( 'Y-m-d H:i:s.000' , strtotime ( " -1 hour " )) . " " . $time_zone . " '::timestamptz \n " ; break ; //last hour
case 3 : $sql_date_range = " and start_stamp >= ' " . date ( 'Y-m-d' ) . " " . " 00:00:00.000 " . $time_zone . " '::timestamptz \n " ; break ; //today
case 4 : $sql_date_range = " and start_stamp between ' " . date ( 'Y-m-d' , strtotime ( " -1 day " )) . " " . " 00:00:00.000 " . $time_zone . " '::timestamptz and ' " . date ( 'Y-m-d' , strtotime ( " -1 day " )) . " " . " 23:59:59.999 " . $time_zone . " '::timestamptz \n " ; break ; //yesterday
case 5 : $sql_date_range = " and start_stamp >= ' " . date ( 'Y-m-d' , strtotime ( " this week " )) . " " . " 00:00:00.000 " . $time_zone . " ' \n " ; break ; //this week
case 6 : $sql_date_range = " and start_stamp >= ' " . date ( 'Y-m-' ) . " 01 " . " 00:00:00.000 " . $time_zone . " '::timestamptz \n " ; break ; //this month
case 7 : $sql_date_range = " and start_stamp >= ' " . date ( 'Y-' ) . " 01-01 " . " 00:00:00.000 " . $time_zone . " '::timestamptz \n " ; break ; //this year
2017-06-13 07:09:36 +02:00
}
}
//calculate the summary data
2019-09-12 01:12:01 +02:00
$sql = " select \n " ;
2017-06-13 07:09:36 +02:00
$sql .= " e.domain_uuid, \n " ;
$sql .= " d.domain_name, \n " ;
$sql .= " e.extension, \n " ;
$sql .= " e.number_alias, \n " ;
2022-05-05 18:43:44 +02:00
//answered
2019-09-12 01:12:01 +02:00
$sql .= " count(*) \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " filter ( \n " ;
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
2022-08-05 21:46:26 +02:00
$sql .= " and missed_call = false \n " ;
2022-05-05 18:55:52 +02:00
if ( ! permission_exists ( 'xml_cdr_enterprise_leg' )) {
$sql .= " and originating_leg_uuid is null \n " ;
}
elseif ( ! permission_exists ( 'xml_cdr_lose_race' )) {
$sql .= " and hangup_cause <> 'LOSE_RACE' \n " ;
}
2022-05-05 18:43:44 +02:00
$sql .= " and (cc_side IS NULL or cc_side !='agent') " ;
2017-06-13 07:09:36 +02:00
if ( $this -> include_internal ) {
2019-10-07 23:28:05 +02:00
$sql .= " and (direction = 'inbound' or direction = 'local') \n " ;
2017-06-13 07:09:36 +02:00
}
else {
2019-10-07 23:28:05 +02:00
$sql .= " and direction = 'inbound' \n " ;
2017-06-13 07:09:36 +02:00
}
2019-10-07 23:28:05 +02:00
$sql .= " ) \n " ;
2019-09-16 12:13:03 +02:00
$sql .= " as answered, \n " ;
2017-06-13 07:09:36 +02:00
2022-05-05 18:43:44 +02:00
//missed
2019-09-12 01:12:01 +02:00
$sql .= " count(*) \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " filter ( \n " ;
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
2022-08-05 19:18:40 +02:00
$sql .= " and missed_call = true \n " ;
2022-08-05 21:46:26 +02:00
$sql .= " and (cc_side is null or cc_side != 'agent') \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " ) \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " as missed, \n " ;
2017-06-13 07:09:36 +02:00
2022-05-05 18:43:44 +02:00
//cc missed
2019-09-12 01:12:01 +02:00
$sql .= " count(*) \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " filter ( \n " ;
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " and c.hangup_cause = 'NO_ANSWER' \n " ;
2022-05-05 18:43:44 +02:00
$sql .= " and (cc_side IS NOT NULL or cc_side ='agent') " ;
2017-06-13 07:09:36 +02:00
if ( $this -> include_internal ) {
2019-09-12 01:12:01 +02:00
$sql .= " and (direction = 'inbound' or direction = 'local') \n " ;
2017-06-13 07:09:36 +02:00
}
2023-02-21 18:38:25 +01:00
else {
2019-09-12 01:12:01 +02:00
$sql .= " and direction = 'inbound' \n " ;
2017-06-13 07:09:36 +02:00
}
2019-10-07 23:28:05 +02:00
$sql .= " ) \n " ;
$sql .= " as no_answer, \n " ;
2017-06-13 07:09:36 +02:00
2022-05-05 18:43:44 +02:00
//busy
2019-09-12 01:12:01 +02:00
$sql .= " count(*) \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " filter ( \n " ;
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
$sql .= " and c.hangup_cause = 'USER_BUSY' \n " ;
2017-06-13 07:09:36 +02:00
if ( $this -> include_internal ) {
2019-10-07 23:28:05 +02:00
$sql .= " and (direction = 'inbound' or direction = 'local') \n " ;
2017-06-13 07:09:36 +02:00
}
else {
2019-10-07 23:28:05 +02:00
$sql .= " and direction = 'inbound' \n " ;
2017-06-13 07:09:36 +02:00
}
2019-10-07 23:28:05 +02:00
$sql .= " ) \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " as busy, \n " ;
2017-06-13 07:09:36 +02:00
2022-05-05 18:43:44 +02:00
//aloc
2019-09-12 01:12:01 +02:00
$sql .= " sum(c.billsec) \n " ;
$sql .= " filter ( \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
if ( ! $this -> include_internal ) {
2019-09-12 01:12:01 +02:00
$sql .= " and (direction = 'inbound' or direction = 'outbound') \n " ;
2017-06-13 07:09:36 +02:00
}
$sql .= " ) / \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " count(*) \n " ;
$sql .= " filter ( \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
if ( ! $this -> include_internal ) {
2019-09-12 01:12:01 +02:00
$sql .= " and (direction = 'inbound' or direction = 'outbound') \n " ;
2017-06-13 07:09:36 +02:00
}
2019-10-07 23:28:05 +02:00
$sql .= " ) \n " ;
$sql .= " as aloc, \n " ;
2017-06-13 07:09:36 +02:00
2022-05-05 18:43:44 +02:00
//inbound calls
2019-09-12 01:12:01 +02:00
$sql .= " count(*) \n " ;
$sql .= " filter ( \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
2022-05-05 18:55:52 +02:00
if ( ! permission_exists ( 'xml_cdr_enterprise_leg' )) {
$sql .= " and originating_leg_uuid is null \n " ;
}
elseif ( ! permission_exists ( 'xml_cdr_lose_race' )) {
$sql .= " and hangup_cause <> 'LOSE_RACE' \n " ;
}
2022-05-05 18:43:44 +02:00
$sql .= " and (cc_side is null or cc_side != 'agent') \n " ;
2017-06-13 07:09:36 +02:00
if ( $this -> include_internal ) {
2019-10-07 23:28:05 +02:00
$sql .= " and (direction = 'inbound' or direction = 'local') \n " ;
2017-06-13 07:09:36 +02:00
}
else {
2019-10-07 23:28:05 +02:00
$sql .= " and direction = 'inbound' \n " ;
2017-06-13 07:09:36 +02:00
}
2019-10-07 23:28:05 +02:00
$sql .= " ) \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " as inbound_calls, \n " ;
2017-06-13 07:09:36 +02:00
2022-05-05 18:43:44 +02:00
//inbound duration
2019-09-12 01:12:01 +02:00
$sql .= " sum(c.billsec) \n " ;
$sql .= " filter ( \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
2017-06-13 07:09:36 +02:00
if ( $this -> include_internal ) {
2019-09-12 01:12:01 +02:00
$sql .= " and (direction = 'inbound' or direction = 'local')) \n " ;
2017-06-13 07:09:36 +02:00
}
else {
2019-09-12 01:12:01 +02:00
$sql .= " and direction = 'inbound') \n " ;
2017-06-13 07:09:36 +02:00
}
2019-09-12 01:12:01 +02:00
$sql .= " as inbound_duration, \n " ;
2017-06-13 07:09:36 +02:00
2022-05-05 18:43:44 +02:00
//outbound duration
2019-09-12 01:12:01 +02:00
$sql .= " count(*) \n " ;
$sql .= " filter ( \n " ;
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
$sql .= " and c.direction = 'outbound' \n " ;
2018-11-22 00:07:02 +01:00
$sql .= " ) \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " as outbound_calls, \n " ;
2017-06-13 07:09:36 +02:00
2019-09-12 01:12:01 +02:00
$sql .= " sum(c.billsec) \n " ;
$sql .= " filter ( \n " ;
$sql .= " where c.extension_uuid = e.extension_uuid \n " ;
$sql .= " and c.direction = 'outbound' \n " ;
2018-11-23 16:03:36 +01:00
$sql .= " ) \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " as outbound_duration, \n " ;
2017-06-13 07:09:36 +02:00
$sql .= " e.description \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " from v_extensions as e, v_domains as d, \n " ;
2019-09-16 12:13:03 +02:00
$sql .= " ( select \n " ;
2017-06-13 07:09:36 +02:00
$sql .= " domain_uuid, \n " ;
2018-11-22 00:07:02 +01:00
$sql .= " extension_uuid, \n " ;
2017-06-13 07:09:36 +02:00
$sql .= " caller_id_number, \n " ;
$sql .= " destination_number, \n " ;
2019-10-07 23:28:05 +02:00
$sql .= " missed_call, \n " ;
2017-06-13 07:09:36 +02:00
$sql .= " answer_stamp, \n " ;
$sql .= " bridge_uuid, \n " ;
$sql .= " direction, \n " ;
$sql .= " start_stamp, \n " ;
$sql .= " hangup_cause, \n " ;
2021-02-22 04:09:37 +01:00
$sql .= " originating_leg_uuid, \n " ;
2022-05-05 18:43:44 +02:00
$sql .= " billsec, \n " ;
$sql .= " cc_side, \n " ;
$sql .= " sip_hangup_disposition, \n " ;
$sql .= " voicemail_message \n " ;
2019-09-12 01:12:01 +02:00
$sql .= " from v_xml_cdr \n " ;
2023-05-29 20:30:07 +02:00
if ( ! ( ! empty ( $_GET [ 'show' ]) && $_GET [ 'show' ] === 'all' && permission_exists ( 'xml_cdr_extension_summary_all' ))) {
2020-02-02 20:50:34 +01:00
$sql .= " where domain_uuid = :domain_uuid \n " ;
}
else {
$sql .= " where true \n " ;
}
2017-06-13 07:09:36 +02:00
$sql .= $sql_date_range ;
2019-09-12 01:12:01 +02:00
$sql .= " ) as c \n " ;
2017-06-13 07:09:36 +02:00
2019-09-12 01:12:01 +02:00
$sql .= " where \n " ;
2017-06-13 07:09:36 +02:00
$sql .= " d.domain_uuid = e.domain_uuid \n " ;
2023-05-29 20:30:07 +02:00
if ( ! ( ! empty ( $_GET [ 'show' ]) && $_GET [ 'show' ] === 'all' && permission_exists ( 'xml_cdr_extension_summary_all' ))) {
2019-09-12 01:12:01 +02:00
$sql .= " and e.domain_uuid = :domain_uuid \n " ;
2017-06-13 07:09:36 +02:00
}
2019-09-12 01:12:01 +02:00
$sql .= " group by e.extension, e.domain_uuid, d.domain_uuid, e.number_alias, e.description \n " ;
$sql .= " order by extension asc \n " ;
2023-05-29 20:30:07 +02:00
if ( ! ( ! empty ( $_GET [ 'show' ]) && $_GET [ 'show' ] === 'all' && permission_exists ( 'xml_cdr_extension_summary_all' ))) {
2020-02-02 20:50:34 +01:00
$parameters [ 'domain_uuid' ] = $this -> domain_uuid ;
}
2019-09-04 07:25:58 +02:00
$database = new database ;
$summary = $database -> select ( $sql , $parameters , 'all' );
unset ( $parameters );
2017-06-13 07:09:36 +02:00
//return the array
return $summary ;
}
2017-10-15 22:26:06 +02:00
/**
* download the recordings
*/
2019-09-06 19:04:17 +02:00
public function download ( $uuid ) {
2023-03-30 01:46:51 +02:00
if ( ! permission_exists ( 'xml_cdr_view' )) {
echo " permission denied " ;
return ;
}
2017-10-15 22:26:06 +02:00
2023-03-30 01:46:51 +02:00
//get call recording from database
if ( ! is_uuid ( $uuid )) {
echo " invalid uuid " ;
return ;
}
2017-10-15 22:26:06 +02:00
2023-03-30 01:46:51 +02:00
$sql = " select record_name, record_path from v_xml_cdr " ;
$sql .= " where xml_cdr_uuid = :xml_cdr_uuid " ;
//$sql .= "and domain_uuid = '".$domain_uuid."' \n";
$parameters [ 'xml_cdr_uuid' ] = $uuid ;
//$parameters['domain_uuid'] = $domain_uuid;
$database = new database ;
$row = $database -> select ( $sql , $parameters , 'row' );
2023-06-02 00:55:19 +02:00
if ( ! empty ( $row ) && is_array ( $row )) {
2023-03-30 01:46:51 +02:00
$record_name = $row [ 'record_name' ];
$record_path = $row [ 'record_path' ];
} else {
echo " recording not found " ;
return ;
2017-10-15 22:26:06 +02:00
}
2023-03-30 01:46:51 +02:00
unset ( $sql , $parameters , $row );
//build full path
$record_file = $record_path . '/' . $record_name ;
//download the file
2023-06-02 00:55:19 +02:00
if ( ! file_exists ( $record_file ) || $record_file == '/' ) {
2023-03-30 01:46:51 +02:00
echo " recording not found " ;
return ;
}
2023-06-06 18:29:09 +02:00
ob_clean ();
2023-03-30 01:46:51 +02:00
$fd = fopen ( $record_file , " rb " );
if ( $_GET [ 't' ] == " bin " ) {
header ( " Content-Type: application/force-download " );
header ( " Content-Type: application/octet-stream " );
header ( " Content-Type: application/download " );
header ( " Content-Description: File Transfer " );
2023-06-02 00:55:19 +02:00
}
else {
2023-03-30 01:46:51 +02:00
$file_ext = pathinfo ( $record_name , PATHINFO_EXTENSION );
switch ( $file_ext ) {
case " wav " : header ( " Content-Type: audio/x-wav " ); break ;
case " mp3 " : header ( " Content-Type: audio/mpeg " ); break ;
case " ogg " : header ( " Content-Type: audio/ogg " ); break ;
}
}
$record_name = preg_replace ( '#[^a-zA-Z0-9_\-\.]#' , '' , $record_name );
header ( 'Content-Disposition: attachment; filename="' . $record_name . '"' );
header ( " Cache-Control: no-cache, must-revalidate " ); // HTTP/1.1
header ( " Expires: Sat, 26 Jul 1997 05:00:00 GMT " ); // Date in the past
if ( $_GET [ 't' ] == " bin " ) {
header ( " Content-Length: " . filesize ( $record_file ));
}
2023-06-06 18:29:09 +02:00
ob_clean ();
2023-06-02 00:55:19 +02:00
2023-06-06 18:29:09 +02:00
//content-range
if ( isset ( $_SERVER [ 'HTTP_RANGE' ]) && $_GET [ 't' ] != " bin " ) {
2023-06-02 00:55:19 +02:00
$this -> range_download ( $record_file );
}
2023-03-30 01:46:51 +02:00
2023-06-06 18:29:09 +02:00
fpassthru ( $fd );
2017-10-15 22:26:06 +02:00
} //end download method
2020-03-31 04:08:45 +02:00
/*
* range download method ( helps safari play audio sources )
*/
private function range_download ( $file ) {
$fp = @ fopen ( $file , 'rb' );
$size = filesize ( $file ); // File size
$length = $size ; // Content length
$start = 0 ; // Start byte
$end = $size - 1 ; // End byte
// Now that we've gotten so far without errors we send the accept range header
/* At the moment we only support single ranges .
* Multiple ranges requires some more work to ensure it works correctly
* and comply with the spesifications : http :// www . w3 . org / Protocols / rfc2616 / rfc2616 - sec19 . html #sec19.2
*
* Multirange support annouces itself with :
* header ( 'Accept-Ranges: bytes' );
*
* Multirange content must be sent with multipart / byteranges mediatype ,
* ( mediatype = mimetype )
* as well as a boundry header to indicate the various chunks of data .
*/
header ( " Accept-Ranges: 0- $length " );
// header('Accept-Ranges: bytes');
// multipart/byteranges
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
if ( isset ( $_SERVER [ 'HTTP_RANGE' ])) {
$c_start = $start ;
$c_end = $end ;
// Extract the range string
list (, $range ) = explode ( '=' , $_SERVER [ 'HTTP_RANGE' ], 2 );
// Make sure the client hasn't sent us a multibyte range
if ( strpos ( $range , ',' ) !== false ) {
// (?) Shoud this be issued here, or should the first
// range be used? Or should the header be ignored and
// we output the whole content?
header ( 'HTTP/1.1 416 Requested Range Not Satisfiable' );
header ( " Content-Range: bytes $start - $end / $size " );
// (?) Echo some info to the client?
exit ;
}
// If the range starts with an '-' we start from the beginning
// If not, we forward the file pointer
// And make sure to get the end byte if spesified
Improved Missed Call accuracy, cdr statistics, and hide duplicated CDRs from Enterprise Ring Groups
Changes
--------
- Improve CDR Import Logic so that missed_call column is more accurate to the "missed" status. It would previously mark unanswered outbound calls as "missed". These are their own category of call.
- Don't mark the CDRs of the "legs" of an Enterprise Ring Group call as missed, only the originating_leg will be marked (one missed call per call) - We could also just "skip" importing these call legs. Simultaneous ring groups don't have these duplicated CDRs for every ringing phone. The "Skip" approach might make most of the rest of this work irrelevant.
- Create `originating_leg_uuid` column in v_xml_cdr and import it into the database during CDR imports so it is available for filtering Enterprise Ring Group calls out of CDRs and reports.
- Move logic that hides the agent leg of CC calls, LOSE_RACE calls, and the Enterprise Leg hiding code from xml_cdr.php into xml_cdr_inc.php into the SQL query WHERE clause so the CDR page looks more consistent. The logic is the same, but these calls are now excluded from the query result entirely instead of having to "skip" rendering them in the list on the xml_cdr.php page.
- Improved CDR statistics page to use the missed_call variable instead of relying upon billsec and answer_stamp/answer_epoch. Added the same logic as the xml_cdr pages to the query so it excludes enterprise ring group call legs.
- Laid the query groundwork in xml_cdr_statistics to report on Average TTA (No UI changes yet to include that statistic)
Retroactive Changes
---------------------
There are a few changes going back in time to bring everything in line with this better reporting accuracy:
- If you want the populated the `originating_leg_uuid column` in `v_xml_cdr`, it will rely upon having the `json` column and not having deleted the data from it like I know some people do for space saving.
- If you don't have the json column, you are mostly out of luck for hiding the duplicate legs of Enterprise ring group calls. It might be possible, but it isn't going to be easy.
- On Newer Versions of postgres, this works:
```
UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid WHERE json->'variables'->>'originating_leg_uuid' IS NOT NULL;
```
- For some reason on postgres 9.4, I had to UPDATE every single record because I couldn't get it to allow the json syntax properly after the WHERE. This is fine, it doesn't change the end result it just means it has to run the UPDATE on every record, which will take a while
```
UPDATE v_xml_cdr SET originating_leg_uuid = (json->'variables'->>'originating_leg_uuid')::uuid;
```
- To remove the `missed_call = true` on all your previous outbound records so that they don't show up when you filter on missed (outbound unanswered calls can be accurately listed with TTA max 0 and direction outbound)
```
UPDATE v_xml_cdr SET missed_call = false WHERE direction = 'outbound' AND missed_call = true;
```
2021-02-18 14:51:48 +01:00
if ( $range == '-' ) {
2020-03-31 04:08:45 +02:00
// The n-number of the last bytes is requested
$c_start = $size - substr ( $range , 1 );
}
else {
$range = explode ( '-' , $range );
$c_start = $range [ 0 ];
$c_end = ( isset ( $range [ 1 ]) && is_numeric ( $range [ 1 ])) ? $range [ 1 ] : $size ;
}
/* Check the range and make sure it ' s treated according to the specs .
* http :// www . w3 . org / Protocols / rfc2616 / rfc2616 - sec14 . html
*/
// End bytes can not be larger than $end.
$c_end = ( $c_end > $end ) ? $end : $c_end ;
// Validate the requested range and return an error if it's not correct.
if ( $c_start > $c_end || $c_start > $size - 1 || $c_end >= $size ) {
header ( 'HTTP/1.1 416 Requested Range Not Satisfiable' );
header ( " Content-Range: bytes $start - $end / $size " );
// (?) Echo some info to the client?
exit ;
}
$start = $c_start ;
$end = $c_end ;
$length = $end - $start + 1 ; // Calculate new content length
fseek ( $fp , $start );
header ( 'HTTP/1.1 206 Partial Content' );
}
// Notify the client the byte range we'll be outputting
header ( " Content-Range: bytes $start - $end / $size " );
header ( " Content-Length: $length " );
// Start buffered download
$buffer = 1024 * 8 ;
while ( ! feof ( $fp ) && ( $p = ftell ( $fp )) <= $end ) {
if ( $p + $buffer > $end ) {
// In case we're only outputtin a chunk, make sure we don't
// read past the length
$buffer = $end - $p + 1 ;
}
set_time_limit ( 0 ); // Reset time limit for big files
echo fread ( $fp , $buffer );
flush (); // Free up memory. Otherwise large files will trigger PHP's memory limit.
}
fclose ( $fp );
}
2019-10-22 09:43:55 +02:00
/**
* delete records
*/
public function delete ( $records ) {
2023-06-02 00:55:19 +02:00
if ( ! permission_exists ( $this -> permission_prefix . 'delete' )) {
2023-02-22 03:44:41 +01:00
return false ;
}
2019-10-22 09:43:55 +02:00
2023-02-21 18:38:25 +01:00
//add multi-lingual support
$language = new text ;
$text = $language -> get ();
2019-10-22 09:43:55 +02:00
2023-02-21 18:38:25 +01:00
//validate the token
$token = new token ;
if ( ! $token -> validate ( $_SERVER [ 'PHP_SELF' ])) {
message :: add ( $text [ 'message-invalid_token' ], 'negative' );
header ( 'Location: ' . $this -> list_page );
exit ;
}
2019-10-22 09:43:55 +02:00
2023-02-21 18:38:25 +01:00
//delete multiple records
if ( ! is_array ( $records ) || @ sizeof ( $records ) == 0 ) {
return ;
}
$records_deleted = 0 ;
2019-10-22 09:43:55 +02:00
2023-02-21 18:38:25 +01:00
//loop through records
foreach ( $records as $x => $record ) {
2023-06-02 00:55:19 +02:00
if ( empty ( $record [ 'checked' ]) || $record [ 'checked' ] != 'true' || ! is_uuid ( $record [ 'uuid' ])) {
2023-02-21 18:38:25 +01:00
continue ;
}
2019-10-22 09:43:55 +02:00
2023-02-21 18:38:25 +01:00
//get the call recordings
$sql = " select xml_cdr_uuid, record_name, record_path from v_xml_cdr " ;
$sql .= " where xml_cdr_uuid = :xml_cdr_uuid " ;
$sql .= " and record_name is not null " ;
$parameters [ 'xml_cdr_uuid' ] = $record [ 'uuid' ];
$database = new database ;
$row = $database -> select ( $sql , $parameters , 'row' );
unset ( $sql , $parameters );
//delete the call recording (file)
$call_recording_path = realpath ( $row [ 'record_path' ]);
$call_recording_name = $row [ 'record_name' ];
if ( file_exists ( $call_recording_path . '/' . $call_recording_name )) {
@ unlink ( $call_recording_path . '/' . $call_recording_name );
}
2019-10-22 09:43:55 +02:00
2023-02-21 18:38:25 +01:00
//build the delete array
$array [ $this -> table ][ $x ][ $this -> uuid_prefix . 'uuid' ] = $record [ 'uuid' ];
2019-10-22 09:43:55 +02:00
2023-02-21 18:38:25 +01:00
//increment counter
$records_deleted ++ ;
}
2019-10-22 09:43:55 +02:00
2023-02-21 18:38:25 +01:00
if ( ! is_array ( $array ) || @ sizeof ( $array ) == 0 ) {
return ;
2019-10-22 09:43:55 +02:00
}
2023-02-21 18:38:25 +01:00
//grant temporary permissions
$p = new permissions ;
$p -> add ( 'call_recording_delete' , 'temp' );
//execute delete
$database = new database ;
$database -> app_name = $this -> app_name ;
$database -> app_uuid = $this -> app_uuid ;
$database -> delete ( $array );
unset ( $array );
//revoke temporary permissions
$p -> delete ( 'call_recording_delete' , 'temp' );
//set message
message :: add ( $text [ 'message-delete' ] . " : " . $records_deleted );
unset ( $records );
2020-02-12 22:14:16 +01:00
} //method
2019-10-22 09:43:55 +02:00
2020-02-12 22:14:16 +01:00
} //class
2017-06-13 07:09:36 +02:00
}
2019-09-04 07:01:19 +02:00
2021-05-10 19:34:47 +02:00
?>