diff --git a/install/phpnuxbill.sql b/install/phpnuxbill.sql index 58d96ec7..b598b2b5 100644 --- a/install/phpnuxbill.sql +++ b/install/phpnuxbill.sql @@ -191,6 +191,8 @@ 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_users` CHANGE `password` `password` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL; +ALTER TABLE `tbl_users` ADD `phone` VARCHAR(32) NOT NULL DEFAULT '' AFTER `password`, ADD `email` VARCHAR(128) NOT NULL DEFAULT '' AFTER `phone`, ADD `city` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kota' AFTER `email`, ADD `subdistrict` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kecamatan' AFTER `city`, ADD `ward` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kelurahan' AFTER `subdistrict`; ALTER TABLE `tbl_appconfig` ADD PRIMARY KEY (`id`); @@ -309,7 +311,7 @@ VALUES ( 'admin', 'Administrator', 'd033e22ae348aeb5660fc2140aec35850c4da997', - 'Admin', + 'SuperAdmin', 'Active', '2022-09-06 16:09:50', '2014-06-23 01:43:07' diff --git a/system/autoload/Lang.php b/system/autoload/Lang.php index 70e2991e..a549a244 100644 --- a/system/autoload/Lang.php +++ b/system/autoload/Lang.php @@ -192,7 +192,7 @@ class Lang curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; CPU OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/28.1 Mobile/15E148 Safari/605.1.15"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); - curl_setopt($ch, CURLOPT_TIMEOUT, 60); + curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt ($ch, CURLOPT_HEADER, 0); $hasil = curl_exec ($ch); curl_close($ch); diff --git a/system/controllers/dashboard.php b/system/controllers/dashboard.php index a55d682c..c6b4da90 100644 --- a/system/controllers/dashboard.php +++ b/system/controllers/dashboard.php @@ -9,9 +9,6 @@ _admin(); $ui->assign('_title', Lang::T('Dashboard')); $admin = Admin::_info(); $ui->assign('_admin', $admin); -if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - r2(U . "home", 'e', Lang::T('You do not have permission to access this page')); -} $fdate = date('Y-m-01'); $tdate = date('Y-m-t'); diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 30add689..c99b9dee 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -76,7 +76,7 @@ switch ($action) { $folders = []; $files = scandir('system/lan/'); foreach ($files as $file) { - if (is_file('system/lan/' . $file) && !in_array($file, ['index.html', 'country.json','.DS_Store'])) { + if (is_file('system/lan/' . $file) && !in_array($file, ['index.html', 'country.json', '.DS_Store'])) { $file = str_replace(".json", "", $file); $folders[$file] = ''; } @@ -84,7 +84,7 @@ switch ($action) { $ui->assign('lani', $folders); $lans = Lang::getIsoLang(); foreach ($lans as $lan => $val) { - if(isset($folders[$lan])){ + if (isset($folders[$lan])) { unset($lans[$lan]); } } @@ -97,19 +97,56 @@ switch ($action) { break; case 'users': - if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent'])) { r2(U . "dashboard", 'e', Lang::T('You do not have permission to access this page')); } - - $ui->assign('xfooter', ''); - $username = _post('username'); if ($username != '') { - $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $username . '%'], $username); - $d = ORM::for_table('tbl_users')->where_like('username', '%' . $username . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); + if ($admin['user_type'] == 'SuperAdmin') { + $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $username . '%'], $username); + $d = ORM::for_table('tbl_users') + ->where_like('username', '%' . $username . '%') + ->offset($paginator['startpoint']) + ->limit($paginator['limit'])->order_by_asc('id')->find_many(); + } else if ($admin['user_type'] == 'Admin') { + $paginator = Paginator::build(ORM::for_table('tbl_users'), [ + 'username' => '%' . $username . '%', + ['user_type' => 'Report'], + ['user_type' => 'Agent'], + ['user_type' => 'Sales'] + ], $username); + $d = ORM::for_table('tbl_users') + ->where_like('username', '%' . $username . '%') + ->where_any_is([ + ['user_type' => 'Report'], + ['user_type' => 'Agent'], + ['user_type' => 'Sales'] + ]) + ->offset($paginator['startpoint']) + ->limit($paginator['limit'])->order_by_asc('id')->find_many(); + } else { + $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $username . '%'], $username); + $d = ORM::for_table('tbl_users') + ->where_like('username', '%' . $username . '%') + ->where('root', $admin['id']) + ->offset($paginator['startpoint']) + ->limit($paginator['limit'])->order_by_asc('id')->find_many(); + } } else { - $paginator = Paginator::build(ORM::for_table('tbl_users')); - $d = ORM::for_table('tbl_users')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); + if ($admin['user_type'] == 'SuperAdmin') { + $paginator = Paginator::build(ORM::for_table('tbl_users')); + $d = ORM::for_table('tbl_users')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); + } else if ($admin['user_type'] == 'Admin') { + $paginator = Paginator::build(ORM::for_table('tbl_users')); + $d = ORM::for_table('tbl_users')->where_any_is([ + ['user_type' => 'Report'], + ['user_type' => 'Agent'], + ['user_type' => 'Sales'] + ])->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); + } else { + $paginator = Paginator::build(ORM::for_table('tbl_users')); + $d = ORM::for_table('tbl_users')->where('root', $admin['id'])->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); + } } $ui->assign('d', $d); @@ -119,21 +156,36 @@ switch ($action) { break; case 'users-add': - if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent'])) { r2(U . "dashboard", 'e', Lang::T('You do not have permission to access this page')); } - run_hook('view_add_admin'); #HOOK + $ui->assign('_title', Lang::T('Add User')); $ui->display('users-add.tpl'); break; case 'users-edit': - if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent'])) { r2(U . "dashboard", 'e', Lang::T('You do not have permission to access this page')); } - + $ui->assign('_title', Lang::T('Edit User')); $id = $routes['2']; - $d = ORM::for_table('tbl_users')->find_one($id); + if ($admin['id'] == $id) { + $d = ORM::for_table('tbl_users')->find_one($id); + } else { + if ($admin['user_type'] == 'SuperAdmin') { + $d = ORM::for_table('tbl_users')->find_one($id); + } else if ($admin['user_type'] == 'Admin') { + $d = ORM::for_table('tbl_users')->where_any_is([ + ['user_type' => 'Report'], + ['user_type' => 'Agent'], + ['user_type' => 'Sales'] + ])->find_one($id); + } else { + $d = ORM::for_table('tbl_users')->where('root', $admin['id'])->find_one($id); + } + } if ($d) { + $ui->assign('id', $id); $ui->assign('d', $d); run_hook('view_edit_admin'); #HOOK $ui->display('users-edit.tpl'); @@ -165,20 +217,22 @@ switch ($action) { $username = _post('username'); $fullname = _post('fullname'); $password = _post('password'); - $cpassword = _post('cpassword'); $user_type = _post('user_type'); + $phone = _post('phone'); + $email = _post('email'); + $city = _post('city'); + $subdistrict = _post('subdistrict'); + $ward = _post('ward'); + $send_notif = _post('send_notif'); $msg = ''; - if (Validator::Length($username, 16, 2) == false) { - $msg .= 'Username should be between 3 to 15 characters' . '
'; + if (Validator::Length($username, 45, 2) == false) { + $msg .= Lang::T('Username should be between 3 to 45 characters') . '
'; } - if (Validator::Length($fullname, 26, 2) == false) { - $msg .= 'Full Name should be between 3 to 25 characters' . '
'; + if (Validator::Length($fullname, 45, 2) == false) { + $msg .= Lang::T('Full Name should be between 3 to 45 characters') . '
'; } - if (!Validator::Length($password, 15, 5)) { - $msg .= 'Password should be between 6 to 15 characters' . '
'; - } - if ($password != $cpassword) { - $msg .= 'Passwords does not match' . '
'; + if (!Validator::Length($password, 1000, 5)) { + $msg .= Lang::T('Password should be minimum 6 characters') . '
'; } $d = ORM::for_table('tbl_users')->where('username', $username)->find_one(); @@ -194,12 +248,22 @@ switch ($action) { $d->fullname = $fullname; $d->password = $password; $d->user_type = $user_type; + $d->phone = $phone; + $d->email = $email; + $d->city = $city; + $d->subdistrict = $subdistrict; + $d->ward = $ward; $d->status = 'Active'; $d->creationdate = $date_now; - $d->save(); - _log('[' . $admin['username'] . ']: ' . Lang::T('Account Created Successfully'), $admin['user_type'], $admin['id']); + if ($send_notif == 'wa') { + Message::sendWhatsapp(Lang::phoneFormat($phone), Lang::T('Hello, Your account has been created successfully.') . "\nUsername: $username\nPassword: $password\n\n" . $config['CompanyName']); + } else if ($send_notif == 'sms') { + Message::sendSMS($phone, Lang::T('Hello, Your account has been created successfully.') . "\nUsername: $username\nPassword: $password\n\n" . $config['CompanyName']); + } + + _log('[' . $admin['username'] . ']: ' . "Created $user_type $username", $admin['user_type'], $admin['id']); r2(U . 'settings/users', 's', Lang::T('Account Created Successfully')); } else { r2(U . 'settings/users-add', 'e', $msg); @@ -211,34 +275,53 @@ switch ($action) { $fullname = _post('fullname'); $password = _post('password'); $cpassword = _post('cpassword'); - + $user_type = _post('user_type'); + $phone = _post('phone'); + $email = _post('email'); + $city = _post('city'); + $subdistrict = _post('subdistrict'); + $ward = _post('ward'); + $status = _post('status'); $msg = ''; - if (Validator::Length($username, 16, 2) == false) { - $msg .= 'Username should be between 3 to 15 characters' . '
'; + if (Validator::Length($username, 45, 2) == false) { + $msg .= Lang::T('Username should be between 3 to 45 characters') . '
'; } - if (Validator::Length($fullname, 26, 2) == false) { - $msg .= 'Full Name should be between 3 to 25 characters' . '
'; + if (Validator::Length($fullname, 45, 2) == false) { + $msg .= Lang::T('Full Name should be between 3 to 45 characters') . '
'; } if ($password != '') { - if (!Validator::Length($password, 15, 5)) { - $msg .= 'Password should be between 6 to 15 characters' . '
'; + if (!Validator::Length($password, 1000, 5)) { + $msg .= Lang::T('Password should be minimum 6 characters') . '
'; } if ($password != $cpassword) { - $msg .= 'Passwords does not match' . '
'; + $msg .= Lang::T('Passwords does not match') . '
'; } } $id = _post('id'); - $d = ORM::for_table('tbl_users')->find_one($id); - if ($d) { + if ($admin['id'] == $id) { + $d = ORM::for_table('tbl_users')->find_one($id); } else { + if ($admin['user_type'] == 'SuperAdmin') { + $d = ORM::for_table('tbl_users')->find_one($id); + } else if ($admin['user_type'] == 'Admin') { + $d = ORM::for_table('tbl_users')->where_any_is([ + ['user_type' => 'Report'], + ['user_type' => 'Agent'], + ['user_type' => 'Sales'] + ])->find_one($id); + } else { + $d = ORM::for_table('tbl_users')->where('root', $admin['id'])->find_one($id); + } + } + if (!$d) { $msg .= Lang::T('Data Not Found') . '
'; } if ($d['username'] != $username) { $c = ORM::for_table('tbl_users')->where('username', $username)->find_one(); if ($c) { - $msg .= Lang::T('Account already axist') . '
'; + $msg .= "$username ".Lang::T('Account already axist') . '
'; } } run_hook('edit_admin'); #HOOK @@ -254,10 +337,16 @@ switch ($action) { $user_type = _post('user_type'); $d->user_type = $user_type; } + $d->phone = $phone; + $d->email = $email; + $d->city = $city; + $d->subdistrict = $subdistrict; + $d->ward = $ward; + $d->status = $status; $d->save(); - _log('[' . $admin['username'] . ']: ' . Lang::T('User Updated Successfully'), $admin['user_type'], $admin['id']); + _log('[' . $admin['username'] . ']: $username ' . Lang::T('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); @@ -308,9 +397,9 @@ switch ($action) { } //checkbox - $checks = ['hide_mrc','hide_tms','hide_aui','hide_al','hide_uet','hide_vs','hide_pg']; + $checks = ['hide_mrc', 'hide_tms', 'hide_aui', 'hide_al', 'hide_uet', 'hide_vs', 'hide_pg']; foreach ($checks as $check) { - if(!isset($_POST[$check])){ + if (!isset($_POST[$check])) { $d = ORM::for_table('tbl_appconfig')->where('setting', $check)->find_one(); if ($d) { $d->value = 'no'; @@ -553,7 +642,7 @@ switch ($action) { run_hook('view_add_language'); #HOOK if (file_exists($lan_file)) { $ui->assign('langs', json_decode(file_get_contents($lan_file), true)); - }else{ + } else { $ui->assign('langs', []); } $ui->display('language-add.tpl'); diff --git a/system/lan/english.json b/system/lan/english.json index 8a34cee2..528239f5 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -393,5 +393,16 @@ "Active Users": "Active Users", "All Users Insights": "All Users Insights", "Radius": "Radius", - "Radius NAS": "Radius NAS" + "Radius NAS": "Radius NAS", + "Profile": "Profile", + "Credentials": "Credentials", + "Phone": "Phone", + "City": "City", + "Sub District": "Sub District", + "Ward": "Ward", + "Send Notification": "Send Notification", + "Add User": "Add User", + "Username should be between 3 to 45 characters": "Username should be between 3 to 45 characters", + "Password should be minimum 6 characters": "Password should be minimum 6 characters", + "Login": "Login" } \ No newline at end of file diff --git a/system/updates.json b/system/updates.json index 7de40cdf..8161740f 100644 --- a/system/updates.json +++ b/system/updates.json @@ -48,5 +48,9 @@ ], "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;" + ], + "2024.2.15":[ + "ALTER TABLE `tbl_users` CHANGE `password` `password` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;", + "ALTER TABLE `tbl_users` ADD `phone` VARCHAR(32) NOT NULL DEFAULT '' AFTER `password`, ADD `email` VARCHAR(128) NOT NULL DEFAULT '' AFTER `phone`, ADD `city` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kota' AFTER `email`, ADD `subdistrict` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kecamatan' AFTER `city`, ADD `ward` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'kelurahan' AFTER `subdistrict`;" ] } \ No newline at end of file diff --git a/ui/ui/sections/header.tpl b/ui/ui/sections/header.tpl index 08dee982..3c5d8208 100644 --- a/ui/ui/sections/header.tpl +++ b/ui/ui/sections/header.tpl @@ -84,7 +84,7 @@

{$_admin['fullname']} - {if $_admin['user_type'] eq 'Admin'} {Lang::T('Administrator')} + {if $_admin['user_type'] eq 'SuperAdmin'} {Lang::T('Administrator')} {else} {Lang::T('Sales')} {/if}

@@ -124,7 +124,7 @@ {$_MENU_AFTER_DASHBOARD} - {if $_admin['user_type'] eq 'Admin' || $_admin['user_type'] eq 'Sales'} + {if in_array($_admin['user_type'],['SuperAdmin','Admin'])}
  • {Lang::T('Customer')} @@ -204,7 +204,7 @@
  • {$_MENU_AFTER_REPORTS} {/if} - {if $_admin['user_type'] eq 'Admin'} + {if in_array($_admin['user_type'],['SuperAdmin','Admin'])}
  • {Lang::T('Network')} @@ -215,10 +215,6 @@