misuzu/public-legacy/manage/users/warnings.php

84 lines
2.5 KiB
PHP
Raw Normal View History

2022-09-13 13:14:49 +00:00
<?php
namespace Misuzu;
use RuntimeException;
2022-09-13 13:14:49 +00:00
if(!$msz->isLoggedIn() || !perms_check_user(MSZ_PERMS_USER, $msz->getActiveUser()->getId(), MSZ_PERM_USER_MANAGE_WARNINGS)) {
2022-09-13 13:14:49 +00:00
echo render_error(403);
return;
}
$users = $msz->getUsers();
2023-07-26 22:43:50 +00:00
$userInfos = [
$msz->getActiveUser()->getId() => $msz->getActiveUser(),
];
$userColours = [
$msz->getActiveUser()->getId() => $users->getUserColour($msz->getActiveUser()),
2023-07-26 22:43:50 +00:00
];
2022-09-13 13:14:49 +00:00
2023-07-26 22:43:50 +00:00
$filterUser = null;
if(filter_has_var(INPUT_GET, 'u')) {
$filterUserId = filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT);
2022-09-13 13:14:49 +00:00
try {
$filterUser = $users->getUser($filterUserId, 'id');
$userInfos[$filterUserId] = $filterUser;
$userColours[$filterUserId] = $users->getUserColour($filterUser);
} catch(RuntimeException $ex) {
2023-07-26 22:43:50 +00:00
echo render_error(404);
return;
2022-09-13 13:14:49 +00:00
}
}
2023-07-26 22:43:50 +00:00
$warns = $msz->getWarnings();
$pagination = new Pagination($warns->countWarnings(userInfo: $filterUser), 10);
2022-09-13 13:14:49 +00:00
2023-07-26 22:43:50 +00:00
if(!$pagination->hasValidOffset()) {
2022-09-13 13:14:49 +00:00
echo render_error(404);
return;
}
2023-07-26 22:43:50 +00:00
$warnList = [];
$warnInfos = $warns->getWarnings(userInfo: $filterUser, pagination: $pagination);
foreach($warnInfos as $warnInfo) {
if(array_key_exists($warnInfo->getUserId(), $userInfos))
$userInfo = $userInfos[$warnInfo->getUserId()];
else
$userInfos[$warnInfo->getUserId()] = $userInfo = $users->getUser($warnInfo->getUserId(), 'id');
2023-07-26 22:43:50 +00:00
if(array_key_exists($userInfo->getId(), $userColours))
$userColour = $userColours[$userInfo->getId()];
2023-07-26 22:43:50 +00:00
else
$userColours[$userInfo->getId()] = $userColour = $users->getUserColour($userInfo);
if(!$warnInfo->hasModId()) {
$modInfo = null;
$modColour = null;
} else {
if(array_key_exists($warnInfo->getModId(), $userInfos))
$modInfo = $userInfos[$warnInfo->getModId()];
else
$userInfos[$warnInfo->getModId()] = $modInfo = $users->getUser($warnInfo->getModId(), 'id');
if(array_key_exists($modInfo->getId(), $userColours))
$modColour = $userColours[$modInfo->getId()];
else
$userColours[$modInfo->getId()] = $modColour = $users->getUserColour($modInfo);
}
2023-07-26 22:43:50 +00:00
$warnList[] = [
'info' => $warnInfo,
'user' => $userInfo,
'user_colour' => $userColour,
2023-07-26 22:43:50 +00:00
'mod' => $modInfo,
'mod_colour' => $modColour,
2023-07-26 22:43:50 +00:00
];
}
2022-09-13 13:14:49 +00:00
Template::render('manage.users.warnings', [
2023-07-26 22:43:50 +00:00
'manage_warns' => $warnList,
'manage_warns_pagination' => $pagination,
'manage_warns_filter_user' => $filterUser,
2022-09-13 13:14:49 +00:00
]);