| Server IP : 172.67.201.108 / Your IP : 216.73.217.74 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/tgnewprod/admin/classes/ |
Upload File : |
<?php
class lcs_db_report_csv extends lcs_db_report_base implements report_interface {
protected $csv_text = '';
const CRLF = "\r\n";
public function __construct() {
}
public function report_start() {
}
public function report_end() {
}
public function header_start() {
}
public function header_end() {
}
public function header_row_start() {
}
public function header_row_end() {
$this->csv_text = $this->remove_last_comma($this->csv_text);
$this->csv_text .= self::CRLF;
}
public function header_cell_add($data = '', $args = []) {
$this->csv_text .= '"'.$this->escape_filter($data).'",';
}
public function footer_start() {
}
public function footer_end() {
}
public function footer_row_start() {
}
public function footer_row_end() {
}
public function footer_cell_add($data = '', $args = []) {
}
public function data_start() {
}
public function data_end() {
}
public function data_row_start() {
}
public function data_row_end() {
$this->csv_text = $this->remove_last_comma($this->csv_text);
$this->csv_text .= self::CRLF;
}
public function data_cell_add($data = '', $args = []) {
$this->csv_text .= '"'.$this->escape_filter($data).'",';
}
public function output_report($filename = '', $save_file = false) {
if (empty($filename) && !empty($_POST['save_file_name'])) :
$filename = $_POST['save_file_name'];
endif;
if (!$save_file && !empty($_POST['save_file'])) :
$save_file = true;
endif;
if ($save_file) :
$upload_dir = APP_UPLOAD_DIR . '/reports/';
if (!is_dir($upload_dir)) :
mkdir($upload_dir, 0777, true);
endif;
$filename = !empty($filename) ? $filename . '.csv' : 'Report.csv';
$upload_path = $upload_dir . $filename;
file_put_contents($upload_path, $this->csv_text);
$_POST['email_attachment_path'] = $upload_path;
else :
$file = 'Report.csv';
$content_type = 'text/csv';
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Type: '.$content_type);
//header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
echo $this->csv_text;
endif;
}
private function escape_filter($text) {
$text = strip_tags($text);
$text = str_replace('"', '""', $text);
return $text;
}
private function remove_last_comma($text) {
if (substr($text, -1) == ',') :
$text = substr($text, 0, -1);
endif;
return $text;
}
}