<?php
define("DB_HOST", "localhost");
define("DB_NAME", "transfer_db");
define("DB_USER", "transfer_user");
define("DB_PASS", "change_me");
define("BASE_URL", "");

define("ADMIN_USER", "admin");
define("ADMIN_PASS", "change_me");

// Google OAuth
define("GOOGLE_CLIENT_ID", "your-google-client-id.apps.googleusercontent.com");
define("GOOGLE_CLIENT_SECRET", "your-google-client-secret");
define("GOOGLE_REDIRECT_URI", "https://transfer.tapee.ac.th/login-google-callback.php");

date_default_timezone_set("Asia/Bangkok");

if (php_sapi_name() !== 'cli') {
    session_start();
}

function requireLogin() {
    if (!isset($_SESSION["logged_in"]) || $_SESSION["logged_in"] !== true) {
        header("Location: " . BASE_URL . "/login.php");
        exit;
    }
}

function isAdmin() {
    return isset($_SESSION["role"]) && $_SESSION["role"] === "admin";
}

function isAdvisor() {
    return isset($_SESSION["role"]) && $_SESSION["role"] === "advisor";
}

function isStudent() {
    return isset($_SESSION["role"]) && $_SESSION["role"] === "student";
}

function requireAdmin() {
    requireLogin();
    if (!isAdmin()) {
        header("Location: " . BASE_URL . "/index.php");
        exit;
    }
}

function getCurrentUserRole() {
    return $_SESSION["role"] ?? null;
}

function getCurrentUserId() {
    return $_SESSION["user_id"] ?? null;
}

function getCurrentUserCurriculumId() {
    return $_SESSION["curriculum_id"] ?? null;
}
