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;
|
box-sizing: border-box;
|
||||||
background: #fff;
|
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 {
|
.form-horizontal button {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
@ -182,6 +198,21 @@ a {
|
|||||||
.form-horizontal button:hover {
|
.form-horizontal button:hover {
|
||||||
background: #333;
|
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 {
|
.login-error, .form-error {
|
||||||
background: #ffe0e0;
|
background: #ffe0e0;
|
||||||
color: #b30000;
|
color: #b30000;
|
||||||
@ -403,6 +434,17 @@ a {
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
display: inline-block;
|
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 {
|
.card--wide {
|
||||||
max-width: 700px;
|
max-width: 700px;
|
||||||
width: auto;
|
width: auto;
|
||||||
|
@ -23,19 +23,32 @@ class EventController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function createEvent() {
|
public function createEvent() {
|
||||||
|
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
|
||||||
|
header('Location: index.php?controller=Event&do=showEvents');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $_POST['name'] ?? null,
|
'name' => $_POST['name'] ?? '',
|
||||||
'beschreibung' => $_POST['beschreibung'] ?? null,
|
'start_date' => $_POST['start_date'] ?? '',
|
||||||
'standortid' => $_POST['standortid'] ?? null,
|
'end_date' => $_POST['end_date'] ?? '',
|
||||||
'datum_von' => $_POST['datum_von'] ?? null,
|
'location_id' => $_POST['location_id'] ?? '',
|
||||||
'datum_bis' => $_POST['datum_bis'] ?? null,
|
'description' => $_POST['description'] ?? '',
|
||||||
'max_tickets' => $_POST['max_tickets'] ?? null,
|
'max_tickets' => $_POST['max_tickets'] ?? '',
|
||||||
'preis' => $_POST['preis'] ?? null
|
'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->model->createEvent($data);
|
||||||
$this->view->setVars(['event' => $data]);
|
$this->view->setDoMethodName('showCreateForwarding');
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function editEventForm() {
|
public function editEventForm() {
|
||||||
@ -64,9 +77,12 @@ class EventController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function showUpdateEvent() {
|
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;
|
$id = $_GET['event_id'] ?? null;
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
// handle error, e.g., redirect or show error message
|
|
||||||
$this->view->setVars(['error' => 'Keine Event-ID angegeben.']);
|
$this->view->setVars(['error' => 'Keine Event-ID angegeben.']);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -75,27 +91,33 @@ class EventController {
|
|||||||
$this->view->setVars(['error' => 'Event nicht gefunden.']);
|
$this->view->setVars(['error' => 'Event nicht gefunden.']);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Map DB fields to view fields if needed
|
$standortModel = new StandortModel();
|
||||||
|
$location = $standortModel->getStandort($event['location_id']);
|
||||||
$eventView = [
|
$eventView = [
|
||||||
'id' => $event['event_id'],
|
'id' => $event['event_id'],
|
||||||
'name' => $event['name'],
|
'name' => $event['name'],
|
||||||
'start_date' => $event['start_date'],
|
'start_date' => $event['start_date'],
|
||||||
'end_date' => $event['end_date'],
|
'end_date' => $event['end_date'],
|
||||||
'location_id' => $event['location_id'],
|
'location_id' => $event['location_id'],
|
||||||
|
'location_name' => $location['city'] ?? '',
|
||||||
'description' => $event['description'],
|
'description' => $event['description'],
|
||||||
'max_tickets' => $event['max_tickets'],
|
'max_tickets' => $event['max_tickets'],
|
||||||
'ticket_price' => $event['ticket_price'],
|
'ticket_price' => $event['ticket_price'],
|
||||||
];
|
];
|
||||||
// Fetch location name (city)
|
$this->view->setVars(['event' => $eventView, 'errors' => []]);
|
||||||
$standortModel = new StandortModel();
|
|
||||||
$location = $standortModel->getStandort($event['location_id']);
|
|
||||||
$eventView['location_name'] = $location['city'] ?? '';
|
|
||||||
$this->view->setVars(['event' => $eventView]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showCreateEvent() {
|
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();
|
$locations = $standortModel->getStandorte();
|
||||||
$this->view->setVars(['locations' => $locations]);
|
$this->view->setVars([
|
||||||
|
'locations' => $locations,
|
||||||
|
'errors' => [],
|
||||||
|
'validData' => []
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,36 +1,38 @@
|
|||||||
<div class="inhalt">
|
<div class="inhalt">
|
||||||
<h2>Create Event</h2>
|
<div class="form-container">
|
||||||
<form action="/Event/create" method="POST">
|
<h1>Event erstellen</h1>
|
||||||
<label>Event Name:</label>
|
<?php if (!empty(
|
||||||
<input type="text" name="name" required><br>
|
$errors['event'])): ?>
|
||||||
|
<div class="error-box"><?=htmlspecialchars($errors['event'])?></div>
|
||||||
<label>Start Date:</label>
|
<?php endif; ?>
|
||||||
<input type="date" name="start_date" required><br>
|
<form class="form-horizontal" action="index.php" method="post">
|
||||||
|
<input type="hidden" name="controller" value="Event">
|
||||||
<label>End Date:</label>
|
<input type="hidden" name="do" value="createEvent">
|
||||||
<input type="date" name="end_date" required><br>
|
<label for="name">Name</label>
|
||||||
|
<input type="text" name="name" id="name" required value="<?=htmlspecialchars($validData['name'] ?? '')?>">
|
||||||
<label>Location:</label>
|
<label for="start_date">Startdatum</label>
|
||||||
<select name="location_id" required>
|
<input type="date" name="start_date" id="start_date" required value="<?=htmlspecialchars($validData['start_date'] ?? '')?>">
|
||||||
<option value="">Select location</option>
|
<label for="end_date">Enddatum</label>
|
||||||
<?php if (!empty($locations)): ?>
|
<input type="date" name="end_date" id="end_date" required value="<?=htmlspecialchars($validData['end_date'] ?? '')?>">
|
||||||
<?php foreach ($locations as $loc): ?>
|
<label for="location_id">Standort</label>
|
||||||
<option value="<?= htmlspecialchars($loc['location_id']) ?>">
|
<select name="location_id" id="location_id" required>
|
||||||
<?= htmlspecialchars($loc['city']) ?>, <?= htmlspecialchars($loc['street']) ?> <?= htmlspecialchars($loc['house_number']) ?>
|
<option value="">Standort wählen</option>
|
||||||
</option>
|
<?php if (!empty($locations)): ?>
|
||||||
<?php endforeach; ?>
|
<?php foreach ($locations as $loc): ?>
|
||||||
<?php endif; ?>
|
<option value="<?= htmlspecialchars($loc['location_id']) ?>" <?= (isset($validData['location_id']) && $validData['location_id'] == $loc['location_id']) ? 'selected' : '' ?>>
|
||||||
</select><br>
|
<?= htmlspecialchars($loc['city']) ?>, <?= htmlspecialchars($loc['street']) ?> <?= htmlspecialchars($loc['house_number']) ?>
|
||||||
|
</option>
|
||||||
<label>Description:</label>
|
<?php endforeach; ?>
|
||||||
<textarea name="description" required></textarea><br>
|
<?php endif; ?>
|
||||||
|
</select>
|
||||||
<label>Max Tickets:</label>
|
<label for="description">Beschreibung</label>
|
||||||
<input type="number" name="max_tickets" required><br>
|
<textarea name="description" id="description" rows="7" required><?=htmlspecialchars($validData['description'] ?? '')?></textarea>
|
||||||
|
<label for="max_tickets">Max. Tickets</label>
|
||||||
<label>Ticket Price:</label>
|
<input type="number" name="max_tickets" id="max_tickets" required value="<?=htmlspecialchars($validData['max_tickets'] ?? '')?>">
|
||||||
<input type="number" step="0.01" name="ticket_price" required><br>
|
<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 type="submit">Create Event</button>
|
<button class="button-register" type="submit">Event erstellen</button>
|
||||||
</form>
|
</form>
|
||||||
|
<a href="?controller=Event&do=showEvents">Zurück zur Übersicht</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
@ -1,7 +1,12 @@
|
|||||||
<?php if (!empty($events)): ?>
|
<?php if (!empty($events)): ?>
|
||||||
<div class="inhalt">
|
<div class="inhalt">
|
||||||
<div class="content-container">
|
<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">
|
<div class="event-container-inhalt">
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
@ -11,6 +16,9 @@
|
|||||||
<th>Von</th>
|
<th>Von</th>
|
||||||
<th>Bis</th>
|
<th>Bis</th>
|
||||||
<th>Max. Tickets</th>
|
<th>Max. Tickets</th>
|
||||||
|
<?php if (isset($_SESSION['is_admin']) && $_SESSION['is_admin']): ?>
|
||||||
|
<th>Aktionen</th>
|
||||||
|
<?php endif; ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<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['start_date'])); ?></td>
|
||||||
<td><?php echo date('d.m.Y', strtotime($event['end_date'])); ?></td>
|
<td><?php echo date('d.m.Y', strtotime($event['end_date'])); ?></td>
|
||||||
<td><?php echo (int) $event['max_tickets']; ?></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>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -3,32 +3,35 @@ include dirname(__DIR__).'/header.phtml';
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="inhalt">
|
<div class="inhalt">
|
||||||
<h2>Update Event</h2>
|
<div class="form-container">
|
||||||
<form action="/Event/update?id=<?= htmlspecialchars($event['id']) ?>" method="POST">
|
<h1>Event bearbeiten</h1>
|
||||||
<label>Event Name:</label>
|
<?php if (!empty(
|
||||||
<input type="text" name="name" value="<?= htmlspecialchars($event['name']) ?>" required><br>
|
$errors['event'])): ?>
|
||||||
|
<div class="error-box"><?=htmlspecialchars($errors['event'])?></div>
|
||||||
<label>Start Date:</label>
|
<?php endif; ?>
|
||||||
<input type="date" name="start_date" value="<?= htmlspecialchars($event['start_date']) ?>" required><br>
|
<form class="form-horizontal" action="index.php" method="post">
|
||||||
|
<input type="hidden" name="controller" value="Event">
|
||||||
<label>End Date:</label>
|
<input type="hidden" name="do" value="updateEvent">
|
||||||
<input type="date" name="end_date" value="<?= htmlspecialchars($event['end_date']) ?>" required><br>
|
<input type="hidden" name="id" value="<?=htmlspecialchars($event['id'] ?? '')?>">
|
||||||
|
<label for="name">Name</label>
|
||||||
<label>Location:</label>
|
<input type="text" name="name" id="name" required value="<?=htmlspecialchars($event['name'] ?? '')?>">
|
||||||
<input type="text" name="location_name" value="<?= htmlspecialchars($event['location_name']) ?>" readonly><br>
|
<label for="start_date">Startdatum</label>
|
||||||
<input type="hidden" name="location_id" value="<?= htmlspecialchars($event['location_id']) ?>">
|
<input type="date" name="start_date" id="start_date" required value="<?=htmlspecialchars($event['start_date'] ?? '')?>">
|
||||||
|
<label for="end_date">Enddatum</label>
|
||||||
<label>Description:</label>
|
<input type="date" name="end_date" id="end_date" required value="<?=htmlspecialchars($event['end_date'] ?? '')?>">
|
||||||
<textarea name="description" required><?= htmlspecialchars($event['description']) ?></textarea><br>
|
<label for="location_id">Standort</label>
|
||||||
|
<input type="text" name="location_name" value="<?=htmlspecialchars($event['location_name'] ?? '')?>" readonly>
|
||||||
<label>Max Tickets:</label>
|
<input type="hidden" name="location_id" value="<?=htmlspecialchars($event['location_id'] ?? '')?>">
|
||||||
<input type="number" name="max_tickets" value="<?= htmlspecialchars($event['max_tickets']) ?>" required><br>
|
<label for="description">Beschreibung</label>
|
||||||
|
<textarea name="description" id="description" rows="7" required><?=htmlspecialchars($event['description'] ?? '')?></textarea>
|
||||||
<label>Ticket Price:</label>
|
<label for="max_tickets">Max. Tickets</label>
|
||||||
<input type="number" step="0.01" name="ticket_price" value="<?= htmlspecialchars($event['ticket_price']) ?>" required><br>
|
<input type="number" name="max_tickets" id="max_tickets" required value="<?=htmlspecialchars($event['max_tickets'] ?? '')?>">
|
||||||
|
<label for="ticket_price">Ticketpreis</label>
|
||||||
<button type="submit">Update Event</button>
|
<input type="number" step="0.01" name="ticket_price" id="ticket_price" required value="<?=htmlspecialchars($event['ticket_price'] ?? '')?>">
|
||||||
</form>
|
<button class="button-register" type="submit">Änderungen speichern</button>
|
||||||
|
</form>
|
||||||
|
<a href="?controller=Event&do=showEvents">Zurück zur Übersicht</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
<?php include dirname(__DIR__).'/footer.phtml'; ?>
|
Loading…
x
Reference in New Issue
Block a user