This commit is contained in:
Flatlogic Bot 2026-02-23 10:20:56 +00:00
parent 5f8729e07e
commit a53d29cad2
11 changed files with 765 additions and 413 deletions

View File

@ -8,6 +8,12 @@ if (!isset($_SESSION['user_id'])) {
$error = '';
$success = false;
$pdo = db();
// Fetch current user details to pre-fill
$stmt = $pdo->prepare("SELECT phone, address FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user_info = $stmt->fetch();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$brand = $_POST['brand'] ?? '';
@ -16,9 +22,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$price = $_POST['price'] ?? '';
$city = $_POST['city'] ?? '';
$description = $_POST['description'] ?? '';
$image_url = $_POST['image_url'] ?? ''; // For simplicity, we use URL or placeholder
$phone = $_POST['phone'] ?? '';
$address = $_POST['address'] ?? '';
$pdo = db();
// Update user info if provided
if ($phone || $address) {
$stmt = $pdo->prepare("UPDATE users SET phone = ?, address = ? WHERE id = ?");
$stmt->execute([$phone, $address, $_SESSION['user_id']]);
}
try {
$pdo->beginTransaction();
@ -26,9 +38,34 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stmt->execute([$_SESSION['user_id'], $brand, $model, $year, $price, $city, $description]);
$carId = $pdo->lastInsertId();
if ($image_url) {
// Handle Image Upload
if (isset($_FILES['car_image']) && $_FILES['car_image']['error'] === UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['car_image']['tmp_name'];
$fileName = $_FILES['car_image']['name'];
$fileSize = $_FILES['car_image']['size'];
$fileType = $_FILES['car_image']['type'];
$fileNameCmps = explode(".", $fileName);
$fileExtension = strtolower(end($fileNameCmps));
$allowedfileExtensions = array('jpg', 'gif', 'png', 'jpeg', 'webp');
if (in_array($fileExtension, $allowedfileExtensions)) {
$uploadFileDir = './assets/images/uploads/';
$newFileName = md5(time() . $fileName) . '.' . $fileExtension;
$dest_path = $uploadFileDir . $newFileName;
if(move_uploaded_file($fileTmpPath, $dest_path)) {
$imagePath = 'assets/images/uploads/' . $newFileName;
$stmt = $pdo->prepare("INSERT INTO car_images (car_id, image_path, is_main) VALUES (?, ?, 1)");
$stmt->execute([$carId, $imagePath]);
} else {
throw new Exception("There was an error moving the uploaded file.");
}
} else {
throw new Exception("Upload failed. Allowed file types: " . implode(',', $allowedfileExtensions));
}
} else if (!empty($_POST['image_url'])) {
$stmt = $pdo->prepare("INSERT INTO car_images (car_id, image_path, is_main) VALUES (?, ?, 1)");
$stmt->execute([$carId, $image_url]);
$stmt->execute([$carId, $_POST['image_url']]);
}
$pdo->commit();
@ -42,15 +79,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$cities = ['Kabul', 'Herat', 'Mazar-i-Sharif', 'Kandahar', 'Jalalabad', 'Kunduz', 'Ghazni', 'Balkh'];
?>
<div class="container" style="max-width: 800px;">
<div class="container" style="max-width: 900px;">
<div class="box" style="padding: 4rem;">
<h1 style="margin-bottom: 1rem; font-size: 2.5rem; font-weight: 900;">List Your Vehicle</h1>
<p style="color: var(--text-secondary); margin-bottom: 3rem;">Provide details about your car. Our team will review and approve your listing within 24 hours.</p>
<p style="color: var(--text-secondary); margin-bottom: 3rem;">Provide details about your car and yourself. Our team will review and approve your listing.</p>
<?php if ($success): ?>
<div class="glass" style="padding: 2rem; border-color: var(--success); background: rgba(46, 213, 115, 0.05); color: var(--success); margin-bottom: 3rem; text-align: center; border-radius: 16px;">
<h3 style="margin-bottom: 0.5rem;">🎉 Listing Submitted!</h3>
<p>Your car has been sent for approval. You can track its status in your dashboard.</p>
<p>Your car and seller information have been sent for approval. You can track its status in your dashboard.</p>
<div style="margin-top: 1.5rem;">
<a href="dashboard.php" class="btn btn-primary btn-sm">Go to Dashboard</a>
</div>
@ -61,7 +98,8 @@ $cities = ['Kabul', 'Herat', 'Mazar-i-Sharif', 'Kandahar', 'Jalalabad', 'Kunduz'
<div class="alert alert-error" style="margin-bottom: 2rem;"><?= $error ?></div>
<?php endif; ?>
<form method="POST">
<form method="POST" enctype="multipart/form-data">
<h3 style="margin-bottom: 1.5rem; color: var(--primary-color);">1. Vehicle Details</h3>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;">
<div class="form-group">
<label>Brand</label>
@ -94,22 +132,55 @@ $cities = ['Kabul', 'Herat', 'Mazar-i-Sharif', 'Kandahar', 'Jalalabad', 'Kunduz'
</div>
<div class="form-group">
<label>Image URL (Optional)</label>
<input type="url" name="image_url" class="form-control" placeholder="https://example.com/car.jpg">
<small style="color: var(--text-secondary); margin-top: 0.5rem; display: block;">For this prototype, please provide a direct link to an image.</small>
<label>Vehicle Photo</label>
<div class="glass" style="padding: 2rem; text-align: center; border: 2px dashed var(--glass-border); border-radius: 12px;">
<input type="file" name="car_image" id="car_image" style="display: none;" accept="image/*">
<label for="car_image" style="cursor: pointer;">
<div style="font-size: 2.5rem; margin-bottom: 1rem;">📸</div>
<div style="font-weight: 700; color: var(--primary-color);">Click to upload photo</div>
<div style="font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.5rem;">JPG, PNG or WEBP (Max 5MB)</div>
</label>
<div id="file-name" style="margin-top: 1rem; font-weight: 600; color: var(--success); display: none;"></div>
</div>
<div style="margin-top: 1rem;">
<label>Or Image URL</label>
<input type="url" name="image_url" class="form-control" placeholder="https://example.com/car.jpg">
</div>
</div>
<div class="form-group">
<label>Description</label>
<textarea name="description" class="form-control" rows="5" required placeholder="Describe the condition, features, and any other relevant details..."></textarea>
<textarea name="description" class="form-control" rows="4" required placeholder="Describe the condition, features..."></textarea>
</div>
<hr style="margin: 3rem 0; border: 0; border-top: 1px solid var(--glass-border);">
<h3 style="margin-bottom: 1.5rem; color: var(--primary-color);">2. Seller Information</h3>
<div class="form-group">
<label>Phone Number</label>
<input type="text" name="phone" class="form-control" required placeholder="+93 7xx xxx xxx" value="<?= htmlspecialchars($user_info['phone'] ?? '') ?>">
</div>
<div class="form-group">
<label>Location/Address</label>
<textarea name="address" class="form-control" rows="2" required placeholder="Detailed address for vehicle inspection..."><?= htmlspecialchars($user_info['address'] ?? '') ?></textarea>
</div>
<div style="margin-top: 3rem; display: flex; gap: 1.5rem;">
<button type="submit" class="btn btn-primary" style="flex: 2; padding: 1.2rem;">Submit Listing</button>
<button type="submit" class="btn btn-primary" style="flex: 2; padding: 1.2rem; font-size: 1.1rem; font-weight: 700;">Submit for Approval</button>
<a href="dashboard.php" class="btn btn-outline" style="flex: 1; text-align: center; padding: 1.2rem;">Cancel</a>
</div>
</form>
</div>
</div>
<script>
document.getElementById('car_image').onchange = function() {
if (this.files && this.files[0]) {
const fileName = document.getElementById('file-name');
fileName.textContent = 'Selected: ' + this.files[0].name;
fileName.style.display = 'block';
}
};
</script>
<?php require_once __DIR__ . '/includes/footer.php'; ?>

View File

@ -1,116 +1,119 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/header.php';
if (!isset($_SESSION['user_id']) || ($_SESSION['role'] ?? '') !== 'admin') {
header('Location: login.php');
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
header('Location: index.php');
exit;
}
$pdo = db();
$message = '';
// Handle Status Changes
if (isset($_GET['action']) && isset($_GET['id'])) {
$action = $_GET['action'];
$id = $_GET['id'];
if (isset($_POST['action']) && isset($_POST['car_id'])) {
$car_id = $_POST['car_id'];
$action = $_POST['action'];
$status = ($action === 'approve') ? 'approved' : 'rejected';
if ($action === 'approve') {
$pdo->prepare("UPDATE cars SET status = 'approved' WHERE id = ?")->execute([$id]);
} elseif ($action === 'reject') {
$pdo->prepare("UPDATE cars SET status = 'rejected' WHERE id = ?")->execute([$id]);
} elseif ($action === 'hot') {
$pdo->prepare("UPDATE cars SET is_hot_deal = NOT is_hot_deal WHERE id = ?")->execute([$id]);
} elseif ($action === 'delete') {
$pdo->prepare("UPDATE cars SET deleted_at = NOW() WHERE id = ?")->execute([$id]);
$stmt = $pdo->prepare("UPDATE cars SET status = ? WHERE id = ?");
if ($stmt->execute([$status, $car_id])) {
$message = "Car listing " . ($status === 'approved' ? 'approved' : 'rejected') . " successfully.";
}
header('Location: admin_cars.php');
exit;
}
$cars = $pdo->query("
SELECT c.*, u.name as owner_name
FROM cars c
JOIN users u ON c.user_id = u.id
WHERE c.deleted_at IS NULL
ORDER BY c.created_at DESC
")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Cars | Admin</title>
<link rel="stylesheet" href="assets/css/style.css?v=<?= time() ?>">
</head>
<body style="background: #050505;">
<div class="dashboard-container">
<aside class="sidebar">
<a href="index.php" class="sidebar-brand">AFGCARS</a>
<ul class="sidebar-menu">
<li><a href="admin_dashboard.php"><span>Dashboard</span></a></li>
<li><a href="admin_cars.php" class="active"><span>Manage Cars</span></a></li>
<li><a href="admin_users.php"><span>Users</span></a></li>
<li><a href="admin_messages.php"><span>Messages</span></a></li>
</ul>
<div class="sidebar-footer">
<a href="logout.php" style="color: var(--danger); text-decoration: none; font-weight: 600;">Logout</a>
</div>
</aside>
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$stmt = $pdo->prepare("UPDATE cars SET deleted_at = NOW() WHERE id = ?");
if ($stmt->execute([$id])) {
$message = "Car deleted successfully.";
}
}
<main class="main-content">
<h1 style="margin-bottom: 2rem; font-weight: 900;">Manage Car Listings</h1>
<div class="glass" style="padding: 2rem;">
<div class="table-container">
<table>
<thead>
<tr>
<th>Car Details</th>
<th>Owner</th>
<th>Price</th>
<th>Status</th>
<th>Featured</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($cars as $car): ?>
<tr>
<td>
<div style="font-weight: 700;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></div>
<div style="font-size: 0.8rem; color: var(--text-secondary);"><?= $car['year'] ?> - <?= $car['city'] ?></div>
</td>
<td><?= htmlspecialchars($car['owner_name']) ?></td>
<td style="font-weight: 700; color: var(--primary-color);">$<?= number_format($car['price']) ?></td>
<td>
<span class="badge badge-<?= $car['status'] === 'approved' ? 'success' : ($car['status'] === 'pending' ? 'warning' : 'danger') ?>">
<?= ucfirst($car['status']) ?>
</span>
</td>
<td>
<a href="admin_cars.php?action=hot&id=<?= $car['id'] ?>" style="text-decoration: none; font-size: 1.2rem;">
<?= $car['is_hot_deal'] ? '🔥' : '❄️' ?>
</a>
</td>
<td>
<div style="display: flex; gap: 0.8rem;">
<?php if ($car['status'] !== 'approved'): ?>
<a href="admin_cars.php?action=approve&id=<?= $car['id'] ?>" style="color: var(--success); text-decoration: none; font-weight: 700; font-size: 0.8rem;">Approve</a>
<?php endif; ?>
<?php if ($car['status'] !== 'rejected'): ?>
<a href="admin_cars.php?action=reject&id=<?= $car['id'] ?>" style="color: var(--warning); text-decoration: none; font-weight: 700; font-size: 0.8rem;">Reject</a>
<?php endif; ?>
<a href="admin_cars.php?action=delete&id=<?= $car['id'] ?>" onclick="return confirm('Are you sure?')" style="color: var(--danger); text-decoration: none; font-weight: 700; font-size: 0.8rem;">Delete</a>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</main>
// Fetch all cars with user and image info
$stmt = $pdo->query("
SELECT c.*, u.name as seller_name, u.phone as seller_phone, ci.image_path
FROM cars c
JOIN users u ON c.user_id = u.id
LEFT JOIN car_images ci ON c.id = ci.car_id AND ci.is_main = 1
WHERE c.deleted_at IS NULL
ORDER BY c.created_at DESC
");
$cars = $stmt->fetchAll();
?>
<div class="container-fluid" style="padding: 2rem 4rem;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 3rem;">
<div>
<h1 style="font-size: 2.5rem; font-weight: 900; margin-bottom: 0.5rem;">Inventory Management</h1>
<p style="color: var(--text-secondary);">Review and approve vehicle listings from sellers.</p>
</div>
<div style="display: flex; gap: 1rem;">
<a href="admin_purchases.php" class="btn btn-primary">View Purchase Requests</a>
<a href="admin_dashboard.php" class="btn btn-outline">Back to Dashboard</a>
</div>
</div>
</body>
</html>
<?php if ($message): ?>
<div class="glass" style="padding: 1rem; margin-bottom: 2rem; border-color: var(--primary-color); color: var(--primary-color); font-weight: 600;">
<?= $message ?>
</div>
<?php endif; ?>
<div class="glass" style="overflow-x: auto; padding: 0;">
<table style="width: 100%; border-collapse: collapse; text-align: left;">
<thead>
<tr style="background: rgba(0,0,0,0.05);">
<th style="padding: 1.5rem;">Vehicle</th>
<th style="padding: 1.5rem;">Seller</th>
<th style="padding: 1.5rem;">Price</th>
<th style="padding: 1.5rem;">Location</th>
<th style="padding: 1.5rem;">Status</th>
<th style="padding: 1.5rem;">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($cars as $car): ?>
<tr style="border-bottom: 1px solid var(--glass-border);">
<td style="padding: 1.5rem;">
<div style="display: flex; align-items: center; gap: 1rem;">
<img src="<?= htmlspecialchars($car['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>" style="width: 100px; height: 60px; object-fit: cover; border-radius: 8px;">
<div>
<div style="font-weight: 700;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></div>
<div style="font-size: 0.8rem; color: var(--text-secondary);"><?= $car['year'] ?></div>
</div>
</div>
</td>
<td style="padding: 1.5rem;">
<div style="font-weight: 600;"><?= htmlspecialchars($car['seller_name']) ?></div>
<div style="font-size: 0.85rem; color: var(--text-secondary);"><?= htmlspecialchars($car['seller_phone']) ?></div>
</td>
<td style="padding: 1.5rem; font-weight: 700;">$<?= number_format($car['price']) ?></td>
<td style="padding: 1.5rem; color: var(--text-secondary);"><?= htmlspecialchars($car['city']) ?></td>
<td style="padding: 1.5rem;">
<span class="badge" style="background: <?= $car['status'] === 'approved' ? 'var(--success)' : ($car['status'] === 'sold' ? '#000' : ($car['status'] === 'rejected' ? 'var(--danger)' : 'var(--primary-color)')) ?>; color: white; padding: 0.3rem 0.8rem; border-radius: 20px; font-size: 0.75rem; text-transform: uppercase;">
<?= $car['status'] ?>
</span>
</td>
<td style="padding: 1.5rem;">
<div style="display: flex; gap: 0.5rem;">
<?php if ($car['status'] === 'pending'): ?>
<form method="POST" style="display: inline;">
<input type="hidden" name="car_id" value="<?= $car['id'] ?>">
<button type="submit" name="action" value="approve" class="btn btn-primary" style="padding: 0.5rem 1rem; font-size: 0.8rem;">Approve</button>
</form>
<form method="POST" style="display: inline;">
<input type="hidden" name="car_id" value="<?= $car['id'] ?>">
<button type="submit" name="action" value="reject" class="btn btn-outline" style="padding: 0.5rem 1rem; font-size: 0.8rem; color: var(--danger); border-color: var(--danger);">Reject</button>
</form>
<?php endif; ?>
<a href="edit_car.php?id=<?= $car['id'] ?>" class="btn btn-outline" style="padding: 0.5rem 1rem; font-size: 0.8rem;">Edit</a>
<a href="?delete=<?= $car['id'] ?>" class="btn btn-outline" style="padding: 0.5rem 1rem; font-size: 0.8rem; color: var(--danger); border-color: var(--danger);" onclick="return confirm('Are you sure?')">Delete</a>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>

View File

@ -14,7 +14,7 @@ $pdo = db();
$totalCars = $pdo->query("SELECT COUNT(*) FROM cars WHERE deleted_at IS NULL")->fetchColumn();
$pendingCars = $pdo->query("SELECT COUNT(*) FROM cars WHERE status = 'pending' AND deleted_at IS NULL")->fetchColumn();
$totalUsers = $pdo->query("SELECT COUNT(*) FROM users WHERE deleted_at IS NULL")->fetchColumn();
$totalPurchases = $pdo->query("SELECT COUNT(*) FROM purchases")->fetchColumn();
$totalPurchases = $pdo->query("SELECT COUNT(*) FROM purchases WHERE status = 'pending'")->fetchColumn();
// Fetch Recent Cars
$recentCars = $pdo->query("
@ -47,9 +47,9 @@ $recentMessages = $pdo->query("SELECT * FROM contact_messages ORDER BY created_a
<ul class="sidebar-menu">
<li><a href="admin_dashboard.php" class="active"><span>Dashboard</span></a></li>
<li><a href="admin_cars.php"><span>Manage Cars</span></a></li>
<li><a href="admin_purchases.php"><span>Purchase Requests</span></a></li>
<li><a href="admin_users.php"><span>Users</span></a></li>
<li><a href="admin_messages.php"><span>Messages</span></a></li>
<li><a href="admin_settings.php"><span>Settings</span></a></li>
</ul>
<div class="sidebar-footer">
<a href="logout.php" style="color: var(--danger); font-size: 0.9rem; text-decoration: none; font-weight: 600;">Logout</a>
@ -75,15 +75,15 @@ $recentMessages = $pdo->query("SELECT * FROM contact_messages ORDER BY created_a
<span class="stat-value"><?= $totalCars ?></span>
</div>
<div class="stat-card glass" style="border-left: 4px solid var(--warning);">
<span class="stat-label">Pending Approval</span>
<span class="stat-label">Listing Requests</span>
<span class="stat-value"><?= $pendingCars ?></span>
</div>
<div class="stat-card glass">
<span class="stat-label">Total Users</span>
<span class="stat-value"><?= $totalUsers ?></span>
</div>
<div class="stat-card glass" style="border-left: 4px solid var(--success);">
<span class="stat-label">Purchases</span>
<div class="stat-card glass" style="border-left: 4px solid var(--success); cursor: pointer;" onclick="window.location.href='admin_purchases.php'">
<span class="stat-label">Pending Purchases</span>
<span class="stat-value"><?= $totalPurchases ?></span>
</div>
</div>
@ -95,8 +95,8 @@ $recentMessages = $pdo->query("SELECT * FROM contact_messages ORDER BY created_a
<h3 style="font-weight: 800;">Recent Car Listings</h3>
<a href="admin_cars.php" style="color: var(--primary-color); text-decoration: none; font-size: 0.85rem; font-weight: 600;">View All</a>
</div>
<div class="table-container">
<table>
<div class="table-container" style="overflow-x: auto;">
<table style="width: 100%;">
<thead>
<tr>
<th>Car</th>
@ -142,7 +142,7 @@ $recentMessages = $pdo->query("SELECT * FROM contact_messages ORDER BY created_a
<span style="font-size: 0.7rem; color: var(--text-secondary);"><?= date('M d', strtotime($msg['created_at'])) ?></span>
</div>
<p style="font-size: 0.85rem; color: var(--text-secondary); line-height: 1.4;">
<?= htmlspecialchars(substr($msg['message'], 0, 80)) ?>...
<?= htmlspecialchars(substr($msg['message'] ?? '', 0, 80)) ?>...
</p>
</div>
<?php endforeach; ?>

View File

@ -37,11 +37,12 @@ $messages = $pdo->query("SELECT * FROM contact_messages ORDER BY created_at DESC
<ul class="sidebar-menu">
<li><a href="admin_dashboard.php"><span>Dashboard</span></a></li>
<li><a href="admin_cars.php"><span>Manage Cars</span></a></li>
<li><a href="admin_purchases.php"><span>Purchase Requests</span></a></li>
<li><a href="admin_users.php"><span>Users</span></a></li>
<li><a href="admin_messages.php" class="active"><span>Messages</span></a></li>
</ul>
<div class="sidebar-footer">
<a href="logout.php" style="color: var(--danger); text-decoration: none; font-weight: 600;">Logout</a>
<a href="logout.php" style="color: var(--danger); font-size: 0.9rem; text-decoration: none; font-weight: 600;">Logout</a>
</div>
</aside>

136
admin_purchases.php Normal file
View File

@ -0,0 +1,136 @@
<?php
require_once __DIR__ . '/includes/header.php';
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
header('Location: index.php');
exit;
}
$pdo = db();
$message = '';
if (isset($_POST['action']) && isset($_POST['purchase_id'])) {
$purchase_id = $_POST['purchase_id'];
$action = $_POST['action'];
$status = ($action === 'approve') ? 'approved' : 'rejected';
try {
$pdo->beginTransaction();
// Update purchase status
$stmt = $pdo->prepare("UPDATE purchases SET status = ? WHERE id = ?");
$stmt->execute([$status, $purchase_id]);
if ($status === 'approved') {
// Get car ID
$stmt = $pdo->prepare("SELECT car_id FROM purchases WHERE id = ?");
$stmt->execute([$purchase_id]);
$car_id = $stmt->fetchColumn();
// Mark car as sold
$stmt = $pdo->prepare("UPDATE cars SET status = 'sold' WHERE id = ?");
$stmt->execute([$car_id]);
}
$pdo->commit();
$message = "Purchase request " . ($status === 'approved' ? 'approved' : 'rejected') . " successfully.";
} catch (Exception $e) {
$pdo->rollBack();
$message = "Error: " . $e->getMessage();
}
}
// Fetch all purchases with car and user info
$stmt = $pdo->query("
SELECT p.*, c.brand, c.model, c.price, c.year, u.name as buyer_user_name, ci.image_path
FROM purchases p
JOIN cars c ON p.car_id = c.id
JOIN users u ON p.user_id = u.id
LEFT JOIN car_images ci ON c.id = ci.car_id AND ci.is_main = 1
ORDER BY p.created_at DESC
");
$purchases = $stmt->fetchAll();
?>
<div class="container-fluid" style="padding: 2rem 4rem;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 3rem;">
<div>
<h1 style="font-size: 2.5rem; font-weight: 900; margin-bottom: 0.5rem;">Purchase Requests</h1>
<p style="color: var(--text-secondary);">Review and manage buyer bank verification requests.</p>
</div>
<a href="admin_dashboard.php" class="btn btn-outline">Back to Dashboard</a>
</div>
<?php if ($message): ?>
<div class="glass" style="padding: 1rem; margin-bottom: 2rem; border-color: var(--primary-color); color: var(--primary-color); font-weight: 600;">
<?= $message ?>
</div>
<?php endif; ?>
<div class="glass" style="overflow-x: auto; padding: 0;">
<table style="width: 100%; border-collapse: collapse; text-align: left;">
<thead>
<tr style="background: rgba(0,0,0,0.05);">
<th style="padding: 1.5rem;">Vehicle</th>
<th style="padding: 1.5rem;">Buyer Details</th>
<th style="padding: 1.5rem;">Bank ID</th>
<th style="padding: 1.5rem;">Price</th>
<th style="padding: 1.5rem;">Status</th>
<th style="padding: 1.5rem;">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($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: 1rem;">
<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: 700;"><?= htmlspecialchars($p['brand'] . ' ' . $p['model']) ?></div>
<div style="font-size: 0.8rem; color: var(--text-secondary);"><?= $p['year'] ?></div>
</div>
</div>
</td>
<td style="padding: 1.5rem;">
<div style="font-weight: 600;"><?= htmlspecialchars($p['buyer_name']) ?></div>
<div style="font-size: 0.85rem; color: var(--text-secondary);"><?= htmlspecialchars($p['buyer_phone']) ?></div>
<div style="font-size: 0.75rem; color: var(--text-secondary); max-width: 200px;"><?= htmlspecialchars($p['personal_info']) ?></div>
</td>
<td style="padding: 1.5rem;">
<code style="background: rgba(0,0,0,0.1); padding: 0.3rem 0.6rem; border-radius: 4px;"><?= htmlspecialchars($p['bank_id']) ?></code>
</td>
<td style="padding: 1.5rem; font-weight: 700; color: var(--primary-color);">$<?= number_format($p['price']) ?></td>
<td style="padding: 1.5rem;">
<span class="badge" style="background: <?= $p['status'] === 'approved' ? 'var(--success)' : ($p['status'] === 'rejected' ? 'var(--danger)' : 'var(--primary-color)') ?>; color: white; padding: 0.3rem 0.8rem; border-radius: 20px; font-size: 0.75rem; text-transform: uppercase;">
<?= $p['status'] ?>
</span>
</td>
<td style="padding: 1.5rem;">
<?php if ($p['status'] === 'pending'): ?>
<div style="display: flex; gap: 0.5rem;">
<form method="POST" style="display: inline;">
<input type="hidden" name="purchase_id" value="<?= $p['id'] ?>">
<button type="submit" name="action" value="approve" class="btn btn-primary" style="padding: 0.5rem 1rem; font-size: 0.8rem;">Approve</button>
</form>
<form method="POST" style="display: inline;">
<input type="hidden" name="purchase_id" value="<?= $p['id'] ?>">
<button type="submit" name="action" value="reject" class="btn btn-outline" style="padding: 0.5rem 1rem; font-size: 0.8rem; border-color: var(--danger); color: var(--danger);">Reject</button>
</form>
</div>
<?php else: ?>
<span style="color: var(--text-secondary); font-size: 0.85rem;">Completed</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($purchases)): ?>
<tr>
<td colspan="6" style="padding: 4rem; text-align: center; color: var(--text-secondary);">No purchase requests found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>

View File

@ -39,11 +39,12 @@ $users = $pdo->query("SELECT * FROM users WHERE deleted_at IS NULL ORDER BY crea
<ul class="sidebar-menu">
<li><a href="admin_dashboard.php"><span>Dashboard</span></a></li>
<li><a href="admin_cars.php"><span>Manage Cars</span></a></li>
<li><a href="admin_purchases.php"><span>Purchase Requests</span></a></li>
<li><a href="admin_users.php" class="active"><span>Users</span></a></li>
<li><a href="admin_messages.php"><span>Messages</span></a></li>
</ul>
<div class="sidebar-footer">
<a href="logout.php" style="color: var(--danger); text-decoration: none; font-weight: 600;">Logout</a>
<a href="logout.php" style="color: var(--danger); font-size: 0.9rem; text-decoration: none; font-weight: 600;">Logout</a>
</div>
</aside>
@ -56,9 +57,9 @@ $users = $pdo->query("SELECT * FROM users WHERE deleted_at IS NULL ORDER BY crea
<thead>
<tr>
<th>User Info</th>
<th>Phone/Address</th>
<th>Role</th>
<th>Status</th>
<th>Joined</th>
<th>Actions</th>
</tr>
</thead>
@ -69,9 +70,12 @@ $users = $pdo->query("SELECT * FROM users WHERE deleted_at IS NULL ORDER BY crea
<div style="font-weight: 700;"><?= htmlspecialchars($u['name']) ?></div>
<div style="font-size: 0.8rem; color: var(--text-secondary);"><?= htmlspecialchars($u['email']) ?></div>
</td>
<td>
<div style="font-size: 0.85rem; font-weight: 600;"><?= htmlspecialchars($u['phone'] ?: 'N/A') ?></div>
<div style="font-size: 0.75rem; color: var(--text-secondary); max-width: 200px;"><?= htmlspecialchars($u['address'] ?: 'N/A') ?></div>
</td>
<td><span class="badge badge-<?= $u['role'] === 'admin' ? 'danger' : 'success' ?>"><?= strtoupper($u['role']) ?></span></td>
<td><span class="badge badge-<?= $u['status'] === 'active' ? 'success' : 'warning' ?>"><?= ucfirst($u['status']) ?></span></td>
<td><?= date('M d, Y', strtotime($u['created_at'])) ?></td>
<td>
<div style="display: flex; gap: 0.8rem;">
<?php if ($u['status'] === 'active'): ?>

View File

@ -4,141 +4,107 @@ require_once __DIR__ . '/includes/header.php';
$pdo = db();
$id = $_GET['id'] ?? 0;
$stmt = $pdo->prepare("SELECT c.*, u.name as seller_name FROM cars c JOIN users u ON c.user_id = u.id WHERE c.id = ? AND c.status = 'approved'");
$stmt = $pdo->prepare("
SELECT c.*, u.name as seller_name, ci.image_path
FROM cars c
JOIN users u ON c.user_id = u.id
LEFT JOIN car_images ci ON c.id = ci.car_id AND ci.is_main = 1
WHERE c.id = ? AND c.deleted_at IS NULL AND (c.status = 'approved' OR c.status = 'sold')
");
$stmt->execute([$id]);
$car = $stmt->fetch();
if (!$car) {
echo "<div class='container' style='text-align: center; padding: 10rem 5%;'><h1>Car not found.</h1><a href='cars.php' class='btn btn-primary' style='margin-top: 2rem;'>Back to Marketplace</a></div>";
require_once __DIR__ . '/includes/footer.php';
header('Location: cars.php');
exit;
}
// Get images
$stmt = $pdo->prepare("SELECT * FROM car_images WHERE car_id = ?");
// Fetch all images
$stmt = $pdo->prepare("SELECT image_path FROM car_images WHERE car_id = ?");
$stmt->execute([$id]);
$images = $stmt->fetchAll();
$mainImage = '';
foreach ($images as $img) {
if ($img['is_main']) {
$mainImage = $img['image_path'];
break;
}
}
if (!$mainImage && !empty($images)) $mainImage = $images[0]['image_path'];
// Similar cars
$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.brand = ? AND c.id != ? AND c.status = 'approved' LIMIT 3");
$stmt->execute([$car['brand'], $id]);
$similar = $stmt->fetchAll();
$images = $stmt->fetchAll(PDO::FETCH_COLUMN);
?>
<div class="container" style="padding-top: 2rem;">
<div style="display: grid; grid-template-columns: 1.5fr 1fr; gap: 4rem;">
<div class="container" style="padding: 2rem 0;">
<div style="display: grid; grid-template-columns: 1.5fr 1fr; gap: 4rem; align-items: start;">
<!-- Left Column: Images & Info -->
<div>
<div id="main-car-image" class="glass" style="height: 550px; background-image: url('<?= htmlspecialchars($mainImage ?: 'assets/images/placeholder-car.jpg') ?>'); background-size: cover; background-position: center; border-radius: 20px; margin-bottom: 2rem; box-shadow: 0 20px 40px rgba(0,0,0,0.5);"></div>
<?php if (count($images) > 1): ?>
<div style="display: flex; gap: 1rem; margin-bottom: 3rem;">
<?php foreach ($images as $img): ?>
<div class="glass" style="width: 100px; height: 80px; background-image: url('<?= htmlspecialchars($img['image_path']) ?>'); background-size: cover; background-position: center; cursor: pointer; border-radius: 12px; transition: var(--transition);" onclick="document.getElementById('main-car-image').style.backgroundImage='url(\'<?= htmlspecialchars($img['image_path']) ?>\')'"></div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="glass" style="padding: 3rem; border-left: 4px solid var(--primary-color);">
<h2 style="margin-bottom: 2rem; display: flex; align-items: center; gap: 1rem;">
<span>📜</span> Detailed Description
</h2>
<div style="color: var(--text-secondary); line-height: 2; font-size: 1.1rem;">
<?= nl2br(htmlspecialchars($car['description'])) ?>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-top: 3rem; border-top: 1px solid var(--glass-border); padding-top: 2rem;">
<div>
<p style="color: var(--primary-color); font-weight: 700; margin-bottom: 0.5rem; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 1px;">Vehicle Condition</p>
<p style="color: var(--text-primary);">Excellent / Premium</p>
</div>
<div>
<p style="color: var(--primary-color); font-weight: 700; margin-bottom: 0.5rem; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 1px;">Transmission</p>
<p style="color: var(--text-primary);">Automatic</p>
</div>
<div>
<p style="color: var(--primary-color); font-weight: 700; margin-bottom: 0.5rem; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 1px;">Fuel Type</p>
<p style="color: var(--text-primary);">Petrol / Hybrid</p>
</div>
<div>
<p style="color: var(--primary-color); font-weight: 700; margin-bottom: 0.5rem; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 1px;">Import Status</p>
<p style="color: var(--text-primary);">Custom Cleared</p>
</div>
</div>
</div>
</div>
<div>
<div class="glass" style="padding: 3rem; position: sticky; top: 120px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
<span style="background: rgba(212, 175, 55, 0.2); color: var(--primary-color); padding: 6px 16px; border-radius: 50px; font-weight: 700; font-size: 0.85rem; border: 1px solid var(--primary-color);"><?= $car['year'] ?> MODEL</span>
<span style="color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;">📍 <?= $car['city'] ?>, AFG</span>
</div>
<h1 style="font-size: 3rem; margin-bottom: 1rem; line-height: 1.1; font-weight: 800;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h1>
<div class="car-price" style="font-size: 2.5rem; margin-bottom: 2.5rem;">$<?= number_format($car['price']) ?></div>
<div style="background: rgba(255,255,255,0.02); padding: 2rem; border-radius: 16px; margin-bottom: 2.5rem; border: 1px solid var(--glass-border);">
<p style="color: var(--text-secondary); margin-bottom: 1rem; display: flex; align-items: center; gap: 0.8rem;">
<span style="opacity: 0.5;">👤</span> Seller: <strong style="color: var(--text-primary);"><?= htmlspecialchars($car['seller_name']) ?></strong>
</p>
<p style="color: var(--text-secondary); display: flex; align-items: center; gap: 0.8rem;">
<span style="opacity: 0.5;">🆔</span> Listing ID: <strong style="color: var(--text-primary);">#AFG-<?= str_pad($car['id'], 5, '0', STR_PAD_LEFT) ?></strong>
</p>
</div>
<?php if (isset($_SESSION['user_id'])): ?>
<a href="purchase.php?id=<?= $car['id'] ?>" class="btn btn-primary" style="width: 100%; text-align: center; margin-bottom: 1.5rem; padding: 1.2rem; font-size: 1.1rem;">Initiate Purchase</a>
<a href="#" class="btn btn-outline" style="width: 100%; text-align: center; padding: 1.2rem;">Add to Favorites</a>
<?php else: ?>
<div style="text-align: center; padding: 2rem; border: 1px dashed var(--glass-border); border-radius: 16px;">
<p style="margin-bottom: 1.5rem; color: var(--text-secondary); font-size: 0.95rem;">Interested in this vehicle? Log in to contact the seller.</p>
<a href="login.php" class="btn btn-primary" style="width: 100%; text-align: center;">Login to Proceed</a>
<div style="position: relative; margin-bottom: 2rem;">
<img src="<?= htmlspecialchars($car['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>" style="width: 100%; border-radius: 24px; box-shadow: 0 20px 40px rgba(0,0,0,0.1);">
<?php if ($car['status'] === 'sold'): ?>
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); border-radius: 24px; display: flex; align-items: center; justify-content: center;">
<div style="border: 10px double white; color: white; padding: 20px 50px; font-weight: 900; font-size: 5rem; transform: rotate(-15deg); letter-spacing: 10px;">SOLD</div>
</div>
<?php endif; ?>
<div style="margin-top: 3rem; text-align: center;">
<p style="color: var(--text-secondary); font-size: 0.8rem;">Share this listing:</p>
<div style="display: flex; gap: 1rem; justify-content: center; margin-top: 1rem; font-size: 1.5rem;">
<span style="cursor: pointer; opacity: 0.6;">📱</span>
<span style="cursor: pointer; opacity: 0.6;">💬</span>
<span style="cursor: pointer; opacity: 0.6;">📧</span>
</div>
</div>
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 3rem;">
<?php foreach ($images as $img): ?>
<img src="<?= htmlspecialchars($img) ?>" style="width: 100%; height: 100px; object-fit: cover; border-radius: 12px; cursor: pointer; transition: transform 0.3s ease;" onmouseover="this.style.transform='scale(1.05)'" onmouseout="this.style.transform='scale(1)'">
<?php endforeach; ?>
</div>
<div class="glass" style="padding: 3rem;">
<h2 style="font-size: 1.8rem; font-weight: 800; margin-bottom: 1.5rem;">Description</h2>
<div style="line-height: 1.8; color: var(--text-secondary); white-space: pre-line;">
<?= htmlspecialchars($car['description']) ?>
</div>
</div>
</div>
</div>
<?php if ($similar): ?>
<div style="margin-top: 6rem;">
<h2 class="section-title" style="text-align: left;">Similar Premium Vehicles</h2>
<div class="grid">
<?php foreach ($similar as $s): ?>
<div class="car-card glass">
<div class="car-img-container" style="overflow: hidden; height: 200px;">
<div class="car-img" style="background-image: url('<?= htmlspecialchars($s['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>'); background-size: cover; background-position: center; height: 100%;"></div>
<!-- Right Column: Details & Actions -->
<div style="position: sticky; top: 120px;">
<div class="glass" style="padding: 3rem; border-top: 5px solid var(--primary-color);">
<div style="margin-bottom: 2rem;">
<span style="background: rgba(212, 175, 55, 0.1); color: var(--primary-color); padding: 0.5rem 1rem; border-radius: 30px; font-size: 0.8rem; font-weight: 800; text-transform: uppercase;"><?= htmlspecialchars($car['city']) ?></span>
</div>
<h1 style="font-size: 2.5rem; font-weight: 900; margin-bottom: 1rem; line-height: 1.1;">
<?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?>
</h1>
<p style="font-size: 1.2rem; color: var(--text-secondary); margin-bottom: 2rem;">
Year: <strong><?= $car['year'] ?></strong> | Status: <strong><?= ucfirst($car['status']) ?></strong>
</p>
<div style="background: rgba(0,0,0,0.03); padding: 2rem; border-radius: 16px; margin-bottom: 2.5rem;">
<p style="color: var(--text-secondary); margin-bottom: 0.5rem; font-size: 0.9rem; font-weight: 700; text-transform: uppercase;">Current Price</p>
<div style="font-size: 3rem; font-weight: 900; color: var(--primary-color);">$<?= number_format($car['price']) ?></div>
</div>
<?php if ($car['status'] === 'sold'): ?>
<div style="padding: 2rem; background: rgba(0,0,0,0.05); border-radius: 16px; text-align: center; color: var(--text-secondary); font-weight: 700;">
This vehicle has been sold.
</div>
<?php else: ?>
<a href="purchase.php?id=<?= $car['id'] ?>" class="btn btn-primary" style="width: 100%; padding: 1.5rem; font-size: 1.2rem; font-weight: 800; margin-bottom: 1.5rem; text-align: center; display: block;">Initiate Purchase Request</a>
<?php endif; ?>
<div style="padding-top: 2rem; border-top: 1px solid var(--glass-border);">
<div style="display: flex; align-items: center; gap: 1rem;">
<div style="width: 50px; height: 50px; background: var(--primary-color); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1.2rem;">
<?= strtoupper(substr($car['seller_name'], 0, 1)) ?>
</div>
<div class="car-info">
<div class="car-meta">
<span>📅 <?= htmlspecialchars($s['year']) ?></span>
<span>📍 <?= htmlspecialchars($s['city']) ?></span>
</div>
<h3><?= htmlspecialchars($s['brand'] . ' ' . $s['model']) ?></h3>
<div class="car-price">$<?= number_format($s['price']) ?></div>
<a href="car_detail.php?id=<?= $s['id'] ?>" class="btn btn-outline" style="width: 100%; text-align: center;">View Details</a>
<div>
<p style="color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; margin-bottom: 0.2rem;">Seller</p>
<p style="font-weight: 700;"><?= htmlspecialchars($car['seller_name']) ?></p>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="glass" style="margin-top: 2rem; padding: 2rem; background: rgba(46, 213, 115, 0.05); border-color: rgba(46, 213, 115, 0.2);">
<h4 style="color: #2ed573; margin-bottom: 0.8rem; display: flex; align-items: center; gap: 0.5rem;">
<span>🛡️</span> AfgCars Secure
</h4>
<p style="font-size: 0.85rem; color: #666; line-height: 1.6;">
Every listing is manually verified by our team. Personal information and bank IDs are encrypted and used only for legal documentation.
</p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>
<?php require_once __DIR__ . '/includes/footer.php'; ?>

142
cars.php
View File

@ -2,98 +2,108 @@
require_once __DIR__ . '/includes/header.php';
$pdo = db();
$search = $_GET['q'] ?? '';
$brand = $_GET['brand'] ?? '';
$search = $_GET['search'] ?? '';
$city = $_GET['city'] ?? '';
$brand = $_GET['brand'] ?? '';
$query = "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.status = 'approved'";
$query = "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.deleted_at IS NULL AND (c.status = 'approved' OR c.status = 'sold')";
$params = [];
if ($search) {
$query .= " AND (c.brand LIKE ? OR c.model LIKE ?)";
$query .= " AND (brand LIKE ? OR model LIKE ?)";
$params[] = "%$search%";
$params[] = "%$search%";
}
if ($brand) {
$query .= " AND c.brand = ?";
$params[] = $brand;
}
if ($city) {
$query .= " AND c.city = ?";
$query .= " AND city = ?";
$params[] = $city;
}
if ($brand) {
$query .= " AND brand = ?";
$params[] = $brand;
}
$query .= " ORDER BY c.created_at DESC";
$stmt = $pdo->prepare($query);
$stmt->execute($params);
$cars = $stmt->fetchAll();
// Fetch distinct cities and brands for filters
$cities = $pdo->query("SELECT DISTINCT city FROM cars WHERE status = 'approved'")->fetchAll(PDO::FETCH_COLUMN);
$brands = $pdo->query("SELECT DISTINCT brand FROM cars WHERE status = 'approved'")->fetchAll(PDO::FETCH_COLUMN);
$cities = ['Kabul', 'Herat', 'Mazar-i-Sharif', 'Kandahar', 'Jalalabad', 'Kunduz', 'Ghazni', 'Balkh'];
?>
<div class="container" style="padding-top: 2rem;">
<h1 class="section-title">Premium Marketplace</h1>
<form class="glass" style="padding: 2.5rem; margin-bottom: 4rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.5rem; align-items: end; border-left: 4px solid var(--primary-color);">
<div class="form-group" style="margin-bottom: 0;">
<label>Keyword</label>
<input type="text" name="q" value="<?= htmlspecialchars($search) ?>" class="form-control" placeholder="Search brand or model...">
</div>
<div class="form-group" style="margin-bottom: 0;">
<label>Brand</label>
<select name="brand" class="form-control">
<option value="">All Brands</option>
<?php foreach ($brands as $b): ?>
<option value="<?= htmlspecialchars($b) ?>" <?= $brand == $b ? 'selected' : '' ?>><?= htmlspecialchars($b) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group" style="margin-bottom: 0;">
<label>City</label>
<select name="city" class="form-control">
<option value="">All Cities</option>
<?php foreach ($cities as $c): ?>
<option value="<?= htmlspecialchars($c) ?>" <?= $city == $c ? 'selected' : '' ?>><?= htmlspecialchars($c) ?></option>
<?php endforeach; ?>
</select>
</div>
<div style="display: flex; gap: 0.5rem;">
<button type="submit" class="btn btn-primary" style="flex: 2;">Apply Filters</button>
<a href="cars.php" class="btn btn-outline" style="flex: 1; text-align: center; display: flex; align-items: center; justify-content: center; padding: 0;"></a>
</div>
</form>
<div class="container" style="padding: 2rem 0;">
<div style="margin-bottom: 4rem;">
<h1 style="font-size: 3rem; font-weight: 900; margin-bottom: 1rem;">Premium Inventory</h1>
<p style="color: var(--text-secondary); font-size: 1.2rem;">Find the perfect vehicle for your lifestyle in our verified marketplace.</p>
</div>
<div class="grid">
<?php if (empty($cars)): ?>
<div style="grid-column: 1/-1; text-align: center; padding: 6rem; background: rgba(255,255,255,0.02); border-radius: 20px;">
<div style="font-size: 4rem; margin-bottom: 1.5rem; opacity: 0.3;">🚗💨</div>
<h2 style="color: var(--text-secondary);">No vehicles found</h2>
<p style="color: var(--text-secondary); margin-bottom: 2rem;">We couldn't find any cars matching your current filters.</p>
<a href="cars.php" class="btn btn-primary">Clear all filters</a>
<!-- Filters -->
<div class="glass" style="padding: 2rem; margin-bottom: 4rem;">
<form method="GET" style="display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 1.5rem; align-items: end;">
<div class="form-group" style="margin-bottom: 0;">
<label>Search</label>
<input type="text" name="search" class="form-control" placeholder="Search brand or model..." value="<?= htmlspecialchars($search) ?>">
</div>
<?php else: ?>
<?php foreach ($cars as $car): ?>
<div class="car-card glass">
<div class="car-img-container" style="overflow: hidden; height: 240px; position: relative;">
<div class="car-img" style="background-image: url('<?= htmlspecialchars($car['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>'); background-size: cover; background-position: center; height: 100%;"></div>
<?php if ($car['is_hot_deal']): ?>
<div style="position: absolute; top: 1rem; left: 1rem; background: var(--primary-color); color: #000; padding: 0.4rem 1rem; border-radius: 50px; font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;">Hot Deal</div>
<?php endif; ?>
</div>
<div class="car-info">
<div class="car-meta">
<span>📅 <?= htmlspecialchars($car['year']) ?></span>
<span>📍 <?= htmlspecialchars($car['city']) ?></span>
<div class="form-group" style="margin-bottom: 0;">
<label>City</label>
<select name="city" class="form-control">
<option value="">All Cities</option>
<?php foreach ($cities as $c): ?>
<option value="<?= $c ?>" <?= $city === $c ? 'selected' : '' ?>><?= $c ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group" style="margin-bottom: 0;">
<label>Brand</label>
<select name="brand" class="form-control">
<option value="">All Brands</option>
<?php foreach ($brands as $b): ?>
<option value="<?= $b ?>" <?= $brand === $b ? 'selected' : '' ?>><?= $b ?></option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn btn-primary" style="height: 50px;">Apply Filters</button>
</form>
</div>
<!-- Listings -->
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 2.5rem;">
<?php foreach ($cars as $car): ?>
<div class="glass car-card" style="padding: 0; overflow: hidden; position: relative;">
<div style="height: 220px; background-image: url('<?= htmlspecialchars($car['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>'); background-size: cover; background-position: center; position: relative;">
<?php if ($car['status'] === 'sold'): ?>
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; z-index: 2;">
<div style="border: 4px solid #fff; color: #fff; padding: 10px 25px; font-weight: 900; font-size: 2rem; transform: rotate(-15deg); letter-spacing: 4px;">SOLD</div>
</div>
<h3><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h3>
<div class="car-price">$<?= number_format($car['price']) ?></div>
<a href="car_detail.php?id=<?= $car['id'] ?>" class="btn btn-outline" style="width: 100%; text-align: center;">View Details</a>
<?php elseif ($car['is_hot_deal']): ?>
<span style="position: absolute; top: 1.5rem; left: 1.5rem; background: var(--danger); color: white; padding: 0.5rem 1rem; border-radius: 30px; font-size: 0.75rem; font-weight: 800; text-transform: uppercase; z-index: 1;">Hot Deal</span>
<?php endif; ?>
</div>
<div style="padding: 2rem;">
<h3 style="font-size: 1.4rem; font-weight: 800; margin-bottom: 0.5rem;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h3>
<p style="color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.95rem; display: flex; align-items: center; gap: 0.5rem;">
<span>📍</span> <?= htmlspecialchars($car['city']) ?> • <?= $car['year'] ?>
</p>
<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-size: 1.5rem; font-weight: 900; color: var(--primary-color);">$<?= number_format($car['price']) ?></span>
<a href="car_detail.php?id=<?= $car['id'] ?>" class="btn btn-primary btn-sm" style="<?= $car['status'] === 'sold' ? 'background: #555; pointer-events: none;' : '' ?>">View Details</a>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php if (empty($cars)): ?>
<div style="text-align: center; padding: 10rem 0;">
<div style="font-size: 4rem; margin-bottom: 2rem;">🔍</div>
<h2 style="font-weight: 800; margin-bottom: 1rem;">No vehicles found</h2>
<p style="color: var(--text-secondary);">Try adjusting your filters or search terms.</p>
</div>
<?php endif; ?>
</div>
<?php require_once __DIR__ . '/includes/footer.php'; ?>

View File

@ -1,111 +1,149 @@
<?php
session_start();
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/header.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
if (($_SESSION['role'] ?? '') === 'admin') {
header('Location: admin_dashboard.php');
exit;
}
$pdo = db();
$userId = $_SESSION['user_id'];
$user_id = $_SESSION['user_id'];
// Fetch user's purchases
$purchases = $pdo->prepare("
SELECT p.*, c.brand, c.model, c.year, c.price
// 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
");
$purchases->execute([$userId]);
$myPurchases = $purchases->fetchAll();
// Fetch user's listings
$listings = $pdo->prepare("
SELECT * FROM cars
WHERE user_id = ? AND deleted_at IS NULL
ORDER BY created_at DESC
");
$listings->execute([$userId]);
$myCars = $listings->fetchAll();
require_once __DIR__ . '/includes/header.php';
$stmt->execute([$user_id]);
$my_purchases = $stmt->fetchAll();
?>
<div class="container" style="padding-top: 3rem;">
<div style="display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 3rem; border-bottom: 1px solid var(--glass-border); padding-bottom: 2rem;">
<div class="container" style="padding: 2rem 0;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 3rem;">
<div>
<h1 style="font-size: 2.5rem; font-weight: 900;">Welcome, <?= htmlspecialchars($_SESSION['user_name']) ?></h1>
<p style="color: var(--text-secondary);">Manage your car listings and view your purchase history.</p>
<h1 style="font-size: 2.5rem; font-weight: 900; margin-bottom: 0.5rem;">User Dashboard</h1>
<p style="color: var(--text-secondary);">Manage your vehicle listings and track your purchase requests.</p>
</div>
<a href="logout.php" class="btn btn-outline" style="border-color: var(--danger); color: var(--danger);">Sign Out</a>
<a href="add_car.php" class="btn btn-primary">List New Vehicle</a>
</div>
<div style="display: grid; grid-template-columns: 2fr 1fr; gap: 3rem;">
<!-- Listings -->
<div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
<h2 style="font-weight: 800;">My Listings</h2>
<a href="add_car.php" class="btn btn-primary btn-sm" style="padding: 0.6rem 1.2rem; font-size: 0.8rem;">+ List New Car</a>
</div>
<div style="display: grid; grid-template-columns: 1fr; gap: 4rem;">
<!-- My Listings Section -->
<section>
<h2 style="font-size: 1.8rem; font-weight: 800; margin-bottom: 2rem; display: flex; align-items: center; gap: 1rem;">
<span style="background: var(--primary-color); color: white; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px; font-size: 1.2rem;">🚗</span>
My Vehicle Listings
</h2>
<?php if (empty($myCars)): ?>
<?php if (empty($my_listings)): ?>
<div class="glass" style="padding: 4rem; text-align: center;">
<p style="color: var(--text-secondary); margin-bottom: 1.5rem;">You haven't listed any cars yet.</p>
<a href="add_car.php" class="btn btn-outline">Start Selling</a>
<p style="color: var(--text-secondary); margin-bottom: 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 class="grid" style="grid-template-columns: 1fr;">
<?php foreach ($myCars as $car): ?>
<div class="glass" style="padding: 1.5rem; display: flex; justify-content: space-between; align-items: center;">
<div>
<h3 style="margin-bottom: 0.3rem;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h3>
<span class="badge badge-<?= $car['status'] === 'approved' ? 'success' : ($car['status'] === 'pending' ? 'warning' : 'danger') ?>">
<?= ucfirst($car['status']) ?>
</span>
<span style="margin-left: 1rem; color: var(--text-secondary); font-size: 0.9rem;">$<?= number_format($car['price']) ?></span>
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2rem;">
<?php foreach ($my_listings as $car): ?>
<div class="glass" style="padding: 0; overflow: hidden; position: relative;">
<div style="height: 180px; 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: 180px; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; color: white; font-weight: 900; font-size: 2rem; letter-spacing: 5px;">SOLD</div>
<?php endif; ?>
</div>
<div style="display: flex; gap: 1rem;">
<a href="car_detail.php?id=<?= $car['id'] ?>" class="btn btn-outline" style="padding: 0.5rem 1rem; font-size: 0.8rem;">View</a>
<a href="edit_car.php?id=<?= $car['id'] ?>" class="btn btn-auth" style="padding: 0.5rem 1rem; font-size: 0.8rem;">Edit</a>
<div style="padding: 1.5rem;">
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem;">
<div>
<h3 style="font-size: 1.2rem; font-weight: 700; margin-bottom: 0.2rem;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h3>
<p style="color: var(--text-secondary); font-size: 0.85rem;"><?= $car['year'] ?> - <?= htmlspecialchars($car['city']) ?></p>
</div>
<span class="badge" style="background: <?= $car['status'] === 'approved' ? 'var(--success)' : ($car['status'] === 'sold' ? '#000' : ($car['status'] === 'rejected' ? 'var(--danger)' : 'var(--primary-color)')) ?>; color: white; padding: 0.3rem 0.6rem; border-radius: 8px; font-size: 0.7rem; text-transform: uppercase; font-weight: 700;">
<?= $car['status'] ?>
</span>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--glass-border); padding-top: 1rem; margin-top: 1rem;">
<span style="font-weight: 800; color: var(--primary-color);">$<?= number_format($car['price']) ?></span>
<a href="edit_car.php?id=<?= $car['id'] ?>" style="color: var(--text-secondary); font-size: 0.9rem; font-weight: 600;">Edit Details</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</section>
<!-- My Purchase Requests Section -->
<section>
<h2 style="font-size: 1.8rem; font-weight: 800; margin-bottom: 2rem; display: flex; align-items: center; gap: 1rem;">
<span style="background: var(--primary-color); color: white; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px; font-size: 1.2rem;">💰</span>
My Purchase Requests
</h2>
<?php if (empty($my_purchases)): ?>
<div class="glass" style="padding: 4rem; text-align: center;">
<p style="color: var(--text-secondary); margin-bottom: 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="glass" style="padding: 0; overflow: hidden;">
<table style="width: 100%; border-collapse: collapse; text-align: left;">
<thead>
<tr style="background: rgba(0,0,0,0.03);">
<th style="padding: 1.5rem;">Vehicle</th>
<th style="padding: 1.5rem;">Price</th>
<th style="padding: 1.5rem;">Bank ID</th>
<th style="padding: 1.5rem;">Status</th>
<th style="padding: 1.5rem;">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($my_purchases as $p): ?>
<tr style="border-bottom: 1px solid var(--glass-border);">
<td style="padding: 1.2rem 1.5rem;">
<div style="display: flex; align-items: center; gap: 1rem;">
<img src="<?= htmlspecialchars($p['image_path'] ?: 'assets/images/placeholder-car.jpg') ?>" style="width: 60px; height: 40px; object-fit: cover; border-radius: 4px;">
<div>
<div style="font-weight: 700; font-size: 0.95rem;"><?= htmlspecialchars($p['brand'] . ' ' . $p['model']) ?></div>
<div style="font-size: 0.75rem; color: var(--text-secondary);"><?= $p['year'] ?></div>
</div>
</div>
</td>
<td style="padding: 1.2rem 1.5rem; font-weight: 700;">$<?= number_format($p['price']) ?></td>
<td style="padding: 1.2rem 1.5rem;"><code style="font-size: 0.8rem;"><?= htmlspecialchars($p['bank_id']) ?></code></td>
<td style="padding: 1.2rem 1.5rem;">
<span style="color: <?= $p['status'] === 'approved' ? 'var(--success)' : ($p['status'] === 'rejected' ? 'var(--danger)' : 'var(--primary-color)') ?>; font-weight: 700; font-size: 0.85rem; text-transform: uppercase;">
<?= $p['status'] ?>
</span>
</td>
<td style="padding: 1.2rem 1.5rem;">
<?php if ($p['status'] === 'approved'): ?>
<a href="receipt.php?id=<?= $p['id'] ?>" class="btn btn-primary" style="padding: 0.4rem 0.8rem; font-size: 0.8rem;">View Receipt</a>
<?php else: ?>
<span style="color: var(--text-secondary); font-size: 0.8rem;">Waiting for review</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</section>
<!-- Purchases -->
<div>
<h2 style="font-weight: 800; margin-bottom: 2rem;">Recent Activity</h2>
<div class="glass" style="padding: 2rem;">
<h4 style="margin-bottom: 1.5rem; color: var(--primary-color);">Purchase History</h4>
<?php if (empty($myPurchases)): ?>
<p style="color: var(--text-secondary); font-size: 0.9rem;">No purchases found.</p>
<?php else: ?>
<div style="display: flex; flex-direction: column; gap: 1.5rem;">
<?php foreach ($myPurchases as $p): ?>
<div style="border-bottom: 1px solid rgba(255,255,255,0.05); padding-bottom: 1rem;">
<div style="display: flex; justify-content: space-between; margin-bottom: 0.3rem;">
<span style="font-weight: 700; font-size: 0.9rem;"><?= htmlspecialchars($p['brand'] . ' ' . $p['model']) ?></span>
<span style="font-size: 0.8rem; color: var(--primary-color); font-weight: 700;">$<?= number_format($p['price']) ?></span>
</div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<span style="font-size: 0.75rem; color: var(--text-secondary);"><?= date('M d, Y', strtotime($p['created_at'])) ?></span>
<span class="badge badge-success" style="font-size: 0.65rem;">Completed</span>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>

View File

@ -24,10 +24,12 @@ $error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['buyer_name'] ?? '';
$phone = $_POST['buyer_phone'] ?? '';
$bank_id = $_POST['bank_id'] ?? '';
$personal_info = $_POST['personal_info'] ?? '';
$email = $_SESSION['user_email'] ?? '';
$stmt = $pdo->prepare("INSERT INTO purchases (car_id, user_id, buyer_name, buyer_email, buyer_phone) VALUES (?, ?, ?, ?, ?)");
if ($stmt->execute([$id, $_SESSION['user_id'], $name, $email, $phone])) {
$stmt = $pdo->prepare("INSERT INTO purchases (car_id, user_id, buyer_name, buyer_email, buyer_phone, bank_id, personal_info, status) VALUES (?, ?, ?, ?, ?, ?, ?, 'pending')");
if ($stmt->execute([$id, $_SESSION['user_id'], $name, $email, $phone, $bank_id, $personal_info])) {
$success = true;
} else {
$error = "Failed to submit request. Please try again.";
@ -35,18 +37,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
?>
<div class="container" style="max-width: 1000px;">
<div class="container" style="max-width: 1100px;">
<?php if ($success): ?>
<div class="glass" style="padding: 5rem; text-align: center; border-top: 4px solid var(--primary-color);">
<div style="font-size: 5rem; margin-bottom: 2rem;"></div>
<div style="font-size: 5rem; margin-bottom: 2rem;">🚀</div>
<h1 style="color: var(--primary-color); font-size: 3rem; margin-bottom: 1.5rem; font-weight: 800;">Request Submitted!</h1>
<p style="margin-bottom: 3rem; font-size: 1.2rem; color: var(--text-secondary); max-width: 700px; margin-left: auto; margin-right: auto; line-height: 1.8;">
Your purchase request for the <strong><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></strong> has been sent to our verification team.
Our representative will contact you at <strong><?= htmlspecialchars($phone) ?></strong> within 24 hours to guide you through the offline bank transfer process.
Your purchase request for the <strong><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></strong> with Bank ID <strong><?= htmlspecialchars($bank_id) ?></strong> has been sent to our admin for review.
Once approved, you will receive a confirmation receipt.
</p>
<div style="display: flex; gap: 1.5rem; justify-content: center;">
<a href="cars.php" class="btn btn-primary">Back to Marketplace</a>
<a href="index.php" class="btn btn-outline">Home Page</a>
<a href="dashboard.php" class="btn btn-primary">Go to Dashboard</a>
<a href="cars.php" class="btn btn-outline">Back to Marketplace</a>
</div>
</div>
<?php else: ?>
@ -57,45 +59,51 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<h2 style="font-size: 1.5rem; margin-bottom: 0.5rem;"><?= htmlspecialchars($car['brand'] . ' ' . $car['model']) ?></h2>
<p style="color: var(--text-secondary); margin-bottom: 1.5rem;"><?= $car['year'] ?> Model - <?= $car['city'] ?></p>
<div style="display: flex; justify-content: space-between; border-top: 1px solid var(--glass-border); padding-top: 1.5rem;">
<span style="font-weight: 600;">Total Amount</span>
<span style="font-weight: 600;">Total Price</span>
<span style="font-weight: 800; color: var(--primary-color); font-size: 1.5rem;">$<?= number_format($car['price']) ?></span>
</div>
</div>
<div class="glass" style="padding: 4rem;">
<h1 style="margin-bottom: 1rem; font-size: 2.5rem; font-weight: 800;">Complete Your Request</h1>
<p style="color: var(--text-secondary); margin-bottom: 3rem; font-size: 1.1rem;">Please provide your contact details. This is an offline purchase simulation for the Afghan automotive market.</p>
<h1 style="margin-bottom: 1rem; font-size: 2.5rem; font-weight: 800;">Buyer Verification</h1>
<p style="color: var(--text-secondary); margin-bottom: 3rem; font-size: 1.1rem;">Please provide your banking and personal information to initiate the purchase process.</p>
<?php if ($error): ?>
<div class="alert alert-error" style="margin-bottom: 2rem;"><?= $error ?></div>
<?php endif; ?>
<form method="POST">
<div class="form-group">
<label>Your Full Name</label>
<input type="text" name="buyer_name" class="form-control" value="<?= htmlspecialchars($_SESSION['user_name']) ?>" required placeholder="Enter your full legal name">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;">
<div class="form-group">
<label>Full Legal Name</label>
<input type="text" name="buyer_name" class="form-control" value="<?= htmlspecialchars($_SESSION['user_name']) ?>" required>
</div>
<div class="form-group">
<label>Phone Number</label>
<input type="text" name="buyer_phone" class="form-control" required placeholder="+93 7xx xxx xxx">
</div>
</div>
<div class="form-group">
<label>Active Phone Number (For Verification)</label>
<input type="text" name="buyer_phone" class="form-control" required placeholder="+93 7xx xxx xxx">
<label>Bank ID / Account Number</label>
<input type="text" name="bank_id" class="form-control" required placeholder="Azizi Bank / Kabul Bank ID">
<small style="color: var(--text-secondary);">This ID will be used to verify your transaction.</small>
</div>
<div class="form-group">
<label>Additional Personal Info (ID Card No, Address, etc.)</label>
<textarea name="personal_info" class="form-control" rows="3" required placeholder="Enter your ID card number and current residential address for legal documentation..."></textarea>
</div>
<div style="margin: 3rem 0; padding: 2.5rem; background: rgba(212, 175, 55, 0.05); border-left: 5px solid var(--primary-color); border-radius: 16px;">
<h4 style="color: var(--primary-color); margin-bottom: 1rem; font-size: 1.2rem; display: flex; align-items: center; gap: 0.8rem;">
<span>🏦</span> Offline Payment Process
</h4>
<p style="font-size: 0.95rem; color: var(--text-secondary); line-height: 1.8;">
1. Submit this purchase request.<br>
2. Wait for admin approval (usually within 24 hours).<br>
3. Visit any <strong>Azizi Bank</strong> or <strong>New Kabul Bank</strong> branch.<br>
4. Deposit the total amount into the verified seller's account.<br>
5. Upload the bank receipt to complete the transaction.
<div style="margin: 2rem 0; padding: 2rem; background: rgba(212, 175, 55, 0.05); border-left: 5px solid var(--primary-color); border-radius: 12px;">
<p style="font-size: 0.9rem; color: var(--text-secondary); line-height: 1.6; margin: 0;">
<strong>Note:</strong> By submitting this request, you agree to the verification process. After admin approval, a sale receipt will be generated.
</p>
</div>
<div style="display: flex; gap: 1.5rem; align-items: center;">
<button type="submit" class="btn btn-primary" style="flex: 2; padding: 1.2rem; font-size: 1.1rem;">Confirm & Submit Request</button>
<a href="car_detail.php?id=<?= $id ?>" class="btn btn-outline" style="flex: 1; text-align: center; padding: 1.2rem; font-size: 1.1rem;">Cancel</a>
<button type="submit" class="btn btn-primary" style="flex: 2; padding: 1.2rem; font-size: 1.1rem; font-weight: 700;">Submit Purchase Request</button>
<a href="car_detail.php?id=<?= $id ?>" class="btn btn-outline" style="flex: 1; text-align: center; padding: 1.2rem;">Cancel</a>
</div>
</form>
</div>

115
receipt.php Normal file
View File

@ -0,0 +1,115 @@
<?php
require_once __DIR__ . '/includes/header.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
$pdo = db();
$purchase_id = $_GET['id'] ?? 0;
// Fetch purchase details (must be approved and belong to the user or admin)
$stmt = $pdo->prepare("
SELECT p.*, c.brand, c.model, c.year, c.price, c.city, u.name as seller_name, u.phone as seller_phone
FROM purchases p
JOIN cars c ON p.car_id = c.id
JOIN users u ON c.user_id = u.id
WHERE p.id = ? AND p.status = 'approved' AND (p.user_id = ? OR ?)
");
$isAdmin = isset($_SESSION['role']) && $_SESSION['role'] === 'admin';
$stmt->execute([$purchase_id, $_SESSION['user_id'], $isAdmin]);
$data = $stmt->fetch();
if (!$data) {
echo "<div class='container' style='padding: 5rem; text-align: center;'><h1>Receipt not found or not approved.</h1><a href='dashboard.php' class='btn btn-primary'>Back to Dashboard</a></div>";
require_once __DIR__ . '/includes/footer.php';
exit;
}
?>
<div class="container" style="max-width: 800px; padding: 4rem 0;">
<div id="receipt" class="glass" style="padding: 4rem; background: white; color: #333; position: relative; overflow: hidden; border: 1px solid #ddd; border-radius: 0;">
<!-- Watermark -->
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-45deg); font-size: 8rem; font-weight: 900; color: rgba(46, 213, 115, 0.1); pointer-events: none; z-index: 0; white-space: nowrap;">PAID & VERIFIED</div>
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4rem; position: relative; z-index: 1;">
<div>
<h1 style="color: var(--primary-color); font-weight: 900; font-size: 2.5rem; margin: 0;">AfgCars</h1>
<p style="color: #666; margin-top: 0.5rem;">Premium Vehicle Marketplace</p>
</div>
<div style="text-align: right;">
<h2 style="font-weight: 800; margin: 0;">OFFICIAL RECEIPT</h2>
<p style="color: #666; margin-top: 0.5rem;">Receipt #: RC-<?= str_pad($data['id'], 6, '0', STR_PAD_LEFT) ?></p>
<p style="color: #666;">Date: <?= date('M d, Y', strtotime($data['created_at'])) ?></p>
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 4rem; margin-bottom: 4rem; position: relative; z-index: 1;">
<div>
<h4 style="border-bottom: 2px solid #eee; padding-bottom: 0.5rem; margin-bottom: 1rem; color: #888; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px;">Buyer Details</h4>
<p style="font-weight: 700; font-size: 1.1rem; margin-bottom: 0.3rem;"><?= htmlspecialchars($data['buyer_name']) ?></p>
<p style="margin-bottom: 0.3rem;"><?= htmlspecialchars($data['buyer_email']) ?></p>
<p style="margin-bottom: 0.3rem;"><?= htmlspecialchars($data['buyer_phone']) ?></p>
<p style="font-weight: 600; color: var(--primary-color); margin-top: 1rem;">Bank ID: <?= htmlspecialchars($data['bank_id']) ?></p>
</div>
<div>
<h4 style="border-bottom: 2px solid #eee; padding-bottom: 0.5rem; margin-bottom: 1rem; color: #888; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px;">Seller Details</h4>
<p style="font-weight: 700; font-size: 1.1rem; margin-bottom: 0.3rem;"><?= htmlspecialchars($data['seller_name']) ?></p>
<p style="margin-bottom: 0.3rem;">Verification: Verified Merchant</p>
<p style="margin-bottom: 0.3rem;"><?= htmlspecialchars($data['seller_phone']) ?></p>
<p style="margin-bottom: 0.3rem;"><?= htmlspecialchars($data['city']) ?>, Afghanistan</p>
</div>
</div>
<div style="margin-bottom: 4rem; position: relative; z-index: 1;">
<table style="width: 100%; border-collapse: collapse;">
<thead>
<tr style="background: #f9f9f9; text-align: left;">
<th style="padding: 1rem; border-bottom: 2px solid #ddd;">Description</th>
<th style="padding: 1rem; border-bottom: 2px solid #ddd; text-align: right;">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding: 1.5rem 1rem; border-bottom: 1px solid #eee;">
<div style="font-weight: 700; font-size: 1.2rem;"><?= htmlspecialchars($data['brand'] . ' ' . $data['model']) ?></div>
<div style="color: #666; font-size: 0.9rem; margin-top: 0.3rem;"><?= $data['year'] ?> Model - Transaction Verified via Bank ID: <?= htmlspecialchars($data['bank_id']) ?></div>
</td>
<td style="padding: 1.5rem 1rem; border-bottom: 1px solid #eee; text-align: right; font-weight: 700; font-size: 1.2rem;">$<?= number_format($data['price']) ?></td>
</tr>
</tbody>
<tfoot>
<tr>
<td style="padding: 2rem 1rem; text-align: right; font-weight: 600; font-size: 1.1rem;">Total Paid</td>
<td style="padding: 2rem 1rem; text-align: right; font-weight: 900; font-size: 1.8rem; color: var(--primary-color);">$<?= number_format($data['price']) ?></td>
</tr>
</tfoot>
</table>
</div>
<div style="border-top: 1px dashed #ccc; padding-top: 2rem; text-align: center; color: #888; font-size: 0.85rem; position: relative; z-index: 1;">
<p style="margin-bottom: 0.5rem;">This is a computer-generated receipt. No signature is required.</p>
<p>AfgCars Verification System - Securing the Afghan Automotive Market</p>
</div>
<!-- Paid Badge -->
<div style="position: absolute; bottom: 100px; right: 40px; border: 5px double var(--success); color: var(--success); padding: 10px 20px; font-size: 2rem; font-weight: 900; transform: rotate(-15deg); border-radius: 10px; opacity: 0.8;">PAID</div>
</div>
<div style="margin-top: 3rem; display: flex; gap: 1.5rem; justify-content: center;">
<button onclick="window.print()" class="btn btn-primary">Print Receipt</button>
<a href="dashboard.php" class="btn btn-outline">Back to Dashboard</a>
</div>
</div>
<style>
@media print {
nav, footer, .btn { display: none !important; }
body { background: white !important; }
.container { max-width: 100% !important; padding: 0 !important; margin: 0 !important; }
.glass { border: none !important; box-shadow: none !important; }
}
</style>
<?php require_once __DIR__ . '/includes/footer.php'; ?>