If show all is used on the export then remove the domain name from the file name.

This commit is contained in:
markjcrane
2016-02-23 19:33:16 -07:00
parent c0ddb2d857
commit 8b2cb82df7
+219 -209
View File
@@ -42,238 +42,248 @@ else {
$rows_per_page = 0; $rows_per_page = 0;
require_once "xml_cdr_inc.php"; require_once "xml_cdr_inc.php";
$export_format = check_str($_REQUEST['export_format']); //get the format
$export_format = check_str($_REQUEST['export_format']);
if ($export_format == 'csv') { //get the format
$showall = check_str($_REQUEST['showall']);
//define file name //exprot the csv
$csv_filename = "cdr_".$_SESSION['domain_name']."_".date("Ymd_His").".csv"; if ($export_format == 'csv') {
//set the http headers //define file name
header('Content-type: application/octet-binary'); if ($_REQUEST['showall'] == 'true') {
header('Content-Disposition: attachment; filename='.$csv_filename); $csv_filename = "cdr_".date("Ymd_His").".csv";
}
//set the csv headers else {
$z = 0; $csv_filename = "cdr_".$_SESSION['domain_name']."_".date("Ymd_His").".csv";
foreach($result[0] as $key => $val) {
if ($key != "xml" && $key != "json") {
if ($z == 0) {
echo '"'.$key.'"';
}
else {
echo ',"'.$key.'"';
}
} }
$z++;
}
echo "\n";
//show the csv data //set the http headers
$x=0; header('Content-type: application/octet-binary');
while(true) { header('Content-Disposition: attachment; filename='.$csv_filename);
//set the csv headers
$z = 0; $z = 0;
foreach($result[0] as $key => $val) { foreach($result[0] as $key => $val) {
if ($key != "xml" && $key != "json") { if ($key != "xml" && $key != "json") {
if ($z == 0) { if ($z == 0) {
echo '"'.$result[$x][$key].'"'; echo '"'.$key.'"';
} }
else { else {
echo ',"'.$result[$x][$key].'"'; echo ',"'.$key.'"';
} }
} }
$z++; $z++;
} }
echo "\n"; echo "\n";
++$x;
if ($x > ($result_count-1)) {
break;
}
//$row++;
}
} //show the csv data
else if ($export_format == 'pdf') { $x=0;
while(true) {
//load pdf libraries $z = 0;
require_once("resources/tcpdf/tcpdf.php"); foreach($result[0] as $key => $val) {
require_once("resources/fpdi/fpdi.php"); if ($key != "xml" && $key != "json") {
if ($z == 0) {
//determine page size echo '"'.$result[$x][$key].'"';
switch ($_SESSION['fax']['page_size']['text']) { }
case 'a4' : else {
$page_width = 11.7; //in echo ',"'.$result[$x][$key].'"';
$page_height = 8.3; //in }
break; }
case 'legal' : $z++;
$page_width = 14; //in }
$page_height = 8.5; //in echo "\n";
break; ++$x;
case 'letter' : if ($x > ($result_count-1)) {
default : break;
$page_width = 11; //in }
$page_height = 8.5; //in }
} }
// initialize pdf //export as a PDF
$pdf = new FPDI('L', 'in'); if ($export_format == 'pdf') {
$pdf -> SetAutoPageBreak(false);
$pdf -> setPrintHeader(false); //load pdf libraries
$pdf -> setPrintFooter(false); require_once("resources/tcpdf/tcpdf.php");
$pdf -> SetMargins(0.5, 0.5, 0.5, true); require_once("resources/fpdi/fpdi.php");
//set default font //determine page size
$pdf -> SetFont('helvetica', '', 7); switch ($_SESSION['fax']['page_size']['text']) {
//add new page case 'a4' :
$pdf -> AddPage('L', array($page_width, $page_height)); $page_width = 11.7; //in
$page_height = 8.3; //in
$chunk = 0; break;
case 'legal' :
//write the table column headers $page_width = 14; //in
$data_start = '<table cellpadding="0" cellspacing="0" border="0" width="100%">'; $page_height = 8.5; //in
$data_end = '</table>'; break;
case 'letter' :
$data_head = '<tr>'; default :
$data_head .= '<td width="7.5%"><b>'.$text['label-direction'].'</b></td>'; $page_width = 11; //in
$data_head .= '<td width="15%"><b>'.$text['label-cid-name'].'</b></td>'; $page_height = 8.5; //in
$data_head .= '<td width="8.5%"><b>'.$text['label-cid-number'].'</b></td>'; }
$data_head .= '<td width="11%"><b>'.$text['label-destination'].'</b></td>';
$data_head .= '<td width="11%"><b>'.$text['label-start'].'</b></td>'; // initialize pdf
$data_head .= '<td width="4%" align="right"><b>'.$text['label-tta'].'</b></td>'; $pdf = new FPDI('L', 'in');
$data_head .= '<td width="8.5%" align="right"><b>'.$text['label-duration'].'</b></td>'; $pdf -> SetAutoPageBreak(false);
$data_head .= '<td width="8.5%" align="right"><b>'.$text['label-billsec'].'</b></td>'; $pdf -> setPrintHeader(false);
$data_head .= '<td width="7%" align="right"><b>'."PDD".'</b></td>'; $pdf -> setPrintFooter(false);
$data_head .= '<td width="5%" align="right"><b>'."MOS".'</b></td>'; $pdf -> SetMargins(0.5, 0.5, 0.5, true);
$data_head .= '<td width="2%"></td>';
$data_head .= '<td width="15%"><b>'.$text['label-hangup_cause'].'</b></td>'; //set default font
$data_head .= '</tr>'; $pdf -> SetFont('helvetica', '', 7);
$data_head .= '<tr><td colspan="12"><hr></td></tr>'; //add new page
$pdf -> AddPage('L', array($page_width, $page_height));
//initialize total variables
$total['duration'] = 0; $chunk = 0;
$total['billmsec'] = 0;
$total['pdd_ms'] = 0; //write the table column headers
$total['rtp_audio_in_mos'] = 0; $data_start = '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
$total['tta'] = 0; $data_end = '</table>';
//write the row cells $data_head = '<tr>';
$z = 0; // total counter $data_head .= '<td width="7.5%"><b>'.$text['label-direction'].'</b></td>';
$p = 0; // per page counter $data_head .= '<td width="15%"><b>'.$text['label-cid-name'].'</b></td>';
if (sizeof($result) > 0) { $data_head .= '<td width="8.5%"><b>'.$text['label-cid-number'].'</b></td>';
foreach($result as $cdr_num => $fields) { $data_head .= '<td width="11%"><b>'.$text['label-destination'].'</b></td>';
$data_body[$p] .= '<tr>'; $data_head .= '<td width="11%"><b>'.$text['label-start'].'</b></td>';
$data_body[$p] .= '<td width="7.5%">'.$text['label-'.$fields['direction']].'</td>'; $data_head .= '<td width="4%" align="right"><b>'.$text['label-tta'].'</b></td>';
$data_body[$p] .= '<td width="15%">'.$fields['caller_id_name'].'</td>'; $data_head .= '<td width="8.5%" align="right"><b>'.$text['label-duration'].'</b></td>';
$data_body[$p] .= '<td width="8.5%">'.$fields['caller_id_number'].'</td>'; $data_head .= '<td width="8.5%" align="right"><b>'.$text['label-billsec'].'</b></td>';
$data_body[$p] .= '<td width="11%">'.format_phone($fields['destination_number']).'</td>'; $data_head .= '<td width="7%" align="right"><b>'."PDD".'</b></td>';
$data_body[$p] .= '<td width="11%">'.$fields['start_stamp'].'</td>'; $data_head .= '<td width="5%" align="right"><b>'."MOS".'</b></td>';
$total['tta'] += ($fields['tta'] > 0) ? $fields['tta'] : 0; $data_head .= '<td width="2%"></td>';
$data_body[$p] .= '<td width="4%" align="right">'.(($fields['tta'] > 0) ? $fields['tta'].'s' : null).'</td>'; $data_head .= '<td width="15%"><b>'.$text['label-hangup_cause'].'</b></td>';
$seconds = ($fields['hangup_cause'] == "ORIGINATOR_CANCEL") ? $fields['duration'] : round(($fields['billmsec'] / 1000), 0, PHP_ROUND_HALF_UP); $data_head .= '</tr>';
$total['duration'] += $seconds; $data_head .= '<tr><td colspan="12"><hr></td></tr>';
$data_body[$p] .= '<td width="8.5%" align="right">'.gmdate("G:i:s", $seconds).'</td>';
$total['billmsec'] += $fields['billmsec']; //initialize total variables
$data_body[$p] .= '<td width="8.5%" align="right">'.number_format(round($fields['billmsec'] / 1000, 2), 2).'s</td>'; $total['duration'] = 0;
$data_body[$p] .= '<td width="7%" align="right">'; $total['billmsec'] = 0;
if (permission_exists("xml_cdr_pdd")) { $total['pdd_ms'] = 0;
$total['pdd_ms'] += $fields['pdd_ms']; $total['rtp_audio_in_mos'] = 0;
$data_body[$p] .= number_format(round($fields['pdd_ms'] / 1000, 2), 2).'s'; $total['tta'] = 0;
}
$data_body[$p] .= '</td>'; //write the row cells
$data_body[$p] .= '<td width="5%" align="right">'; $z = 0; // total counter
if (permission_exists("xml_cdr_mos")) { $p = 0; // per page counter
$total['rtp_audio_in_mos'] += $fields['rtp_audio_in_mos']; if (sizeof($result) > 0) {
$data_body[$p] .= (strlen($total['rtp_audio_in_mos']) > 0) ? $fields['rtp_audio_in_mos'] : null; foreach($result as $cdr_num => $fields) {
} $data_body[$p] .= '<tr>';
$data_body[$p] .= '</td>'; $data_body[$p] .= '<td width="7.5%">'.$text['label-'.$fields['direction']].'</td>';
$data_body[$p] .= '<td width="2%"></td>'; $data_body[$p] .= '<td width="15%">'.$fields['caller_id_name'].'</td>';
$data_body[$p] .= '<td width="15%">'.ucwords(strtolower(str_replace("_", " ", $fields['hangup_cause']))).'</td>'; $data_body[$p] .= '<td width="8.5%">'.$fields['caller_id_number'].'</td>';
$data_body[$p] .= '</tr>'; $data_body[$p] .= '<td width="11%">'.format_phone($fields['destination_number']).'</td>';
$data_body[$p] .= '<td width="11%">'.$fields['start_stamp'].'</td>';
$z++; $total['tta'] += ($fields['tta'] > 0) ? $fields['tta'] : 0;
$p++; $data_body[$p] .= '<td width="4%" 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);
if ($p == 60) { $total['duration'] += $seconds;
//output data $data_body[$p] .= '<td width="8.5%" align="right">'.gmdate("G:i:s", $seconds).'</td>';
$data_body_chunk = $data_start.$data_head; $total['billmsec'] += $fields['billmsec'];
foreach ($data_body as $data_body_row) { $data_body[$p] .= '<td width="8.5%" align="right">'.number_format(round($fields['billmsec'] / 1000, 2), 2).'s</td>';
$data_body_chunk .= $data_body_row; $data_body[$p] .= '<td width="7%" align="right">';
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] .= '</td>';
$data_body[$p] .= '<td width="5%" align="right">';
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] .= '</td>';
$data_body[$p] .= '<td width="2%"></td>';
$data_body[$p] .= '<td width="15%">'.ucwords(strtolower(str_replace("_", " ", $fields['hangup_cause']))).'</td>';
$data_body[$p] .= '</tr>';
$z++;
$p++;
if ($p == 60) {
//output data
$data_body_chunk = $data_start.$data_head;
foreach ($data_body as $data_body_row) {
$data_body_chunk .= $data_body_row;
}
$data_body_chunk .= $data_end;
$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));
} }
$data_body_chunk .= $data_end;
$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));
} }
} }
//write divider
$data_footer = '<tr><td colspan="12"></td></tr>';
//write totals
$data_footer .= '<tr>';
$data_footer .= '<td><b>'.$text['label-total'].'</b></td>';
$data_footer .= '<td>'.$z.'</td>';
$data_footer .= '<td colspan="3"></td>';
$data_footer .= '<td align="right"><b>'.number_format(round($total['tta'], 1), 0).'s</b></td>';
$data_footer .= '<td align="right"><b>'.gmdate("G:i:s", $total['duration']).'</b></td>';
$data_footer .= '<td align="right"><b>'.gmdate("G:i:s", round($total['billmsec'] / 1000, 0)).'</b></td>';
$data_footer .= '<td align="right"><b>'.number_format(round(($total['pdd_ms'] / 1000), 2), 2).'s</b></td>';
$data_footer .= '<td colspan="2"></td>';
$data_footer .= '</tr>';
//write divider
$data_footer .= '<tr><td colspan="12"><hr></td></tr>';
//write averages
$data_footer .= '<tr>';
$data_footer .= '<td><b>'.$text['label-average'].'</b></td>';
$data_footer .= '<td colspan="4"></td>';
$data_footer .= '<td align="right"><b>'.round(($total['tta'] / $z), 1).'</b></td>';
$data_footer .= '<td align="right"><b>'.gmdate("G:i:s", ($total['duration'] / $z)).'</b></td>';
$data_footer .= '<td align="right"><b>'.gmdate("G:i:s", round($total['billmsec'] / $z / 1000, 0)).'</b></td>';
$data_footer .= '<td align="right"><b>'.number_format(round(($total['pdd_ms'] / $z / 1000), 2), 2).'s</b></td>';
$data_footer .= '<td align="right"><b>'.round(($total['rtp_audio_in_mos'] / $z), 2).'</b></td>';
$data_footer .= '<td></td>';
$data_footer .= '</tr>';
//write divider
$data_footer .= '<tr><td colspan="12"><hr></td></tr>';
//add last page
if ($p >= 55) {
$pdf -> AddPage('L', array($page_width, $page_height));
}
//output remaining data
$data_body_chunk = $data_start.$data_head;
foreach ($data_body as $data_body_row) {
$data_body_chunk .= $data_body_row;
}
$data_body_chunk .= $data_footer.$data_end;
$pdf -> writeHTML($data_body_chunk, true, false, false, false, '');
unset($data_body_chunk);
//define file name
$pdf_filename = "cdr_".$_SESSION['domain_name']."_".date("Ymd_His").".pdf";
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="'.$pdf_filename.'"');
header("Content-Type: application/pdf");
header('Accept-Ranges: bytes');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past
// push pdf download
$pdf -> Output($pdf_filename, 'D'); // Display [I]nline, Save to [F]ile, [D]ownload
} }
//write divider
$data_footer = '<tr><td colspan="12"></td></tr>';
//write totals
$data_footer .= '<tr>';
$data_footer .= '<td><b>'.$text['label-total'].'</b></td>';
$data_footer .= '<td>'.$z.'</td>';
$data_footer .= '<td colspan="3"></td>';
$data_footer .= '<td align="right"><b>'.number_format(round($total['tta'], 1), 0).'s</b></td>';
$data_footer .= '<td align="right"><b>'.gmdate("G:i:s", $total['duration']).'</b></td>';
$data_footer .= '<td align="right"><b>'.gmdate("G:i:s", round($total['billmsec'] / 1000, 0)).'</b></td>';
$data_footer .= '<td align="right"><b>'.number_format(round(($total['pdd_ms'] / 1000), 2), 2).'s</b></td>';
$data_footer .= '<td colspan="2"></td>';
$data_footer .= '</tr>';
//write divider
$data_footer .= '<tr><td colspan="12"><hr></td></tr>';
//write averages
$data_footer .= '<tr>';
$data_footer .= '<td><b>'.$text['label-average'].'</b></td>';
$data_footer .= '<td colspan="4"></td>';
$data_footer .= '<td align="right"><b>'.round(($total['tta'] / $z), 1).'</b></td>';
$data_footer .= '<td align="right"><b>'.gmdate("G:i:s", ($total['duration'] / $z)).'</b></td>';
$data_footer .= '<td align="right"><b>'.gmdate("G:i:s", round($total['billmsec'] / $z / 1000, 0)).'</b></td>';
$data_footer .= '<td align="right"><b>'.number_format(round(($total['pdd_ms'] / $z / 1000), 2), 2).'s</b></td>';
$data_footer .= '<td align="right"><b>'.round(($total['rtp_audio_in_mos'] / $z), 2).'</b></td>';
$data_footer .= '<td></td>';
$data_footer .= '</tr>';
//write divider
$data_footer .= '<tr><td colspan="12"><hr></td></tr>';
//add last page
if ($p >= 55) {
$pdf -> AddPage('L', array($page_width, $page_height));
}
//output remaining data
$data_body_chunk = $data_start.$data_head;
foreach ($data_body as $data_body_row) {
$data_body_chunk .= $data_body_row;
}
$data_body_chunk .= $data_footer.$data_end;
$pdf -> writeHTML($data_body_chunk, true, false, false, false, '');
unset($data_body_chunk);
//define file name
$pdf_filename = "cdr_".$_SESSION['domain_name']."_".date("Ymd_His").".pdf";
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="'.$pdf_filename.'"');
header("Content-Type: application/pdf");
header('Accept-Ranges: bytes');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // date in the past
// push pdf download
$pdf -> Output($pdf_filename, 'D'); // Display [I]nline, Save to [F]ile, [D]ownload
}
?> ?>