Added Create, Update and Delete to Events and added styles.

This commit is contained in:
2025-07-11 21:16:42 +02:00
parent d4534f9a11
commit 7787cb2956
5 changed files with 163 additions and 80 deletions

View File

@@ -1,36 +1,38 @@
<div class="inhalt">
<h2>Create Event</h2>
<form action="/Event/create" method="POST">
<label>Event Name:</label>
<input type="text" name="name" required><br>
<label>Start Date:</label>
<input type="date" name="start_date" required><br>
<label>End Date:</label>
<input type="date" name="end_date" required><br>
<label>Location:</label>
<select name="location_id" required>
<option value="">Select location</option>
<?php if (!empty($locations)): ?>
<?php foreach ($locations as $loc): ?>
<option value="<?= htmlspecialchars($loc['location_id']) ?>">
<?= htmlspecialchars($loc['city']) ?>, <?= htmlspecialchars($loc['street']) ?> <?= htmlspecialchars($loc['house_number']) ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select><br>
<label>Description:</label>
<textarea name="description" required></textarea><br>
<label>Max Tickets:</label>
<input type="number" name="max_tickets" required><br>
<label>Ticket Price:</label>
<input type="number" step="0.01" name="ticket_price" required><br>
<button type="submit">Create Event</button>
</form>
<div class="form-container">
<h1>Event erstellen</h1>
<?php if (!empty(
$errors['event'])): ?>
<div class="error-box"><?=htmlspecialchars($errors['event'])?></div>
<?php endif; ?>
<form class="form-horizontal" action="index.php" method="post">
<input type="hidden" name="controller" value="Event">
<input type="hidden" name="do" value="createEvent">
<label for="name">Name</label>
<input type="text" name="name" id="name" required value="<?=htmlspecialchars($validData['name'] ?? '')?>">
<label for="start_date">Startdatum</label>
<input type="date" name="start_date" id="start_date" required value="<?=htmlspecialchars($validData['start_date'] ?? '')?>">
<label for="end_date">Enddatum</label>
<input type="date" name="end_date" id="end_date" required value="<?=htmlspecialchars($validData['end_date'] ?? '')?>">
<label for="location_id">Standort</label>
<select name="location_id" id="location_id" required>
<option value="">Standort wählen</option>
<?php if (!empty($locations)): ?>
<?php foreach ($locations as $loc): ?>
<option value="<?= htmlspecialchars($loc['location_id']) ?>" <?= (isset($validData['location_id']) && $validData['location_id'] == $loc['location_id']) ? 'selected' : '' ?>>
<?= htmlspecialchars($loc['city']) ?>, <?= htmlspecialchars($loc['street']) ?> <?= htmlspecialchars($loc['house_number']) ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<label for="description">Beschreibung</label>
<textarea name="description" id="description" rows="7" required><?=htmlspecialchars($validData['description'] ?? '')?></textarea>
<label for="max_tickets">Max. Tickets</label>
<input type="number" name="max_tickets" id="max_tickets" required value="<?=htmlspecialchars($validData['max_tickets'] ?? '')?>">
<label for="ticket_price">Ticketpreis</label>
<input type="number" step="0.01" name="ticket_price" id="ticket_price" required value="<?=htmlspecialchars($validData['ticket_price'] ?? '')?>">
<button class="button-register" type="submit">Event erstellen</button>
</form>
<a href="?controller=Event&do=showEvents">Zurück zur Übersicht</a>
</div>
</div>

View File

@@ -1,7 +1,12 @@
<?php if (!empty($events)): ?>
<div class="inhalt">
<div class="content-container">
<h2>Alle Ausstellungen</h2>
<div class="event-header">
<h2>Alle Ausstellungen</h2>
<?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
<a href="?controller=Event&do=showCreateEvent" class="admin-btn">Event erstellen</a>
<?php endif; ?>
</div>
<div class="event-container-inhalt">
<table>
<thead>
@@ -11,6 +16,9 @@
<th>Von</th>
<th>Bis</th>
<th>Max. Tickets</th>
<?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
<th>Aktionen</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
@@ -21,6 +29,12 @@
<td><?php echo date('d.m.Y', strtotime($event['start_date'])); ?></td>
<td><?php echo date('d.m.Y', strtotime($event['end_date'])); ?></td>
<td><?php echo (int) $event['max_tickets']; ?></td>
<?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
<td>
<a href="?controller=Event&do=showUpdateEvent&event_id=<?php echo $event['event_id']; ?>" class="admin-btn">Bearbeiten</a>
<a href="?controller=Event&do=deleteEvent&event_id=<?php echo $event['event_id']; ?>" class="admin-btn" onclick="return confirm('Wirklich löschen?');">Löschen</a>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>

View File

@@ -3,32 +3,35 @@ include dirname(__DIR__).'/header.phtml';
?>
<div class="inhalt">
<h2>Update Event</h2>
<form action="/Event/update?id=<?= htmlspecialchars($event['id']) ?>" method="POST">
<label>Event Name:</label>
<input type="text" name="name" value="<?= htmlspecialchars($event['name']) ?>" required><br>
<label>Start Date:</label>
<input type="date" name="start_date" value="<?= htmlspecialchars($event['start_date']) ?>" required><br>
<label>End Date:</label>
<input type="date" name="end_date" value="<?= htmlspecialchars($event['end_date']) ?>" required><br>
<label>Location:</label>
<input type="text" name="location_name" value="<?= htmlspecialchars($event['location_name']) ?>" readonly><br>
<input type="hidden" name="location_id" value="<?= htmlspecialchars($event['location_id']) ?>">
<label>Description:</label>
<textarea name="description" required><?= htmlspecialchars($event['description']) ?></textarea><br>
<label>Max Tickets:</label>
<input type="number" name="max_tickets" value="<?= htmlspecialchars($event['max_tickets']) ?>" required><br>
<label>Ticket Price:</label>
<input type="number" step="0.01" name="ticket_price" value="<?= htmlspecialchars($event['ticket_price']) ?>" required><br>
<button type="submit">Update Event</button>
</form>
<div class="form-container">
<h1>Event bearbeiten</h1>
<?php if (!empty(
$errors['event'])): ?>
<div class="error-box"><?=htmlspecialchars($errors['event'])?></div>
<?php endif; ?>
<form class="form-horizontal" action="index.php" method="post">
<input type="hidden" name="controller" value="Event">
<input type="hidden" name="do" value="updateEvent">
<input type="hidden" name="id" value="<?=htmlspecialchars($event['id'] ?? '')?>">
<label for="name">Name</label>
<input type="text" name="name" id="name" required value="<?=htmlspecialchars($event['name'] ?? '')?>">
<label for="start_date">Startdatum</label>
<input type="date" name="start_date" id="start_date" required value="<?=htmlspecialchars($event['start_date'] ?? '')?>">
<label for="end_date">Enddatum</label>
<input type="date" name="end_date" id="end_date" required value="<?=htmlspecialchars($event['end_date'] ?? '')?>">
<label for="location_id">Standort</label>
<input type="text" name="location_name" value="<?=htmlspecialchars($event['location_name'] ?? '')?>" readonly>
<input type="hidden" name="location_id" value="<?=htmlspecialchars($event['location_id'] ?? '')?>">
<label for="description">Beschreibung</label>
<textarea name="description" id="description" rows="7" required><?=htmlspecialchars($event['description'] ?? '')?></textarea>
<label for="max_tickets">Max. Tickets</label>
<input type="number" name="max_tickets" id="max_tickets" required value="<?=htmlspecialchars($event['max_tickets'] ?? '')?>">
<label for="ticket_price">Ticketpreis</label>
<input type="number" step="0.01" name="ticket_price" id="ticket_price" required value="<?=htmlspecialchars($event['ticket_price'] ?? '')?>">
<button class="button-register" type="submit">Änderungen speichern</button>
</form>
<a href="?controller=Event&do=showEvents">Zurück zur Übersicht</a>
</div>
</div>
<?php include dirname(__DIR__).'/footer.phtml'; ?>