diff --git a/admin/branches.php b/admin/branches.php index a4a9ba9..8a8317b 100644 --- a/admin/branches.php +++ b/admin/branches.php @@ -91,4 +91,11 @@ $branches = $pdo->query("SELECT * FROM branches ORDER BY created_at DESC")->fetc + diff --git a/admin/cars.php b/admin/cars.php index 2d9d601..884e9d9 100644 --- a/admin/cars.php +++ b/admin/cars.php @@ -16,12 +16,29 @@ if (isset($_POST['delete_car'])) { // Handle Add (Basic Implementation) if (isset($_POST['add_car'])) { try { - $stmt = $pdo->prepare("INSERT INTO cars (vin, brand, model, year, price, mileage, transmission, fuel_type, status, branch_id, dealer_id, installment_available) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'Available', ?, ?, ?)"); + $image_url = 'assets/images/cars/default.jpg'; // Default + + // Handle Image Upload + if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { + $uploadDir = __DIR__ . '/../assets/images/cars/'; + if (!is_dir($uploadDir)) mkdir($uploadDir, 0777, true); + + $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); + $filename = uniqid('car_') . '.' . $ext; + $targetPath = $uploadDir . $filename; + + if (move_uploaded_file($_FILES['image']['tmp_name'], $targetPath)) { + $image_url = 'assets/images/cars/' . $filename; + } + } + + $stmt = $pdo->prepare("INSERT INTO cars (vin, brand, model, year, price, mileage, transmission, fuel_type, status, branch_id, dealer_id, installment_available, image_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'Available', ?, ?, ?, ?)"); $stmt->execute([ $_POST['vin'], $_POST['brand'], $_POST['model'], $_POST['year'], $_POST['price'], $_POST['mileage'], $_POST['transmission'], $_POST['fuel_type'], $_POST['branch_id'], $_POST['dealer_id'] ?: null, - isset($_POST['installment_available']) ? 1 : 0 + isset($_POST['installment_available']) ? 1 : 0, + $image_url ]); // Log activity @@ -83,9 +100,13 @@ $cars = $stmt->fetchAll();
diff --git a/marketplace.php b/marketplace.php index 3df1f94..5da8e4a 100644 --- a/marketplace.php +++ b/marketplace.php @@ -56,7 +56,7 @@ try {