diff --git a/app/Controller/BanController.php b/app/Controller/BanController.php index d7718f80..de4d42d8 100644 --- a/app/Controller/BanController.php +++ b/app/Controller/BanController.php @@ -17,9 +17,8 @@ function admin_index() $this->set('title_for_layout', $this->Lang->get("BAN__HOME")); $this->layout = 'admin'; - + $this->loadModel("user"); $this->loadModel("Ban"); - $this->loadModel("User"); $banned_users = $this->Ban->find("all"); $users = $this->User->find("all"); @@ -34,6 +33,7 @@ function admin_add() $this->set('title_for_layout', $this->Lang->get("BAN__HOME")); $this->layout = 'admin'; + $this->set('type', $this->Configuration->getKey('member_page_type')); if ($this->request->is("post")) { $this->autoRender = false; @@ -79,12 +79,11 @@ public function admin_get_users_not_ban() 0 => ['label' => 'success', 'name' => $this->Lang->get('USER__RANK_MEMBER')], 2 => ['label' => 'warning', 'name' => $this->Lang->get('USER__RANK_MODERATOR')], 3 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')], - 4 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')], - 5 => ['label' => 'primary', 'name' => $this->Lang->get('USER__RANK_BANNED')] + 4 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')] ]; $this->loadModel('Rank'); $custom_ranks = $this->Rank->find('all'); - foreach ($custom_ranks as $value) { + foreach ($custom_ranks as $key => $value) { $available_ranks[$value['Rank']['rank_id']] = [ 'label' => 'info', 'name' => $value['Rank']['name'] @@ -100,7 +99,7 @@ public function admin_get_users_not_ban() $response = $this->DataTable->getResponse(); $users = $response['aaData']; $data = []; - foreach ($users as $value) { + foreach ($users as $key => $value) { $checkIsBan = $this->Ban->find('first', ["conditions" => ['user_id' => $value['User']['id']]]); if ($checkIsBan != null) @@ -127,4 +126,33 @@ public function admin_get_users_not_ban() } } } + + function admin_liveSearch($query = false) + { + $this->autoRender = false; + $this->response->type('json'); + if ($this->isConnected and $this->Permissions->can('MANAGE_USERS')) { + $this->loadModel("User"); + if ($query != false) { + $result = $this->User->find('all', ['conditions' => ['pseudo LIKE' => $query . '%']]); + foreach ($result as $key => $value) { + $checkIsBan = $this->Ban->find('first', ["conditions" => ['user_id' => $value['User']['id']]]); + + if ($checkIsBan != null) + continue; + + if ($this->Permissions->have($value['User']['rank'], "CAN_BE_BAN")) + continue; + + $users[] = ['pseudo' => $value['User']['pseudo'], 'id' => $value['User']['id']]; + } + $response = (empty($result)) ? ['status' => false] : ['status' => true, 'data' => $users]; + $this->response->body($response); + } else { + $this->response->body(json_encode(['status' => false])); + } + } else { + $this->response->body(json_encode(['status' => false])); + } + } } diff --git a/app/View/Ban/admin_add.ctp b/app/View/Ban/admin_add.ctp index ab43a4c5..a54b57cc 100644 --- a/app/View/Ban/admin_add.ctp +++ b/app/View/Ban/admin_add.ctp @@ -23,7 +23,6 @@
@@ -40,6 +39,7 @@