| Car |
@@ -142,7 +142,7 @@ $recentMessages = $pdo->query("SELECT * FROM contact_messages ORDER BY created_a
= date('M d', strtotime($msg['created_at'])) ?>
- = htmlspecialchars(substr($msg['message'], 0, 80)) ?>...
+ = htmlspecialchars(substr($msg['message'] ?? '', 0, 80)) ?>...
diff --git a/admin_messages.php b/admin_messages.php
index 2cd0340..00061e4 100644
--- a/admin_messages.php
+++ b/admin_messages.php
@@ -37,11 +37,12 @@ $messages = $pdo->query("SELECT * FROM contact_messages ORDER BY created_at DESC
diff --git a/admin_purchases.php b/admin_purchases.php
new file mode 100644
index 0000000..25e2c86
--- /dev/null
+++ b/admin_purchases.php
@@ -0,0 +1,136 @@
+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();
+?>
+
+
+
+
+
Purchase Requests
+
Review and manage buyer bank verification requests.
+
+
Back to Dashboard
+
+
+
+
+ = $message ?>
+
+
+
+
+
+
+
+ | Vehicle |
+ Buyer Details |
+ Bank ID |
+ Price |
+ Status |
+ Action |
+
+
+
+
+
+
+
+  ?>)
+
+ = htmlspecialchars($p['brand'] . ' ' . $p['model']) ?>
+ = $p['year'] ?>
+
+
+ |
+
+ = htmlspecialchars($p['buyer_name']) ?>
+ = htmlspecialchars($p['buyer_phone']) ?>
+ = htmlspecialchars($p['personal_info']) ?>
+ |
+
+ = htmlspecialchars($p['bank_id']) ?>
+ |
+ $= number_format($p['price']) ?> |
+
+
+ = $p['status'] ?>
+
+ |
+
+
+
+
+
+
+
+ Completed
+
+ |
+
+
+
+
+ | No purchase requests found. |
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/admin_users.php b/admin_users.php
index 6cc5b31..6767659 100644
--- a/admin_users.php
+++ b/admin_users.php
@@ -39,11 +39,12 @@ $users = $pdo->query("SELECT * FROM users WHERE deleted_at IS NULL ORDER BY crea
@@ -56,9 +57,9 @@ $users = $pdo->query("SELECT * FROM users WHERE deleted_at IS NULL ORDER BY crea
| User Info |
+ Phone/Address |
Role |
Status |
- Joined |
Actions |
@@ -69,9 +70,12 @@ $users = $pdo->query("SELECT * FROM users WHERE deleted_at IS NULL ORDER BY crea
= htmlspecialchars($u['name']) ?>
= htmlspecialchars($u['email']) ?>
+
+ = htmlspecialchars($u['phone'] ?: 'N/A') ?>
+ = htmlspecialchars($u['address'] ?: 'N/A') ?>
+ |
= strtoupper($u['role']) ?> |
= ucfirst($u['status']) ?> |
- = date('M d, Y', strtotime($u['created_at'])) ?> |
diff --git a/car_detail.php b/car_detail.php
index 206b3f6..23c6c4b 100644
--- a/car_detail.php
+++ b/car_detail.php
@@ -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 " ";
- 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);
?>
-
-
+
+
+
+
-
-
- 1): ?>
-
-
-
-
-
- 📜 Detailed Description
-
-
- = nl2br(htmlspecialchars($car['description'])) ?>
-
-
-
-
- Vehicle Condition
- Excellent / Premium
-
-
- Transmission
- Automatic
-
-
- Fuel Type
- Petrol / Hybrid
-
-
- Import Status
- Custom Cleared
-
-
-
-
-
-
-
-
- = $car['year'] ?> MODEL
- 📍 = $car['city'] ?>, AFG
-
-
- = htmlspecialchars($car['brand'] . ' ' . $car['model']) ?>
- $= number_format($car['price']) ?>
-
-
-
- 👤 Seller: = htmlspecialchars($car['seller_name']) ?>
-
-
- 🆔 Listing ID: #AFG-= str_pad($car['id'], 5, '0', STR_PAD_LEFT) ?>
-
-
-
-
- Initiate Purchase
- Add to Favorites
-
-
- Interested in this vehicle? Log in to contact the seller.
- Login to Proceed
+
+  ?>)
+
+
-
-
- Share this listing:
-
- 📱
- 💬
- 📧
-
+
+
+
+
+  ?>)
+
+
+
+
+ Description
+
+ = htmlspecialchars($car['description']) ?>
-
-
-
- Similar Premium Vehicles
-
-
-
-
-
+
+
+
+
+ = htmlspecialchars($car['city']) ?>
+
+
+
+ = htmlspecialchars($car['brand'] . ' ' . $car['model']) ?>
+
+
+
+ Year: = $car['year'] ?> | Status: = ucfirst($car['status']) ?>
+
+
+
+ Current Price
+ $= number_format($car['price']) ?>
+
+
+
+
+ This vehicle has been sold.
+
+
+ Initiate Purchase Request
+
+
+
+
+
+ = strtoupper(substr($car['seller_name'], 0, 1)) ?>
-
-
- 📅 = htmlspecialchars($s['year']) ?>
- 📍 = htmlspecialchars($s['city']) ?>
-
- = htmlspecialchars($s['brand'] . ' ' . $s['model']) ?>
- $= number_format($s['price']) ?>
- View Details
+
+ Seller
+ = htmlspecialchars($car['seller_name']) ?>
-
+
+
+
+
+
+ 🛡️ AfgCars Secure
+
+
+ Every listing is manually verified by our team. Personal information and bank IDs are encrypted and used only for legal documentation.
+
-
+
+
-
+
\ No newline at end of file
diff --git a/cars.php b/cars.php
index 64d0490..5d018df 100644
--- a/cars.php
+++ b/cars.php
@@ -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'];
?>
-
- Premium Marketplace
-
-
+
+
+ Premium Inventory
+ Find the perfect vehicle for your lifestyle in our verified marketplace.
+
-
-
-
- 🚗💨
- No vehicles found
- We couldn't find any cars matching your current filters.
- Clear all filters
+
+ |