2023-07-26 22:43:50 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
|
|
|
use RuntimeException;
|
|
|
|
|
2024-12-02 02:28:08 +00:00
|
|
|
if(!isset($msz) || !($msz instanceof \Misuzu\MisuzuContext))
|
|
|
|
die('Script must be called through the Misuzu route dispatcher.');
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
if(!$msz->authInfo->getPerms('user')->check(Perm::U_WARNINGS_MANAGE))
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(403);
|
2023-07-26 22:43:50 +00:00
|
|
|
|
|
|
|
if($_SERVER['REQUEST_METHOD'] === 'GET' && filter_has_var(INPUT_GET, 'delete')) {
|
2023-08-31 15:59:53 +00:00
|
|
|
if(!CSRF::validateRequest())
|
|
|
|
Template::throwError(403);
|
|
|
|
|
|
|
|
try {
|
2024-11-30 04:09:29 +00:00
|
|
|
$warnInfo = $msz->usersCtx->warnings->getWarning((string)filter_input(INPUT_GET, 'w'));
|
2023-08-31 15:59:53 +00:00
|
|
|
} catch(RuntimeException $ex) {
|
|
|
|
Template::throwError(404);
|
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$msz->usersCtx->warnings->deleteWarnings($warnInfo);
|
|
|
|
$msz->createAuditLog('WARN_DELETE', [$warnInfo->id, $warnInfo->userId]);
|
|
|
|
Tools::redirect($msz->urls->format('manage-users-warnings', ['user' => $warnInfo->userId]));
|
2023-07-26 22:43:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2024-11-30 04:09:29 +00:00
|
|
|
$userInfo = $msz->usersCtx->users->getUser(filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT), 'id');
|
2023-07-26 22:43:50 +00:00
|
|
|
} catch(RuntimeException $ex) {
|
2023-08-31 15:59:53 +00:00
|
|
|
Template::throwError(404);
|
2023-07-26 22:43:50 +00:00
|
|
|
}
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$modInfo = $msz->authInfo->userInfo;
|
2023-07-26 22:43:50 +00:00
|
|
|
|
2024-12-02 21:33:15 +00:00
|
|
|
while($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
|
2023-07-26 22:43:50 +00:00
|
|
|
$body = trim((string)filter_input(INPUT_POST, 'uw_body'));
|
|
|
|
Template::set('warn_value_body', $body);
|
|
|
|
|
2024-11-30 04:09:29 +00:00
|
|
|
$warnInfo = $msz->usersCtx->warnings->createWarning(
|
2023-07-26 22:43:50 +00:00
|
|
|
$userInfo, $body, modInfo: $modInfo
|
|
|
|
);
|
|
|
|
|
2024-11-30 04:20:20 +00:00
|
|
|
$msz->createAuditLog('WARN_CREATE', [$warnInfo->id, $userInfo->id]);
|
|
|
|
Tools::redirect($msz->urls->format('manage-users-warnings', ['user' => $userInfo->id]));
|
2023-07-26 22:43:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Template::render('manage.users.warning', [
|
|
|
|
'warn_user' => $userInfo,
|
|
|
|
]);
|