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() { public function showTickets() {
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id'])) {
header('Location: index.php?controller=Auth&do=showLoginForm'); $this->view->setVars(['error' => 'Bitte melden Sie sich an, um Ihre Tickets zu sehen.']);
exit; $this->view->setDoMethodName('showLoginForm');
return;
} }
$tickets = $this->ticketModel->getUserTickets($_SESSION['user_id']); $tickets = $this->ticketModel->getUserTickets($_SESSION['user_id']);
@ -30,20 +31,23 @@ class TicketController {
public function showBuyTicketForm() { public function showBuyTicketForm() {
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id'])) {
header('Location: index.php?controller=Auth&do=showLoginForm'); $this->view->setVars(['error' => 'Bitte melden Sie sich an, um Tickets zu kaufen.']);
exit; $this->view->setDoMethodName('showLoginForm');
return;
} }
$event_id = $_GET['event_id'] ?? null; $event_id = $_GET['event_id'] ?? null;
if (!$event_id) { if (!$event_id) {
header('Location: index.php?controller=Event&do=showEvents'); $this->view->setVars(['error' => 'Keine Event-ID angegeben.']);
exit; $this->view->setDoMethodName('showEvents');
return;
} }
$event = $this->eventModel->getEvent($event_id); $event = $this->eventModel->getEvent($event_id);
if (!$event) { if (!$event) {
header('Location: index.php?controller=Event&do=showEvents'); $this->view->setVars(['error' => 'Event nicht gefunden.']);
exit; $this->view->setDoMethodName('showEvents');
return;
} }
// Check if user already has a ticket for this event // Check if user already has a ticket for this event
@ -107,8 +111,9 @@ class TicketController {
public function deleteTicket() { public function deleteTicket() {
if (!isset($_SESSION['user_id'])) { if (!isset($_SESSION['user_id'])) {
header('Location: index.php?controller=Auth&do=showLoginForm'); $this->view->setVars(['error' => 'Bitte melden Sie sich an.']);
exit; $this->view->setDoMethodName('showLoginForm');
return;
} }
$ticket_id = $_GET['ticket_id'] ?? null; $ticket_id = $_GET['ticket_id'] ?? null;
@ -116,7 +121,7 @@ class TicketController {
$this->ticketModel->deleteTicket($ticket_id); $this->ticketModel->deleteTicket($ticket_id);
} }
header('Location: index.php?controller=Ticket&do=showTickets'); // Redirect to tickets page using JavaScript
exit; $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)): ?> <?php if (isset($error)): ?>
<div class="error-box"><?= htmlspecialchars($error) ?></div> <div class="error-box"><?= htmlspecialchars($error) ?></div>
<?php endif; ?> <div style="text-align:center; margin-top: 1.5em;">
<a href="?controller=Event&do=showEvents">Zurück zu den Events</a>
<?php if (isset($event)): ?> </div>
<?php elseif (isset($event)): ?>
<div class="event-details"> <div class="event-details">
<h2><?= htmlspecialchars($event['name']) ?></h2> <h2><?= htmlspecialchars($event['name']) ?></h2>
<p><strong>Beschreibung:</strong> <?= nl2br(htmlspecialchars($event['description'])) ?></p> <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>Möchten Sie ein Ticket für dieses Event kaufen?</p>
<p><strong>Preis:</strong> <?= number_format($event['ticket_price'], 2, ',', '.') ?></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> </form>
<div style="text-align:center; margin-top: 1.5em;"> <div style="text-align:center; margin-top: 1.5em;">
@ -49,4 +50,10 @@ include dirname(__DIR__).'/header.phtml';
</div> </div>
</div> </div>
<?php if (isset($redirect)): ?>
<script>
window.location.href = '<?= $redirect ?>';
</script>
<?php endif; ?>
<?php include dirname(__DIR__).'/footer.phtml'; ?> <?php include dirname(__DIR__).'/footer.phtml'; ?>

View File

@ -8,7 +8,12 @@ include dirname(__DIR__).'/header.phtml';
<h2>Meine Tickets</h2> <h2>Meine Tickets</h2>
</div> </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"> <div class="event-container-inhalt">
<table> <table>
<thead> <thead>
@ -50,4 +55,10 @@ include dirname(__DIR__).'/header.phtml';
</div> </div>
</div> </div>
<?php if (isset($redirect)): ?>
<script>
window.location.href = '<?= $redirect ?>';
</script>
<?php endif; ?>
<?php include dirname(__DIR__).'/footer.phtml'; ?> <?php include dirname(__DIR__).'/footer.phtml'; ?>