first commit

This commit is contained in:
2026-07-25 16:54:11 +07:00
commit 36395c2b55
84 changed files with 40698 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
<?php
/*******************************************************************
Module : /Data/CSV.php
Desc. : Class pembuatan file CSV
Created By : Siau Pheng ([email protected]).
Created Date : April 2rd, 2011.
Last Modified : July 25th, 2026.
(c) 2011 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Data;
define( DELI_CSV, ";" );
define( CRLF_CSV, "\r\n" );
final class CSV {
private $__avalue = [];
private $__atabel = [];
public function add_field($tnama="", $ffunc="") {
$this->__atabel[] = [$tnama, $ffunc];
}
public function add_value() {
$tmp_arr = func_get_args();
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
$tmp_out = "";
for ($i=0; $i<count($this->__atabel); $i++) {
$tmp_val = $tmp_arr[$i];
if (is_array($this->__atabel[$i][1]) && trim($tmp_val)<>"") {
$tmp_val = $this->__atabel[$i][1][$tmp_val];
} else if (function_exists($this->__atabel[$i][1]) && trim($tmp_val)<>"") {
$tmp_val = call_user_func($this->__atabel[$i][1], $tmp_val);
}
$tmp_out .= DELI_CSV . $tmp_val;
}
$tmp_out = substr($tmp_out, 1);
$this->__avalue[] = $tmp_out;
}
public function download($nama_file="export.csv") {
$out = ""; $tmp_out = "";
// add header
for ($i=0; $i<count($this->__atabel); $i++) {
$tmp_out .= DELI_CSV . $this->__atabel[$i][0];
}
$out .= substr($tmp_out, 1) . CRLF_CSV;
// add content
for ($i=0; $i<count($this->__avalue); $i++) {
$out .= $this->__avalue[$i] . CRLF_CSV;
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$nama_file."\"");
echo $out;
}
}
?>