Table number is required.'; } else { try { if ($action === 'edit_table' && $id) { if (!has_permission('tables_add')) { $message = '
Access Denied.
'; } else { $stmt = $pdo->prepare("UPDATE tables SET table_number = ?, capacity = ?, area_id = ?, status = ? WHERE id = ?"); $stmt->execute([$table_number, $capacity, $area_id, $status, $id]); $message = '
Table updated successfully!
'; } } elseif ($action === 'add_table') { if (!has_permission('tables_add')) { $message = '
Access Denied.
'; } else { $stmt = $pdo->prepare("INSERT INTO tables (table_number, capacity, area_id, status) VALUES (?, ?, ?, ?)"); $stmt->execute([$table_number, $capacity, $area_id, $status]); $message = '
Table created successfully!
'; } } } catch (PDOException $e) { $message = '
Database error: ' . $e->getMessage() . '
'; } } } // Handle Delete (Soft Delete) if (isset($_GET['delete'])) { if (!has_permission('tables_del')) { $message = '
Access Denied: You do not have permission to delete tables.
'; } else { try { $id = (int)$_GET['delete']; // Soft delete to avoid breaking historical order integrity $pdo->prepare("UPDATE tables SET is_deleted = 1 WHERE id = ?")->execute([$id]); header("Location: tables.php?deleted=1"); exit; } catch (PDOException $e) { $message = '
Error removing table: ' . $e->getMessage() . '
'; } } } if (isset($_GET['deleted'])) { $message = '
Table removed successfully!
'; } $areas = $pdo->query("SELECT * FROM areas WHERE is_deleted = 0 ORDER BY name ASC")->fetchAll(); $query = "SELECT t.*, a.name as area_name FROM tables t LEFT JOIN areas a ON t.area_id = a.id WHERE t.is_deleted = 0 ORDER BY a.name ASC, t.table_number ASC"; $tables_pagination = paginate_query($pdo, $query); $tables = $tables_pagination['data']; include 'includes/header.php'; ?>

Tables

ID Table Number Area Capacity Status Actions
# Persons Available Occupied
No tables found.