2 Commits
26 changed files with 441 additions and 238 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
[![Software License][ico-license]](LICENSE.md) [![Software License][ico-license]](LICENSE.md)
[![Total Downloads][ico-downloads]][link-downloads] [![Total Downloads][ico-downloads]][link-downloads]
webapp adalah framework webbase aplikasi yang dibuat dengan basis kode PHP dan digabungkan dengan beberapa repo lain, sehingga menghasilkan webbase framework yang efisien dan efektif. Webapp adalah framework webbase aplikasi yang dibuat dengan basis kode PHP dan digabungkan dengan beberapa repo lain, sehingga menghasilkan webbase framework yang efisien dan efektif.
Maintenance versi repo tambahan, akan dilakukan secara periodik dengan mempertimbangkan kesiapan infrastruktur framework secara utuh. Maintenance versi repo tambahan, akan dilakukan secara periodik dengan mempertimbangkan kesiapan infrastruktur framework secara utuh.
+11
View File
@@ -493,3 +493,14 @@ input.double, input.integer, input.number {
background-color: #d8dbe0; background-color: #d8dbe0;
opacity: 1; opacity: 1;
} }
/** bashboard **/
.my-bashboard {
height: auto;
}
@media (min-width: 992px) {
.my-bashboard {
height: 500px;
}
}
+2 -3
View File
@@ -373,7 +373,7 @@ var FoniaJS = {
}); });
$('.option-tags').each((i, el) => { $('.option-tags').each((i, el) => {
const elm = $(el); const elm = $(el);
if (!jQuery.isFunction(jQuery.fn.select2)) return; if (typeof jQuery.fn.select2 !== 'function') return;
var _opts = {tags: false, dropdownAutoWidth: true, width: 'auto', theme: 'bootstrap-5', language: 'id'}; var _opts = {tags: false, dropdownAutoWidth: true, width: 'auto', theme: 'bootstrap-5', language: 'id'};
var _dmodal = elm.closest('div.modal'); var _dmodal = elm.closest('div.modal');
if (_dmodal.length) _opts.dropdownParent = _dmodal; if (_dmodal.length) _opts.dropdownParent = _dmodal;
@@ -798,7 +798,7 @@ class _Request_JSONF extends _Request {
strBody += '</tbody>'; strBody += '</tbody>';
$(divData).append(strTab + strHead + strBody + strFoot + '</table>'); $(divData).append(strTab + strHead + strBody + strFoot + '</table>');
var opsi = { responsive: true, columnDefs: [{responsivePriority:1,targets:0},{responsivePriority:2,targets:1}], lengthMenu: [], dom: '<"row"<"col-sm-12"tr>><"row"<"col-sm-12 col-lg-auto"<"toolbar">><"col-sm-3 col-lg-auto ms-lg-auto"l><"col-sm-9 col-lg-auto"p>>', autoWidth: false, processing: true, searching: false, columns: aSortCol, order: [[iCol, (ini.config.sort_dir=='A'?'asc':'desc')]], pageLength: ini.config.row_count, stateSave: true, stateSaveCallback: function(sett,data){localStorage.setItem(ini.id,JSON.stringify(data));}, stateLoadCallback: function(sett){try{var data=JSON.parse(localStorage.getItem(ini.id))??{};data.length=ini.config.row_count;return data;}catch(e){console.log(e)}} }; var opsi = { responsive: true, columnDefs: [{responsivePriority:1,targets:0},{responsivePriority:2,targets:1},{responsivePriority:0,targets:-1}], lengthMenu: [], dom: '<"row"<"col-sm-12"tr>><"row"<"col-sm-12 col-lg-auto"<"toolbar">><"col-sm-3 col-lg-auto ms-lg-auto"l><"col-sm-9 col-lg-auto"p>>', autoWidth: false, processing: true, searching: false, columns: aSortCol, order: [[iCol, (ini.config.sort_dir=='A'?'asc':'desc')]], pageLength: ini.config.row_count, stateSave: true, stateSaveCallback: function(sett,data){localStorage.setItem(ini.id,JSON.stringify(data));}, stateLoadCallback: function(sett){try{var data=JSON.parse(localStorage.getItem(ini.id))??{};data.length=ini.config.row_count;return data;}catch(e){console.log(e)}} };
/** start live db **/ /** start live db **/
if (ini.config.live){ if (ini.config.live){
var post_data = {}; var post_data = {};
@@ -1009,7 +1009,6 @@ class _Request_JSONF extends _Request {
tr.addClass('dt-hasChild parent'); tr.addClass('dt-hasChild parent');
} }
}); });
// disnini
} }
var otabel = $('#'+ini.id+'Tabel').DataTable(opsi); var otabel = $('#'+ini.id+'Tabel').DataTable(opsi);
} }
+2 -1
View File
@@ -27,8 +27,9 @@
"shuchkin/simplexlsxgen": "^1.3" "shuchkin/simplexlsxgen": "^1.3"
}, },
"autoload": { "autoload": {
"classmap": ["src/"],
"psr-4": { "psr-4": {
"siaupheng\\webapp\\": "src/" "Webapp\\": "src/"
}, },
"files": [ "files": [
"src/Function/Auth.php", "src/Function/Auth.php",
+17 -4
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /DB/CheckSQL.php Module : /DB/CheckSQL.php
Desc. : Class Check SQL / Repair Database
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : May 11th, 2011. Created Date : May 11th, 2011.
Last Modified : August 21st, 2026. Last Modified : August 21st, 2026.
@@ -14,20 +13,34 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\DB; namespace Webapp\DB;
use \Exception; use \Exception;
use \flight\Engine; use \flight\Engine;
use \flight\database\SimplePdo; use \flight\database\SimplePdo;
/**
* Class CheckSQL
*
* Check Database Mysql/MariaDB dan Repair.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\DB
*/
final class CheckSQL { final class CheckSQL {
private Array $__atabel = []; private Array $__atabel = [];
protected Engine $app; protected Engine $app;
protected SimplePdo $db; protected SimplePdo $db;
public function __construct(Engine $app, SimplePdo $db) { /**
* @param Engine $app
*/
public function __construct(Engine $app) {
$this->app = $app; $this->app = $app;
$this->db = $db; $this->db = $app->db();
$nama_db = $this->db->fetchField('SELECT DATABASE()'); $nama_db = $this->db->fetchField('SELECT DATABASE()');
$arow = $this->db->fetchAll("SELECT TABLE_NAME,ENGINE,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='".$nama_db."' AND TABLE_TYPE='BASE TABLE'"); $arow = $this->db->fetchAll("SELECT TABLE_NAME,ENGINE,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='".$nama_db."' AND TABLE_TYPE='BASE TABLE'");
foreach ($arow as $row) { foreach ($arow as $row) {
+6 -6
View File
@@ -15,7 +15,7 @@
//todo: deprecated //todo: deprecated
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\DB; namespace Webapp\DB;
final class DumpSQL { final class DumpSQL {
private $__adata = array(); private $__adata = array();
@@ -24,7 +24,7 @@ final class DumpSQL {
public function __construct($db = null){ public function __construct($db = null){
if (is_resource($db)) { $this->__db = $db; } if (is_resource($db)) { $this->__db = $db; }
else { $this->__db = new \siaupheng\webapp\DB\MySQL(); } else { $this->__db = new Webapp\DB\MySQL(); }
$this->__adata = $this->__db->getConfig(); $this->__adata = $this->__db->getConfig();
} }
@@ -56,7 +56,7 @@ final class DumpSQL {
public function create_backup($folder="backups") { public function create_backup($folder="backups") {
$namafile = date("Ymd").".gz"; $namafile = date("Ymd").".gz";
$folder = $_SESSION['__WEB_APP']['REAL_PATH'].$folder."/".date("Y"); $folder = PROJECT_ROOT.$folder."/".date("Y");
if (!is_dir($folder)) mkdir($folder); if (!is_dir($folder)) mkdir($folder);
if (file_exists($folder."/".$namafile)) unlink($folder."/".$namafile); 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']; $_cmd = "mysqldump -C --hex-blob -h ".$this->__adata['host']." -P ".$this->__adata['port']." -u ".$this->__adata['user']." -p".$this->__adata['pwd']." ".$this->__adata['db'];
@@ -97,8 +97,8 @@ final class DumpSQL {
} }
public function disk_space() { public function disk_space() {
$_free = disk_free_space($_SESSION['__WEB_APP']['REAL_PATH']); $_free = disk_free_space(PROJECT_ROOT);
$_tot = disk_total_space($_SESSION['__WEB_APP']['REAL_PATH']); $_tot = disk_total_space(PROJECT_ROOT);
$_used = $_tot - $_free; $_used = $_tot - $_free;
$_aret = array(); $_aret = array();
$_aret['TOTAL'] = $this->format_bytes($_tot); $_aret['TOTAL'] = $this->format_bytes($_tot);
@@ -110,7 +110,7 @@ final class DumpSQL {
} }
public function update_list($folder="backups") { public function update_list($folder="backups") {
$folder = $_SESSION['__WEB_APP']['REAL_PATH'].$folder; $folder = PROJECT_ROOT.$folder;
$this->__db->Query("TRUNCATE TABLE app_backup"); $this->__db->Query("TRUNCATE TABLE app_backup");
$afile = $this->get_file_list($folder); $afile = $this->get_file_list($folder);
foreach($afile as $_key => $_val) { foreach($afile as $_key => $_val) {
+19 -6
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /DB/SQL.php Module : /DB/SQL.php
Desc. : Class Query database
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : February 2nd, 2007. Created Date : February 2nd, 2007.
Last Modified : August 21st, 2026. Last Modified : August 21st, 2026.
@@ -14,12 +13,23 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\DB; namespace Webapp\DB;
use \flight\Engine; use \flight\Engine;
use \flight\Session; use \flight\Session;
use \flight\database\SimplePdo; use \flight\database\SimplePdo;
use siaupheng\webapp\Web\Param; use Webapp\Web\Param;
/**
* Class SQL
*
* Database CRUD dengan data dari GET/POST.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\DB
*/
final class SQL { final class SQL {
private string $_ttable; private string $_ttable;
@@ -29,10 +39,13 @@ final class SQL {
protected SimplePdo $db; protected SimplePdo $db;
protected array webuser; protected array webuser;
public function __construct(Engine $app, Ssssion $session, SimplePdo $db){ /**
* @param Engine $app
*/
public function __construct(Engine $app){
$this->app = $app; $this->app = $app;
$this->db = $db; $this->db = $app->db();
$this->webuser = $session->get('__WEB_USER', ['UserID'=>0, 'UNIX'=>0]); $this->webuser = $app->session()->get('__WEB_USER', ['UserID'=>0, 'UNIX'=>0]);
} }
//todo: deprecated //todo: deprecated
+12 -2
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Data/CSV.php Module : /Data/CSV.php
Desc. : Class pembuatan file CSV
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : April 2rd, 2011. Created Date : April 2rd, 2011.
Last Modified : August 21st, 2026. Last Modified : August 21st, 2026.
@@ -14,11 +13,22 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Data; namespace Webapp\Data;
define( DELI_CSV, ";" ); define( DELI_CSV, ";" );
define( CRLF_CSV, "\r\n" ); define( CRLF_CSV, "\r\n" );
/**
* Class CSV
*
* Membuat file CSV.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Data
*/
final class CSV { final class CSV {
private $__avalue = []; private $__avalue = [];
private $__atabel = []; private $__atabel = [];
+18 -4
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Data/Cache.php Module : /Data/Cache.php
Desc. : Class cache css dan js aplikasi
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : March 16th, 2008. Created Date : March 16th, 2008.
Last Modified : August 21st, 2026. Last Modified : August 21st, 2026.
@@ -14,7 +13,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Data; namespace Webapp\Data;
use \flight\Engine; use \flight\Engine;
use \flight\Session; use \flight\Session;
@@ -22,6 +21,17 @@ use \FilesystemIterator;
use \MatthiasMullie\Minify; use \MatthiasMullie\Minify;
use \SplFileInfo; use \SplFileInfo;
/**
* Class Cache
*
* Membuat Cache gabungan CSS dan JS sesuai dengan session.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Data
*/
final class Cache { final class Cache {
private $__cachedir = ""; private $__cachedir = "";
private $__cssdir = ""; private $__cssdir = "";
@@ -34,9 +44,13 @@ final class Cache {
protected Session $session; protected Session $session;
protected array $__asset = []; protected array $__asset = [];
public function __construct(Engine $app, Session $session) { /**
* @param Engine $app
*/
public function __construct(Engine $app) {
$this->app = $app; $this->app = $app;
$this->session = $session; $this->session = $app->session();
$rootdir = (defined('PROJECT_ROOT')) ? PROJECT_ROOT : $this->app->get('app.project_root'); $rootdir = (defined('PROJECT_ROOT')) ? PROJECT_ROOT : $this->app->get('app.project_root');
$this->__cachedir = $rootdir . '/public/chunks/'; $this->__cachedir = $rootdir . '/public/chunks/';
$this->__localedir = $rootdir . '/app/Scripts/locale/'; $this->__localedir = $rootdir . '/app/Scripts/locale/';
+20 -6
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Data/PDF.php Module : /Data/PDF.php
Desc. : Class pembuatan file PDF
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : April 18th, 2015. Created Date : April 18th, 2015.
Last Modified : August 21st, 2026. Last Modified : August 21st, 2026.
@@ -14,11 +13,22 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Data; namespace Webapp\Data;
use \flight\Session; use \flight\Engine;
use \Mpdf; use \Mpdf;
/**
* Class PDF
*
* Membuat file PDF.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Data
*/
final class PDF { final class PDF {
private $__avalue = []; private $__avalue = [];
private $__atabel = []; private $__atabel = [];
@@ -27,9 +37,13 @@ final class PDF {
protected array $webapp; protected array $webapp;
protected array $webuser; protected array $webuser;
public function __construct(Session $session) { /**
$this->webapp = $session->get('__WEB_APP', ['REG_NAME'=>'', 'APP_NAME'=>'', 'APP_VER'=>'']); * @param Engine $app
$this->webuser = $session->get('__WEB_USER', ['UserID'=>0, 'Username'=>'']); */
public function __construct(Engine $app) {
$this->webapp = $app->session()->get('__WEB_APP', ['REG_NAME'=>'', 'APP_NAME'=>'', 'APP_VER'=>'']);
$this->webuser = $app->session()->get('__WEB_USER', ['UserID'=>0, 'Username'=>'']);
} }
public function add_field(string $nama, string|int $lebar=0, string $align="L", string $func="", int $kol=1): void { public function add_field(string $nama, string|int $lebar=0, string $align="L", string $func="", int $kol=1): void {
+1 -1
View File
@@ -15,7 +15,7 @@
//todo: deprecated //todo: deprecated
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Data; namespace Webapp\Data;
final class SimpleXLS { final class SimpleXLS {
private $__wbook = null; private $__wbook = null;
+1 -1
View File
@@ -15,7 +15,7 @@
//todo: deprecated //todo: deprecated
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Data; namespace Webapp\Data;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
+5 -6
View File
@@ -18,14 +18,14 @@ use \flight\Session;
if (!function_exists('user_level')) { if (!function_exists('user_level')) {
function user_level(Session $session, int $level = 9): bool { function user_level(Session $session, int $level = 9): bool {
if ($session->get('__WEB_USER', ['Level'=>9]) <= $level) return true; if ($session->get('__WEB_USER', ['Level'=>9])['Level'] <= $level) return true;
return false; return false;
} }
} }
if (!function_exists('user_level_not')) { if (!function_exists('user_level_not')) {
function user_level_not(Session $session, int $level = 9): bool { function user_level_not(Session $session, int $level = 9): bool {
if ($session->get('__WEB_USER', ['Level'=>9]) !== $level) return true; if ($session->get('__WEB_USER', ['Level'=>9])['Level'] !== $level) return true;
return false; return false;
} }
} }
@@ -38,8 +38,9 @@ if (!function_exists('user_logged')) {
if (!function_exists('user_id')) { if (!function_exists('user_id')) {
function user_id(Session $session, int $digit = 0): string|int { function user_id(Session $session, int $digit = 0): string|int {
if ($digit > 0) return isi_nol($session->get('__WEB_USER', ['UserID'=>0])['UserID'], $digit); $id_user = (int)$session->get('__WEB_USER', ['UserID'=>0])['UserID'];
return (int)$session->get('__WEB_USER', ['UserID'=>0])['UserID']; if ($digit > 0) return isi_nol($id_user, $digit);
return $id_user;
} }
} }
@@ -60,5 +61,3 @@ if (!function_exists('user_nama')) {
return (string)$session->get('__WEB_USER', ['Nama'=>''])['Nama']; return (string)$session->get('__WEB_USER', ['Nama'=>''])['Nama'];
} }
} }
?>
+82 -81
View File
@@ -16,20 +16,20 @@ declare(strict_types=1);
/*************************** FORMAT ANGKA / CURRENCY *****************************/ /*************************** FORMAT ANGKA / CURRENCY *****************************/
if (!function_exists('rupiah')) {//oke if (!function_exists('rupiah')) {
function rupiah(string|float $angka = 0, int $desi = 0): string { function rupiah(mixed $angka = 0, int $desi = 0): string {
return number_format((float) $angka, $desi, ",", "."); return number_format((float) $angka, $desi, ",", ".");
} }
} }
if (!function_exists('rupiah2')) {//oke if (!function_exists('rupiah2')) {
function rupiah2($angka = 0): string { function rupiah2(mixed $angka = 0): string {
return rupiah($angka, 2); return rupiah($angka, 2);
} }
} }
//todo: deprecated /* todo: deprecated
/*if (!function_exists('rupiah30')) { if (!function_exists('rupiah30')) {
function rupiah30($angka = 0): string { function rupiah30($angka = 0): string {
$nilai = explode(".", $angka); $nilai = explode(".", $angka);
$hasil = (intval($nilai[1])==0) ? rupiah($angka, 0) : rupiah($angka, 3); $hasil = (intval($nilai[1])==0) ? rupiah($angka, 0) : rupiah($angka, 3);
@@ -38,76 +38,77 @@ if (!function_exists('rupiah2')) {//oke
}*/ }*/
if (!function_exists('kurung_rup')) { if (!function_exists('kurung_rup')) {
function kurung_rup($angka = 0, $desi = 0) { function kurung_rup(mixed $angka = 0, int $desi = 0): string {
$thasil = rupiah(abs($angka), $desi); $thasil = rupiah(abs((float) $angka), $desi);
if ($angka<0) return "(".$thasil.")"; if ((float) $angka < 0) return "(".$thasil.")";
return $thasil." "; return $thasil." ";
} }
} }
if (!function_exists('kurung')) { if (!function_exists('kurung')) {
function kurung($angka = 0, $desi = 0) { function kurung(mixed $angka = 0, int $desi = 0): string {
$thasil = uang(abs($angka), $desi); $thasil = uang(abs((float) $angka), $desi);
if ($angka<0) return "(".$thasil.")"; if ((float) $angka < 0) return "(".$thasil.")";
return $thasil." "; return $thasil." ";
} }
} }
if (!function_exists('kurung2')) { if (!function_exists('kurung2')) {
function kurung2($angka = 0) { function kurung2(mixed $angka = 0): string {
return kurung($angka, 2); return kurung($angka, 2);
} }
} }
if (!function_exists('uang')) {//oke if (!function_exists('uang')) {
function uang(string|float $angka = '0', int $desi = 0) { function uang(mixed $angka = 0, int $desi = 0): string {
$angka = str_replace(",", "", (string) $angka); $angka = str_replace(",", "", (string) $angka);
return number_format((float) $angka, $desi); return number_format((float) $angka, $desi);
} }
} }
if (!function_exists('uang2')) { if (!function_exists('uang2')) {
function uang2($angka = 0) { function uang2(mixed $angka = 0): string {
return uang($angka, 2); return uang($angka, 2);
} }
} }
/* todo: deprecated
if (!function_exists('koma30')) { if (!function_exists('koma30')) {
function koma30($angka = 0) { function koma30($angka = 0) {
$nilai = explode(".", $angka); $nilai = explode(".", $angka);
$hasil = (intval($nilai[1])==0) ? uang($angka, 0) : uang($angka, 3); $hasil = (intval($nilai[1])==0) ? uang($angka, 0) : uang($angka, 3);
return $hasil; return $hasil;
} }
} }*/
if (!function_exists('items')) { if (!function_exists('items')) {
function items($item = 0) { function items(mixed $item = 0): string {
return rupiah($item)." Items"; return rupiah($item)." Items";
} }
} }
if (!function_exists('records')) { if (!function_exists('records')) {
function records($item = 0) { function records(mixed $item = 0): string {
return rupiah($item)." Records"; return rupiah($item)." Records";
} }
} }
if (!function_exists('baris')) { if (!function_exists('baris')) {
function baris($item = 0) { function baris(mixed $item = 0): string {
return rupiah($item)." Baris"; return rupiah($item)." Baris";
} }
} }
if (!function_exists('npwp')) { if (!function_exists('npwp')) {
function npwp($nomor = "000000000000000") { function npwp(string $nomor = "000000000000000"): string {
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); 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')) { if (!function_exists('romawi')) {
function romawi($n) { function romawi(int $n): string {
$hasil = ""; $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"); $iromawi = ["","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)) { if (array_key_exists($n, $iromawi)) {
$hasil = $iromawi[$n]; $hasil = $iromawi[$n];
} else if ($n >= 11 && $n <= 99) { } else if ($n >= 11 && $n <= 99) {
@@ -125,7 +126,7 @@ if (!function_exists('romawi')) {
} }
if (!function_exists('abjad')) { if (!function_exists('abjad')) {
function abjad($n) { function abjad(int $n): string {
$_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return substr($_str, ($n-1), 1); return substr($_str, ($n-1), 1);
} }
@@ -134,8 +135,8 @@ if (!function_exists('abjad')) {
/*************************** FORM CONTROL *****************************/ /*************************** FORM CONTROL *****************************/
if (!function_exists('checkbox')) { if (!function_exists('checkbox')) {
function checkbox($nilai = 0) { function checkbox(mixed $nilai): string {
$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"; $thasil = (empty($nilai) or (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>'; return '<i class="fs-6 bi-'.$thasil.'"></i>';
} }
} }
@@ -143,32 +144,32 @@ if (!function_exists('checkbox')) {
/*************************** FORMAT TANGGAL / KALENDER *****************************/ /*************************** FORMAT TANGGAL / KALENDER *****************************/
if (!function_exists('sqltgl')) { if (!function_exists('sqltgl')) {
function sqltgl($waktu = "0") { function sqltgl(string $waktu): string {
return tgl_sql2str($waktu); return tgl_sql2str($waktu);
} }
} }
if (!function_exists('sqltgls')) { if (!function_exists('sqltgls')) {
function sqltgls($waktu = "0") { function sqltgls(string $waktu): string {
return tgl_sql2str($waktu, false, true); return tgl_sql2str($waktu, false, true);
} }
} }
if (!function_exists('sqljam')) { if (!function_exists('sqljam')) {
function sqljam($waktu = "0") { function sqljam(string $waktu): string {
return tgl_sql2str($waktu, true); return tgl_sql2str($waktu, true);
} }
} }
if (!function_exists('sqljams')) { if (!function_exists('sqljams')) {
function sqljams($waktu = "0") { function sqljams(string $waktu): string {
return tgl_sql2str($waktu, true, true); return tgl_sql2str($waktu, true, true);
} }
} }
if (!function_exists('tgl_sql2str')) { if (!function_exists('tgl_sql2str')) {
function tgl_sql2str($waktu = "0", $jam = false, $short = false) { function tgl_sql2str(string $waktu, bool $jam = false, bool $short = false): string {
if ($waktu=="0" || $waktu=="") return; if (empty($waktu)) return '';
$atgl = explode(" ", $waktu); $atgl = explode(" ", $waktu);
$sjam = ($jam) ? ((empty($atgl[1])) ? date("H:i:s") : $atgl[1]) : ""; $sjam = ($jam) ? ((empty($atgl[1])) ? date("H:i:s") : $atgl[1]) : "";
$atgl = explode("-", $atgl[0]); $atgl = explode("-", $atgl[0]);
@@ -179,66 +180,66 @@ if (!function_exists('tgl_sql2str')) {
} }
if (!function_exists('tgl_ymd')) { if (!function_exists('tgl_ymd')) {
function tgl_ymd($jam = false) { function tgl_ymd(bool $jam = false): string {
return (($jam) ? date("Y-m-d H:i:s") : date("Y-m-d")); return (($jam) ? date("Y-m-d H:i:s") : date("Y-m-d"));
} }
} }
if (!function_exists('tgl_dmy')) { if (!function_exists('tgl_dmy')) {
function tgl_dmy($jam = false) { function tgl_dmy(bool $jam = false): string {
return (($jam) ? date("d-m-Y H:i:s") : date("d-m-Y")); return (($jam) ? date("d-m-Y H:i:s") : date("d-m-Y"));
} }
} }
if (!function_exists('tgl_operasi')) { if (!function_exists('tgl_operasi')) {
function tgl_operasi($dtgl = "", $nhari = 0, $nbln = 0, $nthn = 0) { function tgl_operasi(string $tgl, int $hari = 0, int $bln = 0, int $thn = 0): string {
$atgl = explode("-", $dtgl); $atgl = explode("-", $tgl);
return date("d-m-Y", mktime(0,0,0, $atgl[1]+$nbln, $atgl[0]+$nhari, $atgl[2]+$nthn)); return date("d-m-Y", mktime(0,0,0, (int) $atgl[1]+$bln, (int) $atgl[0]+$hari, (int) $atgl[2]+$thn));
} }
} }
if (!function_exists('tgl_range_hari')) { if (!function_exists('tgl_range_hari')) {
function tgl_range_hari($dftgl="", $dttgl="", $bhitung_awal=false) { function tgl_range_hari(string $tgl_from, string $tgl_to, bool $hitung_awal = false): float {
$_start = strtotime(tgl_sql2str($dftgl)); if (empty($tgl_to) or empty($tgl_from)) return 0;
$_end = strtotime(tgl_sql2str($dttgl)); $_start = strtotime(tgl_sql2str($tgl_from));
return ceil(abs($_end - $_start) / 86400) + (($bhitung_awal==true)?1:0); $_end = strtotime(tgl_sql2str($tgl_to));
return ceil(abs($_end - $_start) / 86400) + (($hitung_awal)?1:0);
} }
} }
if (!function_exists('tgl_akhbln')) { if (!function_exists('tgl_akhbln')) {
function tgl_akhbln($tgl) { function tgl_akhbln(string $tgl): string {
if (empty($tgl)) return '';
$atgl = explode("-", $tgl); $atgl = explode("-", $tgl);
$ablna = array(31,28,31,30,31,30,31,31,30,31,30,31); $ablna = ['31','28','31','30','31','30','31','31','30','31','30','31'];
// jika tahun masehi dan bulan 2 // jika tahun masehi dan bulan 2
if ( (round($atgl[2]/4)==($atgl[2]/4)) && intval($atgl[1])==2 ) return "29-02-".$atgl[2]; if ((round((int) $atgl[2]/4) === ((int) $atgl[2]/4)) && (int) $atgl[1] === 2) return "29-02-".$atgl[2];
return $ablna[(intval($atgl[1])-1)]."-".isi_nol($atgl[1],2)."-".$atgl[2]; return $ablna[(int) $atgl[1]-1]."-".isi_nol($atgl[1],2)."-".$atgl[2];
} }
} }
if (!function_exists('tgl_panjang')) { if (!function_exists('tgl_panjang')) {
function tgl_panjang($dtgl = "") { function tgl_panjang(string $tgl): string {
if (trim($dtgl)=="") $dtgl = tgl_dmy(); if (empty($tgl)) $tgl = tgl_dmy();
$atgl = explode("-", $dtgl); $atgl = explode("-", $tgl);
$abulan = bulan_array(); $abulan = bulan_array();
return $atgl[0]." ".$abulan[intval($atgl[1])]." ".$atgl[2]; return $atgl[0]." ".$abulan[$atgl[1]]." ".$atgl[2];
} }
} }
if (!function_exists('tgl_hari')) { if (!function_exists('tgl_hari')) {
function tgl_hari($dtgl = "") { function tgl_hari(string $tgl): string {
$nhari = date("w"); $nhari = date("w");
if (trim($dtgl)!="") { if (!empty($tgl)) {
//$atgl = getdate($dtgl); $nhari = date("w", strtotime(tgl_sql2str($tgl)));
//$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"); $ahari = ["0"=>"Minggu","1"=>"Senin","2"=>"Selasa","3"=>"Rabu","4"=>"Kamis","5"=>"Jum'at","6"=>"Sabtu"];
return $ahari[$nhari]; return $ahari[$nhari];
} }
} }
if (!function_exists('tgl_triwulan')) { if (!function_exists('tgl_triwulan')) {
function tgl_triwulan($dtgl = "") { function tgl_triwulan(string $tgl): int {
if ($dtgl == "") { if (empty($tgl)) {
$dtgl = date("m"); $dtgl = date("m");
} else { } else {
$atgl = explode("-", $tgl); $atgl = explode("-", $tgl);
@@ -254,13 +255,13 @@ if (!function_exists('tgl_triwulan')) {
} }
if (!function_exists('bulan_array')) { if (!function_exists('bulan_array')) {
function bulan_array() { function bulan_array(): 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"); return ["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')) { if (!function_exists('triwulan_array')) {
function triwulan_array() { function triwulan_array(): array {
return ["1"=>"Triwulan 1","2"=>"Triwulan 2","3"=>"Triwulan 3","4"=>"Triwulan 4"]; return ["1"=>"Triwulan 1","2"=>"Triwulan 2","3"=>"Triwulan 3","4"=>"Triwulan 4"];
} }
} }
@@ -268,24 +269,25 @@ if (!function_exists('triwulan_array')) {
/*************************** FORMAT TAMPILAN & ERROR *****************************/ /*************************** FORMAT TAMPILAN & ERROR *****************************/
if (!function_exists('subjudul')) { if (!function_exists('subjudul')) {
function subjudul($tjudul) { function subjudul(string $judul): string {
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>'; 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;">'.$judul.'</span>&nbsp;&nbsp;</td><td width="50%"><hr /></td></tr></table>';
} }
} }
/* todo: deprecated
if (!function_exists('showerror')) { if (!function_exists('showerror')) {
function showerror($terror) { function showerror(string $error): void {
echo '<input type="hidden" id="_Error" class="error" value="'.$terror.'!" />'; echo '<input type="hidden" id="_Error" class="error" value="'.$error.'!" />';
}
} }
}*/
if (!function_exists('br2nl')) { if (!function_exists('br2nl')) {
function br2nl($string) { function br2nl(string $string): string {
return preg_replace('/\<br(\s*)?\/?\>/i', "\n\r", $string); return preg_replace('/\<br(\s*)?\/?\>/i', "\n\r", $string);
} }
} }
if (!function_exists('isi_nol')) {//oke if (!function_exists('isi_nol')) {
function isi_nol(string|int $nilai = 0, int $panjang = 1): string { function isi_nol(string|int $nilai = 0, int $panjang = 1): string {
$nilai = (string)$nilai; $nilai = (string)$nilai;
return ($panjang>strlen($nilai) ? str_repeat("0", $panjang-strlen($nilai)):'').$nilai; return ($panjang>strlen($nilai) ? str_repeat("0", $panjang-strlen($nilai)):'').$nilai;
@@ -293,7 +295,7 @@ if (!function_exists('isi_nol')) {//oke
} }
if (!function_exists('isMobile')) { if (!function_exists('isMobile')) {
function isMobile() { function isMobile(): bool {
$agen = $_SERVER['HTTP_USER_AGENT']; $agen = $_SERVER['HTTP_USER_AGENT'];
$amobile = ['Android', 'webOS', 'iPhone', 'iPad', 'iPod', 'BlackBerry', 'Windows Phone', 'Mobile']; $amobile = ['Android', 'webOS', 'iPhone', 'iPad', 'iPod', 'BlackBerry', 'Windows Phone', 'Mobile'];
foreach ($amobile as $keyword) { foreach ($amobile as $keyword) {
@@ -304,7 +306,7 @@ if (!function_exists('isMobile')) {
} }
if (!function_exists('isLinux')) { if (!function_exists('isLinux')) {
function isLinux() { function isLinux(): bool {
$agen = $_SERVER['HTTP_USER_AGENT']; $agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen, 'linux') !== false) return true; if (stripos($agen, 'linux') !== false) return true;
return false; return false;
@@ -312,7 +314,7 @@ if (!function_exists('isLinux')) {
} }
if (!function_exists('isIE')) { if (!function_exists('isIE')) {
function isIE() { function isIE(): bool {
$agen = $_SERVER['HTTP_USER_AGENT']; $agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen, 'msie') !== false) return true; if (stripos($agen, 'msie') !== false) return true;
return false; return false;
@@ -320,7 +322,7 @@ if (!function_exists('isIE')) {
} }
if (!function_exists('isChrome')) { if (!function_exists('isChrome')) {
function isChrome() { function isChrome(): bool {
$agen = $_SERVER['HTTP_USER_AGENT']; $agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen, 'chrome') !== false) return true; if (stripos($agen, 'chrome') !== false) return true;
return false; return false;
@@ -328,22 +330,23 @@ if (!function_exists('isChrome')) {
} }
if (!function_exists('isFirefox')) { if (!function_exists('isFirefox')) {
function isFirefox() { function isFirefox(): bool {
$agen = $_SERVER['HTTP_USER_AGENT']; $agen = $_SERVER['HTTP_USER_AGENT'];
if (stripos($agen, 'firefox') !== false) return true; if (stripos($agen, 'firefox') !== false) return true;
return false; return false;
} }
} }
/* todo: deprecated
if (!function_exists('potong')) { if (!function_exists('potong')) {
function potong($nilai) {//utk rkpd function potong($nilai) {//utk rkpd
return substr($nilai, 0, 60); return substr($nilai, 0, 60);
} }
} }*/
if (!function_exists('format_bytes')) { if (!function_exists('format_bytes')) {
function format_bytes($bytes) { function format_bytes(int $bytes): string {
if ($bytes < 1024) return $bytes.' B'; if ($bytes < 1024) return (string) $bytes.' B';
elseif ($bytes < 1048576) return uang2($bytes / 1024).' KB'; elseif ($bytes < 1048576) return uang2($bytes / 1024).' KB';
elseif ($bytes < 1073741824) return uang2($bytes / 1048576).' MB'; elseif ($bytes < 1073741824) return uang2($bytes / 1048576).' MB';
elseif ($bytes < 1099511627776) return uang2($bytes / 1073741824).' GB'; elseif ($bytes < 1099511627776) return uang2($bytes / 1073741824).' GB';
@@ -352,12 +355,10 @@ if (!function_exists('format_bytes')) {
} }
if (!function_exists('random_color')) { if (!function_exists('random_color')) {
function random_color($trans = "0.6") { function random_color(string $trans = "0.6"): string {
$col_r = mt_rand( 0, 255 ); $col_r = (string) mt_rand( 0, 255 );
$col_g = mt_rand( 0, 255 ); $col_g = (string) mt_rand( 0, 255 );
$col_b = mt_rand( 0, 255 ); $col_b = (string) mt_rand( 0, 255 );
return "rgba(".$col_r.",".$col_g.",".$col_b.",".$trans.")"; return "rgba(".$col_r.",".$col_g.",".$col_b.",".$trans.")";
} }
} }
?>
+21 -8
View File
@@ -3,10 +3,9 @@
/******************************************************************* /*******************************************************************
Module : /Printer/PrintHTML.php Module : /Printer/PrintHTML.php
Desc. : Class cetak HTML
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 15th, 2008. Created Date : June 15th, 2008.
Last Modified : August 21st, 2026. Last Modified : August 26th, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM. (c) 3FONIA Software; WWW.3FONIA.COM.
@@ -14,9 +13,20 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Printer; namespace Webapp\Printer;
use \flight\Session; use \flight\Engine;
/**
* Class PrintHTML
*
* Menghasilkan bentuk laporan dalam format HTML.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Printer
*/
final class PrintHTML { final class PrintHTML {
private $__avalue = []; private $__avalue = [];
@@ -26,9 +36,12 @@ final class PrintHTML {
protected array $webapp; protected array $webapp;
protected array $webuser; protected array $webuser;
public function __construct(Session $session) { /**
$this->webapp = $session->get('__WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'']); * @param Engine $app
$this->webuser = $session->get('__WEB_USER', ['UserID'=>0, 'Username'=>'']); */
public function __construct(Engine $app) {
$this->webapp = $app->session()->get('__WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'']);
$this->webuser = $app->session()->get('__WEB_USER', ['UserID'=>0, 'Username'=>'']);
} }
public function set_css(string $style): void { public function set_css(string $style): void {
@@ -54,7 +67,7 @@ final class PrintHTML {
} else if (function_exists($this->__atabel[$i][2]) && trim("".$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 = 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_val = $this->set_align((string) $tmp_val, $this->__atabel[$i][1], $this->__atabel[$i][3]);
$tmp_out .= $tmp_val; $tmp_out .= $tmp_val;
} }
$tmp_out .= "</tr>"; $tmp_out .= "</tr>";
+20 -8
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Printer/PrintPOS.php Module : /Printer/PrintPOS.php
Desc. : Class cetak POS
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 15th, 2008. Created Date : June 15th, 2008.
Last Modified : August 21st, 2026. Last Modified : August 21st, 2026.
@@ -14,10 +13,20 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Printer; namespace Webapp\Printer;
use \flight\Engine; use \flight\Engine;
use \flight\Session;
/**
* Class PrintPOS
*
* Pembuatan Nota/Struk untuk cetak ke Printer POS.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Printer
*/
class PrintPOS { class PrintPOS {
private $_header = []; private $_header = [];
@@ -35,10 +44,13 @@ class PrintPOS {
private array $webuser; private array $webuser;
protected Engine $app; protected Engine $app;
public function __construct(Engine $app, Session $session) { /**
* @param Engine $app
*/
public function __construct(Engine $app) {
$this->app = $app; $this->app = $app;
$this->webapp = $session->get('__WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'', 'REAL_PATH'=>'']); $this->webapp = $app->session()->get('__WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'']);
$this->webuser = $session->get('__WEB_USER', ['UserID'=>0, 'Username'=>'']); $this->webuser = $app->session()->get('__WEB_USER', ['UserID'=>0, 'Username'=>'']);
} }
public function set_opendrawer(): void { public function set_opendrawer(): void {
@@ -58,8 +70,8 @@ class PrintPOS {
} }
public function set_header_logo(string $logo_file = ""): void { public function set_header_logo(string $logo_file = ""): void {
if (!empty($logo_file) && file_exists($this->webapp['REAL_PATH']."assets/images/".$logo_file)) { if (!empty($logo_file) && file_exists(PROJECT_ROOT."assets/images/".$logo_file)) {
$this->_config['logo'] = $this->webapp['WEB_PATH']."assets/images/".$logo_file; $this->_config['logo'] = PROJECT_BASE."assets/images/".$logo_file;
} }
} }
+20 -8
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Printer/PrintRAW.php Module : /Printer/PrintRAW.php
Desc. : Class cetak RAW
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 15th, 2008. Created Date : June 15th, 2008.
Last Modified : November 1st, 2023. Last Modified : November 1st, 2023.
@@ -14,10 +13,20 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Printer; namespace Webapp\Printer;
use \flight\Engine; use \flight\Engine;
use \flight\Session;
/**
* Class PrintRAW
*
* Pembuatan Laporan dalam bentuk RAW / Natural.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Printer
*/
class PrintRAW { class PrintRAW {
private $_header = []; private $_header = [];
@@ -32,14 +41,17 @@ class PrintRAW {
'opendraw' => false, 'opendraw' => false,
'cutpaper' => false, 'cutpaper' => false,
]; ];
private array $webapp;
private array $webuser;
protected Engine $app; protected Engine $app;
protected array $webapp;
protected array $webuser;
public function __construct(Engine $app, Session $session) { /**
* @param Engine $app
*/
public function __construct(Engine $app) {
$this->app = $app; $this->app = $app;
$this->webapp = $session->get('__WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'', 'REAL_PATH'=>'']); $this->webapp = $app->session()->get('__WEB_APP', ['APP_NAME'=>'', 'APP_VER'=>'']);
$this->webuser = $session->get('__WEB_USER', ['UserID'=>0, 'Username'=>'']); $this->webuser = $app->session()->get('__WEB_USER', ['UserID'=>0, 'Username'=>'']);
} }
public function set_opendrawer(): void { public function set_opendrawer(): void {
+18 -5
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Web/Auth.php Module : /Web/Auth.php
Desc. : Class User Control dan Manajemen
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : March 16th, 2008. Created Date : March 16th, 2008.
Last Modified : August 22nd, 2026. Last Modified : August 22nd, 2026.
@@ -14,22 +13,36 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
use \flight\Engine; use \flight\Engine;
use \flight\Session; use \flight\Session;
use \flight\database\SimplePdo; use \flight\database\SimplePdo;
/**
* Class Auth
*
* Kontrol dan Manajemen User Session.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
final class Auth { final class Auth {
private int $__id_reg = 0; private int $__id_reg = 0;
protected Engine $app; protected Engine $app;
protected SimplePdo $db; protected SimplePdo $db;
protected Session $session; protected Session $session;
public function __construct(Engine $app, SimplePdo $db, Session $session){ /**
* @param Engine $app
*/
public function __construct(Engine $app){
$this->app = $app; $this->app = $app;
$this->db = $db; $this->db = $app->db();
$this->session = $session; $this->session = $app->session();
$this->__id_reg = (int)$this->session->get('__WEB_APP', ['REG_ID'=>0])['REG_ID']; $this->__id_reg = (int)$this->session->get('__WEB_APP', ['REG_ID'=>0])['REG_ID'];
} }
+12 -2
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Web/Button.php Module : /Web/Button.php
Desc. : Button Generator (jQuery & Bootstrap)
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : February 27th, 2008. Created Date : February 27th, 2008.
Last Modified : August 22nd, 2026. Last Modified : August 22nd, 2026.
@@ -14,7 +13,18 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
/**
* Class Button
*
* Pembuatan tombol aplikasi (jQuery & Bootstrap).
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
class Button { class Button {
private $__abutton =[]; private $__abutton =[];
+29 -16
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Web/Form.php Module : /Web/Form.php
Desc. : Form Generator (jQuery & Bootstrap)
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : February 27th, 2008. Created Date : February 27th, 2008.
Last Modified : August 22nd, 2026. Last Modified : August 22nd, 2026.
@@ -14,12 +13,23 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
use \flight\Engine; use \flight\Engine;
use \flight\Session; use \flight\Session;
use \flight\database\SimplePdo; use \flight\database\SimplePdo;
/**
* Class Form
*
* Pembuatan form (jQuery & Bootstrap).
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
final class Form { final class Form {
private $__aform = []; private $__aform = [];
private $__ahide = []; private $__ahide = [];
@@ -27,13 +37,16 @@ final class Form {
protected SimplePdo $db; protected SimplePdo $db;
protected Session $session; protected Session $session;
public function __construct(Engine $app, SimplePdo $db, Session $session){ /**
* @param Engine $app
*/
public function __construct(Engine $app){
$this->app = $app; $this->app = $app;
$this->db = $db; $this->db = $app->db();
$this->session = $session; $this->session = $app->session();
} }
public function option(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null, bool $multi=false, bool $group=false): string { public function option(string $label, string $field, mixed $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null, bool $multi=false, bool $group=false): string {
$_opsi = ''; $_opsi = '';
if (!empty($change)) $_opsi .= ' ochan="'.$change.'"'; if (!empty($change)) $_opsi .= ' ochan="'.$change.'"';
if ($enable===false) $_opsi .= ' disabled=true'; if ($enable===false) $_opsi .= ' disabled=true';
@@ -69,7 +82,7 @@ final class Form {
return $tout; return $tout;
} }
public function option_db(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, ?string $table=null, ?array $afield=null, ?string $where=null, ?array $aarray=null, ?string $help=null, ?string $change=null, bool $multi=false): string { public function option_db(string $label, string $field, mixed $value=null, bool $enable=true, bool $req=false, ?string $table=null, ?array $afield=null, ?string $where=null, ?array $aarray=null, ?string $help=null, ?string $change=null, bool $multi=false): string {
$_twhere = ''; $_twhere = '';
if (!is_array($afield)) $afield = ["ID", "Nama", "Label"]; if (!is_array($afield)) $afield = ["ID", "Nama", "Label"];
if (!empty($where)) { if (!empty($where)) {
@@ -87,7 +100,7 @@ final class Form {
return $this->option($label, $field, $value, $enable, $req, $ahasil, $help, $change, $multi); return $this->option($label, $field, $value, $enable, $req, $ahasil, $help, $change, $multi);
} }
public function option_que(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, ?string $query=null, ?array $afield=null, ?array $aarray=null, ?string $help=null, ?string $change=null): string { public function option_que(string $label, string $field, mixed $value=null, bool $enable=true, bool $req=false, ?string $query=null, ?array $afield=null, ?array $aarray=null, ?string $help=null, ?string $change=null): string {
if (!is_array($afield)) $afield = ["ID", "Nama", "Label"]; if (!is_array($afield)) $afield = ["ID", "Nama", "Label"];
$ahasil = []; $ahasil = [];
if (is_array($aarray)) $ahasil[$aarray[0]] = (!isset($afield[2])) ? $aarray[1] : [$aarray[1], $aarray[2]]; if (is_array($aarray)) $ahasil[$aarray[0]] = (!isset($afield[2])) ? $aarray[1] : [$aarray[1], $aarray[2]];
@@ -100,7 +113,7 @@ final class Form {
return $this->option($label, $field, $value, $enable, $req, $ahasil, $help, $change); return $this->option($label, $field, $value, $enable, $req, $ahasil, $help, $change);
} }
public function option_jkl(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string { public function option_jkl(string $label, string $field, mixed $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {
return $this->option($label, $field, $value, $enable, $req, ["L" => "Laki-Laki", "P" => "Perempuan"], $help, $change); return $this->option($label, $field, $value, $enable, $req, ["L" => "Laki-Laki", "P" => "Perempuan"], $help, $change);
} }
@@ -108,7 +121,7 @@ final class Form {
return $this->option($label, $field, $value, $enable, $req, $this->session->get('__WEB_APP')['USER_LEVEL'], $help, $change); return $this->option($label, $field, $value, $enable, $req, $this->session->get('__WEB_APP')['USER_LEVEL'], $help, $change);
} }
public function radio(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string { public function radio(string $label, string $field, mixed $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string {
$_val = array_values($arr); $_val = array_values($arr);
if (empty($value)) $value = $_val[0]; if (empty($value)) $value = $_val[0];
$_opsi = ''; $_opsi = '';
@@ -136,7 +149,7 @@ final class Form {
return $this->radio($label, $field, $value, $enable, $req, ["A"=>"A", "B"=>"B", "AB"=>"AB", "O"=>"O", "X"=>"NONE"], $help, $change); return $this->radio($label, $field, $value, $enable, $req, ["A"=>"A", "B"=>"B", "AB"=>"AB", "O"=>"O", "X"=>"NONE"], $help, $change);
} }
public function checkbox(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string { public function checkbox(string $label, string $field, mixed $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string {
$_val = array_values($arr); $_val = array_values($arr);
if (empty($value)) $value = $_val[1]; if (empty($value)) $value = $_val[1];
$_opsi = ' odata="'.htmlspecialchars(json_encode($arr)).'"'; $_opsi = ' odata="'.htmlspecialchars(json_encode($arr)).'"';
@@ -150,7 +163,7 @@ final class Form {
return $tout; return $tout;
} }
public function switch(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string { public function switch(string $label, string $field, mixed $value=null, bool $enable=true, bool $req=false, array $arr=[], ?string $help=null, ?string $change=null): string {
$_val = array_values($arr); $_val = array_values($arr);
if (empty($value)) $value = $_val[1]; if (empty($value)) $value = $_val[1];
$_opsi = ' odata="'.htmlspecialchars(json_encode($arr)).'"'; $_opsi = ' odata="'.htmlspecialchars(json_encode($arr)).'"';
@@ -164,7 +177,7 @@ final class Form {
return $tout; return $tout;
} }
public function textbox(string $label, string $field, string|int|null $value=null, bool $enable=true, bool $req=false, string $type="text", ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null, ?string $keyup=null, ?string $blur=null): string { public function textbox(string $label, string $field, mixed $value=null, bool $enable=true, bool $req=false, string $type="text", ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {
$_opsi = ''; $_opsi = '';
if (!empty($keyup)) $_opsi .= ' okyup="'.$keyup.'"'; if (!empty($keyup)) $_opsi .= ' okyup="'.$keyup.'"';
if (!empty($blur)) $_opsi .= ' oblur="'.$blur.'"'; if (!empty($blur)) $_opsi .= ' oblur="'.$blur.'"';
@@ -178,7 +191,7 @@ final class Form {
if ($type === 'double') $value = uang2($value); if ($type === 'double') $value = uang2($value);
$type = "text"; $type = "text";
} }
$tout = '<input type="'.$type.'" class="form-control'.$_tclass.'" id="'.$field.'" name="'.$field.'" value="'.$value.'"'.$_opsi.' />'; $tout = '<input type="'.$type.'" class="form-control'.$_tclass.'" id="'.$field.'" name="'.$field.'" value="'.(string)$value.'"'.$_opsi.' />';
$this->__aform[$field] = [ 'label' => $label, 'help' => $help, 'form' => $tout ]; $this->__aform[$field] = [ 'label' => $label, 'help' => $help, 'form' => $tout ];
return $tout; return $tout;
} }
@@ -219,7 +232,7 @@ final class Form {
return $tout; return $tout;
} }
public function plaintext(string $label, string $field, string|int|null $value=null): string { public function plaintext(string $label, string $field, mixed $value=null): string {
$tout = '<input type="text" class="form-control-plaintext" id="'.$field.'" name="'.$field.'" value="'.$value.'" readonly />'; $tout = '<input type="text" class="form-control-plaintext" id="'.$field.'" name="'.$field.'" value="'.$value.'" readonly />';
$this->__aform[$field] = ['label' => $label, 'help' => "", 'form' => $tout]; $this->__aform[$field] = ['label' => $label, 'help' => "", 'form' => $tout];
return $tout; return $tout;
@@ -239,7 +252,7 @@ final class Form {
return $tout; return $tout;
} }
public function hidden(string $field, string|int|null $value=null, string $class="text"): string { public function hidden(string $field, mixed $value=null, string $class="text"): string {
$tout = '<input type="hidden" id="'.$field.'" value="'.$value.'" class="'.$class.'" />'; $tout = '<input type="hidden" id="'.$field.'" value="'.$value.'" class="'.$class.'" />';
$this->__ahide[$field] = $tout; $this->__ahide[$field] = $tout;
return $tout; return $tout;
+20 -7
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Web/Menu.php Module : /Web/Menu.php
Desc. : Class Menu Manajemen
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : January 16th, 2008. Created Date : January 16th, 2008.
Last Modified : August 22nd, 2026. Last Modified : August 22nd, 2026.
@@ -14,12 +13,23 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
use \flight\Engine; use \flight\Engine;
use \flight\Session; use \flight\Session;
use \flight\database\SimplePdo; use \flight\database\SimplePdo;
/**
* Class Menu
*
* Manajemen Menu aplikasi.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
final class Menu { final class Menu {
private array $webapp; private array $webapp;
private array $webuser; private array $webuser;
@@ -27,12 +37,15 @@ final class Menu {
protected SimplePdo $db; protected SimplePdo $db;
protected Session $session; protected Session $session;
public function __construct(Engine $app, SimplePdo $db, Session $session){ /**
* @param Engine $app
*/
public function __construct(Engine $app){
$this->app = $app; $this->app = $app;
$this->db = $db; $this->db = $app->db();
$this->session = $session; $this->session = $app->session();
$this->webapp = $session->get('__WEB_APP', ['APP_MODULE'=>'', 'PARENT_SITE'=>'', 'PARENT_SUB'=>false]); $this->webapp = $this->session->get('__WEB_APP', ['APP_MODULE'=>'', 'PARENT_SITE'=>'', 'PARENT_SUB'=>false]);
$this->webuser = $session->get('__WEB_USER', ['Menu'=>'', 'Menu_Grup'=>'', 'MENU_MODUL'=>[]]); $this->webuser = $this->session->get('__WEB_USER', ['Menu'=>'', 'Menu_Grup'=>'', 'MENU_MODUL'=>[]]);
} }
public function Sidebar(): string { public function Sidebar(): string {
+13 -3
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Web/Param.php Module : /Web/Param.php
Desc. : Class Parameter Manajemen
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : November 14th, 2013. Created Date : November 14th, 2013.
Last Modified : August 22nd, 2026. Last Modified : August 22nd, 2026.
@@ -14,10 +13,21 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
use \flight\Engine; use \flight\Engine;
/**
* Class Param
*
* Manajemen Variable Request dari GET / POST.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
final class Param { final class Param {
private static $__ahasil = []; private static $__ahasil = [];
@@ -30,7 +40,7 @@ final class Param {
if (empty($app)) $app = \Flight::app(); if (empty($app)) $app = \Flight::app();
$_asumber = array_merge($app->request()->query->getData(), $app->request()->data->getData()); $_asumber = array_merge($app->request()->query->getData(), $app->request()->data->getData());
foreach ($_asumber as $__key => $__val) { foreach ($_asumber as $__key => $__val) {
self::$__ahasil[$__key] = self::safeSQL($__val); self::$__ahasil[$__key] = is_string($__val) ? self::safeSQL($__val) : $__val;
} }
} }
+24 -24
View File
@@ -3,53 +3,53 @@
/******************************************************************* /*******************************************************************
Module : /Web/Register.php Module : /Web/Register.php
Desc. : Class Registrasi Aplikasi
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : November 23th, 2011. Created Date : November 23th, 2011.
Last Modified : August 11th, 2026. Last Modified : August 22nd, 2026.
(c) 2011 - 2026, 3FONIA Software; WWW.3FONIA.COM. (c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/ *******************************************************************/
//OK
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
use flight\Engine; use \flight\Engine;
use flight\Session; use \flight\Session;
use flight\database\SimplePdo; use \flight\database\SimplePdo;
/**
* Class Register
*
* Registrasi aplikasi.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
final class Register { final class Register {
protected Engine $app; public function __construct(){
protected SimplePdo $db;
protected Session $session;
public function __construct(Engine $app, SimplePdo $db, Session $session){
$this->app = $app;
$this->db = $db;
$this->session = $session;
} }
public static function reg_id() { public static function reg_id(Session $session) {
$webapp = (array)\Flight::app()->session()->get('__WEB_APP'); $id = (string)$session->get('__WEB_APP', ['REG_ID'=>''])['REG_ID'];
$id = (string)$webapp['REG_ID'] ?? '';
return (substr($id,0,3).".".substr($id,3,3).".".substr($id,6)); return (substr($id,0,3).".".substr($id,3,3).".".substr($id,6));
} }
public static function reg_code() { public static function reg_code(Session $session) {
$webapp = (array)\Flight::app()->session()->get('__WEB_APP'); $id = (string)$session->get('__WEB_APP', ['REG_CODE'=>''])['REG_CODE'];
$id = (string)$webapp['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)); 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));
} }
static function reg_check(Session $session) {//oke public static function reg_check(Session $session) {
$webapp = $session->get('__WEB_APP'); $webapp = $session->get('__WEB_APP');
return (bool)(isset($webapp['REG_STATUS']) && $webapp['REG_STATUS']) ?? false; return (bool)(isset($webapp['REG_STATUS']) && $webapp['REG_STATUS']) ?? false;
} }
static function reg_status(SimplePdo $db, array $apps) {//oke public static function reg_status(SimplePdo $db, array $apps) {
$kode_db = (bool)$db->fetchField('SELECT UPPER(CONVERT(MD5(CONCAT(REG_YEAR,CONVERT(MD5(CONCAT(REG_ID,REG_NAME)) using latin1),REG_ID,REG_NAME)) using latin1))=REG_CODE FROM app_config WHERE REG_ID=?', [$apps['APP_CODE'] ?? '']); $kode_db = (bool)$db->fetchField('SELECT UPPER(CONVERT(MD5(CONCAT(REG_YEAR,CONVERT(MD5(CONCAT(REG_ID,REG_NAME)) using latin1),REG_ID,REG_NAME)) using latin1))=REG_CODE FROM app_config WHERE REG_ID=?', [$apps['APP_CODE'] ?? '']);
return [ 'REG_STATUS' => $kode_db === true ]; return [ 'REG_STATUS' => $kode_db === true ];
} }
+18 -5
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Web/Table.php Module : /Web/Table.php
Desc. : Datatable (jQuery & Bootstrap)
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : January 16th, 2008. Created Date : January 16th, 2008.
Last Modified : August 22nd, 2026. Last Modified : August 22nd, 2026.
@@ -14,11 +13,22 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
use \flight\Engine; use \flight\Engine;
use \flight\database\SimplePdo; use \flight\database\SimplePdo;
/**
* Class Table
*
* Pembuatan DataTable (jQuery & Bootstrap).
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
final class Table { final class Table {
private $__ttable = ""; private $__ttable = "";
private $__tfield = ""; private $__tfield = "";
@@ -45,9 +55,12 @@ final class Table {
protected SimplePdo $db; protected SimplePdo $db;
protected array $data; protected array $data;
public function __construct(Engine $app, SimplePdo $db) { /**
* @param Engine $app
*/
public function __construct(Engine $app) {
$this->app = $app; $this->app = $app;
$this->db = $db; $this->db = $app->db();
$this->data = $this->app->request()->data->getData(); $this->data = $this->app->request()->data->getData();
} }
@@ -81,7 +94,7 @@ final class Table {
} }
public function set_row_color(string $field = "", string $val = "", string $css = ""): void { public function set_row_color(string $field = "", string $val = "", string $css = ""): void {
if (epmty($field)) return; if (empty($field)) return;
$this->__arowcol[] = [ 'F' => $field, 'V' => $val, 'C' => $css ]; $this->__arowcol[] = [ 'F' => $field, 'V' => $val, 'C' => $css ];
} }
+12 -2
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Web/Terbilang.php Module : /Web/Terbilang.php
Desc. : Class Format Angka & Terbilang
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : February 12th, 2009. Created Date : February 12th, 2009.
Last Modified : August 22nd, 2026. Last Modified : August 22nd, 2026.
@@ -14,7 +13,18 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
/**
* Class Terbilang
*
* Pembuatan text terbilang.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
final class Terbilang { final class Terbilang {
private $numb = ["","Satu","Dua","Tiga","Empat","Lima","Enam","Tujuh","Delapan","Sembilan"]; private $numb = ["","Satu","Dua","Tiga","Empat","Lima","Enam","Tujuh","Delapan","Sembilan"];
+26 -17
View File
@@ -3,7 +3,6 @@
/******************************************************************* /*******************************************************************
Module : /Web/Update.php Module : /Web/Update.php
Desc. : Class Update Aplikasi Otomatis
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 14th, 2013. Created Date : June 14th, 2013.
Last Modified : August 22nd, 2026. Last Modified : August 22nd, 2026.
@@ -14,26 +13,37 @@
declare(strict_types=1); declare(strict_types=1);
namespace siaupheng\webapp\Web; namespace Webapp\Web;
use \flight\Engine; use \flight\Engine;
use \flight\Session;
/**
* Class Update
*
* Update Otomatis Aplikasi berbasis GIT.
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
*
* @package Webapp\Web
*/
final class Update { final class Update {
protected Array $__conf = []; private Array $__conf = [];
protected Bool $is_git = false; private Bool $is_git = false;
protected Engine $app; protected Engine $app;
public function __construct(Engine $app, Session $session){ /**
* @param Engine $app
*/
public function __construct(Engine $app){
$this->app = $app; $this->app = $app;
$this->__conf = $session->get('__WEB_APP'); $this->__conf = $app->session()->get('__WEB_APP');
$this->current(); $this->current();
} }
public function current() { public function current(): void {
$_target = $this->__conf['REAL_PATH']; if (defined('PROJECT_ROOT')) chdir(PROJECT_ROOT);
if (isset($_target)) chdir($_target);
try { try {
$output = shell_exec("git log -1 --pretty=format:\"%H||%s||%ci\" --abbrev-commit 2>&1"); $output = shell_exec("git log -1 --pretty=format:\"%H||%s||%ci\" --abbrev-commit 2>&1");
if ($output) { if ($output) {
@@ -57,7 +67,7 @@ final class Update {
} }
} }
public function check() { public function check(): array {
$_ainfo['cur_version'] = $this->__conf['APP_BUILD']; $_ainfo['cur_version'] = $this->__conf['APP_BUILD'];
$_ainfo['cur_sha'] = substr($this->__conf['GIT_SHA1'], 0, 10); $_ainfo['cur_sha'] = substr($this->__conf['GIT_SHA1'], 0, 10);
$_ainfo['cur_sha1'] = $this->__conf['GIT_SHA1']; $_ainfo['cur_sha1'] = $this->__conf['GIT_SHA1'];
@@ -89,14 +99,13 @@ final class Update {
return $_ainfo; return $_ainfo;
} }
public function go() { public function go(): array {
$_target = $this->__conf['REAL_PATH'];
$_branch = $this->__conf['GIT_BRANCH'] ?? "main"; $_branch = $this->__conf['GIT_BRANCH'] ?? "main";
if (isset($_target)) { if (defined('PROJECT_ROOT')) {
chdir($_target); chdir(PROJECT_ROOT);
$output = shell_exec("git reset --hard HEAD && git pull origin {$_branch} 2>&1"); $output = shell_exec("git reset --hard HEAD && git pull origin {$_branch} 2>&1");
return ['success'=>true,'message'=>$output]; return ['success'=>true,'message'=>$output];
} else return ['success'=>false,'message'=>"Tanpa REAL_PATH !"]; } else return ['success'=>false,'message'=>"Tanpa PROJECT_ROOT !"];
} }
public function mysql() { public function mysql() {