From c306a59fece314906a3d7fa800799e2708b3f518 Mon Sep 17 00:00:00 2001 From: pbbfa23cse Date: Fri, 11 Jul 2025 21:22:22 +0200 Subject: [PATCH] Fixed delete and update error. --- Controller/EventController.php | 58 +++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/Controller/EventController.php b/Controller/EventController.php index 2330eb4..5899876 100644 --- a/Controller/EventController.php +++ b/Controller/EventController.php @@ -57,23 +57,57 @@ class EventController { $this->view->setVars(['event' => $event]); } - public function updateEvent($id, $data) { - $id = $_POST['ausstellungid']; + public function updateEvent() { + if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) { + header('Location: index.php?controller=Event&do=showEvents'); + exit; + } + $id = $_POST['id'] ?? null; $data = [ - 'standortid' => $_POST['standortid'] ?? null, - 'datum_von' => $_POST['datum_von'] ?? null, - 'datum_bis' => $_POST['datum_bis'] ?? null, - 'name' => $_POST['name'] ?? null, - 'beschreibung' => $_POST['beschreibung'] ?? 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(); + $location = $standortModel->getStandort($data['location_id']); + $eventView = [ + 'id' => $id, + 'name' => $data['name'], + 'start_date' => $data['start_date'], + 'end_date' => $data['end_date'], + 'location_id' => $data['location_id'], + 'location_name' => $location['city'] ?? '', + 'description' => $data['description'], + 'max_tickets' => $data['max_tickets'], + 'ticket_price' => $data['ticket_price'], + ]; + $this->view->setVars(['event' => $eventView, 'errors' => $errors]); + $this->view->setDoMethodName('showUpdateEvent'); + return; + } $this->model->updateEvent($id, $data); + $this->view->setDoMethodName('showUpdateForwarding'); } - public function deleteEvent($id) { - $this->model->deleteEvent($id); - $this->view->setVars(['id' => $id]); + public function deleteEvent() { + if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) { + header('Location: index.php?controller=Event&do=showEvents'); + exit; + } + $id = $_GET['event_id'] ?? null; + if ($id) { + $this->model->deleteEvent($id); + } + $this->view->setDoMethodName('deleteEvent'); } public function showUpdateEvent() {