<?php



session_start(); 
    $u_uname = '';
    if (isset($_COOKIE['auth_token']))
    {
        $u_uname = $_COOKIE['auth_token'];
    }else{
        header("location:../login.php");
    }

include '../include/pay_connection.php';



$user_id = mysqli_real_escape_string($link, $_POST['user_id']);


$query = "SELECT activation_status,wallet_balance FROM users WHERE user_id = '$user_id'";
$result = mysqli_query($link, $query);


if ($result) {
    $row = mysqli_fetch_assoc($result);
    $wallet_balance = $row['wallet_balance'];
        $opening_balance = $wallet_balance;
        

    if ($row['activation_status'] == 1) {
        
        
         $insert_query = "INSERT INTO transaction_history (`user_id`, `amount`,`remark`, `reason`, `status`, `opening_balance`, `closing_balance`) 
                                     VALUES ('$user_id', '25000', 'activation charge debited by admin','debit', 'success', '$opening_balance', '$opening_balance')";
                    mysqli_query($link, $insert_query);
        
        header("location:../id_activator.php?status=0");
        // echo "User is active.";
    } else {
        
        header("location:../id_activator.php?status=1");
        echo "User is inactive.";
    }
}
// else {
    
//     header("location:../id_activator.php?status=2");
//     // echo "Error fetching activation status.";
// }


mysqli_close($link);
     


?>