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
+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;
}
}