<?php
session_start();
if(!isset($_SESSION['agent_uid']) || $_SESSION['agent_uid'] == ""){
    header("location:index.php");
    exit;
}
include("conn.php");

$agent_uid    = $_SESSION['agent_uid'];
$agent_mobile = $_SESSION['agent_mobile'];

// Verify agent still active
$agent_verify = mysqli_fetch_assoc(mysqli_query($conn,
    "SELECT userid FROM tb_agent WHERE userid='$agent_uid' AND status='1'"
));
if(!$agent_verify){
    session_destroy();
    header("location:index.php?err=kicked");
    exit;
}

// Agent wallet balance
$agent_wallet = mysqli_fetch_assoc(mysqli_query($conn,
    "SELECT motta FROM shonu_kaichila WHERE balakedara='$agent_uid'"
));
$agent_balance = $agent_wallet['motta'] ?? 0;

// Agent-এর নিজের invitation code (owncode) — এটা user-দের দিতে হবে signup-এর সময়
$agent_code_row = mysqli_fetch_assoc(mysqli_query($conn,
    "SELECT owncode FROM shonu_subjects WHERE id='$agent_uid'"
));
$agent_owncode = $agent_code_row['owncode'] ?? '';
?>
