<?php
declare(strict_types=1);

namespace App\Controllers;

require_once BASE_PATH . '/app/helpers/permissions.php';

require_once BASE_PATH . '/app/helpers/conference_scope.php';

use App\Core\Controller;

final class AdminSwitchConferenceController extends Controller
{
    public function switch(): void
    {
        require_permission('admin.access');
        if (!$this->isPost()) redirect('admin/dashboard');
        csrf_check();

        $id = (int)($_POST['conference_id'] ?? 0);
        if (\function_exists('set_current_conference_id')) {
            \set_current_conference_id($id);
        } else {
            if (session_status() !== PHP_SESSION_ACTIVE) { @session_start(); }
            $_SESSION['current_conference_id'] = $id;
        }

        $back = trim((string)($_POST['back'] ?? 'admin/dashboard'));
        redirect($back ?: 'admin/dashboard');
    }
}
