34830-vm/my-trips.php
Flatlogic Bot 952205e132 herway
2025-10-09 14:48:50 +00:00

143 lines
6.2 KiB
PHP

<?php
session_start();
require_once 'db/config.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!';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Trips - HerWay</title>
<meta name="description" content="View your planned trips on HerWay.">
<!-- Google Fonts: Poppins -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<!-- Header -->
<header class="navbar navbar-expand-lg navbar-light bg-light sticky-top">
<div class="container">
<a class="navbar-brand fw-bold" href="index.php">HerWay</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="index.php#features">Features</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#about">About</a></li>
<li class="nav-item"><a class="nav-link" href="index.php#contact">Contact</a></li>
<?php if (isset($_SESSION['user_id'])): ?>
<li class="nav-item"><a class="nav-link" href="my-trips.php">My Trips</a></li>
<li class="nav-item"><a class="btn btn-outline-primary ms-lg-3" href="logout.php">Logout</a></li>
<?php else: ?>
<li class="nav-item"><a class="nav-link" href="login.php">Login</a></li>
<li class="nav-item"><a class="btn btn-primary ms-lg-3" href="register.php">Sign Up</a></li>
<?php endif; ?>
</ul>
</div>
</div>
</header>
<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>
<!-- Footer -->
<footer class="py-4 bg-dark text-white">
<div class="container text-center">
<p>&copy; <?php echo date("Y"); ?> HerWay. All Rights Reserved.</p>
<p>
<a href="#" class="text-white">Privacy Policy</a> |
<a href="#" class="text-white">Terms of Service</a>
</p>
</div>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/main.js"></script>
</body>
</html>