upgrade first session to flightphp

This commit is contained in:
2026-08-19 17:22:07 +07:00
parent 36395c2b55
commit 27ebdca49b
31 changed files with 1383 additions and 7659 deletions
+42 -47
View File
@@ -12,45 +12,43 @@
*******************************************************************/
//OK
declare(strict_types=1);
namespace siaupheng\webapp\Web;
use flight\Engine;
use flight\Session;
use flight\database\SimplePdo;
final class Menu {
protected $__db = null;
protected Engine $app;
protected SimplePdo $db;
protected Session $session;
public function __construct($db = null){
$this->__db = $db ?? new \siaupheng\webapp\DB\MySQL();
public function __construct(?Engine $app = null){
$this->app = (empty($app) === true) ? \Flight::app() : $app;
$this->db = $this->app->db();
$this->session = $this->app->session();
}
private function Menu_Query($qry = "", $order = "Kode") {
$twhere = ($qry!="") ? "WHERE ".$qry : "";
$this->__db->Query("SELECT * FROM app_menu ".$twhere." ORDER BY ".$order." ASC");
$ahasil = array();
while ($this->__db->Next()) {
$ahasil[] = $this->__db->AllRow();
}
return $ahasil;
}
public function Menu_Sidebar() {//oke
$a_modul = array();
$is_modul = (($_SESSION['__WEB_APP']['APP_MODULE'] ?? "") <> "") ? true : false;
public function Menu_Sidebar() {
$a_modul = [];
$is_modul = ($this->session->get('__WEB_APP', ['APP_MODULE'=>''])['APP_MODULE'] <> '') ? true : false;
if ($is_modul == true) {
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
$a_modul[] = $this->session->get('__WEB_APP')['APP_MODULE'];
} else {
$atmp = $this->Menu_Query("Level=0 AND Aktif=1 AND Modul<>'IND'", "Urut");
for ($i=0; $i<count($atmp); $i++) {
$a_modul[] = $atmp[$i]['Modul'];
$atmp = $this->db->fetchAll('SELECT * FROM app_menu WHERE Level=0 AND Aktif=1 AND Modul<>"IND" ORDER BY Urut');
foreach ($atmp as $tmp) {
$a_modul[] = $tmp['Modul'];
}
}
$my_menu = array_unique(array_filter(explode(",", $_SESSION['__WEB_USER']['Menu_Grup'].",".$_SESSION['__WEB_USER']['Menu'])));
$tsql = " AND Modul IN ('".implode("','",$a_modul)."')";
$tsql .= ($is_modul == true) ? " AND Level>0" : "";
$tsql .= " AND Kode IN ('".implode("','",$my_menu)."')";
$amodul = $this->Menu_Query("Aktif=1".$tsql, "Kode");
$my_menu = array_unique(array_filter(explode(",", $this->session->get('__WEB_USER', ['Menu_Grup'=>''])['Menu_Grup'].",".$this->session->get('__WEB_USER', ['Menu'=>''])['Menu'])));
$tsql = 'SELECT * FROM app_menu WHERE Aktif=1 AND Modul IN (?) AND Kode IN (?)';
if ($is_modul == true) $tsql .= ' AND Level>0';
$amodul = $this->db->fetchAll($tsql . ' ORDER BY Kode', [$a_modul, $my_menu]);
$thasil = '';
$last_level = 0;
@@ -72,26 +70,25 @@ final class Menu {
return $thasil;
}
public function Menu_Header() {//oke
$a_modul = array();
$is_modul = (($_SESSION['__WEB_APP']['APP_MODULE'] ?? "") <> "") ? true : false;
public function Menu_Header() {
$a_modul = [];
$is_modul = ($this->session->get('__WEB_APP', ['APP_MODULE'=>''])['APP_MODULE'] <> '') ? true : false;
$mulai_level = 0;
if ($is_modul == true) {
$a_modul[] = $_SESSION['__WEB_APP']['APP_MODULE'];
$a_modul[] = $this->session->get('__WEB_APP')['APP_MODULE'];
$mulai_level = 1;
} else {
$atmp = $this->Menu_Query("Level=0 AND Aktif=1 AND Modul<>'IND'", "Urut");
for ($i=0; $i<count($atmp); $i++) {
$a_modul[] = $atmp[$i]['Modul'];
$atmp = $this->db->fetchAll('SELECT * FROM app_menu WHERE Level=0 AND Aktif=1 AND Modul<>"IND" ORDER BY Urut');
foreach ($atmp as $tmp) {
$a_modul[] = $tmp['Modul'];
}
}
$my_menu = array_unique(array_filter(explode(",", $_SESSION['__WEB_USER']['Menu_Grup'].",".$_SESSION['__WEB_USER']['Menu'])));
$tsql = " AND Modul IN ('".implode("','",$a_modul)."')";
$tsql .= ($is_modul == true) ? " AND Level>0" : "";
$tsql .= " AND Kode IN ('".implode("','",$my_menu)."')";
$amodul = $this->Menu_Query("Aktif=1".$tsql, "Kode");
$my_menu = array_unique(array_filter(explode(",", $this->session->get('__WEB_USER', ['Menu_Grup'=>''])['Menu_Grup'].",".$this->session->get('__WEB_USER', ['Menu'=>''])['Menu'])));
$tsql = 'SELECT * FROM app_menu WHERE Aktif=1 AND Modul IN (?) AND Kode IN (?)';
if ($is_modul == true) $tsql .= ' AND Level>0';
$amodul = $this->db->fetchAll($tsql . ' ORDER BY Kode', [$a_modul, $my_menu]);
$thasil = '';
$last_level = 0;
@@ -119,23 +116,22 @@ final class Menu {
return $thasil;
}
static function MenuJSON($db = null, $page = "", $tquery = "") {//oke
$_mdb = $db ?? new \siaupheng\webapp\DB\MySQL();
static function MenuJSON($db = null, $page = "", $tquery = "") {
$_mdb = (empty($db) === true) ? new SimplePdo() : $db;
$_query = ($tquery=="") ? "" : ",'".$tquery."'";
$ajson = ['login' => true];
$apage = ['Link' => ""];
$acus_page = [
'SYSP' => ['Kode'=>"SYSP", 'Judul'=>"Profil Pengguna", 'Link'=>"sys/profile.php", 'JS'=>"SYSProfileJS", 'Width'=>600, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]'],
'SYSC' => ['Kode'=>"SYSC", 'Judul'=>"Ubah Password", 'Link'=>"sys/chpasswd.php", 'JS'=>"SYSChpasswdJS", 'Width'=>500, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]']
'SYSP' => ['Kode'=>"SYSP", 'Judul'=>"Profil Pengguna", 'Link'=>"system/profile", 'JS'=>"SYSProfileJS", 'Width'=>600, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]'],
'SYSC' => ['Kode'=>"SYSC", 'Judul'=>"Ubah Password", 'Link'=>"system/chpasswd", 'JS'=>"SYSChpasswdJS", 'Width'=>500, 'Button'=>'[{},{"i":"butBatal"},{"i":"butSave","v":"Simpan","c":"success"}]']
];
if ($acus_page[$page] ?? false) {
$apage = $acus_page[$page];
} else if ($page <> "") {
$_mdb->Query("SELECT * FROM app_menu WHERE Kode='".$page."'");
if ($_mdb->Next()) $apage = $_mdb->AllRow();
$apage['Width'] = intval($apage['Width']);
$apage = $_mdb->fetchRow('SELECT * FROM app_menu WHERE Kode=?', [$page]);
$apage['Width'] = (int)$apage['Width'];
}
$ajson['iswindow'] = ($apage['Width'] > 0) ? true : false;
@@ -146,7 +142,6 @@ final class Menu {
$ajson['func'] = $apage['JS'];
$ajson['kode'] = $apage['Kode'];
if (!file_exists($_SESSION['__WEB_APP']['REAL_PATH']."apps/php/".$apage['Link'])) $ajson['php'] = "";
return $ajson;
}
}