dsasd
This commit is contained in:
@@ -119,6 +119,32 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
'status' => 'published',
|
||||
]);
|
||||
$info = 'Event gespeichert.';
|
||||
} elseif ($action === 'event_delete') {
|
||||
$eventId = (int)($_POST['event_id'] ?? 0);
|
||||
$stmt = $pdo->prepare('SELECT id, created_by, status, (SELECT COUNT(*) FROM event_participants ep WHERE ep.event_id = events.id) AS participant_count FROM events WHERE id = :id LIMIT 1');
|
||||
$stmt->execute(['id' => $eventId]);
|
||||
$ev = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$ev || (int)$ev['created_by'] !== $userId) {
|
||||
throw new RuntimeException('Event nicht gefunden.');
|
||||
}
|
||||
if ((int)$ev['participant_count'] > 0) {
|
||||
throw new RuntimeException('Event hat Anmeldungen und kann nicht gelöscht werden.');
|
||||
}
|
||||
$pdo->prepare('DELETE FROM events WHERE id = :id')->execute(['id' => $eventId]);
|
||||
$info = 'Event gelöscht.';
|
||||
} elseif ($action === 'event_cancel') {
|
||||
$eventId = (int)($_POST['event_id'] ?? 0);
|
||||
$stmt = $pdo->prepare('SELECT id, created_by FROM events WHERE id = :id LIMIT 1');
|
||||
$stmt->execute(['id' => $eventId]);
|
||||
$ev = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$ev || (int)$ev['created_by'] !== $userId) {
|
||||
throw new RuntimeException('Event nicht gefunden.');
|
||||
}
|
||||
$pdo->prepare('UPDATE events SET status = :st, updated_at = NOW() WHERE id = :id')->execute([
|
||||
'st' => 'cancelled',
|
||||
'id' => $eventId,
|
||||
]);
|
||||
$info = 'Event wurde abgesagt.';
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$error = $e->getMessage();
|
||||
@@ -160,10 +186,27 @@ foreach ($childrenRaw as $c) {
|
||||
$children[] = $c;
|
||||
}
|
||||
|
||||
$events = [];
|
||||
$stmt = $pdo->prepare('SELECT id, title, teaser_public, starts_at, city, visibility FROM events WHERE created_by = :id ORDER BY starts_at DESC');
|
||||
$eventsUpcoming = [];
|
||||
$eventsPast = [];
|
||||
$stmt = $pdo->prepare(
|
||||
'SELECT e.id, e.title, e.teaser_public, e.starts_at, e.city, e.visibility, e.status,
|
||||
(SELECT COUNT(*) FROM event_participants ep WHERE ep.event_id = e.id) AS participant_count
|
||||
FROM events e
|
||||
WHERE e.created_by = :id AND e.starts_at >= NOW()
|
||||
ORDER BY e.starts_at ASC'
|
||||
);
|
||||
$stmt->execute(['id' => $userId]);
|
||||
$events = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
||||
$eventsUpcoming = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
'SELECT e.id, e.title, e.teaser_public, e.starts_at, e.city, e.visibility, e.status,
|
||||
(SELECT COUNT(*) FROM event_participants ep WHERE ep.event_id = e.id) AS participant_count
|
||||
FROM events e
|
||||
WHERE e.created_by = :id AND e.starts_at < NOW()
|
||||
ORDER BY e.starts_at DESC'
|
||||
);
|
||||
$stmt->execute(['id' => $userId]);
|
||||
$eventsPast = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
||||
?>
|
||||
<main class="section">
|
||||
<div class="container" style="display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:12px;">
|
||||
@@ -225,26 +268,76 @@ $events = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container dash-section">
|
||||
<div class="container dash-section" id="events">
|
||||
<div class="card dash-card">
|
||||
<div class="badge">Deine Events</div>
|
||||
<?php if (!$events): ?>
|
||||
<p class="muted small">Noch keine Events angelegt.</p>
|
||||
<div class="flex gap-12" style="margin:10px 0 16px 0; flex-wrap: wrap;">
|
||||
<button class="btn" type="button" data-modal-open="modalEvent">Event anlegen</button>
|
||||
</div>
|
||||
<?php if (!$eventsUpcoming): ?>
|
||||
<p class="muted small">Keine zukünftigen Events angelegt.</p>
|
||||
<?php else: ?>
|
||||
<ul class="dash-list">
|
||||
<?php foreach ($events as $e): ?>
|
||||
<li><?= htmlspecialchars($e['title'], ENT_QUOTES) ?> – <?= htmlspecialchars($e['city'], ENT_QUOTES) ?>, <?= htmlspecialchars($e['starts_at'], ENT_QUOTES) ?> (<?= htmlspecialchars($e['visibility'], ENT_QUOTES) ?>)</li>
|
||||
<ul class="dash-list" style="margin-top:10px;">
|
||||
<?php foreach ($eventsUpcoming as $e): ?>
|
||||
<li>
|
||||
<div style="display:flex; justify-content:space-between; gap:12px; align-items:center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<strong><?= htmlspecialchars($e['title'], ENT_QUOTES) ?></strong>
|
||||
<?php if ($e['status'] === 'cancelled'): ?>
|
||||
<span class="badge" style="background:#fee2e2; color:#991b1b;">Abgesagt</span>
|
||||
<?php endif; ?>
|
||||
<div class="muted small" style="margin-top:4px;">
|
||||
<?= htmlspecialchars($e['city'], ENT_QUOTES) ?> · <?= htmlspecialchars($e['starts_at'], ENT_QUOTES) ?> · <?= htmlspecialchars($e['visibility'], ENT_QUOTES) ?>
|
||||
· Anmeldungen: <?= (int)$e['participant_count'] ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex gap-8" style="flex-wrap: wrap;">
|
||||
<?php if ((int)$e['participant_count'] === 0): ?>
|
||||
<form method="post" action="/dashboard#events" onsubmit="return confirm('Event wirklich löschen?');">
|
||||
<input type="hidden" name="action" value="event_delete">
|
||||
<input type="hidden" name="event_id" value="<?= (int)$e['id'] ?>">
|
||||
<button class="btn ghost" type="submit">Löschen</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<?php if ($e['status'] !== 'cancelled'): ?>
|
||||
<form method="post" action="/dashboard#events" onsubmit="return confirm('Event für alle absagen?');">
|
||||
<input type="hidden" name="action" value="event_cancel">
|
||||
<input type="hidden" name="event_id" value="<?= (int)$e['id'] ?>">
|
||||
<button class="btn ghost" type="submit">Absagen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container dash-section" id="events">
|
||||
<div class="card dash-card">
|
||||
<div class="badge">Eigenes Event</div>
|
||||
<h3>Neuen Termin erstellen</h3>
|
||||
<button class="btn" type="button" data-modal-open="modalEvent">Event anlegen</button>
|
||||
<details style="margin-top:12px;">
|
||||
<summary style="cursor:pointer;">Vergangene Events anzeigen</summary>
|
||||
<?php if (!$eventsPast): ?>
|
||||
<p class="muted small">Keine vergangenen Events.</p>
|
||||
<?php else: ?>
|
||||
<ul class="dash-list" style="margin-top:10px;">
|
||||
<?php foreach ($eventsPast as $e): ?>
|
||||
<li>
|
||||
<div style="display:flex; justify-content:space-between; gap:12px; align-items:center; flex-wrap: wrap;">
|
||||
<div>
|
||||
<strong><?= htmlspecialchars($e['title'], ENT_QUOTES) ?></strong>
|
||||
<?php if ($e['status'] === 'cancelled'): ?>
|
||||
<span class="badge" style="background:#fee2e2; color:#991b1b;">Abgesagt</span>
|
||||
<?php endif; ?>
|
||||
<div class="muted small" style="margin-top:4px;">
|
||||
<?= htmlspecialchars($e['city'], ENT_QUOTES) ?> · <?= htmlspecialchars($e['starts_at'], ENT_QUOTES) ?> · <?= htmlspecialchars($e['visibility'], ENT_QUOTES) ?>
|
||||
· Anmeldungen: <?= (int)$e['participant_count'] ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user