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
+172
View File
@@ -0,0 +1,172 @@
<?php
/*******************************************************************
Module : /App.php
Desc. : HTML5 Page Generator (jQuery & Bootstrap)
Created By : Siau Pheng ([email protected]).
Created Date : January 10th, 2008.
Last Modified : July 25th, 2026.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp;
final class App {
public $version = "4.1.0";
private $apps = [];
private $auser = [];
private $cache = null;
private $menu = null;
private $reg = null;
protected $__db = null;
protected $__form = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
$this->__form = new \siaupheng\webapp\Web\Form($this->__db);
$this->apps = $_SESSION['__WEB_APP'];
if (isset($_SESSION['__WEB_USER'])) {
$this->apps['TEMPLATE'] = "index.php";
$this->auser = $_SESSION['__WEB_USER'];
$this->auser['user_img'] = "profiles/profile.png";
if (file_exists($this->apps['REAL_PATH']."assets/images/profiles/".$this->auser['UserID'].".png")) {
$this->auser['user_img'] = "profiles/".$this->auser['UserID'].".png";
}
}
$this->reg = new \siaupheng\webapp\Web\Register($this->__db);
$this->cache = new \siaupheng\webapp\Data\Cache($this->__db);
$this->menu = new \siaupheng\webapp\Web\Menu($this->__db);
}
public function TampilApp($aoption = []) {
if ($this->reg->reg_check()) {
if (!user_logged()) {
$this->apps['TEMPLATE'] = "login.php";
}
} else {
$this->apps['TEMPLATE'] = "404.php";
}
// gunakan template khusus sesuai request
if (($aoption['PAGE_404']['value'] ?? 0) == 1) {
$this->apps['TEMPLATE'] = "404.php";
}
// loading template file {{}}
$buffer = "";
if (file_exists($this->apps['REAL_PATH']."assets/templates/".$this->apps['TEMPLATE'])) {
$buffer = file_get_contents($this->apps['REAL_PATH']."assets/templates/".$this->apps['TEMPLATE']);
$buffer = preg_replace("/(?:(?:\\/\\*(?:[^*]|(?:\\*+[^*\\/]))*\\*+\\/)|(?:(?<!\\:)\\/\\/. *))/", "", $buffer);
}
$aoption = [...$this->apps, 'CSS_JS' => ""];
// penambahan file css + js + app-js
$aoption['CSS_JS'] = '<link rel="stylesheet" type="text/css" href="'.$this->cache->Main("css").'">'."\n";
$aoption['CSS_JS'] .= '<script type="text/javascript" src="'.$this->cache->Main("js").'"></script>'."\n";
if (user_logged()) $aoption['CSS_JS'] .= '<script type="text/javascript" src="'.$this->cache->Apps().'"></script>'."\n";
$_secret = $aoption['APP_CODE'] .";". $aoption['APP_SID'] .";". $_SERVER['HTTP_HOST'] .";". $aoption['WEB_PATH'] .";". "http://".$_SERVER['HTTP_HOST'].$aoption['WEB_PATH'] .";". isMobile() .";". ($aoption['AUTH_LEVEL']?$aoption['AUTH_LEVEL']:0) .";". $this->version;
$_suser = (user_logged()) ? $this->auser['Username'] .";". $this->auser['UserID'] .";". $this->auser['Grup_MenuID'] .";". $this->auser['Level'] : "nobody;999;999;9";
$aoption['CSS_JS'] .= '<script type="text/javascript" language="javascript">'."\n";
$aoption['CSS_JS'] .= 'FoniaJS.setConfig("'.base64_encode($_secret).'", "'.base64_encode($_suser).'");';
$aoption['CSS_JS'] .= '$(document).ready(function(){';
$tnaviside = ""; $tnavihead = "";
if (user_logged()) {
$aoption['CSS_JS'] .= 'FoniaJS.loadMenu();';
$tnaviside = $this->menu->Menu_Sidebar();
$tnavihead = $this->menu->Menu_Header();
}
$aoption['CSS_JS'] .= '});';
$aoption['CSS_JS'] .= '</script>'."\n";
// informasi tahun aplikasi dan pembuatan menu
if (strpos($buffer, '{{CREATOR_YEAR}}')===false) {
$aoption['REG_YEAR'] = ($aoption['REG_YEAR']!=date('Y')) ? $aoption['REG_YEAR']." - ".date('Y') : $aoption['REG_YEAR'];
} else {
$aoption['CREATOR_YEAR'] = ($aoption['CREATOR_YEAR']!=date('Y')) ? $aoption['CREATOR_YEAR']." - ".date('Y') : $aoption['CREATOR_YEAR'];
}
// perubahan variabel dari data konfigurasi
$aoption['APP_NAME_VER'] = $aoption['APP_NAME']." v".$aoption['APP_VER'];
$aoption['APP_NAMES_VER'] = $aoption['APP_NAMES']." v".$aoption['APP_VER'];
$aoption['APP_NAMES_UP'] = strtoupper($aoption['APP_NAMES'] ?? "");
$aoption['REG_ID'] = $this->reg->reg_id();
$aoption['REG_NAME_UP'] = strtoupper($aoption['REG_NAME'] ?? "");
$aoption['REG_CITY_UP'] = strtoupper($aoption['REG_CITY'] ?? "");
$aoption['USER_IMG'] = $this->auser['user_img'] ?? "";
$aoption['NAVI_SIDEBAR'] = $tnaviside;
$aoption['NAVI_HEADER'] = $tnavihead;
if (isset($this->auser) && is_array($this->auser)) {
$aoption['USER_ID'] = $this->auser['UserID'] ?? "";
$aoption['USER_USER'] = $this->auser['Username'] ?? "";
$aoption['USER_NAME'] = $this->auser['Nama'] ?? "";
$aoption['USER_POSISI'] = $this->auser['Posisi'] ?? "";
// menu modul
$t_modul = "";
if (isset($this->auser['MENU_MODUL']) && is_array($this->auser['MENU_MODUL']) && count($this->auser['MENU_MODUL'])>0) {
$t_modul = '<div class="dropdown-divider"></div>';
if ($_SERVER['SERVER_ADDR'] == "127.0.0.1") {
$href1 = $this->apps['WEB_PATH'].'../';
$href2 = "";
} else {
$_host = $_SERVER['HTTP_ORIGIN'] ?? $_SERVER['HTTP_HOST'] ?? $this->apps['PARENT_SITE'];
$_host = str_replace(['http://','https://'], "", $_host);
if ($this->apps['PARENT_SUB']==true) {
$_subs = explode('.', $_host);
if (count($_subs) > 2) array_shift($_subs);
$href1 = "//";
$href2 = "." . implode('.', $_subs);
} else {
$href1 = "//" . $_host . '/';
$href2 = "";
}
}
foreach ($this->auser['MENU_MODUL'] as $modul) {
$href = $href1.$modul['APP_PATH'].$href2;
$href .= '/?auth='.$_SESSION['APP_TOKEN'];
$t_modul .= '<a class="dropdown-item slink" href="'.$href.'"><i class="'.$modul['Icon'].' me-2"></i> '.$modul['Judul'].'</a>';
}
}
// menu extra
$amodul_ext = $aoption['MENU_MODUL'] ?? [];
if (count($amodul_ext) > 0) {
$t_modul .= '<div class="dropdown-divider"></div>';
foreach ($amodul_ext as $modul) {
$t_modul .= '<a class="dropdown-item slink" id="'.$modul['Id'].'"><i class="'.$modul['Icon'].' me-2"></i> '.$modul['Judul'].'</a>';
}
}
$aoption['MENU_MODUL'] = $t_modul;
}
// penyisipan option (pilihan tahun, tanggal login, dll)
if (count($aoption) > 0) {
foreach ($aoption as $__key => $val) {
$opt_var = $val['value'];
if (strpos($__key, "OPTION")!==false) {
$opt_var = $this->__form->option("_", $__key, $val['value'], true, true, $val['option']);
} else if (strpos($__key, "RADIO")!==false) {
$opt_var = $this->__form->radio("_", $__key, $val['value'], true, true, $val['radio']);
} else if (strpos($__key, "PICKDATE")!==false) {
$opt_var = $this->__form->datebox("_", $__key, $val['value'], true, true);
}
$aoption[$__key] = $opt_var;
}
}
$output = preg_replace_callback('/\{\{([a-zA-Z0-9_]+)\}\}/', fn($matches) => isset($aoption[$matches[1]]) ? $aoption[$matches[1]] : "", $buffer);
echo $output;
}
}
?>
+108
View File
@@ -0,0 +1,108 @@
<?php
/*******************************************************************
Module : /DB/CheckSQL.php
Desc. : Class Check SQL / Repair Database
Created By : Siau Pheng ([email protected]).
Created Date : May 11th, 2011.
Last Modified : May 8th, 2021.
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\DB;
final class CheckSQL {
private $__atabel = [];
private $__aignore = [];
protected $__db = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
$this->__db->Query("SELECT TABLE_NAME,ENGINE,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='".$this->__db->getDBName()."' AND TABLE_TYPE='BASE TABLE'");
while ($this->__db->Next()) {
$this->__atabel[] = array($this->__db->Row("TABLE_NAME"), ' <i>('.$this->__db->Row("ENGINE").')</i>',' <i>('.uang($this->__db->Row("TABLE_ROWS")).' Records)</i>');
}
}
public function ignore_table() {
$tmp_arr = func_get_args();
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
$this->__aignore = $tmp_arr;
}
private function _check_db($atabel=array()) {
$hasil = "";
if (!in_array($atabel[0], $this->__aignore)) {
$pesan = "<span style=\"color:blue;\">OK</span>";
$this->__db->Query("CHECK TABLE ".$atabel[0]);
if ($this->__db->Next()) {
if (strtoupper($this->__db->Row("Msg_text"))<>"OK") {
$pesan = "<span style=\"color:red;\">ERROR</span>";
$this->__db->Query("REPAIR TABLE ".$atabel[0]);
if ($this->__db->Next()) {
if (strtoupper($this->__db->Row("Msg_text"))=="OK") {
$pesan .= " -> <span style=\"color:blue;\">FIXED</span>";
}
}
}
}
$hasil = $atabel[0] . $atabel[2] ." ... ". $pesan ."<br>";
}
return $hasil;
}
public function count_db() {
return count($this->__atabel);
}
public function check_db() {
$hasil = "=== CEK DATABASE ===<br>";
for ($n=0;$n<count($this->__atabel);$n++) {
$hasil .= $this->_check_db($this->__atabel[$n]);
}
return $hasil;
}
public function check_db_step($n) {
$hasil .= $this->_check_db($this->__atabel[$n]);
}
public function repair_db() {
$hasil = "=== REPAIR DATABASE ===<br>";
for ($n=0;$n<count($this->__atabel);$n++) {
if (!in_array($this->__atabel[$n][0], $this->__aignore)) {
$pesan = "<span style=\"color:blue;\">OK</span>";
$this->__db->Query("REPAIR TABLE ".$this->__atabel[$n][0]);
while ($this->__db->Next()) {
$pesan = (strtoupper($this->__db->Row("Msg_text"))=="OK") ? "<span style=\"color:blue;\">OK</span>" : "<span style=\"color:red;\">ERROR</span>";
}
$hasil .= $this->__atabel[$n][0] . $this->__atabel[$n][1] ." ... ". $pesan ."<br>";
}
}
return $hasil;
}
public function optimize_db() {
$hasil = "=== OPTIMALISASI DATABASE ===<br>";
for ($n=0;$n<count($this->__atabel);$n++) {
if (!in_array($this->__atabel[$n][0], $this->__aignore)) {
$pesan = "<span style=\"color:blue;\">OK</span>";
$this->__db->Query("OPTIMIZE TABLE ".$this->__atabel[$n][0]);
while ($this->__db->Next()) {
$pesan = (strtoupper($this->__db->Row("Msg_text"))=="OK" || strtoupper($this->__db->Row("Msg_text"))=="TABLE IS ALREADY UP TO DATE") ? "<span style=\"color:blue;\">OK</span>" : "<span style=\"color:red;\">ERROR</span>";
}
$hasil .= $this->__atabel[$n][0] . $this->__atabel[$n][1] ." ... ". $pesan ."<br>";
}
}
return $hasil;
}
}
?>
+126
View File
@@ -0,0 +1,126 @@
<?php
/*******************************************************************
Module : /DB/DumpSQL.php
Desc. : Class Dump Data SQL
Created By : Siau Pheng ([email protected]).
Created Date : May 11th, 2011.
Last Modified : May 8th, 2021.
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\DB;
final class DumpSQL {
private $__adata = array();
private $__aignore = array("vi_%","rep_%");
protected $__db = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
$this->__adata = $this->__db->getConfig();
}
public function set_db($nama_db = "") {
if ($nama_db<>"") $this->__adata['db'] = $nama_db;
}
public function ignore_table() {
$tmp_arr = func_get_args();
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
$this->__aignore = array_merge($this->__aignore, $tmp_arr);
}
private function ignore_prepare() {
$ahasil = array();
foreach($this->__aignore as $_val) {
if (strpos($_val, "%")===false) {
$ahasil[] = $_val;
} else {
$this->__db->Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='".$this->__db->getDBName()."' AND TABLE_NAME LIKE '".$_val."'");
while ($this->__db->Next()) {
$ahasil[] = $this->__db->Row("TABLE_NAME");
}
}
}
return $ahasil;
}
public function create_backup($folder="backups") {
$namafile = date("Ymd").".gz";
$folder = $_SESSION['__WEB_APP']['REAL_PATH'].$folder."/".date("Y");
if (!is_dir($folder)) mkdir($folder);
if (file_exists($folder."/".$namafile)) unlink($folder."/".$namafile);
$_cmd = "mysqldump -C --hex-blob -h ".$this->__adata['host']." -P ".$this->__adata['port']." -u ".$this->__adata['user']." -p".$this->__adata['pwd']." ".$this->__adata['db'];
$itable = $this->ignore_prepare();
foreach($itable as $_val) $_cmd .= " --ignore-table=".$this->__adata['db'].".".$_val;
$_cmd .= " | gzip -9 > ".$folder."/".$namafile;
system($_cmd);
}
private function get_file_list($directory) {
$arrayItems = array();
$skipByExclude = false;
$handle = opendir($directory);
if ($handle) {
while (false !== ($file = readdir($handle))) {
preg_match("/(^(([\.]){1,2})$|(\.(svn|git|md))|(Thumbs\.db|\.DS_STORE))$/iu", $file, $skip);
$skipByExclude = in_array($file, array(",",".."));
if (!$skip && !$skipByExclude) {
if (is_dir($directory. DIRECTORY_SEPARATOR . $file)) {
$arrayItems = array_merge($arrayItems, $this->get_file_list($directory. DIRECTORY_SEPARATOR . $file));
} else {
$file = $directory . DIRECTORY_SEPARATOR . $file;
$arrayItems[] = str_replace("\\", "/", $file);
}
}
}
closedir($handle);
}
return $arrayItems;
}
private function format_bytes($bytes) {
if ($bytes < 1024) return $bytes.' B';
elseif ($bytes < 1048576) return uang2($bytes / 1024).' KB';
elseif ($bytes < 1073741824) return uang2($bytes / 1048576).' MB';
elseif ($bytes < 1099511627776) return uang2($bytes / 1073741824).' GB';
else return uang2($bytes / 1099511627776).' TB';
}
public function disk_space() {
$_free = disk_free_space($_SESSION['__WEB_APP']['REAL_PATH']);
$_tot = disk_total_space($_SESSION['__WEB_APP']['REAL_PATH']);
$_used = $_tot - $_free;
$_aret = array();
$_aret['TOTAL'] = $this->format_bytes($_tot);
$_aret['USED'] = $this->format_bytes($_used);
$_aret['FREE'] = $this->format_bytes($_free);
$_aret['USED_P'] = ($_used/$_tot) * 100;
$_aret['FREE_P'] = ($_free/$_tot) * 100;
return $_aret;
}
public function update_list($folder="backups") {
$folder = $_SESSION['__WEB_APP']['REAL_PATH'].$folder;
$this->__db->Query("TRUNCATE TABLE app_backup");
$afile = $this->get_file_list($folder);
foreach($afile as $_key => $_val) {
if (file_exists($_val)) {
$_file = str_replace($folder."/", "", $_val);
$_waktu = date("Y-m-d H:i:s", filemtime($_val));
$_ukuran = $this->format_bytes(filesize($_val));
$this->__db->Query("INSERT INTO app_backup SET Nama_File='".$_file."',Tanggal='".$_waktu."',Ukuran='".$_ukuran."'");
}
}
}
}
?>
+228
View File
@@ -0,0 +1,228 @@
<?php
/*******************************************************************
Module : /DB/MySQL.php
Desc. : Class database MySQL / MariaDB
Created By : Siau Pheng ([email protected]).
Created Date : February 2nd, 2007.
Last Modified : October 19th, 2023.
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\DB;
final class MySQL {
private $cnn;
private $rs = 0;
private $rec = array();
private $row = 0;
private $halt_on_error = 1; //1: halt w message, 2: not halt w message, 3: not halt no message
private $auto_free = 1; //1: free query automatically, 0: must call free method to free query
private $db_config = null;
private $err_num = 0;
private $err_msg = '';
private $debug_msg = 1;
private $ischangingdb = false;
public function __construct() {
if (!is_array($this->db_config)) $this->setConfig();
$this->debug_msg = ($_SERVER['SERVER_ADDR'] == "127.0.0.1") ? 1 : 0;
}
private function setConfig() {
global $APP_DATA;
if (!is_array($APP_DATA)) {
if (file_exists($_SESSION['__WEB_APP']['REAL_PATH']."apps/cfg/mysql.php"))
require_once($_SESSION['__WEB_APP']['REAL_PATH']."apps/cfg/mysql.php");
}
$this->db_config = $APP_DATA;
}
public function getConfig() {
return $this->db_config;
}
function Connect() {
if (!$this->cnn) {
$this->cnn = @mysqli_connect($this->db_config['host'], $this->db_config['user'], $this->db_config['pwd'], $this->db_config['db'], intval($this->db_config['port']), $this->db_config['sock']);
if (!$this->cnn) {
$this->ErrHandler("Connection failed!");
return 0;
} else {
@mysqli_query($this->cnn, "SET NAMES utf8");
@mysqli_query($this->cnn, "SET CHARACTER SET utf8");
@mysqli_query($this->cnn, "SET character_set_connection=utf8");
}
}
return $this->cnn;
}
function Connection() {
return $this->cnn;
}
function ResultSet() {
return $this->rs;
}
function Free() {
if (is_resource($this->rs)) @mysqli_free_result($this->rs);
$this->rs = 0;
$this->row = 0;
$this->rec = array();
$this->err_num = 0;
$this->err_msg = '';
}
function SafeSQL($str) {
if (!$this->cnn) $this->Connect();
return mysqli_real_escape_string($this->cnn, strval($str));
}
function &Query($stqry = "", $dbname = "") {
if ($stqry == "") return 0;
if (!$this->Connect()) return 0;
if ($dbname != "" || $this->ischangingdb) {
if ($dbname != "") {
if (!@mysqli_select_db($this->cnn, $dbname)) {
$this->ErrHandler("Cannot select database!");
return 0;
}
$this->ischangingdb = true;
} else {
if (!@mysqli_select_db($this->cnn, $this->db_config['db'])) {
$this->ErrHandler("Cannot select database!");
return 0;
}
$this->ischangingdb = false;
}
}
if ($this->rs) $this->Free();
$this->rs = @mysqli_query($this->cnn, $stqry);
$this->row = 0;
$this->err_msg = @mysqli_error($this->cnn);
if (!$this->rs) $this->ErrHandler("Invalid SQL!: ".$stqry);
return $this->rs;
}
function Next() {
if (!$this->rs) {
$this->ErrHandler("Cannot move cursor to next record!");
return 0;
}
$this->rec = @mysqli_fetch_array($this->rs, MYSQLI_ASSOC);
$this->row += 1;
$this->err_msg = @mysqli_error($this->cnn);
$result = is_array($this->rec);
if (!$result && $this->auto_free) $this->Free();
return $result;
}
function Reset() {
@mysqli_data_seek($this->rs, 0);
}
function Seek($rownum = 0) {
return @mysqli_data_seek($this->rs, $rownum);
}
function Row($name = "", $defval = "") {
if (isset($this->rec[$name])) {
return (($this->rec[$name] == "") ? $defval : $this->rec[$name]);
} else {
return (($defval != "") ? $defval : "");
}
}
function RowNumeric($name = "", $defval = 0) {
$defval = is_numeric($defval) ? $defval : 0;
if (isset($this->rec[$name])) {
if (is_numeric($this->rec[$name])) return $this->rec[$name];
return $defval;
} else return $defval;
}
function RowFloat($name = "", $defval = 0) {
$defval = is_numeric($defval) ? $defval : 0;
if (isset($this->rec[$name])) {
if ($this->rec[$name]) $defval = $this->rec[$name];
}
return floatval($defval);
}
function AllRow() {
return $this->rec;
}
function ValueArray($colname = "") {
$currrow = $this->row;
@mysqli_data_seek($this->rs, 0);
$result = array();
while ($__row = mysqli_fetch_array($this->rs))
if (isset($__row[$colname])) array_push($result, $__row[$colname]);
@mysqli_data_seek($this->rs, $currrow);
return $result;
}
function ValueArrayFormater($colname = "", $formater = "") {
$currrow = $this->row;
$formater = $formater == ""?$formater = "return \$__row[\$colname];":"return ".str_replace("<value>", "\$__row[\$colname]", $formater).";";
@mysqli_data_seek($this->rs, 0);
$result = array();
while ($__row = mysqli_fetch_array($this->rs))
if (isset($__row[$colname])) array_push($result, eval($formater));
@mysqli_data_seek($this->rs, $currrow);
return $result;
}
function ValueList($colname = "", $delim = ",") {
$result = @$this->ValueArray($colname);
return @implode($delim, $result);
}
function CurrentRow() {
return $this->row;
}
function AffectedRows() {
return @mysqli_affected_rows($this->cnn);
}
function RecordCount() {
return @mysqli_num_rows($this->rs);
}
function NumFields() {
return @mysqli_num_fields($this->rs);
}
function LastInsertID() {
$lastinsertid = -1;
$crs = @mysqli_query($this->cnn, "SELECT LAST_INSERT_ID() AS lastinsertid");
$crow = @mysqli_fetch_array($crs);
if (isset($crow["lastinsertid"])) if (is_numeric($crow["lastinsertid"])) $lastinsertid = $crow["lastinsertid"];
return $lastinsertid;
}
function ErrHandler($err_msg = "") {
$this->err_msg = @mysqli_error($this->cnn);
if ($this->halt_on_error == 3) return;
if ($err_msg == "") $err_msg = "Undefined error!";
if ($this->debug_msg) {
printf('<span style="font-size:1.2em;"><b>MySQL Error : %s</b> %s</span><br>', $this->db_config['db'], $this->err_msg);
printf('<span style="font-size:1.2em;"><b>Database error : </b> %s</span><br>', $err_msg);
}
if ($this->halt_on_error == 1) die("");
}
function getDBName() {
return $this->db_config['db'];
}
}
?>
+131
View File
@@ -0,0 +1,131 @@
<?php
/*******************************************************************
Module : /DB/SQL.php
Desc. : Class Query database
Created By : Siau Pheng ([email protected]).
Created Date : February 2nd, 2007.
Last Modified : December 17th, 2023.
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\DB;
final class SQL {
private $__ttable = "";
private $__afield = array();
private $__avalue = array();
private $__anomor = array();
private $__twhere = "";
protected $__db = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
}
public function SafeSQL($ttext = "") {
return $this->__db->SafeSQL($ttext);
}
public function set_table($ttable = "") {
$this->__ttable = $ttable;
}
public function add_param($tparam = "", $tvalue = null, $bnomor = false) {
$this->__afield[] = $tparam;
$this->__avalue[] = (is_null($tvalue) && isset($_REQUEST[$tparam])) ? $this->__db->SafeSQL($_REQUEST[$tparam]) : $tvalue;
$this->__anomor[] = $bnomor;
}
public function add_param_date($tparam = "", $tvalue = null) {
$this->__afield[] = $tparam;
$this->__avalue[] = tgl_sql2str((is_null($tvalue) && isset($_REQUEST[$tparam])) ? $this->__db->SafeSQL($_REQUEST[$tparam]) : $tvalue);
$this->__anomor[] = false;
}
public function add_param_stamp($tparam = "DateStamp") {
$this->__afield[] = $tparam;
$this->__avalue[] = "NOW()";
$this->__anomor[] = true;
}
public function add_param_unix() {
$this->__afield[] = "Unix";
$this->__avalue[] = user_unix();
$this->__anomor[] = false;
}
public function add_param_userid($tparam = "UserID") {
$this->__afield[] = $tparam;
$this->__avalue[] = user_id();
$this->__anomor[] = false;
}
public function add_where_unix() {
$this->__twhere .= (($this->__twhere=="") ? " WHERE " : " AND ") . "(Unix='".user_unix()."')";
}
public function add_where_date($tfield = "", $tvalue = null) {
$tvalue = ($tvalue == null) ? "0000-00-00" : tgl_sql2str($tvalue);
$this->add_where($tfield, $tvalue);
}
public function add_where($tfield = "", $tvalue = null) {
$__tvalue = (is_null($tvalue) && isset($_REQUEST[$tfield])) ? $this->__db->SafeSQL($_REQUEST[$tfield]) : $tvalue;
$this->__twhere .= (($this->__twhere=="") ? " WHERE " : " AND ") . "(".$tfield."='".$__tvalue."')";
}
public function clear_param() {
$this->__afield = array();
$this->__avalue = array();
$this->__anomor = array();
}
public function clear_where() {
$this->__twhere = "";
}
public function InsertDB() {
$tsql = "INSERT INTO ".$this->__ttable." (";
$tfield = "";
$tvalue = "";
for ($i=0; $i<count($this->__afield); $i++) {
$tfield .= ",".$this->__afield[$i];
$tvalue .= ",".(($this->__anomor[$i])?"":"'").$this->__avalue[$i].(($this->__anomor[$i])?"":"'");
}
$tsql .= substr($tfield,1);
$tsql .= ") VALUES (";
$tsql .= substr($tvalue,1);
$tsql .= ")";
$this->__db->Query($tsql);
}
public function UpdateDB() {
$tsql = "UPDATE ".$this->__ttable." SET ";
$tfield = "";
for ($i=0; $i<count($this->__afield); $i++) {
$tfield .= ",".$this->__afield[$i]."=".(($this->__anomor[$i])?"":"'").$this->__avalue[$i].(($this->__anomor[$i])?"":"'");
}
$tsql .= substr($tfield,1);
$tsql .= ($this->__twhere=="") ? "" : $this->__twhere;
$this->__db->Query($tsql);
}
public function DeleteDB() {
$tsql = "DELETE FROM ".$this->__ttable;
$tsql .= ($this->__twhere=="") ? "" : $this->__twhere;
$this->__db->Query($tsql);
}
public function LastInsertID() {
return $this->__db->LastInsertID();
}
}
?>
+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;
}
}
?>
+193
View File
@@ -0,0 +1,193 @@
<?php
/*******************************************************************
Module : /Data/Cache.php
Desc. : Class cache aplikasi
Created By : Siau Pheng ([email protected]).
Created Date : March 16th, 2008.
Last Modified : July 25th, 2026.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Data;
use MatthiasMullie\Minify;
final class Cache {
private $__cachedays = 0;
private $__cachedir = "";
private $__cssdir = "";
private $__localedir = "";
private $__jsdir = "";
private $__jsapp = "";
private $__realpath = "";
private $__ini = [];
protected $__db = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else $this->__db = new \siaupheng\webapp\DB\MySQL();
$rootdir = $_SESSION['__WEB_APP']['REAL_PATH'];
$this->__cachedir = $rootdir . 'chunks/';
$this->__cssdir = __DIR__ . '/../../assets/css/';
$this->__localedir = $rootdir . 'assets/locale/';
$this->__jsdir = __DIR__ . '/../../assets/js/';
$this->__jsapp = $rootdir . 'apps/js/';
$this->__realpath = $rootdir;
if (!is_dir($this->__cachedir)) mkdir($this->__cachedir, 0755, true);
if (!file_exists($this->__cachedir . "cache.ini")) {
$this->__ini = [
'css' => ['login_stamp'=>"0",'login_file'=>"",'index_stamp'=>"0",'index_file'=>"",'display_stamp'=>"0",'display_file'=>""],
'js' => ['login_stamp'=>"0",'login_file'=>"",'index_stamp'=>"0",'index_file'=>"",'display_stamp'=>"0",'display_file'=>""]
];
$this->save_ini();
}
$this->__ini = parse_ini_file($this->__cachedir . "cache.ini", true);
}
private function gen_file($type="css", $mode="index") {
$afile = [];
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 (is_dir($this->__localedir)) {
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=[], $lastmod=0) {
$contents = ''; $smini = null;
$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="") {
if ($mode == "") $mode = "login";
if (($_SESSION['__WEB_USER']['UserID'] ?? 0) > 0) $mode = "index";
$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'] ."chunks/". $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'] ."chunks/". $appfile;
}
}
?>
+181
View File
@@ -0,0 +1,181 @@
<?php
/*******************************************************************
Module : /Data/PDF.php
Desc. : Class pembuatan file PDF
Created By : Siau Pheng ([email protected]).
Created Date : April 18th, 2015.
Last Modified : July 25th, 2026.
(c) 2015 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Data;
use Mpdf;
final class PDF {
private $__avalue = [];
private $__atabel = [];
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 = [];
$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("&nbsp;", 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 = ["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);
}
}
?>
+163
View File
@@ -0,0 +1,163 @@
<?php
/*******************************************************************
Module : /Data/SimpleXLS.php
Desc. : Class pembuatan file Simple XLS
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : November 18th, 2012.
Last Modified : September 30th, 2025.
(c) 2012 - 2025, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Data;
final class SimpleXLS {
private $__wbook = null;
private $__atabel = [];
private $__astyle = [];
private $__aheader = [];
private $__amerge = [];
private $__avalue = [];
private $__tsheet = null;
public function __construct($oprop=[]) {
$this->__wbook = new \Shuchkin\SimpleXLSXGen();
$this->__wbook
->setAuthor($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
->setLastModifiedBy($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
->setTitle($oprop['title'] ?? "")
->setSubject($oprop['subject'] ?? $_SESSION['__WEB_APP']['REG_NAME'])
->setDescription($oprop['desc'] ?? "")
->setCompany($_SESSION['__WEB_APP']['REG_NAME'])
->setDefaultFont("Calibri")
->setDefaultFontSize(11);
}
private function coord2cell($x, $y) {
$c = '';
for ($i = $x; $i >= 0; $i = ((int)($i / 26)) - 1) {
$c = chr(ord('A') + $i % 26) . $c;
}
return $c . ($y + 1);
}
private function create_style($tstyle="L") {
$_astyle = explode(",", $tstyle);
$_s_style = ""; $_e_style = "";
foreach ($_astyle as $_key => $_val) {
if ($_val == "L") {$_s_style .= '<left>'; $_e_style .= '</left>';}
if ($_val == "R") {$_s_style .= '<right>'; $_e_style .= '</right>';}
if ($_val == "C") {$_s_style .= '<center>'; $_e_style .= '</center>';}
if ($_val == "W") {$_s_style .= '<wraptext>'; $_e_style .= '</wraptext>';}
if ($_val == "B") {$_s_style .= '<b>'; $_e_style .= '</b>';}
if ($_val == "I") {$_s_style .= '<i>'; $_e_style .= '</i>';}
if ($_val == "S") {$_s_style .= "\0"; $_e_style .= '';}
if ($_val == "N") {$_s_style .= '<style nf="#,##0.00">'; $_e_style .= '</style>';}
if ($_val == "N0") {$_s_style .= '<style nf="#,##0">'; $_e_style .= '</style>';}
}
return ['s'=>$_s_style, 'e'=>$_e_style];
}
public function clear_field() {
$this->__atabel = [];
}
public function add_header($tjudul="") {
if ($tjudul=="") return;
$this->__aheader[] = $tjudul;
}
public function add_empty_row($nrow=1) {
$_jkolom = count($this->__atabel);
for ($i=0; $i<$nrow; $i++) {
$this->__avalue[] = array_fill(0,$_jkolom,"");
}
}
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="") {
$this->__atabel[] = [$tnama, $nlebar, $ffunc];
$this->__astyle[] = $this->create_style($talign);
}
public function add_sheet($tnama_sheet="BARU", $bw_header=true) {
$this->__tsheet = $tnama_sheet;
$_jkolom = count($this->__atabel);
foreach ($this->__aheader as $_key => $_val) {
$a_out = ['<style font-size="12"><center>'.$_val."</center></style>"];
$this->__amerge[] = $this->coord2cell(0, count($this->__avalue)) . ":" . $this->coord2cell($_jkolom-1, count($this->__avalue));
$this->__avalue[] = $a_out;
}
if ($bw_header==true) $this->show_headers();
}
public function add_value() {
$tmp_arr = func_get_args();
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0];
$a_out = [];
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);
}
$a_out[] = $this->__astyle[$i]['s'] . $tmp_val . $this->__astyle[$i]['e'];
}
$this->__avalue[] = $a_out;
}
public function add_span() {
$tmp_arr = func_get_args();
$a_out = [];
for ($i=0; $i<count($tmp_arr); $i++) {
$tmp_val = $tmp_arr[$i]; // CONTENT, COLSPAN=1, L, FUNC
if (!isset($tmp_val[1])) $tmp_val[1] = 1;
if (!isset($tmp_val[2])) $tmp_val[2] = "L";
if (isset($tmp_val[3])) {
if (function_exists($tmp_val[3]) && trim("".$tmp_val[0])<>"") {
$tmp_val[0] = call_user_func($tmp_val[3], $tmp_val[0]);
}
}
$tmp_style = $this->create_style($tmp_val[2]);
if ($tmp_val[1]>1) $this->__amerge[] = $this->coord2cell(count($a_out), count($this->__avalue)) . ":" . $this->coord2cell((count($a_out)+$tmp_val[1])-1, count($this->__avalue));
$a_out[] = $tmp_style['s'] . $tmp_val[0] . $tmp_style['e'];
for ($k=1; $k<$tmp_val[1]; $k++) $a_out[] = null;
}
$this->__avalue[] = $a_out;
}
public function add_stamp($ctk_ke=1, $bnama=false) {
$this->__avalue[] = ["<i>".$_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):"")."</i>"];
}
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 show_headers() {
$a_out = [];
for ($i=0; $i<count($this->__atabel); $i++) {
$a_out[] = '<style bgcolor="#D0D0D0"><center>'.$this->__atabel[$i][0].'</center></style>';
}
$this->__avalue[] = $a_out;
}
public function send($tnama_file="File_Excel") {
$this->__wbook->addSheet($this->__avalue, $this->__tsheet);
for ($i=0; $i<count($this->__atabel); $i++) {
$this->__wbook->setColWidth(($i+1), $this->__atabel[$i][1]);
}
for ($i=0; $i<count($this->__amerge); $i++) {
$this->__wbook->mergeCells($this->__amerge[$i]);
}
$this->__wbook->downloadAs($tnama_file);
}
}
?>
+155
View File
@@ -0,0 +1,155 @@
<?php
/*******************************************************************
Module : /Data/XLS.php
Desc. : Class pembuatan file XLS
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : November 18th, 2012.
Last Modified : October 26th, 2023.
(c) 2012 - 2023, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Data;
use PhpOffice\PhpSpreadsheet\IOFactory;
final class XLS {
private $__tnamafile = null;
private $__bline = true;
private $__wbook = null;
private $__wsheet = null;
private $__baris = 0;
private $__kolom = 0;
private $__atabel = [];
private $__astyle =[];
private $__aheader = [];
private $__fhead = null;
private $__isheet = 0;
public function __construct($tnama_file="", $oprop=[]) {//oke
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder() );
$this->__tnamafile = $tnama_file;
$this->__wbook = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$this->__wbook->getProperties()
->setCreator($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
->setLastModifiedBy($_SESSION['__WEB_APP']['APP_NAME']." v".$_SESSION['__WEB_APP']['APP_VER'])
->setTitle($oprop['title'] ?? "")
->setSubject($oprop['subject'] ?? "")
->setDescription($oprop['desc'] ?? "")
->setCompany($_SESSION['__WEB_APP']['REG_NAME']);
$this->__wsheet = $this->__wbook->getActiveSheet();
$this->__fhead = [
'font' => ['bold' => true],
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, 'wrapText' => true],
'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['rgb'=>"D0D0D0"]],
'borders' => ['allBorders' => ['borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, 'color' => ['rgb'=>"C0C0C0"]]]
];
}
public function create_style($tstyle="L") {//oke
$_astyle = explode(",", $tstyle);
$_tmp_style = [];
$_bline = $this->__bline;
foreach ($_astyle as $_key => $_val) {
if ($_val == "L") $_tmp_style['alignment'] = ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT];
if ($_val == "R") $_tmp_style['alignment'] = ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT];
if ($_val == "C") $_tmp_style['alignment'] = ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER];
if ($_val == "W") $_tmp_style['alignment'] = ['wrapText' => true];
if ($_val == "B") $_tmp_style['font'] = ['bold' => true];
if ($_val == "S") $_tmp_style['numberFormat'] = ['formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_TEXT];
if ($_val == "N") $_tmp_style['numberFormat'] = ['formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2];
if ($_val == "N0") $_tmp_style['numberFormat'] = ['formatCode' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2];
if ($_val == "NL") $_bline = false;
if ($_val == "H") {
$_bline = false;
$_tmp_style = $this->__fhead;
}
}
return $_tmp_style;
}
public function clear_field() {//up : 2014-06-19
$this->__atabel = [];
$this->__astyle = [];
}
public function set_pos($nbaris=0, $nkolom=0) {
$this->__baris = $nbaris;
$this->__kolom = $nkolom;
}
public function set_garis_bawah($bgaris=true) {}//todo: deleted
public function add_header($tjudul="") {//oke
if ($tjudul=="") return;
$this->__aheader[] = $tjudul;
}
public function add_empty_row($nrow=1) {//oke
$this->__baris += $nrow;
}
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="") {//oke
$this->__atabel[] = [$tnama, $nlebar, $ffunc];
$this->__astyle[] = $this->create_style($talign);
}
public function add_sheet($tnama_sheet="BARU", $bw_header=true) {//not yet !!!
if ($this->__isheet > 0) {
$this->__wbook->createSheet();
$this->__wsheet = $this->__wbook->setActiveSheetIndex(++$this->__isheet);
}
$this->__wsheet->setTitle($tnama_sheet);
for ($i=0; $i<count($this->__atabel); $i++) {
//sampai disini dulu !!
$this->__wsheet->getColumnDimension($this->__kolom+$i)->setWidth($this->__atabel[$i][1]);
}
$_fjudul = $this->__wbook->addFormat();
$_fjudul->setBold();
$_fjudul->setAlign("center");
$_jkolom = count($this->__atabel);
if ($_jkolom>0) $_jkolom--;
foreach ($this->__aheader as $_key => $_val) {
$this->__wsheet->write($this->__baris,$this->__kolom,$_val,$_fjudul);
$this->__wsheet->setMerge($this->__baris,$this->__kolom,$this->__baris,$this->__kolom+$_jkolom);
$this->__baris++;
}
$this->__baris++;
if ($bw_header==true) $this->show_headers();
}
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 send($tnama_file="File_Excel") {//oke
$this->__wsheet->setActiveSheetIndex(0);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$tnama_file.'"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($this->__wsheet, 'Xlsx');
$writer->save('php://output');
}
}
?>
+75
View File
@@ -0,0 +1,75 @@
<?php
/*******************************************************************
Module : /Display.php
Desc. : HTML5 Page Generator (jQuery & Bootstrap)
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : January 10th, 2008.
Last Modified : July 25th, 2026.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp;
final class Display {
public $version = "1.1.0";
private $apps = [];
private $cache = null;
protected $__db = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
$this->apps = $_SESSION['__WEB_APP'];
if (($this->apps['TEMPLATE'] ?? "") == "") $this->apps['TEMPLATE'] = "display.php";
$this->cache = new \siaupheng\webapp\Data\Cache($this->__db);
}
public function TampilDisplay() {
// loading template file {{}}
$buffer = "";
if (file_exists($this->apps['REAL_PATH']."assets/templates/".$this->apps['TEMPLATE'])) {
$buffer = file_get_contents($this->apps['REAL_PATH']."assets/templates/".$this->apps['TEMPLATE']);
$buffer = preg_replace("/(?:(?:\\/\\*(?:[^*]|(?:\\*+[^*\\/]))*\\*+\\/)|(?:(?<!\\:)\\/\\/. *))/", "", $buffer);
}
$aoption = [...$this->apps, 'CSS_JS' => ""];
// penambahan file css + js + app-js
$aoption['CSS_JS'] = '<link rel="stylesheet" type="text/css" href="'.$this->cache->Main("css", "display").'">'."\n";
$aoption['CSS_JS'] .= '<script type="text/javascript" src="'.$this->cache->Main("js", "display").'"></script>'."\n";
$_secret = $aoption['APP_DISPLAY'] .";". $aoption['APP_SID'] .";". $_SERVER['HTTP_HOST'] .";". $aoption['WEB_PATH'] .";". "http://".$_SERVER['HTTP_HOST'].$aoption['WEB_PATH'] .";". isMobile() .";". ($aoption['AUTH_LEVEL']?$aoption['AUTH_LEVEL']:0) .";". $this->version;
$_suser = "nobody;999;999;9";
$aoption['CSS_JS'] .= '<script type="text/javascript" language="javascript">'."\n";
$aoption['CSS_JS'] .= 'FoniaJS.setConfig("'.base64_encode($_secret).'", "'.base64_encode($_suser).'");';
$aoption['CSS_JS'] .= '</script>'."\n";
// informasi tahun aplikasi dan pembuatan menu
if (strpos($buffer, '{{CREATOR_YEAR}}')===false) {
$aoption['REG_YEAR'] = ($aoption['REG_YEAR']!=date('Y')) ? $aoption['REG_YEAR']." - ".date('Y') : $aoption['REG_YEAR'];
} else {
$aoption['CREATOR_YEAR'] = ($aoption['CREATOR_YEAR']!=date('Y')) ? $aoption['CREATOR_YEAR']." - ".date('Y') : $aoption['CREATOR_YEAR'];
}
// perubahan variabel dari data konfigurasi
$aoption['APP_NAME_VER'] = $aoption['APP_NAME']." v".$aoption['APP_VER'];
$aoption['APP_NAMES_VER'] = $aoption['APP_NAMES']." v".$aoption['APP_VER'];
$aoption['APP_NAMES_UP'] = strtoupper($aoption['APP_NAMES'] ?? "");
$aoption['REG_NAME_UP'] = strtoupper($aoption['REG_NAME'] ?? "");
$aoption['REG_CITY_UP'] = strtoupper($aoption['REG_CITY'] ?? "");
$output = preg_replace_callback('/\{\{([a-zA-Z0-9_]+)\}\}/', fn($matches) => isset($aoption[$matches[1]]) ? $aoption[$matches[1]] : "", $buffer);
echo $output;
}
}
?>
+63
View File
@@ -0,0 +1,63 @@
<?php
/*******************************************************************
Module : /Function/Auth.php
Desc. : Fungsi Custom Auth
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : January 27th, 2008.
Last Modified : January 21st, 2024.
(c) 2008 - 2024, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
if (!function_exists('user_level')) {
function user_level($level = 9) {
if ($_SESSION['__WEB_USER']['Level'] <= $level) return true;
return false;
}
}
if (!function_exists('user_level_not')) {
function user_level_not($level = 9) {
if ($_SESSION['__WEB_USER']['Level'] !== $level) return true;
return false;
}
}
if (!function_exists('user_logged')) {
function user_logged() {
if (isset($_SESSION['__WEB_USER'])) return true;
return false;
}
}
if (!function_exists('user_id')) {
function user_id($idigit = 0) {
if ($idigit > 0) return isi_nol($_SESSION['__WEB_USER']['UserID'], $idigit);
return $_SESSION['__WEB_USER']['UserID'];
}
}
if (!function_exists('user_user')) {
function user_user() {
return $_SESSION['__WEB_USER']['Username'];
}
}
if (!function_exists('user_unix')) {
function user_unix() {
return $_SESSION['__WEB_USER']['UNIX'];
}
}
if (!function_exists('user_nama')) {
function user_nama() {
return $_SESSION['__WEB_USER']['Nama'];
}
}
?>
+35
View File
@@ -0,0 +1,35 @@
<?php
/*******************************************************************
Module : /Function/JSON.php
Desc. : Fungsi Custom JSON
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : April 14th, 2012.
Last Modified : April 29th, 2022.
(c) 2012 - 2022, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
if (!function_exists('is_json')) {
function is_json($string) {
json_decode($string);
return json_last_error() === JSON_ERROR_NONE;
}
}
if (!function_exists('send_json')) {
function send_json($ajson = array(), $bempty = false) {
if (count($ajson) > 0 || $bempty == true) {
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($ajson);
}
}
}
?>
+353
View File
@@ -0,0 +1,353 @@
<?php
/*******************************************************************
Module : /Function/Misc.php
Desc. : Fungsi Custom Lain Lain
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : January 27th, 2008.
Last Modified : December 26th, 2025.
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
/*************************** FORMAT ANGKA / CURRENCY *****************************/
if (!function_exists('rupiah')) {
function rupiah($angka = 0, $desi = 0) {
return number_format(doubleval($angka), intval($desi), ",", ".");
}
}
if (!function_exists('rupiah2')) {
function rupiah2($angka = 0) {
return rupiah($angka, 2);
}
}
if (!function_exists('rupiah30')) {
function rupiah30($angka = 0) {
$nilai = explode(".", $angka);
$hasil = (intval($nilai[1])==0) ? rupiah($angka, 0) : rupiah($angka, 3);
return $hasil;
}
}
if (!function_exists('kurung_rup')) {
function kurung_rup($angka = 0, $desi = 0) {
$thasil = rupiah(abs($angka), $desi);
if ($angka<0) return "(".$thasil.")";
return $thasil." ";
}
}
if (!function_exists('kurung')) {
function kurung($angka = 0, $desi = 0) {
$thasil = uang(abs($angka), $desi);
if ($angka<0) return "(".$thasil.")";
return $thasil." ";
}
}
if (!function_exists('kurung2')) {
function kurung2($angka = 0) {
return kurung($angka, 2);
}
}
if (!function_exists('uang')) {
function uang($angka = 0, $desi = 0) {
$angka = str_replace(",","",$angka);
return number_format(doubleval($angka), intval($desi));
}
}
if (!function_exists('uang2')) {
function uang2($angka = 0) {
return uang($angka, 2);
}
}
if (!function_exists('koma30')) {
function koma30($angka = 0) {
$nilai = explode(".", $angka);
$hasil = (intval($nilai[1])==0) ? uang($angka, 0) : uang($angka, 3);
return $hasil;
}
}
if (!function_exists('items')) {
function items($item = 0) {
return rupiah($item)." Items";
}
}
if (!function_exists('records')) {
function records($item = 0) {
return rupiah($item)." Records";
}
}
if (!function_exists('baris')) {
function baris($item = 0) {
return rupiah($item)." Baris";
}
}
if (!function_exists('npwp')) {
function npwp($nomor = "000000000000000") {
return substr($nomor,0,2).".".substr($nomor,2,3).".".substr($nomor,5,3).".".substr($nomor,8,1)."-".substr($nomor,9,3).".".substr($nomor,12,3);
}
}
if (!function_exists('romawi')) {
function romawi($n) {
$hasil = "";
$iromawi = array("","I","II","III","IV","V","VI","VII","VIII","IX","X",20=>"XX",30=>"XXX",40=>"XL",50=>"L",60=>"LX",70=>"LXX",80=>"LXXX",90=>"XC",100=>"C",200=>"CC",300=>"CCC",400=>"CD",500=>"D",600=>"DC",700=>"DCC",800=>"DCCC",900=>"CM",1000=>"M",2000=>"MM",3000=>"MMM");
if (array_key_exists($n,$iromawi)) {
$hasil = $iromawi[$n];
} else if ($n >= 11 && $n <= 99) {
$i = $n % 10;
$hasil = $iromawi[$n-$i] . Romawi($n % 10);
} else if ($n >= 101 && $n <= 999) {
$i = $n % 100;
$hasil = $iromawi[$n-$i] . Romawi($n % 100);
} else {
$i = $n % 1000;
$hasil = $iromawi[$n-$i] . Romawi($n % 1000);
}
return $hasil;
}
}
if (!function_exists('abjad')) {
function abjad($n) {
$_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return substr($_str, ($n-1), 1);
}
}
/*************************** FORM CONTROL *****************************/
if (!function_exists('checkbox')) {
function checkbox($nilai = 0) {
$thasil = ((is_string($nilai) && ($nilai=="N" || $nilai=="0")) or (is_numeric($nilai) && $nilai==0) or (is_bool($nilai) && $nilai==false)) ? "circle text-secondary" : "check-circle text-info";
return '<i class="fs-6 bi-'.$thasil.'"></i>';
}
}
/*************************** FORMAT TANGGAL / KALENDER *****************************/
if (!function_exists('sqltgl')) {
function sqltgl($waktu = "0") {
return tgl_sql2str($waktu);
}
}
if (!function_exists('sqltgls')) {
function sqltgls($waktu = "0") {
return tgl_sql2str($waktu, false, true);
}
}
if (!function_exists('sqljam')) {
function sqljam($waktu = "0") {
return tgl_sql2str($waktu, true);
}
}
if (!function_exists('sqljams')) {
function sqljams($waktu = "0") {
return tgl_sql2str($waktu, true, true);
}
}
if (!function_exists('tgl_sql2str')) {
function tgl_sql2str($waktu = "0", $jam = false, $short = false) {
if ($waktu=="0" || $waktu=="") return;
$atgl = explode(" ", $waktu);
$sjam = ($jam) ? ((empty($atgl[1]))?date("H:i:s"):$atgl[1]) : "";
$atgl = explode("-", $atgl[0]);
$stgl = $atgl[2]."-".$atgl[1]."-".$atgl[0];
if ($short) $stgl = $atgl[2].".".$atgl[1].".".substr($atgl[0],2);
return $stgl.(($jam)?" ".$sjam:"");
}
}
if (!function_exists('tgl_ymd')) {
function tgl_ymd($jam = false) {
return (($jam) ? date("Y-m-d H:i:s") : date("Y-m-d"));
}
}
if (!function_exists('tgl_dmy')) {
function tgl_dmy($jam = false) {
return (($jam) ? date("d-m-Y H:i:s") : date("d-m-Y"));
}
}
if (!function_exists('tgl_operasi')) {
function tgl_operasi($dtgl = "", $nhari = 0, $nbln = 0, $nthn = 0) {
$atgl = explode("-", $dtgl);
return date("d-m-Y", mktime(0,0,0, $atgl[1]+$nbln, $atgl[0]+$nhari, $atgl[2]+$nthn));
}
}
if (!function_exists('tgl_range_hari')) {
function tgl_range_hari($dftgl="", $dttgl="", $bhitung_awal=false) {
$_start = strtotime(tgl_sql2str($dftgl));
$_end = strtotime(tgl_sql2str($dttgl));
return ceil(abs($_end - $_start) / 86400) + (($bhitung_awal==true)?1:0);
}
}
if (!function_exists('tgl_akhbln')) {
function tgl_akhbln($tgl) {
$atgl = explode("-", $tgl);
$ablna = array(31,28,31,30,31,30,31,31,30,31,30,31);
// jika tahun masehi dan bulan 2
if ( (round($atgl[2]/4)==($atgl[2]/4)) && intval($atgl[1])==2 ) return "29-02-".$atgl[2];
return $ablna[(intval($atgl[1])-1)]."-".isi_nol($atgl[1],2)."-".$atgl[2];
}
}
if (!function_exists('tgl_panjang')) {
function tgl_panjang($dtgl = "") {
if (trim($dtgl)=="") $dtgl = tgl_dmy();
$atgl = explode("-", $dtgl);
$abulan = bulan_array();
return $atgl[0]." ".$abulan[intval($atgl[1])]." ".$atgl[2];
}
}
if (!function_exists('tgl_hari')) {
function tgl_hari($dtgl = "") {
$nhari = date("w");
if (trim($dtgl)!="") {
//$atgl = getdate($dtgl);
//$nhari = $atgl[wday];
$nhari = date("w", strtotime(tgl_sql2str($dtgl)));
}
$ahari = array("0"=>"Minggu","1"=>"Senin","2"=>"Selasa","3"=>"Rabu","4"=>"Kamis","5"=>"Jum'at","6"=>"Sabtu");
return $ahari[$nhari];
}
}
if (!function_exists('tgl_triwulan')) {
function tgl_triwulan($dtgl = "") {
if ($dtgl == "") {
$dtgl = date("m");
} else {
$atgl = explode("-", $tgl);
$dtgl = $atgl[1];
}
$hasil = 0;
if ($dtgl >= 1 && $dtgl <= 3) $hasil = 1;
if ($dtgl >= 4 && $dtgl <= 6) $hasil = 2;
if ($dtgl >= 7 && $dtgl <= 9) $hasil = 3;
if ($dtgl >= 10 && $dtgl <= 12) $hasil = 4;
return $hasil;
}
}
if (!function_exists('bulan_array')) {
function bulan_array() {
return array("1"=>"Januari","2"=>"Februari","3"=>"Maret","4"=>"April","5"=>"Mei","6"=>"Juni","7"=>"Juli","8"=>"Agustus","9"=>"September","10"=>"Oktober","11"=>"November","12"=>"Desember");
}
}
if (!function_exists('triwulan_array')) {
function triwulan_array() {
return ["1"=>"Triwulan 1","2"=>"Triwulan 2","3"=>"Triwulan 3","4"=>"Triwulan 4"];
}
}
/*************************** FORMAT TAMPILAN & ERROR *****************************/
if (!function_exists('subjudul')) {
function subjudul($tjudul) {
return '<table border="0" align="center" valign="middle" width="100%" height="26px"><tr><td width="50%"><hr /></td><td>&nbsp;&nbsp;<span style="text-align:center;font-weight:bold;white-space:nowrap;">'.$tjudul.'</span>&nbsp;&nbsp;</td><td width="50%"><hr /></td></tr></table>';
}
}
if (!function_exists('showerror')) {
function showerror($terror) {
echo '<input type="hidden" id="_Error" class="error" value="'.$terror.'!" />';
}
}
if (!function_exists('br2nl')) {
function br2nl($string) {
return preg_replace('/\<br(\s*)?\/?\>/i', "\n\r", $string);
}
}
if (!function_exists('isi_nol')) {
function isi_nol($nilai = "0", $panjang = 1) {
$nilai = strval($nilai);
return ($panjang>strlen($nilai) ? str_repeat("0", $panjang-strlen($nilai)):'').$nilai;
}
}
if (!function_exists('isMobile')) {
function isMobile() {
$agen = $_SERVER['HTTP_USER_AGENT'];
$amobile = ['Android', 'webOS', 'iPhone', 'iPad', 'iPod', 'BlackBerry', 'Windows Phone', 'Mobile'];
foreach ($amobile as $keyword) {
if (stripos($agen,$keyword) !== false) return true;
}
return false;
}
}
if (!function_exists('isLinux')) {
function isLinux() {
$agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen,'linux') !== false) return true;
return false;
}
}
if (!function_exists('isIE')) {
function isIE() {
$agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen,'msie') !== false) return true;
return false;
}
}
if (!function_exists('isChrome')) {
function isChrome() {
$agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen,'chrome') !== false) return true;
return false;
}
}
if (!function_exists('isFirefox')) {
function isFirefox() {
$agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen,'firefox') !== false) return true;
return false;
}
}
if (!function_exists('potong')) {
function potong($nilai) {//utk rkpd
return substr($nilai, 0, 60);
}
}
if (!function_exists('format_bytes')) {
function format_bytes($bytes) {
if ($bytes < 1024) return $bytes.' B';
elseif ($bytes < 1048576) return uang2($bytes / 1024).' KB';
elseif ($bytes < 1073741824) return uang2($bytes / 1048576).' MB';
elseif ($bytes < 1099511627776) return uang2($bytes / 1073741824).' GB';
else return uang2($bytes / 1099511627776).' TB';
}
}
?>
+137
View File
@@ -0,0 +1,137 @@
<?php
/*******************************************************************
Module : /Printing/PrintHTML.php
Desc. : Class cetak HTML
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 15th, 2008.
Last Modified : September 30th, 2025.
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Printer;
final class PrintHTML {
private $__avalue = [];
private $__atabel = [];
private $__css = "table";
private $__tstamp = "";
public function __construct() {
}
public function set_css($style = "") {
if ($style=="") return;
$this->__css = $style;
}
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="", $nkol=1) {//up 2012-03-07
$this->__atabel[] = [$tnama, $nlebar, $ffunc, $talign, $nkol];
}
public function show_fields() {//todo: deleted
}
public function clear() {
$this->__avalue = [];
}
public function add_value() {
$tmp_arr = func_get_args();
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0]; //up 2009-09-27
$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)<>"") { //up 2010-05-28
$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, EXTRA
if (!isset($tmp_val[1])) $tmp_val[1] = 1;
if (!isset($tmp_val[2])) $tmp_val[2] = "L";
if (!isset($tmp_val[4])) $tmp_val[4] = "";
if (isset($tmp_val[3])) {
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_val[4]);
$tmp_out .= $tmp_val;
}
$tmp_out .= "</tr>";
$this->__avalue[] = $tmp_out;
}
public function add_stamp($ctk_ke=1, $bnama=false) {//up 2023-10-13
$this->__tstamp = $this->get_stamp($ctk_ke, $bnama);
}
public function get_stamp($ctk_ke=1, $bnama=false) {//up 2012-10-11
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 show($jumlah_ctk=1) {//up 2012-10-11
$out = "<table class=\"".$this->__css."\"><thead>";
// header out
$tmp_out = "<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>";
$out .= "</thead>".$tmp_out."<tbody>";
// content out
for ($i=0; $i<count($this->__avalue); $i++) {
$tmp_str = $this->__avalue[$i];
if (strpos($tmp_str, "_LINE")>0) $tmp_str = "<hr />";
$out .= $tmp_str;
}
$out .= "</tbody></table>";
$out .= $this->__tstamp;
for ($i=1; $i<=$jumlah_ctk; $i++) echo $out;
}
public function set_align($ttext, $nlen, $tdir="L", $bline=false, $bhead=false, $ncol=1, $textra="") {//up 2011-04-14
$tstyle = $this->create_style($tdir);
if ($bline===true) {
return "<tr><td colspan=\"".count($this->__atabel)."\" class=\"".$tstyle." ".$textra."\">".$ttext."</td></tr>";
} else {
return (($bhead===true)?"<th":"<td").(($ncol>1)?" colspan=\"".$ncol."\"":"")." class=\"".$tstyle." ".$textra."\" ".(($bhead===true)?"width=\"".$nlen."\"":"").">".$ttext.(($bhead===true)?"</th>":"</td>");
}
}
private function create_style($tstyle="L") { //up 2014-10-12
// style = Left Right Center No-Border No-Left No-Right Bold Italic
$apad = ["L"=>"l", "R"=>"r", "C"=>"c", "NB"=>"nb", "NL"=>"noleft", "NR"=>"noright", "B"=>"b", "I"=>"i"];
$_astyle = explode(",", $tstyle);
$thasil = "";
foreach ($_astyle as $_key => $_val) {
$thasil .= " ".$apad[$_val];
}
return substr($thasil,1);
}
public function add_pagebreak() {}//delete: not used anymore
}
?>
+146
View File
@@ -0,0 +1,146 @@
<?php
/*******************************************************************
Module : /Printing/PrintPOS.php
Desc. : Class cetak POS
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 15th, 2008.
Last Modified : December 3rd, 2025.
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Printer;
/* VERSI BARU DENGAN MULTI SHEET */
class PrintPOS {//up: 20251203
private $_header = [];
private $_avalue = [];
private $_astyle = [];
private $_ncont = 0;
private $_maxchr = 40;
private $_config = [
'fontsize' => 1,
'opendraw' => false,
'cutpaper' => false,
'logo' => null ];
public function __construct() {
}
public function set_opendrawer() {
$this->_config['opendraw'] = true;
}
public function set_cutpaper() {
$this->_config['cutpaper'] = true;
}
public function set_maxchr($nmax = 0) {//up: 2015-03-22
if ($nmax > 0) $this->_maxchr = $nmax;
}
public function set_fontsize($nsize = 1) {//up: 2015-09-30
if ($nsize > 0) $this->_config['fontsize'] = $nsize;
}
public function set_printnv_logo() {}//delete
public function set_header_logo($logo_file = "") {//up: 2019-01-08
if ($logo_file=="") return;
if (file_exists($_SESSION['__WEB_APP']['REAL_PATH']."assets/images/".$logo_file)) {
$this->_config['logo'] = $_SESSION['__WEB_APP']['WEB_PATH']."assets/images/".$logo_file;
}
}
public function add_header() {//up: 2025-12-03
$extra = func_get_args();
if (count($extra) > 0) {
foreach ($extra as $_val) {
$this->_header[] = $_val;
}
}
}
public function add_sheet() {//up: 20170321
$this->_ncont++;
}
public function add() {//up: 20180524
$val_arr = func_get_args(); $ttext = ""; $tstyle = "L";
if (is_array($val_arr[0])) {
foreach($val_arr as $aval) {
$ttext .= $this->set_align((isset($aval[0])?$aval[0]:""), (isset($aval[1])?$aval[1]:0), (isset($aval[2])?$aval[2]:$tstyle));
}
} else {
$ttext = (isset($val_arr[0])) ? $val_arr[0] : "";
$tstyle = (isset($val_arr[1])) ? $val_arr[1] : $tstyle;
}
$this->_avalue[$this->_ncont][] = $ttext;
$this->_astyle[$this->_ncont][] = $tstyle;
}
public function addl($ttext = "") {
$this->add($ttext);
}
public function addr($ttext = "") {
$this->add($ttext, "R");
}
public function addc($ttext = "") {
$this->add($ttext, "C");
}
public function add_line($tmp = "-") {
$this->add("__LINE ".$tmp);
}
public function add_empty($nrep = 1) {
for ($i=0;$i<$nrep;$i++) $this->add("");
}
public function add_stamp($ctk_ke=1, $bnama=false) {
$this->add($_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):""));
}
private function _json_out() {//up: 2016-11-12
$acontent = array();
$nmax = $this->_maxchr;
for ($s=0; $s<count($this->_avalue); $s++) {
for ($i=0; $i<count($this->_avalue[$s]); $i++) {
$tmp_str = $this->_avalue[$s][$i];
if (strpos($tmp_str, "_LINE")>0) {
$tmp_arr = explode(" ", $tmp_str);
$tmp_str = str_pad($tmp_arr[1], $nmax, $tmp_arr[1]);
}
$acontent[$s][] = ($this->_astyle[$s][$i]=="X") ? $tmp_str : $this->set_align($tmp_str, $nmax, $this->_astyle[$s][$i]);
}
}
$aout = array('type' => "escp");
$aout['config'] = $this->_config;
$aout['header'] = $this->_header;
$aout['content'] = $acontent;
send_json($aout);
}
public function show($jumlah_ctk=1) {
$this->_config['times'] = $jumlah_ctk;
$this->_json_out();
}
public function set_align($ttext, $nlen=0, $tdir="L") {//up: 20180524
$apad = array("L"=>STR_PAD_RIGHT, "R"=>STR_PAD_LEFT, "C"=>STR_PAD_BOTH);
$nlen = ($nlen==0) ? strlen($ttext) : $nlen;
$ttext = (strlen($ttext)>$nlen) ? substr($ttext, 0, $nlen) : $ttext;
return str_pad($ttext, $nlen, " ", $apad[$tdir]);
}
}
?>
+157
View File
@@ -0,0 +1,157 @@
<?php
/*******************************************************************
Module : /Printing/PrintRAW.php
Desc. : Class cetak RAW
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 15th, 2008.
Last Modified : November 1st, 2023.
(c) 2008 - 2023, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Printer;
class PrintRAW {
private $_header = [];
private $_avalue = [];
private $_atabel = [];
private $_ncont = 0;
private $_maxchr = 40;
private $_spacekol = " ";
private $_config = [
'fontsize' => "01",
'nvlogo' => false,
'opendraw' => false,
'opendrawbegin' => false,
'cutpaper' => false ];
public function __construct() {
}
public function set_opendrawer($bbegin = true) {
$this->_config['opendraw'] = true;
$this->_config['opendrawbegin'] = $bbegin;
}
public function set_cutpaper() {
$this->_config['cutpaper'] = true;
}
public function set_maxchr($nmax = 0) {//up: 2015-03-22
if ($nmax > 0) $this->_maxchr = $nmax;
}
public function set_fontsize($nsize = 1) {//up: 2015-09-30
if ($nsize > 0) $this->_config['fontsize'] = str_pad($nsize, 2, "0", STR_PAD_LEFT);
}
public function set_printnv_logo() {//up: 2015-03-23
$this->_config['nvlogo'] = true;
}
public function add_header($nvlogo = false, $extra = []) {//up: 2016-11-12
$this->_config['nvlogo'] = $nvlogo;
$this->_header[] = $_SESSION['__WEB_APP']['REG_NAME'];
if (count($extra) > 0) {
foreach ($extra as $_val) {
$this->_header[] = $_val;
}
}
$this->_header[] = $_SESSION['__WEB_APP']['REG_CITY'];
}
public function add_sheet() {//up: 20170321
$this->_ncont++;
}
public function add_field($tnama="", $nlebar=0, $talign="L", $ffunc="") {
$this->_atabel[] = [$tnama, $nlebar, $ffunc, $talign];
}
public function show_fields() {
$tmp_out = "<b>";
for ($i=0; $i<count($this->_atabel); $i++) {
$tmp_out .= $this->set_align($this->_atabel[$i][0], $this->_atabel[$i][1], "C");
if ($i < (count($this->_atabel)-1)) $tmp_out .= $this->_spacekol;
}
$tmp_out .= "</b>";
$this->_avalue[$this->_ncont][] = "__LINE -";
$this->_avalue[$this->_ncont][] = $tmp_out;
$this->_avalue[$this->_ncont][] = "__LINE -";
}
public function add_value() {
$tmp_arr = func_get_args();
if (is_array($tmp_arr[0])) $tmp_arr = $tmp_arr[0]; //up 2009-09-27
$tmp_out = "";
for ($i=0; $i<count($this->_atabel); $i++) {
$tmp_val = $tmp_arr[$i];
if (is_array($this->_atabel[$i][2]) && trim($tmp_val)<>"") { //up 2010-05-28
$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]);
if ($i < (count($this->_atabel)-1)) $tmp_val .= $this->_spacekol;
$tmp_out .= $tmp_val;
}
$this->_avalue[$this->_ncont][] = $tmp_out;
}
public function add($ttext = "") {
$this->_avalue[$this->_ncont][] = $ttext;
}
public function add_line($tmp = "-") {
$this->add("__LINE ".$tmp);
}
public function add_empty($nrep = 1) {
for ($i=0;$i<$nrep;$i++) $this->add("");
}
public function add_stamp($ctk_ke=1, $bnama=false) {
$this->add($_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):""));
}
private function _json_out() {//up: 2016-11-12
$acontent = array();
$nmax = $this->_maxchr;
for ($s=0; $s<count($this->_avalue); $s++) {
for ($i=0; $i<count($this->_avalue[$s]); $i++) {
$tmp_str = $this->_avalue[$s][$i];
if (strpos($tmp_str, "_LINE")>0) {
$tmp_arr = explode(" ", $tmp_str);
$tmp_str = str_pad($tmp_arr[1], $nmax, $tmp_arr[1]);
}
$acontent[$s][] = $tmp_str;
}
}
$aout = array('type' => "escp");
$aout['config'] = $this->_config;
$aout['header'] = $this->_header;
$aout['content'] = $acontent;
send_json($aout);
}
public function show($jumlah_ctk=1) {
$this->_config['times'] = $jumlah_ctk;
$this->_json_out();
}
public function set_align($ttext, $nlen, $tdir="L") {
$apad = array("L"=>STR_PAD_RIGHT, "R"=>STR_PAD_LEFT, "C"=>STR_PAD_BOTH);
$ttext = (strlen($ttext)>$nlen) ? substr($ttext, 0, $nlen) : $ttext;
return str_pad($ttext, $nlen, " ", $apad[$tdir]);
}
}
?>
+139
View File
@@ -0,0 +1,139 @@
<?php
/*******************************************************************
Module : /Web/Auth.php
Desc. : Fungsi login dan user checking
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : March 16th, 2008.
Last Modified : April 3rd, 2022.
(c) 2008 - 2022, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Auth {
private $__id_reg = 0;
protected $__db = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
$this->__id_reg = $_SESSION['__WEB_APP']['REG_ID'];
}
public function set_id_reg($id = 0) {
if ($id > 0) $this->__id_reg = $id;
}
public function user_check($user, $pass) {
$i_hasil = 0;
$this->__db->Query("SELECT COUNT(*) Ada FROM app_operator WHERE Username='".$this->__db->safeSQL($user)."' AND Password=MD5('".$this->__db->safeSQL($pass)."') AND Aktif=1");
if ($this->__db->Next()) $i_hasil = $this->__db->Row("Ada", 0);
return ($i_hasil > 0 ? true : false);
}
public function user_data($user) {
$adata = [];
$this->__db->Query("SELECT *,DECODE(Menu,'".$this->__id_reg."') Menu2 FROM app_operator WHERE Username='".$this->__db->SafeSQL($user)."'");
if ($this->__db->Next()) {
$adata = $this->__db->AllRow();
$adata['Menu'] = $adata['Menu2'];
unset($adata['Menu2']);
}
if (!isset($_SESSION['APP_TOKEN'])) {
$_token = $this->genToken(60);
$_SESSION['APP_TOKEN'] = $_token;
$this->__db->Query("INSERT INTO app_token SET Token='".$_token."',UserID='".$adata['UserID']."',IP='".$_SERVER['REMOTE_ADDR']."'");
}
if (intval($adata['Grup_MenuID']) > 0) $adata['Menu_Grup'] = $this->user_allmenu($adata['Grup_MenuID']);
$adata['UNIX'] = time();
$adata['LOCALE'] = $_SESSION['__WEB_APP']['DEF_LOCALE'];
return $adata;
}
public function gen_module_menu() {
$amodul = []; $aallow = [];
if ($_SESSION['__WEB_APP']['APP_MODULE']) {
$this->__db->Query("SELECT * FROM app_menu_grup WHERE Grup_MenuID='".$_SESSION['__WEB_USER']['Grup_MenuID']."' LIMIT 1");
if ($this->__db->Next()) $aallow = ($this->__db->Row("Modul_Akses")=="") ? array() : explode(",", $this->__db->Row("Modul_Akses"));
if (count($aallow) > 0) {
$this->__db->Query("SELECT * FROM (SELECT APP_MODULE,APP_PATH FROM app_config) A LEFT JOIN (SELECT Modul,Urut,Judul,Icon FROM app_menu WHERE Level=0) B ON (A.APP_MODULE=B.Modul) ORDER BY B.Urut");
while ($this->__db->Next()) {
if (!in_array($this->__db->Row("Modul"), $aallow) || $this->__db->Row("Modul")==$_SESSION['__WEB_APP']['APP_MODULE']) continue;
$amodul[] = $this->__db->AllRow();
}
}
}
$_SESSION['__WEB_USER']['MENU_MODUL'] = $amodul;
}
public function user_allmenu($id_grup = 0) {
$allmenu = "";
$this->__db->Query("SELECT DECODE(Menu,'".$this->__id_reg."') MenuX FROM app_menu_grup WHERE Grup_MenuID='".$id_grup."'");
if ($this->__db->Next()) $allmenu = $this->__db->Row("MenuX");
return $allmenu;
}
public function user_check_level($user, $level = 9) {
$i_hasil = 0;
$this->__db->Query("SELECT COUNT(*) Ada FROM app_operator WHERE Username='".$this->__db->safeSQL($user)."' AND Level<='".$this->__db->safeSQL($level)."' AND Aktif=1");
if ($this->__db->Next()) $i_hasil = $this->__db->Row("Ada", 0);
return ($i_hasil > 0 ? true : false);
}
public function user_log() {
if ($_SESSION['__WEB_APP']['USER_LOG'] == false) return;
$a_hasil = array();
$this->__db->Query("SELECT * FROM app_logs WHERE UserID='".user_id()."' ORDER BY Last_Date DESC LIMIT 1");
if ($this->__db->Next()) $a_hasil = $this->__db->AllRow();
if (count($a_hasil) > 0) {
$this->__db->Query("UPDATE app_operator SET Last_IP='".$a_hasil['Last_IP']."',Last_Date='".$a_hasil['Last_Date']."' WHERE UserID='".user_id()."'");
}
$this->__db->Query("INSERT IGNORE INTO app_logs SELECT UserID,Token,IP,DateStamp FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
}
public function logout() {
$this->__db->Query("DELETE FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
}
public function token_check() {
$hasil = false;
$this->__db->Query("SELECT * FROM app_token WHERE Token='".$_SESSION['APP_TOKEN']."'");
if ($this->__db->Next()) $hasil = true;
if ($hasil == true) $this->__db->Query("UPDATE app_token SET DateStamp=NOW() WHERE Token='".$_SESSION['APP_TOKEN']."'");
return $hasil;
}
public function token_update() {
$this->__db->Query("UPDATE app_token SET DateStamp=NOW() WHERE Token='".$_SESSION['APP_TOKEN']."'");
}
public function redirect($appUrl) {
$source = parse_url($appUrl);
$desti = "";
$this->__db->Query("SELECT * FROM app_host WHERE Nama_Host='".$source['host']."'");
if ($this->__db->Next()) {
$desti = $source['scheme'].$source['host'].$source['path'].'?'.'auth='.$_SESSION['APP_TOKEN'];
}
return $desti;
}
private function genToken($length = 16) {
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle(str_repeat($pool, 5)), 0, $length);
}
public function getUserByToken($token) {
$hasil = "";
$this->__db->Query("SELECT * FROM app_operator WHERE UserID IN (SELECT UserID FROM app_token WHERE Token='".$token."') LIMIT 1");
if ($this->__db->Next()) $hasil = $this->__db->Row("Username");
return $hasil;
}
}
?>
+65
View File
@@ -0,0 +1,65 @@
<?php
/*******************************************************************
Module : /Web/Button.php
Desc. : Button Generator (jQuery & Bootstrap)
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : February 27th, 2008.
Last Modified : January 22nd, 2024.
(c) 2008 - 2024, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
class Button {
private $__abutton =[];
public function __construct() {}
private function add($type="info", $id="", $label="", $bmiss=false) {
if ($id=="") $id = "random".rand(1000, 10000);
$this->__abutton[] = ['type'=>$type, 'id'=>$id, 'label'=>$label, 'bmiss'=>$bmiss];
}
public function separator() {
$this->__abutton[] = ['type'=>"separator"];
}
public function primary($id="", $label="", $bmiss=false) {
$this->add("primary", $id, $label, $bmiss);
}
public function info($id="", $label="", $bmiss=false) {
$this->add("info", $id, $label, $bmiss);
}
public function danger($id="", $label="", $bmiss=false) {
$this->add("danger", $id, $label, $bmiss);
}
public function warning($id="", $label="", $bmiss=false) {
$this->add("warning", $id, $label, $bmiss);
}
public function success($id="", $label="", $bmiss=false) {
$this->add("success", $id, $label, $bmiss);
}
public function secondary($id="", $label="", $bmiss=false) {
$this->add("secondary", $id, $label, $bmiss);
}
public function Button($size=2) {
if (0==count($this->__abutton)) return "";
$_out = '<div class="row mb-1"><div class="col-12 col-sm-6 my-0 mx-sm-0 text-center text-sm-start">'; $_ma = ' me-sm-2';
foreach ($this->__abutton as $item) {
if ("separator" == $item['type']) {
$_out .= '</div><div class="col-12 col-sm-6 my-0 mx-sm-0 text-center text-sm-end">'; $_ma = ' ms-sm-2';
} else {
$_out .= '<button type="button" class="btn btn-'.$item['type'].' mb-2 mb-sm-0'.$_ma.' col-10 col-sm-auto shadow-none" id="'.$item['id'].'"'.(true==$item['bmiss']?' data-bs-dismiss="modal"':'').'>'.$item['label'].'</button>';
}
}
$_out .= '</div></div>';
return $_out;
}
}
?>
+325
View File
@@ -0,0 +1,325 @@
<?php
/*******************************************************************
Module : /Web/Form.php
Desc. : Form Generator (jQuery & Bootstrap)
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : February 27th, 2008.
Last Modified : December 26th, 2025.
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Form {
private $__aform = array();
private $__ahide = array();
private $__button = null;
private $__nbtnsize = 2;
protected $__db = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
$this->__button = new Button();
}
public function option($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null, $bmulti=false, $bgroup=false) {
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_change = ($tchange==null) ? '' : ' onchange="'.$tchange.'"';
$_multi = ($bmulti==true) ? ' multiple' : '';
$tout = '<select class="form-select option-tags" id="'.$tfield.'" name="'.$tfield.'"'.$_enab.$_change.$_req.$_multi.' >';
if (count($aarr)>0) {
$n_group = 0;
foreach ($aarr as $key => $val) {
$_val2 = $val; $olabel = "";
if (is_array($val)) {
$_val2 = $val[0];
if ($bgroup) {
if (1==$val[1]) {
if (0 < $n_group++) $tout .= '</optgroup>';
$tout .= '<optgroup label="'.$_val2.'">';
continue;
}
} else {
$olabel = (isset($val[1])) ? ' olabel="'.$val[1].'"' : "";
}
}
$tout .= '<option value="'.$key.'"'.$olabel;
$aval = array($tvalue);
if ($bmulti==true) $aval = explode(",", ($tvalue ?? "0"));
$tout .= (in_array($key, $aval)) ? ' selected="selected"' : "";
$tout .= '>'.$_val2.'</option>';
}
if ($bgroup && $n_group>0) $tout .= '</optgroup>';
}
$tout .= '</select>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function option_db($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $ttable=null, $afield=null, $twhere=null, $addarray=null, $thelp=null, $tchange=null, $bmulti=false) {
$afield = ($afield==null) ? array("ID", "Nama", "Label") : $afield;
$_twhere = ($twhere==null) ? "" : " WHERE ".$twhere;
$_twhere .= ($twhere===null || stripos($twhere,"ORDER BY")===false) ? " ORDER BY ".$afield[1] : "";
$ahasil = [];
if (is_array($addarray)) $ahasil[$addarray[0]] = (!isset($afield[2])) ? $addarray[1] : [$addarray[1], $addarray[2]];
if ($ttable<>null) {
$this->__db->Query("SELECT ".implode(",", $afield)." FROM ".$ttable.$_twhere);
while ($this->__db->Next()) {
$ahasil[$this->__db->Row($afield[0])] = (!isset($afield[2])) ? $this->__db->Row($afield[1]) : [$this->__db->Row($afield[1]), $this->__db->Row($afield[2])];
}
}
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $ahasil, $thelp, $tchange, $bmulti);
return $tout;
}
public function option_que($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $tquery=null, $afield=null, $addarray=null, $thelp="", $tchange=null) {
$afield = ($afield==null) ? array("ID", "Nama", "Label") : $afield;
$ahasil = array();
if (is_array($addarray)) $ahasil[$addarray[0]] = (!isset($afield[2])) ? $addarray[1] : array($addarray[1], $addarray[2]);
if ($tquery<>null) {
$this->__db->Query($tquery);
while ($this->__db->Next()) {
$ahasil[$this->__db->Row($afield[0])] = (!isset($afield[2])) ? $this->__db->Row($afield[1]) : array($this->__db->Row($afield[1]), $this->__db->Row($afield[2]));
}
}
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $ahasil, $thelp, $tchange);
return $tout;
}
public function option_jkl($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) {
$akel = array("L" => "Laki-Laki", "P" => "Perempuan");
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $akel, $thelp, $tchange);
return $tout;
}
public function option_ulevel($tlabel="", $tfield, $tvalue=9, $benable=true, $breq=false, $thelp="", $tchange=null) {
$tout = $this->option($tlabel, $tfield, $tvalue, $benable, $breq, $_SESSION['__WEB_APP']['USER_LEVEL'], $thelp, $tchange);
return $tout;
}
public function radio($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null) {
if ($tvalue == null) {
$tmp_key = array_keys($aarr);
$tvalue = $tmp_key[0];
}
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_change = ($tchange==null) ? "" : ' onchange="'.$tchange.'"';
$tout = '<input type="hidden" id="'.$tfield.'" value="'.$tvalue.'" />';
if (count($aarr)>0) {
foreach ($aarr as $key => $val) {
$tout .= '<div class="form-check form-check-inline me-2"><input class="form-check-input" id="'.$tfield.$key.'" type="radio" value="'.$key.'" name="'.$tfield.'"';
$tout .= ($key == $tvalue) ? ' checked="checked"' : '';
$tout .= ' onclick="if(this.checked)$(\'#'.$tfield.'\').val(this.value);"'.$_enab.$_change.$_req;
$tout .= '><label class="form-check-label" for="'.$tfield.$key.'">'.$val.'</label></div>';
}
}
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function radio_jkl($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) {
$tout = $this->radio($tlabel, $tfield, $tvalue, $benable, $breq, array("L" => "Laki-Laki", "P" => "Perempuan"), $thelp, $tchange);
return $tout;
}
public function radio_gd($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) {
$tvalue = ($tvalue=="") ? "X" : $tvalue;
$tout = $this->radio($tlabel, $tfield, $tvalue, $benable, $breq, array("A"=>"A", "B"=>"B", "AB"=>"AB", "O"=>"O", "X"=>"NONE"), $thelp, $tchange);
return $tout;
}
public function checkbox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $avalue=array(), $thelp="", $tchange=null) {
$bhasil = ((is_string($tvalue) && in_array($tvalue,array("N","T","0"))) or (is_numeric($tvalue) && $tvalue==0) or (is_bool($tvalue) && $tvalue===false) or empty($tvalue)) ? true : false;
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_change = ' onchange="this.value=(this.checked)?\''.$avalue[0].'\':\''.$avalue[1].'\';'.($tchange==null?'':$tchange).'"';
$tout = '<input type="checkbox" class="form-check-input" id="'.$tfield.'" name="'.$tfield.'" value="'.($bhasil?$avalue[1]:$avalue[0]).'"'.$_enab.$_change.$_req;
$tout .= ($bhasil==false) ? ' checked="checked"' : '';
$tout .= '>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function switch($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $aarr=array(), $thelp="", $tchange=null) {
$_val = array_values($aarr);
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_change = ($tchange==null) ? ' onchange="this.value=(this.checked)?\''.$_val[0].'\':\''.$_val[1].'\';"' : ' onchange="this.value=(this.checked)?\''.$_val[0].'\':\''.$_val[1].'\';'.$tchange.'"';
$tout = '<div class="form-check form-switch"><input class="form-check-input me-0" id="'.$tfield.'" name="'.$tfield.'" type="checkbox" role="switch" value="'.$tvalue.'"'.$_enab.$_change.$_req;
$tout .= ($_val[0] == $tvalue) ? ' checked="checked"' : '';
$tout .= '></div>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
//todo: belum diupgrade !!
public function group_cbox($tfield, $tkey=null, $tclass=null, $ttable=null, $afield=null, $ncol=2) {
if ($ttable==null) return;
$avalue = explode(",", $tkey);
$afield = ($afield==null) ? array("ID", "Nama") : $afield;
$_twhere = ($twhere=="") ? " ORDER BY ".$afield[0] : " WHERE ".$twhere;
$tout = "<input id=\"".$tfield."\" value=\"".$tkey."\" type='hidden' class='cgrpbox' /><table width='100%' style='margin:1px 0;padding:2px 2px;'><tr>";
$nkol = 1;
$this->__db->Query("SELECT ".implode(",", $afield)." FROM ".$ttable.$_twhere);
while ($this->__db->Next()) {
$tout .= "<td width='".round(100/$ncol)."%'><label><input type='checkbox' id='".$tfield."_cgrpbox_".$this->__db->Row($afield[0])."' value='".$this->__db->Row($afield[0])."'";
for ($i=0; $i<count($avalue); $i++) {
if ($avalue[$i]==$this->__db->Row($afield[0])) {
$tout .= " checked=\"checked\"";
break;
}
}
$tout .= " class='text ".$tclass."' />&nbsp;".$this->__db->Row($afield[1])."</label></td>";
if ($nkol==$ncol) {
$tout .= "</tr><tr>";
$nkol = 0;
}
$nkol++;
}
$tout .= "</tr></table>";
$this->__aform[$tfield] = $tout;
return $tout;
}
public function textbox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $ttype="text", $holdtxt=null, $nmaxsize=null, $thelp="", $tkeyup=null, $tblur=null) {
$_enab = ($benable==true) ? "" : ' readonly';
$_req = ($breq==true) ? " required=true" : "";
$_max = ($nmaxsize==null) ? "" : ' maxlength="'.$nmaxsize.'"';
$_keyup = ($tkeyup==null) ? "" : ' onkeyup="'.$tkeyup.'"';
$_blur = ($tblur==null) ? "" : ' onblur="'.$tblur.'"';
$_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"';
$_tclass = "";
if (in_array($ttype,array("pickdate","picktime"))) {
$_tclass = ' '.$ttype;
$ttype = "text";
}
if (in_array($ttype,array("double"))) {
$_tclass = ' '.$ttype;
$tvalue = uang2($tvalue);
}
$tout = '<input type="'.$ttype.'" class="form-control'.$_tclass.'" id="'.$tfield.'" name="'.$tfield.'" value="'.$tvalue.'"'.$_enab.$_max.$_keyup.$_blur.$_holdtxt.$_req.' />';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function textauto($tlabel="", $tfield, $avalue=['value'=>0,'text'=>""], $benable=true, $breq=false, $holdtxt=null, $nmaxsize=null, $thelp="") {
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_max = ($nmaxsize==null) ? "" : ' maxlength="'.$nmaxsize.'"';
$_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"';
$tout = '<input type="search" class="form-control" id="'.$tfield.'" name="'.$tfield.'" value="'.$avalue['text'].'"'.$_enab.$_max.$_holdtxt.$_req.' autocomplete="off" />';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function datebox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tkeyup=null, $tblur=null) {
if ($tvalue<>null) $tvalue = tgl_sql2str($tvalue);
$tout = '<div class="input-group">';
$tout .= $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "pickdate", "dd-mm-yyyy", 12, $thelp, $tkeyup, $tblur);
$tout .= '<span class="input-group-text"><i class="bi-calendar4"></i></span></div>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function timebox($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tkeyup=null, $tblur=null) {
$tout = $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "picktime", "hh:mm:ss", 10, $thelp, $tkeyup, $tblur);
return $tout;
}
public function textarea($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $nrows=1, $holdtxt=null, $thelp="", $tkeyup=null, $tblur=null) {
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_rows = ($nrows==null) ? "" : ' rows="'.$nrows.'"';
$_keyup = ($tkeyup==null) ? "" : ' onkeyup="'.$tkeyup.'"';
$_blur = ($tblur==null) ? "" : ' onblur="'.$tblur.'"';
$_holdtxt = ($holdtxt==null) ? "" : ' placeholder="'.$holdtxt.'"';
$tout = '<textarea class="form-control" id="'.$tfield.'" name="'.$tfield.'"'.$_enab.$_rows.$_keyup.$_blur.$_holdtxt.$_req.' >'.$tvalue.'</textarea>';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function plaintext($tlabel="", $tfield, $tvalue=null) {
$tout = '<input type="text" class="form-control-plaintext" id="'.$tfield.'" name="'.$tfield.'" value="'.$tvalue.'" readonly />';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>"", 'form'=>$tout);
return $tout;
}
public function password($tlabel="", $tfield, $tvalue="", $benable=true, $breq=false, $holdtxt=null, $nmaxsize=null, $thelp="", $tkeyup=null) {
$tout = $this->textbox($tlabel, $tfield, $tvalue, $benable, $breq, "password", $holdtxt, $nmaxsize, $thelp, $tkeyup, $tblur);
return $tout;
}
public function color($tlabel="", $tfield, $tvalue=null, $benable=true, $breq=false, $thelp="", $tchange=null) {
$_enab = ($benable==true) ? "" : ' disabled=true';
$_req = ($breq==true) ? " required=true" : "";
$_change = ($tchange==null) ? '' : ' onchange="'.$tchange.'"';
$tout = '<input type="color" class="form-control form-control-color" id="'.$tfield.'" name="'.$tfield.'" value="'.$tvalue.'"'.$_enab.$_change.$_req.' />';
$this->__aform[$tfield] = array('label'=>$tlabel, 'help'=>$thelp, 'form'=>$tout);
return $tout;
}
public function hidden($tfield, $tvalue="", $tclass="text") {
$tout = '<input type="hidden" id="'.$tfield.'" value="'.$tvalue.'" class="'.$tclass.'" />';
$this->__ahide[$tfield] = $tout;
return $tout;
}
public function clear() {
$this->__aform = array();
}
public function show($tstr) {
foreach ($this->__aform as $_key => $_val) {
$tval = '<div class="row mb-1"><label class="col-sm-5 col-lg-4 col-form-label" for="'.$_key.'">'.$_val['label'].'</label><div class="col-sm-7 col-lg-8">'.$_val['form'].($_val['help']==""?'':'<span class="help-block"><small>'.$_val['help'].'</small></span>').'</div></div>';
$tstr = str_replace("_".$_key."_", $tval, $tstr);
}
$txtbtn = $this->__button->Button($this->__nbtnsize);
if (""<>$txtbtn) {
$tstr .= '<div class="row mb-1"><div class="col"><hr class="my-2"></div></div>';
$tstr .= $txtbtn;
}
foreach ($this->__ahide as $_key => $_val) {
$tstr = str_replace("_".$_key."_", $_val, $tstr);
}
$tstr = str_replace("\n", "", $tstr);
$tstr = str_replace("\t", "", $tstr);
echo $tstr;
}
public function btn_separator() {
$this->__button->separator();
}
public function btn_primary($id="", $label="", $bmiss=false) {
$this->__button->primary($id, $label, $bmiss);
}
public function btn_info($id="", $label="", $bmiss=false) {
$this->__button->info($id, $label, $bmiss);
}
public function btn_danger($id="", $label="", $bmiss=false) {
$this->__button->danger($id, $label, $bmiss);
}
public function btn_warning($id="", $label="", $bmiss=false) {
$this->__button->warning($id, $label, $bmiss);
}
public function btn_success($id="", $label="", $bmiss=false) {
$this->__button->success($id, $label, $bmiss);
}
public function btn_secondary($id="", $label="", $bmiss=false) {
$this->__button->secondary($id, $label, $bmiss);
}
public function Button($size=2) {
$this->__nbtnsize = $size;
}
}
?>
+154
View File
@@ -0,0 +1,154 @@
<?php
/*******************************************************************
Module : /Web/Menu.php
Desc. : Class menu
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : January 16th, 2008.
Last Modified : December 26th, 2025.
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Menu {
protected $__db = null;
public function __construct($db = null){
$this->__db = $db ?? new \siaupheng\webapp\DB\MySQL();
}
private function Menu_Query($qry = "", $order = "Kode") {
$twhere = ($qry!="") ? "WHERE ".$qry : "";
$this->__db->Query("SELECT * FROM app_menu ".$twhere." ORDER BY ".$order." ASC");
$ahasil = array();
while ($this->__db->Next()) {
$ahasil[] = $this->__db->AllRow();
}
return $ahasil;
}
public function Menu_Sidebar() {//oke
$a_modul = array();
$is_modul = (($_SESSION['__WEB_APP']['APP_MODULE'] ?? "") <> "") ? true : false;
if ($is_modul == true) {
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
} else {
$atmp = $this->Menu_Query("Level=0 AND Aktif=1 AND Modul<>'IND'", "Urut");
for ($i=0; $i<count($atmp); $i++) {
$a_modul[] = $atmp[$i]['Modul'];
}
}
$my_menu = array_unique(array_filter(explode(",", $_SESSION['__WEB_USER']['Menu_Grup'].",".$_SESSION['__WEB_USER']['Menu'])));
$tsql = " AND Modul IN ('".implode("','",$a_modul)."')";
$tsql .= ($is_modul == true) ? " AND Level>0" : "";
$tsql .= " AND Kode IN ('".implode("','",$my_menu)."')";
$amodul = $this->Menu_Query("Aktif=1".$tsql, "Kode");
$thasil = '';
$last_level = 0;
for ($i=0; $i<count($amodul); $i++) {
if (($i>0) and ($amodul[$i]['Level']<$amodul[$i-1]['Level'])) {
$thasil .= str_repeat("</ul></li>", $amodul[$i-1]['Level']-$amodul[$i]['Level']);
}
$ticon = ($amodul[$i]['Icon']) ? '<i class="me-2 '.$amodul[$i]['Icon'].'"></i>' : "";
if (($amodul[$i]['Level']>=0) && (isset($amodul[$i+1]) && ($amodul[$i+1]['Level']>$amodul[$i]['Level']))) {
$thasil .= '<li class="nav-item has-submenu"><a class="nav-link" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'<i class="bi-caret-down float-end"></i></a><ul class="submenu collapse">';
} else if (trim($amodul[$i]['Menu'])=="-") {
$thasil .= '<li class="nav-divider"></li>';
} else {
$thasil .= '<li class="nav-item"><a class="nav-link mlink" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a></li>';
}
$last_level = $amodul[$i]['Level'];
}
if ($last_level>1) $thasil .= str_repeat("</ul></li>", $last_level-1);
return $thasil;
}
public function Menu_Header() {//oke
$a_modul = array();
$is_modul = (($_SESSION['__WEB_APP']['APP_MODULE'] ?? "") <> "") ? true : false;
$mulai_level = 0;
if ($is_modul == true) {
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
$mulai_level = 1;
} else {
$atmp = $this->Menu_Query("Level=0 AND Aktif=1 AND Modul<>'IND'", "Urut");
for ($i=0; $i<count($atmp); $i++) {
$a_modul[] = $atmp[$i]['Modul'];
}
}
$my_menu = array_unique(array_filter(explode(",", $_SESSION['__WEB_USER']['Menu_Grup'].",".$_SESSION['__WEB_USER']['Menu'])));
$tsql = " AND Modul IN ('".implode("','",$a_modul)."')";
$tsql .= ($is_modul == true) ? " AND Level>0" : "";
$tsql .= " AND Kode IN ('".implode("','",$my_menu)."')";
$amodul = $this->Menu_Query("Aktif=1".$tsql, "Kode");
$thasil = '';
$last_level = 0;
for ($i=0; $i<count($amodul); $i++) {
if (($i>0) and ($amodul[$i]['Level']<$amodul[$i-1]['Level'])) {
$thasil .= str_repeat("</ul></li>", $amodul[$i-1]['Level']-$amodul[$i]['Level']);
}
$ticon = ($amodul[$i]['Icon']) ? '<i class="me-2 '.$amodul[$i]['Icon'].'"></i>' : "";
if (isset($amodul[$i+1]) && ($amodul[$i+1]['Level']>$amodul[$i]['Level'])) {//have submenu
if ($amodul[$i]['Level']==$mulai_level) {
$thasil .= '<li class="nav-item pe-4 dropdown"><a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a><ul class="dropdown-menu" data-bs-popper="none">';
} else {
$thasil .= '<li class="dropdown-submenu"><a class="dropdown-item dropdown-toggle slink" data-bs-toggle="dropdown" aria-expanded="false" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a><ul class="dropdown-menu" data-bs-popper="none">';
}
} else if (trim($amodul[$i]['Menu'])=="-" && $amodul[$i]['Level']>$mulai_level) {//divider
$thasil .= '<li class="dropdown-divider"></li>';
} else if ($amodul[$i]['Level']==$mulai_level) {//level = 1 + no submenu
$thasil .= '<li class="nav-item pe-4"><a class="nav-link mlink" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a></li>';
} else {// level > 1 + no submenu
$thasil .= '<li><a class="dropdown-item mlink" id="'.$amodul[$i]['Kode'].'Link" title="'.$amodul[$i]['Judul'].'">'.$ticon.$amodul[$i]['Menu'].'</a></li>';
}
$last_level = $amodul[$i]['Level'];
}
if ($last_level>$mulai_level) $thasil .= str_repeat("</ul></li>", $last_level-$mulai_level);
return $thasil;
}
static function MenuJSON($db = null, $page = "", $tquery = "") {//oke
$_mdb = $db ?? new \siaupheng\webapp\DB\MySQL();
$_query = ($tquery=="") ? "" : ",'".$tquery."'";
$ajson = ['login' => true];
$apage = ['Link' => ""];
$acus_page = [
'SYSP' => ['Kode'=>"SYSP", 'Judul'=>"Profil Pengguna", 'Link'=>"sys/profile.php", 'JS'=>"SYSProfileJS", 'Width'=>600, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]'],
'SYSC' => ['Kode'=>"SYSC", 'Judul'=>"Ubah Password", 'Link'=>"sys/chpasswd.php", 'JS'=>"SYSChpasswdJS", 'Width'=>500, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]']
];
if ($acus_page[$page] ?? false) {
$apage = $acus_page[$page];
} else if ($page <> "") {
$_mdb->Query("SELECT * FROM app_menu WHERE Kode='".$page."'");
if ($_mdb->Next()) $apage = $_mdb->AllRow();
$apage['Width'] = intval($apage['Width']);
}
$ajson['iswindow'] = ($apage['Width'] > 0) ? true : false;
$ajson['width'] = $apage['Width'];
$ajson['title'] = $apage['Judul'];
$ajson['button'] = is_json($apage['Button']) ? json_decode($apage['Button']) : $apage['Button'];
$ajson['php'] = $apage['Link'];
$ajson['func'] = $apage['JS'];
$ajson['kode'] = $apage['Kode'];
if (!file_exists($_SESSION['__WEB_APP']['REAL_PATH']."apps/php/".$apage['Link'])) $ajson['php'] = "";
return $ajson;
}
}
?>
+72
View File
@@ -0,0 +1,72 @@
<?php
/*******************************************************************
Module : /Web/Param.php
Desc. : Class data parameter dari client side
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : November 14th, 2013.
Last Modified : May 8th, 2021.
(c) 2013 - 2021, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Param {
private static $__ahasil = [];
public function __construct() {
if (count(self::$__ahasil)==0) self::__data();
}
private static function __data() {
$_asumber = array_merge($_REQUEST, $_POST, $_GET);
foreach ($_asumber as $__key => $__val) {
self::$__ahasil[$__key] = self::safeSQL($__val);
}
}
public static function safeSQL($tstr = "") {
$_se = array("\\","\0","\n","\r","\x1a","'",'"');
$_re = array("\\\\","\\0","\\n","\\r","\Z","\'",'\"');
return str_replace($_se, $_re, $tstr);
}
public static function Get($tkey = "", $tdef = null) {
if (count(self::$__ahasil)==0) self::__data();
if (isset(self::$__ahasil[$tkey]) && self::$__ahasil[$tkey]) return self::$__ahasil[$tkey];
return $tdef;
}
public static function Get_Text($tkey = "", $tdef = null) {
if (count(self::$__ahasil)==0) self::__data();
$_str = (isset(self::$__ahasil[$tkey])) ? self::$__ahasil[$tkey] : $tdef;
$_str = str_replace("\\r", "", $_str);
$_str = str_replace("\\n", " ", $_str);
$_str = str_replace("\\t", " ", $_str);
return (trim($_str));
}
public static function Get_Array() {
if (count(self::$__ahasil)==0) self::__data();
return self::$__ahasil;
}
public static function Get_ArrayCBOX() {//note: bisa tidak dipakai lagi
if (count(self::$__ahasil)==0) self::__data();
$_ahasil = [];
foreach (self::$__ahasil as $__key => $__val) {
if (strpos($__key, "_cbox_")>0) {
$_tmpkey = substr($__key, strpos($__key, "_cbox_")+6);
$_ahasil[$_tmpkey] = $__val;
}
}
return $_ahasil;
}
}
?>
+47
View File
@@ -0,0 +1,47 @@
<?php
/*******************************************************************
Module : /Web/Register.php
Desc. : Class Registrasi Aplikasi
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : November 23th, 2011.
Last Modified : May 6th, 2021.
(c) 2011 - 2021, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Register {
protected $__db = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); }
}
static public function reg_id() {
$id = $_SESSION['__WEB_APP']['REG_ID'] ?? "";
return (substr($id,0,3).".".substr($id,3,3).".".substr($id,6));
}
static public function reg_code() {
$id = $_SESSION['__WEB_APP']['REG_CODE'];
return (substr($id,0,6)."-".substr($id,6,5)."-".substr($id,11,5)."-".substr($id,16,5)."-".substr($id,21,5)."-".substr($id,26,6));
}
public function reg_check() {
$isreg = false;
$this->__db->Query("SELECT UPPER(CONVERT(MD5(CONCAT(REG_YEAR,CONVERT(MD5(CONCAT(REG_ID,REG_NAME)) using latin1),REG_ID,REG_NAME)) using latin1)) KODE_REGISTER FROM app_config WHERE REG_ID='".$_SESSION['__WEB_APP']['APP_CODE']."' LIMIT 1");
if ($this->__db->Next()) {
if ($this->__db->Row("KODE_REGISTER","")==$_SESSION['__WEB_APP']['REG_CODE']) $isreg = true;
}
return $isreg;
}
}
?>
+316
View File
@@ -0,0 +1,316 @@
<?php
/*******************************************************************
Module : /Web/Table.php
Desc. : HTML Table (jQuery & Bootstrap)
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : January 16th, 2008.
Last Modified : January 26th, 2026.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Table {
private $__ttable = "";
private $__tfield = "";
private $__twhere = "";
private $__tquery = "";
private $__tquery_footer = "";
private $__aheader = [];
private $__afield = [];
private $__astyle = [];
private $__aformat = [];
private $__afooter = [];
private $__aotype = [];
private $__arowcol = [];
private $__arow_func = [];
private $__tfunc_select = "";
private $__tfunc_navi = "";
private $__btxtbutton = false;
private $__bnobutton = false;
private $__bscrollbar = false;
private $__acontrol = ['field'=>false, 'value'=>""];
private $__acbox = [];
private $__aoption = [];
private $__npage_rec = 10;
private $__nreclimit = 0;
private $__nscrollheight = 0;
private $__ord_field = "";
private $__ord_dir = "A";
private $__tcss = "";
private $__livedata = false;
protected $__cdb = null;
protected $__cpa = null;
public function __construct($db = null){
if (is_resource($db)) { $this->__cdb = $db; }
else { $this->__cdb = new \siaupheng\webapp\DB\MySQL(); }
$this->__cpa = new \siaupheng\webapp\Web\Param();
}
public function set_table($ttable = "", $tfield = "", $twhere = "") {
$this->__ttable = $ttable;
if ($tfield != "") $this->__tfield = $tfield;
if ($twhere != "") $this->__twhere = $twhere;
}
public function set_query($tquery = "") {
$this->__tquery = $tquery;
}
public function set_query_footer($tquery = "") {
$this->__tquery_footer = $tquery;
}
public function set_css($tcss = "") {
$this->__tcss = $tcss;
}
public function set_limit($nlimit = 0) {
$this->__nreclimit = $nlimit;
}
public function set_field_order($tfield = "", $torder = "A") {
$this->__ord_field = $tfield;
$this->__ord_dir = $torder;
}
public function set_textbtn($bistxt = true) {
$this->__btxtbutton = $bistxt;
}
public function set_scrollbar($bisscroll = true, $nheight = 200) {
$this->__bscrollbar = $bisscroll;
$this->__nscrollheight = $nheight;
}
public function set_row_color($tfield = "", $tval = "", $tcss = "") {
if ($tfield=="") return;
$this->__arowcol[] = ['F'=>$tfield, 'V'=>$tval, 'C'=>$tcss];
}
public function set_func_navi($tfunc = "") {
$this->__tfunc_navi = $tfunc;
}
public function set_func_select($tfunc = "") {
$this->__tfunc_select = $tfunc;
}
public function set_func_btn($tfunc = "", $tlabel = "") {
$this->__arow_func[] = ['label' => $tlabel, 'func' => $tfunc];
}
public function set_row_control($tfield = "", $tvalue = "Y") {
$this->__acontrol['field'] = $tfield;
$this->__acontrol['value'] = $tvalue;
}
public function add_row_form($ticon = "pencil", $tlabel = "", $tfunc = "", $tfield = "", $tvalue = "") {
if ($tfunc == "") {
$this->__aoption[] = ['type' => "button-dt", 'func' => $tlabel, 'icon' => "pencil", 'label' => $ticon];
} else {//todo: new format with icon, upgrade all later !
$this->__aoption[] = ['type' => "button-dt", 'func' => $tfunc, 'icon' => $ticon, 'label' => $tlabel, 'field' => $tfield, 'value' => $tvalue];
}
}
public function add_row_btn($ticon = "", $tlabel = "", $tfunc = "", $tfield = "", $tvalue = "", $tfield_css = "", $avalue_css = []) {
$this->__aoption[] = ['type' => "button", 'func' => $tfunc, 'icon' => $ticon, 'label' => $tlabel, 'field' => $tfield, 'value' => $tvalue, 'field_css' => $tfield_css, 'avalue_css' => $avalue_css];
}
public function add_row_del($tlabel = "", $tfunc = "", $tfield = "Unix", $tvalue = "") {
$this->__aoption[] = ['type' => "button", 'func' => $tfunc, 'icon' => "x", 'label' => $tlabel, 'field' => $tfield, 'value' => $tvalue];
}
public function add_row_edit($tlabel = "", $tfunc = "") {
$this->add_row_btn("note", $tlabel, $tfunc);
}
public function add_row_checkbox($tfield = "ID", $tcontrol = "Edit", $avalue = ["Y","N"]) {
$this->__acbox['field'] = $tfield;
$this->__acbox['control'] = $tcontrol;
$this->__acbox['avalue'] = $avalue;
$this->__aoption[] = ['type' => "checkbox", 'field' => $tfield, 'avalue' => $avalue];
}
public function no_button() {
$this->__bnobutton = true;
}
public function add_field($tfield = "", $theader = "", $tstyle = "l", $tformat = "", $tfooter = "", $totype = "") {
$this->__aheader[] = $theader;
$this->__afield[] = $tfield;
$this->__astyle[] = $tstyle;
$this->__aformat[] = $tformat;
$this->__afooter[] = $tfooter;
$this->__aotype[] = $totype;
}
public function json_table($nama_tabel = "tabel_", $baris_tabel = 10) {
$adata = []; $njml_kol = 0;
// adding header
for ($i=0; $i<count($this->__afield); $i++) {
$adata['header'][] = ['f'=>$this->__astyle[$i], 'o'=>$this->__afield[$i], 'c'=>$this->__aheader[$i], 's'=>$this->__aotype[$i]];
$njml_kol += ($this->__astyle[$i]=="hidden") ? 0 : 1;
}
// adding footer
if ($this->__tquery_footer) {
$this->__cdb->Query($this->__tquery_footer);
$this->__cdb->Next();
for ($i=0; $i<count($this->__afield); $i++) {
$tval = $this->__cdb->Row($this->__afield[$i], 0);
if (is_array($this->__afooter[$i])) {
$tval2 = $this->__afooter[$i][$tval];
} else if (!is_null($this->__afooter[$i]) && function_exists($this->__afooter[$i])) {
$tval2 = call_user_func($this->__afooter[$i], $tval);
} else {
$tval2 = ($this->__afooter[$i]<>"") ? $this->__afooter[$i] : $tval;
}
$adata['footer'][] = ['c'=>$tval2];
}
}
$acontent = [];
if (!$this->__livedata) {
$this->__cdb->Query($this->__tquery);
while ($this->__cdb->Next()) {
$abaris = [];
$aoption = ['button'=>[]];
if (count($this->__aoption)>0) {
if ((($this->__acontrol['field']===false) || ($this->__cdb->Row($this->__acontrol['field'])==$this->__acontrol['value'])) && $this->__bnobutton===false) {
// adding all option
for ($i=0; $i<count($this->__aoption); $i++) {
if (in_array($this->__aoption[$i]['type'], ["button","button-dt"])) {
if (!isset($this->__aoption[$i]['field'])) continue;
if (($this->__aoption[$i]['field']!="") && ($this->__cdb->Row($this->__aoption[$i]['field'])<>(trim("".$this->__aoption[$i]['value'])!="" ? $this->__aoption[$i]['value'] : $_SESSION['__WEB_USER']['UNIX']))) {} else {
$aoption['button'][] = [$this->__aoption[$i]['icon'], (empty($this->__aoption[$i]['field_css'])?'':$this->__aoption[$i]['avalue_css'][$this->__cdb->Row($this->__aoption[$i]['field_css'])]??'')];
}
}
}
// adding checkbox option
if (array_key_exists("field", $this->__acbox)) {
$aoption['checkbox']['field'] = $this->__cdb->Row($this->__acbox['field']);
$aoption['checkbox']['value'] = $this->__cdb->Row($this->__acbox['control']);
}
}
}
if (count($this->__arowcol)>0) {//up: 2014-06-13
for ($i=0; $i<count($this->__arowcol); $i++) {
if ($this->__cdb->Row($this->__arowcol[$i]['F']) == $this->__arowcol[$i]['V']) $aoption['rowcss'] = $this->__arowcol[$i]['C'];
}
}
$abaris[] = $aoption;
for ($i=0; $i<count($this->__afield); $i++) {
$tval = stripslashes($this->__cdb->Row($this->__afield[$i]));//up: 2015-01-05
if (is_array($this->__aformat[$i])) {
$tval = $this->__aformat[$i][$tval];
} else if (!is_null($this->__aformat[$i]) && function_exists($this->__aformat[$i])) {
$tval = call_user_func($this->__aformat[$i], $tval);
}
$abaris[] = $tval;
}
$acontent[] = $abaris;
}
}
// navigator
$anavi = [ 'func_navi' => $this->__tfunc_navi, 'button' => $this->__arow_func ];
$adata['type'] = "table";
$adata['id'] = $nama_tabel;
$adata['config'] = ['css' => $this->__tcss, 'row_count' => $baris_tabel, 'func_select' => $this->__tfunc_select, 'nobutton' => $this->__bnobutton, 'txtbutton' => $this->__btxtbutton, 'scrollbar' => $this->__bscrollbar, 'scroll_height' => $this->__nscrollheight, 'sort_col' => $this->__ord_field, 'sort_dir' => $this->__ord_dir, 'live' => $this->__livedata];
$adata['option'] = [];
foreach ($this->__aoption as $aval) {
if ($aval['type']!=="checkbox") unset($aval['field']); unset($aval['value']); unset($aval['field_css']); unset($aval['value_css']); $adata['option'][] = $aval;
}
$adata['navi'] = $anavi;
$adata['content'] = $acontent;
return $adata;
}
public function db_table($nama_tabel = "tabel_", $baris_tabel = 10) {
$adata = [];
$this->__livedata = true;
$this->prepare_query();
$id_draw = intval($this->__cpa->Get("draw", 0));
$i_start = intval($this->__cpa->Get("start", 0));
$i_length = intval($this->__cpa->Get("length", 0));
$i_order = $this->__cpa->Get("order", 0);
if ($id_draw > 0) {
$record = 0;
$this->__cdb->Query("SELECT COUNT(*) Item FROM ".$this->__ttable.$this->__twhere);
if ($this->__cdb->Next()) $record = intval($this->__cdb->Row("Item", 0));
$adata['type'] = "table-live";
$adata['id'] = $nama_tabel;
$adata['config'] = ['draw' => $id_draw, 'recordsTotal' => $record, 'recordsFiltered' => $record];
$t_order = "ASC";
if ($i_order <> 0) {
$t_order = ($i_order[0]['dir']=="asc") ? "ASC" : "DESC";
$i_order = $i_order[0]['column'];
}
if (($i_length > $record) || ($i_start >= $record) || ($record <= 10)) $i_length = -1;
$sql_limit = ($i_start>=0 && $i_length != -1) ? " LIMIT ".$i_start.", ".$i_length : "";
$sql_order = ($this->__afield[$i_order]) ? " ORDER BY ".$this->__afield[$i_order]." ".$t_order : "";
$adata['data'] = [];
$this->__cdb->Query("SELECT ".$this->__tfield." FROM ".$this->__ttable.$this->__twhere.$sql_order.$sql_limit);
while ($this->__cdb->Next()) {
$abaris = [];
$aoption = ['button'=>[]];
if (count($this->__aoption)>0) {
if ((($this->__acontrol['field']===false) || ($this->__cdb->Row($this->__acontrol['field'])==$this->__acontrol['value'])) && $this->__bnobutton===false) {
// adding all option
for ($i=0; $i<count($this->__aoption); $i++) {
if (in_array($this->__aoption[$i]['type'], ["button","button-dt"])) {
if (($this->__aoption[$i]['field']!="") && ($this->__cdb->Row($this->__aoption[$i]['field'])<>(trim("".$this->__aoption[$i]['value'])!="" ? $this->__aoption[$i]['value'] : $_SESSION['__WEB_USER']['UNIX']))) {} else {
$aoption['button'][] = [$this->__aoption[$i]['icon'], (empty($this->__aoption[$i]['field_css'])?'':$this->__aoption[$i]['avalue_css'][$this->__cdb->Row($this->__aoption[$i]['field_css'])]??'')];
}
}
}
// adding checkbox option
if (array_key_exists("field", $this->__acbox)) {
$aoption['checkbox']['field'] = $this->__cdb->Row($this->__acbox['field']);
$aoption['checkbox']['value'] = $this->__cdb->Row($this->__acbox['control']);
}
}
}
if (count($this->__arowcol)>0) {//up: 2014-06-13
for ($i=0; $i<count($this->__arowcol); $i++) {
if ($this->__cdb->Row($this->__arowcol[$i]['F']) == $this->__arowcol[$i]['V']) $aoption['rowcss'] = $this->__arowcol[$i]['C'];
}
}
$abaris[] = $aoption;
for ($i=0; $i<count($this->__afield); $i++) {
$tval = stripslashes($this->__cdb->Row($this->__afield[$i]));//up: 2015-01-05
if (is_array($this->__aformat[$i])) {
$tval = $this->__aformat[$i][$tval];
} else if (!is_null($this->__aformat[$i]) && function_exists($this->__aformat[$i])) {
$tval = call_user_func($this->__aformat[$i], $tval);
}
$abaris[] = $tval;
}
$adata['data'][] = $abaris;
}
} else {
$adata = $this->json_table($nama_tabel, $baris_tabel);
}
return $adata;
}
private function prepare_query() {
if ($this->__tfield == "") $this->__tfield = "`".implode('`,`', $this->__afield)."`";
if ($this->__twhere != "") $this->__twhere = " WHERE " . $this->__twhere;
}
}
?>
+132
View File
@@ -0,0 +1,132 @@
<?php
/*******************************************************************
Module : /Web/Terbilang.php
Desc. : Class Format Angka & Terbilang
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : February 12th, 2009.
Last Modified : May 6th, 2021.
(c) 2009 - 2021, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Terbilang {
private $numb = array("","Satu","Dua","Tiga","Empat","Lima","Enam","Tujuh","Delapan","Sembilan");
public function __construct() {}
public function Terbilang($nilai=0, $muang="Rupiah") {
$number = 0;
$hasil = "";
$int = trim($nilai);
if (is_int(strpos($int,"-"))) {
$number = substr($int,strpos($int,"-")+1,strlen($int));
$hasil = "Minus";
} else {
$number = $int;
}
# strpost : untuk mencari "." pada variabel number
$xpos = strpos($number,".");
if (is_int($xpos)) {
# round : Untuk pembulatan angka desimal, strlen : untuk menghitung jumlah karakter
$pecahan = round(substr($number,$xpos,strlen($number)),2);
$last = substr($number,0,$xpos);
} else {
$pecahan = "";
$last = $number;
}
if ($last==0 || $number==0) {
return $hasil."NOL ".$muang;
} else {
# floor : Pembulatan angka terbaik dari desimal, pow : Ekspresi Eksponensial
$triliun = floor($last/pow(10,12));
$last = $this->mod($last,1000000000000);
$miliar = floor($last/pow(10,9));
$last = $this->mod($last,1000000000);
$juta = floor($last/pow(10,6));
$last = $this->mod($last,1000000);
$ribu = floor($last/pow(10,3));
$last = $this->mod($last,1000);
$kata = $this->tigadigit($triliun, "Triliun");
$kata .= $this->tigadigit($miliar, "Miliar");
$kata .= $this->tigadigit($juta, "Juta");
$kata .= $this->tigadigit($ribu, "Ribu");
$kata .= $this->tigadigit($last, "");
$kata .= " ".$muang;
}
if ($pecahan>0) {
$kata .= " Dan". $this->tigadigit(round($pecahan*100),"Sen");
}
return $hasil . $kata;
}
private function mod($a, $b) {
return $a-$b*floor($a/$b);
}
private function tigadigit($amount, $suffix="") {
$last = (int) $amount;
$kata = "";
if ($last == 1 && $suffix=="Ribu") {
$kata = " Seribu";
return $kata;
}
if ($last < 20 && $last > 10) {
if ($last==11) {
$kata = " Sebelas";
} else {
$kata = " ".$this->numb[$last-10]." Belas";
}
if ($suffix != "") {
$kata .= " ". $suffix;
}
return $kata;
}
$ratus = floor($last/100);
if ($ratus <= 0) {
$kata .= "";
} elseif ($ratus == 1) {
$kata .= " Seratus";
} else {
$kata .= " ".$this->numb[$ratus]." Ratus";
}
$last = $this->mod($last,100);
if ($last < 20 && $last > 10) {
if ($last == 11) {
$kata .= " Sebelas ". $suffix;
} else {
$kata .= " ".$this->numb[$last-10]." Belas ". $suffix;
}
return $kata;
}
$puluh = floor($last/10);
if ($puluh == 0) {
$kata .= "";
} elseif ($puluh == 1) {
$kata .= " Sepuluh";
} else {
$kata .= " ".$this->numb[$puluh]." Puluh";
}
$last = $this->mod($last,10);
if ($last>0 && $last<=9) {
$kata .= " ".$this->numb[$last];
}
if ($amount>0 && $amount<=1000) {
$kata .= " ".$suffix;
}
return $kata;
}
}
?>
+97
View File
@@ -0,0 +1,97 @@
<?php
/*******************************************************************
Module : /Web/Update.php
Desc. : Class Update Aplikasi Otomatis
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 14th, 2013.
Last Modified : March 3rd, 2026.
(c) 2013 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Update {
protected $__conf = [];
protected $is_git = false;
public function __construct(){
$this->__conf = $_SESSION['__WEB_APP'];
$this->get_current();
}
public function get_current() {
$_target = $this->__conf['REAL_PATH'];
if (isset($_target)) chdir($_target);
try {
$output = shell_exec("git log -1 --pretty=format:\"%H||%s||%ci\" --abbrev-commit 2>&1");
if ($output) {
$_ainfo = explode("||", $output);
$this->__conf['GIT_SHA1'] = $_ainfo[0];
$this->__conf['GIT_DATE'] = $_ainfo[2];
$this->is_git = true;
}
$output = shell_exec("git config --get remote.origin.url 2>&1");
if ($output) {
$output = str_replace(["http://","https://",".git"], "", $output);
$_ainfo = explode("/", trim($output));
$this->__conf['GIT_OWNER'] = $_ainfo[1];
$this->__conf['GIT_REPO'] = $_ainfo[2];
}
$output = shell_exec("git branch --show-current 2>&1");
if ($output) {
$this->__conf['GIT_BRANCH'] = $output;
}
} catch (Exception $e) {
}
}
public function check_update() {
$_ainfo['cur_version'] = $this->__conf['APP_BUILD'];
$_ainfo['cur_sha'] = substr($this->__conf['GIT_SHA1'], 0, 10);
$_ainfo['cur_sha1'] = $this->__conf['GIT_SHA1'];
$_ainfo['cur_date'] = $this->__conf['GIT_DATE'];
$_ainfo['svr_status'] = 0;
$_ainfo['svr_message'] = "Server Offline";
if (!$this->is_git) return $_ainfo;
try {
$_url = "https://git.trifonia.cloud/api/v1/repos/".$this->__conf['GIT_OWNER']."/".$this->__conf['GIT_REPO']."/commits?limit=1";
$_conten = file_get_contents($_url);
$ajson = json_decode($_conten, true);
if (count($ajson) > 0) {
$_ainfo['new_sha'] = substr($ajson[0]['sha'], 0, 10);
$_ainfo['new_sha1'] = $ajson[0]['sha'];
$_ainfo['new_date'] = date("Y-m-d H:i:s O", strtotime($ajson[0]['created']));
$_ainfo['new_message'] = $ajson[0]['commit']['message'];
$_ainfo['svr_status'] = 1;
$_ainfo['svr_message'] = "Server Online";
}
} catch (Exception $e) {
}
return $_ainfo;
}
public function go_update() {
$_target = $this->__conf['REAL_PATH'];
$_branch = $this->__conf['GIT_BRANCH'] ?? "main";
if (isset($_target)) {
chdir($_target);
$output = shell_exec("git reset --hard HEAD && git pull origin {$_branch} 2>&1");
return ['success'=>true,'message'=>$output];
} else return ['success'=>false,'message'=>"Tanpa REAL_PATH !"];
}
public function update_mysql() {
}
}
?>