<?php
/**
 * auth_init.php
 * -------------------------------------------------------------------
 * Sets up auth/role variables with NO HTML output whatsoever.
 * Require this FIRST (right after session_start() + config.php),
 * before any permission checks, POST handling, or header() redirects.
 * layout_header.php also requires this (via require_once) so it's safe
 * even if a page only includes layout_header.php directly.
 * -------------------------------------------------------------------
 */

if (!isset($_SESSION['user_id'])) {
    header("Location: ../login.php");
    exit;
}

require_once __DIR__ . '/helpers.php';

$username = $_SESSION['username'];
$role = $_SESSION['role'];
$isManager = strtolower(trim($role)) === 'manager';
$isAdmin = in_array(strtolower(trim($role)), ['admin', 'superadmin', 'hr', 'finance']); // adjust to your actual admin-type roles
$userDeptId = isset($_SESSION['department_id']) ? intval($_SESSION['department_id']) : 0;
