Repositories | Polyback | Log in to see private repositories


polyback-website / 32de824ed1c6d1185126d78087d2c781572f8c28 / directory_admin/abuse-reports.php

4,676 bytes | parent directory

<?php require $_SERVER['DOCUMENT_ROOT'].'/api/private/core.php';

// In-game abuse reports for moderators: who reported whom, why, and the game's recent chat.

use pizzaboxer\ProjectPolygon\Database;
use pizzaboxer\ProjectPolygon\Users;
use pizzaboxer\ProjectPolygon\PageBuilder;

Users::RequireAdmin([Users::STAFF_MODERATOR, Users::STAFF_ADMINISTRATOR]);

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["handle"]))
{
	if (!is_string($_POST["polygon_csrf"] ?? null) || !hash_equals((string) SESSION["csrfToken"], $_POST["polygon_csrf"])) die(http_response_code(403));
	Database::singleton()->run(
		"UPDATE AbuseReports SET HandledBy = :a, HandledAt = UNIX_TIMESTAMP() WHERE ID = :id AND HandledBy IS NULL",
		[":a" => SESSION["user"]["id"], ":id" => (int) $_POST["handle"]]
	);
	Users::LogStaffAction("[ User Moderation ] " . SESSION["user"]["username"] . " marked abuse report #" . (int) $_POST["handle"] . " as handled.");
	header("Location: /admin/abuse-reports" . (isset($_GET["Show"]) ? "?Show=" . urlencode($_GET["Show"]) : ""));
	die();
}

$show = ($_GET["Show"] ?? "Open") === "All" ? "All" : "Open";
$where = $show == "Open" ? "WHERE HandledBy IS NULL" : "";
$page = max(1, (int) ($_GET["Page"] ?? 1));
$count = Database::singleton()->run("SELECT COUNT(*) FROM AbuseReports $where")->fetchColumn();
$pages = max(1, ceil($count / 15));
$page = min($page, $pages);
$offset = ($page - 1) * 15;
$reports = Database::singleton()->run("SELECT * FROM AbuseReports $where ORDER BY ID DESC LIMIT 15 OFFSET $offset");

$pageBuilder = new PageBuilder(["title" => "Abuse Reports"]);
$pageBuilder->buildHeader();
?>
<div class="row mb-2">
	<div class="col"><h3 class="font-weight-normal">Abuse Reports</h3></div>
	<div class="col-auto">
		<a class="btn btn-sm <?=$show == "Open" ? "btn-primary" : "btn-light"?>" href="?Show=Open">Open</a>
		<a class="btn btn-sm <?=$show == "All" ? "btn-primary" : "btn-light"?>" href="?Show=All">All</a>
	</div>
</div>
<?php if ($count == 0) { ?><p class="text-muted">No <?=$show == "Open" ? "open " : ""?>reports.</p><?php } ?>
<?php while ($r = $reports->fetch(\PDO::FETCH_OBJ)) { $chat = json_decode($r->ChatLog, true) ?: []; ?>
<div class="card mb-3">
	<div class="card-body">
		<div class="d-flex justify-content-between">
			<div>
				<b>#<?=$r->ID?></b>
				<a href="/user?ID=<?=$r->ReporterID?>"><?=htmlspecialchars(Users::GetNameFromID($r->ReporterID))?></a>
				reported
				<?php if ($r->TargetID) { ?><a href="/user?ID=<?=$r->TargetID?>"><?=htmlspecialchars(Users::GetNameFromID($r->TargetID))?></a><?php } else { ?>the game<?php } ?>
				for <b><?=htmlspecialchars($r->Reason)?></b>
				<?php if ($r->PlaceID) { ?>in <a href="/placeitem?id=<?=$r->PlaceID?>">place <?=$r->PlaceID?></a><?php } ?>
				<span class="text-muted" title="<?=date('j/n/Y g:i:s A \G\M\T', $r->Created)?>"><?=GetReadableTime($r->Created)?></span>
			</div>
			<div>
				<?php if ($r->HandledBy) { ?>
				<span class="text-muted">Handled by <?=htmlspecialchars(Users::GetNameFromID($r->HandledBy))?></span>
				<?php } else { ?>
				<form method="post" class="d-inline">
					<input type="hidden" name="handle" value="<?=$r->ID?>">
					<input type="hidden" name="polygon_csrf" value="<?=SESSION["csrfToken"]?>">
					<button class="btn btn-sm btn-success">Mark handled</button>
				</form>
				<?php if ($r->TargetID) { ?><a class="btn btn-sm btn-outline-danger" href="/admin/moderate-user?username=<?=urlencode(Users::GetNameFromID($r->TargetID))?>">Moderate</a><?php } ?>
				<?php } ?>
			</div>
		</div>
		<?php if ($r->Comment !== "") { ?><p class="mt-2 mb-2"><?=nl2br(htmlspecialchars($r->Comment))?></p><?php } ?>
		<?php if (count($chat)) { ?>
		<details class="mt-2"><summary>Chat before the report (<?=count($chat)?> messages)</summary>
			<div class="small mt-1" style="max-height:240px;overflow:auto">
			<?php foreach ($chat as $line) { ?>
				<div<?=$r->TargetID && $line["userId"] == $r->TargetID ? ' class="text-danger"' : ''?>><b><?=htmlspecialchars($line["name"])?>:</b> <?=htmlspecialchars($line["text"])?></div>
			<?php } ?>
			</div>
		</details>
		<?php } ?>
	</div>
</div>
<?php } ?>
<?php if ($pages > 1) { ?>
<div class="pagination form-inline justify-content-center">
	<a class="btn btn-light<?=$page <= 1 ? ' disabled' : '" href="?Show=' . $show . '&Page=' . ($page - 1)?>"><h5 class="mb-0"><i class="fal fa-caret-left"></i></h5></a>
	<span class="px-3">Page <?=$page?> of <?=$pages?></span>
	<a class="btn btn-light<?=$page >= $pages ? ' disabled' : '" href="?Show=' . $show . '&Page=' . ($page + 1)?>"><h5 class="mb-0"><i class="fal fa-caret-right"></i></h5></a>
</div>
<?php } ?>
<?php $pageBuilder->buildFooter(); ?>