From aab2880153d5729015b87ac242623a39fde1b6da Mon Sep 17 00:00:00 2001 From: fusionate Date: Wed, 20 Sep 2023 01:15:04 +0000 Subject: [PATCH] CDR - Export: Integrate permissions on PDF output. --- app/xml_cdr/xml_cdr_export.php | 217 ++++++++++++++++++++++----------- 1 file changed, 147 insertions(+), 70 deletions(-) diff --git a/app/xml_cdr/xml_cdr_export.php b/app/xml_cdr/xml_cdr_export.php index 2cc04372ae..776518d588 100644 --- a/app/xml_cdr/xml_cdr_export.php +++ b/app/xml_cdr/xml_cdr_export.php @@ -137,25 +137,60 @@ //add new page $pdf->AddPage('L', array($page_width, $page_height)); - //set the number of columns - $columns = 13; + //initialize columns and colspan variables + $columns = $colspan_line_totals_averages = 0; //write the table column headers $data_start = ''; $data_end = '
'; $data_head = ''; - $data_head .= ''.$text['label-direction'].''; - $data_head .= ''.$text['label-caller_id_name'].''; - $data_head .= ''.$text['label-caller_id_number'].''; - $data_head .= ''.$text['label-caller_destination'].''; - $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 (permission_exists('xml_cdr_direction')) { + $data_head .= ''.$text['label-direction'].''; + $columns++; + } + if (permission_exists('xml_cdr_extension')) { + $data_head .= ''.$text['label-ext'].''; + $columns++; + } + if (permission_exists('xml_cdr_caller_id_name')) { + $data_head .= ''.$text['label-caller_id_name'].''; + $columns++; + } + if (permission_exists('xml_cdr_caller_id_number')) { + $data_head .= ''.$text['label-caller_id_number'].''; + $columns++; + } + if (permission_exists('xml_cdr_caller_destination')) { + $data_head .= ''.$text['label-caller_destination'].''; + $columns++; + } + if (permission_exists('xml_cdr_destination')) { + $data_head .= ''.$text['label-destination'].''; + $columns++; + } + if (permission_exists('xml_cdr_start')) { + $data_head .= ''.$text['label-start'].''; + $columns++; + } + $colspan_line_totals_averages = $columns - 1; + if (permission_exists('xml_cdr_tta')) { + $data_head .= ''.$text['label-tta'].''; + $columns++; + } + if (permission_exists('xml_cdr_duration')) { + $data_head .= ''.$text['label-duration'].''; + $columns += 2; + $data_head .= ''.$text['label-billsec'].''; + } + if (permission_exists('xml_cdr_pdd')) { + $data_head .= ''."PDD".''; + $columns++; + } + if (permission_exists('xml_cdr_mos')) { + $data_head .= ''."MOS".''; + $columns++; + } if (!empty($_SESSION['cdr']['field']) && is_array($_SESSION['cdr']['field'])) { foreach ($_SESSION['cdr']['field'] as $field) { $array = explode(",", $field); @@ -165,13 +200,17 @@ if ($field_name != "destination_number") { $data_head .= ''.$field_label.''; } - $columns = $columns + 1; + $columns++; } } - $data_head .= ''; - $data_head .= ''.$text['label-hangup_cause'].''; + if (permission_exists('xml_cdr_hangup_cause')) { + $data_head .= ''.$text['label-hangup_cause'].''; + $columns++; + } $data_head .= ''; - $data_head .= '
'; + if ($columns != 0) { + $data_head .= '
'; + } //initialize total variables $total['duration'] = 0; @@ -183,35 +222,49 @@ //write the row cells $z = 0; // total counter $p = 0; // per page counter - if (sizeof($result) > 0) { + if (sizeof($result) > 0 && $columns != 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['caller_destination']).''; - $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).''; - $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).''; - $total['billmsec'] += $fields['billmsec']; - $data_body[$p] .= ''.number_format(round($fields['billmsec'] / 1000, 2), 2).'s'; - $data_body[$p] .= ''; + if (permission_exists('xml_cdr_direction')) { + $data_body[$p] .= ''.$text['label-'.$fields['direction']].''; + } + if (permission_exists('xml_cdr_extension')) { + $data_body[$p] .= ''.$fields['extension'].''; + } + if (permission_exists('xml_cdr_caller_id_name')) { + $data_body[$p] .= ''.$fields['caller_id_name'].''; + } + if (permission_exists('xml_cdr_caller_id_number')) { + $data_body[$p] .= ''.$fields['caller_id_number'].''; + } + if (permission_exists('xml_cdr_caller_destination')) { + $data_body[$p] .= ''.format_phone($fields['caller_destination']).''; + } + if (permission_exists('xml_cdr_destination')) { + $data_body[$p] .= ''.format_phone($fields['destination_number']).''; + } + if (permission_exists('xml_cdr_start')) { + $data_body[$p] .= ''.$fields['start_stamp'].''; + } + if (permission_exists('xml_cdr_tta')) { + $total['tta'] += ($fields['tta'] > 0) ? $fields['tta'] : 0; + $data_body[$p] .= ''.(($fields['tta'] >= 0) ? $fields['tta'].'s' : null).''; + } + if (permission_exists('xml_cdr_duration')) { + $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).''; + $total['billmsec'] += $fields['billmsec']; + $data_body[$p] .= ''.number_format(round($fields['billmsec'] / 1000, 2), 2).'s'; + } 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] .= ''.number_format(round($fields['pdd_ms'] / 1000, 2), 2).'s'; } - $data_body[$p] .= ''; - $data_body[$p] .= ''; - if (permission_exists("xml_cdr_mos")) { + if (permission_exists('xml_cdr_mos')) { $total['rtp_audio_in_mos'] += $fields['rtp_audio_in_mos']; - $data_body[$p] .= (!empty($total['rtp_audio_in_mos'])) ? $fields['rtp_audio_in_mos'] : null; + $data_body[$p] .= ''.($fields['rtp_audio_in_mos'] ?? '').''; } - $data_body[$p] .= ''; - if (!empty($_SESSION['cdr']['field']) && is_array($_SESSION['cdr']['field'])) { foreach ($_SESSION['cdr']['field'] as $field) { $array = explode(",", $field); @@ -226,8 +279,9 @@ } } - $data_body[$p] .= ' '; - $data_body[$p] .= ''.ucwords(strtolower(str_replace("_", " ", $fields['hangup_cause']))).''; + if (permission_exists('xml_cdr_hangup_cause')) { + $data_body[$p] .= ''.ucwords(strtolower(str_replace("_", " ", $fields['hangup_cause']))).''; + } $data_body[$p] .= ''; $z++; @@ -253,38 +307,61 @@ } - //write divider - $data_footer = ''; + if ($columns != 0) { - //write totals - $data_footer .= ''; - $data_footer .= ''.$text['label-total'].''; - $data_footer .= ''.$z.''; - $data_footer .= ''; - $data_footer .= ''.number_format(round($total['tta'], 1), 0).'s'; - $data_footer .= ''.gmdate("G:i:s", $total['duration']).''; - $data_footer .= ''.gmdate("G:i:s", round($total['billmsec'] / 1000, 0)).''; - $data_footer .= ''.number_format(round(($total['pdd_ms'] / 1000), 2), 2).'s'; - $data_footer .= ''; - $data_footer .= ''; + //write divider + $data_footer = ''; - //write divider - $data_footer .= '
'; + //write totals + $data_footer .= ''; + $data_footer .= ''.$text['label-total'].''; + $data_footer .= ''.$z.''; + if (permission_exists('xml_cdr_tta')) { + $data_footer .= ''.number_format(round($total['tta'], 1), 0).'s'; + } + if (permission_exists('xml_cdr_duration')) { + $data_footer .= ''.gmdate("G:i:s", $total['duration']).''; + $data_footer .= ''.gmdate("G:i:s", round($total['billmsec'] / 1000, 0)).''; + } + if (permission_exists("xml_cdr_pdd")) { + $data_footer .= ''.number_format(round(($total['pdd_ms'] / 1000), 2), 2).'s'; + } + if (permission_exists('xml_cdr_mos')) { + $data_footer .= ''; + } + if (permission_exists('xml_cdr_hangup_cause')) { + $data_footer .= ''; + } + $data_footer .= ''; - //write averages - $data_footer .= ''; - $data_footer .= ''.$text['label-average'].''; - $data_footer .= ''; - $data_footer .= ''.round(($total['tta'] / $z), 1).''; - $data_footer .= ''.gmdate("G:i:s", floor($total['duration'] / $z)).''; - $data_footer .= ''.gmdate("G:i:s", round($total['billmsec'] / $z / 1000, 0)).''; - $data_footer .= ''.number_format(round(($total['pdd_ms'] / $z / 1000), 2), 2).'s'; - $data_footer .= ''.round(($total['rtp_audio_in_mos'] / $z), 2).''; - $data_footer .= ''; - $data_footer .= ''; + $data_footer .= '
'; - //write divider - $data_footer .= '
'; + //write averages + $data_footer .= ''; + $data_footer .= ''.$text['label-average'].''; + $data_footer .= ''; + if (permission_exists('xml_cdr_tta')) { + $data_footer .= ''.round(($total['tta'] / $z), 1).''; + } + if (permission_exists('xml_cdr_duration')) { + $data_footer .= ''.gmdate("G:i:s", floor($total['duration'] / $z)).''; + $data_footer .= ''.gmdate("G:i:s", round($total['billmsec'] / $z / 1000, 0)).''; + } + if (permission_exists("xml_cdr_pdd")) { + $data_footer .= ''.number_format(round(($total['pdd_ms'] / $z / 1000), 2), 2).'s'; + } + if (permission_exists('xml_cdr_mos')) { + $data_footer .= ''.round(($total['rtp_audio_in_mos'] / $z), 2).''; + } + if (permission_exists('xml_cdr_hangup_cause')) { + $data_footer .= ''; + } + $data_footer .= ''; + + //write divider + $data_footer .= '
'; + + } //add last page if ($p >= 55) { @@ -317,4 +394,4 @@ } -?> +?> \ No newline at end of file