133 lines
5.8 KiB
PHP
133 lines
5.8 KiB
PHP
<?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'; ?>
|