diff --git a/src/App/Auth.php b/src/App/Auth.php index 35d627f..2eb6215 100644 --- a/src/App/Auth.php +++ b/src/App/Auth.php @@ -5,7 +5,7 @@ Module : /App/Auth.php Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : March 16th, 2008. - Last Modified : September 10th, 2026. + Last Modified : October 21st, 2026. (c) 3FONIA Software; WWW.3FONIA.COM. @@ -43,65 +43,43 @@ final class Auth { $this->app = $app; $this->db = $app->db(); $this->session = $app->session(); - $this->id_reg = (int) $this->session->get('WEB_APP', ['REG_ID'=>0])['REG_ID']; - } - - public function set_id_reg(int|string $id = 0): void { - if ((int) $id > 0) $this->id_reg = (int) $id; + $this->id_reg = (int) $this->session->get('WEB_APP', ['PARENT_CODE'=>0])['PARENT_CODE']; } 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]); + $i_hasil = (int) $this->db->fetchField('SELECT COUNT(*) FROM app_operator WHERE Username=? AND Password=MD5(?) AND Aktif=1', [$user, $pass]) ?? 0; return ($i_hasil > 0 ? true : false); } - public function user_data(string $user): array { + public function user_data(string $user, bool $gen_module=true): array { $adata = [ 'Grup_MenuID' => 0 ]; - $xdata = $this->db->fetchRow('SELECT *,DECODE(Menu,?) Menu2 FROM app_operator WHERE Username=?', [$this->id_reg, $user]); - if ($xdata) { - $adata = $xdata->getData(); - $adata['Menu'] = $adata['Menu2']; - unset($adata['Menu2'], $adata['Password']); - } + $xdata = $this->db->fetchRow('SELECT UserID,Grup_MenuID,Username,Nama,Posisi,Email,HP,Level,Last_IP,Last_Date FROM app_operator WHERE Username=?', [$user]); + if ($xdata) $adata = $xdata->getData(); if (empty($this->session->get('APP_TOKEN'))) { $_token = $this->genToken(60); $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((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(): 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']]); + if ($gen_module === true && !empty($this->session->get('WEB_APP')['APP_MODULE'])) { + $tallow = $this->db->fetchField('SELECT Modul_Akses FROM app_menu_grup WHERE Grup_MenuID=?', [$adata['Grup_MenuID']]) ?? ''; $aallow = explode(",", $tallow); - if (count($aallow) > 0) { $stat = $this->db->runQuery('SELECT * FROM (SELECT APP_MODULE,APP_PATH FROM app_config) A LEFT JOIN (SELECT Modul,Urut,Judul,Icon FROM app_menu WHERE Level=0) B ON (A.APP_MODULE=B.Modul) ORDER BY B.Urut'); while ($row = $stat->fetch()) { - if (!in_array($row['Modul'], $aallow) || $row['Modul']==$this->session->get('WEB_APP')['APP_MODULE']) continue; - $amodul[] = $row; + if (!in_array($row['Modul'], $aallow) || $row['Modul'] === $this->session->get('WEB_APP')['APP_MODULE']) continue; + $adata['MENU_MODUL'][] = $row; } } } - $auser = $this->session->get('WEB_USER', []); - $auser['MENU_MODUL'] = $amodul; - $this->session->set('WEB_USER', $auser); - } - - 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; + return $adata; } 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]); + $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); } @@ -143,9 +121,21 @@ final class Auth { } 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')]); + $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; } + + public function pos_login(int $id_cab, int $id_user, int $unix, string $ip): void { + if (empty($id_cab) || empty($id_user) || empty($ip)) return; + $this->db->delete('disp_login', 'CabID=? AND UserID=?', [$id_cab, $id_user]); + $this->db->runQuery('INSERT INTO disp_login (IP, CabID, UserID, Unix, Date) VALUES (?, ?, ?, ?, NOW())', [ $ip, $id_cab, $id_user, $unix ?? 0 ]); + } + + public function pos_logout(int $id_cab, int $id_user, int $unix, string $ip): void { + if (empty($id_cab) || empty($id_user) || empty($ip)) return; + $this->db->delete('disp_login', 'CabID=? AND UserID=? AND IP=? AND Unix=?', [$id_cab, $id_user, $ip, $unix ?? 0 ]); + } + } ?> diff --git a/src/Data/Cache.php b/src/Data/Cache.php index da69647..2cc5e48 100644 --- a/src/Data/Cache.php +++ b/src/Data/Cache.php @@ -5,7 +5,7 @@ Module : /Data/Cache.php Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : March 16th, 2008. - Last Modified : September 3rd, 2026. + Last Modified : October 12th, 2026. (c) 3FONIA Software; WWW.3FONIA.COM. @@ -43,6 +43,7 @@ final class Cache { private array $ini; private array $web_app; private array $web_user; + private array $my_menu = []; private bool $is_login; private bool $IS_DEV = false; protected Engine $app; @@ -72,7 +73,7 @@ final class Cache { $this->ini = [ 'login' => [ 'css' => "", 'js' => "", 'app' => "", ], 'index' => [ 'css' => "", 'js' => "", 'app' => "", ], - 'display' => [ 'css' => "", 'js' => "", 'app' => "", ], + 'monitor' => [ 'css' => "", 'js' => "", 'app' => "", ], ]; $this->save_ini(); } else $this->ini = parse_ini_file($this->cachedir . "cache.ini", true); @@ -134,7 +135,7 @@ final class Cache { } if ($mode === 'index') { $_ajs = ['system/profile', 'system/chpasswd']; - $amenu = array_values($this->web_user['Merge_Menu'] ?? []); + $amenu = array_values($this->my_menu ?? []); $_ops = $this->db->fetchColumn("SELECT Link FROM app_menu WHERE Kode IN (?) AND Link<>'' ORDER BY Kode", [$amenu]); if ($_ops) $_ajs = array_merge($_ajs, $_ops); $dirIterator = new \RecursiveDirectoryIterator($this->jsapp, \RecursiveDirectoryIterator::SKIP_DOTS); @@ -142,7 +143,7 @@ final class Cache { $iterator = new \RecursiveIteratorIterator($dirFilter); foreach ($iterator as $_file) { if ($_file->isFile() && - !in_array($_file->getFilename(), ['login.js','index.js','display.js']) && + !in_array($_file->getFilename(), ['login.js','index.js','monitor.js']) && array_any($_ajs, fn($js) => str_ends_with(str_replace(['_','\\'],['','/'],$_file->getRealPath()), $js.'.js'))) { $afile[] = $_file->getRealPath(); $itime += $_file->getMTime(); @@ -194,7 +195,10 @@ final class Cache { public function Cache(string $mode = "index"): array { if ($mode === 'index') { $this->ini['index']['app'] = (string) $this->db->fetchField("SELECT JS FROM app_operator_profile WHERE UserID=?", [$this->web_user['UserID']]) ?? ''; - $this->web_user['Merge_Menu'] = array_filter(array_unique(explode(",", $this->web_user['Menu_Grup'] .",". $this->web_user['Menu']))); + $_menu = $this->db->fetchField("SELECT CONVERT(DECODE(Menu,?) USING UTF8MB4) Menu FROM app_operator WHERE UserID=?", [$this->web_app['PARENT_CODE'], $this->web_user['UserID']]) ?? ''; + $_gmenu = ''; + if ($this->web_user['Grup_MenuID'] > 0) $_gmenu = $this->db->fetchField('SELECT CONVERT(DECODE(Menu,?) USING UTF8MB4) Menu FROM app_menu_grup WHERE Grup_MenuID=?', [$this->web_app['PARENT_CODE'], $this->web_user['Grup_MenuID']]) ?? ''; + $this->my_menu = array_filter(array_unique(explode(",", $_gmenu .",". $_menu))); } $is_modif = false; @@ -235,7 +239,7 @@ final class Cache { return $acache; } - public function Make_Cache(array $amode = ['login', 'index', 'display']): array { + public function Make_Cache(array $amode = ['login', 'index', 'monitor']): array { $is_modif = false; foreach ($amode as $mode) { foreach (['css','js','app'] as $type) { @@ -252,11 +256,11 @@ final class Cache { if ($is_modif === true) $this->save_ini(); if (in_array('index', $amode)) { - $agrup = $this->db->fetchAll('SELECT Grup_MenuID,DECODE(Menu,?) Menu FROM app_menu_grup', [$this->web_app['PARENT_CODE']]); - $auser = $this->db->fetchAll("SELECT A.*,IFNULL(B.JS,'') JS FROM (SELECT UserID,Grup_MenuID,DECODE(Menu,?) Menu FROM app_operator) A LEFT JOIN app_operator_profile B ON (A.UserID=B.UserID)", [$this->web_app['PARENT_CODE']]); + $agrup = $this->db->fetchAll('SELECT Grup_MenuID,CONVERT(DECODE(Menu,?) USING UTF8MB4) Menu FROM app_menu_grup', [$this->web_app['PARENT_CODE']]); + $auser = $this->db->fetchAll("SELECT A.*,IFNULL(B.JS,'') JS FROM (SELECT UserID,Grup_MenuID,CONVERT(DECODE(Menu,?) USING UTF8MB4) Menu FROM app_operator) A LEFT JOIN app_operator_profile B ON (A.UserID=B.UserID)", [$this->web_app['PARENT_CODE']]); foreach ($auser as $user) { if (empty($user['JS']) || !file_exists($this->cachedir . $user['JS'])) { - $this->web_user['Merge_Menu'] = array_filter(array_unique(explode(",", $user['Menu'] .",". ($agrup[$user['Grup_MenuID']]['Menu'] ?? '')))); + $this->my_menu = array_filter(array_unique(explode(",", $user['Menu'] .",". ($agrup[$user['Grup_MenuID']]['Menu'] ?? '')))); [ $afile, $lastmod ] = $this->gen_file('index', 'app'); $cachefile = md5('index-app-' . (string) $user['UserID'] . $lastmod) . '.js'; diff --git a/src/Data/Xlsx.php b/src/Data/Xlsx.php index b19dbb8..3432ef6 100644 --- a/src/Data/Xlsx.php +++ b/src/Data/Xlsx.php @@ -2,7 +2,7 @@ /******************************************************************* - PHP Class : /Data/Xls.php + PHP Class : /Data/Xlsx.php Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : November 18th, 2012. Last Modified : October 1st, 2026. diff --git a/src/Web/Menu.php b/src/Web/Menu.php index 8070251..dbe2686 100644 --- a/src/Web/Menu.php +++ b/src/Web/Menu.php @@ -5,7 +5,7 @@ Module : /Web/Menu.php Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : January 16th, 2008. - Last Modified : August 22nd, 2026. + Last Modified : October 21st, 2026. (c) 3FONIA Software; WWW.3FONIA.COM. @@ -31,8 +31,9 @@ use \flight\database\SimplePdo; */ final class Menu { - private array $webapp; - private array $webuser; + private array $web_app; + private array $web_user; + private array $my_menu; protected Engine $app; protected SimplePdo $db; protected Session $session; @@ -44,27 +45,28 @@ final class Menu { $this->app = $app; $this->db = $app->db(); $this->session = $app->session(); - $this->webapp = $this->session->get('WEB_APP', ['APP_MODULE'=>'', 'PARENT_SITE'=>'', 'PARENT_SUB'=>false]); - $this->webuser = $this->session->get('WEB_USER', ['Menu'=>'', 'Menu_Grup'=>'', 'MENU_MODUL'=>[]]); + $this->web_app = $this->session->get('WEB_APP', ['APP_MODULE'=>'', 'PARENT_SITE'=>'', 'PARENT_SUB'=>false]); + $this->web_user = $this->session->get('WEB_USER', ['Menu'=>'', 'Menu_Grup'=>'', 'MENU_MODUL'=>[]]); + $_gmenu = ''; + $_umenu = $this->db->fetchField("SELECT CONVERT(DECODE(Menu,?) USING UTF8MB4) Menu FROM app_operator WHERE UserID=?", [$this->web_app['PARENT_CODE'], $this->web_user['UserID']]) ?? ''; + if ($this->web_user['Grup_MenuID'] > 0) $_gmenu = $this->db->fetchField('SELECT CONVERT(DECODE(Menu,?) USING UTF8MB4) Menu FROM app_menu_grup WHERE Grup_MenuID=?', [$this->web_app['PARENT_CODE'], $this->web_user['Grup_MenuID']]) ?? ''; + $this->my_menu = array_unique(array_filter(explode(",", $_gmenu.",".$_umenu))); } public function Sidebar(): string { $a_modul = []; - $is_modul = ($this->webapp['APP_MODULE'] !== '') ? true : false; - if ($is_modul == true) { - $a_modul[] = $this->webapp['APP_MODULE']; + $is_modul = !empty($this->web_app['APP_MODULE']); + if ($is_modul === true) { + $a_modul[] = $this->web_app['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) { - $a_modul[] = $tmp['Modul']; - } + foreach ($atmp as $tmp) $a_modul[] = $tmp['Modul']; } - $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'; - $amodul = $this->db->fetchAll($tsql . ' ORDER BY Kode', [$a_modul, $my_menu]); + $amodul = $this->db->fetchAll($tsql . ' ORDER BY Kode', [$a_modul, $this->my_menu]); $thasil = ''; $last_level = 0; @@ -88,10 +90,10 @@ final class Menu { public function Header(): string { $a_modul = []; - $is_modul = ($this->webapp['APP_MODULE'] !== '') ? true : false; + $is_modul = !empty($this->web_app['APP_MODULE']); $mulai_level = 0; - if ($is_modul == true) { - $a_modul[] = $this->webapp['APP_MODULE']; + if ($is_modul === true) { + $a_modul[] = $this->web_app['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'); @@ -100,11 +102,10 @@ final class 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'; - $amodul = $this->db->fetchAll($tsql . ' ORDER BY Kode', [$a_modul, $my_menu]); + $amodul = $this->db->fetchAll($tsql . ' ORDER BY Kode', [$a_modul, $this->my_menu]); $thasil = ''; $last_level = 0; @@ -134,15 +135,15 @@ final class Menu { public function Modul(): string { $t_modul = ''; - if (is_array($this->webuser['MENU_MODUL']) && count($this->webuser['MENU_MODUL'])>0) { + if (is_array($this->web_user['MENU_MODUL']) && count($this->web_user['MENU_MODUL'])>0) { $t_modul = ''; 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 = $this->app->request()->getVar('HTTP_ORIGIN') ?? $this->app->request()->getVar('HTTP_HOST') ?? $this->web_app['PARENT_SITE']; $_host = str_replace(['http://','https://'], "", $_host); - if ($this->webapp['PARENT_SUB'] === true) { + if ($this->web_app['PARENT_SUB'] === true) { $_subs = explode('.', $_host); if (count($_subs) > 2) array_shift($_subs); $href1 = "//"; @@ -152,7 +153,7 @@ final class Menu { $href2 = ""; } } - foreach ($this->webuser['MENU_MODUL'] as $modul) { + foreach ($this->web_user['MENU_MODUL'] as $modul) { $href = $href1 . $modul['APP_PATH'] . $href2 . '/' . $this->session->get('APP_TOKEN'); $t_modul .= ' '.$modul['Judul'].''; } @@ -173,7 +174,7 @@ final class Menu { $apage = $acus_page[$page]; } else if ($page <> "") { $apage = $db->fetchRow('SELECT * FROM app_menu WHERE Kode=?', [$page]); - $apage['Width'] = (int)$apage['Width']; + $apage['Width'] = (int) $apage['Width']; } $ajson['iswindow'] = ($apage['Width'] > 0) ? true : false; diff --git a/src/Web/Param.php b/src/Web/Param.php index 769d674..67178df 100644 --- a/src/Web/Param.php +++ b/src/Web/Param.php @@ -5,7 +5,7 @@ Module : /Web/Param.php Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : November 14th, 2013. - Last Modified : September 16th, 2026. + Last Modified : October 16th, 2026. (c) 3FONIA Software; WWW.3FONIA.COM. @@ -75,15 +75,6 @@ final class Param { return self::$__ahasil; } - //delete - public static function Get_Text(string $key, mixed $def = null): mixed { - return self::Get($key, $def); - } - - //delete - public static function Get_ArrayCBOX() { - return []; - } } ?>