207 lines
9.1 KiB
PHP
207 lines
9.1 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
$notification = null;
|
|
|
|
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)) {
|
|
try {
|
|
$db = db();
|
|
$stmt = $db->prepare("INSERT INTO bunks (name, owner, contact, location) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute([$name, $owner, $contact, $location]);
|
|
$_SESSION['notification'] = ['text' => 'Bunk added successfully!', 'type' => 'success'];
|
|
} catch (PDOException $e) {
|
|
$_SESSION['notification'] = ['text' => 'Error adding bunk: ' . $e->getMessage(), 'type' => 'danger'];
|
|
}
|
|
} else {
|
|
$_SESSION['notification'] = ['text' => 'Bunk name is required.', 'type' => 'warning'];
|
|
}
|
|
header("Location: bunks.php");
|
|
exit;
|
|
}
|
|
|
|
if (isset($_SESSION['notification'])) {
|
|
$notification = $_SESSION['notification'];
|
|
unset($_SESSION['notification']);
|
|
}
|
|
|
|
try {
|
|
$db = db();
|
|
$stmt = $db->query("SELECT id, name, owner, contact, location, created_at FROM bunks ORDER BY created_at DESC");
|
|
$bunks = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
$bunks = [];
|
|
$notification = ['text' => 'Error fetching bunks: ' . $e->getMessage(), 'type' => 'danger'];
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Bunk Management</title>
|
|
<meta name="description" content="Manage your fuel bunks efficiently. Built with Flatlogic Generator.">
|
|
<meta name="keywords" content="fuel bunk management, petrol pump software, inventory, sales tracking, flatlogic">
|
|
<meta property="og:title" content="Bunk Management">
|
|
<meta property="og:description" content="Manage your fuel bunks efficiently. Built with Flatlogic Generator.">
|
|
<meta property="og:image" content="">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<meta name="twitter:image" content="">
|
|
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
background-color: #f8f9fa;
|
|
}
|
|
.navbar {
|
|
background: linear-gradient(to right, #0d6efd, #0dcaf0);
|
|
}
|
|
.toast-container {
|
|
z-index: 1080;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark shadow-sm">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">Bunk Admin</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="index.php">Dashboard</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="bunks.php">Bunks</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<h1 class="h2">Bunk Management</h1>
|
|
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addBunkModal">
|
|
<i class="bi bi-plus-circle me-1"></i> Add New Bunk
|
|
</button>
|
|
</div>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Owner</th>
|
|
<th>Contact</th>
|
|
<th>Location</th>
|
|
<th>Created</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($bunks)): ?>
|
|
<tr>
|
|
<td colspan="6" class="text-center text-muted">No bunks found. Add one to get started!</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($bunks as $bunk): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($bunk['name']) ?></td>
|
|
<td><?= htmlspecialchars($bunk['owner']) ?></td>
|
|
<td><?= htmlspecialchars($bunk['contact']) ?></td>
|
|
<td><?= htmlspecialchars($bunk['location']) ?></td>
|
|
<td><?= date('d M, Y', strtotime($bunk['created_at'])) ?></td>
|
|
<td>
|
|
<button class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></button>
|
|
<button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Bunk Modal -->
|
|
<div class="modal fade" id="addBunkModal" tabindex="-1" aria-labelledby="addBunkModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<form action="bunks.php" method="POST">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addBunkModalLabel">Add New Bunk</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<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</label>
|
|
<input type="text" class="form-control" id="owner" name="owner">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="contact" class="form-label">Contact</label>
|
|
<input type="text" class="form-control" id="contact" name="contact">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="location" class="form-label">Location</label>
|
|
<textarea class="form-control" id="location" name="location" rows="3"></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
<button type="submit" name="add_bunk" class="btn btn-primary">Save Bunk</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Toast Notification -->
|
|
<div class="position-fixed bottom-0 end-0 p-3 toast-container">
|
|
<div id="notificationToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
|
<div class="toast-header">
|
|
<strong class="me-auto">Notification</strong>
|
|
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
|
</div>
|
|
<div class="toast-body">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
<?php if ($notification): ?>
|
|
const toastEl = document.getElementById('notificationToast');
|
|
const toastBody = toastEl.querySelector('.toast-body');
|
|
|
|
toastEl.classList.remove('bg-success', 'bg-danger', 'bg-warning');
|
|
toastEl.classList.add('bg-<?= $notification['type'] ?>', 'text-white');
|
|
toastBody.textContent = '<?= addslashes(htmlspecialchars($notification['text'])) ?>';
|
|
|
|
const toast = new bootstrap.Toast(toastEl);
|
|
toast.show();
|
|
<?php endif; ?>
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|