35438-vm/admin_vehicles.php
2025-11-03 08:24:38 +00:00

72 lines
3.1 KiB
PHP

<?php
require_once 'includes/admin_header.php';
require_once 'db/config.php';
// Fetch vehicles from the database
try {
$pdo = db();
$stmt = $pdo->query('SELECT * FROM vehicles ORDER BY name ASC');
$vehicles = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$error_message = "Database error: " . $e->getMessage();
$vehicles = [];
}
require_once 'includes/admin_sidebar.php';
?>
<h1 class="h2">Manage Vehicles</h1>
<p>Add, edit, or remove vehicles from your fleet.</p>
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Vehicle List</h5>
<a href="admin_add_vehicle.php" class="btn btn-primary"><i class="bi bi-plus-circle me-2"></i>Add Vehicle</a>
</div>
<div class="card-body">
<?php if (isset($error_message)): ?>
<div class="alert alert-danger">
<?php echo htmlspecialchars($error_message); ?>
</div>
<?php elseif (empty($vehicles)): ?>
<div class="alert alert-info">
No vehicles found. <a href="admin_add_vehicle.php">Add one now</a>.
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Capacity</th>
<th>Price per Day</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($vehicles as $vehicle): ?>
<tr>
<td><?php echo htmlspecialchars($vehicle['name']); ?></td>
<td><?php echo htmlspecialchars(ucfirst($vehicle['type'])); ?></td>
<td><?php echo htmlspecialchars($vehicle['capacity']); ?></td>
<td>Rp <?php echo number_format($vehicle['price_per_day'], 0, ',', '.'); ?></td>
<td><span class="badge bg-<?php echo $vehicle['is_available'] ? 'success' : 'secondary'; ?>"><?php echo $vehicle['is_available'] ? 'Available' : 'Unavailable'; ?></span></td>
<td>
<a href="admin_edit_vehicle.php?id=<?php echo $vehicle['id']; ?>" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil-square"></i></a>
<a href="admin_delete_vehicle.php?id=<?php echo $vehicle['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this vehicle?');"><i class="bi bi-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
<?php
require_once 'includes/admin_footer.php';
?>