From 35d679ed2c8aa631a05086f08c276163e1064885 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Mon, 26 Feb 2024 11:25:15 +0700 Subject: [PATCH] Menu With Auth --- system/autoload/Admin.php | 6 +++++- system/autoload/Hookers.php | 2 +- system/boot.php | 19 +++++++++++-------- system/controllers/autoload.php | 1 - system/controllers/bandwidth.php | 1 - system/controllers/codecanyon.php | 1 - system/controllers/community.php | 1 - system/controllers/customers.php | 1 - system/controllers/dashboard.php | 1 - system/controllers/export.php | 1 - system/controllers/logs.php | 1 - system/controllers/pages.php | 1 - system/controllers/paymentgateway.php | 1 - system/controllers/pluginmanager.php | 1 - system/controllers/pool.php | 1 - system/controllers/prepaid.php | 1 - system/controllers/radius.php | 1 - system/controllers/reports.php | 1 - system/controllers/routers.php | 1 - system/controllers/services.php | 1 - system/controllers/settings.php | 1 - system/lan/english.json | 4 +++- ui/ui/sections/header.tpl | 9 +++++---- 23 files changed, 25 insertions(+), 33 deletions(-) diff --git a/system/autoload/Admin.php b/system/autoload/Admin.php index 5d4a7a35..11b63143 100644 --- a/system/autoload/Admin.php +++ b/system/autoload/Admin.php @@ -42,6 +42,10 @@ Class Admin{ if(empty($id) && $id==0){ $id = Admin::getID(); } - return ORM::for_table('tbl_users')->find_one($id); + if($id){ + return ORM::for_table('tbl_users')->find_one($id); + }else{ + return []; + } } } \ No newline at end of file diff --git a/system/autoload/Hookers.php b/system/autoload/Hookers.php index d2e80ddf..16d665c4 100644 --- a/system/autoload/Hookers.php +++ b/system/autoload/Hookers.php @@ -18,7 +18,7 @@ $menu_registered = array(); * @param string icon from ion icon, ion-person, only for AFTER_ * @param string label for showing label or number of notification or update * @param string color Label color - * @param string auth ['SuperAdmin', 'Admin', 'Report', 'Agent', 'Sales'] will only show in this user, empty array for all users + * @param string auth authorization ['SuperAdmin', 'Admin', 'Report', 'Agent', 'Sales'] will only show in this user, empty array for all users */ function register_menu($name, $admin, $function, $position, $icon = '', $label = '', $color = 'success', $auth = []) { diff --git a/system/boot.php b/system/boot.php index 0bd3ec4b..17050d98 100644 --- a/system/boot.php +++ b/system/boot.php @@ -91,6 +91,7 @@ $handler = $routes[0]; if ($handler == '') { $handler = 'default'; } +$admin = Admin::_info(); try { $sys_render = $root_path.File::pathFixer('system/controllers/' . $handler . '.php'); if (file_exists($sys_render)) { @@ -102,15 +103,17 @@ try { $ui->assign('_system_menu', $routes[0]); foreach ($menu_registered as $menu) { if ($menu['admin'] && _admin(false)) { - $menus[$menu['position']] .= ''; - if (!empty($menu['icon'])) { - $menus[$menu['position']] .= ''; + if(count($menu['auth'])==0 || in_array($admin['user_type'], $menu['auth'])){ + $menus[$menu['position']] .= ''; + if (!empty($menu['icon'])) { + $menus[$menu['position']] .= ''; + } + if (!empty($menu['label'])) { + $menus[$menu['position']] .= ''; + $menus[$menu['position']] .= '' . $menu['label'] . ''; + } + $menus[$menu['position']] .= '' . $menu['name'] . ''; } - if (!empty($menu['label'])) { - $menus[$menu['position']] .= ''; - $menus[$menu['position']] .= '' . $menu['label'] . ''; - } - $menus[$menu['position']] .= '' . $menu['name'] . ''; } else if (!$menu['admin'] && _auth(false)) { $menus[$menu['position']] .= ''; if (!empty($menu['icon'])) { diff --git a/system/controllers/autoload.php b/system/controllers/autoload.php index 536bc20b..3a4ce34a 100644 --- a/system/controllers/autoload.php +++ b/system/controllers/autoload.php @@ -13,7 +13,6 @@ $ui->assign('_title', Lang::T('Network')); $ui->assign('_system_menu', 'network'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); switch ($action) { diff --git a/system/controllers/bandwidth.php b/system/controllers/bandwidth.php index c36d5716..cf12e38f 100644 --- a/system/controllers/bandwidth.php +++ b/system/controllers/bandwidth.php @@ -9,7 +9,6 @@ $ui->assign('_title', Lang::T('Bandwidth Plans')); $ui->assign('_system_menu', 'services'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { diff --git a/system/controllers/codecanyon.php b/system/controllers/codecanyon.php index e6612c25..95d13c9e 100644 --- a/system/controllers/codecanyon.php +++ b/system/controllers/codecanyon.php @@ -11,7 +11,6 @@ $ui->assign('_system_menu', 'settings'); $plugin_repository = 'https://hotspotbilling.github.io/Plugin-Repository/repository.json'; $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); $cache = File::pathFixer('system/cache/codecanyon.json'); diff --git a/system/controllers/community.php b/system/controllers/community.php index fe43e27b..c52b000a 100644 --- a/system/controllers/community.php +++ b/system/controllers/community.php @@ -9,7 +9,6 @@ $ui->assign('_title', 'Community'); $ui->assign('_system_menu', 'community'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); $ui->display('community.tpl'); \ No newline at end of file diff --git a/system/controllers/customers.php b/system/controllers/customers.php index e30a2c07..430dc8ef 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -10,7 +10,6 @@ $ui->assign('_title', Lang::T('Customer')); $ui->assign('_system_menu', 'customers'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); diff --git a/system/controllers/dashboard.php b/system/controllers/dashboard.php index c6b4da90..5df4557d 100644 --- a/system/controllers/dashboard.php +++ b/system/controllers/dashboard.php @@ -7,7 +7,6 @@ _admin(); $ui->assign('_title', Lang::T('Dashboard')); -$admin = Admin::_info(); $ui->assign('_admin', $admin); $fdate = date('Y-m-01'); diff --git a/system/controllers/export.php b/system/controllers/export.php index 02871815..35b04842 100644 --- a/system/controllers/export.php +++ b/system/controllers/export.php @@ -10,7 +10,6 @@ $ui->assign('_title', Lang::T('Reports')); $ui->assign('_sysfrm_menu', 'reports'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); $mdate = date('Y-m-d'); diff --git a/system/controllers/logs.php b/system/controllers/logs.php index c6f1be8a..1427194d 100644 --- a/system/controllers/logs.php +++ b/system/controllers/logs.php @@ -10,7 +10,6 @@ $ui->assign('_title', 'PHPNuxBill Logs'); $ui->assign('_system_menu', 'logs'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { diff --git a/system/controllers/pages.php b/system/controllers/pages.php index 5437a338..1d60dfab 100644 --- a/system/controllers/pages.php +++ b/system/controllers/pages.php @@ -9,7 +9,6 @@ $ui->assign('_title', 'Pages'); $ui->assign('_system_menu', 'pages'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); if(strpos($action,"-reset")!==false){ diff --git a/system/controllers/paymentgateway.php b/system/controllers/paymentgateway.php index 5aad90ac..290f8041 100644 --- a/system/controllers/paymentgateway.php +++ b/system/controllers/paymentgateway.php @@ -8,7 +8,6 @@ _admin(); $ui->assign('_system_menu', 'paymentgateway'); $action = alphanumeric($routes['1']); -$admin = Admin::_info(); $ui->assign('_admin', $admin); if(file_exists('system/paymentgateway/'.$action.'.php')){ diff --git a/system/controllers/pluginmanager.php b/system/controllers/pluginmanager.php index c1b51356..5225d4ff 100644 --- a/system/controllers/pluginmanager.php +++ b/system/controllers/pluginmanager.php @@ -11,7 +11,6 @@ $ui->assign('_system_menu', 'settings'); $plugin_repository = 'https://hotspotbilling.github.io/Plugin-Repository/repository.json'; $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); diff --git a/system/controllers/pool.php b/system/controllers/pool.php index 60d2b34e..5d0f928b 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -10,7 +10,6 @@ $ui->assign('_title', Lang::T('Network')); $ui->assign('_system_menu', 'network'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index 0b3434f8..fb810186 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -10,7 +10,6 @@ $ui->assign('_title', Lang::T('Recharge Account')); $ui->assign('_system_menu', 'prepaid'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); $select2_customer = <<assign('_title', $_L['Plugin Manager']); $ui->assign('_system_menu', 'settings'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); diff --git a/system/controllers/reports.php b/system/controllers/reports.php index 86b81481..ca79b027 100644 --- a/system/controllers/reports.php +++ b/system/controllers/reports.php @@ -10,7 +10,6 @@ $ui->assign('_title', Lang::T('Reports')); $ui->assign('_system_menu', 'reports'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); $mdate = date('Y-m-d'); diff --git a/system/controllers/routers.php b/system/controllers/routers.php index d0bf7765..49f68ef7 100644 --- a/system/controllers/routers.php +++ b/system/controllers/routers.php @@ -10,7 +10,6 @@ $ui->assign('_title', Lang::T('Network')); $ui->assign('_system_menu', 'network'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); use PEAR2\Net\RouterOS; diff --git a/system/controllers/services.php b/system/controllers/services.php index 6dc49598..29991dc7 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -9,7 +9,6 @@ $ui->assign('_title', Lang::T('Hotspot Plans')); $ui->assign('_system_menu', 'services'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 47244122..64d64bfc 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -9,7 +9,6 @@ $ui->assign('_title', Lang::T('Settings')); $ui->assign('_system_menu', 'settings'); $action = $routes['1']; -$admin = Admin::_info(); $ui->assign('_admin', $admin); switch ($action) { diff --git a/system/lan/english.json b/system/lan/english.json index bf4c5750..e4e269d5 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -454,5 +454,7 @@ "Alert": "Alert", "success": "success", "Click_Here": "Click Here", - "danger": "danger" + "danger": "danger", + "Logout_Successful": "Logout Successful", + "warning": "warning" } \ No newline at end of file diff --git a/ui/ui/sections/header.tpl b/ui/ui/sections/header.tpl index f4400c86..895fd11e 100644 --- a/ui/ui/sections/header.tpl +++ b/ui/ui/sections/header.tpl @@ -171,8 +171,8 @@ {/if} + {$_MENU_AFTER_PREPAID} {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} - {$_MENU_AFTER_PREPAID}
  • {Lang::T('Services')} @@ -192,8 +192,8 @@ {$_MENU_SERVICES}
  • - {$_MENU_AFTER_SERVICES} {/if} + {$_MENU_AFTER_SERVICES}
  • {Lang::T('Reports')} @@ -268,8 +268,8 @@ {$_MENU_PAGES}
  • - {$_MENU_AFTER_PAGES} {/if} + {$_MENU_AFTER_PAGES}
  • @@ -311,8 +311,8 @@ {/if}
  • + {$_MENU_AFTER_SETTINGS} {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} - {$_MENU_AFTER_SETTINGS}
  • {Lang::T('Logs')} @@ -338,6 +338,7 @@ {Lang::T('Community')}
  • + {$_MENU_AFTER_COMMUNITY}