123 lines
5.2 KiB
PHP
123 lines
5.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../db/config.php';
|
|
$pdo = db();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_table') {
|
|
$stmt = $pdo->prepare("INSERT INTO tables (area_id, name, capacity) VALUES (?, ?, ?)");
|
|
$stmt->execute([$_POST['area_id'], $_POST['name'], $_POST['capacity']]);
|
|
header("Location: tables.php");
|
|
exit;
|
|
}
|
|
|
|
if (isset($_GET['delete'])) {
|
|
$pdo->prepare("DELETE FROM tables WHERE id = ?")->execute([$_GET['delete']]);
|
|
header("Location: tables.php");
|
|
exit;
|
|
}
|
|
|
|
// Fetch tables with area names
|
|
$query = "SELECT tables.*, areas.name as area_name
|
|
FROM tables
|
|
LEFT JOIN areas ON tables.area_id = areas.id
|
|
ORDER BY tables.id DESC";
|
|
|
|
$tables_pagination = paginate_query($pdo, $query);
|
|
$tables = $tables_pagination['data'];
|
|
|
|
// Fetch areas for dropdown
|
|
$areas = $pdo->query("SELECT id, name FROM areas ORDER BY name ASC")->fetchAll();
|
|
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="fw-bold mb-0">Tables</h2>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addTableModal">
|
|
<i class="bi bi-plus-lg"></i> Add Table
|
|
</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($tables_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>Area</th>
|
|
<th>Capacity</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($tables as $table): ?>
|
|
<tr>
|
|
<td class="ps-4 fw-medium">#<?= $table['id'] ?></td>
|
|
<td class="fw-bold"><?= htmlspecialchars($table['name']) ?></td>
|
|
<td><span class="badge bg-secondary"><?= htmlspecialchars($table['area_name'] ?? 'N/A') ?></span></td>
|
|
<td><?= htmlspecialchars($table['capacity']) ?> pax</td>
|
|
<td>
|
|
<a href="table_edit.php?id=<?= $table['id'] ?>" class="btn btn-sm btn-outline-primary me-1" title="Edit"><i class="bi bi-pencil"></i></a>
|
|
<a href="?delete=<?= $table['id'] ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this table?')" title="Delete"><i class="bi bi-trash"></i></a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($tables)): ?>
|
|
<tr>
|
|
<td colspan="5" class="text-center py-4 text-muted">No tables found. Add one to get started.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- Bottom Pagination -->
|
|
<div class="p-3 border-top bg-light">
|
|
<?php render_pagination_controls($tables_pagination); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Table Modal -->
|
|
<div class="modal fade" id="addTableModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Add Table</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_table">
|
|
<div class="mb-3">
|
|
<label class="form-label">Table Name/Number</label>
|
|
<input type="text" name="name" class="form-control" placeholder="e.g. T1, Window 5" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Area</label>
|
|
<select name="area_id" class="form-select" required>
|
|
<option value="">Select Area</option>
|
|
<?php foreach ($areas as $area): ?>
|
|
<option value="<?= $area['id'] ?>"><?= htmlspecialchars($area['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Capacity (Pax)</label>
|
|
<input type="number" name="capacity" class="form-control" value="4" min="1" required>
|
|
</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 Table</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|