diff --git a/about.php b/about.php index d0a5f5c..a3826fe 100644 --- a/about.php +++ b/about.php @@ -1,59 +1,58 @@ -
-
+
+
-
-

About AFG_CARS

-

Establishing Excellence Since 2014

-
-

- AFG_CARS is Afghanistan's premier destination for high-end automotive solutions. We specialize in sourcing the world's most desired luxury and performance vehicles, ensuring each one meets our strict criteria for quality and history. -

-

- Our revolutionary installment programs have made luxury ownership possible for thousands of Afghan citizens, providing a transparent and secure path to vehicle ownership without the burden of immediate full-capital expenditure. -

- -
-
-

Our Vision

-

To modernize the Afghan automotive market through technology and transparency.

-
-
-

Our Mission

-

Providing quality vehicles for every road and every budget with absolute integrity.

-
-
+

About AFG CARS

+

Your trusted partner for premium automotive solutions in Afghanistan.

+

Founded in 2010, AFG CARS has established itself as the leading car dealership in Afghanistan. We specialize in importing and selling high-quality vehicles from top global manufacturers.

+

Our mission is to provide our customers with reliable, luxury vehicles at competitive prices, backed by exceptional customer service and flexible financing options.

- -
-
-
-
2K+
-
Cars Delivered
+
+
+
+
+

10+

+

Years Experience

+
+
+

5000+

+

Cars Sold

+
+
+

4

+

Major Branches

+
+
+

100%

+

Satisfaction

+
-
-
04
-
Showrooms
-
-
-
15+
-
Global Partners
-
-
-
100%
-
Verified Stock
-
-
-
-

Enterprise System Managed by Mohammad Sadiq

-

Lamp Stack | MariaDB | PHP 8.2 | Premium UI

-
+ +
+

Our Core Values

+
+
+

Integrity

+

We believe in transparent pricing and honest dealings with every customer.

+
+
+

Quality

+

Every vehicle undergoes a rigorous 150-point inspection before sale.

+
+
+

Service

+

Our relationship doesn't end at the sale; we provide ongoing support.

+
+
+
+ - + diff --git a/admin/cars.php b/admin/cars.php index 884e9d9..e39ca1c 100644 --- a/admin/cars.php +++ b/admin/cars.php @@ -1,188 +1,106 @@ prepare("DELETE FROM cars WHERE id = ?"); - $stmt->execute([$id]); - $success = "Car deleted successfully."; + $stmt->execute([$_GET['delete']]); + $msg = "Car deleted successfully."; } -// Handle Add (Basic Implementation) -if (isset($_POST['add_car'])) { - try { - $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, - $image_url - ]); - - // Log activity - $adminId = $_SESSION['user_id']; - $pdo->prepare("INSERT INTO activity_logs (user_id, action) VALUES (?, 'Added new car: ' . ?)")->execute([$adminId, $_POST['brand'] . ' ' . $_POST['model']]); - - $success = "Car added successfully."; - } catch (PDOException $e) { - $error = "Error adding car: " . $e->getMessage(); - } +// Handle Add +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $brand = $_POST['brand']; + $model = $_POST['model']; + $year = $_POST['year']; + $price = $_POST['price']; + $branch_id = $_POST['branch_id']; + + // Use a random placeholder from the 20 generated ones for demo purposes + $random_img = rand(1, 20); + $image_path = "assets/images/cars/car{$random_img}.jpg"; + + $stmt = $pdo->prepare("INSERT INTO cars (brand, model, year, price, branch_id, status, image_path, is_featured) VALUES (?, ?, ?, ?, ?, 'available', ?, 0)"); + $stmt->execute([$brand, $model, $year, $price, $branch_id, $image_path]); + $msg = "Car added successfully."; } +// Fetch Cars +$cars = $pdo->query("SELECT cars.*, branches.city FROM cars LEFT JOIN branches ON cars.branch_id = branches.id ORDER BY created_at DESC")->fetchAll(); $branches = $pdo->query("SELECT * FROM branches")->fetchAll(); -$dealers = $pdo->query("SELECT * FROM users WHERE role = 'Dealer'")->fetchAll(); - -$stmt = $pdo->query("SELECT cars.*, branches.name as branch_name FROM cars LEFT JOIN branches ON cars.branch_id = branches.id ORDER BY cars.created_at DESC"); -$cars = $stmt->fetchAll(); ?> - +
+ + +
+

Manage Cars

+ + +
+ +
+ -
-
- -
- - - - - - - - - - - - - - - - - - - - - - - -
IDBrand/ModelYearPriceStatusActions
#$ -
- - -
-
-
- - -
- - - + diff --git a/admin/dashboard.php b/admin/dashboard.php new file mode 100644 index 0000000..3e10964 --- /dev/null +++ b/admin/dashboard.php @@ -0,0 +1,78 @@ +query("SELECT COUNT(*) FROM cars")->fetchColumn(); +$total_users = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn(); +$total_sales = $pdo->query("SELECT COUNT(*) FROM sales")->fetchColumn(); +$pending_inquiries = $pdo->query("SELECT COUNT(*) FROM inquiries")->fetchColumn(); +?> + +
+ + +
+

Dashboard

+

Welcome back,

+ +
+
+

Total Cars

+
+
+
+

Total Users

+
+
+
+

Sales

+
+
+
+

Inquiries

+
+
+
+ +
+

Recent Inquiries

+ + + + + + + + query("SELECT * FROM inquiries ORDER BY created_at DESC LIMIT 5"); + while ($row = $stmt->fetch()): + ?> + + + + + + + "; } + ?> +
DateNameEmailMessage
...
No data
+
+
+
+ + diff --git a/admin/employees.php b/admin/employees.php new file mode 100644 index 0000000..e69de29 diff --git a/admin/includes/header.php b/admin/includes/header.php index c65423c..127cbc4 100644 --- a/admin/includes/header.php +++ b/admin/includes/header.php @@ -108,9 +108,9 @@ requireAdmin();
- + diff --git a/db/config.php b/db/config.php index 52026a9..113bcaa 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,22 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; +try { + $pdo = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4", DB_USER, DB_PASS); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); +} catch (PDOException $e) { + die("Database Connection Failed: " . $e->getMessage()); +} + +// Global helper function if needed, but we can just use $pdo +function getDB() { + global $pdo; + return $pdo; } diff --git a/db/database.sql b/db/database.sql new file mode 100644 index 0000000..7698d51 --- /dev/null +++ b/db/database.sql @@ -0,0 +1,86 @@ +-- Database Schema for AFG_CARS Enterprise System +SET FOREIGN_KEY_CHECKS=0; + +DROP TABLE IF EXISTS `installments`; +DROP TABLE IF EXISTS `sales`; +DROP TABLE IF EXISTS `inquiries`; +DROP TABLE IF EXISTS `cars`; +DROP TABLE IF EXISTS `branches`; +DROP TABLE IF EXISTS `users`; + +-- Users Table +CREATE TABLE `users` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(100) NOT NULL, + `email` VARCHAR(100) NOT NULL UNIQUE, + `password` VARCHAR(255) NOT NULL, + `role` ENUM('admin', 'user') DEFAULT 'user', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +-- Branches Table +CREATE TABLE `branches` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(100) NOT NULL, + `city` VARCHAR(50) NOT NULL, + `address` TEXT, + `phone` VARCHAR(20) +); + +-- Cars Table +CREATE TABLE `cars` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `branch_id` INT, + `brand` VARCHAR(50) NOT NULL, + `model` VARCHAR(50) NOT NULL, + `year` INT NOT NULL, + `price` DECIMAL(10, 2) NOT NULL, + `mileage` INT DEFAULT 0, + `fuel_type` VARCHAR(20) DEFAULT 'Petrol', + `transmission` VARCHAR(20) DEFAULT 'Automatic', + `description` TEXT, + `image_path` VARCHAR(255), + `status` ENUM('available', 'sold') DEFAULT 'available', + `is_featured` BOOLEAN DEFAULT 0, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`branch_id`) REFERENCES `branches`(`id`) ON DELETE SET NULL +); + +-- Sales Table +CREATE TABLE `sales` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `car_id` INT NOT NULL, + `user_id` INT NOT NULL, + `sale_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `sale_price` DECIMAL(10, 2) NOT NULL, + FOREIGN KEY (`car_id`) REFERENCES `cars`(`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +); + +-- Installments Table +CREATE TABLE `installments` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `car_id` INT NOT NULL, + `user_id` INT NOT NULL, + `total_amount` DECIMAL(10, 2) NOT NULL, + `monthly_payment` DECIMAL(10, 2) NOT NULL, + `months` INT NOT NULL, + `status` ENUM('pending', 'approved', 'rejected', 'completed') DEFAULT 'pending', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`car_id`) REFERENCES `cars`(`id`), + FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) +); + +-- Inquiries/Contact Table +CREATE TABLE `inquiries` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `car_id` INT DEFAULT NULL, + `user_id` INT DEFAULT NULL, + `name` VARCHAR(100), + `email` VARCHAR(100), + `message` TEXT, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (`car_id`) REFERENCES `cars`(`id`) ON DELETE SET NULL +); + +SET FOREIGN_KEY_CHECKS=1; diff --git a/dealer/index.php b/dealer/index.php deleted file mode 100644 index 4cbf9ec..0000000 --- a/dealer/index.php +++ /dev/null @@ -1,44 +0,0 @@ -prepare("SELECT COUNT(*) FROM cars WHERE dealer_id = ?"); -$myCars->execute([$dealerId]); -$myCarsCount = $myCars->fetchColumn(); - -$mySales = $pdo->prepare("SELECT COUNT(*) FROM sales s JOIN cars c ON s.car_id = c.id WHERE c.dealer_id = ?"); -$mySales->execute([$dealerId]); -$mySalesCount = $mySales->fetchColumn(); -?> - -
- - -
-
-
-
My Inventory
-
-
-
-
My Sales
-
-
- -
-

Manage Inventory

-

You can add new cars to your branch inventory here.

- Go to Inventory Management - -
-
- - diff --git a/includes/auth.php b/includes/auth.php index 33f8422..44fb63e 100644 --- a/includes/auth.php +++ b/includes/auth.php @@ -1,51 +1,46 @@ prepare("SELECT * FROM users WHERE username = ? OR email = ?"); - $stmt->execute([$username, $username]); +// Login function +function login($email, $password) { + global $pdo; + $stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?"); + $stmt->execute([$email]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; - $_SESSION['username'] = $user['username']; - $_SESSION['role'] = $user['role']; + $_SESSION['user_name'] = $user['name']; + $_SESSION['user_email'] = $user['email']; + $_SESSION['user_role'] = $user['role']; return true; } return false; } +// Logout function function logout() { session_destroy(); - header('Location: /login.php'); + header("Location: login.php"); exit; } diff --git a/includes/footer.php b/includes/footer.php index db733e9..4856aba 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -1,38 +1,37 @@ - - + diff --git a/includes/header.php b/includes/header.php index 92b64f5..ac17640 100644 --- a/includes/header.php +++ b/includes/header.php @@ -1,50 +1,40 @@ - <?= htmlspecialchars($projectTitle) ?> - - - - + AFG CARS Enterprise + -
- -
diff --git a/includes/middleware.php b/includes/middleware.php new file mode 100644 index 0000000..17e3f78 --- /dev/null +++ b/includes/middleware.php @@ -0,0 +1,19 @@ + 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18'; -} - -function pexels_get($url) { - $ch = curl_init(); - curl_setopt_array($ch, [ - CURLOPT_URL => $url, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ], - CURLOPT_TIMEOUT => 15, - ]); - $resp = curl_exec($ch); - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - if ($code >= 200 && $code < 300 && $resp) return json_decode($resp, true); - return null; -} - -function download_to($srcUrl, $destPath) { - $data = file_get_contents($srcUrl); - if ($data === false) return false; - if (!is_dir(dirname($destPath))) mkdir(dirname($destPath), 0775, true); - return file_put_contents($destPath, $data) !== false; -} diff --git a/index.php b/index.php index 9fb7762..789325f 100644 --- a/index.php +++ b/index.php @@ -1,94 +1,79 @@ query("SELECT c.*, b.name as branch_name - FROM cars c - JOIN branches b ON c.branch_id = b.id - WHERE c.status = 'Available' AND c.is_featured = 1 - ORDER BY c.created_at DESC - LIMIT 6")->fetchAll(); - - $branches = $db->query("SELECT * FROM branches LIMIT 3")->fetchAll(); + $stmt = $pdo->query("SELECT * FROM cars WHERE is_featured = 1 LIMIT 6"); + $featured_cars = $stmt->fetchAll(); + + // Fetch branches for selector + $branches = $pdo->query("SELECT * FROM branches")->fetchAll(); } catch (Exception $e) { $featured_cars = []; $branches = []; } ?> - +
-

Experience Supreme Luxury Automotive

-

Afghanistan's premier destination for elite vehicles, flexible installments, and professional service across our major branches.

-
- View Cars - Sell Your Car +
+

Find Your Dream Car

+

Premium Vehicles. Flexible Installments. Nationwide Service.

+ Browse Inventory
- -
-
-
-

Why Choose Us

-

Our commitment to excellence makes us the market leader.

+ +
+

Installment Calculator

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
-
-
-
- -

Trusted Dealership

-

Over 10 years of excellence in the automotive industry with thousands of happy clients.

-
-
- -

Verified Listings

-

Every vehicle undergoes a rigorous 150-point technical and background inspection.

-
-
- -

Secure Transactions

-

Safe, transparent, and legally binding payment processes for all vehicle sales.

-
-
- -

Fast Approval

-

Get your luxury car today with instant installment approval and minimal paperwork.

+
+ Monthly Payment: $1,145.83
- -
-
-
-

Featured Collection

-

Hand-picked premium vehicles currently available in our showrooms.

-
- View All -
+ +
+

Featured Vehicles

-
-
- PREMIUM - <?= htmlspecialchars($car['brand']) ?> -
-
-
-
$
-
- - +
+ <?= htmlspecialchars($car['brand']) ?> +
+

+
$
+
+ • + km
-
- Installments from $/mo -
-
@@ -96,78 +81,37 @@ try {
- -
-
-
-

Customer Reviews

-

What our elite clientele says about their experience with AFG_CARS.

-
-
-
-
-
-
AS
-
-
Ahmad Shah
-
Verified Buyer
-
-
-
- -
-

"The best experience I've had buying a car in Kabul. The installment plan was very easy to understand and the team was extremely professional. Highly recommended!"

-
-
-
-
MK
-
-
Mariam Khan
-
Business Owner
-
-
-
- -
-

"Found my dream Lexus LX 600 here. The condition was exactly as described. The Herat branch team was very helpful with all the paperwork. 5 stars!"

-
-
-
-
RZ
-
-
Reza Zaki
-
Verified Buyer
-
-
-
- -
-

"Transparent pricing and high-quality inventory. I appreciate the technical reports they provided before I made my decision. Best dealership in Afghanistan."

-
-
-
- - -
-
-
-

Dealership Locations

-

Visit us at any of our modern showrooms across Afghanistan.

-
-
-
+ +
+

Visit Our Branches

+
-
-

-
-

-

-

-
- Open Map +
+

+

+

+ View Map
- + + + diff --git a/login.php b/login.php index baf5f01..cc886a5 100644 --- a/login.php +++ b/login.php @@ -1,41 +1,27 @@ prepare("INSERT INTO activity_logs (user_id, action, ip_address) VALUES (?, 'Login', ?)") - ->execute([$_SESSION['user_id'], $_SERVER['REMOTE_ADDR']]); - } catch (Exception $e) { /* Ignore logging error */ } - - switch ($role) { - case 'Admin': - case 'Super Admin': - case 'Manager': - header('Location: /admin/index.php'); - break; - case 'Dealer': - header('Location: /dealer/index.php'); - break; - case 'Customer': - case 'Buyer': - header('Location: /buyer/index.php'); - break; - default: - header('Location: /index.php'); + if (login($email, $password)) { + if (getUserRole() === 'admin') { + header("Location: admin/index.php"); + } else { + header("Location: index.php"); } exit; } else { - $error = "Invalid username or password"; + $error = "Invalid email or password"; } } ?> @@ -44,81 +30,35 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { - Login - Car Market + Login - AFG CARS - - - - + diff --git a/register.php b/register.php deleted file mode 100644 index f253caf..0000000 --- a/register.php +++ /dev/null @@ -1,140 +0,0 @@ -prepare("SELECT id FROM users WHERE username = ? OR email = ?"); - $stmt->execute([$username, $email]); - if ($stmt->fetch()) { - $error = "Username or email already exists"; - } else { - // Register user - $hash = password_hash($password, PASSWORD_DEFAULT); - $stmt = $pdo->prepare("INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, 'Customer')"); - try { - $stmt->execute([$username, $email, $hash]); - $success = "Registration successful!"; - } catch (PDOException $e) { - $error = "Registration failed: " . $e->getMessage(); - } - } - } -} -?> - - - - - - Register - Car Market - - - - -
-

Create Account

- -
- - -
-

Proceed to Login

- -
-
- - -
-
- - -
-
- - -
-
- - -
- - -
- -
- - diff --git a/setup.php b/setup.php index f2e5797..5446afb 100644 --- a/setup.php +++ b/setup.php @@ -1,142 +1,70 @@ AFG CARS Enterprise Setup"; + try { - $db = db(); + global $pdo; // Assumes db/config.php creates $pdo - // Drop tables if they exist for a clean re-seed - $db->exec("SET FOREIGN_KEY_CHECKS = 0"); - $db->exec("DROP TABLE IF EXISTS notifications"); - $db->exec("DROP TABLE IF EXISTS activity_logs"); - $db->exec("DROP TABLE IF EXISTS installments"); - $db->exec("DROP TABLE IF EXISTS sales"); - $db->exec("DROP TABLE IF EXISTS reviews"); - $db->exec("DROP TABLE IF EXISTS car_images"); - $db->exec("DROP TABLE IF EXISTS cars"); - $db->exec("DROP TABLE IF EXISTS branches"); - $db->exec("DROP TABLE IF EXISTS users"); - $db->exec("SET FOREIGN_KEY_CHECKS = 1"); + echo "

1. Initializing Database Schema...

"; + + // Read SQL file + $sql_file = __DIR__ . '/db/database.sql'; + if (!file_exists($sql_file)) { + throw new Exception("Database SQL file not found at: $sql_file"); + } + + $sql_content = file_get_contents($sql_file); + + // Split into individual queries (basic splitting by semicolon) + // Note: This is a simple splitter and might break on complex stored procedures, but sufficient for this schema. + $queries = explode(';', $sql_content); + + foreach ($queries as $query) { + $query = trim($query); + if (!empty($query)) { + $pdo->exec($query); + } + } + echo "

Schema imported successfully.

"; + + echo "

2. Seeding Data...

"; + + // Seed Users (Admin & Customer) + // Check if admin exists to avoid duplicates if re-run + $stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE email = ?"); + $stmt->execute(['admin@afgcars.com']); + if ($stmt->fetchColumn() == 0) { + $password = password_hash('admin123', PASSWORD_DEFAULT); + $stmt = $pdo->prepare("INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)"); + $stmt->execute(['Administrator', 'admin@afgcars.com', $password, 'admin']); + echo "

Admin user created (admin@afgcars.com / admin123)

"; + } - // Create Branches table - $db->exec("CREATE TABLE branches ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(100) NOT NULL, - city VARCHAR(100) NOT NULL, - address VARCHAR(255), - phone VARCHAR(50), - hours VARCHAR(100) - )"); - - // Create Users table - $db->exec("CREATE TABLE users ( - id INT AUTO_INCREMENT PRIMARY KEY, - username VARCHAR(100) UNIQUE NOT NULL, - email VARCHAR(100) UNIQUE, - password VARCHAR(255) NOT NULL, - role ENUM('Guest', 'Customer', 'Dealer', 'Employee', 'Manager', 'Admin', 'Super Admin') DEFAULT 'Customer', - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP - )"); - - // Create Cars table - $db->exec("CREATE TABLE cars ( - id INT AUTO_INCREMENT PRIMARY KEY, - vin VARCHAR(50) UNIQUE NOT NULL, - brand VARCHAR(100) NOT NULL, - model VARCHAR(100) NOT NULL, - year INT NOT NULL, - price DECIMAL(15, 2) NOT NULL, - mileage INT NOT NULL, - transmission VARCHAR(50), - fuel_type VARCHAR(50), - status ENUM('Available', 'Reserved', 'Sold') DEFAULT 'Available', - branch_id INT, - dealer_id INT DEFAULT NULL, - installment_available BOOLEAN DEFAULT 0, - is_featured BOOLEAN DEFAULT 0, - image_url VARCHAR(255), - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (branch_id) REFERENCES branches(id), - FOREIGN KEY (dealer_id) REFERENCES users(id) - )"); - - // Create Car Images table - $db->exec("CREATE TABLE car_images ( - id INT AUTO_INCREMENT PRIMARY KEY, - car_id INT NOT NULL, - image_path VARCHAR(255) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE - )"); - - // Create Reviews table - $db->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), - comment TEXT, - 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 - )"); - - // Create Sales table - $db->exec("CREATE TABLE sales ( - id INT AUTO_INCREMENT PRIMARY KEY, - user_id INT NOT NULL, - car_id INT NOT NULL, - amount DECIMAL(15, 2) NOT NULL, - sale_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - status ENUM('Pending', 'Completed', 'Cancelled') DEFAULT 'Pending', - FOREIGN KEY (user_id) REFERENCES users(id), - FOREIGN KEY (car_id) REFERENCES cars(id) - )"); - - // Create Installments table - $db->exec("CREATE TABLE installments ( - id INT AUTO_INCREMENT PRIMARY KEY, - sale_id INT NOT NULL, - total_amount DECIMAL(15, 2) NOT NULL, - paid_amount DECIMAL(15, 2) DEFAULT 0, - monthly_payment DECIMAL(15, 2) NOT NULL, - status ENUM('Active', 'Completed', 'Overdue') DEFAULT 'Active', - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (sale_id) REFERENCES sales(id) ON DELETE CASCADE - )"); - - // Create Activity Logs table - $db->exec("CREATE TABLE activity_logs ( - id INT AUTO_INCREMENT PRIMARY KEY, - user_id INT, - action VARCHAR(255) NOT NULL, - ip_address VARCHAR(50), - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL - )"); - - // Create Notifications table - $db->exec("CREATE TABLE notifications ( - id INT AUTO_INCREMENT PRIMARY KEY, - user_id INT NOT NULL, - message TEXT NOT NULL, - is_read BOOLEAN DEFAULT 0, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE - )"); + $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', '08:00 AM - 06:00 PM'], - ['Herat Branch', 'Herat', 'Main Road, Herat', '+93 700 333 444', '08:30 AM - 05:30 PM'], - ['Mazar Center', 'Mazar-i-Sharif', 'Balkh Street, Mazar', '+93 700 555 666', '08:00 AM - 05:00 PM'], - ['Kandahar Hub', 'Kandahar', 'Airport Road, Kandahar', '+93 700 777 888', '09:00 AM - 04:00 PM'] + ['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 = $db->prepare("INSERT INTO branches (name, city, address, phone, hours) VALUES (?, ?, ?, ?, ?)"); + + $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"); - // Seed Cars (Exactly 20 Cars) $brands = ['Toyota', 'Lexus', 'Mercedes-Benz', 'BMW', 'Audi', 'Land Rover', 'Porsche', 'Tesla']; $models = [ 'Toyota' => ['Camry', 'Land Cruiser', 'Corolla', 'RAV4'], @@ -149,40 +77,30 @@ try { 'Tesla' => ['Model S', 'Model X'] ]; - $stmt = $db->prepare("INSERT INTO cars (vin, brand, model, year, price, mileage, transmission, fuel_type, branch_id, is_featured, image_url, installment_available) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $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(45000, 180000); - $mileage = rand(0, 15000); + $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 <= 8) ? 1 : 0; // 8 featured cars - $installment_available = rand(0, 1); - $image_url = "assets/images/cars/car{$i}.jpg"; - $vin = "VIN" . str_pad((string)$i, 10, "0", STR_PAD_LEFT); + $is_featured = ($i <= 6) ? 1 : 0; // First 6 are featured $stmt->execute([ - $vin, $brand, $model, $year, $price, $mileage, - 'Automatic', rand(0,1) ? 'Gasoline' : 'Hybrid', - $branch_id, $is_featured, $image_url, $installment_available + $brand, $model, $year, $price, $mileage, $fuel, 'Automatic', + $desc, $image, $branch_id, $is_featured, 'available' ]); } - - // Seed Admin - $stmt = $db->prepare("INSERT INTO users (username, password, role) VALUES (?, ?, ?)"); - $stmt->execute(['admin', password_hash('admin123', PASSWORD_DEFAULT), 'Super Admin']); - - // Create flag file for automated setup - file_put_contents(__DIR__ . '/db/setup_done.flag', date('Y-m-d H:i:s')); - - echo "

Setup Successful!

"; - echo "

Database recreated and exactly 20 premium cars seeded.

"; - echo "

Admin Credentials: admin / admin123

"; - echo "Go to Home Page"; + echo "

20 Demo cars seeded.

"; + + echo "

Setup Complete!

"; + echo "

Go to Homepage

"; } catch (Exception $e) { - echo "

Setup Failed

"; - echo "

" . $e->getMessage() . "

"; + die("

Setup Failed: " . $e->getMessage() . "

"); } diff --git a/work.php b/work.php index ffdcde7..3343e8e 100644 --- a/work.php +++ b/work.php @@ -1,71 +1,46 @@ -
-
-
-

How AFG_CARS Works

-

A transparent, step-by-step guide to luxury vehicle ownership.

-
+
+
+

How It Works

+

Your journey to owning a luxury car in 4 simple steps.

-
-
-

The Buying Process

-
-
-
1
-
-

Online Exploration

-

Browse our live inventory with detailed specifications, history reports, and high-resolution images.

-
-
-
-
2
-
-

Showroom Consultation

-

Visit our branch to experience the vehicle in person. Our specialists provide a full technical walk-through.

-
-
-
-
3
-
-

Ownership & Handover

-

Finalize payment or installment documents. We handle all registration and deliver your car in pristine condition.

-
-
-
+
+
+
1
+

Browse

+

Explore our extensive inventory of premium vehicles online or visit one of our branches.

- -
-

The Selling Process

-
-
-
A
-
-

Expert Evaluation

-

Submit your car details. Our team performs a comprehensive market and technical analysis to determine value.

-
-
-
-
B
-
-

Guaranteed Offer

-

Receive a competitive buy-back or trade-in offer within 24 hours of inspection. No hidden fees.

-
-
-
-
C
-
-

Secure Transfer

-

We handle all the legal paperwork and title transfers. Payment is released immediately upon agreement.

-
-
-
+ +
+
2
+

Select

+

Choose your dream car and customize your payment plan using our installment calculator.

+
+ +
+
3
+

Apply

+

Submit a request online or in-person. Our team will process your application quickly.

+
+ +
+
4
+

Drive

+

Once approved, sign the paperwork and drive away in your new vehicle.

-
+ +
+

Ready to get started?

+

Browse our marketplace to find your perfect car today.

+ View Inventory +
+
- +