original push
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/CSV.php
|
||||
Desc. : v3 - Class pembuatan file CSV
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 2rd, 2011.
|
||||
Last Modified : May 6th, 2021.
|
||||
|
||||
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Data;
|
||||
|
||||
define( DELI_CSV, ";" );
|
||||
define( CRLF_CSV, "\r\n" );
|
||||
|
||||
final class CSV {
|
||||
private $__avalue = array();
|
||||
private $__atabel = array();
|
||||
|
||||
public function add_field($tnama="", $ffunc="") {
|
||||
$this->__atabel[] = array($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 = "";
|
||||
// add header
|
||||
$tmp_out = "";
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/Cache.php
|
||||
Desc. : v3 - Class cache aplikasi
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : March 16th, 2008.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2008 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Data;
|
||||
|
||||
use MatthiasMullie\Minify;
|
||||
|
||||
final class Cache {
|
||||
private $__cachedays = 0;
|
||||
private $__cachedir = "";
|
||||
private $__cssdir = "";
|
||||
private $__localedir = "";
|
||||
private $__jsdir = "";
|
||||
private $__jsapp = "";
|
||||
private $__realpath = "";
|
||||
private $__ini = array();
|
||||
protected $__db = null;
|
||||
|
||||
public function __construct($db = null){
|
||||
if (is_resource($db)) { $this->__db = $db; }
|
||||
else $this->__db = new \siaupheng\fonia3\DB\MySQL();
|
||||
|
||||
$rootdir = $_SESSION['__WEB_APP']['REAL_PATH'];
|
||||
$this->__cachedir = $rootdir . 'cache/';
|
||||
$this->__cssdir = __DIR__ . '/../../assets/css/';
|
||||
$this->__localedir = $rootdir . 'assets/locale/';
|
||||
$this->__jsdir = __DIR__ . '/../../assets/js/';
|
||||
$this->__jsapp = $rootdir . 'apps/js/';
|
||||
$this->__realpath = $rootdir;
|
||||
if (!file_exists($this->__cachedir . "cache.ini")) {
|
||||
$this->__ini = array('css'=>array('login_stamp'=>"0",'login_file'=>"",'index_stamp'=>"0",'index_file'=>""), 'js'=>array('login_stamp'=>"0",'login_file'=>"",'index_stamp'=>"0",'index_file'=>""));
|
||||
$this->save_ini();
|
||||
}
|
||||
$this->__ini = parse_ini_file($this->__cachedir . "cache.ini", true);
|
||||
}
|
||||
|
||||
private function gen_file($type="css", $mode="index") {
|
||||
$afile = array();
|
||||
if ($type == "css") {
|
||||
$_afile = array_unique($GLOBALS['A_CSS']);
|
||||
foreach ($_afile as $__key => $val) {
|
||||
$afile[] = $this->__cssdir .$val;
|
||||
}
|
||||
if (file_exists($this->__realpath . 'assets/css/')) {
|
||||
if ($handle = opendir($this->__realpath . 'assets/css/')) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file == '.' || $file == '..' || is_dir($this->__realpath . 'assets/css/'.$file)) continue;
|
||||
$afile[] = $this->__realpath . 'assets/css/' . $file;
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
} else if ($type == "js") {
|
||||
$_afile = array_unique($GLOBALS['A_JS']);
|
||||
foreach ($_afile as $__key => $val) {
|
||||
$afile[] = $this->__jsdir .$val;
|
||||
}
|
||||
if (file_exists($this->__realpath . 'assets/js/')) {
|
||||
if ($handle = opendir($this->__realpath . 'assets/js/')) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file == '.' || $file == '..' || is_dir($this->__realpath . 'assets/js/'.$file)) continue;
|
||||
$afile[] = $this->__realpath . 'assets/js/' . $file;
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
// add locale file
|
||||
$ljs = (isset($_SESSION['__WEB_USER']['LOCALE'])?$_SESSION['__WEB_USER']['LOCALE']:$_SESSION['__WEB_APP']['DEF_LOCALE']).".js";
|
||||
if ($handle = opendir($this->__localedir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
$file = $this->__localedir . $file;
|
||||
if (substr($file, -5) == $ljs) $afile[] = $this->__localedir .basename(str_replace("\\", "/", $file));
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
$afile[] = $this->__jsapp . $mode . ".js";
|
||||
} else if ($type == "app") {
|
||||
$afile[] = $this->__jsapp ."sys/profile.js";
|
||||
$afile[] = $this->__jsapp ."sys/chpasswd.js";
|
||||
$amenu = explode(",", $_SESSION['__WEB_USER']['Menu_Grup'] .",". $_SESSION['__WEB_USER']['Menu']);
|
||||
$tmenu = implode("','", array_unique($amenu));
|
||||
$this->__db->Query("SELECT * FROM app_menu WHERE Link<>'' AND Kode IN ('".$tmenu."') ORDER BY Level, Urut");
|
||||
while ($this->__db->Next()) {
|
||||
$afile[] = $this->__jsapp . str_replace("php", "js", $this->__db->Row("Link"));
|
||||
}
|
||||
}
|
||||
return $afile;
|
||||
}
|
||||
|
||||
private function check_file($afile) {
|
||||
$lastmod = 0;
|
||||
foreach ($afile as $nfile) {
|
||||
if (file_exists($nfile)) {
|
||||
$lastmod += filemtime($nfile);
|
||||
}
|
||||
}
|
||||
if ($this->__cachedays > 0) {
|
||||
if ($handle = opendir($this->__cachedir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file == '.' || $file == '..' || is_dir($this->__cachedir.$file)) continue;
|
||||
if ((time()-filemtime($this->__cachedir.$file)) > (86400*$this->__cachedays)) {
|
||||
unlink($this->__cachedir . $file);
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
return $lastmod;
|
||||
}
|
||||
|
||||
private function create_cache($type="css", $mode="index", $afile=array(), $lastmod=0) {
|
||||
$contents = '';
|
||||
$bpublic = ($_SERVER['SERVER_ADDR'] == "127.0.0.1") ? false : true;
|
||||
if ($bpublic == true) {
|
||||
if ($type=="css") {
|
||||
$smini = new Minify\CSS;
|
||||
} else {
|
||||
$smini = new Minify\JS;
|
||||
}
|
||||
}
|
||||
foreach ($afile as $nfile) {
|
||||
if (file_exists($nfile)) {
|
||||
if ($bpublic == true) {
|
||||
$smini->add($nfile);
|
||||
} else {
|
||||
$contents .= "\n". file_get_contents($nfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($bpublic) $contents = $smini->minify();
|
||||
$cachefile = md5($mode . $lastmod) . ($type=="app"?".app":"") . ($type=="css" ? ".css" : ".js");
|
||||
file_put_contents($this->__cachedir . $cachefile, $contents);
|
||||
if ($type == "app") return;
|
||||
$this->__ini[$type][$mode.'_stamp'] = $lastmod;
|
||||
$this->__ini[$type][$mode.'_file'] = $cachefile;
|
||||
$this->save_ini();
|
||||
}
|
||||
|
||||
private function save_ini(){
|
||||
$content = "";
|
||||
foreach ($this->__ini as $key => $elem) {
|
||||
$content .= ($content==""?"":"\n"). "[".$key."]\n";
|
||||
foreach ($elem as $key2 => $elem2) {
|
||||
if ($elem2=="") $content .= $key2." = \n";
|
||||
else $content .= $key2." = \"".$elem2."\"\n";
|
||||
}
|
||||
}
|
||||
file_put_contents($this->__cachedir . "cache.ini", $content);
|
||||
}
|
||||
|
||||
public function Main($type="css") {
|
||||
$mode = (isset($_SESSION['__WEB_USER']) && is_array($_SESSION['__WEB_USER']) && $_SESSION['__WEB_USER']['UserID']>0) ? "index" : "login";
|
||||
$afile = $this->gen_file($type, $mode);
|
||||
$lastmod = $this->check_file($afile);
|
||||
if ($lastmod <> intval($this->__ini[$type][$mode.'_stamp']) || !file_exists($this->__cachedir . $this->__ini[$type][$mode.'_file'])) {
|
||||
$this->create_cache($type, $mode, $afile, $lastmod);
|
||||
}
|
||||
return $_SESSION['__WEB_APP']['WEB_PATH'] ."cache/". $this->__ini[$type][$mode.'_file'];
|
||||
}
|
||||
|
||||
public function Apps() {
|
||||
$id_user = (isset($_SESSION['__WEB_USER']) && is_array($_SESSION['__WEB_USER'])) ? $_SESSION['__WEB_USER']['UserID'] : 0;
|
||||
$afile = $this->gen_file("app", $id_user);
|
||||
$lastmod = $this->check_file($afile);
|
||||
$appfile = md5($id_user . $lastmod) . ".app.js";
|
||||
if (!file_exists($this->__cachedir . $appfile)) {
|
||||
$this->create_cache("app", $id_user, $afile, $lastmod);
|
||||
}
|
||||
return $_SESSION['__WEB_APP']['WEB_PATH'] ."cache/". $appfile;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /Data/PDF.php
|
||||
Desc. : v3 - Class pembuatan file PDF
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 18th, 2015.
|
||||
Last Modified : May 8th, 2021.
|
||||
|
||||
(c) 2015 - 2021, 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace siaupheng\fonia3\Data;
|
||||
|
||||
use Mpdf;
|
||||
|
||||
final class PDF {
|
||||
private $__avalue = array();
|
||||
private $__atabel = array();
|
||||
private $__theader = "";
|
||||
private $__tcolname = "";
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="", $nkol=1) {
|
||||
$this->__atabel[] = array($tnama, $nlebar.'%', $ffunc, $talign, $nkol);
|
||||
}
|
||||
|
||||
public function show_fields() {
|
||||
$tmp_out = "<thead><tr>";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
if ($this->__atabel[$i][4]==0) continue;
|
||||
$tmp_out .= $this->set_align($this->__atabel[$i][0], $this->__atabel[$i][1], "C", false, true, $this->__atabel[$i][4]);
|
||||
}
|
||||
$tmp_out .= "</tr></thead>";
|
||||
$this->__tcolname = $tmp_out;
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
$this->__avalue = array();
|
||||
$this->__theader = "";
|
||||
$this->__tcolname = "";
|
||||
}
|
||||
|
||||
public function set_header($tlapor="", $tperiod="") {
|
||||
$thasil = '<div style="text-align:center;font-size:12pt;"><b>'.strtoupper($_SESSION['__WEB_APP']['REG_NAME']);
|
||||
$thasil .= (($tlapor=="") ? "" : '<br>'.$tlapor) . '</b>';
|
||||
$thasil .= ($tperiod=="") ? "" : '<br><span style="font-size:11pt;">'.$tperiod.'</span>';
|
||||
$thasil .= '</div><br>';
|
||||
$this->__theader = $thasil;
|
||||
}
|
||||
|
||||
public function add_value() {
|
||||
$tmp_arr = func_get_args();
|
||||
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
|
||||
$tmp_out = "<tr>";
|
||||
for ($i=0; $i<count($this->__atabel); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];
|
||||
if (is_array($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = $this->__atabel[$i][2][$tmp_val];
|
||||
} else if (function_exists($this->__atabel[$i][2]) && trim($tmp_val)<>"") {
|
||||
$tmp_val = call_user_func($this->__atabel[$i][2], $tmp_val);
|
||||
}
|
||||
$tmp_val = $this->set_align($tmp_val, $this->__atabel[$i][1], $this->__atabel[$i][3]);
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
}
|
||||
|
||||
public function add_span() {
|
||||
$tmp_arr = func_get_args();
|
||||
$tmp_out = "<tr>";
|
||||
for ($i=0; $i<count($tmp_arr); $i++) {
|
||||
$tmp_val = $tmp_arr[$i];// CONTENT, COLSPAN=1, L, FUNC
|
||||
if (function_exists($tmp_val[3]) && trim($tmp_val[0])<>"") {
|
||||
$tmp_val[0] = call_user_func($tmp_val[3], $tmp_val[0]);
|
||||
}
|
||||
$tmp_val = $this->set_align($tmp_val[0], 0, $tmp_val[2], false, false, $tmp_val[1]);
|
||||
$tmp_out .= $tmp_val;
|
||||
}
|
||||
$tmp_out .= "</tr>";
|
||||
$this->__avalue[] = $tmp_out;
|
||||
}
|
||||
|
||||
public function add_empty() {
|
||||
$this->__avalue[] = $this->set_align(" ", 0, "L,NB", true);
|
||||
}
|
||||
|
||||
public function add_stamp($ctk_ke=1, $bnama=false) {
|
||||
$this->__avalue[] = $this->set_align($_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):""), 0, "L,NB", true);
|
||||
}
|
||||
|
||||
public function get_stamp($ctk_ke=1, $bnama=false) {
|
||||
return $_SESSION['__WEB_APP']['APP_NAME']."v".$_SESSION['__WEB_APP']['APP_VER'].date("\@ymd.His")."-".user_id(3).(($bnama==true)?"/".strtoupper(user_user()):"").(($ctk_ke>0)?"#".isi_nol($ctk_ke,2):"");
|
||||
}
|
||||
|
||||
public function createPDF($nama_file = "Nama_File.pdf", $nfontz = 8, $orien = "P") {
|
||||
$html = '
|
||||
<style>
|
||||
#pdf_area {
|
||||
width: 100%;
|
||||
color: #000;
|
||||
}
|
||||
#pdf_area p { margin: 0; padding: 0; }
|
||||
#pdf_cont table {
|
||||
border: 1px solid #ccc;
|
||||
border-spacing: 0;
|
||||
border-collapse: collapse;
|
||||
overflow: auto;
|
||||
}
|
||||
#pdf_cont table th, #pdf_cont table td {
|
||||
font-size: 12pt;
|
||||
text-align: left;
|
||||
}
|
||||
#pdf_cont table th {
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
padding: 2mm;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
#pdf_cont table td {
|
||||
padding: 1mm;
|
||||
}
|
||||
#pdf_cont table td.left { text-align: left; }
|
||||
#pdf_cont table td.center { text-align: center; }
|
||||
#pdf_cont table td.right { text-align: right; }
|
||||
#pdf_cont table td.bold { font-weight: bold; }
|
||||
#pdf_cont table td.italic { font-style: italic; }
|
||||
</style>
|
||||
<body class="pdf_area">
|
||||
<htmlpagefooter name="RepFoot">
|
||||
<table width="100%" style="border:none;"><tr><td width="50%" style="text-align:left;border:none;">'.$this->get_stamp(1, true).'</td><td width="50%" style="text-align:right;font-style:italic;border:none;">Halaman : {PAGENO} dari {nbpg}</td></tr></table>
|
||||
</htmlpagefooter>
|
||||
<sethtmlpagefooter name="RepFoot" show-this-page="1" value="on" />';
|
||||
if ($this->__theader<>"") $html .= $this->__theader;
|
||||
$html .= '<div id="pdf_cont"><table>';
|
||||
if ($this->__tcolname<>"") $html .= $this->__tcolname;
|
||||
$html .= '<tbody>';
|
||||
|
||||
// content out
|
||||
for ($i=0; $i<count($this->__avalue); $i++) {
|
||||
$html .= $this->__avalue[$i];
|
||||
}
|
||||
$html .= '</tbody></table></div></div></body>';
|
||||
$mpdf = new mPDF('c', 'A4'.($orien=="L"?"-L":""), $nfontz, '', 5, 5, 5, 10, 5, 5);
|
||||
$mpdf->useSubstitutions = false;
|
||||
$mpdf->WriteHTML($html);
|
||||
$mpdf->Output($nama_file.".pdf", "I");
|
||||
}
|
||||
|
||||
public function set_align($ttext, $nlen, $tdir="L", $bline=false, $bhead=false, $ncol=1) {
|
||||
$tstyle = $this->create_style($tdir);
|
||||
if (strpos(strtolower($ttext), "<tr>")===false) { //jika tidak ada <tr> up 2011-04-14
|
||||
if ($bline===true) {
|
||||
return '<tr><td colspan="'.count($this->__atabel).'" class="'.$tstyle.'">'.$ttext."</td></tr>";
|
||||
} else {
|
||||
return (($bhead===true)?"<th":"<td").(($ncol>1)?' colspan="'.$ncol.'"':"").' class="'.$tstyle.'" '.(($bhead===true)?'width="'.$nlen.'"':"").">".$ttext.(($bhead===true)?"</th>":"</td>");
|
||||
}
|
||||
} else {
|
||||
return (($bline===true) ? $ttext : (($bhead===true)?"<th":"<td").(($ncol>1)?" colspan=\"".$ncol."\"":"")." class=\"".$tstyle." \" ".(($bhead===true)?"width=\"".$nlen."\"":"").">".$ttext.(($bhead===true)?"</th>":"</td>"));
|
||||
}
|
||||
}
|
||||
|
||||
private function create_style($tstyle="L") {
|
||||
$apad = array("L"=>"left", "R"=>"right", "C"=>"center", "NB"=>"nb", "NL"=>"noleft", "NR"=>"noright", "B"=>"bold", "I"=>"italic");
|
||||
$_astyle = explode(",", $tstyle);
|
||||
$thasil = "";
|
||||
foreach ($_astyle as $_key => $_val) {
|
||||
$thasil .= " ".$apad[$_val];
|
||||
}
|
||||
return substr($thasil,1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user