Update xml_cdr_export.php

This commit is contained in:
FusionPBX
2018-06-25 21:08:28 -06:00
committed by GitHub
parent c15dacbd5d
commit c6b12e5f00
+81 -52
View File
@@ -23,16 +23,20 @@
Contributor(s): Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
*/ */
include "root.php";
require_once "resources/require.php"; //includes
require_once "resources/check_auth.php"; include "root.php";
if (permission_exists('xml_cdr_view')) { require_once "resources/require.php";
//access granted require_once "resources/check_auth.php";
}
else { //check permissions
echo "access denied"; if (permission_exists('xml_cdr_view')) {
exit; //access granted
} }
else {
echo "access denied";
exit;
}
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@@ -40,9 +44,6 @@ else {
//additional includes //additional includes
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $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"; require_once "xml_cdr_inc.php";
//get the format //get the format
@@ -129,37 +130,50 @@ else {
// initialize pdf // initialize pdf
$pdf = new FPDI('L', 'in'); $pdf = new FPDI('L', 'in');
$pdf -> SetAutoPageBreak(false); $pdf->SetAutoPageBreak(false);
$pdf -> setPrintHeader(false); $pdf->setPrintHeader(false);
$pdf -> setPrintFooter(false); $pdf->setPrintFooter(false);
$pdf -> SetMargins(0.5, 0.5, 0.5, true); $pdf->SetMargins(0.5, 0.5, 0.5, true);
//set default font //set default font
$pdf -> SetFont('helvetica', '', 7); $pdf->SetFont('helvetica', '', 7);
//add new page //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 //write the table column headers
$data_start = '<table cellpadding="0" cellspacing="0" border="0" width="100%">'; $data_start = '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
$data_end = '</table>'; $data_end = '</table>';
$data_head = '<tr>'; $data_head = '<tr>';
$data_head .= '<td width="7.5%"><b>'.$text['label-direction'].'</b></td>'; $data_head .= '<td width="5%"><b>'.$text['label-direction'].'</b></td>';
$data_head .= '<td width="15%"><b>'.$text['label-cid-name'].'</b></td>'; $data_head .= '<td width="9%"><b>'.$text['label-caller_id_name'].'</b></td>';
$data_head .= '<td width="8.5%"><b>'.$text['label-cid-number'].'</b></td>'; $data_head .= '<td width="9%"><b>'.$text['label-caller_id_number'].'</b></td>';
$data_head .= '<td width="11%"><b>'.$text['label-destination'].'</b></td>'; $data_head .= '<td width="9%"><b>'.$text['label-destination'].'</b></td>';
$data_head .= '<td width="11%"><b>'.$text['label-start'].'</b></td>'; $data_head .= '<td width="10%" nowrap="nowrap"><b>'.$text['label-start'].'</b></td>';
$data_head .= '<td width="4%" align="right"><b>'.$text['label-tta'].'</b></td>'; $data_head .= '<td width="3%" align="right"><b>'.$text['label-tta'].'</b></td>';
$data_head .= '<td width="8.5%" align="right"><b>'.$text['label-duration'].'</b></td>'; $data_head .= '<td width="8%" align="right"><b>'.$text['label-duration'].'</b></td>';
$data_head .= '<td width="8.5%" align="right"><b>'.$text['label-billsec'].'</b></td>'; $data_head .= '<td width="8%" align="right"><b>'.$text['label-billsec'].'</b></td>';
$data_head .= '<td width="7%" align="right"><b>'."PDD".'</b></td>'; $data_head .= '<td width="5%" align="right"><b>'."PDD".'</b></td>';
$data_head .= '<td width="5%" align="right"><b>'."MOS".'</b></td>'; $data_head .= '<td width="5%" align="center"><b>'."MOS".'</b></td>';
$data_head .= '<td width="2%"></td>'; if (is_array($_SESSION['cdr']['field'])) {
$data_head .= '<td width="15%"><b>'.$text['label-hangup_cause'].'</b></td>'; 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 .= '<td width="10%" align="left"><b>'.$field_label.'</b></td>';
}
$columns = $columns + 1;
}
}
$data_head .= '<td width="1%"></td>';
$data_head .= '<td width="10%"><b>'.$text['label-hangup_cause'].'</b></td>';
$data_head .= '</tr>'; $data_head .= '</tr>';
$data_head .= '<tr><td colspan="12"><hr></td></tr>'; $data_head .= '<tr><td colspan="'.$columns.'"><hr></td></tr>';
//initialize total variables //initialize total variables
$total['duration'] = 0; $total['duration'] = 0;
@@ -174,32 +188,47 @@ else {
if (sizeof($result) > 0) { if (sizeof($result) > 0) {
foreach($result as $cdr_num => $fields) { foreach($result as $cdr_num => $fields) {
$data_body[$p] .= '<tr>'; $data_body[$p] .= '<tr>';
$data_body[$p] .= '<td width="7.5%">'.$text['label-'.$fields['direction']].'</td>'; $data_body[$p] .= '<td>'.$text['label-'.$fields['direction']].'</td>';
$data_body[$p] .= '<td width="15%">'.$fields['caller_id_name'].'</td>'; $data_body[$p] .= '<td>'.$fields['caller_id_name'].'</td>';
$data_body[$p] .= '<td width="8.5%">'.$fields['caller_id_number'].'</td>'; $data_body[$p] .= '<td>'.$fields['caller_id_number'].'</td>';
$data_body[$p] .= '<td width="11%">'.format_phone($fields['destination_number']).'</td>'; $data_body[$p] .= '<td>'.format_phone($fields['destination_number']).'</td>';
$data_body[$p] .= '<td width="11%">'.$fields['start_stamp'].'</td>'; $data_body[$p] .= '<td>'.$fields['start_stamp'].'</td>';
$total['tta'] += ($fields['tta'] > 0) ? $fields['tta'] : 0; $total['tta'] += ($fields['tta'] > 0) ? $fields['tta'] : 0;
$data_body[$p] .= '<td width="4%" align="right">'.(($fields['tta'] > 0) ? $fields['tta'].'s' : null).'</td>'; $data_body[$p] .= '<td align="right">'.(($fields['tta'] > 0) ? $fields['tta'].'s' : null).'</td>';
$seconds = ($fields['hangup_cause'] == "ORIGINATOR_CANCEL") ? $fields['duration'] : round(($fields['billmsec'] / 1000), 0, PHP_ROUND_HALF_UP); $seconds = ($fields['hangup_cause'] == "ORIGINATOR_CANCEL") ? $fields['duration'] : round(($fields['billmsec'] / 1000), 0, PHP_ROUND_HALF_UP);
$total['duration'] += $seconds; $total['duration'] += $seconds;
$data_body[$p] .= '<td width="8.5%" align="right">'.gmdate("G:i:s", $seconds).'</td>'; $data_body[$p] .= '<td align="right">'.gmdate("G:i:s", $seconds).'</td>';
$total['billmsec'] += $fields['billmsec']; $total['billmsec'] += $fields['billmsec'];
$data_body[$p] .= '<td width="8.5%" align="right">'.number_format(round($fields['billmsec'] / 1000, 2), 2).'s</td>'; $data_body[$p] .= '<td align="right">'.number_format(round($fields['billmsec'] / 1000, 2), 2).'s</td>';
$data_body[$p] .= '<td width="7%" align="right">'; $data_body[$p] .= '<td align="right">';
if (permission_exists("xml_cdr_pdd")) { if (permission_exists("xml_cdr_pdd")) {
$total['pdd_ms'] += $fields['pdd_ms']; $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] .= '</td>'; $data_body[$p] .= '</td>';
$data_body[$p] .= '<td width="5%" align="right">'; $data_body[$p] .= '<td align="center">';
if (permission_exists("xml_cdr_mos")) { if (permission_exists("xml_cdr_mos")) {
$total['rtp_audio_in_mos'] += $fields['rtp_audio_in_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] .= (strlen($total['rtp_audio_in_mos']) > 0) ? $fields['rtp_audio_in_mos'] : null;
} }
$data_body[$p] .= '</td>'; $data_body[$p] .= '</td>';
$data_body[$p] .= '<td width="2%"></td>';
$data_body[$p] .= '<td width="15%">'.ucwords(strtolower(str_replace("_", " ", $fields['hangup_cause']))).'</td>'; 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] .= '<td align="right">';
$data_body[$p] .= $fields[$field_name];
$data_body[$p] .= '</td>';
}
}
}
$data_body[$p] .= '<td>&nbsp;</td>';
$data_body[$p] .= '<td>'.ucwords(strtolower(str_replace("_", " ", $fields['hangup_cause']))).'</td>';
$data_body[$p] .= '</tr>'; $data_body[$p] .= '</tr>';
$z++; $z++;
@@ -212,13 +241,13 @@ else {
$data_body_chunk .= $data_body_row; $data_body_chunk .= $data_body_row;
} }
$data_body_chunk .= $data_end; $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_chunk);
unset($data_body); unset($data_body);
$p = 0; $p = 0;
//add new page //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 //write divider
$data_footer = '<tr><td colspan="12"></td></tr>'; $data_footer = '<tr><td colspan="'.$columns.'"></td></tr>';
//write totals //write totals
$data_footer .= '<tr>'; $data_footer .= '<tr>';
@@ -241,7 +270,7 @@ else {
$data_footer .= '</tr>'; $data_footer .= '</tr>';
//write divider //write divider
$data_footer .= '<tr><td colspan="12"><hr></td></tr>'; $data_footer .= '<tr><td colspan="'.$columns.'"><hr></td></tr>';
//write averages //write averages
$data_footer .= '<tr>'; $data_footer .= '<tr>';
@@ -256,11 +285,11 @@ else {
$data_footer .= '</tr>'; $data_footer .= '</tr>';
//write divider //write divider
$data_footer .= '<tr><td colspan="12"><hr></td></tr>'; $data_footer .= '<tr><td colspan="'.$columns.'"><hr></td></tr>';
//add last page //add last page
if ($p >= 55) { if ($p >= 55) {
$pdf -> AddPage('L', array($page_width, $page_height)); $pdf->AddPage('L', array($page_width, $page_height));
} }
//output remaining data //output remaining data
$data_body_chunk = $data_start.$data_head; $data_body_chunk = $data_start.$data_head;
@@ -268,7 +297,7 @@ else {
$data_body_chunk .= $data_body_row; $data_body_chunk .= $data_body_row;
} }
$data_body_chunk .= $data_footer.$data_end; $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); unset($data_body_chunk);
//define file name //define file name