Added Create, Update and Delete to Events and added styles.
This commit is contained in:
parent
d4534f9a11
commit
7787cb2956
@ -167,6 +167,22 @@ a {
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
}
|
||||
.form-horizontal input[type="date"],
|
||||
.form-horizontal input[type="number"],
|
||||
.form-horizontal select,
|
||||
.form-horizontal textarea {
|
||||
width: 100%;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid #BAC8D4;
|
||||
border-radius: 4px;
|
||||
font-size: 1rem;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
}
|
||||
.form-horizontal textarea {
|
||||
resize: vertical;
|
||||
min-height: 100px;
|
||||
}
|
||||
.form-horizontal button {
|
||||
width: 100%;
|
||||
padding: 10px 0;
|
||||
@ -182,6 +198,21 @@ a {
|
||||
.form-horizontal button:hover {
|
||||
background: #333;
|
||||
}
|
||||
.button-register {
|
||||
width: 100%;
|
||||
padding: 10px 0;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background: #4d4d4d;
|
||||
color: #fff;
|
||||
font-size: 1rem;
|
||||
margin-top: 8px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.button-register:hover {
|
||||
background: #333;
|
||||
}
|
||||
.login-error, .form-error {
|
||||
background: #ffe0e0;
|
||||
color: #b30000;
|
||||
@ -403,6 +434,17 @@ a {
|
||||
margin: 0 auto;
|
||||
display: inline-block;
|
||||
}
|
||||
.event-header {
|
||||
text-align: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.event-header h2 {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.event-header .admin-btn {
|
||||
margin: 0 auto;
|
||||
display: inline-block;
|
||||
}
|
||||
.card--wide {
|
||||
max-width: 700px;
|
||||
width: auto;
|
||||
|
@ -23,19 +23,32 @@ class EventController {
|
||||
}
|
||||
|
||||
public function createEvent() {
|
||||
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
|
||||
header('Location: index.php?controller=Event&do=showEvents');
|
||||
exit;
|
||||
}
|
||||
$data = [
|
||||
'name' => $_POST['name'] ?? null,
|
||||
'beschreibung' => $_POST['beschreibung'] ?? null,
|
||||
'standortid' => $_POST['standortid'] ?? null,
|
||||
'datum_von' => $_POST['datum_von'] ?? null,
|
||||
'datum_bis' => $_POST['datum_bis'] ?? null,
|
||||
'max_tickets' => $_POST['max_tickets'] ?? null,
|
||||
'preis' => $_POST['preis'] ?? null
|
||||
'name' => $_POST['name'] ?? '',
|
||||
'start_date' => $_POST['start_date'] ?? '',
|
||||
'end_date' => $_POST['end_date'] ?? '',
|
||||
'location_id' => $_POST['location_id'] ?? '',
|
||||
'description' => $_POST['description'] ?? '',
|
||||
'max_tickets' => $_POST['max_tickets'] ?? '',
|
||||
'ticket_price' => $_POST['ticket_price'] ?? ''
|
||||
];
|
||||
|
||||
$errors = [];
|
||||
if (empty($data['name']) || empty($data['start_date']) || empty($data['end_date']) || empty($data['location_id']) || empty($data['description']) || empty($data['max_tickets']) || empty($data['ticket_price'])) {
|
||||
$errors['event'] = 'Bitte alle Felder ausfüllen.';
|
||||
}
|
||||
if (!empty($errors)) {
|
||||
$standortModel = new StandortModel();
|
||||
$locations = $standortModel->getStandorte();
|
||||
$this->view->setVars(['errors' => $errors, 'validData' => $data, 'locations' => $locations]);
|
||||
$this->view->setDoMethodName('showCreateEvent');
|
||||
return;
|
||||
}
|
||||
$this->model->createEvent($data);
|
||||
$this->view->setVars(['event' => $data]);
|
||||
exit;
|
||||
$this->view->setDoMethodName('showCreateForwarding');
|
||||
}
|
||||
|
||||
public function editEventForm() {
|
||||
@ -64,9 +77,12 @@ class EventController {
|
||||
}
|
||||
|
||||
public function showUpdateEvent() {
|
||||
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
|
||||
header('Location: index.php?controller=Event&do=showEvents');
|
||||
exit;
|
||||
}
|
||||
$id = $_GET['event_id'] ?? null;
|
||||
if (!$id) {
|
||||
// handle error, e.g., redirect or show error message
|
||||
$this->view->setVars(['error' => 'Keine Event-ID angegeben.']);
|
||||
return;
|
||||
}
|
||||
@ -75,27 +91,33 @@ class EventController {
|
||||
$this->view->setVars(['error' => 'Event nicht gefunden.']);
|
||||
return;
|
||||
}
|
||||
// Map DB fields to view fields if needed
|
||||
$standortModel = new StandortModel();
|
||||
$location = $standortModel->getStandort($event['location_id']);
|
||||
$eventView = [
|
||||
'id' => $event['event_id'],
|
||||
'name' => $event['name'],
|
||||
'start_date' => $event['start_date'],
|
||||
'end_date' => $event['end_date'],
|
||||
'location_id' => $event['location_id'],
|
||||
'location_name' => $location['city'] ?? '',
|
||||
'description' => $event['description'],
|
||||
'max_tickets' => $event['max_tickets'],
|
||||
'ticket_price' => $event['ticket_price'],
|
||||
];
|
||||
// Fetch location name (city)
|
||||
$standortModel = new StandortModel();
|
||||
$location = $standortModel->getStandort($event['location_id']);
|
||||
$eventView['location_name'] = $location['city'] ?? '';
|
||||
$this->view->setVars(['event' => $eventView]);
|
||||
$this->view->setVars(['event' => $eventView, 'errors' => []]);
|
||||
}
|
||||
|
||||
public function showCreateEvent() {
|
||||
$standortModel = new \Blog\Model\StandortModel();
|
||||
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
|
||||
header('Location: index.php?controller=Event&do=showEvents');
|
||||
exit;
|
||||
}
|
||||
$standortModel = new StandortModel();
|
||||
$locations = $standortModel->getStandorte();
|
||||
$this->view->setVars(['locations' => $locations]);
|
||||
$this->view->setVars([
|
||||
'locations' => $locations,
|
||||
'errors' => [],
|
||||
'validData' => []
|
||||
]);
|
||||
}
|
||||
}
|
@ -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>
|
@ -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>
|
||||
|
@ -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'; ?>
|
Loading…
x
Reference in New Issue
Block a user