AFG CARS Enterprise Setup"; try { global $pdo; // Assumes db/config.php creates $pdo echo "
Schema imported successfully.
"; echo "Admin user created (admin@afgcars.com / admin123)
"; } $stmt->execute(['John Doe', 'user@example.com', password_hash('user123', PASSWORD_DEFAULT), 'user']); echo "Demo user created (user@example.com / user123)
"; // Seed Branches // Tables are fresh from schema import, so no need to truncate $branches = [ ['Kabul Main', 'Kabul', 'Shar-e-Naw, Kabul', '+93 700 111 222'], ['Herat Branch', 'Herat', 'Main Road, Herat', '+93 700 333 444'], ['Mazar Center', 'Mazar-i-Sharif', 'Balkh Street, Mazar', '+93 700 555 666'], ['Kandahar Hub', 'Kandahar', 'Airport Road, Kandahar', '+93 700 777 888'] ]; $stmt = $pdo->prepare("INSERT INTO branches (name, city, address, phone) VALUES (?, ?, ?, ?)"); foreach ($branches as $branch) { $stmt->execute($branch); } echo "Branches seeded.
"; // Seed Cars // $pdo->exec("SET FOREIGN_KEY_CHECKS=0"); // $pdo->exec("TRUNCATE TABLE cars"); // $pdo->exec("SET FOREIGN_KEY_CHECKS=1"); $brands = ['Toyota', 'Lexus', 'Mercedes-Benz', 'BMW', 'Audi', 'Land Rover', 'Porsche', 'Tesla']; $models = [ 'Toyota' => ['Camry', 'Land Cruiser', 'Corolla', 'RAV4'], 'Lexus' => ['LX 600', 'RX 350', 'ES 350'], 'Mercedes-Benz' => ['S-Class', 'G-Wagon', 'E-Class'], 'BMW' => ['X7', 'X5', '7 Series'], 'Audi' => ['Q8', 'A8', 'RS7'], 'Land Rover' => ['Defender', 'Range Rover'], 'Porsche' => ['911 Carrera', 'Cayenne'], 'Tesla' => ['Model S', 'Model X'] ]; $stmt = $pdo->prepare("INSERT INTO cars (brand, model, year, price, mileage, fuel_type, transmission, description, image_path, branch_id, is_featured, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); for ($i = 1; $i <= 20; $i++) { $brand = $brands[array_rand($brands)]; $model = $models[$brand][array_rand($models[$brand])]; $year = rand(2020, 2024); $price = rand(25000, 150000); $mileage = rand(0, 50000); $fuel = rand(0, 1) ? 'Petrol' : 'Hybrid'; $desc = "Premium condition $brand $model. Full options, well maintained."; $image = "assets/images/cars/car{$i}.jpg"; $branch_id = rand(1, 4); $is_featured = ($i <= 6) ? 1 : 0; // First 6 are featured $stmt->execute([ $brand, $model, $year, $price, $mileage, $fuel, 'Automatic', $desc, $image, $branch_id, $is_featured, 'available' ]); } echo "20 Demo cars seeded.
"; echo "