Added Styles to Create and Update Event

This commit is contained in:
Viktor Sergeev 2025-07-07 20:32:35 +02:00
parent a9944259b6
commit 3faec473ef
3 changed files with 97 additions and 14 deletions

View File

@ -3,6 +3,7 @@
namespace Blog\Controller; namespace Blog\Controller;
use Blog\Model\EventModel; use Blog\Model\EventModel;
use Blog\Model\StandortModel;
class EventController { class EventController {
@ -61,4 +62,40 @@ class EventController {
$this->model->deleteEvent($id); $this->model->deleteEvent($id);
$this->view->setVars(['id' => $id]); $this->view->setVars(['id' => $id]);
} }
public function showUpdateEvent() {
$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;
}
$event = $this->model->getEvent($id);
if (!$event) {
$this->view->setVars(['error' => 'Event nicht gefunden.']);
return;
}
// Map DB fields to view fields if needed
$eventView = [
'id' => $event['event_id'],
'name' => $event['name'],
'start_date' => $event['start_date'],
'end_date' => $event['end_date'],
'location_id' => $event['location_id'],
'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]);
}
public function showCreateEvent() {
$standortModel = new \Blog\Model\StandortModel();
$locations = $standortModel->getStandorte();
$this->view->setVars(['locations' => $locations]);
}
} }

View File

@ -1,12 +1,36 @@
<?php
include dirname(__DIR__).'/header.phtml';
?>
<div class="inhalt"> <div class="inhalt">
<div class="msg"> <h2>Create Event</h2>
<p>Das Event "<?php echo $name?>" wurde erfolgreich erstellt!</p> <form action="/Event/create" method="POST">
<a href="?controller=Event&do=showEvents">Weiter</a> <label>Event Name:</label>
</div> <input type="text" name="name" required><br>
</div>
<?php include dirname(__DIR__).'/footer.phtml'; ?> <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>

View File

@ -3,10 +3,32 @@ include dirname(__DIR__).'/header.phtml';
?> ?>
<div class="inhalt"> <div class="inhalt">
<div class="msg"> <h2>Update Event</h2>
<p>Das Event mit der ID "<?php echo $ausstellungid?>" wurde erfolgreich bearbeitet!</p> <form action="/Event/update?id=<?= htmlspecialchars($event['id']) ?>" method="POST">
<a href="?controller=Event&do=showEvents">Weiter</a> <label>Event Name:</label>
</div> <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> </div>
<?php include dirname(__DIR__).'/footer.phtml'; ?> <?php include dirname(__DIR__).'/footer.phtml'; ?>