78 lines
3.1 KiB
PHP
78 lines
3.1 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'includes/header.php';
|
|
|
|
// Redirect to login if user is not authenticated
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit();
|
|
}
|
|
|
|
$trips = [];
|
|
$error_message = '';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT destination, trip_time, status, created_at FROM trips WHERE user_id = :user_id ORDER BY trip_time DESC");
|
|
$stmt->bindParam(':user_id', $_SESSION['user_id'], PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$trips = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
$error_message = 'Database error: ' . $e->getMessage();
|
|
}
|
|
|
|
$success_message = '';
|
|
if (isset($_GET['status']) && $_GET['status'] === 'success') {
|
|
$success_message = 'Your trip has been successfully saved!';
|
|
}
|
|
?>
|
|
|
|
<main class="py-5">
|
|
<section id="my-trips" class="container">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h2">My Planned Trips</h1>
|
|
<a href="trip-setup.php" class="btn btn-primary">Plan a New Trip</a>
|
|
</div>
|
|
|
|
<?php if (!empty($success_message)): ?>
|
|
<div class="alert alert-success"><?php echo htmlspecialchars($success_message); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (!empty($error_message)): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<?php if (empty($trips)): ?>
|
|
<p class="text-center text-muted">You have no planned trips yet.</p>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Destination</th>
|
|
<th>Date & Time</th>
|
|
<th>Status</th>
|
|
<th>Booked On</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($trips as $trip): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($trip['destination']); ?></td>
|
|
<td><?php echo htmlspecialchars(date('D, M j, Y, g:i A', strtotime($trip['trip_time']))); ?></td>
|
|
<td><span class="badge bg-primary"><?php echo htmlspecialchars(ucfirst($trip['status'])); ?></span></td>
|
|
<td><?php echo htmlspecialchars(date('M j, Y', strtotime($trip['created_at']))); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|