<?php
    if (isset($_SESSION['user_email'])) {

        // Получаем пользователя
        $user = $db_connect->get("users", "*", [
            "email" => $_SESSION['user_email']
        ]);

        if ($user) {

            $userRole = $db_connect->get("users_roles", "role_id", ["user_id" => $user["id"]]);

            // Получаем название роли
            $role = $db_connect->get("roles", [
                "name"
            ], [
                "id" => $userRole
            ]);

            $user['role_name'] = $role['name'] ?? 'Guest';

            // Баланс
            $userBalanceInfo = getConvertedBalanceInfo();
            $user["balance"] = $userBalanceInfo["finalBalance"];

            // Передаём в шаблон
            $smarty->assign('user', $user);
            $smarty->assign('user_email', htmlspecialchars($user['email']));
            $smarty->assign('role_id', $userRole);
            $smarty->assign('role_name', $user['role_name']);
            $smarty->assign('user_balance', $user['balance']);
            $smarty->assign('currency', $userBalanceInfo["currentCurrency"]);

            $userGroup = $userRole;
        }

        require_once(ENGINE_DIR . '/mods/user_rules.php');
    }
