Skip to content

Commit 9b553bd

Browse files
committed
improv. fix ban controller
1 parent 92ce8b7 commit 9b553bd

2 files changed

Lines changed: 87 additions & 8 deletions

File tree

app/Controller/BanController.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ function admin_index()
1717

1818
$this->set('title_for_layout', $this->Lang->get("BAN__HOME"));
1919
$this->layout = 'admin';
20-
20+
$this->loadModel("user");
2121
$this->loadModel("Ban");
22-
$this->loadModel("User");
2322
$banned_users = $this->Ban->find("all");
2423

2524
$users = $this->User->find("all");
@@ -34,6 +33,7 @@ function admin_add()
3433

3534
$this->set('title_for_layout', $this->Lang->get("BAN__HOME"));
3635
$this->layout = 'admin';
36+
$this->set('type', $this->Configuration->getKey('member_page_type'));
3737

3838
if ($this->request->is("post")) {
3939
$this->autoRender = false;
@@ -79,12 +79,11 @@ public function admin_get_users_not_ban()
7979
0 => ['label' => 'success', 'name' => $this->Lang->get('USER__RANK_MEMBER')],
8080
2 => ['label' => 'warning', 'name' => $this->Lang->get('USER__RANK_MODERATOR')],
8181
3 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')],
82-
4 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')],
83-
5 => ['label' => 'primary', 'name' => $this->Lang->get('USER__RANK_BANNED')]
82+
4 => ['label' => 'danger', 'name' => $this->Lang->get('USER__RANK_ADMINISTRATOR')]
8483
];
8584
$this->loadModel('Rank');
8685
$custom_ranks = $this->Rank->find('all');
87-
foreach ($custom_ranks as $value) {
86+
foreach ($custom_ranks as $key => $value) {
8887
$available_ranks[$value['Rank']['rank_id']] = [
8988
'label' => 'info',
9089
'name' => $value['Rank']['name']
@@ -100,7 +99,7 @@ public function admin_get_users_not_ban()
10099
$response = $this->DataTable->getResponse();
101100
$users = $response['aaData'];
102101
$data = [];
103-
foreach ($users as $value) {
102+
foreach ($users as $key => $value) {
104103
$checkIsBan = $this->Ban->find('first', ["conditions" => ['user_id' => $value['User']['id']]]);
105104

106105
if ($checkIsBan != null)
@@ -127,4 +126,33 @@ public function admin_get_users_not_ban()
127126
}
128127
}
129128
}
129+
130+
function admin_liveSearch($query = false)
131+
{
132+
$this->autoRender = false;
133+
$this->response->type('json');
134+
if ($this->isConnected and $this->Permissions->can('MANAGE_USERS')) {
135+
$this->loadModel("User");
136+
if ($query != false) {
137+
$result = $this->User->find('all', ['conditions' => ['pseudo LIKE' => $query . '%']]);
138+
foreach ($result as $key => $value) {
139+
$checkIsBan = $this->Ban->find('first', ["conditions" => ['user_id' => $value['User']['id']]]);
140+
141+
if ($checkIsBan != null)
142+
continue;
143+
144+
if ($this->Permissions->have($value['User']['rank'], "CAN_BE_BAN"))
145+
continue;
146+
147+
$users[] = ['pseudo' => $value['User']['pseudo'], 'id' => $value['User']['id']];
148+
}
149+
$response = (empty($result)) ? ['status' => false] : ['status' => true, 'data' => $users];
150+
$this->response->body($response);
151+
} else {
152+
$this->response->body(json_encode(['status' => false]));
153+
}
154+
} else {
155+
$this->response->body(json_encode(['status' => false]));
156+
}
157+
}
130158
}

app/View/Ban/admin_add.ctp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<div class="form-group">
2424
<label><?= $Lang->get('BAN__REASON') ?></label>
2525
<input type="text" class="form-control"
26-
value="<?= $page['title'] ?>"
2726
name="reason">
2827
</div>
2928
</div>
@@ -40,6 +39,7 @@
4039
</div>
4140
</section>
4241
<script type="text/javascript">
42+
<?php if($type == '0') { ?>
4343
$(document).ready(function () {
4444
$('#users').DataTable({
4545
"paging": true,
@@ -53,10 +53,61 @@
5353
"bServerSide": true,
5454
"sAjaxSource": "<?= $this->Html->url(['action' => 'get_users_not_ban']) ?>",
5555
"aoColumns": [
56-
{mData: "User.ban", "bSearchable": true},
56+
{mData: "User.ban", "bSearchable": false},
5757
{mData: "User.pseudo", "bSearchable": true},
5858
{mData: "User.rank", "bSearchable": false}
5959
]
6060
});
6161
});
62+
<?php } else { ?>
63+
$('form[method="search"]').each(function (e) {
64+
65+
$(this).on('submit', function (e) {
66+
e.preventDefault();
67+
var val = $(this).find('input[name="search"]').val();
68+
window.location = '<?= $this->Html->url(['action' => 'edit']) ?>/' + val;
69+
});
70+
71+
var url = $(this).attr('action');
72+
var form = $(this);
73+
74+
$(this).find('input[name="search"]').keyup(function (e) {
75+
76+
var value = $(this).val();
77+
78+
$.ajax({
79+
url: url + '/' + encodeURI(value),
80+
method: 'GET',
81+
dataType: 'JSON',
82+
success: function (data) {
83+
84+
form.find('.list-group').empty();
85+
86+
if (data.status) {
87+
88+
var users = data.data;
89+
90+
for (var i = 0; i < users.length; i++) {
91+
92+
console.log(users[i]);
93+
94+
form.find('.list-group').prepend('<a href="<?= $this->Html->url(['action' => 'edit']) ?>/' + users[i]['id'] + '" class="list-group-item">' + users[i]['pseudo'] + '</a>')
95+
96+
}
97+
98+
form.find('.list-group').slideDown(250);
99+
100+
} else {
101+
form.find('.list-group').slideUp(250);
102+
}
103+
104+
},
105+
error: function (data) {
106+
form.find('.list-group').slideUp(250);
107+
}
108+
})
109+
110+
});
111+
});
112+
<?php } ?>
62113
</script>

0 commit comments

Comments
 (0)