diff --git a/system/boot.php b/system/boot.php index 7d352b33..971a3e3e 100644 --- a/system/boot.php +++ b/system/boot.php @@ -23,6 +23,7 @@ if (file_exists('system/config.php')) { r2('system/install'); } + function safedata($value) { $value = trim($value); @@ -38,6 +39,50 @@ function _post($param, $defvalue = '') } } +$menu_registered = array(); + +/** + * Register for global menu + * @param string name Name of the menu + * @param bool admin true if for admin and false for customer + * @param string function function to run after menu clicks + * @param string position position of menu, use AFTER_ for root menu | + * Admin/Sales menu: AFTER_DASHBOARD, CUSTOMERS, PREPAID, SERVICES, REPORTS, VOUCHER, AFTER_ORDER, NETWORK, SETTINGS, AFTER_PAYMENTGATEWAY + * | Customer menu: AFTER_DASHBOARD, ORDER, HISTORY, ACCOUNTS + * @param string icon from ion icon, ion-person, only for AFTER_ + */ +function register_menu($name, $admin, $function, $position, $icon = '') +{ + global $menu_registered; + $menu_registered[] = [ + "name" => $name, + "admin" => $admin, + "position" => $position, + "icon" => $icon, + "function" => $function + ]; +} + +$hook_registered = array(); + +function register_hook($action, $function){ + $hook_registered[] = [ + 'action' => $action, + 'function' => $function + ]; +} + +function run_hook($action){ + global $hook_registered; + foreach($hook_registered as $hook){ + if($hook['action'] == $action){ + if(function_exists($hook['function'])){ + call_user_func($hook['function']); + } + } + } +} + function _get($param, $defvalue = '') { if (!isset($_GET[$param])) { @@ -115,6 +160,13 @@ if (isset($_SESSION['notify'])) { unset($_SESSION['ntype']); } + +//register all plugin +foreach (glob("system/plugin/*.php") as $filename) +{ + include $filename; +} + // on some server, it getting error because of slash is backwards function _autoloader($class) { @@ -140,21 +192,29 @@ function _autoloader($class) spl_autoload_register('_autoloader'); -function _auth() +function _auth($login = true) { if (isset($_SESSION['uid'])) { return true; } else { - r2(U . 'login'); + if ($login) { + r2(U . 'login'); + } else { + return false; + } } } -function _admin() +function _admin($login = true) { if (isset($_SESSION['aid'])) { return true; } else { - r2(U . 'login'); + if ($login) { + r2(U . 'login'); + } else { + return false; + } } } @@ -263,34 +323,43 @@ function time_elapsed_string($datetime, $full = false) // Routing Engine $req = _get('_route'); $routes = explode('/', $req); -$handler = $routes['0']; +$ui->assign('_routes', $routes); +$handler = $routes[0]; if ($handler == '') { $handler = 'default'; } $sys_render = 'system/controllers/' . $handler . '.php'; if (file_exists($sys_render)) { + $menus = array(); + // "name" => $name, + // "admin" => $admin, + // "position" => $position, + // "function" => $function + $ui->assign('_system_menu', $routes[0]); + foreach ($menu_registered as $menu) { + if($menu['admin'] && _admin(false)) { + if(strpos($menu['position'],'AFTER_')===false) { + $menus[$menu['position']] .= ''.$menu['name'].''; + }else{ + $menus[$menu['position']] .= ''. + ''. + ''.$menu['name'].''; + } + }else if(!$menu['admin'] && _auth(false)) { + if(strpos($menu['position'],'AFTER_')===false) { + $menus[$menu['position']] .= ''.$menu['name'].''; + }else{ + $menus[$menu['position']] .= ''. + ''. + ''.$menu['name'].''; + } + } + } + foreach ($menus as $k => $v) { + $ui->assign('_MENU_'.$k, $v); + } + unset($menus, $menu_registered); include($sys_render); } else { - header("HTTP/1.0 404 Not Found"); - exit("
-
-    ___ ___ ___
-   | | |   | | |
-   |_  | | |_  |
-     |_|___| |_|
-
-
-    _____     _      _____               _
-   |   | |___| |_   |   __|___ _ _ ___ _| |
-   | | | | . |  _|  |   __| . | | |   | . |
-   |_|___|___|_|    |__|  |___|___|_|_|___|
-
-   _   ______   ____  _____          ____  ____
-   (_) |_   _ \ |_   \|_   _|        |_  _||_  _|
-   __    | |_) |  |   \ | |  __   _    \ \  / /
-  [  |   |  __'.  | |\ \| | [  | | |    > `' <
-   | |  _| |__) |_| |_\   |_ | \_/ |, _/ /'`\ \_
-  [___]|_______/|_____|\____|'.__.'_/|____||____|
-
-
"); + r2(U.'dashboard', 'e', 'not found'); } diff --git a/system/controllers/accounts.php b/system/controllers/accounts.php index bb889c4c..0053115d 100644 --- a/system/controllers/accounts.php +++ b/system/controllers/accounts.php @@ -21,6 +21,7 @@ switch ($action) { case 'change-password-post': $password = _post('password'); + run_hook('customer_change_password'); #HOOK if($password != ''){ $d = ORM::for_table('tbl_customers')->where('username',$user['username'])->find_one(); if($d){ @@ -148,7 +149,7 @@ switch ($action) { $fullname = _post('fullname'); $address = _post('address'); $phonenumber = _post('phonenumber'); - + run_hook('customer_edit_profile'); #HOOK $msg = ''; if(Validator::Length($fullname,31,2) == false){ $msg .= 'Full Name should be between 3 to 30 characters'. '
'; diff --git a/system/controllers/admin.php b/system/controllers/admin.php index 73bbfdbf..5acf4439 100644 --- a/system/controllers/admin.php +++ b/system/controllers/admin.php @@ -1,40 +1,42 @@ where('username',$username)->find_one(); - if($d){ - $d_pass = $d['password']; - if(Password::_verify($password,$d_pass) == true){ - $_SESSION['aid'] = $d['id']; - $d->last_login = date('Y-m-d H:i:s'); - $d->save(); - _log($username .' '. $_L['Login_Successful'],'Admin',$d['id']); - r2(U.'dashboard'); - }else{ - _msglog('e',$_L['Invalid_Username_or_Password']); - _log($username .' '. $_L['Failed_Login'],'Admin'); - r2(U.'admin'); - } - }else{ - _msglog('e',$_L['Invalid_Username_or_Password']); - r2(U.'admin'); - } - }else{ - _msglog('e',$_L['Invalid_Username_or_Password']); - r2(U.'admin'); - } + $username = _post('username'); + $password = _post('password'); + run_hook('admin_login'); #HOOK + if ($username != '' and $password != '') { + $d = ORM::for_table('tbl_users')->where('username', $username)->find_one(); + if ($d) { + $d_pass = $d['password']; + if (Password::_verify($password, $d_pass) == true) { + $_SESSION['aid'] = $d['id']; + $d->last_login = date('Y-m-d H:i:s'); + $d->save(); + _log($username . ' ' . $_L['Login_Successful'], 'Admin', $d['id']); + r2(U . 'dashboard'); + } else { + _msglog('e', $_L['Invalid_Username_or_Password']); + _log($username . ' ' . $_L['Failed_Login'], 'Admin'); + r2(U . 'admin'); + } + } else { + _msglog('e', $_L['Invalid_Username_or_Password']); + r2(U . 'admin'); + } + } else { + _msglog('e', $_L['Invalid_Username_or_Password']); + r2(U . 'admin'); + } break; @@ -46,4 +48,3 @@ switch($do){ $ui->display('admin.tpl'); break; } - diff --git a/system/controllers/plugin.php b/system/controllers/plugin.php new file mode 100644 index 00000000..0879da97 --- /dev/null +++ b/system/controllers/plugin.php @@ -0,0 +1,7 @@ +

404

-

Coming Soon!! Next Version...

diff --git a/ui/ui/sections/header.tpl b/ui/ui/sections/header.tpl index 05b20af1..862dec80 100644 --- a/ui/ui/sections/header.tpl +++ b/ui/ui/sections/header.tpl @@ -130,19 +130,7 @@ {$_L['Dashboard']} - - + {$_MENU_AFTER_DASHBOARD} {if $_admin['user_type'] eq 'Admin' || $_admin['user_type'] eq 'Sales'}
  • @@ -151,10 +139,12 @@
  • + {$_MENU_AFTER_CUSTOMERS}
  • @@ -162,12 +152,14 @@
  • + {$_MENU_AFTER_PREPAID}
  • @@ -175,11 +167,13 @@
  • + {$_MENU_AFTER_SERVICES}
  • @@ -187,40 +181,12 @@ -
  • - {else} -
  • - - - {$_L['Voucher']} - - - -
  • -
  • - - - {$_L['Order_Voucher']} - -
  • -
  • - - - {$_L['My_Account']} - - -
  • + {$_MENU_AFTER_REPORTS} {/if} {if $_admin['user_type'] eq 'Admin'}
  • @@ -230,10 +196,12 @@
  • + {$_MENU_AFTER_NETWORKS}
  • @@ -241,12 +209,14 @@
  • + {$_MENU_AFTER_PAGES}
  • @@ -254,19 +224,21 @@
  • + {$_MENU_AFTER_SETTINGS}
  • {Lang::T('Payment Gateway')}
  • + {$_MENU_AFTER_PAYMENTGATEWAY}
  • diff --git a/ui/ui/sections/user-header.tpl b/ui/ui/sections/user-header.tpl index 3008a892..a74aa867 100644 --- a/ui/ui/sections/user-header.tpl +++ b/ui/ui/sections/user-header.tpl @@ -105,23 +105,11 @@ {$_L['Dashboard']}
  • - - + {$_MENU_AFTER_DASHBOARD}
  • - ORDER + {Lang::T('ORDER')}
  • + {$_MENU_AFTER_ORDER}
  • {Lang::T('History')}
  • + {$_MENU_AFTER_HISTORY}
  • @@ -147,10 +138,10 @@
  • - + {$_MENU_AFTER_ACCOUNTS}