From fac3d8cd1c3b46d92da43340c2c96439df52692b Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 22 Oct 2025 13:28:04 +0000 Subject: [PATCH] Auto commit: 2025-10-22T13:28:04.969Z --- assets/css/custom.css | 38 +++++ assets/js/main.js | 9 ++ db/config.php | 74 +++++++-- db/migrations/001_create_vehicles_table.sql | 11 ++ includes/footer.php | 10 ++ includes/header.php | 38 +++++ index.php | 152 +----------------- vehicles.php | 169 ++++++++++++++++++++ 8 files changed, 338 insertions(+), 163 deletions(-) create mode 100644 assets/css/custom.css create mode 100644 assets/js/main.js create mode 100644 db/migrations/001_create_vehicles_table.sql create mode 100644 includes/footer.php create mode 100644 includes/header.php create mode 100644 vehicles.php diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..dd525d6 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,38 @@ +/* assets/css/custom.css */ +body { + background-color: #f8f9fa; +} + +.navbar-brand { + font-weight: bold; +} + +.card-header { + font-weight: 500; +} + +.empty-state { + text-align: center; + padding: 4rem 2rem; + background-color: #fff; + border-radius: 0.5rem; + border: 1px dashed #ced4da; +} + +.empty-state i { + font-size: 3rem; + color: #adb5bd; +} + +.empty-state h5 { + margin-top: 1.5rem; + font-weight: 500; +} + +.empty-state p { + color: #6c757d; +} + +.toast-container { + z-index: 1090; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..683d225 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,9 @@ +// assets/js/main.js +document.addEventListener('DOMContentLoaded', function () { + // Activate toasts + var toastElList = [].slice.call(document.querySelectorAll('.toast')); + var toastList = toastElList.map(function (toastEl) { + return new bootstrap.Toast(toastEl); + }); + toastList.forEach(toast => toast.show()); +}); diff --git a/db/config.php b/db/config.php index cc9229f..aabffc1 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,63 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; +function db_connect() { + static $pdo; + if ($pdo) { + return $pdo; + } + + // Database credentials - DO NOT MODIFY + $host = '127.0.0.1'; + $dbname = 'app'; + $user = 'app'; + $pass = 'app'; + $port = 3306; + $charset = 'utf8mb4'; + + $dsn = "mysql:host=$host;port=$port;dbname=$dbname;charset=$charset"; + $options = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + + try { + $pdo = new PDO($dsn, $user, $pass, $options); + return $pdo; + } catch (PDOException $e) { + // In a real app, log this error and show a generic message + throw new PDOException($e->getMessage(), (int)$e->getCode()); + } } + +function run_migrations() { + $pdo = db_connect(); + $migrationsDir = __DIR__ . '/migrations'; + if (!is_dir($migrationsDir)) { + mkdir($migrationsDir, 0775, true); + } + + $migrationFiles = glob($migrationsDir . '/*.sql'); + sort($migrationFiles); + + foreach ($migrationFiles as $file) { + try { + $sql = file_get_contents($file); + if (!empty(trim($sql))) { + $pdo->exec($sql); + } + } catch (PDOException $e) { + // Log error, handle failure + error_log("Migration failed for file $file: " . $e->getMessage()); + } + } +} + +// Run migrations automatically on include +run_migrations(); + +// Helper function for easy access +function db() { + return db_connect(); +} \ No newline at end of file diff --git a/db/migrations/001_create_vehicles_table.sql b/db/migrations/001_create_vehicles_table.sql new file mode 100644 index 0000000..6373b18 --- /dev/null +++ b/db/migrations/001_create_vehicles_table.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS `vehicles` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `license_plate` VARCHAR(255) NOT NULL, + `model` VARCHAR(255) NOT NULL, + `current_mileage` INT, + `assigned_driver` VARCHAR(255), + `next_service_due` DATE, + `photo` VARCHAR(255) NULL, + `last_maintenance_date` DATE NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..847b87f --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..e2b6bdf --- /dev/null +++ b/includes/header.php @@ -0,0 +1,38 @@ + + + + + + flkeet - Fleet Management + + + + + + + + + + + + + + + + +
diff --git a/index.php b/index.php index 7205f3d..b852a6d 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,4 @@ - - - - - - New Style - - - - - - - - - - - - - - - - - - - - - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
-
- Page updated: (UTC) -
- - +// Redirect to the main application page +header('Location: vehicles.php'); +exit(); \ No newline at end of file diff --git a/vehicles.php b/vehicles.php new file mode 100644 index 0000000..284bd7b --- /dev/null +++ b/vehicles.php @@ -0,0 +1,169 @@ + ["min_range"=>0]]); + $assigned_driver = trim($_POST['assigned_driver'] ?? ''); + $next_service_due = trim($_POST['next_service_due'] ?? ''); + + if (empty($license_plate) || empty($model)) { + $error = "License plate and model are required."; + } else { + try { + $stmt = $pdo->prepare( + "INSERT INTO vehicles (license_plate, model, current_mileage, assigned_driver, next_service_due) VALUES (?, ?, ?, ?, ?)" + ); + $stmt->execute([ + $license_plate, + $model, + $current_mileage ?: null, + $assigned_driver ?: null, + empty($next_service_due) ? null : $next_service_due + ]); + $message = "Vehicle '{$license_plate}' added successfully!"; + } catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); + } + } +} + +// Fetch all vehicles to display +$vehicles = []; +try { + $stmt = $pdo->query("SELECT id, license_plate, model, current_mileage, assigned_driver, next_service_due FROM vehicles ORDER BY created_at DESC"); + $vehicles = $stmt->fetchAll(); +} catch (PDOException $e) { + $error = "Could not fetch vehicles: " . $e->getMessage(); +} + +include 'includes/header.php'; +?> + + +
+ + + + + + +
+ + +
+

Fleet Overview

+ +
+ +
+
+ All Vehicles +
+
+ +
+ +
No vehicles yet
+

Get started by adding your first vehicle to the fleet.

+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
License PlateModelMileageAssigned DriverNext Service DueActions
+ + +
+
+ +
+
+ + + + +