<?php
session_start();

// Initialize Composer.
require_once 'vendor/autoload.php';
require_once 'db_functions.php';

// Load environment variables.
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
$dotenv->safeLoad();

// Set SESSION variable.
if (!isset($_SESSION['initialized'])) {
    $_SESSION['initialized'] = true;
    $_SESSION['theme'] = 'dark';
}

if ($_SESSION['initialized'] && isset($_POST['theme'])) {
    $_SESSION['theme'] = $_POST['theme'];
    unset($_POST['theme']);
}

if (isset($_COOKIE['user_id']))
    exec_statement('UPDATE user SET is_active = true WHERE user_id = ' . $_COOKIE['user_id'] . ';', 1);
