<?php
/* ========================
   AUTH STAFF
   Path: /auth/auth_staff.php
======================== */

// Start session jika belum
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

/* ========================
   CEK LOGIN
======================== */
if (!isset($_SESSION['login']) || $_SESSION['login'] !== true) {
    header("Location: ../../index.html?error=session");
    exit;
}

/* ========================
   NORMALISASI ROLE
======================== */
$role = strtoupper(trim($_SESSION['role'] ?? $_SESSION['user_type'] ?? ''));

/* ========================
   VALIDASI STAFF ONLY
======================== */
if ($role !== 'S') {
    // Redirect ke dashboard sesuai role mereka
    if ($role === 'A' || $role === 'M') {
        header("Location: ../../dashboard.php");
    } else {
        header("Location: ../../index.html?error=forbidden");
    }
    exit;
}

// Optional: Set timezone
date_default_timezone_set('Asia/Jakarta');