<?php
include('../includes/session.php');
include('../includes/config.php');
include('../template/ahkweb/header.php');

$fee = 0;
$captcha_data = json_decode(file_get_contents("$tng_apiurl/aadhar_captcha_verification.php"), true);

if (isset($_POST['eid'])) {
    $eid = $_POST['eid'];
    $captcha = $_POST['captcha'];
    $captchaTxnId = $_POST['captchaTxnId'];

    if ($rw['findwallet'] >= $fee) {
        $url = "$tng_apiurl/enrollment_status_verification.php?eid=" . urlencode($eid) . "&captcha=" . urlencode($captcha) . "&captchaSID=" . urlencode($captchaTxnId);

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_CUSTOMREQUEST => "GET"
        ));
        $response = curl_exec($curl);
        curl_close($curl);
        $resdata = json_decode($response, true);

        if ($resdata['sampleCode'] === "200") {
            
            $msg = $resdata['resMessage'];
            $msgcode = $resdata['resMessageCode'];
           

           if ($resdata['sampleCode'] === "200") {
    $msgcode = $resdata['resMessageCode'] ?? "No code";
    $msg = $resdata['resMessage'] ?? "Success";
    
    echo '<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script>
        Swal.fire({
            icon: "success",
            title: "Status: ' . htmlspecialchars($msgcode) . ' Message: ' . htmlspecialchars($msg) . ' ",
            text: "Suucess",
            timer: 5000,
            timerProgressBar: true
        });
    </script>';
} else {
    $error = $resdata['error'] ?? "Unknown error occurred.";
    echo '<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script>
        Swal.fire({
            icon: "error",
            title: "Failed",
            text: "' . htmlspecialchars($error) . '",
            timer: 4000,
            timerProgressBar: true
        });
    </script>';
}

        }
    } else {
        echo '<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
    Swal.fire({
        icon: "error",
        title: "Low Balance",
        text: "Please recharge your wallet.",
        timer: 3000,
        timerProgressBar: true
    });
    setTimeout(() => { window.location = "wallet.php"; }, 2000);
</script>';

    }
}
?>

<div class="page-wrapper">
    <div class="page-content">
        <div class="mobile-menu-overlay"></div>
        <div class="main-container">
            <div class="col-lg-12">
                <div class="card" style="margin-left: 10px; padding-left: 30px; padding-top: 12px; box-shadow: 1px 5px 5px 5px;">
                    <div class="stat-widget-two">
                        <div class="stat-content">
                            <div class="stat-text">
                                <div class="container-fluid">
                                    <div class="row">
                                        <div class="col-lg-4 col-md-6 col-sm-6">
                                            <div class="card">
                                                <div class="card-body">
                                                    
                                                   
                        <div class="card" style="padding: 30px;">
                            <h4>Aadhaar Enrollment Status Checker</h4>
                             </div>
                            <form action="" method="POST">
                                <div class="mb-3">
                                    <label for="eid" class="form-label">Enter EID (28 digit with timestamp)</label>
                                    <input type="text" class="form-control" name="eid" id="eid" required>
                                </div>
                                <div class="mb-3">
                                    <label class="form-label">Enter Captcha</label><br>
                                    <img src="<?php echo $captcha_data['captcha']; ?>" style="border: 1px solid #333; margin-bottom:10px;">
                                    <input type="hidden" name="captchaTxnId" value="<?php echo $captcha_data['captchaTxnId']; ?>">
                                    <input type="text" class="form-control" name="captcha" required>
                                </div>
                                <div class="mb-3">
                                    <input type="submit" class="btn btn-primary" value="Check Status">
                                </div>
                            </form>
                            <div class="alert alert-info">
                                Fee ₹<?php echo $fee; ?> 
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>  
</div>
   
                <br><br><br><br>
            </div>
        </div>
    </div>
</div>

<?php include('footer.php'); ?>
<script src="../template/ahkweb/assets/js/bootstrap.bundle.min.js"></script>
<script src="../template/ahkweb/assets/plugins/simplebar/js/simplebar.min.js"></script>
<script src="../template/ahkweb/assets/plugins/metismenu/js/metisMenu.min.js"></script>
<script src="../template/ahkweb/assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
<script src="../template/ahkweb/assets/js/app.js"></script>
</html>
