<?php
require_once 'config.php';
require_once 'functions.php';

if (!isLoggedIn() && basename($_SERVER['PHP_SELF']) != 'login.php') {
    redirect('login.php');
}

if (isLoggedIn()) {
    $current_page = basename($_SERVER['PHP_SELF']);
    
    if (isAdmin() && strpos($_SERVER['REQUEST_URI'], '/admin/') === false && $current_page != 'index.php') {
        redirect('admin/dashboard.php');
    }
    
    if (isPenguji() && strpos($_SERVER['REQUEST_URI'], '/penguji/') === false && $current_page != 'index.php') {
        redirect('penguji/dashboard.php');
    }
}

// HAPUS fungsi-fungsi berikut karena sudah ada di functions.php
// function isPenguji() {
//     return isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'penguji';
// }
// 
// function formatTanggal($date) {
//     return date('d/m/Y', strtotime($date));
// }
// 
// function sanitize($data) {
//     return htmlspecialchars(trim($data), ENT_QUOTES, 'UTF-8');
// }
?>