<?php include('config.php');

// TEMP: use logged-in user later
//$_SESSION['user_id'] = 1;

// Check if user started an application
if (!isset($_SESSION['user_id'])) {
    //header("Location: login.php");
    echo "<script>
            window.location.href = 'login.php';
        </script>";
    exit();
}
//$userID = $_SESSION['user_id'];
$userID = $_SESSION['user_id'];
$user_id = $userID;

$sql = "SELECT * FROM users WHERE id = '$userID'";
$result = mysqli_query($conn, $sql);
$result = mysqli_fetch_array($result);

$userName = $result['username'];
$userEmail = $result['email'];
$userFirstName = $result['first_name'];
$userLastName = $result['last_name'];
$userVerified = $result['verification_completed'];
$kycSubmitted = $result['verification_sumitted'];
$userAddress = $result['address'];
$userStatus = $result['status'];
$referred_by = $result['referred_by'];
$funds_locked = $result['funds_locked'];
$referral_balance = $result['referral_balance'];




$fundBalance = $result['fund_balance'];
$totalProfit = $result['total_profit'];
$availableBalance = $result['available_balance'];

$email = $userEmail;
$first_name = $userFirstName;

/*
    $sql = "SELECT * FROM `kyc_documents` WHERE user_id = '$userID'";
    $kyc_sql = mysqli_query($conn, $sql);
    $kyc_result = mysqli_fetch_array($kyc_sql);

    $kyc_verified = $kyc_result['verification_status'];
*/


$ref = mysqli_query($conn, "SELECT * FROM referral_settings WHERE is_active = 1");
$refRow = mysqli_fetch_array($ref);

$bot_bonus = $refRow['bot_bonus'];

$query = "SELECT * FROM user_bot_subscriptions WHERE status = 'active'";
$result = mysqli_query($conn, $query);
$count = mysqli_num_rows($result);
if ($count > 0) {
    mysqli_query($conn, "UPDATE users SET funds_locked = 1 WHERE id = $userID");
}elseif ($count == 0) {
    mysqli_query($conn, "UPDATE users SET funds_locked = 0 WHERE id = $userID");
}

?>


