diff --git a/includes/header.php b/includes/header.php index 7eb39e6..0ab61db 100644 --- a/includes/header.php +++ b/includes/header.php @@ -4,67 +4,7 @@ session_start(); require_once __DIR__ . '/../db/config.php'; // --- Helper Functions (MUST BE DEFINED BEFORE settings.php) --- - -function isLoggedIn() { - return isset($_SESSION['user_id']); -} - -function isSuperAdmin() { - return isset($_SESSION['is_super_admin']) && $_SESSION['is_super_admin'] == 1; -} - -function isAdmin() { - if (isSuperAdmin()) return true; - if (isset($_SESSION['user_role']) && strtolower($_SESSION['user_role']) === 'admin') return true; - if (isset($_SESSION['role']) && strtolower($_SESSION['role']) === 'admin') return true; - return false; -} - -function redirect($path) { - if (!headers_sent()) { - header("Location: $path"); - } else { - echo ""; - } - exit; -} - -// Permission helpers -function canView($page = null) { - if (isAdmin()) return true; - if ($page) { - return $_SESSION['permissions'][$page]['view'] ?? false; - } - return $_SESSION['can_view'] ?? false; -} - -function canAdd($page = null) { - if (isAdmin()) return true; - if ($page) { - return $_SESSION['permissions'][$page]['add'] ?? false; - } - return $_SESSION['can_add'] ?? false; -} - -function canEdit($page = null) { - if (isAdmin()) return true; - if ($page) { - return $_SESSION['permissions'][$page]['edit'] ?? false; - } - return $_SESSION['can_edit'] ?? false; -} - -function canDelete($page = null) { - if (isAdmin()) return true; - if ($page) { - return $_SESSION['permissions'][$page]['delete'] ?? false; - } - return $_SESSION['can_delete'] ?? false; -} - -function canViewInternal() { - return canView('internal'); -} +require_once __DIR__ . '/permissions.php'; // Now load centralized settings (which may use the helpers above) require_once __DIR__ . '/settings.php'; diff --git a/includes/permissions.php b/includes/permissions.php new file mode 100644 index 0000000..12913b4 --- /dev/null +++ b/includes/permissions.php @@ -0,0 +1,64 @@ +window.location.href='$path';"; + } + exit; +} + +// Permission helpers +function canView($page = null) { + if (isAdmin()) return true; + if ($page) { + return $_SESSION['permissions'][$page]['view'] ?? false; + } + return $_SESSION['can_view'] ?? false; +} + +function canAdd($page = null) { + if (isAdmin()) return true; + if ($page) { + return $_SESSION['permissions'][$page]['add'] ?? false; + } + return $_SESSION['can_add'] ?? false; +} + +function canEdit($page = null) { + if (isAdmin()) return true; + if ($page) { + return $_SESSION['permissions'][$page]['edit'] ?? false; + } + return $_SESSION['can_edit'] ?? false; +} + +function canDelete($page = null) { + if (isAdmin()) return true; + if ($page) { + return $_SESSION['permissions'][$page]['delete'] ?? false; + } + return $_SESSION['can_delete'] ?? false; +} + +function canViewInternal() { + return canView('internal'); +} diff --git a/meetings.php b/meetings.php index 2f2bc23..606c1c0 100644 --- a/meetings.php +++ b/meetings.php @@ -96,16 +96,16 @@ if (isset($_SESSION['success'])) { } ?> - - + + @@ -260,63 +260,58 @@ if (isset($_SESSION['success'])) {