upgrade all with dice compatible

This commit is contained in:
2026-08-22 12:53:04 +07:00
parent 27ebdca49b
commit e7bb9a6c90
34 changed files with 546 additions and 486 deletions
+34 -34
View File
@@ -3,23 +3,22 @@
/*******************************************************************
Module : /Web/Auth.php
Desc. : Class login dan user checking
Desc. : Class User Control dan Manajemen
Created By : Siau Pheng ([email protected]).
Created Date : March 16th, 2008.
Last Modified : April 3rd, 2022.
Last Modified : August 22nd, 2026.
(c) 2008 - 2022, 3FONIA Software; WWW.3FONIA.COM.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\Web;
use flight\Engine;
use flight\Session;
use flight\database\SimplePdo;
use \flight\Engine;
use \flight\Session;
use \flight\database\SimplePdo;
final class Auth {
private int $__id_reg = 0;
@@ -27,23 +26,23 @@ final class Auth {
protected SimplePdo $db;
protected Session $session;
public function __construct(?Engine $app = null){
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->db = $this->app->db();
$this->session = $this->app->session();
public function __construct(Engine $app, SimplePdo $db, Session $session){
$this->app = $app;
$this->db = $db;
$this->session = $session;
$this->__id_reg = (int)$this->session->get('__WEB_APP', ['REG_ID'=>0])['REG_ID'];
}
public function set_id_reg($id = 0) {
public function set_id_reg(int|string $id = 0): void {
if ($id > 0) $this->__id_reg = (int)$id;
}
public function user_check($user, $pass) {
$i_hasil = $this->db->fetchField('SELECT COUNT(*) FROM app_operator WHERE Username=? AND Password=MD5(?) AND Aktif=1', [$user, $pass]);
public function user_check(string $user, string $pass): bool {
$i_hasil = (int)$this->db->fetchField('SELECT COUNT(*) FROM app_operator WHERE Username=? AND Password=MD5(?) AND Aktif=1', [$user, $pass]);
return ($i_hasil > 0 ? true : false);
}
public function user_data($user) {
public function user_data(string $user): array {
$adata = $this->db->fetchRow('SELECT *,DECODE(Menu,?) Menu2 FROM app_operator WHERE Username=?', [$this->__id_reg, $user])->getData();
$adata['Menu'] = $adata['Menu2'];
unset($adata['Menu2']);
@@ -53,13 +52,14 @@ final class Auth {
$this->session->set('APP_TOKEN', $_token);
$this->db->insert('app_token', [ 'Token' => $_token, 'UserID' => $adata['UserID'], 'IP' => $this->app->request()->ip ]);
}
if ((int)$adata['Grup_MenuID'] > 0) $adata['Menu_Grup'] = $this->user_allmenu($adata['Grup_MenuID']);
if ((int)$adata['Grup_MenuID'] > 0) $adata['Menu_Grup'] = $this->user_allmenu((int)$adata['Grup_MenuID']);
$adata['UNIX'] = time();
$adata['LOCALE'] = $this->session->get('__WEB_APP', ['DEF_LOCALE'=>'id'])['DEF_LOCALE'];
$adata['MENU_MODUL'] = [];
return $adata;
}
public function gen_module_menu() {
public function gen_module_menu(): void {
$amodul = []; $aallow = []; $tallow = '';
if ($this->session->get('__WEB_APP', ['APP_MODULE'=>0])['APP_MODULE']) {
$tallow = $this->db->fetchField('SELECT Modul_Akses FROM app_menu_grup WHERE Grup_MenuID=?', [$this->session->get('__WEB_USER', ['Grup_MenuID'=>0])['Grup_MenuID']]);
@@ -78,55 +78,55 @@ final class Auth {
$this->session->set('__WEB_USER', $auser);
}
public function user_allmenu(int $id_grup = 0) {
public function user_allmenu(int $id_grup = 0): string {
$allmenu = $this->db->fetchField('SELECT DECODE(Menu,?) MenuX FROM app_menu_grup WHERE Grup_MenuID=?', [$this->__id_reg, $id_grup]);
return $allmenu;
}
public function user_check_level($user, $level = 9) {
$i_hasil = $this->db->fetchField('SELECT COUNT(*) FROM app_operator WHERE Username=? AND Level<=? AND Aktif=1', [$user, $level]);
public function user_check_level(string $user, int $level = 9): bool {
$i_hasil = (int)$this->db->fetchField('SELECT COUNT(*) FROM app_operator WHERE Username=? AND Level<=? AND Aktif=1', [$user, $level]);
return ($i_hasil > 0 ? true : false);
}
public function user_log() {
$a_hasil = $this->db->fetchRow('SELECT * FROM app_logs WHERE UserID=? ORDER BY Last_Date DESC LIMIT 1', [user_id()])->getData();
public function user_log(): void {
$_user_id = $this->session->get('__WEB_USER')['UserID'] ?? 0;
if ($_user_id === 0) return;
$a_hasil = $this->db->fetchRow('SELECT * FROM app_logs WHERE UserID=? ORDER BY Last_Date DESC LIMIT 1', [$_user_id])->getData();
if (count($a_hasil) > 0) {
$this->db->update('app_operator', [ 'Last_IP' => $a_hasil['Last_IP'], 'Last_Date' => $a_hasil['Last_Date'] ], 'UserID=?', [user_id()]);
$this->db->update('app_operator', [ 'Last_IP' => $a_hasil['Last_IP'], 'Last_Date' => $a_hasil['Last_Date'] ], 'UserID=?', [$_user_id]);
}
$this->db->runQuery('INSERT IGNORE INTO app_logs SELECT UserID,Token,IP,DateStamp FROM app_token WHERE Token=?', [$this->session->get('APP_TOKEN')]);
}
public function logout() {
public function logout(): void {
$this->db->delete('app_token', 'Token=?', [$this->session->get('APP_TOKEN')]);
}
public function token_check(string $token) {
public function token_check(string $token): bool {
$hasil = (bool)$this->db->fetchField('SELECT 1 FROM app_token WHERE Token=?', [$token ?? $this->session->get('APP_TOKEN')]);
if ($hasil === true) $this->db->update('app_token', ['DateStamp' => 'NOW()'], 'Token=?', [$token ?? $this->session->get('APP_TOKEN')]);
return $hasil;
}
public function token_update() {
$this->db->update('app_token', ['DateStamp' => 'NOW()'], 'Token=?', [$app->session->get('APP_TOKEN')]);
public function token_update(): void {
$this->db->update('app_token', ['DateStamp' => 'NOW()'], 'Token=?', [$this->session->get('APP_TOKEN')]);
}
public function redirect(string $appUrl) {
public function redirect(string $appUrl): string {
$source = parse_url($appUrl);
$desti = "";
$hasil = (bool)$this->db->fetchField('SELECT 1 FROM app_host WHERE Nama_Host=?', [$source['host']]);
if ($hasil === true) {
$desti = $source['scheme'].$source['host'].$source['path'].'?'.'auth='.$app->session->get('APP_TOKEN');
}
if ($hasil) $desti = $source['scheme'].$source['host'].$source['path'].'?'.'auth='.$this->session->get('APP_TOKEN');
return $desti;
}
private function genToken(int $length = 16) {
private function genToken(int $length = 16): string {
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle(str_repeat($pool, 5)), 0, $length);
}
public function getUserByToken(string $token) {
$hasil = $this->db->fetchField('SELECT Username FROM app_operator WHERE UserID IN (SELECT UserID FROM app_token WHERE Token=?) LIMIT 1', [$token ??$app->session->get('APP_TOKEN')]);
public function getUserByToken(string $token): string {
$hasil = $this->db->fetchField('SELECT Username FROM app_operator WHERE UserID IN (SELECT UserID FROM app_token WHERE Token=?) LIMIT 1', [$token ?? $this->session->get('APP_TOKEN')]);
return $hasil;
}
}
+24 -23
View File
@@ -6,9 +6,9 @@
Desc. : Button Generator (jQuery & Bootstrap)
Created By : Siau Pheng ([email protected]).
Created Date : February 27th, 2008.
Last Modified : January 22nd, 2024.
Last Modified : August 22nd, 2026.
(c) 2008 - 2024, 3FONIA Software; WWW.3FONIA.COM.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
@@ -20,41 +20,42 @@ 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];
private function add(string $type="info", string $id="", string $label="", bool $miss=false): void {
if (empty($id)) $id = "random".(string)rand(1000, 10000);
$this->__abutton[] = [ 'type' => $type, 'id' => $id, 'label' => $label, 'miss' => $miss ];
}
public function separator() {
$this->__abutton[] = ['type'=>"separator"];
public function separator(): void {
$this->__abutton[] = [ 'type' => "separator" ];
}
public function primary($id="", $label="", $bmiss=false) {
$this->add("primary", $id, $label, $bmiss);
public function primary(string $id="", string $label="", bool $miss=false): void {
$this->add("primary", $id, $label, $miss);
}
public function info($id="", $label="", $bmiss=false) {
$this->add("info", $id, $label, $bmiss);
public function info(string $id="", string $label="", bool $miss=false): void {
$this->add("info", $id, $label, $miss);
}
public function danger($id="", $label="", $bmiss=false) {
$this->add("danger", $id, $label, $bmiss);
public function danger(string $id="", string $label="", bool $miss=false): void {
$this->add("danger", $id, $label, $miss);
}
public function warning($id="", $label="", $bmiss=false) {
$this->add("warning", $id, $label, $bmiss);
public function warning(string $id="", string $label="", bool $miss=false): void {
$this->add("warning", $id, $label, $miss);
}
public function success($id="", $label="", $bmiss=false) {
$this->add("success", $id, $label, $bmiss);
public function success(string $id="", string $label="", bool $miss=false): void {
$this->add("success", $id, $label, $miss);
}
public function secondary($id="", $label="", $bmiss=false) {
$this->add("secondary", $id, $label, $bmiss);
public function secondary(string $id="", string $label="", bool $miss=false): void {
$this->add("secondary", $id, $label, $miss);
}
public function Button($size=2) {
if (0==count($this->__abutton)) return "";
public function Button(int $size=2): string {
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']) {
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 .= '<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['miss']?' data-bs-dismiss="modal"':'').'>'.$item['label'].'</button>';
}
}
$_out .= '</div></div>';
+33 -35
View File
@@ -6,20 +6,19 @@
Desc. : Form Generator (jQuery & Bootstrap)
Created By : Siau Pheng ([email protected]).
Created Date : February 27th, 2008.
Last Modified : August 19th, 2026.
Last Modified : August 22nd, 2026.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\Web;
use flight\Engine;
use flight\Session;
use flight\database\SimplePdo;
use \flight\Engine;
use \flight\Session;
use \flight\database\SimplePdo;
final class Form {
private $__aform = [];
@@ -28,13 +27,13 @@ final class Form {
protected SimplePdo $db;
protected Session $session;
public function __construct(?Engine $app = null){
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->db = $this->app->db();
$this->session = $this->app->session();
public function __construct(Engine $app, SimplePdo $db, Session $session){
$this->app = $app;
$this->db = $db;
$this->session = $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 {//oke
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 {
$_opsi = '';
if (!empty($change)) $_opsi .= ' ochan="'.$change.'"';
if ($enable===false) $_opsi .= ' disabled=true';
@@ -70,12 +69,12 @@ final class Form {
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 {//oke
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 {
$_twhere = '';
if (!is_array($afield)) $afield = ["ID", "Nama", "Label"];
if (!empty($where)) {
$_twhere = ' WHERE '.$where;
$_twhere .= (stripos($twhere,"ORDER BY")===false) ? ' ORDER BY '.$afield[1] : '';
$_twhere .= (stripos($where,"ORDER BY")===false) ? ' ORDER BY '.$afield[1] : '';
}
$ahasil = [];
if (is_array($aarray)) $ahasil[$aarray[0]] = (!isset($afield[2])) ? $aarray[1] : [$aarray[1], $aarray[2]];
@@ -88,7 +87,7 @@ final class Form {
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 {//oke
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 {
if (!is_array($afield)) $afield = ["ID", "Nama", "Label"];
$ahasil = [];
if (is_array($aarray)) $ahasil[$aarray[0]] = (!isset($afield[2])) ? $aarray[1] : [$aarray[1], $aarray[2]];
@@ -101,15 +100,15 @@ final class Form {
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 {//oke
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 {
return $this->option($label, $field, $value, $enable, $req, ["L" => "Laki-Laki", "P" => "Perempuan"], $help, $change);
}
public function option_ulevel(string $label, string $field, int $value=9, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
public function option_ulevel(string $label, string $field, int $value=9, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {
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 {//oke
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 {
$_val = array_values($arr);
if (empty($value)) $value = $_val[0];
$_opsi = '';
@@ -128,16 +127,16 @@ final class Form {
return $tout;
}
public function radio_jkl(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
public function radio_jkl(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {
return $this->radio($label, $field, $value, $enable, $req, ["L" => "Laki-Laki", "P" => "Perempuan"], $help, $change);
}
public function radio_gd(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
public function radio_gd(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {
if (!empty($value)) $value = 'X';
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 {//oke
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 {
$_val = array_values($arr);
if (empty($value)) $value = $_val[1];
$_opsi = ' odata="'.htmlspecialchars(json_encode($arr)).'"';
@@ -151,7 +150,7 @@ final class Form {
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 {//oke
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 {
$_val = array_values($arr);
if (empty($value)) $value = $_val[1];
$_opsi = ' odata="'.htmlspecialchars(json_encode($arr)).'"';
@@ -165,7 +164,7 @@ final class Form {
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 {//oke
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 {
$_opsi = '';
if (!empty($keyup)) $_opsi .= ' okyup="'.$keyup.'"';
if (!empty($blur)) $_opsi .= ' oblur="'.$blur.'"';
@@ -184,7 +183,7 @@ final class Form {
return $tout;
}
public function textauto(string $label, string $field, array $avalue=['value'=>0,'text'=>""], bool $enable=true, bool $req=false, ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null): string {//oke
public function textauto(string $label, string $field, array $avalue=['value'=>0,'text'=>""], bool $enable=true, bool $req=false, ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null): string {
$_opsi = '';
if (!empty($holdtxt)) $_opsi .= ' placeholder="'.$holdtxt.'"';
if (!empty($maxsize)) $_opsi .= ' maxlength="'.$maxsize.'"';
@@ -195,7 +194,7 @@ final class Form {
return $tout;
}
public function datebox(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {//oke
public function datebox(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {
if (!empty($value)) $value = tgl_sql2str($value);
$tout = '<div class="input-group date">';
$tout .= $this->textbox($label, $field, $value, $enable, $req, "pickdate", "dd-mm-yyyy", null, $help, $keyup, $blur);
@@ -204,11 +203,11 @@ final class Form {
return $tout;
}
public function timebox(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {//oke
public function timebox(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {
return $this->textbox($label, $field, $value, $enable, $req, "picktime", "hh:mm:ss", 10, $help, $keyup, $blur);
}
public function textarea(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, int $rows=1, ?string $holdtxt=null, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {//oke
public function textarea(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, int $rows=1, ?string $holdtxt=null, ?string $help=null, ?string $keyup=null, ?string $blur=null): string {
$_opsi = '';
if (!empty($keyup)) $_opsi .= ' okyup="'.$keyup.'"';
if (!empty($blur)) $_opsi .= ' oblur="'.$blur.'"';
@@ -220,17 +219,17 @@ final class Form {
return $tout;
}
public function plaintext(string $label, string $field, string|int|null $value=null): string {//oke
public function plaintext(string $label, string $field, string|int|null $value=null): string {
$tout = '<input type="text" class="form-control-plaintext" id="'.$field.'" name="'.$field.'" value="'.$value.'" readonly />';
$this->__aform[$field] = ['label' => $label, 'help' => "", 'form' => $tout];
return $tout;
}
public function password(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null, ?string $keyup=null): string {//oke
public function password(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $holdtxt=null, ?int $maxsize=null, ?string $help=null, ?string $keyup=null): string {
return $this->textbox($label, $field, $value, $enable, $req, "password", $holdtxt, $maxsize, $help, $keyup, null);
}
public function color(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {//oke
public function color(string $label, string $field, ?string $value=null, bool $enable=true, bool $req=false, ?string $help=null, ?string $change=null): string {
$_opsi = '';
if (!empty($change)) $_opsi .= ' ochan="'.$change.'"';
if ($enable===false) $_opsi .= ' disabled=true';
@@ -240,20 +239,19 @@ final class Form {
return $tout;
}
public function hidden(string $field, string|int|null $value=null, string $class="text"): string {//oke
public function hidden(string $field, string|int|null $value=null, string $class="text"): string {
$tout = '<input type="hidden" id="'.$field.'" value="'.$value.'" class="'.$class.'" />';
$this->__ahide[$field] = $tout;
return $tout;
}
public function clear() {
public function clear(): void {
$this->__aform = [];
}
public function show($tstr) {
if ($tstr === 0) $tstr = 4;//default
$col_left = 'col-sm-' . ($tstr+2) . ' col-lg-' . $tstr;
$col_right = 'col-sm-' . (10-$tstr) . ' col-lg-' . (12-$tstr);
public function show(int $lebar_kolom = 4): string {
$col_left = 'col-sm-' . ($lebar_kolom+2) . ' col-lg-' . $lebar_kolom;
$col_right = 'col-sm-' . (10-$lebar_kolom) . ' col-lg-' . (12-$lebar_kolom);
$tres = '';
foreach ($this->__aform as $_key => $_val) {
$tres .= sprintf('<div class="row mb-1"><label class="%s col-form-label" for="%s">%s</label><div class="%s">%s %s</div></div>', $col_left, $_key, $_val['label'], $col_right, $_val['form'], (empty($_val['help'])?'':'<span class="help-block"><small>'.$_val['help'].'</small></span>'));
+54 -25
View File
@@ -3,40 +3,43 @@
/*******************************************************************
Module : /Web/Menu.php
Desc. : Class menu
Desc. : Class Menu Manajemen
Created By : Siau Pheng ([email protected]).
Created Date : January 16th, 2008.
Last Modified : December 26th, 2025.
Last Modified : August 22nd, 2026.
(c) 2008 - 2025, 3FONIA Software; WWW.3FONIA.COM.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\Web;
use flight\Engine;
use flight\Session;
use flight\database\SimplePdo;
use \flight\Engine;
use \flight\Session;
use \flight\database\SimplePdo;
final class Menu {
private array $webapp;
private array $webuser;
protected Engine $app;
protected SimplePdo $db;
protected Session $session;
public function __construct(?Engine $app = null){
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->db = $this->app->db();
$this->session = $this->app->session();
public function __construct(Engine $app, SimplePdo $db, Session $session){
$this->app = $app;
$this->db = $db;
$this->session = $session;
$this->webapp = $session->get('__WEB_APP', ['APP_MODULE'=>'', 'PARENT_SITE'=>'', 'PARENT_SUB'=>false]);
$this->webuser = $session->get('__WEB_USER', ['Menu'=>'', 'Menu_Grup'=>'', 'MENU_MODUL'=>[]]);
}
public function Menu_Sidebar() {
public function Sidebar(): string {
$a_modul = [];
$is_modul = ($this->session->get('__WEB_APP', ['APP_MODULE'=>''])['APP_MODULE'] <> '') ? true : false;
$is_modul = ($this->webapp['APP_MODULE'] !== '') ? true : false;
if ($is_modul == true) {
$a_modul[] = $this->session->get('__WEB_APP')['APP_MODULE'];
$a_modul[] = $this->webapp['APP_MODULE'];
} else {
$atmp = $this->db->fetchAll('SELECT * FROM app_menu WHERE Level=0 AND Aktif=1 AND Modul<>"IND" ORDER BY Urut');
foreach ($atmp as $tmp) {
@@ -44,7 +47,7 @@ final class Menu {
}
}
$my_menu = array_unique(array_filter(explode(",", $this->session->get('__WEB_USER', ['Menu_Grup'=>''])['Menu_Grup'].",".$this->session->get('__WEB_USER', ['Menu'=>''])['Menu'])));
$my_menu = array_unique(array_filter(explode(",", $this->webuser['Menu_Grup'].",".$this->webuser['Menu'])));
$tsql = 'SELECT * FROM app_menu WHERE Aktif=1 AND Modul IN (?) AND Kode IN (?)';
if ($is_modul == true) $tsql .= ' AND Level>0';
@@ -70,12 +73,12 @@ final class Menu {
return $thasil;
}
public function Menu_Header() {
public function Header(): string {
$a_modul = [];
$is_modul = ($this->session->get('__WEB_APP', ['APP_MODULE'=>''])['APP_MODULE'] <> '') ? true : false;
$is_modul = ($this->webapp['APP_MODULE'] !== '') ? true : false;
$mulai_level = 0;
if ($is_modul == true) {
$a_modul[] = $this->session->get('__WEB_APP')['APP_MODULE'];
$a_modul[] = $this->webapp['APP_MODULE'];
$mulai_level = 1;
} else {
$atmp = $this->db->fetchAll('SELECT * FROM app_menu WHERE Level=0 AND Aktif=1 AND Modul<>"IND" ORDER BY Urut');
@@ -84,7 +87,7 @@ final class Menu {
}
}
$my_menu = array_unique(array_filter(explode(",", $this->session->get('__WEB_USER', ['Menu_Grup'=>''])['Menu_Grup'].",".$this->session->get('__WEB_USER', ['Menu'=>''])['Menu'])));
$my_menu = array_unique(array_filter(explode(",", $this->webuser['Menu_Grup'].",".$this->webuser['Menu'])));
$tsql = 'SELECT * FROM app_menu WHERE Aktif=1 AND Modul IN (?) AND Kode IN (?)';
if ($is_modul == true) $tsql .= ' AND Level>0';
@@ -116,9 +119,35 @@ final class Menu {
return $thasil;
}
static function MenuJSON($db = null, $page = "", $tquery = "") {
$_mdb = (empty($db) === true) ? new SimplePdo() : $db;
$_query = ($tquery=="") ? "" : ",'".$tquery."'";
public function Modul(): string {
$t_modul = '';
if (is_array($this->webuser['MENU_MODUL']) && count($this->webuser['MENU_MODUL'])>0) {
$t_modul = '<div class="dropdown-divider"></div>';
if ($this->app->request()->getVar('SERVER_ADDR') === '127.0.0.1') {
$href1 = '//127.0.0.1/';
$href2 = "";
} else {
$_host = $this->app->request()->getVar('HTTP_ORIGIN') ?? $this->app->request()->getVar('HTTP_HOST') ?? $this->webapp['PARENT_SITE'];
$_host = str_replace(['http://','https://'], "", $_host);
if ($this->webapp['PARENT_SUB'] === true) {
$_subs = explode('.', $_host);
if (count($_subs) > 2) array_shift($_subs);
$href1 = "//";
$href2 = "." . implode('.', $_subs);
} else {
$href1 = "//" . $_host . '/';
$href2 = "";
}
}
foreach ($this->webuser['MENU_MODUL'] as $modul) {
$href = $href1 . $modul['APP_PATH'] . $href2 . '/' . $this->session->get('APP_TOKEN');
$t_modul .= '<a class="dropdown-item slink" href="'.$href.'"><i class="'.$modul['Icon'].' me-2"></i> '.$modul['Judul'].'</a>';
}
}
return $t_modul;
}
static function MenuJSON(SimplePdo $db, string $page = "", string $q = ""): array {
$ajson = ['login' => true];
$apage = ['Link' => ""];
@@ -130,18 +159,18 @@ final class Menu {
if ($acus_page[$page] ?? false) {
$apage = $acus_page[$page];
} else if ($page <> "") {
$apage = $_mdb->fetchRow('SELECT * FROM app_menu WHERE Kode=?', [$page]);
$apage = $db->fetchRow('SELECT * FROM app_menu WHERE Kode=?', [$page]);
$apage['Width'] = (int)$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['button'] = json_validate($apage['Button']) ? json_decode($apage['Button']) : $apage['Button'];
$ajson['php'] = $apage['Link'];
$ajson['func'] = $apage['JS'];
$ajson['kode'] = $apage['Kode'];
return $ajson;
}
}
+12 -13
View File
@@ -3,16 +3,15 @@
/*******************************************************************
Module : /Web/Param.php
Desc. : Class data parameter dari client side
Desc. : Class Parameter Manajemen
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : November 14th, 2013.
Last Modified : August 8th, 2026.
Last Modified : August 22nd, 2026.
(c) 2013 - 2026, 3FONIA Software; WWW.3FONIA.COM.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\Web;
@@ -26,7 +25,7 @@ final class Param {
if (count(self::$__ahasil)==0) self::__data();
}
private static function __data() {
private static function __data(): void {
global $app;
if (empty($app)) $app = \Flight::app();
$_asumber = array_merge($app->request()->query->getData(), $app->request()->data->getData());
@@ -35,28 +34,28 @@ final class Param {
}
}
public static function safeSQL($tstr = "") {
public static function safeSQL(string $str = ""): string {
$_se = array("\\","\0","\n","\r","\x1a","'",'"');
$_re = array("\\\\","\\0","\\n","\\r","\Z","\'",'\"');
return str_replace($_se, $_re, $tstr);
return str_replace($_se, $_re, $str);
}
public static function Get($tkey = "", $tdef = null) {
public static function Get(string $key = "", mixed $def = null): mixed {
if (count(self::$__ahasil)==0) self::__data();
if (isset(self::$__ahasil[$tkey]) && self::$__ahasil[$tkey]) return self::$__ahasil[$tkey];
return $tdef;
if (isset(self::$__ahasil[$key]) && self::$__ahasil[$key]) return self::$__ahasil[$key];
return $def;
}
public static function Get_Text($tkey = "", $tdef = null) {
public static function Get_Text(string $key, mixed $def = null): mixed {
if (count(self::$__ahasil)==0) self::__data();
$_str = (isset(self::$__ahasil[$tkey])) ? self::$__ahasil[$tkey] : $tdef;
$_str = (isset(self::$__ahasil[$key])) ? self::$__ahasil[$key] : $def;
$_str = str_replace("\\r", "", $_str);
$_str = str_replace("\\n", " ", $_str);
$_str = str_replace("\\t", " ", $_str);
return (trim($_str));
}
public static function Get_Array() {
public static function Get_Array(): array {
if (count(self::$__ahasil)==0) self::__data();
return self::$__ahasil;
}
+10 -7
View File
@@ -18,15 +18,18 @@ declare(strict_types=1);
namespace siaupheng\webapp\Web;
use flight\Engine;
use flight\Session;
use flight\database\SimplePdo;
final class Register {
protected Engine $app;
protected SimplePdo $db;
protected Session $session;
public function __construct(?Engine $app = null){
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->db = $this->app->db();
public function __construct(Engine $app, SimplePdo $db, Session $session){
$this->app = $app;
$this->db = $db;
$this->session = $session;
}
public static function reg_id() {
@@ -41,13 +44,13 @@ final class Register {
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 static function reg_check() {
$webapp = (array)\Flight::app()->session()->get('__WEB_APP');
static function reg_check(Session $session) {//oke
$webapp = $session->get('__WEB_APP');
return (bool)(isset($webapp['REG_STATUS']) && $webapp['REG_STATUS']) ?? false;
}
public function reg_status(array $apps) {
$kode_db = (bool)$this->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'] ?? '']);
static function reg_status(SimplePdo $db, array $apps) {//oke
$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 ];
}
}
+8 -9
View File
@@ -3,22 +3,21 @@
/*******************************************************************
Module : /Web/Table.php
Desc. : HTML Table (jQuery & Bootstrap)
Desc. : Datatable (jQuery & Bootstrap)
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : January 16th, 2008.
Last Modified : August 16th, 2026.
Last Modified : August 22nd, 2026.
(c) 2008 - 2026, 3FONIA Software; WWW.3FONIA.COM.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\Web;
use flight\Engine;
use flight\database\SimplePdo;
use \flight\Engine;
use \flight\database\SimplePdo;
final class Table {
private $__ttable = "";
@@ -46,9 +45,9 @@ final class Table {
protected SimplePdo $db;
protected array $data;
public function __construct(?Engine $app = null) {
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->db = $this->app->db();
public function __construct(Engine $app, SimplePdo $db) {
$this->app = $app;
$this->db = $db;
$this->data = $this->app->request()->data->getData();
}
+10 -10
View File
@@ -6,9 +6,9 @@
Desc. : Class Format Angka & Terbilang
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : February 12th, 2009.
Last Modified : May 6th, 2021.
Last Modified : August 22nd, 2026.
(c) 2009 - 2021, 3FONIA Software; WWW.3FONIA.COM.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
@@ -17,14 +17,14 @@ declare(strict_types=1);
namespace siaupheng\webapp\Web;
final class Terbilang {
private $numb = array("","Satu","Dua","Tiga","Empat","Lima","Enam","Tujuh","Delapan","Sembilan");
private $numb = ["","Satu","Dua","Tiga","Empat","Lima","Enam","Tujuh","Delapan","Sembilan"];
public function __construct() {}
public function Terbilang($nilai=0, $muang="Rupiah") {
public function Terbilang(float $nilai=0, string $muang="Rupiah"): string {
$number = 0;
$hasil = "";
$int = trim($nilai);
$int = (string)$nilai;
if (is_int(strpos($int,"-"))) {
$number = substr($int,strpos($int,"-")+1,strlen($int));
$hasil = "Minus";
@@ -36,11 +36,11 @@ final class Terbilang {
$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);
$pecahan = round((float)substr($number,$xpos,strlen($number)),2);
$last = substr($number,0,$xpos);
} else {
$pecahan = "";
$last = $number;
$last = (float)$number;
}
if ($last==0 || $number==0) {
return $hasil."NOL ".$muang;
@@ -71,12 +71,12 @@ final class Terbilang {
return $hasil . $kata;
}
private function mod($a, $b) {
private function mod(float $a, float $b): float {
return $a-$b*floor($a/$b);
}
private function tigadigit($amount, $suffix="") {
$last = (int) $amount;
private function tigadigit(float $amount, string $suffix=""): string {
$last = (int)$amount;
$kata = "";
if ($last == 1 && $suffix=="Ribu") {
$kata = " Seribu";
+7 -7
View File
@@ -6,27 +6,27 @@
Desc. : Class Update Aplikasi Otomatis
Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 14th, 2013.
Last Modified : August 12th, 2026.
Last Modified : August 22nd, 2026.
(c) 2013 - 2026, 3FONIA Software; WWW.3FONIA.COM.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\Web;
use flight\Engine;
use \flight\Engine;
use \flight\Session;
final class Update {
protected Array $__conf = [];
protected Bool $is_git = false;
protected Engine $app;
public function __construct(?Engine $app = null){
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->__conf = $app->session()->get('__WEB_APP');
public function __construct(Engine $app, Session $session){
$this->app = $app;
$this->__conf = $session->get('__WEB_APP');
$this->current();
}