diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index 80db1fe9..58d96ec7 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -190,6 +190,7 @@ CREATE TABLE `tb_languages` ( ALTER TABLE `tbl_voucher` ADD `generated_by` INT NOT NULL DEFAULT '0' COMMENT 'id admin' AFTER `status`; ALTER TABLE `tbl_users` ADD `root` INT NOT NULL DEFAULT '0' COMMENT 'for sub account' AFTER `id`; +ALTER TABLE `tbl_users` CHANGE `user_type` `user_type` ENUM('SuperAdmin','Admin','Report','Agent','Sales') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL; ALTER TABLE `tbl_appconfig` ADD PRIMARY KEY (`id`); diff --git a/system/controllers/admin.php b/system/controllers/admin.php index dbdca380..f84e4340 100644 --- a/system/controllers/admin.php +++ b/system/controllers/admin.php @@ -25,11 +25,11 @@ switch ($do) { Admin::setCookie($d['id']); $d->last_login = date('Y-m-d H:i:s'); $d->save(); - _log($username . ' ' . $_L['Login_Successful'], 'Admin', $d['id']); + _log($username . ' ' . $_L['Login_Successful'], $d['user_type'], $d['id']); r2(U . 'dashboard'); } else { _msglog('e', $_L['Invalid_Username_or_Password']); - _log($username . ' ' . $_L['Failed_Login'], 'Admin'); + _log($username . ' ' . $_L['Failed_Login'], $d['user_type']); r2(U . 'admin'); } } else { diff --git a/system/controllers/bandwidth.php b/system/controllers/bandwidth.php index 566e635e..3fe13630 100644 --- a/system/controllers/bandwidth.php +++ b/system/controllers/bandwidth.php @@ -12,7 +12,7 @@ $action = $routes['1']; $admin = Admin::_info(); $ui->assign('_admin', $admin); -if($admin['user_type'] != 'Admin' AND $admin['user_type'] != 'Sales'){ +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U."dashboard",'e',$_L['Do_Not_Access']); } diff --git a/system/controllers/codecanyon.php b/system/controllers/codecanyon.php index f91c66cb..ee948348 100644 --- a/system/controllers/codecanyon.php +++ b/system/controllers/codecanyon.php @@ -15,7 +15,7 @@ $admin = Admin::_info(); $ui->assign('_admin', $admin); $cache = File::pathFixer('system/cache/codecanyon.json'); -if ($admin['user_type'] != 'Admin') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } if (empty($config['envato_token'])) { diff --git a/system/controllers/customers.php b/system/controllers/customers.php index 1549ac66..9347eb00 100644 --- a/system/controllers/customers.php +++ b/system/controllers/customers.php @@ -14,7 +14,7 @@ $admin = Admin::_info(); $ui->assign('_admin', $admin); -if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } @@ -50,8 +50,8 @@ switch ($action) { case 'csv': $cs = ORM::for_table('tbl_customers') - ->select('tbl_customers.id','id') - ->select('tbl_customers.username','username') + ->select('tbl_customers.id', 'id') + ->select('tbl_customers.username', 'username') ->select('fullname') ->select('phonenumber') ->select('email') @@ -59,7 +59,7 @@ switch ($action) { ->select('namebp') ->select('routers') ->select('status') - ->select('method','Payment') + ->select('method', 'Payment') ->join('tbl_user_recharges', array('tbl_customers.id', '=', 'tbl_user_recharges.customer_id')) ->order_by_asc('tbl_customers.id')->find_array(); $h = false; @@ -77,11 +77,11 @@ switch ($action) { $ks[] = $k; $vs[] = $v; } - if(!$h){ - echo '"'.implode('";"', $ks)."\"\n"; + if (!$h) { + echo '"' . implode('";"', $ks) . "\"\n"; $h = true; } - echo '"'.implode('";"', $vs)."\"\n"; + echo '"' . implode('";"', $vs) . "\"\n"; } break; case 'add': @@ -137,7 +137,7 @@ switch ($action) { $p = ORM::for_table('tbl_plans')->where('id', $b['plan_id'])->where('enabled', '1')->find_one(); if ($p) { if ($p['is_radius']) { - Radius::customerAddPlan($c, $p, $p['expiration'].' '.$p['time']); + Radius::customerAddPlan($c, $p, $p['expiration'] . ' ' . $p['time']); r2(U . 'customers/view/' . $id_customer, 's', 'Success sync customer to Radius'); } else { $mikrotik = Mikrotik::info($b['routers']); @@ -167,7 +167,7 @@ switch ($action) { $v = $routes['3']; if (empty($v) || $v == 'order') { $v = 'order'; - $paginator = Paginator::build(ORM::for_table('tbl_payment_gateway'),['username'=>$customer['username']]); + $paginator = Paginator::build(ORM::for_table('tbl_payment_gateway'), ['username' => $customer['username']]); $order = ORM::for_table('tbl_payment_gateway') ->where('username', $customer['username']) ->offset($paginator['startpoint']) @@ -177,7 +177,7 @@ switch ($action) { $ui->assign('paginator', $paginator); $ui->assign('order', $order); } else if ($v == 'activation') { - $paginator = Paginator::build(ORM::for_table('tbl_transactions'),['username'=>$customer['username']]); + $paginator = Paginator::build(ORM::for_table('tbl_transactions'), ['username' => $customer['username']]); $activation = ORM::for_table('tbl_transactions') ->where('username', $customer['username']) ->offset($paginator['startpoint']) @@ -369,11 +369,11 @@ switch ($action) { $c->save(); $p = ORM::for_table('tbl_plans')->find_one($c['plan_id']); if ($p['is_radius']) { - if($userDiff){ + if ($userDiff) { Radius::customerChangeUsername($oldusername, $username); } - Radius::customerAddPlan($d, $p, $p['expiration'].' '.$p['time']); - }else{ + Radius::customerAddPlan($d, $p, $p['expiration'] . ' ' . $p['time']); + } else { $mikrotik = Mikrotik::info($c['routers']); if ($c['type'] == 'Hotspot') { $client = Mikrotik::getClient($mikrotik['ip_address'], $mikrotik['username'], $mikrotik['password']); diff --git a/system/controllers/dashboard.php b/system/controllers/dashboard.php index f803cae2..1d14f7f8 100644 --- a/system/controllers/dashboard.php +++ b/system/controllers/dashboard.php @@ -9,7 +9,7 @@ _admin(); $ui->assign('_title', $_L['Dashboard']); $admin = Admin::_info(); $ui->assign('_admin', $admin); -if (!in_array($admin['user_type'], ['Admin', 'Sales'])) { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "home", 'e', $_L['Do_Not_Access']); } diff --git a/system/controllers/logs.php b/system/controllers/logs.php index f0b35b39..23ea294f 100644 --- a/system/controllers/logs.php +++ b/system/controllers/logs.php @@ -13,7 +13,7 @@ $action = $routes['1']; $admin = Admin::_info(); $ui->assign('_admin', $admin); -if ($admin['user_type'] != 'Admin') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } diff --git a/system/controllers/pluginmanager.php b/system/controllers/pluginmanager.php index 57d7701a..84834d25 100644 --- a/system/controllers/pluginmanager.php +++ b/system/controllers/pluginmanager.php @@ -15,7 +15,7 @@ $admin = Admin::_info(); $ui->assign('_admin', $admin); -if ($admin['user_type'] != 'Admin') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } diff --git a/system/controllers/pool.php b/system/controllers/pool.php index 2261d8eb..a4508657 100644 --- a/system/controllers/pool.php +++ b/system/controllers/pool.php @@ -13,7 +13,7 @@ $action = $routes['1']; $admin = Admin::_info(); $ui->assign('_admin', $admin); -if ($admin['user_type'] != 'Admin') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index 8345a823..9cc1b8fe 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -13,7 +13,7 @@ $action = $routes['1']; $admin = Admin::_info(); $ui->assign('_admin', $admin); -if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Sales'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } @@ -128,7 +128,7 @@ switch ($action) { $ui->assign('in', $in); $ui->assign('date', date("Y-m-d H:i:s")); $ui->display('invoice.tpl'); - _log('[' . $admin['username'] . ']: ' . 'Recharge ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', 'Admin', $admin['id']); + _log('[' . $admin['username'] . ']: ' . 'Recharge ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']); } else { r2(U . 'prepaid/recharge', 'e', "Failed to recharge account"); } @@ -202,7 +202,7 @@ switch ($action) { } } $d->delete(); - _log('[' . $admin['username'] . ']: ' . 'Delete Plan for Customer ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', 'Admin', $admin['id']); + _log('[' . $admin['username'] . ']: ' . 'Delete Plan for Customer ' . $c['username'] . ' [' . $in['plan_name'] . '][' . Lang::moneyFormat($in['price']) . ']', $admin['user_type'], $admin['id']); r2(U . 'prepaid/list', 's', $_L['Delete_Successfully']); } break; @@ -247,7 +247,7 @@ switch ($action) { if($d['status'] == 'on'){ Package::changeTo($username, $id_plan, $id); } - _log('[' . $admin['username'] . ']: ' . 'Edit Plan for Customer ' . $d['username'] . ' to [' . $d['namebp'] . '][' . Lang::moneyFormat($p['price']) . ']', 'Admin', $admin['id']); + _log('[' . $admin['username'] . ']: ' . 'Edit Plan for Customer ' . $d['username'] . ' to [' . $d['namebp'] . '][' . Lang::moneyFormat($p['price']) . ']', $admin['user_type'], $admin['id']); r2(U . 'prepaid/list', 's', $_L['Updated_Successfully']); } else { r2(U . 'prepaid/edit/' . $id, 'e', $msg); diff --git a/system/controllers/radius.php b/system/controllers/radius.php index 2cf1cf36..28404383 100644 --- a/system/controllers/radius.php +++ b/system/controllers/radius.php @@ -12,7 +12,7 @@ $admin = Admin::_info(); $ui->assign('_admin', $admin); -if ($admin['user_type'] != 'Admin') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } diff --git a/system/controllers/reports.php b/system/controllers/reports.php index 84b58792..bdf16d14 100644 --- a/system/controllers/reports.php +++ b/system/controllers/reports.php @@ -13,7 +13,7 @@ $action = $routes['1']; $admin = Admin::_info(); $ui->assign('_admin', $admin); -if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Sales'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } diff --git a/system/controllers/routers.php b/system/controllers/routers.php index 31cc4cce..8de53bb7 100644 --- a/system/controllers/routers.php +++ b/system/controllers/routers.php @@ -17,7 +17,7 @@ use PEAR2\Net\RouterOS; require_once 'system/autoload/PEAR2/Autoload.php'; -if ($admin['user_type'] != 'Admin') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } diff --git a/system/controllers/services.php b/system/controllers/services.php index 4909a9c3..1c0f4d77 100644 --- a/system/controllers/services.php +++ b/system/controllers/services.php @@ -12,7 +12,7 @@ $action = $routes['1']; $admin = Admin::_info(); $ui->assign('_admin', $admin); -if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') { +if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 307fc25c..06d1a738 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -14,7 +14,7 @@ $ui->assign('_admin', $admin); switch ($action) { case 'app': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } @@ -70,7 +70,7 @@ switch ($action) { break; case 'localisation': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } $folders = []; @@ -89,7 +89,7 @@ switch ($action) { break; case 'users': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } @@ -111,7 +111,7 @@ switch ($action) { break; case 'users-add': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } run_hook('view_add_admin'); #HOOK @@ -119,7 +119,7 @@ switch ($action) { break; case 'users-edit': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } @@ -135,7 +135,7 @@ switch ($action) { break; case 'users-delete': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } @@ -191,7 +191,7 @@ switch ($action) { $d->save(); - _log('[' . $admin['username'] . ']: ' . $_L['account_created_successfully'], 'Admin', $admin['id']); + _log('[' . $admin['username'] . ']: ' . $_L['account_created_successfully'], $admin['user_type'], $admin['id']); r2(U . 'settings/users', 's', $_L['account_created_successfully']); } else { r2(U . 'settings/users-add', 'e', $msg); @@ -249,7 +249,7 @@ switch ($action) { $d->save(); - _log('[' . $admin['username'] . ']: ' . $_L['User_Updated_Successfully'], 'Admin', $admin['id']); + _log('[' . $admin['username'] . ']: ' . $_L['User_Updated_Successfully'], $admin['user_type'], $admin['id']); r2(U . 'settings/users', 's', 'User Updated Successfully'); } else { r2(U . 'settings/users-edit/' . $id, 'e', $msg); @@ -316,7 +316,7 @@ switch ($action) { } } - _log('[' . $admin['username'] . ']: ' . $_L['Settings_Saved_Successfully'], 'Admin', $admin['id']); + _log('[' . $admin['username'] . ']: ' . $_L['Settings_Saved_Successfully'], $admin['user_type'], $admin['id']); r2(U . 'settings/app', 's', $_L['Settings_Saved_Successfully']); } @@ -404,13 +404,13 @@ switch ($action) { $d->value = $lan; $d->save(); - _log('[' . $admin['username'] . ']: ' . $_L['Settings_Saved_Successfully'], 'Admin', $admin['id']); + _log('[' . $admin['username'] . ']: ' . $_L['Settings_Saved_Successfully'], $admin['user_type'], $admin['id']); r2(U . 'settings/localisation', 's', $_L['Settings_Saved_Successfully']); } break; case 'change-password': - if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } run_hook('view_change_password'); #HOOK @@ -439,7 +439,7 @@ switch ($action) { $d->save(); _msglog('s', $_L['Password_Changed_Successfully']); - _log('[' . $admin['username'] . ']: Password changed successfully', 'Admin', $admin['id']); + _log('[' . $admin['username'] . ']: Password changed successfully', $admin['user_type'], $admin['id']); r2(U . 'admin'); } else { @@ -454,7 +454,7 @@ switch ($action) { break; case 'notifications': - if ($admin['user_type'] != 'Admin' and $admin['user_type'] != 'Sales') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } run_hook('view_notifications'); #HOOK @@ -471,7 +471,7 @@ switch ($action) { r2(U . 'settings/notifications', 's', $_L['Settings_Saved_Successfully']); break; case 'dbstatus': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } @@ -489,7 +489,7 @@ switch ($action) { break; case 'dbbackup': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } $tables = $_POST['tables']; @@ -509,7 +509,7 @@ switch ($action) { echo json_encode($array); break; case 'dbrestore': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } if (file_exists($_FILES['json']['tmp_name'])) { @@ -539,7 +539,7 @@ switch ($action) { } break; case 'language': - if ($admin['user_type'] != 'Admin') { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', $_L['Do_Not_Access']); } run_hook('view_add_language'); #HOOK diff --git a/system/updates.json b/system/updates.json index ee2a1101..7de40cdf 100644 --- a/system/updates.json +++ b/system/updates.json @@ -45,5 +45,8 @@ "2024.2.7": [ "ALTER TABLE `tbl_voucher` ADD `generated_by` INT NOT NULL DEFAULT '0' COMMENT 'id admin' AFTER `status`;", "ALTER TABLE `tbl_users` ADD `root` INT NOT NULL DEFAULT '0' COMMENT 'for sub account' AFTER `id`;" + ], + "2024.2.12": [ + "ALTER TABLE `tbl_users` CHANGE `user_type` `user_type` ENUM('SuperAdmin','Admin','Report','Agent','Sales') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;" ] } \ No newline at end of file diff --git a/ui/ui/users-add.tpl b/ui/ui/users-add.tpl index 7259ddf8..2083f414 100644 --- a/ui/ui/users-add.tpl +++ b/ui/ui/users-add.tpl @@ -24,8 +24,11 @@