<?php
session_start();

$isLoggedIn = false;
$fullName = '';
$email = '';
$idMember = '';
$memberSub = null;

if (isset($_SESSION['login']) && $_SESSION['login'] == 1) {
    $isLoggedIn = true;
    $fullName = $_SESSION['FullName'] ?? 'Profile';
    $email = $_SESSION['Email'] ?? '-';
    $idMember = $_SESSION['UserID'] ?? '';
} elseif (isset($_COOKIE['fe_remember_email'])) {
    $isLoggedIn = true;
    $_SESSION['login'] = 1;
    $_SESSION['Email'] = $_COOKIE['fe_remember_email'];
    $_SESSION['FullName'] = $_COOKIE['fe_remember_fullname'] ?? 'Profile';
    $fullName = $_SESSION['FullName'];
    $email = $_SESSION['Email'];
    $idMember = $_SESSION['UserID'] ?? '';
}

if ($isLoggedIn && !empty($idMember)) {
    include('config/koneksi.php');
    
    $sqlmemb = "SELECT * FROM member_subscriptions WHERE member_id = ?";
    $stmt = $conn->prepare($sqlmemb);
    $stmt->bind_param("i", $idMember);
    $stmt->execute();
    $resultSub = $stmt->get_result();
    $memberSub = $resultSub->fetch_assoc();
    $stmt->close();
}
?>
