101 lines
4.0 KiB
PHP
101 lines
4.0 KiB
PHP
<?php
|
|
require_once __DIR__ . "/../includes/functions.php";
|
|
require_permission("outlets_view");
|
|
require_once __DIR__ . '/../db/config.php';
|
|
$pdo = db();
|
|
|
|
if (isset($_POST['action']) && $_POST['action'] === 'add_outlet') {
|
|
$stmt = $pdo->prepare("INSERT INTO outlets (name, address) VALUES (?, ?)");
|
|
$stmt->execute([$_POST['name'], $_POST['address']]);
|
|
header("Location: outlets.php");
|
|
exit;
|
|
}
|
|
|
|
if (isset($_GET['delete'])) {
|
|
$pdo->prepare("DELETE FROM outlets WHERE id = ?")->execute([$_GET['delete']]);
|
|
header("Location: outlets.php");
|
|
exit;
|
|
}
|
|
|
|
$query = "SELECT * FROM outlets ORDER BY id DESC";
|
|
$outlets_pagination = paginate_query($pdo, $query);
|
|
$outlets = $outlets_pagination['data'];
|
|
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="fw-bold mb-0">Outlets</h2>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addOutletModal">
|
|
<i class="bi bi-plus-lg"></i> Add Outlet
|
|
</button>
|
|
</div>
|
|
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body p-0">
|
|
<!-- Pagination Controls -->
|
|
<div class="p-3 border-bottom bg-light">
|
|
<?php render_pagination_controls($outlets_pagination); ?>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th class="ps-4">ID</th>
|
|
<th>Name</th>
|
|
<th>Address</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($outlets as $outlet): ?>
|
|
<tr>
|
|
<td class="ps-4 fw-medium">#<?= $outlet['id'] ?></td>
|
|
<td class="fw-bold"><?= htmlspecialchars($outlet['name']) ?></td>
|
|
<td><small class="text-muted"><?= htmlspecialchars($outlet['address']) ?></small></td>
|
|
<td>
|
|
<a href="outlet_edit.php?id=<?= $outlet['id'] ?>" class="btn btn-sm btn-outline-secondary me-1"><i class="bi bi-pencil"></i></a>
|
|
<a href="?delete=<?= $outlet['id'] ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this outlet?')"><i class="bi bi-trash"></i></a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- Bottom Pagination -->
|
|
<div class="p-3 border-top bg-light">
|
|
<?php render_pagination_controls($outlets_pagination); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Outlet Modal -->
|
|
<div class="modal fade" id="addOutletModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Add Outlet</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<form method="POST">
|
|
<div class="modal-body">
|
|
<input type="hidden" name="action" value="add_outlet">
|
|
<div class="mb-3">
|
|
<label class="form-label">Name</label>
|
|
<input type="text" name="name" class="form-control" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Address</label>
|
|
<textarea name="address" class="form-control" rows="2"></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
<button type="submit" class="btn btn-primary">Save Outlet</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|