<?php

if (!function_exists('ec_require_login')) {

    function ec_require_login(): void
    {
        if (session_status() !== PHP_SESSION_ACTIVE) {
            session_start();
        }

        if (empty($_SESSION['user_id'])) {

            $_SESSION['redirect_after_login'] =
                $_SERVER['REQUEST_URI'] ?? '';

            header('Location: /easychair/login');

            exit;
        }
    }
}

if (!function_exists('ec_require_conference')) {

    function ec_require_conference(): void
    {
        ec_require_login();

        if (
            empty($_SESSION['conference_id'])
            &&
            empty($_SESSION['current_conference_id'])
        ) {

            header('Location: /easychair/select-conference');

            exit;
        }
    }
}
