diff --git a/app/xml_cdr/xml_cdr_export.php b/app/xml_cdr/xml_cdr_export.php index 9b7e361dcd..0d4f66f5e1 100644 --- a/app/xml_cdr/xml_cdr_export.php +++ b/app/xml_cdr/xml_cdr_export.php @@ -23,16 +23,20 @@ Contributor(s): Mark J Crane */ -include "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; -} + +//includes + include "root.php"; + require_once "resources/require.php"; + require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('xml_cdr_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } //add multi-lingual support $language = new text; @@ -40,9 +44,6 @@ else { //additional includes $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - if ($_REQUEST['archive_request'] == 'true') { - $archive_request = 'true'; - } require_once "xml_cdr_inc.php"; //get the format @@ -129,37 +130,50 @@ else { // initialize pdf $pdf = new FPDI('L', 'in'); - $pdf -> SetAutoPageBreak(false); - $pdf -> setPrintHeader(false); - $pdf -> setPrintFooter(false); - $pdf -> SetMargins(0.5, 0.5, 0.5, true); + $pdf->SetAutoPageBreak(false); + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + $pdf->SetMargins(0.5, 0.5, 0.5, true); //set default font - $pdf -> SetFont('helvetica', '', 7); + $pdf->SetFont('helvetica', '', 7); //add new page - $pdf -> AddPage('L', array($page_width, $page_height)); + $pdf->AddPage('L', array($page_width, $page_height)); - $chunk = 0; + //set the number of columns + $columns = 12; //write the table column headers $data_start = ''; $data_end = '
'; $data_head = ''; - $data_head .= ''.$text['label-direction'].''; - $data_head .= ''.$text['label-cid-name'].''; - $data_head .= ''.$text['label-cid-number'].''; - $data_head .= ''.$text['label-destination'].''; - $data_head .= ''.$text['label-start'].''; - $data_head .= ''.$text['label-tta'].''; - $data_head .= ''.$text['label-duration'].''; - $data_head .= ''.$text['label-billsec'].''; - $data_head .= ''."PDD".''; - $data_head .= ''."MOS".''; - $data_head .= ''; - $data_head .= ''.$text['label-hangup_cause'].''; + $data_head .= ''.$text['label-direction'].''; + $data_head .= ''.$text['label-caller_id_name'].''; + $data_head .= ''.$text['label-caller_id_number'].''; + $data_head .= ''.$text['label-destination'].''; + $data_head .= ''.$text['label-start'].''; + $data_head .= ''.$text['label-tta'].''; + $data_head .= ''.$text['label-duration'].''; + $data_head .= ''.$text['label-billsec'].''; + $data_head .= ''."PDD".''; + $data_head .= ''."MOS".''; + if (is_array($_SESSION['cdr']['field'])) { + foreach ($_SESSION['cdr']['field'] as $field) { + $array = explode(",", $field); + $field_name = end($array); + $field_label = ucwords(str_replace("_", " ", $field_name)); + $field_label = str_replace("Sip", "SIP", $field_label); + if ($field_name != "destination_number") { + $data_head .= ''.$field_label.''; + } + $columns = $columns + 1; + } + } + $data_head .= ''; + $data_head .= ''.$text['label-hangup_cause'].''; $data_head .= ''; - $data_head .= '
'; + $data_head .= '
'; //initialize total variables $total['duration'] = 0; @@ -174,32 +188,47 @@ else { if (sizeof($result) > 0) { foreach($result as $cdr_num => $fields) { $data_body[$p] .= ''; - $data_body[$p] .= ''.$text['label-'.$fields['direction']].''; - $data_body[$p] .= ''.$fields['caller_id_name'].''; - $data_body[$p] .= ''.$fields['caller_id_number'].''; - $data_body[$p] .= ''.format_phone($fields['destination_number']).''; - $data_body[$p] .= ''.$fields['start_stamp'].''; + $data_body[$p] .= ''.$text['label-'.$fields['direction']].''; + $data_body[$p] .= ''.$fields['caller_id_name'].''; + $data_body[$p] .= ''.$fields['caller_id_number'].''; + $data_body[$p] .= ''.format_phone($fields['destination_number']).''; + $data_body[$p] .= ''.$fields['start_stamp'].''; $total['tta'] += ($fields['tta'] > 0) ? $fields['tta'] : 0; - $data_body[$p] .= ''.(($fields['tta'] > 0) ? $fields['tta'].'s' : null).''; + $data_body[$p] .= ''.(($fields['tta'] > 0) ? $fields['tta'].'s' : null).''; $seconds = ($fields['hangup_cause'] == "ORIGINATOR_CANCEL") ? $fields['duration'] : round(($fields['billmsec'] / 1000), 0, PHP_ROUND_HALF_UP); $total['duration'] += $seconds; - $data_body[$p] .= ''.gmdate("G:i:s", $seconds).''; + $data_body[$p] .= ''.gmdate("G:i:s", $seconds).''; $total['billmsec'] += $fields['billmsec']; - $data_body[$p] .= ''.number_format(round($fields['billmsec'] / 1000, 2), 2).'s'; - $data_body[$p] .= ''; + $data_body[$p] .= ''.number_format(round($fields['billmsec'] / 1000, 2), 2).'s'; + $data_body[$p] .= ''; if (permission_exists("xml_cdr_pdd")) { $total['pdd_ms'] += $fields['pdd_ms']; $data_body[$p] .= number_format(round($fields['pdd_ms'] / 1000, 2), 2).'s'; } $data_body[$p] .= ''; - $data_body[$p] .= ''; + $data_body[$p] .= ''; if (permission_exists("xml_cdr_mos")) { $total['rtp_audio_in_mos'] += $fields['rtp_audio_in_mos']; $data_body[$p] .= (strlen($total['rtp_audio_in_mos']) > 0) ? $fields['rtp_audio_in_mos'] : null; } $data_body[$p] .= ''; - $data_body[$p] .= ''; - $data_body[$p] .= ''.ucwords(strtolower(str_replace("_", " ", $fields['hangup_cause']))).''; + + if (is_array($_SESSION['cdr']['field'])) { + foreach ($_SESSION['cdr']['field'] as $field) { + $array = explode(",", $field); + $field_name = end($array); + $field_label = ucwords(str_replace("_", " ", $field_name)); + $field_label = str_replace("Sip", "SIP", $field_label); + if ($field_name != "destination_number") { + $data_body[$p] .= ''; + $data_body[$p] .= $fields[$field_name]; + $data_body[$p] .= ''; + } + } + } + + $data_body[$p] .= ' '; + $data_body[$p] .= ''.ucwords(strtolower(str_replace("_", " ", $fields['hangup_cause']))).''; $data_body[$p] .= ''; $z++; @@ -212,13 +241,13 @@ else { $data_body_chunk .= $data_body_row; } $data_body_chunk .= $data_end; - $pdf -> writeHTML($data_body_chunk, true, false, false, false, ''); + $pdf->writeHTML($data_body_chunk, true, false, false, false, ''); unset($data_body_chunk); unset($data_body); $p = 0; //add new page - $pdf -> AddPage('L', array($page_width, $page_height)); + $pdf->AddPage('L', array($page_width, $page_height)); } } @@ -226,7 +255,7 @@ else { } //write divider - $data_footer = ''; + $data_footer = ''; //write totals $data_footer .= ''; @@ -241,7 +270,7 @@ else { $data_footer .= ''; //write divider - $data_footer .= '
'; + $data_footer .= '
'; //write averages $data_footer .= ''; @@ -256,11 +285,11 @@ else { $data_footer .= ''; //write divider - $data_footer .= '
'; + $data_footer .= '
'; //add last page if ($p >= 55) { - $pdf -> AddPage('L', array($page_width, $page_height)); + $pdf->AddPage('L', array($page_width, $page_height)); } //output remaining data $data_body_chunk = $data_start.$data_head; @@ -268,7 +297,7 @@ else { $data_body_chunk .= $data_body_row; } $data_body_chunk .= $data_footer.$data_end; - $pdf -> writeHTML($data_body_chunk, true, false, false, false, ''); + $pdf->writeHTML($data_body_chunk, true, false, false, false, ''); unset($data_body_chunk); //define file name