<?php
session_start();

function checkPermission($allowed_roles = []) {
    // allow login page without role
    if (basename($_SERVER['PHP_SELF']) == "index.php") {
        return;
    }

    if (!isset($_SESSION['role'])) {
        header("Location: index.php");
        exit();
    }
    if (!in_array($_SESSION['role'], $allowed_roles)) {
        die("<div style='display: flex; justify-content: center; margin-top: 100px;'><div><h2 style='font-size: 40px; color:red;text-align:center;'>🚫 Access Denied 🚫</h2> <div style='text-align: center;'><a style='text-align: center; color: #fff; background: #000; display: inline-block; text-decoration: none; padding: 10px 30px; margin-top: 2\10px' href='dashboard.php'>Back to Dashboard</a></div></div></div>");
    }
}
