Minor improvements (#1271)

* Minor improvements

* Update admin_user_ban.php
This commit is contained in:
Roman Kelesidis 2023-12-27 01:02:05 +07:00 committed by GitHub
commit edc365b487
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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'] . '<br /><br />' . sprintf($lang['CLICK_RETURN_BANADMIN'], '<a href="admin_user_ban.php">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'));
} 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 .= '<option value="' . $user_list[$i]['ban_id'] . '">' . $user_list[$i]['username'] . '</option>';
$userban_count++;
foreach ($bans as $ban) {
$select_userlist .= '<option value="' . $ban['ban_id'] . '">' . get_username($ban['ban_userid']) . '</option>';
}
if ($select_userlist == '') {