/var/www/vhosts/m-auto.co/httpdocs/admin
Edit: /var/www/vhosts/m-auto.co/httpdocs/admin/car_form.php (40348B)
'',
'name' => '',
'brand' => '',
'model' => '',
'year' => '',
'category' => '',
'description' => '',
'image' => '',
'video_url' => ''
];
$car_images = [];
$car_trims = [];
$page_title = "إضافة سيارة جديدة";
// Fetch brands and categories for dropdowns
$brands_result = $conn->query("SELECT name, logo FROM brands ORDER BY name");
$categories_result = $conn->query("SELECT name FROM categories ORDER BY name");
// Check if this is an edit request
if (isset($_GET['id'])) {
$car_id = $_GET['id'];
$stmt = $conn->prepare("SELECT * FROM cars WHERE id = ?");
$stmt->bind_param("i", $car_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 1) {
$car = $result->fetch_assoc();
$page_title = "تعديل بيانات السيارة";
// Fetch existing images for this car
$images_stmt = $conn->prepare("SELECT * FROM car_images WHERE car_id = ? ORDER BY is_primary DESC, sort_order ASC");
$images_stmt->bind_param("i", $car_id);
$images_stmt->execute();
$images_result = $images_stmt->get_result();
while ($img = $images_result->fetch_assoc()) {
$car_images[] = $img;
}
$images_stmt->close();
// Fetch existing trims for this car
$trims_stmt = $conn->prepare("SELECT * FROM car_trims WHERE car_id = ? ORDER BY price ASC");
$trims_stmt->bind_param("i", $car_id);
$trims_stmt->execute();
$trims_result = $trims_stmt->get_result();
while ($trim = $trims_result->fetch_assoc()) {
$car_trims[] = $trim;
}
$trims_stmt->close();
} else {
header("Location: cars.php?error=Car not found");
exit();
}
$stmt->close();
}
// Populate with at least one default trim if empty
if (empty($car_trims)) {
$car_trims[] = [
'id' => '',
'name' => 'الفئة القياسية',
'price' => '',
'fuel_type' => '',
'car_condition' => '',
'engine_capacity' => '',
'transmission_type' => '',
'horsepower' => '',
'torque' => '',
'acceleration' => '',
'top_speed' => '',
'fuel_consumption' => '',
'drivetrain' => '',
'seating_capacity' => '',
'body_type' => '',
'exterior_color' => '',
'interior_color' => '',
'tech_specs_pdf' => ''
];
}
?>
= $page_title ?>