<?php
// OneLauncher - includes/auth.php
session_start();

if (!isset($_SESSION['admin_id'])) {
    header('Location: login.php');
    exit;
}

if (isset($_GET['set_theme']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
    $_SESSION['active_theme_id'] = (int)$_GET['set_theme'];
    $redirect = $_SERVER['HTTP_REFERER'] ?? 'dashboard.php';
    // Remove set_theme da URL de redirecionamento para evitar loops ou parâmetros obsoletos
    $redirect = preg_replace('/[?&]set_theme=[^&]*/', '', $redirect);
    header('Location: ' . $redirect);
    exit;
}

if (!isset($_SESSION['active_theme_id'])) {
    $_SESSION['active_theme_id'] = 1;
}
$active_theme_id = (int)$_SESSION['active_theme_id'];
?>
