38395-vm/favorites.php
Flatlogic Bot 4a91088287 sadiq
2026-02-13 15:07:39 +00:00

57 lines
2.7 KiB
PHP

<?php
$page_title = "My Favorites - AFG CARS";
include 'includes/header.php';
if (!$is_logged_in) {
header('Location: ' . APP_URL . 'login.php');
exit;
}
$pdo = db();
$stmt = $pdo->prepare("SELECT c.* FROM cars c JOIN favorites f ON c.id = f.car_id WHERE f.user_id = ?");
$stmt->execute([$_SESSION['user_id']]);
$favs = $stmt->fetchAll();
?>
<div class="container py-5">
<h2 class="fw-bold mb-4">My Favorites</h2>
<div class="row g-4">
<?php if (empty($favs)): ?>
<div class="col-12 text-center py-5">
<i class="bi bi-heart display-1 text-muted opacity-25 mb-4 d-block"></i>
<h5>Your favorites list is empty</h5>
<p class="text-muted">Save cars you like to view them later.</p>
<a href="<?php echo APP_URL; ?>cars.php" class="btn btn-primary mt-3">Browse Cars</a>
</div>
<?php else: ?>
<?php foreach ($favs as $car): ?>
<div class="col-md-4">
<div class="car-card bg-white h-100 d-flex flex-column">
<div class="position-relative">
<img src="<?php echo htmlspecialchars($car['image']); ?>" class="card-img-top" alt="...">
<div class="position-absolute top-0 end-0 m-3">
<a href="<?php echo APP_URL; ?>toggle-favorite.php?id=<?php echo $car['id']; ?>&action=remove" class="btn btn-danger btn-sm rounded-circle shadow">
<i class="bi bi-trash"></i>
</a>
</div>
</div>
<div class="card-body p-4 flex-grow-1 d-flex flex-column">
<h5 class="fw-bold mb-2"><?php echo htmlspecialchars($car['title']); ?></h5>
<div class="d-flex align-items-center gap-3 text-muted small mb-4">
<span><i class="bi bi-geo-alt me-1"></i><?php echo htmlspecialchars($car['location']); ?></span>
<span><i class="bi bi-speedometer2 me-1"></i><?php echo number_format($car['mileage']); ?> km</span>
</div>
<div class="mt-auto d-flex justify-content-between align-items-center">
<span class="price-tag">$<?php echo number_format($car['price']); ?></span>
<a href="<?php echo APP_URL; ?>car-details.php?id=<?php echo $car['id']; ?>" class="btn btn-primary btn-sm px-4">Details</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<?php include 'includes/footer.php'; ?>