<?php
ob_start(); // Start output buffering
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}


// Redirect to login if the session is expired
if (!isset($_SESSION['user'])) {
    header("location:login.php");
    exit;
}

// Get the current page name
$currentPage = basename($_SERVER['PHP_SELF']);

// Restrict `investor_share` users to only `index_admin.php`
if (isset($_SESSION['admin_access']) && $_SESSION['admin_access'] === true) {
    // If the current page is NOT `index_share.php`, redirect to it
    if ($currentPage !== 'index_admin.php') {
        header("location:index_admin.php");
        exit;
    }
}

// For general users, ensure they cannot access `index_share.php` or `index_attendance.php`
if (isset($_SESSION['employee_access']) && $_SESSION['employee_access'] === true) {
    // If the current page is NOT `index_share.php`, redirect to it
    if ($currentPage !== 'index.php') {
        header("location:index.php");
        exit;
    }
}

ob_end_flush(); // Flush the output buffer
?>
