<?php
$pageName  = "IMF Verification";
include($_SERVER['DOCUMENT_ROOT'] . "/user/layout/header.php");
if ($page['kyc_status'] == '1' AND $row['kyc_status'] == '0') {
    header("location:./pending-kyc.php");
    exit;
}



// 

// Other scripts Available
require_once($_SERVER['DOCUMENT_ROOT'] . "/include/Transfer/WireFunction.php");

if (!isset($_SESSION['is_transfer'])) {
    header("Location:./dashboard.php");
}

if (!isset($_SESSION['is_tax_code'])) {
    header("Location:./wire-transfer.php");
    exit();
}

unset($_SESSION['is_cot_code']);




if (isset($_POST['imf_submit'])) {
    $imf_code = $_POST['imf_code'];
    $imf = $row['acct_imf'];
    $amount = $temp_trans['amount'];

    $acct_otp = substr(number_format(time() * rand(), 0, '', ''), 0, 4);

    $sql =  "UPDATE users SET acct_otp=:acct_otp WHERE id=:id";
    $stmt = $conn->prepare($sql);
    $stmt->execute([
        'acct_otp' => $acct_otp,
        'id' => $user_id
    ]);


    $full_name = $row['firstname'] . " " . $row['lastname'];
    $APP_NAME = WEB_TITLE;
    $APP_URL = WEB_URL;
    $SITE_ADDRESS = $page['url_address'];
    $user_email = $row['acct_email'];

    $message = $sendMail->pinRequest($full_name, $acct_otp, $APP_NAME, $APP_URL, $SITE_ADDRESS);
    // User Email
    $subject = "One-Time Code - $APP_NAME";
    $email_message->send_mail($email, $message, $subject);

    if ($imf_code === $imf) {
        $_SESSION['wire-transfer'] = $user_id;
        $_SESSION['is_wire_transfer'] = "wire";
        $_SESSION['is__transfer'] = "None";
        $_SESSION['is_transfer']  = "transfer";
        $_SESSION['is_tax_code'] = "None";

        header("Location:./wire-pin.php");
    } else {
        //notify_alert('Invalid IMF Code','danger','3000','Close');
        toast_alert('error', 'Invalid IMF Code');
    }
}

?>


<!-- App Header -->
<div class="appHeader transparent">
    <div class="left">
        <a href="<?= $web_url ?>/user/dashboard.php" class="headerButton">
            <ion-icon name="chevron-back-outline"></ion-icon>
        </a>
    </div>
    <div class="pageTitle"></div>
    <div class="right">
        <a onclick="location.reload();" class="headerButton">
            <ion-icon name="refresh"></ion-icon>
        </a>
    </div>
</div>
<!-- * App Header -->

<!-- App Capsule -->
<div id="appCapsule">

    <div class="section mt-2 text-center">
        <h1>Enter IMF Code</h1>
        <h4>Enter 4 digit verification code</h4>
    </div>
    <div class="section mb-5 p-2">
        <form method="POST">
            <div class="form-group basic">
                <input type="text" name="imf_code" minlength="3" class="form-control verification-input" autocomplete="off" id="smscode" placeholder="••••" maxlength="4">

                <input type="number" value="<?= $temp_trans['amount'] ?>" name="amount" hidden id="amount">
                <input type="text" value="<?= $temp_trans['bank_name'] ?>" name="bank_name" hidden id="bank_name">
                <input type="text" value="<?= $temp_trans['account_name'] ?>" name="account_name" hidden id="account_name">
                <input type="number" value="<?= $temp_trans['account_number'] ?>" name="account_number" hidden id="account_number">
                <input type="text" value="<?= $temp_trans['account_type'] ?>" name="account_type" hidden id="account_type">
                <input type="text" value="<?= $temp_trans['trans_type'] ?>" name="trans_type" hidden id="trans_type">
                <input type="text" value="<?= $temp_trans['bank_country'] ?>" name="bank_country" hidden id="bank_country">
                <input type="number" value="<?= $temp_trans['user_id'] ?>" name="user_id" id="user_id" hidden>
                <input type="text" value="<?= $temp_trans['routine_number'] ?>" name="routine_number" id="routine_number" hidden>
                <input type="text" value="<?= $temp_trans['swift_code'] ?>" name="swift_code" id="swift_code" hidden>


            </div>

            <div class="form-button-group transparent">
                <button type="submit" name="imf_submit" class="btn btn-primary btn-block btn-lg">Verify</button>
            </div>

        </form>
    </div>

</div>
<!-- * App Capsule -->

<?php



include($_SERVER['DOCUMENT_ROOT'] . "/user/layout/footer.php");

?>