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(); // Use a very standard query without backticks on aliases to maximize compatibility $query = "SELECT t.id, t.table_number, t.capacity, t.status, t.area_id, 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'; // Base URL for QR codes $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https') ? "https://" : "http://"; $host = $_SERVER['HTTP_HOST']; // Calculate project root $current_dir = dirname($_SERVER['PHP_SELF']); // /admin $project_root = dirname($current_dir); // / if ($project_root === DIRECTORY_SEPARATOR) $project_root = ''; $baseUrl = $protocol . $host . $project_root; ?>

Tables

QR Code Table # Area Capacity Status Actions
No tables found

Add your first table to get started.