111 lines
5.6 KiB
PHP
111 lines
5.6 KiB
PHP
<?php
|
|
$page_title = "My Dashboard - AFG CARS";
|
|
include '../includes/header.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: ' . APP_URL . 'login.php');
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
// Stats
|
|
$stats = [
|
|
'active_listings' => $pdo->query("SELECT COUNT(*) FROM cars WHERE user_id = $user_id AND status = 'approved'")->fetchColumn(),
|
|
'pending_listings' => $pdo->query("SELECT COUNT(*) FROM cars WHERE user_id = $user_id AND status = 'pending'")->fetchColumn(),
|
|
'favorites' => $pdo->query("SELECT COUNT(*) FROM cars WHERE id IN (SELECT car_id FROM reviews WHERE user_id = $user_id)")->fetchColumn(), // Using reviews as proxy for favorites in this simple schema
|
|
];
|
|
|
|
// My Cars
|
|
$my_cars = $pdo->prepare("SELECT * FROM cars WHERE user_id = ? ORDER BY created_at DESC");
|
|
$my_cars->execute([$user_id]);
|
|
$cars = $my_cars->fetchAll();
|
|
?>
|
|
|
|
<div class="container py-5">
|
|
<div class="mb-4">
|
|
<a href="<?php echo APP_URL; ?>index.php" class="btn btn-link text-decoration-none p-0 text-muted">
|
|
<i class="bi bi-arrow-left me-1"></i> Back to Home
|
|
</a>
|
|
</div>
|
|
<div class="row g-5">
|
|
<!-- Sidebar -->
|
|
<div class="col-lg-3">
|
|
<div class="bg-white p-4 rounded-4 shadow-sm border">
|
|
<div class="text-center mb-4">
|
|
<div class="bg-primary text-white rounded-circle d-inline-flex align-items-center justify-content-center mb-3" style="width: 80px; height: 80px; font-size: 2rem;">
|
|
<?php echo strtoupper(substr($_SESSION['user_name'], 0, 1)); ?>
|
|
</div>
|
|
<h5 class="fw-bold mb-0"><?php echo htmlspecialchars($_SESSION['user_name']); ?></h5>
|
|
<p class="text-muted small"><?php echo htmlspecialchars($_SESSION['user_email']); ?></p>
|
|
</div>
|
|
|
|
<div class="list-group list-group-flush">
|
|
<a href="dashboard.php" class="list-group-item list-group-item-action border-0 px-0 active">My Listings</a>
|
|
<a href="add-car.php" class="list-group-item list-group-item-action border-0 px-0 text-primary fw-bold">Sell New Car</a>
|
|
<a href="<?php echo APP_URL; ?>logout.php" class="list-group-item list-group-item-action border-0 px-0 text-danger">Logout</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main Content -->
|
|
<div class="col-lg-9">
|
|
<div class="row g-4 mb-5">
|
|
<div class="col-md-4">
|
|
<div class="bg-white p-4 rounded-4 shadow-sm border text-center">
|
|
<div class="text-muted small mb-1">Active Ads</div>
|
|
<h2 class="fw-bold mb-0"><?php echo $stats['active_listings']; ?></h2>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="bg-white p-4 rounded-4 shadow-sm border text-center">
|
|
<div class="text-muted small mb-1">Pending</div>
|
|
<h2 class="fw-bold mb-0 text-warning"><?php echo $stats['pending_listings']; ?></h2>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="bg-white p-4 rounded-4 shadow-sm border text-center">
|
|
<div class="text-muted small mb-1">Total Sales</div>
|
|
<h2 class="fw-bold mb-0 text-success">$0</h2>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h4 class="fw-bold">My Car Listings</h4>
|
|
<a href="add-car.php" class="btn btn-primary px-4">Start Selling</a>
|
|
</div>
|
|
|
|
<?php if (empty($cars)): ?>
|
|
<div class="text-center py-5 bg-white rounded-4 border">
|
|
<i class="bi bi-car-front text-muted display-1 mb-3"></i>
|
|
<h5>No listings found.</h5>
|
|
<p class="text-muted">You haven't listed any cars for sale yet.</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="row g-4">
|
|
<?php foreach ($cars as $car): ?>
|
|
<div class="col-md-12">
|
|
<div class="bg-white p-3 rounded-4 shadow-sm border d-flex gap-4 align-items-center">
|
|
<img src="<?php echo htmlspecialchars($car['image']); ?>" class="rounded-3" style="width: 150px; height: 100px; object-fit: cover;">
|
|
<div class="flex-grow-1">
|
|
<h6 class="fw-bold mb-1"><?php echo htmlspecialchars($car['title']); ?></h6>
|
|
<div class="text-muted small mb-2">$<?php echo number_format($car['price']); ?> • <?php echo $car['location']; ?></div>
|
|
<span class="badge <?php echo $car['status'] === 'approved' ? 'bg-success' : 'bg-warning'; ?> rounded-pill">
|
|
<?php echo strtoupper($car['status']); ?>
|
|
</span>
|
|
</div>
|
|
<div class="pe-3">
|
|
<a href="<?php echo APP_URL; ?>car-details.php?id=<?php echo $car['id']; ?>" class="btn btn-sm btn-outline-primary px-3">View</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include '../includes/footer.php'; ?>
|