From 7787cb2956c9478e95d043af229615eadae2f847 Mon Sep 17 00:00:00 2001 From: pbbfa23cse Date: Fri, 11 Jul 2025 21:16:42 +0200 Subject: [PATCH] Added Create, Update and Delete to Events and added styles. --- CSS/style.css | 42 +++++++++++++++++++ Controller/EventController.php | 60 +++++++++++++++++--------- Views/Event/showCreateEvent.phtml | 70 ++++++++++++++++--------------- Views/Event/showEvents.phtml | 16 ++++++- Views/Event/showUpdateEvent.phtml | 55 ++++++++++++------------ 5 files changed, 163 insertions(+), 80 deletions(-) diff --git a/CSS/style.css b/CSS/style.css index 02a594c..03d8494 100644 --- a/CSS/style.css +++ b/CSS/style.css @@ -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; diff --git a/Controller/EventController.php b/Controller/EventController.php index bca7a6e..2330eb4 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -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' => [] + ]); } } \ No newline at end of file diff --git a/Views/Event/showCreateEvent.phtml b/Views/Event/showCreateEvent.phtml index caba922..16e6cca 100644 --- a/Views/Event/showCreateEvent.phtml +++ b/Views/Event/showCreateEvent.phtml @@ -1,36 +1,38 @@
-

Create Event

-
- -
- - -
- - -
- - -
- - -
- - -
- - -
- - -
+
+

Event erstellen

+ +
+ +
+ + + + + + + + + + + + + + + + + +
+ Zurück zur Übersicht +
\ No newline at end of file diff --git a/Views/Event/showEvents.phtml b/Views/Event/showEvents.phtml index a9f7366..13cd584 100644 --- a/Views/Event/showEvents.phtml +++ b/Views/Event/showEvents.phtml @@ -1,7 +1,12 @@
-

Alle Ausstellungen

+
+

Alle Ausstellungen

+ + Event erstellen + +
@@ -11,6 +16,9 @@ + + + @@ -21,6 +29,12 @@ + + + diff --git a/Views/Event/showUpdateEvent.phtml b/Views/Event/showUpdateEvent.phtml index 86cf753..f10e9cd 100644 --- a/Views/Event/showUpdateEvent.phtml +++ b/Views/Event/showUpdateEvent.phtml @@ -3,32 +3,35 @@ include dirname(__DIR__).'/header.phtml'; ?>
-

Update Event

-
- -
- - -
- - -
- - -
- - - -
- - -
- - -
- - - +
+

Event bearbeiten

+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + Zurück zur Übersicht +
\ No newline at end of file
Von Bis Max. TicketsAktionen
+ Bearbeiten + Löschen +