38701-vm/car_detail.php
Flatlogic Bot 5db61988c3 sadiq
2026-02-23 06:39:28 +00:00

203 lines
12 KiB
PHP

<?php
$title = "Car Details";
require_once __DIR__ . '/includes/header.php';
$car_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$db = db();
// Fetch Car Details
$stmt = $db->prepare("SELECT cars.*, users.full_name as seller_name FROM cars JOIN users ON cars.user_id = users.id WHERE cars.id = ? AND cars.is_deleted = 0 LIMIT 1");
$stmt->execute([$car_id]);
$car = $stmt->fetch();
if (!$car) {
echo "<div class='container' style='padding: 5rem 0; text-align: center;'><h1 class='hero'>Car Not Found</h1><p style='color: var(--text-muted);'>The car you are looking for does not exist or has been removed.</p><a href='cars.php' class='btn btn-primary' style='margin-top: 2rem;'>Back to Marketplace</a></div>";
require_once __DIR__ . '/includes/footer.php';
exit;
}
// Fetch Images
$imgStmt = $db->prepare("SELECT * FROM car_images WHERE car_id = ? ORDER BY is_main DESC");
$imgStmt->execute([$car_id]);
$images = $imgStmt->fetchAll();
// Fetch Similar Cars
$similarStmt = $db->prepare("SELECT * FROM cars WHERE brand = ? AND id != ? AND is_deleted = 0 AND status = 'Available' LIMIT 3");
$similarStmt->execute([$car['brand'], $car_id]);
$similarCars = $similarStmt->fetchAll();
?>
<div class="container" style="padding: 3rem 0;">
<!-- Breadcrumbs / Top Navigation -->
<div style="margin-bottom: 2rem; color: var(--text-muted);">
<a href="index.php">Home</a> / <a href="cars.php">Marketplace</a> / <?php echo htmlspecialchars($car['title']); ?>
</div>
<div style="display: grid; grid-template-columns: 1.5fr 1fr; gap: 3rem;">
<!-- Left: Image Gallery & Description -->
<div>
<!-- Main Image -->
<div class="glass-card car-image" style="height: 500px; border-radius: var(--radius-lg); overflow: hidden;">
<?php
$mainImg = !empty($images) ? $images[0]['image_path'] : 'assets/images/pexels/placeholder_car.jpg';
?>
<img id="main-display-img" src="<?php echo htmlspecialchars($mainImg); ?>" alt="<?php echo htmlspecialchars($car['title']); ?>"
onerror="this.src='https://images.pexels.com/photos/170811/pexels-photo-170811.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1'"
style="width: 100%; height: 100%; object-fit: cover;">
<?php if ($car['is_hot_deal']): ?>
<span class="badge badge-hot">HOT DEAL</span>
<?php endif; ?>
<?php if ($car['status'] == 'SOLD'): ?>
<span class="badge badge-sold">SOLD</span>
<?php endif; ?>
</div>
<!-- Thumbnail Gallery -->
<div style="display: flex; gap: 1rem; margin-top: 1rem; overflow-x: auto; padding-bottom: 0.5rem;">
<?php foreach ($images as $img): ?>
<div class="glass-card" style="width: 100px; height: 80px; flex-shrink: 0; cursor: pointer; border-radius: var(--radius-md); overflow: hidden;">
<img src="<?php echo htmlspecialchars($img['image_path']); ?>" alt="Car Thumb"
style="width: 100%; height: 100%; object-fit: cover;"
onclick="document.getElementById('main-display-img').src=this.src">
</div>
<?php endforeach; ?>
<?php if (count($images) < 2): ?>
<!-- Mock thumbnails for demonstration -->
<div class="glass-card" style="width: 100px; height: 80px; flex-shrink: 0; cursor: pointer; border-radius: var(--radius-md); overflow: hidden;">
<img src="https://images.pexels.com/photos/210019/pexels-photo-210019.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" style="width: 100%; height: 100%; object-fit: cover;" onclick="document.getElementById('main-display-img').src=this.src">
</div>
<div class="glass-card" style="width: 100px; height: 80px; flex-shrink: 0; cursor: pointer; border-radius: var(--radius-md); overflow: hidden;">
<img src="https://images.pexels.com/photos/112460/pexels-photo-112460.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" style="width: 100%; height: 100%; object-fit: cover;" onclick="document.getElementById('main-display-img').src=this.src">
</div>
<?php endif; ?>
</div>
<!-- Description -->
<div class="glass-card" style="margin-top: 3rem; padding: 2.5rem;">
<h3>Description</h3>
<p style="color: var(--text-muted); white-space: pre-line; line-height: 1.8;">
<?php echo htmlspecialchars($car['description']); ?>
</p>
<h3 style="margin-top: 2.5rem;">Specifications</h3>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1.5rem;">
<div style="display: flex; justify-content: space-between; border-bottom: 1px solid var(--border-glass); padding-bottom: 0.5rem;">
<span style="color: var(--text-muted);">Fuel Type</span>
<strong><?php echo htmlspecialchars($car['fuel_type']); ?></strong>
</div>
<div style="display: flex; justify-content: space-between; border-bottom: 1px solid var(--border-glass); padding-bottom: 0.5rem;">
<span style="color: var(--text-muted);">Transmission</span>
<strong><?php echo htmlspecialchars($car['transmission']); ?></strong>
</div>
<div style="display: flex; justify-content: space-between; border-bottom: 1px solid var(--border-glass); padding-bottom: 0.5rem;">
<span style="color: var(--text-muted);">Condition</span>
<strong><?php echo htmlspecialchars($car['condition']); ?></strong>
</div>
<div style="display: flex; justify-content: space-between; border-bottom: 1px solid var(--border-glass); padding-bottom: 0.5rem;">
<span style="color: var(--text-muted);">Mileage</span>
<strong><?php echo number_format($car['mileage']); ?> km</strong>
</div>
</div>
</div>
<!-- Reviews Section Placeholder -->
<div class="glass-card" style="margin-top: 3rem; padding: 2.5rem;">
<h3>Customer Reviews</h3>
<div style="margin-top: 1.5rem; padding: 1.5rem; background: var(--bg-glass); border-radius: var(--radius-md); border-left: 4px solid var(--primary);">
<div style="display: flex; justify-content: space-between; margin-bottom: 0.5rem;">
<strong>Ahmadullah Karimi</strong>
<span style="color: var(--accent);">★★★★★</span>
</div>
<p style="color: var(--text-muted); font-size: 0.9rem;">The car is in amazing condition. The seller was very professional and the viewing at Kabul showroom was smooth.</p>
</div>
<div style="margin-top: 2rem; text-align: center;">
<a href="login.php" class="btn btn-outline">Login to write a review</a>
</div>
</div>
</div>
<!-- Right: Actions & Seller Info -->
<div>
<div class="glass-card" style="padding: 2.5rem; position: sticky; top: 100px;">
<h1 style="margin-bottom: 0.5rem;"><?php echo htmlspecialchars($car['brand'] . ' ' . $car['model']); ?></h1>
<p style="color: var(--text-muted); font-size: 1.2rem; margin-bottom: 1.5rem;"><?php echo htmlspecialchars($car['year']); ?> Model | <?php echo htmlspecialchars($car['city']); ?></p>
<div class="car-price" style="font-size: 2.5rem; margin-bottom: 2rem;">
$<?php echo number_format($car['price'], 0); ?>
</div>
<?php if ($car['status'] == 'Available'): ?>
<button class="btn btn-primary" style="width: 100%; padding: 1rem; font-size: 1.2rem; margin-bottom: 1rem;"
onclick="window.location.href='purchase.php?id=<?php echo $car['id']; ?>'">
Purchase Now (Bank Simulation)
</button>
<button class="btn btn-outline" style="width: 100%; padding: 1rem; font-size: 1.2rem; margin-bottom: 2rem;"
onclick="alert('Added to favorites!')">
Add to Favorites
</button>
<?php else: ?>
<button class="btn btn-outline" style="width: 100%; padding: 1rem; font-size: 1.2rem; margin-bottom: 2rem; cursor: not-allowed;" disabled>
Already SOLD
</button>
<?php endif; ?>
<!-- Seller Info -->
<div style="border-top: 1px solid var(--border-glass); padding-top: 2rem;">
<h4 style="margin-bottom: 1rem;">Seller Information</h4>
<div style="display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem;">
<div style="width: 50px; height: 50px; border-radius: 50%; background: var(--bg-glass); display: flex; align-items: center; justify-content: center; font-weight: bold; border: 1px solid var(--border-glass);">
<?php echo strtoupper(substr($car['seller_name'], 0, 1)); ?>
</div>
<div>
<strong><?php echo htmlspecialchars($car['seller_name']); ?></strong>
<p style="color: var(--text-muted); font-size: 0.8rem;">Verified Premium Seller</p>
</div>
</div>
<h4 style="margin-bottom: 1rem;">Contact Seller</h4>
<form action="#" method="POST">
<div class="form-group" style="margin-bottom: 1rem;">
<textarea class="form-control" rows="4" placeholder="I am interested in this car. Please contact me."></textarea>
</div>
<button type="button" class="btn btn-outline" style="width: 100%;" onclick="alert('Message sent to seller!')">Send Message</button>
</form>
</div>
<div style="margin-top: 2rem; padding: 1rem; background: rgba(56, 189, 248, 0.05); border-radius: var(--radius-md); text-align: center;">
<p style="font-size: 0.8rem; color: var(--text-muted);">📍 Showroom: <br><strong><?php echo htmlspecialchars($car['city']); ?> Premium Showroom</strong></p>
</div>
</div>
</div>
</div>
<!-- Similar Cars Section -->
<?php if (!empty($similarCars)): ?>
<section style="margin-top: 5rem;">
<h2 style="margin-bottom: 2rem;">Similar Cars</h2>
<div class="car-grid">
<?php foreach ($similarCars as $sCar): ?>
<a href="car_detail.php?id=<?php echo $sCar['id']; ?>" class="car-card glass-card">
<div class="car-image">
<?php
$sImgStmt = $db->prepare("SELECT image_path FROM car_images WHERE car_id = ? AND is_main = 1 LIMIT 1");
$sImgStmt->execute([$sCar['id']]);
$sMainImg = $sImgStmt->fetchColumn();
?>
<img src="<?php echo htmlspecialchars($sMainImg ?: 'https://images.pexels.com/photos/170811/pexels-photo-170811.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1'); ?>" alt="Similar Car">
</div>
<div class="car-info">
<h3 style="font-size: 1.1rem;"><?php echo htmlspecialchars($sCar['title']); ?></h3>
<div class="car-price">$<?php echo number_format($sCar['price'], 0); ?></div>
</div>
</a>
<?php endforeach; ?>
</div>
</section>
<?php endif; ?>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>