Portions created by the Initial Developer are Copyright (C) 2008-2016 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists('xml_cdr_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //additional includes require_once "resources/header.php"; require_once "resources/paging.php"; //xml cdr include $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; require_once "xml_cdr_inc.php"; //javascript function: send_cmd echo "\n"; //javascript to toggle export select box echo ""; //page title and description echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
".$text['title']."


\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"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (isset($order_by)) { echo " \n"; echo " \n"; } if (permission_exists('xml_cdr_all' && $_REQUEST['showall'] == 'true')) { echo " \n"; } echo " \n"; echo " \n"; echo " "; echo " \n"; if ($paging_controls_mini != '') { echo " \n"; } echo " \n"; echo "
\n"; if (permission_exists('xml_cdr_all')) { if ($_REQUEST['showall'] != 'true') { echo " \n"; } } if (permission_exists('xml_cdr_search_advanced')) { if ($_REQUEST['showall'] == 'true') { $query_string = "showall=true"; } echo " \n"; } if ($_GET['call_result'] != 'missed') { echo " \n"; } echo " \n"; echo " \n"; echo " "; echo " \n"; echo " ".$paging_controls_mini."
\n"; echo "
\n"; echo "
\n"; echo $text['description']." \n"; echo $text['description2']." \n"; echo $text['description-3']." \n"; echo $text['description-4']." \n"; echo "

\n"; echo "
\n"; //basic search of call detail records if (permission_exists('xml_cdr_search')) { echo "
\n"; echo "\n"; echo "\n"; echo ""; echo ""; echo ""; // show hangup clause filter to super/admin if (if_group("admin") || if_group("superadmin") || if_group("cdr")) { echo ""; } echo ""; echo "
\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-direction']."\n"; echo " \n"; echo " \n"; echo "
\n"; 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 " ".$text['label-source']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-destination']."\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 " ".$text['label-start_range']."\n"; echo " \n"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-cid-name']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-hangup_cause']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
"; echo "\n"; echo ""; echo ""; echo ""; echo ""; echo "
"; echo $text['description_search']; echo ""; if (permission_exists('xml_cdr_all') && $_REQUEST['showall'] == 'true') { echo "\n"; } echo "\n"; echo "\n"; echo "
"; echo "
"; echo "

"; } //mod paging parameters for inclusion in column sort heading links $param = substr($param, 1); //remove leading '&' $param = substr($param, 0, strrpos($param, '&order_by=')); //remove trailing order by //show the results $col_count = 8; echo "
\n"; echo "\n"; echo "\n"; if (permission_exists('xml_cdr_delete') && $result_count > 0) { echo ""; $col_count++; } //column headings echo "\n"; if ($_REQUEST['showall'] && permission_exists('xml_cdr_all')) { echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, null, $param); $col_count++; } echo th_order_by('caller_id_name', $text['label-cid-name'], $order_by, $order, null, null, $param); echo th_order_by('caller_id_number', $text['label-source'], $order_by, $order, null, null, $param); echo th_order_by('destination_number', $text['label-destination'], $order_by, $order, null, null, $param); if (permission_exists('recording_play') || permission_exists('recording_download')) { echo "\n"; $col_count++; } echo th_order_by('start_stamp', $text['label-start'], $order_by, $order, null, "style='text-align: center;'", $param); echo th_order_by('tta', $text['label-tta'], $order_by, $order, null, "style='text-align: right;'", $param); echo th_order_by('duration', $text['label-duration'], $order_by, $order, null, "style='text-align: center;'", $param); if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){ echo "\n"; $col_count++; } if (permission_exists('xml_cdr_pdd')) { echo th_order_by('pdd_ms', 'PDD', $order_by, $order, null, "style='text-align: right;'", $param); $col_count++; } if (permission_exists('xml_cdr_mos')) { echo th_order_by('rtp_audio_in_mos', 'MOS', $order_by, $order, null, "style='text-align: center;'", $param); $col_count++; } if (if_group("admin") || if_group("superadmin") || if_group("cdr")) { echo th_order_by('hangup_cause', $text['label-hangup_cause'], $order_by, $order, null, null, $param); } else { echo "\n"; } if (if_group("admin") || if_group("superadmin") || if_group("cdr")) { echo "\n"; $col_count++; } echo "\n"; if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){ require_once "app/billing/resources/functions/rating.php"; require_once "resources/classes/database.php"; $database = new database; } if ($result_count > 0) { //determine if theme images exist $theme_image_path = $_SERVER["DOCUMENT_ROOT"]."/themes/".$_SESSION['domain']['template']['name']."/images/"; $theme_cdr_images_exist = ( file_exists($theme_image_path."icon_cdr_inbound_answered.png") && file_exists($theme_image_path."icon_cdr_inbound_voicemail.png") && file_exists($theme_image_path."icon_cdr_inbound_cancelled.png") && file_exists($theme_image_path."icon_cdr_inbound_failed.png") && file_exists($theme_image_path."icon_cdr_outbound_answered.png") && file_exists($theme_image_path."icon_cdr_outbound_cancelled.png") && file_exists($theme_image_path."icon_cdr_outbound_failed.png") && file_exists($theme_image_path."icon_cdr_local_answered.png") && file_exists($theme_image_path."icon_cdr_local_voicemail.png") && file_exists($theme_image_path."icon_cdr_local_cancelled.png") && file_exists($theme_image_path."icon_cdr_local_failed.png") ) ? true : false; foreach($result as $index => $row) { $tmp_year = date("Y", strtotime($row['start_stamp'])); $tmp_month = date("M", strtotime($row['start_stamp'])); $tmp_day = date("d", strtotime($row['start_stamp'])); $tmp_start_epoch = ($_SESSION['domain']['time_format']['text'] == '12h') ? date("j M Y g:i:sa", $row['start_epoch']) : date("j M Y H:i:s", $row['start_epoch']); $hangup_cause = $row['hangup_cause']; $hangup_cause = str_replace("_", " ", $hangup_cause); $hangup_cause = strtolower($hangup_cause); $hangup_cause = ucwords($hangup_cause); //if call cancelled, show the ring time, not the bill time. $seconds = ($row['hangup_cause']=="ORIGINATOR_CANCEL") ? $row['duration'] : round(($row['billmsec'] / 1000), 0, PHP_ROUND_HALF_UP); //determine recording properties if (permission_exists('recording_play') || permission_exists('recording_download')) { $tmp_rel_path = '/archive/'.$tmp_year.'/'.$tmp_month.'/'.$tmp_day; $tmp_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION["domain_name"].$tmp_rel_path; $tmp_name = ''; if (!empty($row['recording_file']) && file_exists($row['recording_file'])) { $tmp_name = $row['recording_file']; } else if (file_exists($tmp_dir.'/'.$row['uuid'].'.wav')) { $tmp_name = $row['uuid'].".wav"; } else if (file_exists($tmp_dir.'/'.$row['uuid'].'_1.wav')) { $tmp_name = $row['uuid']."_1.wav"; } else if (file_exists($tmp_dir.'/'.$row['uuid'].'.mp3')) { $tmp_name = $row['uuid'].".mp3"; } else if (file_exists($tmp_dir.'/'.$row['uuid'].'_1.mp3')) { $tmp_name = $row['uuid']."_1.mp3"; } else if (file_exists($tmp_dir.'/'.$row['bridge_uuid'].'.wav')) { $tmp_name = $row['bridge_uuid'].".wav"; } else if (file_exists($tmp_dir.'/'.$row['bridge_uuid'].'_1.wav')) { $tmp_name = $row['bridge_uuid']."_1.wav"; } else if (file_exists($tmp_dir.'/'.$row['bridge_uuid'].'.mp3')) { $tmp_name = $row['bridge_uuid'].".mp3"; } else if (file_exists($tmp_dir.'/'.$row['bridge_uuid'].'_1.mp3')) { $tmp_name = $row['bridge_uuid']."_1.mp3"; } if (strlen($tmp_name) > 0 && file_exists($tmp_dir.'/'.$tmp_name) && $seconds > 0) { $recording_file_path = $tmp_rel_path.'/'.$tmp_name; $recording_file_name = strtolower(pathinfo($tmp_name, PATHINFO_BASENAME)); $recording_file_ext = pathinfo($recording_file_name, PATHINFO_EXTENSION); switch ($recording_file_ext) { case "wav" : $recording_type = "audio/wav"; break; case "mp3" : $recording_type = "audio/mpeg"; break; case "ogg" : $recording_type = "audio/ogg"; break; } } else { unset($recording_file_path); } } //recording playback if (permission_exists('recording_play') && $recording_file_path != '') { echo "\n"; } if (if_group("admin") || if_group("superadmin") || if_group("cdr")) { $tr_link = "href='xml_cdr_details.php?uuid=".$row['uuid'].(($_REQUEST['showall']) ? "&showall=true" : null)."'"; } else { $tr_link = null; } echo "\n"; if (permission_exists('xml_cdr_delete')) { echo " "; $xml_ids[] = 'checkbox_'.$row['uuid']; } //determine call result and appropriate icon echo "\n"; //domain name if ($_REQUEST['showall'] && permission_exists('xml_cdr_all')) { echo " \n"; } //caller id name echo " \n"; //source echo " \n"; //destination echo " \n"; //recording if (permission_exists('recording_play') || permission_exists('recording_download')) { if ($recording_file_path != '') { echo " \n"; } else { echo " \n"; } } //start echo " \n"; //tta (time to answer) echo " \n"; //duration echo " \n"; //billing if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){ $database->table = "v_xml_cdr"; $accountcode = (strlen($row["accountcode"])?$row["accountcode"]:$_SESSION[domain_name]); $database->sql = "SELECT currency FROM v_billings WHERE type_value='$accountcode'"; $database->result = $database->execute(); $billing_currency = (strlen($database->result[0]['currency'])?$database->result[0]['currency']:'USD'); $billing_currency = (strlen($database->result[0]['currency'])?$database->result[0]['currency']: (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') ); unset($database->sql); unset($database->result); $sell_price = strlen($row['call_sell'])?$row['call_sell']:0; $lcr_direction = (strlen($row['direction'])?$row['direction']:"outbound"); $xml_string = trim($row["xml"]); $json_string = trim($row["json"]); if (strlen($xml_string) > 0) { $format = "xml"; } if (strlen($json_string) > 0) { $format = "json"; } try { if ($format == 'json') { $array = json_decode($json_string,true); } if ($format == 'xml') { $array = json_decode(json_encode((array)simplexml_load_string($xml_string)),true); } } catch(Exception $e) { echo $e->getMessage(); } $n = (($lcr_direction == "inbound")? check_str(urldecode($array["caller_profile"]["caller_id_number"])): check_str(urldecode($array["variables"]["lcr_query_digits"])) ); $database->table = "v_lcr"; $database->sql = "SELECT currency FROM v_lcr WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.enabled='true' AND v_lcr.lcr_direction='$lcr_direction' AND v_lcr.digits IN (".number_series($n).") ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1"; $database->result = $database->execute(); // print "
"; print $database->sql . ":";print "[".$database->result[0]['currency']."]"; print_r($array); print "
"; $lcr_currency = ((is_string($database->result[0]['currency']) && strlen($database->result[0]['currency']))?$database->result[0]['currency']: (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') ); //billed currency unset($database->sql); unset($database->result); if ($sell_price){ $price = currency_convert($sell_price, $billing_currency, $lcr_currency); } else { $price = 0; } echo " \n"; unset ($sell_price, $price); } //pdd (post dial delay) if (permission_exists("xml_cdr_pdd")) { echo " \n"; } //mos (mean opinion score) if (permission_exists("xml_cdr_mos")) { echo " \n"; } //hangup cause/call result if (if_group("admin") || if_group("superadmin") || if_group("cdr")) { echo " \n"; } else { echo " \n"; } //control icons if (if_group("admin") || if_group("superadmin") || if_group("cdr")) { echo " \n"; } echo "\n"; $c = ($c) ? 0 : 1; } //end foreach unset($sql, $result, $row_count); } //end if results echo "\n"; echo "
 ".$text['label-recording']."".$text['label-price']."".$text['label-status'].""; if (permission_exists('xml_cdr_delete') && $result_count > 0) { echo "".$v_link_label_delete.""; } echo "
\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['answer_stamp'] == '' && $row['bridge_uuid'] != '') { $call_result = 'cancelled'; } else { $call_result = 'failed'; } } echo "\n"; } else { echo " "; } echo ""; echo $row['domain_name'].' '; echo " ".$row['caller_id_name']."  ".$tmp_start_epoch."".(($row['tta'] > 0) ? $row['tta']."s" : " ")."".gmdate("G:i:s", $seconds)."".number_format($price,6)." $billing_currency".number_format($row['pdd_ms']/1000,2)."s 0) ? "title='".($row['rtp_audio_in_mos'] / 5 * 100)."%'" : null)." style='text-align: center;'>".((strlen($row['rtp_audio_in_mos']) > 0) ? $row['rtp_audio_in_mos'] : " ")."".$hangup_cause."".ucwords($call_result)."
"; echo "
"; echo "

"; echo $paging_controls; echo "

"; // check or uncheck all checkboxes if (sizeof($xml_ids) > 0) { echo "\n"; } //store last search/sort query parameters in session $_SESSION['xml_cdr']['last_query'] = $_SERVER["QUERY_STRING"]; //show the footer require_once "resources/footer.php"; ?>