fixed the redirect

to handle everything properly
This commit is contained in:
Viktor Sergeev 2025-07-11 22:55:51 +02:00
parent a881b3933d
commit f780888107
3 changed files with 40 additions and 17 deletions

View File

@ -20,8 +20,9 @@ class TicketController {
public function showTickets() {
if (!isset($_SESSION['user_id'])) {
header('Location: index.php?controller=Auth&do=showLoginForm');
exit;
$this->view->setVars(['error' => 'Bitte melden Sie sich an, um Ihre Tickets zu sehen.']);
$this->view->setDoMethodName('showLoginForm');
return;
}
$tickets = $this->ticketModel->getUserTickets($_SESSION['user_id']);
@ -30,20 +31,23 @@ class TicketController {
public function showBuyTicketForm() {
if (!isset($_SESSION['user_id'])) {
header('Location: index.php?controller=Auth&do=showLoginForm');
exit;
$this->view->setVars(['error' => 'Bitte melden Sie sich an, um Tickets zu kaufen.']);
$this->view->setDoMethodName('showLoginForm');
return;
}
$event_id = $_GET['event_id'] ?? null;
if (!$event_id) {
header('Location: index.php?controller=Event&do=showEvents');
exit;
$this->view->setVars(['error' => 'Keine Event-ID angegeben.']);
$this->view->setDoMethodName('showEvents');
return;
}
$event = $this->eventModel->getEvent($event_id);
if (!$event) {
header('Location: index.php?controller=Event&do=showEvents');
exit;
$this->view->setVars(['error' => 'Event nicht gefunden.']);
$this->view->setDoMethodName('showEvents');
return;
}
// Check if user already has a ticket for this event
@ -107,8 +111,9 @@ class TicketController {
public function deleteTicket() {
if (!isset($_SESSION['user_id'])) {
header('Location: index.php?controller=Auth&do=showLoginForm');
exit;
$this->view->setVars(['error' => 'Bitte melden Sie sich an.']);
$this->view->setDoMethodName('showLoginForm');
return;
}
$ticket_id = $_GET['ticket_id'] ?? null;
@ -116,7 +121,7 @@ class TicketController {
$this->ticketModel->deleteTicket($ticket_id);
}
header('Location: index.php?controller=Ticket&do=showTickets');
exit;
// Redirect to tickets page using JavaScript
$this->view->setVars(['redirect' => 'index.php?controller=Ticket&do=showTickets']);
}
}

View File

@ -8,9 +8,10 @@ include dirname(__DIR__).'/header.phtml';
<?php if (isset($error)): ?>
<div class="error-box"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<?php if (isset($event)): ?>
<div style="text-align:center; margin-top: 1.5em;">
<a href="?controller=Event&do=showEvents">Zurück zu den Events</a>
</div>
<?php elseif (isset($event)): ?>
<div class="event-details">
<h2><?= htmlspecialchars($event['name']) ?></h2>
<p><strong>Beschreibung:</strong> <?= nl2br(htmlspecialchars($event['description'])) ?></p>
@ -33,7 +34,7 @@ include dirname(__DIR__).'/header.phtml';
<p>Möchten Sie ein Ticket für dieses Event kaufen?</p>
<p><strong>Preis:</strong> <?= number_format($event['ticket_price'], 2, ',', '.') ?></p>
<button class="button-login" type="submit">Ticket kaufen</button>
<button class="button-login" type="submit">Jetzt kaufen</button>
</form>
<div style="text-align:center; margin-top: 1.5em;">
@ -49,4 +50,10 @@ include dirname(__DIR__).'/header.phtml';
</div>
</div>
<?php if (isset($redirect)): ?>
<script>
window.location.href = '<?= $redirect ?>';
</script>
<?php endif; ?>
<?php include dirname(__DIR__).'/footer.phtml'; ?>

View File

@ -8,7 +8,12 @@ include dirname(__DIR__).'/header.phtml';
<h2>Meine Tickets</h2>
</div>
<?php if (!empty($tickets)): ?>
<?php if (isset($error)): ?>
<div class="error-box"><?= htmlspecialchars($error) ?></div>
<div style="text-align:center; margin-top: 1.5em;">
<a href="?controller=Auth&do=showLoginForm">Zum Login</a>
</div>
<?php elseif (!empty($tickets)): ?>
<div class="event-container-inhalt">
<table>
<thead>
@ -50,4 +55,10 @@ include dirname(__DIR__).'/header.phtml';
</div>
</div>
<?php if (isset($redirect)): ?>
<script>
window.location.href = '<?= $redirect ?>';
</script>
<?php endif; ?>
<?php include dirname(__DIR__).'/footer.phtml'; ?>