<?php 
session_start();
include '_inc/dbconn.php';

if(!isset($_SESSION['customer_login'])) { header('location:index.php'); exit; }

$cust_id = $_SESSION['cust_id'];
$amount = mysqli_real_escape_string($con, $_POST['t_val']);

// 1. Fetch User Data & Admin Block Status
$query = mysqli_query($con, "SELECT * FROM users WHERE id='$cust_id'");
$user = mysqli_fetch_array($query);

/** * ADMIN BLOCK CHECK 
 * Based on your SQL, we check the 'status' column or a custom 'transfer_block' column
 */
if($user['status'] == 'BLOCKED') {
    // If admin sent a custom message, show it, else show default
    $block_msg = !empty($user['admin_msg']) ? $user['admin_msg'] : "Your account is restricted from performing transfers. Please contact support.";
    echo "<script>alert('$block_msg'); window.location='customer_transfer.php';</script>";
    exit;
}

// 2. Generate Security Data for next steps
$_SESSION['temp_transfer'] = $_POST;
$_SESSION['otp_code'] = rand(100000, 999999);

// Logic: If user is enabled, show the Processing GIF
?>
<!DOCTYPE html>
<html>
<head>
    <title>Securing Transaction...</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        .processing-container {
            height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: #FFFFFF;
        }
        .loader-gif { width: 120px; margin-bottom: 20px; }
        .text-blue { color: #0052FF; font-weight: 700; }
    </style>
</head>
<body>
    <div class="processing-container">
        <img src="https://i.gifer.com/ZZ5H.gif" class="loader-gif">
        <h4 class="text-blue">Processing Security Protocols...</h4>
        <p class="text-muted">Verifying your account status with the bank servers.</p>
    </div>

    <script>
        // Redirect to OTP verification after 3.5 seconds of "processing"
        setTimeout(function() {
            window.location.href = 'customer_verify_otp.php';
        }, 3500);
    </script>
</body>
</html>
