Fixed delete and update error.

This commit is contained in:
Viktor Sergeev 2025-07-11 21:22:22 +02:00
parent 7787cb2956
commit c306a59fec

View File

@ -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() {