From cb23ddb91243e17112b4d0b2b80dd5bf513c3b09 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 16 Feb 2024 17:25:54 +0700 Subject: [PATCH] Sales are below agent, but admin add sales not yet select Agent --- system/boot.php | 10 +++++++++ system/controllers/settings.php | 39 +++++++++++++++++++++++---------- ui/ui/users.tpl | 6 ++++- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/system/boot.php b/system/boot.php index 698dc198..f12ddc44 100644 --- a/system/boot.php +++ b/system/boot.php @@ -72,6 +72,16 @@ function _get($param, $defvalue = '') return safedata($_GET[$param]); } } + +function _req($param, $defvalue = '') +{ + if (!isset($_REQUEST[$param])) { + return $defvalue; + } else { + return safedata($_REQUEST[$param]); + } +} + try { require_once File::pathFixer('system/orm.php'); diff --git a/system/controllers/settings.php b/system/controllers/settings.php index e4c85b2c..cdb418e6 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -100,23 +100,23 @@ switch ($action) { if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Agent'])) { r2(U . "dashboard", 'e', Lang::T('You do not have permission to access this page')); } - $username = _post('username'); - if ($username != '') { + $search = _req('search'); + if ($search != '') { if ($admin['user_type'] == 'SuperAdmin') { - $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $username . '%'], $username); + $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $search . '%'], $search); $d = ORM::for_table('tbl_users') - ->where_like('username', '%' . $username . '%') + ->where_like('username', '%' . $search . '%') ->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 . '%', + 'username' => '%' . $search . '%', ['user_type' => 'Report'], ['user_type' => 'Agent'], ['user_type' => 'Sales'] - ], $username); + ], $search); $d = ORM::for_table('tbl_users') - ->where_like('username', '%' . $username . '%') + ->where_like('username', '%' . $search . '%') ->where_any_is([ ['user_type' => 'Report'], ['user_type' => 'Agent'], @@ -125,11 +125,13 @@ switch ($action) { ->offset($paginator['startpoint']) ->limit($paginator['limit'])->order_by_asc('id')->find_many(); } else { - $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $username . '%'], $username); + $paginator = Paginator::build(ORM::for_table('tbl_users'), ['username' => '%' . $search . '%'], $search); $d = ORM::for_table('tbl_users') - ->where_like('username', '%' . $username . '%') - ->where('root', $admin['id']) - ->where('id', $admin['id']) + ->where_like('username', '%' . $search . '%') + ->where_any_is([ + ['id' => $admin['id']], + ['root' => $admin['id']] + ]) ->offset($paginator['startpoint']) ->limit($paginator['limit'])->order_by_asc('id')->find_many(); } @@ -154,8 +156,23 @@ switch ($action) { ->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); } } + $admins = []; + foreach ($d as $k) { + if(!empty($k['root'])){ + $admins[] = $k['root']; + } + } + if(count($admins) > 0){ + $adms = ORM::for_table('tbl_users')->where_in('id', $admins)->find_many(); + unset($admins); + foreach($adms as $adm){ + $admins[$adm['id']] = $adm['fullname']; + } + } + $ui->assign('admins', $admins); $ui->assign('d', $d); + $ui->assign('search', $search); $ui->assign('paginator', $paginator); run_hook('view_list_admin'); #HOOK $ui->display('users.tpl'); diff --git a/ui/ui/users.tpl b/ui/ui/users.tpl index 4db65135..0969341f 100644 --- a/ui/ui/users.tpl +++ b/ui/ui/users.tpl @@ -13,7 +13,7 @@
-
@@ -37,6 +37,7 @@ {Lang::T('Email')} {Lang::T('Type')} {Lang::T('Location')} + {Lang::T('Agent')} {Lang::T('Last Login')} {Lang::T('Manage')} @@ -51,6 +52,9 @@ {$ds['email']} {$ds['user_type']} {$ds['city']}, {$ds['subdistrict']}, {$ds['ward']} + {if $ds['root']} + + {$admins[$ds['root']]}{/if} {Lang::dateTimeFormat($ds['last_login'])}