2023-07-26 18:19:46 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
|
|
|
use RuntimeException;
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(!$msz->isLoggedIn() || !perms_check_user(MSZ_PERMS_USER, $msz->getActiveUser()->getId(), MSZ_PERM_USER_MANAGE_BANS)) {
|
2023-07-26 18:19:46 +00:00
|
|
|
echo render_error(403);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
$users = $msz->getUsers();
|
|
|
|
|
2023-07-26 18:19:46 +00:00
|
|
|
$userInfos = [
|
2023-08-02 22:12:47 +00:00
|
|
|
$msz->getActiveUser()->getId() => $msz->getActiveUser(),
|
|
|
|
];
|
|
|
|
$userColours = [
|
|
|
|
$msz->getActiveUser()->getId() => $users->getUserColour($msz->getActiveUser()),
|
2023-07-26 18:19:46 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
$filterUser = null;
|
|
|
|
if(filter_has_var(INPUT_GET, 'u')) {
|
2023-08-02 22:12:47 +00:00
|
|
|
$filterUserId = filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT);
|
2023-07-26 18:19:46 +00:00
|
|
|
try {
|
2023-08-02 22:12:47 +00:00
|
|
|
$filterUser = $users->getUser($filterUserId, 'id');
|
|
|
|
$userInfos[$filterUserId] = $filterUser;
|
|
|
|
$userColours[$filterUserId] = $users->getUserColour($filterUser);
|
2023-07-26 18:19:46 +00:00
|
|
|
} catch(RuntimeException $ex) {
|
|
|
|
echo render_error(404);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$bans = $msz->getBans();
|
|
|
|
$pagination = new Pagination($bans->countBans(userInfo: $filterUser), 10);
|
|
|
|
|
|
|
|
if(!$pagination->hasValidOffset()) {
|
|
|
|
echo render_error(404);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$banList = [];
|
|
|
|
$banInfos = $bans->getBans(userInfo: $filterUser, activeFirst: true, pagination: $pagination);
|
|
|
|
|
|
|
|
foreach($banInfos as $banInfo) {
|
|
|
|
if(array_key_exists($banInfo->getUserId(), $userInfos))
|
|
|
|
$userInfo = $userInfos[$banInfo->getUserId()];
|
|
|
|
else
|
2023-08-02 22:12:47 +00:00
|
|
|
$userInfos[$banInfo->getUserId()] = $userInfo = $users->getUser($banInfo->getUserId(), 'id');
|
2023-07-26 18:19:46 +00:00
|
|
|
|
2023-08-02 22:12:47 +00:00
|
|
|
if(array_key_exists($userInfo->getId(), $userColours))
|
|
|
|
$userColour = $userColours[$userInfo->getId()];
|
2023-07-26 18:19:46 +00:00
|
|
|
else
|
2023-08-02 22:12:47 +00:00
|
|
|
$userColours[$userInfo->getId()] = $userColour = $users->getUserColour($userInfo);
|
|
|
|
|
|
|
|
if(!$banInfo->hasModId()) {
|
|
|
|
$modInfo = null;
|
|
|
|
$modColour = null;
|
|
|
|
} else {
|
|
|
|
if(array_key_exists($banInfo->getModId(), $userInfos))
|
|
|
|
$modInfo = $userInfos[$banInfo->getModId()];
|
|
|
|
else
|
|
|
|
$userInfos[$banInfo->getModId()] = $modInfo = $users->getUser($banInfo->getModId(), 'id');
|
|
|
|
|
|
|
|
if(array_key_exists($modInfo->getId(), $userColours))
|
|
|
|
$modColour = $userColours[$modInfo->getId()];
|
|
|
|
else
|
|
|
|
$userColours[$modInfo->getId()] = $modColour = $users->getUserColour($modInfo);
|
|
|
|
}
|
2023-07-26 18:19:46 +00:00
|
|
|
|
|
|
|
$banList[] = [
|
|
|
|
'info' => $banInfo,
|
|
|
|
'user' => $userInfo,
|
2023-08-02 22:12:47 +00:00
|
|
|
'user_colour' => $userColour,
|
2023-07-26 18:19:46 +00:00
|
|
|
'mod' => $modInfo,
|
2023-08-02 22:12:47 +00:00
|
|
|
'mod_colour' => $modColour,
|
2023-07-26 18:19:46 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
Template::render('manage.users.bans', [
|
|
|
|
'manage_bans' => $banList,
|
|
|
|
'manage_bans_pagination' => $pagination,
|
|
|
|
'manage_bans_filter_user' => $filterUser,
|
|
|
|
]);
|