* * @package Webapp\Web */ final class Menu { private array $web_app; private array $web_user; private array $my_menu; protected Engine $app; protected SimplePdo $db; protected Session $session; /** * @param Engine $app */ public function __construct(Engine $app){ $this->app = $app; $this->db = $app->db(); $this->session = $app->session(); $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 = !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']; } $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, $this->my_menu]); $thasil = ''; $last_level = 0; for ($i=0; $i0) and ($amodul[$i]['Level']<$amodul[$i-1]['Level'])) { $thasil .= str_repeat("", $amodul[$i-1]['Level']-$amodul[$i]['Level']); } $ticon = ($amodul[$i]['Icon']) ? '' : ""; if (($amodul[$i]['Level']>=0) && (isset($amodul[$i+1]) && ($amodul[$i+1]['Level']>$amodul[$i]['Level']))) { $thasil .= '", $last_level-1); return $thasil; } public function Header(): string { $a_modul = []; $is_modul = !empty($this->web_app['APP_MODULE']); $mulai_level = 0; 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'); foreach ($atmp as $tmp) { $a_modul[] = $tmp['Modul']; } } $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, $this->my_menu]); $thasil = ''; $last_level = 0; for ($i=0; $i0) and ($amodul[$i]['Level']<$amodul[$i-1]['Level'])) { $thasil .= str_repeat("", $amodul[$i-1]['Level']-$amodul[$i]['Level']); } $ticon = ($amodul[$i]['Icon']) ? '' : ""; if (isset($amodul[$i+1]) && ($amodul[$i+1]['Level']>$amodul[$i]['Level'])) {//have submenu if ($amodul[$i]['Level']==$mulai_level) { $thasil .= '