<?php
namespace App\Controllers;

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

use App\Core\Controller;
use App\Core\Database;

class SuperAdminConferenceController extends Controller
{
    public function index()
    {

        // Pack512: non-superadmin bypasses selector safely.
        if (function_exists('ec_scope_role') && ec_scope_role() !== 'super_admin') {
            if (function_exists('ec_scope_auto_select_conference')) {
                // ec_scope_auto_select_conference(true);
            }
            $landing = function_exists('ec_scope_landing_url') ? ec_scope_landing_url() : '/easychair/admin/dashboard';
            header("Location: " . $landing);
            exit;
        }

if (!is_super_admin()) exit('Forbidden');

        $db = Database::getInstance();
        $confs = $db->query("
            SELECT c.*, o.name as org_name
            FROM conferences c
            LEFT JOIN organizations o ON c.org_id = o.id
            ORDER BY c.id DESC
        ")->fetchAll();

        $this->view('superadmin/conferences/index', compact('confs'));
    }
}
