Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2948106bb3 |
69
assets/css/custom.css
Normal file
69
assets/css/custom.css
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
|
||||||
|
body {
|
||||||
|
font-family: 'Poppins', sans-serif;
|
||||||
|
background-color: #ecf0f1;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 250px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
padding: 20px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .logo {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link {
|
||||||
|
color: #2c3e50;
|
||||||
|
padding: 10px 15px;
|
||||||
|
margin: 5px 0;
|
||||||
|
border-radius: 8px;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar .nav-link:hover,
|
||||||
|
.sidebar .nav-link.active {
|
||||||
|
background-color: #3498db;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
margin-left: 250px;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
align-items: center;
|
||||||
|
background-color: #ffffff;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.header .user-profile {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header .user-profile img {
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
background-color: #ffffff;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
|
||||||
|
}
|
||||||
0
assets/js/main.js
Normal file
0
assets/js/main.js
Normal file
44
db/migrate.php
Normal file
44
db/migrate.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'config.php';
|
||||||
|
|
||||||
|
echo "Attempting to run migrations...\n";
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
// Set error mode to exception to catch potential issues
|
||||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
|
$migrationsDir = __DIR__ . '/migrations';
|
||||||
|
|
||||||
|
if (!is_dir($migrationsDir)) {
|
||||||
|
mkdir($migrationsDir, 0775, true);
|
||||||
|
echo "Created migrations directory.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = glob($migrationsDir . '/*.sql');
|
||||||
|
|
||||||
|
if (empty($files)) {
|
||||||
|
echo "No migration files found.\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
sort($files);
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$sql = file_get_contents($file);
|
||||||
|
if ($sql) {
|
||||||
|
$pdo->exec($sql);
|
||||||
|
echo "Executed migration: " . basename($file) . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "All migrations executed successfully.\n";
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// Use error_log for server-side logging instead of exposing details to the browser
|
||||||
|
error_log("Migration failed: " . $e->getMessage());
|
||||||
|
// Provide a generic error to the user
|
||||||
|
http_response_code(500);
|
||||||
|
die("Database migration failed. Check server logs for details.");
|
||||||
|
}
|
||||||
|
|
||||||
12
db/migrations/001_create_vehicles_table.sql
Normal file
12
db/migrations/001_create_vehicles_table.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `vehicles` (
|
||||||
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
`make` VARCHAR(255) NOT NULL,
|
||||||
|
`model` VARCHAR(255) NOT NULL,
|
||||||
|
`year` INT NOT NULL,
|
||||||
|
`license_plate` VARCHAR(50) NOT NULL UNIQUE,
|
||||||
|
`vin` VARCHAR(100) NOT NULL UNIQUE,
|
||||||
|
`status` VARCHAR(50) DEFAULT 'active',
|
||||||
|
`driver_id` INT NULL,
|
||||||
|
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
9
db/migrations/002_create_drivers_table.sql
Normal file
9
db/migrations/002_create_drivers_table.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS drivers (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
license_number VARCHAR(255) NOT NULL,
|
||||||
|
phone_number VARCHAR(50),
|
||||||
|
email VARCHAR(255),
|
||||||
|
status VARCHAR(50) DEFAULT 'active',
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
12
db/migrations/003_create_expenses_table.sql
Normal file
12
db/migrations/003_create_expenses_table.sql
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS expenses (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
driver_id INT,
|
||||||
|
vehicle_id INT,
|
||||||
|
expense_date DATE NOT NULL,
|
||||||
|
category VARCHAR(255) NOT NULL,
|
||||||
|
amount DECIMAL(10, 2) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE SET NULL,
|
||||||
|
FOREIGN KEY (vehicle_id) REFERENCES vehicles(id) ON DELETE SET NULL
|
||||||
|
);
|
||||||
14
db/migrations/004_create_routes_table.sql
Normal file
14
db/migrations/004_create_routes_table.sql
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS routes (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
origin VARCHAR(255) NOT NULL,
|
||||||
|
destination VARCHAR(255) NOT NULL,
|
||||||
|
distance DECIMAL(10, 2),
|
||||||
|
status VARCHAR(50) DEFAULT 'planned',
|
||||||
|
departure_time TIMESTAMP NULL,
|
||||||
|
arrival_time TIMESTAMP NULL,
|
||||||
|
driver_id INT,
|
||||||
|
vehicle_id INT,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE SET NULL,
|
||||||
|
FOREIGN KEY (vehicle_id) REFERENCES vehicles(id) ON DELETE SET NULL
|
||||||
|
);
|
||||||
21
db/setup.php
Normal file
21
db/setup.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
// Generated by setup_mariadb_project.sh — edit as needed.
|
||||||
|
define('DB_HOST', '127.0.0.1');
|
||||||
|
define('DB_NAME', 'app_30903');
|
||||||
|
define('DB_USER', 'app_30903');
|
||||||
|
define('DB_PASS', '7d2d5a2d-6e5e-4580-a9b7-3f8e7288a494');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Connect to MySQL without specifying a database
|
||||||
|
$pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Create the database if it doesn't exist
|
||||||
|
$pdo->exec("CREATE DATABASE IF NOT EXISTS `".DB_NAME."`");
|
||||||
|
echo "Database '".DB_NAME."' created or already exists.\n";
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Database setup failed: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
132
drivers.php
Normal file
132
drivers.php
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
include 'includes/header.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
|
||||||
|
// Handle form submission for adding a new driver
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_driver'])) {
|
||||||
|
$name = $_POST['name'] ?? '';
|
||||||
|
$license_number = $_POST['license_number'] ?? '';
|
||||||
|
$phone_number = $_POST['phone_number'] ?? '';
|
||||||
|
$email = $_POST['email'] ?? '';
|
||||||
|
$status = $_POST['status'] ?? 'active';
|
||||||
|
|
||||||
|
if ($name && $license_number) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare(
|
||||||
|
'INSERT INTO drivers (name, license_number, phone_number, email, status) VALUES (?, ?, ?, ?, ?)'
|
||||||
|
);
|
||||||
|
$stmt->execute([$name, $license_number, $phone_number, $email, $status]);
|
||||||
|
$message = '<div class="alert alert-success">Driver added successfully!</div>';
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = '<div class="alert alert-warning">Please fill in all required fields.</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all drivers from the database
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT * FROM drivers ORDER BY created_at DESC');
|
||||||
|
$drivers = $stmt->fetchAll();
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$drivers = [];
|
||||||
|
$message .= '<div class="alert alert-danger">Error fetching drivers: ' . $e->getMessage() . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
include 'includes/sidebar.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<h2 class="mb-4">Driver Management</h2>
|
||||||
|
|
||||||
|
<?php echo $message; ?>
|
||||||
|
|
||||||
|
<div class="card p-3 mb-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<h5 class="mb-0">All Drivers</h5>
|
||||||
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addDriverModal">+ Add New Driver</button>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>License Number</th>
|
||||||
|
<th>Phone Number</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($drivers)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="6" class="text-center">No drivers found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($drivers as $driver): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($driver['name']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($driver['license_number']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($driver['phone_number']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($driver['email']); ?></td>
|
||||||
|
<td><span class="badge bg-success"><?php echo htmlspecialchars(ucfirst($driver['status'])); ?></span></td>
|
||||||
|
<td>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-primary"><i data-feather="edit-2"></i></a>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-danger"><i data-feather="trash-2"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Driver Modal -->
|
||||||
|
<div class="modal fade" id="addDriverModal" tabindex="-1" aria-labelledby="addDriverModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="addDriverModalLabel">Add New Driver</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form action="drivers.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Name</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="license_number" class="form-label">License Number</label>
|
||||||
|
<input type="text" class="form-control" id="license_number" name="license_number" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="phone_number" class="form-label">Phone Number</label>
|
||||||
|
<input type="text" class="form-control" id="phone_number" name="phone_number">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="status" name="status">
|
||||||
|
<option value="active">Active</option>
|
||||||
|
<option value="on_leave">On Leave</option>
|
||||||
|
<option value="inactive">Inactive</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" name="add_driver" class="btn btn-primary">Add Driver</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
161
expenses.php
Normal file
161
expenses.php
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<?php
|
||||||
|
include 'includes/header.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
|
||||||
|
// Handle form submission for adding a new expense
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_expense'])) {
|
||||||
|
$driver_id = $_POST['driver_id'] ?? null;
|
||||||
|
$vehicle_id = $_POST['vehicle_id'] ?? null;
|
||||||
|
$expense_date = $_POST['expense_date'] ?? '';
|
||||||
|
$category = $_POST['category'] ?? '';
|
||||||
|
$amount = $_POST['amount'] ?? '';
|
||||||
|
$description = $_POST['description'] ?? '';
|
||||||
|
|
||||||
|
if ($driver_id && $expense_date && $category && $amount) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare(
|
||||||
|
'INSERT INTO expenses (driver_id, vehicle_id, expense_date, category, amount, description) VALUES (?, ?, ?, ?, ?, ?)'
|
||||||
|
);
|
||||||
|
$stmt->execute([$driver_id, $vehicle_id, $expense_date, $category, $amount, $description]);
|
||||||
|
$message = '<div class="alert alert-success">Expense added successfully!</div>';
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = '<div class="alert alert-warning">Please fill in all required fields.</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all expenses from the database
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT e.*, d.name as driver_name, v.make, v.model, v.license_plate FROM expenses e LEFT JOIN drivers d ON e.driver_id = d.id LEFT JOIN vehicles v ON e.vehicle_id = v.id ORDER BY e.expense_date DESC');
|
||||||
|
$expenses = $stmt->fetchAll();
|
||||||
|
|
||||||
|
// Fetch drivers and vehicles for the form
|
||||||
|
$drivers_stmt = $pdo->query('SELECT id, name FROM drivers ORDER BY name');
|
||||||
|
$drivers = $drivers_stmt->fetchAll();
|
||||||
|
$vehicles_stmt = $pdo->query('SELECT id, make, model, license_plate FROM vehicles ORDER BY make, model');
|
||||||
|
$vehicles = $vehicles_stmt->fetchAll();
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$expenses = [];
|
||||||
|
$drivers = [];
|
||||||
|
$vehicles = [];
|
||||||
|
$message .= '<div class="alert alert-danger">Error fetching data: ' . $e->getMessage() . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
include 'includes/sidebar.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<h2 class="mb-4">Expense Management</h2>
|
||||||
|
|
||||||
|
<?php echo $message; ?>
|
||||||
|
|
||||||
|
<div class="card p-3 mb-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<h5 class="mb-0">All Expenses</h5>
|
||||||
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addExpenseModal">+ Add New Expense</button>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Driver</th>
|
||||||
|
<th>Vehicle</th>
|
||||||
|
<th>Category</th>
|
||||||
|
<th>Amount</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($expenses)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center">No expenses found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($expenses as $expense): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($expense['expense_date']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($expense['driver_name'] ?? 'N/A'); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars(($expense['make'] ?? 'N/A') . ' ' . ($expense['model'] ?? '') . ' (' . ($expense['license_plate'] ?? '') . ')'); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($expense['category']); ?></td>
|
||||||
|
<td>$<?php echo htmlspecialchars(number_format($expense['amount'], 2)); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($expense['description']); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-primary"><i data-feather="edit-2"></i></a>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-danger"><i data-feather="trash-2"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Expense Modal -->
|
||||||
|
<div class="modal fade" id="addExpenseModal" tabindex="-1" aria-labelledby="addExpenseModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="addExpenseModalLabel">Add New Expense</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form action="expenses.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="expense_date" class="form-label">Date</label>
|
||||||
|
<input type="date" class="form-control" id="expense_date" name="expense_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="driver_id" class="form-label">Driver</label>
|
||||||
|
<select class="form-select" id="driver_id" name="driver_id" required>
|
||||||
|
<option value="">Select Driver</option>
|
||||||
|
<?php foreach ($drivers as $driver): ?>
|
||||||
|
<option value="<?php echo $driver['id']; ?>"><?php echo htmlspecialchars($driver['name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="vehicle_id" class="form-label">Vehicle (Optional)</label>
|
||||||
|
<select class="form-select" id="vehicle_id" name="vehicle_id">
|
||||||
|
<option value="">Select Vehicle</option>
|
||||||
|
<?php foreach ($vehicles as $vehicle): ?>
|
||||||
|
<option value="<?php echo $vehicle['id']; ?>"><?php echo htmlspecialchars($vehicle['make'] . ' ' . $vehicle['model'] . ' (' . $vehicle['license_plate'] . ')'); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="category" class="form-label">Category</label>
|
||||||
|
<select class="form-select" id="category" name="category" required>
|
||||||
|
<option value="">Select Category</option>
|
||||||
|
<option value="Fuel">Fuel</option>
|
||||||
|
<option value="Maintenance">Maintenance</option>
|
||||||
|
<option value="Tolls">Tolls</option>
|
||||||
|
<option value="Food">Food</option>
|
||||||
|
<option value="Other">Other</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="amount" class="form-label">Amount</label>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="amount" name="amount" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="description" class="form-label">Description (Optional)</label>
|
||||||
|
<textarea class="form-control" id="description" name="description" rows="3"></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" name="add_expense" class="btn btn-primary">Add Expense</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
9
includes/footer.php
Normal file
9
includes/footer.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||||
|
<script>
|
||||||
|
feather.replace()
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
includes/header.php
Normal file
13
includes/header.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php require_once 'db/config.php'; ?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Fleet Management Dashboard</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||||
|
<script src="https://unpkg.com/feather-icons"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
33
includes/sidebar.php
Normal file
33
includes/sidebar.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<div class="sidebar">
|
||||||
|
<div class="logo">
|
||||||
|
<img src="https://picsum.photos/seed/logo/150/40" alt="Company Logo">
|
||||||
|
</div>
|
||||||
|
<ul class="nav flex-column">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" href="index.php"><i data-feather="home"></i> Dashboard</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="vehicles.php"><i data-feather="truck"></i> Vehicles</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="drivers.php"><i data-feather="users"></i> Drivers</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="routes.php"><i data-feather="map"></i> Routes</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="expenses.php"><i data-feather="dollar-sign"></i> Expenses</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#"><i data-feather="settings"></i> Settings</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<div class="header">
|
||||||
|
<div class="user-profile">
|
||||||
|
<img src="https://picsum.photos/seed/avatar/40/40" alt="User Avatar">
|
||||||
|
<span>John Doe</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
162
index.php
162
index.php
@ -1,131 +1,37 @@
|
|||||||
<?php
|
<?php include 'includes/header.php'; ?>
|
||||||
declare(strict_types=1);
|
<?php include 'includes/sidebar.php'; ?>
|
||||||
@ini_set('display_errors', '1');
|
|
||||||
@error_reporting(E_ALL);
|
|
||||||
@date_default_timezone_set('UTC');
|
|
||||||
|
|
||||||
$phpVersion = PHP_VERSION;
|
<div class="container-fluid">
|
||||||
$now = date('Y-m-d H:i:s');
|
<h2 class="mb-4">Dashboard</h2>
|
||||||
?>
|
<div class="row">
|
||||||
<!doctype html>
|
<div class="col-md-4">
|
||||||
<html lang="en">
|
<div class="card p-3 mb-4">
|
||||||
<head>
|
<h5>Total Vehicles</h5>
|
||||||
<meta charset="utf-8" />
|
<p class="fs-3">150</p>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>New Style</title>
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--bg-color-start: #6a11cb;
|
|
||||||
--bg-color-end: #2575fc;
|
|
||||||
--text-color: #ffffff;
|
|
||||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
|
||||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: 'Inter', sans-serif;
|
|
||||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
|
||||||
color: var(--text-color);
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 100vh;
|
|
||||||
text-align: center;
|
|
||||||
overflow: hidden;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
body::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
|
||||||
animation: bg-pan 20s linear infinite;
|
|
||||||
z-index: -1;
|
|
||||||
}
|
|
||||||
@keyframes bg-pan {
|
|
||||||
0% { background-position: 0% 0%; }
|
|
||||||
100% { background-position: 100% 100%; }
|
|
||||||
}
|
|
||||||
main {
|
|
||||||
padding: 2rem;
|
|
||||||
}
|
|
||||||
.card {
|
|
||||||
background: var(--card-bg-color);
|
|
||||||
border: 1px solid var(--card-border-color);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 2rem;
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
-webkit-backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
.loader {
|
|
||||||
margin: 1.25rem auto 1.25rem;
|
|
||||||
width: 48px;
|
|
||||||
height: 48px;
|
|
||||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
|
||||||
border-top-color: #fff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: spin 1s linear infinite;
|
|
||||||
}
|
|
||||||
@keyframes spin {
|
|
||||||
from { transform: rotate(0deg); }
|
|
||||||
to { transform: rotate(360deg); }
|
|
||||||
}
|
|
||||||
.hint {
|
|
||||||
opacity: 0.9;
|
|
||||||
}
|
|
||||||
.sr-only {
|
|
||||||
position: absolute;
|
|
||||||
width: 1px; height: 1px;
|
|
||||||
padding: 0; margin: -1px;
|
|
||||||
overflow: hidden;
|
|
||||||
clip: rect(0, 0, 0, 0);
|
|
||||||
white-space: nowrap; border: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 3rem;
|
|
||||||
font-weight: 700;
|
|
||||||
margin: 0 0 1rem;
|
|
||||||
letter-spacing: -1px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin: 0.5rem 0;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
background: rgba(0,0,0,0.2);
|
|
||||||
padding: 2px 6px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 1rem;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<main>
|
|
||||||
<div class="card">
|
|
||||||
<h1>Analyzing your requirements and generating your website…</h1>
|
|
||||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
|
||||||
<span class="sr-only">Loading…</span>
|
|
||||||
</div>
|
</div>
|
||||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWiZZy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
|
||||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
|
||||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
|
||||||
</div>
|
</div>
|
||||||
</main>
|
<div class="col-md-4">
|
||||||
<footer>
|
<div class="card p-3 mb-4">
|
||||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
<h5>Active Drivers</h5>
|
||||||
</footer>
|
<p class="fs-3">125</p>
|
||||||
</body>
|
</div>
|
||||||
</html>
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card p-3 mb-4">
|
||||||
|
<h5>Ongoing Routes</h5>
|
||||||
|
<p class="fs-3">42</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div class="card p-3">
|
||||||
|
<h5>Fleet Activity</h5>
|
||||||
|
<img src="https://picsum.photos/seed/chart/1000/400" class="img-fluid" alt="Placeholder chart showing fleet activity">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
177
routes.php
Normal file
177
routes.php
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
<?php
|
||||||
|
include 'includes/header.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
|
||||||
|
// Handle form submission for adding a new route
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_route'])) {
|
||||||
|
$origin = $_POST['origin'] ?? '';
|
||||||
|
$destination = $_POST['destination'] ?? '';
|
||||||
|
$distance = $_POST['distance'] ?? null;
|
||||||
|
$status = $_POST['status'] ?? 'planned';
|
||||||
|
$departure_time = $_POST['departure_time'] ?? null;
|
||||||
|
$arrival_time = $_POST['arrival_time'] ?? null;
|
||||||
|
$driver_id = $_POST['driver_id'] ?? null;
|
||||||
|
$vehicle_id = $_POST['vehicle_id'] ?? null;
|
||||||
|
|
||||||
|
if ($origin && $destination) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare(
|
||||||
|
'INSERT INTO routes (origin, destination, distance, status, departure_time, arrival_time, driver_id, vehicle_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'
|
||||||
|
);
|
||||||
|
$stmt->execute([$origin, $destination, $distance, $status, $departure_time, $arrival_time, $driver_id, $vehicle_id]);
|
||||||
|
$message = '<div class="alert alert-success">Route added successfully!</div>';
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = '<div class="alert alert-warning">Please fill in all required fields.</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all routes from the database
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT r.*, d.name as driver_name, v.make, v.model, v.license_plate FROM routes r LEFT JOIN drivers d ON r.driver_id = d.id LEFT JOIN vehicles v ON r.vehicle_id = v.id ORDER BY r.created_at DESC');
|
||||||
|
$routes = $stmt->fetchAll();
|
||||||
|
|
||||||
|
// Fetch drivers and vehicles for the form
|
||||||
|
$drivers_stmt = $pdo->query('SELECT id, name FROM drivers ORDER BY name');
|
||||||
|
$drivers = $drivers_stmt->fetchAll();
|
||||||
|
$vehicles_stmt = $pdo->query('SELECT id, make, model, license_plate FROM vehicles ORDER BY make, model');
|
||||||
|
$vehicles = $vehicles_stmt->fetchAll();
|
||||||
|
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$routes = [];
|
||||||
|
$drivers = [];
|
||||||
|
$vehicles = [];
|
||||||
|
$message .= '<div class="alert alert-danger">Error fetching data: ' . $e->getMessage() . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
include 'includes/sidebar.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<h2 class="mb-4">Route Management</h2>
|
||||||
|
|
||||||
|
<?php echo $message; ?>
|
||||||
|
|
||||||
|
<div class="card p-3 mb-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<h5 class="mb-0">All Routes</h5>
|
||||||
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addRouteModal">+ Add New Route</button>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Origin</th>
|
||||||
|
<th>Destination</th>
|
||||||
|
<th>Distance</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Driver</th>
|
||||||
|
<th>Vehicle</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($routes)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center">No routes found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($routes as $route): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($route['origin']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($route['destination']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($route['distance']); ?> km</td>
|
||||||
|
<td><span class="badge bg-info"><?php echo htmlspecialchars(ucfirst($route['status'])); ?></span></td>
|
||||||
|
<td><?php echo htmlspecialchars($route['driver_name'] ?? 'N/A'); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars(($route['make'] ?? 'N/A') . ' ' . ($route['model'] ?? '') . ' (' . ($route['license_plate'] ?? '') . ')'); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-primary"><i data-feather="edit-2"></i></a>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-danger"><i data-feather="trash-2"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Route Modal -->
|
||||||
|
<div class="modal fade" id="addRouteModal" tabindex="-1" aria-labelledby="addRouteModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-lg">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="addRouteModalLabel">Add New Route</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form action="routes.php" method="POST">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="origin" class="form-label">Origin</label>
|
||||||
|
<input type="text" class="form-control" id="origin" name="origin" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="destination" class="form-label">Destination</label>
|
||||||
|
<input type="text" class="form-control" id="destination" name="destination" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="distance" class="form-label">Distance (km)</label>
|
||||||
|
<input type="number" step="0.01" class="form-control" id="distance" name="distance">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="status" name="status">
|
||||||
|
<option value="planned">Planned</option>
|
||||||
|
<option value="in_progress">In Progress</option>
|
||||||
|
<option value="completed">Completed</option>
|
||||||
|
<option value="cancelled">Cancelled</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="departure_time" class="form-label">Departure Time</label>
|
||||||
|
<input type="datetime-local" class="form-control" id="departure_time" name="departure_time">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="arrival_time" class="form-label">Arrival Time</label>
|
||||||
|
<input type="datetime-local" class="form-control" id="arrival_time" name="arrival_time">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="driver_id" class="form-label">Driver</label>
|
||||||
|
<select class="form-select" id="driver_id" name="driver_id">
|
||||||
|
<option value="">Select Driver</option>
|
||||||
|
<?php foreach ($drivers as $driver): ?>
|
||||||
|
<option value="<?php echo $driver['id']; ?>"><?php echo htmlspecialchars($driver['name']); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label for="vehicle_id" class="form-label">Vehicle</label>
|
||||||
|
<select class="form-select" id="vehicle_id" name="vehicle_id">
|
||||||
|
<option value="">Select Vehicle</option>
|
||||||
|
<?php foreach ($vehicles as $vehicle): ?>
|
||||||
|
<option value="<?php echo $vehicle['id']; ?>"><?php echo htmlspecialchars($vehicle['make'] . ' ' . $vehicle['model'] . ' (' . $vehicle['license_plate'] . ')'); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit" name="add_route" class="btn btn-primary">Add Route</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
139
vehicles.php
Normal file
139
vehicles.php
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
include 'includes/header.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
|
||||||
|
// Handle form submission for adding a new vehicle
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_vehicle'])) {
|
||||||
|
$make = $_POST['make'] ?? '';
|
||||||
|
$model = $_POST['model'] ?? '';
|
||||||
|
$year = $_POST['year'] ?? '';
|
||||||
|
$license_plate = $_POST['license_plate'] ?? '';
|
||||||
|
$vin = $_POST['vin'] ?? '';
|
||||||
|
$status = $_POST['status'] ?? 'active';
|
||||||
|
|
||||||
|
if ($make && $model && $year && $license_plate && $vin) {
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare(
|
||||||
|
'INSERT INTO vehicles (make, model, year, license_plate, vin, status) VALUES (?, ?, ?, ?, ?, ?)'
|
||||||
|
);
|
||||||
|
$stmt->execute([$make, $model, $year, $license_plate, $vin, $status]);
|
||||||
|
$message = '<div class="alert alert-success">Vehicle added successfully!</div>';
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$message = '<div class="alert alert-warning">Please fill in all required fields.</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch all vehicles from the database
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT * FROM vehicles ORDER BY created_at DESC');
|
||||||
|
$vehicles = $stmt->fetchAll();
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
$vehicles = [];
|
||||||
|
$message .= '<div class="alert alert-danger">Error fetching vehicles: ' . $e->getMessage() . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
include 'includes/sidebar.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container-fluid">
|
||||||
|
<h2 class="mb-4">Vehicle Management</h2>
|
||||||
|
|
||||||
|
<?php echo $message; ?>
|
||||||
|
|
||||||
|
<div class="card p-3 mb-4">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
|
<h5 class="mb-0">All Vehicles</h5>
|
||||||
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addVehicleModal">+ Add New Vehicle</button>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Make</th>
|
||||||
|
<th>Model</th>
|
||||||
|
<th>Year</th>
|
||||||
|
<th>License Plate</th>
|
||||||
|
<th>VIN</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php if (empty($vehicles)): ?>
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="text-center">No vehicles found.</td>
|
||||||
|
</tr>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php foreach ($vehicles as $vehicle): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo htmlspecialchars($vehicle['make']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($vehicle['model']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($vehicle['year']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($vehicle['license_plate']); ?></td>
|
||||||
|
<td><?php echo htmlspecialchars($vehicle['vin']); ?></td>
|
||||||
|
<td><span class="badge bg-success"><?php echo htmlspecialchars(ucfirst($vehicle['status'])); ?></span></td>
|
||||||
|
<td>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-primary"><i data-feather="edit-2"></i></a>
|
||||||
|
<a href="#" class="btn btn-sm btn-outline-danger"><i data-feather="trash-2"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Add Vehicle Modal -->
|
||||||
|
<div class="modal fade" id="addVehicleModal" tabindex="-1" aria-labelledby="addVehicleModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="addVehicleModalLabel">Add New Vehicle</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form action="vehicles.php" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="make" class="form-label">Make</label>
|
||||||
|
<input type="text" class="form-control" id="make" name="make" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="model" class="form-label">Model</label>
|
||||||
|
<input type="text" class="form-control" id="model" name="model" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="year" class="form-label">Year</label>
|
||||||
|
<input type="number" class="form-control" id="year" name="year" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="license_plate" class="form-label">License Plate</label>
|
||||||
|
<input type="text" class="form-control" id="license_plate" name="license_plate" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="vin" class="form-label">VIN</label>
|
||||||
|
<input type="text" class="form-control" id="vin" name="vin" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="status" class="form-label">Status</label>
|
||||||
|
<select class="form-select" id="status" name="status">
|
||||||
|
<option value="active">Active</option>
|
||||||
|
<option value="in_maintenance">In Maintenance</option>
|
||||||
|
<option value="decommissioned">Decommissioned</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<button type="submit" name="add_vehicle" class="btn btn-primary">Add Vehicle</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include 'includes/footer.php'; ?>
|
||||||
Loading…
x
Reference in New Issue
Block a user