117 lines
5.0 KiB
PHP
117 lines
5.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
$pdo = db();
|
|
$message = '';
|
|
|
|
// Handle form submission for adding a new pump
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_pump'])) {
|
|
$bunk_id = $_POST['bunk_id'];
|
|
$tank_id = $_POST['tank_id'];
|
|
$pump_number = trim($_POST['pump_number']);
|
|
|
|
if (!empty($bunk_id) && !empty($tank_id) && !empty($pump_number)) {
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO pumps (bunk_id, tank_id, pump_number) VALUES (?, ?, ?)");
|
|
$stmt->execute([$bunk_id, $tank_id, $pump_number]);
|
|
$message = '<div class="alert alert-success">Pump 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 fields.</div>';
|
|
}
|
|
}
|
|
|
|
// Fetch related data for forms
|
|
$bunks = $pdo->query("SELECT id, name FROM bunks ORDER BY name")->fetchAll(PDO::FETCH_ASSOC);
|
|
$tanks = $pdo->query("
|
|
SELECT t.id, t.name as tank_name, b.name as bunk_name, ft.name as fuel_type_name
|
|
FROM tanks t
|
|
JOIN bunks b ON t.bunk_id = b.id
|
|
JOIN fuel_types ft ON t.fuel_type_id = ft.id
|
|
ORDER BY b.name, t.name
|
|
")->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
|
|
// Fetch all pumps with their bunk and tank name
|
|
$stmt = $pdo->query("
|
|
SELECT p.id, p.pump_number, b.name AS bunk_name, t.name as tank_name, ft.name as fuel_type_name
|
|
FROM pumps p
|
|
JOIN bunks b ON p.bunk_id = b.id
|
|
LEFT JOIN tanks t ON p.tank_id = t.id
|
|
LEFT JOIN fuel_types ft ON t.fuel_type_id = ft.id
|
|
ORDER BY b.name, p.pump_number
|
|
");
|
|
$pumps = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<h2>Manage Pumps</h2>
|
|
<p>List of all fuel pumps and their assigned tanks.</p>
|
|
|
|
<table class="table table-striped table-hover">
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th>Pump Number</th>
|
|
<th>Bunk</th>
|
|
<th>Tank</th>
|
|
<th>Fuel Type</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($pumps)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center">No pumps found. Add one to get started.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($pumps as $pump): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($pump['pump_number']); ?></td>
|
|
<td><?php echo htmlspecialchars($pump['bunk_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($pump['tank_name'] ?? 'N/A'); ?></td>
|
|
<td><?php echo htmlspecialchars($pump['fuel_type_name'] ?? 'N/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 Pump</h5>
|
|
<?php echo $message; ?>
|
|
<form action="pumps.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="bunk_id" class="form-label">Bunk</label>
|
|
<select class="form-select" id="bunk_id" name="bunk_id" required>
|
|
<option value="">Select a Bunk</option>
|
|
<?php foreach ($bunks as $bunk): ?>
|
|
<option value="<?php echo $bunk['id']; ?>"><?php echo htmlspecialchars($bunk['name']); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="tank_id" class="form-label">Tank</label>
|
|
<select class="form-select" id="tank_id" name="tank_id" required>
|
|
<option value="">Select a Tank</option>
|
|
<?php foreach ($tanks as $tank): ?>
|
|
<option value="<?php echo $tank['id']; ?>">(<?php echo htmlspecialchars($tank['bunk_name']); ?>) <?php echo htmlspecialchars($tank['tank_name']); ?> - <?php echo htmlspecialchars($tank['fuel_type_name']); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="pump_number" class="form-label">Pump Number</label>
|
|
<input type="text" class="form-control" id="pump_number" name="pump_number" required placeholder="e.g., P-01">
|
|
</div>
|
|
<button type="submit" name="add_pump" class="btn btn-primary">Add Pump</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|