95 lines
3.8 KiB
PHP
95 lines
3.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
$pdo = db();
|
|
$message = '';
|
|
|
|
// Handle form submission for adding a new bunk
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_bunk'])) {
|
|
$name = trim($_POST['name']);
|
|
$owner = trim($_POST['owner']);
|
|
$contact = trim($_POST['contact']);
|
|
$location = trim($_POST['location']);
|
|
|
|
if (!empty($name) && !empty($owner) && !empty($contact) && !empty($location)) {
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO bunks (name, owner, contact, location) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute([$name, $owner, $contact, $location]);
|
|
$message = '<div class="alert alert-success">Bunk 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 all bunks to display
|
|
$stmt = $pdo->query("SELECT * FROM bunks ORDER BY name");
|
|
$bunks = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
|
|
<div class="row">
|
|
<div class="col-md-8">
|
|
<h2>Manage Bunks</h2>
|
|
<p>List of all petrol bunks registered in the system.</p>
|
|
|
|
<table class="table table-striped table-hover">
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Owner</th>
|
|
<th>Contact</th>
|
|
<th>Location</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($bunks)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center">No bunks found. Add one to get started.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($bunks as $bunk): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($bunk['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($bunk['owner']); ?></td>
|
|
<td><?php echo htmlspecialchars($bunk['contact']); ?></td>
|
|
<td><?php echo htmlspecialchars($bunk['location']); ?></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 Bunk</h5>
|
|
<?php echo $message; ?>
|
|
<form action="bunks.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Bunk Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="owner" class="form-label">Owner Name</label>
|
|
<input type="text" class="form-control" id="owner" name="owner" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="contact" class="form-label">Contact Number</label>
|
|
<input type="text" class="form-control" id="contact" name="contact" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="location" class="form-label">Location / Address</label>
|
|
<textarea class="form-control" id="location" name="location" rows="3" required></textarea>
|
|
</div>
|
|
<button type="submit" name="add_bunk" class="btn btn-primary">Add Bunk</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|