37650-vm/install.php
Flatlogic Bot 1c03905469 sad
2026-01-22 08:07:11 +00:00

632 lines
25 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// install.php
// Single installation file to set up the project on Windows (XAMPP) or Linux.
require_once 'db/config.php';
// Disable output buffering to show progress in real-time
if (function_exists('apache_setenv')) {
@apache_setenv('no-gzip', 1);
}
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);
echo "<!DOCTYPE html><html><head><title>Installation</title><style>body{font-family: sans-serif; padding: 20px; line-height: 1.6;} .success{color: green;} .error{color: red;} .step{margin-bottom: 10px;}</style></head><body>";
echo "<h1>Car Sells in Afghanistan - Installation</h1>";
try {
// 1. Connect to Database Server
$pdo = db();
echo "<div class='step success'>✅ Connected to Database Server.</div>";
// 2. Create Database (if it doesn't exist)
$dbName = DB_NAME;
try {
$pdo->exec("CREATE DATABASE IF NOT EXISTS `$dbName` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
echo "<div class='step success'>✅ Database `$dbName` checked/created.</div>";
} catch (PDOException $e) {
echo "<div class='step'> Note: Could not create database (might already exist or permission denied). Proceeding...</div>";
}
// Select the database
$pdo->exec("USE `$dbName`");
// 3. Drop existing tables (Clean Install)
$pdo->exec("SET FOREIGN_KEY_CHECKS=0");
$tables = ['reviews', 'bookings', 'cars', 'users'];
foreach ($tables as $table) {
$pdo->exec("DROP TABLE IF EXISTS `$table`");
}
$pdo->exec("SET FOREIGN_KEY_CHECKS=1");
echo "<div class='step success'>✅ Existing tables dropped (Clean Install).</div>";
// 4. Create Tables
// Users Table
$pdo->exec("CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
role VARCHAR(20) DEFAULT 'user',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
echo "<div class='step success'>✅ Table `users` created.</div>";
// Cars Table
$pdo->exec("CREATE TABLE cars (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NULL,
title VARCHAR(255) NULL,
make VARCHAR(100),
model VARCHAR(100),
year INT,
mileage INT,
price DECIMAL(10,2),
description TEXT,
status VARCHAR(50) NOT NULL DEFAULT 'pending',
color VARCHAR(50),
province VARCHAR(100),
city VARCHAR(100),
image_url VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
)");
echo "<div class='step success'>✅ Table `cars` created.</div>";
// Bookings Table
$pdo->exec("CREATE TABLE bookings (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
car_id INT NOT NULL,
booking_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
status VARCHAR(50) NOT NULL DEFAULT 'pending',
bank_province VARCHAR(100) NULL,
bank_account_number VARCHAR(100) NULL,
sale_price DECIMAL(10, 2) NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE
)");
echo "<div class='step success'>✅ Table `bookings` created.</div>";
// Reviews Table
$pdo->exec("CREATE TABLE reviews (
id INT AUTO_INCREMENT PRIMARY KEY,
car_id INT NOT NULL,
user_id INT NOT NULL,
rating INT NOT NULL CHECK (rating >= 1 AND rating <= 5),
review TEXT,
status VARCHAR(20) DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
)");
echo "<div class='step success'>✅ Table `reviews` created.</div>";
// 5. Create Default Admin User
$adminUser = 'admin';
$adminEmail = 'admin@gmail.com';
$adminPass = '123'; // As requested
$adminHash = password_hash($adminPass, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, 'admin')");
$stmt->execute([$adminUser, $adminEmail, $adminHash]);
$adminId = $pdo->lastInsertId();
echo "<div class='step success'>✅ Admin user created.<br> &nbsp;&nbsp; Username: <b>$adminUser</b><br> &nbsp;&nbsp; Email: <b>$adminEmail</b><br> &nbsp;&nbsp; Password: <b>$adminPass</b></div>";
// 6. Insert Sample Data (Cars)
// 35 Total Cars (15 original + 20 new)
$carsData = [
// Original 15
[
'title' => 'Toyota Corolla 2020 Clean',
'make' => 'Toyota',
'model' => 'Corolla',
'year' => 2020,
'mileage' => 15000,
'price' => 18500.00,
'description' => 'Very clean car, no accidents. Perfect for city driving.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/112460/pexels-photo-112460.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Honda Civic 2018 Sport',
'make' => 'Honda',
'model' => 'Civic',
'year' => 2018,
'mileage' => 45000,
'price' => 16200.00,
'description' => 'Sport mode, leather seats, sunroof. Excellent condition.',
'status' => 'approved',
'color' => 'Black',
'province' => 'Herat',
'city' => 'Herat',
'image_url' => 'https://images.pexels.com/photos/170811/pexels-photo-170811.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Ford Ranger 2019 4x4',
'make' => 'Ford',
'model' => 'Ranger',
'year' => 2019,
'mileage' => 30000,
'price' => 25000.00,
'description' => 'Strong pickup for tough roads. 4x4 capability.',
'status' => 'pending',
'color' => 'Blue',
'province' => 'Kandahar',
'city' => 'Kandahar',
'image_url' => 'https://images.pexels.com/photos/919073/pexels-photo-919073.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Toyota Land Cruiser 2022',
'make' => 'Toyota',
'model' => 'Land Cruiser',
'year' => 2022,
'mileage' => 5000,
'price' => 85000.00,
'description' => 'Luxury SUV, fully loaded, V8 engine.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/205740/pexels-photo-205740.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Toyota Camry 2015 XLE',
'make' => 'Toyota',
'model' => 'Camry',
'year' => 2015,
'mileage' => 80000,
'price' => 12500.00,
'description' => 'Reliable family sedan, fuel efficient.',
'status' => 'approved',
'color' => 'Silver',
'province' => 'Mazar-i-Sharif',
'city' => 'Mazar',
'image_url' => 'https://images.pexels.com/photos/244206/pexels-photo-244206.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Hyundai Sonata 2021 Hybrid',
'make' => 'Hyundai',
'model' => 'Sonata',
'year' => 2021,
'mileage' => 12000,
'price' => 22000.00,
'description' => 'Hybrid engine, great mileage, modern tech.',
'status' => 'approved',
'color' => 'Grey',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/3764984/pexels-photo-3764984.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Mercedes-Benz C-Class 2016',
'make' => 'Mercedes-Benz',
'model' => 'C-Class',
'year' => 2016,
'mileage' => 55000,
'price' => 28000.00,
'description' => 'Luxury interior, smooth ride, imported from Germany.',
'status' => 'approved',
'color' => 'Black',
'province' => 'Herat',
'city' => 'Herat',
'image_url' => 'https://images.pexels.com/photos/116675/pexels-photo-116675.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'BMW X5 2019 xDrive',
'make' => 'BMW',
'model' => 'X5',
'year' => 2019,
'mileage' => 25000,
'price' => 55000.00,
'description' => 'Premium SUV, panoramic sunroof, leather interior.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/3752169/pexels-photo-3752169.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Kia Sportage 2020 AWD',
'make' => 'Kia',
'model' => 'Sportage',
'year' => 2020,
'mileage' => 18000,
'price' => 21000.00,
'description' => 'Compact SUV, AWD, apple carplay.',
'status' => 'approved',
'color' => 'Red',
'province' => 'Jalalabad',
'city' => 'Jalalabad',
'image_url' => 'https://images.pexels.com/photos/4062468/pexels-photo-4062468.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Nissan Sunny 2017',
'make' => 'Nissan',
'model' => 'Sunny',
'year' => 2017,
'mileage' => 60000,
'price' => 9500.00,
'description' => 'Economic car, cheap maintenance.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kandahar',
'city' => 'Kandahar',
'image_url' => 'https://images.pexels.com/photos/4574184/pexels-photo-4574184.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Toyota Hilux 2021 Revo',
'make' => 'Toyota',
'model' => 'Hilux',
'year' => 2021,
'mileage' => 10000,
'price' => 42000.00,
'description' => 'Powerful diesel engine, off-road ready.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/6301931/pexels-photo-6301931.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Lexus LX570 2018',
'make' => 'Lexus',
'model' => 'LX570',
'year' => 2018,
'mileage' => 40000,
'price' => 95000.00,
'description' => 'Top of the line luxury, armored option available.',
'status' => 'approved',
'color' => 'Black',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/1592384/pexels-photo-1592384.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Suzuki Alto 2022',
'make' => 'Suzuki',
'model' => 'Alto',
'year' => 2022,
'mileage' => 5000,
'price' => 7500.00,
'description' => 'Small city car, very fuel efficient.',
'status' => 'approved',
'color' => 'Red',
'province' => 'Mazar-i-Sharif',
'city' => 'Mazar',
'image_url' => 'https://images.pexels.com/photos/35967/mini-cooper-auto-model-vehicle.jpg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Mazda 6 2019',
'make' => 'Mazda',
'model' => '6',
'year' => 2019,
'mileage' => 28000,
'price' => 19500.00,
'description' => 'Stylish sedan, premium interior.',
'status' => 'approved',
'color' => 'Blue',
'province' => 'Herat',
'city' => 'Herat',
'image_url' => 'https://images.pexels.com/photos/1007410/pexels-photo-1007410.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Chevrolet Tahoe 2015',
'make' => 'Chevrolet',
'model' => 'Tahoe',
'year' => 2015,
'mileage' => 85000,
'price' => 26000.00,
'description' => 'Large family SUV, spacious, American muscle.',
'status' => 'approved',
'color' => 'Black',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/4173163/pexels-photo-4173163.jpeg?auto=compress&cs=tinysrgb&w=600'
],
// New 20 Cars
[
'title' => 'Tesla Model 3 2022 Long Range',
'make' => 'Tesla',
'model' => 'Model 3',
'year' => 2022,
'mileage' => 8000,
'price' => 45000.00,
'description' => 'Electric future. Autopilot included. Mint condition.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/11139552/pexels-photo-11139552.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Ford Mustang 2018 GT',
'make' => 'Ford',
'model' => 'Mustang',
'year' => 2018,
'mileage' => 32000,
'price' => 38000.00,
'description' => 'V8 Muscle car. Sounds amazing.',
'status' => 'approved',
'color' => 'Yellow',
'province' => 'Herat',
'city' => 'Herat',
'image_url' => 'https://images.pexels.com/photos/3311574/pexels-photo-3311574.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Audi Q7 2019 Quattro',
'make' => 'Audi',
'model' => 'Q7',
'year' => 2019,
'mileage' => 41000,
'price' => 52000.00,
'description' => '7 seater luxury SUV. Smooth ride.',
'status' => 'approved',
'color' => 'Black',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/1035108/pexels-photo-1035108.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Jeep Wrangler 2020 Rubicon',
'make' => 'Jeep',
'model' => 'Wrangler',
'year' => 2020,
'mileage' => 15000,
'price' => 48000.00,
'description' => 'Ultimate off-road machine. Convertible top.',
'status' => 'approved',
'color' => 'Red',
'province' => 'Jalalabad',
'city' => 'Jalalabad',
'image_url' => 'https://images.pexels.com/photos/2933243/pexels-photo-2933243.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Hyundai Tucson 2022',
'make' => 'Hyundai',
'model' => 'Tucson',
'year' => 2022,
'mileage' => 5000,
'price' => 31000.00,
'description' => 'Modern design, very comfortable.',
'status' => 'approved',
'color' => 'Grey',
'province' => 'Mazar-i-Sharif',
'city' => 'Mazar',
'image_url' => 'https://images.pexels.com/photos/13622998/pexels-photo-13622998.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Range Rover Sport 2017',
'make' => 'Land Rover',
'model' => 'Range Rover',
'year' => 2017,
'mileage' => 60000,
'price' => 65000.00,
'description' => 'British luxury. Powerful engine.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/116675/pexels-photo-116675.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Volkswagen Golf 2016 GTI',
'make' => 'Volkswagen',
'model' => 'Golf',
'year' => 2016,
'mileage' => 70000,
'price' => 18000.00,
'description' => 'Hot hatch. Fast and fun.',
'status' => 'approved',
'color' => 'Red',
'province' => 'Kandahar',
'city' => 'Kandahar',
'image_url' => 'https://images.pexels.com/photos/10771143/pexels-photo-10771143.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Subaru Forester 2018',
'make' => 'Subaru',
'model' => 'Forester',
'year' => 2018,
'mileage' => 55000,
'price' => 22000.00,
'description' => 'Reliable AWD. Great for snow.',
'status' => 'approved',
'color' => 'Green',
'province' => 'Bamyan',
'city' => 'Bamyan',
'image_url' => 'https://images.pexels.com/photos/15671190/pexels-photo-15671190.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Porsche Cayenne 2015',
'make' => 'Porsche',
'model' => 'Cayenne',
'year' => 2015,
'mileage' => 85000,
'price' => 35000.00,
'description' => 'Sporty SUV. High performance.',
'status' => 'approved',
'color' => 'Black',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/9661271/pexels-photo-9661271.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Toyota RAV4 2021',
'make' => 'Toyota',
'model' => 'RAV4',
'year' => 2021,
'mileage' => 12000,
'price' => 29000.00,
'description' => 'Best selling SUV. Reliable.',
'status' => 'approved',
'color' => 'Blue',
'province' => 'Herat',
'city' => 'Herat',
'image_url' => 'https://images.pexels.com/photos/14532256/pexels-photo-14532256.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Nissan Patrol 2019',
'make' => 'Nissan',
'model' => 'Patrol',
'year' => 2019,
'mileage' => 45000,
'price' => 58000.00,
'description' => 'King of the desert. Spacious.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kandahar',
'city' => 'Kandahar',
'image_url' => 'https://images.pexels.com/photos/1592384/pexels-photo-1592384.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Chevrolet Camaro 2017',
'make' => 'Chevrolet',
'model' => 'Camaro',
'year' => 2017,
'mileage' => 38000,
'price' => 27000.00,
'description' => 'American icon. Fast.',
'status' => 'approved',
'color' => 'Yellow',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/2036544/pexels-photo-2036544.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Mercedes-Benz G-Wagon 2018',
'make' => 'Mercedes-Benz',
'model' => 'G-Class',
'year' => 2018,
'mileage' => 30000,
'price' => 120000.00,
'description' => 'Status symbol. Built like a tank.',
'status' => 'approved',
'color' => 'Black',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/1429775/pexels-photo-1429775.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Kia Sorento 2021',
'make' => 'Kia',
'model' => 'Sorento',
'year' => 2021,
'mileage' => 10000,
'price' => 34000.00,
'description' => 'Family SUV with 3 rows.',
'status' => 'approved',
'color' => 'Grey',
'province' => 'Mazar-i-Sharif',
'city' => 'Mazar',
'image_url' => 'https://images.pexels.com/photos/9714349/pexels-photo-9714349.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Lexus RX350 2016',
'make' => 'Lexus',
'model' => 'RX350',
'year' => 2016,
'mileage' => 65000,
'price' => 32000.00,
'description' => 'Comfortable luxury crossover.',
'status' => 'approved',
'color' => 'White',
'province' => 'Herat',
'city' => 'Herat',
'image_url' => 'https://images.pexels.com/photos/6560298/pexels-photo-6560298.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Hyundai Elantra 2019',
'make' => 'Hyundai',
'model' => 'Elantra',
'year' => 2019,
'mileage' => 40000,
'price' => 14000.00,
'description' => 'Compact sedan, good value.',
'status' => 'approved',
'color' => 'Blue',
'province' => 'Jalalabad',
'city' => 'Jalalabad',
'image_url' => 'https://images.pexels.com/photos/16834162/pexels-photo-16834162.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Toyota Prius 2017',
'make' => 'Toyota',
'model' => 'Prius',
'year' => 2017,
'mileage' => 75000,
'price' => 15500.00,
'description' => 'Hybrid pioneer. Excellent mpg.',
'status' => 'approved',
'color' => 'White',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/17604374/pexels-photo-17604374.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Ford F-150 2020',
'make' => 'Ford',
'model' => 'F-150',
'year' => 2020,
'mileage' => 25000,
'price' => 40000.00,
'description' => 'America\'s best selling truck.',
'status' => 'approved',
'color' => 'Blue',
'province' => 'Kandahar',
'city' => 'Kandahar',
'image_url' => 'https://images.pexels.com/photos/1637859/pexels-photo-1637859.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'BMW 3 Series 2018',
'make' => 'BMW',
'model' => '320i',
'year' => 2018,
'mileage' => 42000,
'price' => 25000.00,
'description' => 'Sports sedan. Driving pleasure.',
'status' => 'approved',
'color' => 'Silver',
'province' => 'Kabul',
'city' => 'Kabul',
'image_url' => 'https://images.pexels.com/photos/3689532/pexels-photo-3689532.jpeg?auto=compress&cs=tinysrgb&w=600'
],
[
'title' => 'Audi A6 2017',
'make' => 'Audi',
'model' => 'A6',
'year' => 2017,
'mileage' => 58000,
'price' => 26000.00,
'description' => 'Executive sedan. High tech.',
'status' => 'approved',
'color' => 'Black',
'province' => 'Herat',
'city' => 'Herat',
'image_url' => 'https://images.pexels.com/photos/119435/pexels-photo-119435.jpeg?auto=compress&cs=tinysrgb&w=600'
]
];
$insertCar = $pdo->prepare("INSERT INTO cars (user_id, title, make, model, year, mileage, price, description, status, color, province, city, image_url) VALUES (:user_id, :title, :make, :model, :year, :mileage, :price, :description, :status, :color, :province, :city, :image_url)");
foreach ($carsData as $car) {
$car['user_id'] = $adminId;
$insertCar->execute($car);
}
echo "<div class='step success'>✅ Seed data inserted (" . count($carsData) . " cars).</div>";
echo "<hr><h2>🎉 Installation Complete!</h2>";
echo "<p>You can now <a href='login.php'>Login here</a>.</p>";
echo "<p><b>Credentials:</b><br>Username: <code>admin</code> or <code>admin@gmail.com</code><br>Password: <code>123</code></p>";
} catch (PDOException $e) {
echo "<div class='step error'>❌ Installation Failed: " . htmlspecialchars($e->getMessage()) . "</div>";
}
echo "</body></html>";
?>