diff --git a/admin/admin_user_ban.php b/admin/admin_user_ban.php
index 3053536e1..742c753a6 100644
--- a/admin/admin_user_ban.php
+++ b/admin/admin_user_ban.php
@@ -14,48 +14,36 @@ if (!empty($setmodules)) {
require __DIR__ . '/pagestart.php';
+// Get bans info from datastore
+if (!$bans = $datastore->get('ban_list')) {
+ $datastore->update('ban_list');
+ $bans = $datastore->get('ban_list');
+}
+
if (isset($_POST['submit'])) {
- $user_list = [];
+ // Ban action
if (!empty($_POST['username'])) {
if (!$this_userdata = get_userdata($_POST['username'], true)) {
bb_die($lang['NO_USER_ID_SPECIFIED']);
}
- $user_list[] = $this_userdata['user_id'];
- }
-
- $sql = 'SELECT * FROM ' . BB_BANLIST;
- if (!($result = DB()->sql_query($sql))) {
- bb_die('Could not obtain banlist information');
- }
-
- $current_banlist = DB()->sql_fetchrowset($result);
- DB()->sql_freeresult($result);
-
- for ($i = 0, $iMax = count($user_list); $i < $iMax; $i++) {
- $in_banlist = false;
- for ($j = 0, $jMax = count($current_banlist); $j < $jMax; $j++) {
- if ($user_list[$i] == $current_banlist[$j]['ban_userid']) {
- $in_banlist = true;
- }
- }
-
- if (!$in_banlist) {
- $sql = 'INSERT INTO ' . BB_BANLIST . ' (ban_userid) VALUES (' . $user_list[$i] . ')';
+ if (!array_key_exists($this_userdata['user_id'], $bans)) {
+ $sql = 'INSERT INTO ' . BB_BANLIST . ' (ban_userid) VALUES (' . $this_userdata['user_id'] . ')';
if (!DB()->sql_query($sql)) {
bb_die('Could not insert ban_userid info into database');
}
}
}
+ // Unban action
$where_sql = '';
- if (isset($_POST['unban_user'])) {
+ if (!empty($_POST['unban_user'])) {
$user_list = $_POST['unban_user'];
for ($i = 0, $iMax = count($user_list); $i < $iMax; $i++) {
if ($user_list[$i] != -1) {
- $where_sql = (int)$user_list[$i];
+ $where_sql .= (($where_sql != '') ? ', ' : '') . (int)$user_list[$i];
}
}
@@ -71,25 +59,10 @@ if (isset($_POST['submit'])) {
bb_die($lang['BAN_UPDATE_SUCESSFUL'] . '
' . sprintf($lang['CLICK_RETURN_BANADMIN'], '', '') . '
' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '', ''));
} else {
$template->assign_vars(['S_BANLIST_ACTION' => 'admin_user_ban.php']);
- $userban_count = 0;
-
- $sql = 'SELECT b.ban_id, u.user_id, u.username
- FROM ' . BB_BANLIST . ' b, ' . BB_USERS . ' u
- WHERE u.user_id = b.ban_userid
- AND b.ban_userid <> 0
- AND u.user_id <> ' . GUEST_UID . '
- ORDER BY u.username ASC';
- if (!($result = DB()->sql_query($sql))) {
- bb_die('Could not select current user_id ban list');
- }
-
- $user_list = DB()->sql_fetchrowset($result);
- DB()->sql_freeresult($result);
$select_userlist = '';
- for ($i = 0, $iMax = count($user_list); $i < $iMax; $i++) {
- $select_userlist .= '';
- $userban_count++;
+ foreach ($bans as $ban) {
+ $select_userlist .= '';
}
if ($select_userlist == '') {