152 lines
10 KiB
PHP
152 lines
10 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
// Fetch user's car listings
|
|
$stmt = $pdo->prepare("
|
|
SELECT c.*, ci.image_path
|
|
FROM cars c
|
|
LEFT JOIN car_images ci ON c.id = ci.car_id AND ci.is_main = 1
|
|
WHERE c.user_id = ? AND c.deleted_at IS NULL
|
|
ORDER BY c.created_at DESC
|
|
");
|
|
$stmt->execute([$user_id]);
|
|
$my_listings = $stmt->fetchAll();
|
|
|
|
// Fetch user's purchase requests
|
|
$stmt = $pdo->prepare("
|
|
SELECT p.*, c.brand, c.model, c.year, c.price, ci.image_path
|
|
FROM purchases p
|
|
JOIN cars c ON p.car_id = c.id
|
|
LEFT JOIN car_images ci ON c.id = ci.car_id AND ci.is_main = 1
|
|
WHERE p.user_id = ?
|
|
ORDER BY p.created_at DESC
|
|
");
|
|
$stmt->execute([$user_id]);
|
|
$my_purchases = $stmt->fetchAll();
|
|
?>
|
|
|
|
<div class="container" style="padding: 4rem 0;">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 4rem;">
|
|
<div>
|
|
<h1 style="font-size: 3rem; font-weight: 900; margin-bottom: 0.5rem; color: #fff;">User Dashboard</h1>
|
|
<p style="color: var(--text-secondary); font-size: 1.1rem;">Manage your vehicle listings and track your purchase requests.</p>
|
|
</div>
|
|
<a href="add_car.php" class="btn btn-primary">List New Vehicle</a>
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr; gap: 5rem;">
|
|
|
|
<!-- My Listings Section -->
|
|
<section>
|
|
<h2 style="font-size: 2rem; font-weight: 800; margin-bottom: 2.5rem; display: flex; align-items: center; gap: 1rem; color: #fff;">
|
|
<span style="background: var(--primary-color); color: #000; width: 45px; height: 45px; display: flex; align-items: center; justify-content: center; border-radius: 12px; font-size: 1.3rem;">🚗</span>
|
|
My Vehicle Listings
|
|
</h2>
|
|
|
|
<?php if (empty($my_listings)): ?>
|
|
<div class="box" style="padding: 5rem; text-align: center;">
|
|
<p style="color: var(--text-secondary); margin-bottom: 2rem; font-size: 1.2rem;">You haven't listed any vehicles yet.</p>
|
|
<a href="add_car.php" class="btn btn-outline">Start Selling Today</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 2.5rem;">
|
|
<?php foreach ($my_listings as $car): ?>
|
|
<div class="card" style="position: relative;">
|
|
<div style="height: 200px; background-image: url('<?= htmlspecialchars($car['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>'); background-size: cover; background-position: center;">
|
|
<?php if ($car['status'] === 'sold'): ?>
|
|
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 200px; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; color: var(--primary-color); font-weight: 900; font-size: 2.5rem; letter-spacing: 5px; text-shadow: 0 5px 15px rgba(0,0,0,0.5);">SOLD</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="card-content">
|
|
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem;">
|
|
<div>
|
|
<h3 style="font-size: 1.4rem; font-weight: 800; margin-bottom: 0.3rem; color: #fff;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h3>
|
|
<p style="color: var(--text-secondary); font-size: 0.9rem; font-weight: 600;"><?= $car['year'] ?> • <?= htmlspecialchars($car['city']) ?></p>
|
|
</div>
|
|
<span style="background: <?= $car['status'] === 'approved' ? 'var(--success)' : ($car['status'] === 'sold' ? 'rgba(255,255,255,0.1)' : ($car['status'] === 'rejected' ? 'var(--danger)' : 'var(--primary-color)')) ?>; color: <?= $car['status'] === 'approved' || $car['status'] === 'rejected' || $car['status'] === 'sold' ? '#fff' : '#000' ?>; padding: 0.4rem 0.8rem; border-radius: 8px; font-size: 0.75rem; text-transform: uppercase; font-weight: 800; letter-spacing: 0.5px;">
|
|
<?= $car['status'] ?>
|
|
</span>
|
|
</div>
|
|
<div style="display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--glass-border); padding-top: 1.5rem;">
|
|
<span style="font-weight: 900; color: var(--primary-color); font-size: 1.25rem;">$<?= number_format($car['price']) ?></span>
|
|
<a href="edit_car.php?id=<?= $car['id'] ?>" style="color: var(--text-primary); font-size: 0.95rem; font-weight: 700; text-decoration: none; display: flex; align-items: center; gap: 0.5rem;">
|
|
Edit Details <span style="color: var(--primary-color);">→</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
<!-- My Purchase Requests Section -->
|
|
<section>
|
|
<h2 style="font-size: 2rem; font-weight: 800; margin-bottom: 2.5rem; display: flex; align-items: center; gap: 1rem; color: #fff;">
|
|
<span style="background: var(--primary-color); color: #000; width: 45px; height: 45px; display: flex; align-items: center; justify-content: center; border-radius: 12px; font-size: 1.3rem;">💰</span>
|
|
My Purchase Requests
|
|
</h2>
|
|
|
|
<?php if (empty($my_purchases)): ?>
|
|
<div class="box" style="padding: 5rem; text-align: center;">
|
|
<p style="color: var(--text-secondary); margin-bottom: 2rem; font-size: 1.2rem;">You haven't made any purchase requests yet.</p>
|
|
<a href="cars.php" class="btn btn-outline">Browse Marketplace</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="box" style="overflow: hidden; padding: 0;">
|
|
<table style="width: 100%; border-collapse: collapse; text-align: left;">
|
|
<thead>
|
|
<tr style="background: rgba(255,255,255,0.02);">
|
|
<th style="padding: 1.5rem; font-weight: 800; font-size: 0.85rem; text-transform: uppercase; color: var(--text-secondary);">Vehicle</th>
|
|
<th style="padding: 1.5rem; font-weight: 800; font-size: 0.85rem; text-transform: uppercase; color: var(--text-secondary);">Price</th>
|
|
<th style="padding: 1.5rem; font-weight: 800; font-size: 0.85rem; text-transform: uppercase; color: var(--text-secondary);">Bank ID</th>
|
|
<th style="padding: 1.5rem; font-weight: 800; font-size: 0.85rem; text-transform: uppercase; color: var(--text-secondary);">Status</th>
|
|
<th style="padding: 1.5rem; font-weight: 800; font-size: 0.85rem; text-transform: uppercase; color: var(--text-secondary);">Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($my_purchases as $p): ?>
|
|
<tr style="border-bottom: 1px solid var(--glass-border);">
|
|
<td style="padding: 1.5rem;">
|
|
<div style="display: flex; align-items: center; gap: 1.2rem;">
|
|
<img src="<?= htmlspecialchars($p['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>" style="width: 80px; height: 50px; object-fit: cover; border-radius: 8px;">
|
|
<div>
|
|
<div style="font-weight: 800; font-size: 1.1rem; color: #fff;"><?= htmlspecialchars($p['brand'] . ' ' . $p['model']) ?></div>
|
|
<div style="font-size: 0.85rem; color: var(--text-secondary); font-weight: 600;"><?= $p['year'] ?> Model</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td style="padding: 1.5rem; font-weight: 900; color: var(--primary-color); font-size: 1.1rem;">$<?= number_format($p['price']) ?></td>
|
|
<td style="padding: 1.5rem;"><code style="font-size: 0.9rem; background: rgba(255,255,255,0.05); padding: 0.4rem 0.8rem; border-radius: 6px; font-weight: 700; color: var(--primary-color);"><?= htmlspecialchars($p['bank_id']) ?></code></td>
|
|
<td style="padding: 1.5rem;">
|
|
<span style="color: <?= $p['status'] === 'approved' ? 'var(--success)' : ($p['status'] === 'rejected' ? 'var(--danger)' : 'var(--primary-color)') ?>; font-weight: 800; font-size: 0.9rem; text-transform: uppercase;">
|
|
<?= $p['status'] ?>
|
|
</span>
|
|
</td>
|
|
<td style="padding: 1.5rem;">
|
|
<?php if ($p['status'] === 'approved'): ?>
|
|
<a href="receipt.php?id=<?= $p['id'] ?>" class="btn btn-primary btn-sm">View Receipt</a>
|
|
<?php else: ?>
|
|
<span style="color: var(--text-secondary); font-size: 0.9rem; font-weight: 600;">Under Review</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|