diff --git a/app/xml_cdr/app_config.php b/app/xml_cdr/app_config.php index 3e71280be6..0f0b1c30d4 100644 --- a/app/xml_cdr/app_config.php +++ b/app/xml_cdr/app_config.php @@ -766,6 +766,10 @@ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "pin number"; $z++; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "status"; + $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "status"; + $z++; $apps[$x]['db'][$y]['fields'][$z]['name'] = "hangup_cause"; $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index cbef26290c..cace151c22 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -199,6 +199,7 @@ if (!class_exists('xml_cdr')) { $this->fields[] = "conference_member_id"; $this->fields[] = "digits_dialed"; $this->fields[] = "pin_number"; + $this->fields[] = "status"; $this->fields[] = "hangup_cause"; $this->fields[] = "hangup_cause_q850"; $this->fields[] = "sip_hangup_disposition"; @@ -249,7 +250,6 @@ if (!class_exists('xml_cdr')) { $database->app_uuid = '4a085c51-7635-ff03-f67b-86e834422848'; //$database->domain_uuid = $domain_uuid; $response = $database->save($array, false); - if ($response['code'] == '200') { //saved to the database successfully delete the database file if (!empty($xml_cdr_dir)) { @@ -538,6 +538,47 @@ if (!class_exists('xml_cdr')) { $last_bridge = urldecode($bridge); } + //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'; + } + if ($missed_call == 'true') { + $status = 'missed'; + } + if (substr($destination_number, 0, 3) == '*99') { + $status = 'voicemail'; + } + 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'; + } + if (empty($status)) { + $status = 'none'; + } + //misc $key = 0; $uuid = urldecode($xml->variables->uuid); @@ -557,6 +598,7 @@ if (!class_exists('xml_cdr')) { //$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); + $this->array[$key]['status'] = $status; //time $start_epoch = urldecode($xml->variables->start_epoch); @@ -568,8 +610,8 @@ if (!class_exists('xml_cdr')) { $end_epoch = urldecode($xml->variables->end_epoch); $this->array[$key]['end_epoch'] = $end_epoch; $this->array[$key]['end_stamp'] = is_numeric($end_epoch) ? date('c', $end_epoch) : null; - $this->array[$key]['duration'] = urldecode($xml->variables->duration); - $this->array[$key]['mduration'] = urldecode($xml->variables->mduration); + $this->array[$key]['duration'] = urldecode($xml->variables->billsec); + $this->array[$key]['mduration'] = urldecode($xml->variables->billmsec); $this->array[$key]['billsec'] = urldecode($xml->variables->billsec); $this->array[$key]['billmsec'] = urldecode($xml->variables->billmsec); diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index 22675fa384..e0a609a9e1 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -148,7 +148,7 @@ echo " \n"; echo " \n"; echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo " \n"; echo " \n"; @@ -193,8 +193,8 @@ echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'link'=>'xml_cdr.php']); } echo button::create(['type'=>'button','label'=>$text['button-refresh'],'icon'=>'sync-alt','style'=>'margin-left: 15px;','onclick'=>'location.reload(true);']); - if (isset($_GET['call_result']) && $_GET['call_result'] != 'missed') { - echo button::create(['type'=>'button','label'=>$text['button-missed'],'icon'=>'phone-slash','link'=>'?call_result=missed']); + if (isset($_GET['status']) && $_GET['status'] != 'missed') { + echo button::create(['type'=>'button','label'=>$text['button-missed'],'icon'=>'phone-slash','link'=>'?status=missed']); } if (permission_exists('xml_cdr_export')) { @@ -264,13 +264,14 @@ echo " ".$text['label-status']."\n"; echo " \n"; echo "
\n"; - echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; echo "
\n"; echo " \n"; @@ -625,10 +626,12 @@ $theme_cdr_images_exist = ( file_exists($theme_image_path."icon_cdr_inbound_answered.png") && file_exists($theme_image_path."icon_cdr_inbound_voicemail.png") && + file_exists($theme_image_path."icon_cdr_inbound_missed.png") && file_exists($theme_image_path."icon_cdr_inbound_cancelled.png") && file_exists($theme_image_path."icon_cdr_inbound_failed.png") && file_exists($theme_image_path."icon_cdr_outbound_answered.png") && file_exists($theme_image_path."icon_cdr_outbound_cancelled.png") && + file_exists($theme_image_path."icon_cdr_outbound_busy.png") && file_exists($theme_image_path."icon_cdr_outbound_failed.png") && file_exists($theme_image_path."icon_cdr_local_answered.png") && file_exists($theme_image_path."icon_cdr_local_voicemail.png") && @@ -645,6 +648,50 @@ $x = 0; foreach ($result as $index => $row) { + //set the status + $status = $row['status']; + if (empty($row['status'])) { + //define an array of failed hangup causes + $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" + ); + + //determine the call status + if ($row['billsec'] > 0) { + $status = 'answered'; + } + if ($row['missed_call'] == '1') { + $status = 'missed'; + } + if (substr($row['destination_number'], 0, 3) == '*99') { + $status = 'voicemail'; + } + if ($row['hangup_cause'] == 'ORIGINATOR_CANCEL') { + $status = 'cancelled'; + } + if ($row['hangup_cause'] == 'USER_BUSY') { + $status = 'busy'; + } + if (in_array($row['hangup_cause'], $failed_array)) { + $status = 'failed'; + } + } + //clear previous variables unset($record_path, $record_name); @@ -693,25 +740,13 @@ if (permission_exists('xml_cdr_direction')) { $content .= "\n"; if ($theme_cdr_images_exist) { - if ($row['direction'] == 'inbound' || $row['direction'] == 'local') { - if ($row['answer_stamp'] != '' && $row['bridge_uuid'] != '') { $call_result = 'answered'; } - else if ($row['answer_stamp'] != '' && $row['bridge_uuid'] == '') { $call_result = 'voicemail'; } - else if ($row['answer_stamp'] == '' && $row['bridge_uuid'] == '' && $row['sip_hangup_disposition'] != 'send_refuse') { $call_result = 'cancelled'; } - else { $call_result = 'failed'; } - } - else if ($row['direction'] == 'outbound') { - if ($row['answer_stamp'] != '' && $row['bridge_uuid'] != '') { $call_result = 'answered'; } - else if ($row['hangup_cause'] == 'NORMAL_CLEARING') { $call_result = 'answered'; } - else if ($row['answer_stamp'] == '' && $row['bridge_uuid'] != '') { $call_result = 'cancelled'; } - else { $call_result = 'failed'; } - } if (!empty($row['direction'])) { - $image_name = "icon_cdr_" . $row['direction'] . "_" . $call_result; + $image_name = "icon_cdr_" . $row['direction'] . "_" . $status; if ($row['leg'] == 'b') { $image_name .= '_b'; } $image_name .= ".png"; - $content .= "\n"; + $content .= "\n"; } } else { $content .= " "; } @@ -824,8 +859,8 @@ } //call result/status if (permission_exists("xml_cdr_status")) { - $content .= " ".ucwords(escape($call_result))."\n"; - } + $content .= " ".escape($text['label-'.$status])."\n"; + } //hangup cause if (permission_exists('xml_cdr_hangup_cause')) { $content .= " ".escape($hangup_cause)."\n"; diff --git a/app/xml_cdr/xml_cdr_details.php b/app/xml_cdr/xml_cdr_details.php index 11ffb5d8c4..8872729ef7 100644 --- a/app/xml_cdr/xml_cdr_details.php +++ b/app/xml_cdr/xml_cdr_details.php @@ -188,14 +188,46 @@ $row_style["1"] = "row_style1"; //set the status - if ($billsec > 0) { - $status = 'answered'; - } - if ($missed_call == '1') { - $status = 'missed'; - } - if (substr($destination_number, 0, 3) == '*99') { - $status = 'voicemail'; + if (empty($status)) { + //define an array of failed hangup causes + $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" + ); + + //determine the call status + if ($billsec > 0) { + $status = 'answered'; + } + if ($missed_call == '1') { + $status = 'missed'; + } + if (substr($destination_number, 0, 3) == '*99') { + $status = 'voicemail'; + } + if ($hangup_cause == 'ORIGINATOR_CANCEL') { + $status = 'cancelled'; + } + if ($hangup_cause == 'USER_BUSY') { + $status = 'busy'; + } + if (in_array($hangup_cause, $failed_array)) { + $status = 'failed'; + } } //build the summary array diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index e97598b8ce..7f2b2ce777 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -68,7 +68,7 @@ $duration_max = $_REQUEST["duration_max"] ?? ''; $billsec = $_REQUEST["billsec"] ?? ''; $hangup_cause = $_REQUEST["hangup_cause"] ?? ''; - $call_result = $_REQUEST["call_result"] ?? ''; + $status = $_REQUEST["status"] ?? ''; $xml_cdr_uuid = $_REQUEST["xml_cdr_uuid"] ?? ''; $bleg_uuid = $_REQUEST["bleg_uuid"] ?? ''; $accountcode = $_REQUEST["accountcode"] ?? ''; @@ -163,7 +163,7 @@ $param .= "&duration_max=".urlencode($duration_max ?? ''); $param .= "&billsec=".urlencode($billsec ?? ''); $param .= "&hangup_cause=".urlencode($hangup_cause ?? ''); - $param .= "&call_result=".urlencode($call_result ?? ''); + $param .= "&status=".urlencode($status ?? ''); $param .= "&xml_cdr_uuid=".urlencode($xml_cdr_uuid ?? ''); $param .= "&bleg_uuid=".urlencode($bleg_uuid ?? ''); $param .= "&accountcode=".urlencode($accountcode ?? ''); @@ -250,7 +250,7 @@ $sql .= "to_char(timezone(:time_zone, start_stamp), 'HH12:MI:SS am') as start_time_formatted, \n"; $sql .= "c.start_epoch, \n"; $sql .= "c.hangup_cause, \n"; - $sql .= "c.duration, \n"; + $sql .= "c.billsec as duration, \n"; $sql .= "c.billmsec, \n"; $sql .= "c.missed_call, \n"; $sql .= "c.record_path, \n"; @@ -282,6 +282,7 @@ } $sql .= "c.accountcode, \n"; $sql .= "c.answer_stamp, \n"; + $sql .= "c.status, \n"; $sql .= "c.sip_hangup_disposition, \n"; if (permission_exists("xml_cdr_pdd")) { $sql .= "c.pdd_ms, \n"; @@ -446,11 +447,11 @@ } } if (is_numeric($duration_min)) { - $sql .= "and duration >= :duration_min \n"; + $sql .= "and billsec >= :duration_min \n"; $parameters['duration_min'] = $duration_min; } if (is_numeric($duration_max)) { - $sql .= "and duration <= :duration_max \n"; + $sql .= "and billsec <= :duration_max \n"; $parameters['duration_max'] = $duration_max; } if (!empty($billsec)) { @@ -466,58 +467,9 @@ if (!permission_exists('xml_cdr_lose_race')) { $sql .= "and hangup_cause != 'LOSE_RACE' \n"; } - - if (!empty($call_result)) { - switch ($call_result) { - case 'answered': - $sql .= "and (answer_stamp is not null and bridge_uuid is not null) \n"; - break; - case 'voicemail': - $sql .= "and (answer_stamp is not null and bridge_uuid is null) \n"; - break; - case 'missed': - $sql .= "and missed_call = true \n"; - break; - case 'cancelled': - if ($direction == 'inbound' || $direction == 'local' || $call_result == 'missed') { - $sql .= "and (( \n"; - $sql .= " answer_stamp is null \n"; - $sql .= " and bridge_uuid is null \n"; - $sql .= " and sip_hangup_disposition <> 'send_refuse' \n"; - $sql .= " ) \n"; - $sql .= " or ( \n"; - $sql .= " answer_stamp is not null \n"; - $sql .= " and bridge_uuid is null \n"; - $sql .= " and voicemail_message = false \n"; - $sql .= " )) \n"; - } - else if ($direction == 'outbound') { - $sql .= "and (answer_stamp is null and bridge_uuid is not null) "; - } - else { - $sql .= " and (( \n"; - $sql .= " (direction = 'inbound' or direction = 'local') \n"; - $sql .= " and answer_stamp is null \n"; - $sql .= " and bridge_uuid is null \n"; - $sql .= " and sip_hangup_disposition <> 'send_refuse' \n"; - $sql .= " ) \n"; - $sql .= " or ( \n"; - $sql .= " direction = 'outbound' \n"; - $sql .= " and answer_stamp is null \n"; - $sql .= " and bridge_uuid is not null \n"; - $sql .= " ) \n"; - $sql .= " or ( \n"; - $sql .= " (direction = 'inbound' or direction = 'local') \n"; - $sql .= " and answer_stamp is not null \n"; - $sql .= " and bridge_uuid is null \n"; - $sql .= " and voicemail_message = false \n"; - $sql .= " )) \n"; - } - break; - default: - $sql .= "and (answer_stamp is null and bridge_uuid is null and duration = 0) \n"; - //$sql .= "and (answer_stamp is null and bridge_uuid is null and billsec = 0 and sip_hangup_disposition = 'send_refuse') "; - } + if (!empty($status)) { + $sql .= "and status >= :status \n"; + $parameters['status'] = $status; } if (!empty($xml_cdr_uuid)) { $sql .= "and xml_cdr_uuid = :xml_cdr_uuid \n";