<?php
require_once 'config.php';

// Fungsi untuk mengecek apakah user sudah login
function checkLogin() {
    if (!isset($_SESSION['user_id']) || !isset($_SESSION['role'])) {
        header("Location: login.php");
        exit();
    }
}

// Fungsi untuk mengecek role yang diizinkan
function checkRole($allowed_roles) {
    if (!isset($_SESSION['user_id']) || !isset($_SESSION['role'])) {
        header("Location: login.php");
        exit();
    }
    
    if (!in_array($_SESSION['role'], $allowed_roles)) {
        $_SESSION = array();
        if (isset($_COOKIE[session_name()])) {
            setcookie(session_name(), '', time()-3600, '/');
        }
        session_destroy();
        header("Location: login.php");
        exit();
    }
}
?> 