83 lines
3.1 KiB
PHP
83 lines
3.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
$pdo = db();
|
|
$message = '';
|
|
|
|
// Handle form submission for adding a new fuel type
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_fuel_type'])) {
|
|
$name = trim($_POST['name']);
|
|
|
|
if (!empty($name)) {
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO fuel_types (name) VALUES (?)");
|
|
$stmt->execute([$name]);
|
|
$message = '<div class="alert alert-success">Fuel type added successfully!</div>';
|
|
} catch (PDOException $e) {
|
|
if ($e->errorInfo[1] == 1062) { // Duplicate entry
|
|
$message = '<div class="alert alert-danger">Error: A fuel type with this name already exists.</div>';
|
|
} else {
|
|
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
|
}
|
|
}
|
|
} else {
|
|
$message = '<div class="alert alert-warning">Please enter a fuel type name.</div>';
|
|
}
|
|
}
|
|
|
|
// Fetch all fuel types to display
|
|
$stmt = $pdo->query("SELECT * FROM fuel_types ORDER BY name");
|
|
$fuel_types = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<h2>Manage Fuel Types</h2>
|
|
<p>List of all fuel types available in the system (e.g., MS, HSD, Power).</p>
|
|
|
|
<table class="table table-striped table-hover">
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th>Fuel Type Name</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($fuel_types)): ?>
|
|
<tr>
|
|
<td colspan="2" class="text-center">No fuel types found. Add one to get started.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($fuel_types as $fuel_type): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($fuel_type['name']); ?></td>
|
|
<td>
|
|
<a href="#" class="btn btn-sm btn-outline-primary disabled">Edit</a>
|
|
<a href="#" class="btn btn-sm btn-outline-danger disabled">Delete</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Add New Fuel Type</h5>
|
|
<?php echo $message; ?>
|
|
<form action="fuel_types.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Fuel Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" required placeholder="e.g., MS (Petrol)">
|
|
</div>
|
|
<button type="submit" name="add_fuel_type" class="btn btn-primary">Add Fuel Type</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|