335 lines
18 KiB
PHP
335 lines
18 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
$app = app();
|
|
$pdo = $app->pdo();
|
|
$userId = $_SESSION['user_id'] ?? null;
|
|
|
|
if (!$userId) {
|
|
redirect('/login');
|
|
}
|
|
|
|
$communityCfg = require __DIR__ . '/../../../config/community.php';
|
|
$access = $pdo ? new \App\CommunityAccess($pdo, $communityCfg) : null;
|
|
$community = $pdo ? new \App\Community($pdo, $communityCfg) : null;
|
|
$migration = $pdo ? new \App\CommunityMigration($pdo) : null;
|
|
$listingCatalog = $pdo ? new \App\ListingCatalog($pdo) : null;
|
|
$communityPoints = $community ? $community->computePoints((int)$userId) : 0.0;
|
|
|
|
if (!$access || !$access->canAccessCommunityAdmin((int)$userId, $communityPoints)) {
|
|
http_response_code(403);
|
|
echo '<main class="section"><div class="container"><div class="card dash-card"><h1>Kein Zugriff</h1><p class="muted">Dieser Bereich ist nur für Community-Admins freigegeben.</p></div></div></main>';
|
|
return;
|
|
}
|
|
|
|
$error = '';
|
|
$info = '';
|
|
$canModerateForum = $access->canModerateForum((int)$userId);
|
|
$canManageApplications = $access->canManageApplications((int)$userId) && $access->supportsApplications();
|
|
$canManageRoles = $access->canManageRoles((int)$userId);
|
|
$canReviewListings = $listingCatalog !== null && $access->canReviewListings((int)$userId, $communityPoints);
|
|
$roleUserSearchQuery = trim((string)($_GET['role_user_query'] ?? ''));
|
|
$roleUserSearchResults = ($canManageRoles || $canManageApplications) && $roleUserSearchQuery !== ''
|
|
? $access->searchUsers($roleUserSearchQuery, 12)
|
|
: [];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$action = (string)($_POST['action'] ?? '');
|
|
try {
|
|
if ($action === 'listing_request_decide') {
|
|
if (!$canReviewListings || !$listingCatalog) {
|
|
throw new \RuntimeException('Keine Berechtigung für Listing-Freigaben.');
|
|
}
|
|
$listingCatalog->decideModerationRequest((int)$userId, (int)($_POST['request_id'] ?? 0), (string)($_POST['decision'] ?? ''), (string)($_POST['review_note'] ?? ''));
|
|
$info = 'Listing-Anfrage wurde bearbeitet.';
|
|
} elseif ($action === 'application_decide') {
|
|
$access->decideApplication((int)$userId, (int)($_POST['application_id'] ?? 0), (string)($_POST['decision'] ?? ''), (string)($_POST['decision_reason'] ?? ''));
|
|
$info = 'Bewerbung wurde bearbeitet.';
|
|
} elseif ($action === 'report_resolve') {
|
|
$access->resolveReport((int)$userId, (int)($_POST['report_id'] ?? 0), (string)($_POST['moderator_note'] ?? ''));
|
|
$info = 'Meldung wurde abgeschlossen.';
|
|
} elseif ($action === 'role_revoke') {
|
|
$access->revokeRole((int)$userId, (int)($_POST['target_user_id'] ?? 0), (string)($_POST['role'] ?? ''));
|
|
$info = 'Rolle wurde entzogen.';
|
|
} elseif ($action === 'role_assign') {
|
|
$access->assignRole((int)$userId, (int)($_POST['target_user_id'] ?? 0), (string)($_POST['role'] ?? ''));
|
|
$info = 'Rolle wurde vergeben.';
|
|
} elseif ($action === 'community_migrate') {
|
|
if (!$canManageApplications || !$migration) {
|
|
throw new \RuntimeException('Keine Berechtigung für die Community-Migration.');
|
|
}
|
|
$migration->apply();
|
|
$info = 'Die Community-Migration wurde ausgeführt.';
|
|
}
|
|
} catch (\Throwable $e) {
|
|
$error = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
$listingRequests = $canReviewListings && $listingCatalog ? $listingCatalog->listOpenModerationRequests() : [];
|
|
$applications = $canManageApplications ? $access->listApplications('open') : [];
|
|
$reports = $access->supportsReports() ? $access->listOpenReports() : [];
|
|
$roleAssignments = $canManageRoles ? $access->listRoleAssignments() : [];
|
|
$migrationStatus = ($migration && $canManageApplications) ? $migration->status() : null;
|
|
?>
|
|
<main class="section">
|
|
<div class="container">
|
|
<div class="forum-breadcrumbs">
|
|
<a href="/">Home</a>
|
|
<span>/</span>
|
|
<a href="/dashboard?area=admin&section=admin-home">Admin-Einstellungen</a>
|
|
<span>/</span>
|
|
<span>Community-Admin</span>
|
|
</div>
|
|
|
|
<div class="forum-hero forum-hero--compact">
|
|
<div>
|
|
<h1>Community-Admin</h1>
|
|
<p class="forum-hero__copy">Moderation, Bewerbungen und Rollen an einem Ort.</p>
|
|
</div>
|
|
<div class="forum-hero__cta">
|
|
<a class="btn ghost" href="/dashboard?area=admin&section=admin-home">Zurück zu den Admin-Einstellungen</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div class="toast-bar" style="margin-top:14px; border-color:#f87171; color:#991b1b;"><?= htmlspecialchars($error, ENT_QUOTES) ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($info): ?>
|
|
<div class="toast-bar" style="margin-top:14px;"><?= htmlspecialchars($info, ENT_QUOTES) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="forum-admin-grid">
|
|
<?php if ($canReviewListings): ?>
|
|
<section class="forum-board" id="listing-requests">
|
|
<div class="forum-board__head">
|
|
<div>
|
|
<h2>Offene Orts- und Veranstaltungsanfragen</h2>
|
|
<p class="muted">Neue Einträge sowie Änderungs- und Löschwünsche prüfen.</p>
|
|
</div>
|
|
</div>
|
|
<div class="forum-admin-list">
|
|
<?php foreach ($listingRequests as $request): ?>
|
|
<?php
|
|
$payload = is_array($request['payload'] ?? null) ? $request['payload'] : [];
|
|
$requestTypeLabel = match ((string)($request['request_type'] ?? '')) {
|
|
'create' => 'Neu',
|
|
'update' => 'Änderung',
|
|
'delete' => 'Löschung',
|
|
default => 'Anfrage',
|
|
};
|
|
?>
|
|
<article class="forum-admin-item">
|
|
<div>
|
|
<strong><?= htmlspecialchars((string)$requestTypeLabel, ENT_QUOTES) ?> · <?= htmlspecialchars((string)$request['title'], ENT_QUOTES) ?></strong>
|
|
<p class="muted small">Typ: <?= htmlspecialchars((string)(($request['listing_type'] ?? '') === 'place' ? 'Ort' : 'Veranstaltung'), ENT_QUOTES) ?> · Von <?= htmlspecialchars((string)($request['requested_by_name'] ?: 'Mitglied'), ENT_QUOTES) ?> · am <?= htmlspecialchars((string)$request['created_at'], ENT_QUOTES) ?></p>
|
|
<?php if (!empty($request['request_reason'])): ?>
|
|
<p><strong>Begründung:</strong><br><?= nl2br(htmlspecialchars((string)$request['request_reason'], ENT_QUOTES)) ?></p>
|
|
<?php endif; ?>
|
|
<p class="muted small">
|
|
<?= htmlspecialchars(trim(implode(' · ', array_filter([
|
|
trim(implode(', ', array_filter([
|
|
(string)($request['street'] ?? ''),
|
|
trim((string)($request['zip'] ?? '') . ' ' . (string)($request['city'] ?? '')),
|
|
]))),
|
|
(string)($request['region'] ?? ''),
|
|
]))), ENT_QUOTES) ?>
|
|
</p>
|
|
<?php if ($payload !== []): ?>
|
|
<div class="muted small" style="margin-top:8px;">
|
|
Vorgeschlagener Titel: <?= htmlspecialchars((string)($payload['title'] ?? $request['title']), ENT_QUOTES) ?><br>
|
|
Vorgeschlagene Adresse: <?= htmlspecialchars(trim(implode(', ', array_filter([
|
|
(string)($payload['street'] ?? ''),
|
|
trim((string)($payload['zip'] ?? '') . ' ' . (string)($payload['city'] ?? '')),
|
|
(string)($payload['region'] ?? ''),
|
|
]))), ENT_QUOTES) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<form method="post" class="forum-admin-item__actions">
|
|
<input type="hidden" name="action" value="listing_request_decide">
|
|
<input type="hidden" name="request_id" value="<?= (int)$request['id'] ?>">
|
|
<textarea name="review_note" class="textarea" rows="3" placeholder="Hinweis für die Entscheidung"></textarea>
|
|
<div class="flex gap-12">
|
|
<button class="btn" type="submit" name="decision" value="approved">Freigeben</button>
|
|
<button class="btn ghost" type="submit" name="decision" value="rejected">Ablehnen</button>
|
|
</div>
|
|
</form>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
<?php if (!$listingRequests): ?>
|
|
<div class="forum-empty">Keine offenen Orts- oder Veranstaltungsanfragen.</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($canManageApplications): ?>
|
|
<section class="forum-board">
|
|
<div class="forum-board__head">
|
|
<div>
|
|
<h2>Offene Bewerbungen</h2>
|
|
<p class="muted">Bewerbungen für die Forum-Moderation prüfen.</p>
|
|
</div>
|
|
</div>
|
|
<div class="forum-admin-list">
|
|
<?php foreach ($applications as $application): ?>
|
|
<article class="forum-admin-item">
|
|
<div>
|
|
<strong><?= htmlspecialchars((string)($application['display_name'] ?: $application['email']), ENT_QUOTES) ?></strong>
|
|
<p><?= nl2br(htmlspecialchars((string)$application['motivation'], ENT_QUOTES)) ?></p>
|
|
</div>
|
|
<form method="post" class="forum-admin-item__actions">
|
|
<input type="hidden" name="action" value="application_decide">
|
|
<input type="hidden" name="application_id" value="<?= (int)$application['id'] ?>">
|
|
<textarea name="decision_reason" class="textarea" rows="3" placeholder="Begründung"></textarea>
|
|
<div class="flex gap-12">
|
|
<button class="btn" type="submit" name="decision" value="approved">Annehmen</button>
|
|
<button class="btn ghost" type="submit" name="decision" value="rejected">Ablehnen</button>
|
|
</div>
|
|
</form>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
<?php if (!$applications): ?>
|
|
<div class="forum-empty">Keine offenen Bewerbungen.</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($canModerateForum): ?>
|
|
<section class="forum-board">
|
|
<div class="forum-board__head">
|
|
<div>
|
|
<h2>Offene Meldungen</h2>
|
|
<p class="muted">Gemeldete Inhalte prüfen und abschließen.</p>
|
|
</div>
|
|
</div>
|
|
<div class="forum-admin-list">
|
|
<?php foreach ($reports as $report): ?>
|
|
<article class="forum-admin-item">
|
|
<div>
|
|
<strong><?= htmlspecialchars((string)$report['target_type'], ENT_QUOTES) ?> #<?= (int)$report['target_id'] ?></strong>
|
|
<p><?= nl2br(htmlspecialchars((string)$report['reason'], ENT_QUOTES)) ?></p>
|
|
<p class="muted small">Gemeldet von <?= htmlspecialchars((string)($report['reporter_name'] ?: 'Mitglied'), ENT_QUOTES) ?> am <?= htmlspecialchars((string)$report['created_at'], ENT_QUOTES) ?></p>
|
|
</div>
|
|
<form method="post" class="forum-admin-item__actions">
|
|
<input type="hidden" name="action" value="report_resolve">
|
|
<input type="hidden" name="report_id" value="<?= (int)$report['id'] ?>">
|
|
<textarea name="moderator_note" class="textarea" rows="3" placeholder="Moderationsnotiz"></textarea>
|
|
<button class="btn" type="submit">Als erledigt markieren</button>
|
|
</form>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
<?php if (!$reports): ?>
|
|
<div class="forum-empty">Keine offenen Meldungen.</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($canManageRoles || $canManageApplications): ?>
|
|
<section class="forum-board">
|
|
<div class="forum-board__head">
|
|
<div>
|
|
<h2>Rollen verwalten</h2>
|
|
</div>
|
|
</div>
|
|
<div style="padding:24px; border-bottom:1px solid var(--color-border);">
|
|
<form method="get" class="form-grid single">
|
|
<div class="stack gap-6">
|
|
<label class="label" for="adminRoleUserQuery">Benutzer suchen</label>
|
|
<input id="adminRoleUserQuery" name="role_user_query" class="input" value="<?= htmlspecialchars($roleUserSearchQuery, ENT_QUOTES) ?>" placeholder="Name oder E-Mail">
|
|
</div>
|
|
<div>
|
|
<button class="btn" type="submit">Suchen</button>
|
|
</div>
|
|
</form>
|
|
<?php if ($roleUserSearchResults): ?>
|
|
<div class="stack gap-12" style="margin-top:18px;">
|
|
<?php foreach ($roleUserSearchResults as $candidate): ?>
|
|
<?php
|
|
$candidateUserId = (int)($candidate['id'] ?? 0);
|
|
$candidateRoles = $access->getUserRoles($candidateUserId);
|
|
$assignableRoles = $canManageRoles ? ['forum_admin', 'site_admin', 'owner'] : ['forum_admin'];
|
|
?>
|
|
<div class="card" style="padding:14px;">
|
|
<strong><?= htmlspecialchars((string)($candidate['display_name'] ?: trim(((string)($candidate['first_name'] ?? '')) . ' ' . ((string)($candidate['last_name'] ?? ''))) ?: 'Mitglied'), ENT_QUOTES) ?></strong>
|
|
<div class="muted small" style="margin-top:6px;">
|
|
ID: <?= $candidateUserId ?> · <?= htmlspecialchars((string)($candidate['email'] ?? ''), ENT_QUOTES) ?>
|
|
</div>
|
|
<?php if ($candidateRoles): ?>
|
|
<div class="muted small" style="margin-top:6px;">Aktuelle Rollen: <?= htmlspecialchars(implode(', ', array_map('strval', $candidateRoles)), ENT_QUOTES) ?></div>
|
|
<?php endif; ?>
|
|
<div class="flex gap-8" style="margin-top:12px; flex-wrap:wrap;">
|
|
<?php foreach ($assignableRoles as $roleKey): ?>
|
|
<?php if (!in_array($roleKey, $candidateRoles, true)): ?>
|
|
<form method="post">
|
|
<input type="hidden" name="action" value="role_assign">
|
|
<input type="hidden" name="target_user_id" value="<?= $candidateUserId ?>">
|
|
<input type="hidden" name="role" value="<?= htmlspecialchars($roleKey, ENT_QUOTES) ?>">
|
|
<button class="btn ghost" type="submit"><?= htmlspecialchars($roleKey, ENT_QUOTES) ?> vergeben</button>
|
|
</form>
|
|
<?php elseif ($canManageRoles): ?>
|
|
<form method="post">
|
|
<input type="hidden" name="action" value="role_revoke">
|
|
<input type="hidden" name="target_user_id" value="<?= $candidateUserId ?>">
|
|
<input type="hidden" name="role" value="<?= htmlspecialchars($roleKey, ENT_QUOTES) ?>">
|
|
<button class="btn ghost" type="submit"><?= htmlspecialchars($roleKey, ENT_QUOTES) ?> entziehen</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php elseif ($roleUserSearchQuery !== ''): ?>
|
|
<p class="muted small" style="margin-top:18px;">Keine passenden Benutzer gefunden.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="forum-admin-list">
|
|
<?php foreach ($roleAssignments as $assignment): ?>
|
|
<article class="forum-admin-item">
|
|
<div>
|
|
<strong><?= htmlspecialchars((string)($assignment['display_name'] ?: $assignment['email']), ENT_QUOTES) ?></strong>
|
|
<p class="muted small">Rolle: <?= htmlspecialchars((string)$assignment['role'], ENT_QUOTES) ?> · seit <?= htmlspecialchars((string)$assignment['assigned_at'], ENT_QUOTES) ?></p>
|
|
</div>
|
|
<form method="post">
|
|
<input type="hidden" name="action" value="role_revoke">
|
|
<input type="hidden" name="target_user_id" value="<?= (int)$assignment['user_id'] ?>">
|
|
<input type="hidden" name="role" value="<?= htmlspecialchars((string)$assignment['role'], ENT_QUOTES) ?>">
|
|
<button class="btn ghost" type="submit">Rolle entziehen</button>
|
|
</form>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
<?php if (!$roleAssignments): ?>
|
|
<div class="forum-empty">Keine Rollen vergeben.</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($canManageApplications && $migrationStatus): ?>
|
|
<section class="forum-board">
|
|
<div class="forum-board__head">
|
|
<div>
|
|
<h2>Migration</h2>
|
|
<p class="muted">Status der Community-Datenbank prüfen.</p>
|
|
</div>
|
|
</div>
|
|
<div style="padding:24px;">
|
|
<ul class="dash-list">
|
|
<li>Status: <?= !empty($migrationStatus['complete']) ? 'Vollständig eingerichtet' : 'Migration noch offen' ?></li>
|
|
<li>Fehlende Bausteine: <?= !empty($migrationStatus['missing']) ? htmlspecialchars(implode(', ', $migrationStatus['missing']), ENT_QUOTES) : 'Keine' ?></li>
|
|
</ul>
|
|
<form method="post" style="margin-top:14px;">
|
|
<input type="hidden" name="action" value="community_migrate">
|
|
<button class="btn" type="submit">Community-Migration ausführen</button>
|
|
</form>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</main>
|