<?php ob_start();
include('../includes/db_conx.php');

isset($_SESSION['detect_login']);

if (!isset($_SESSION['detect_login'])) {
    header("location: ../online/customer_login");
    exit();
} else {
    $id = $_SESSION['id'];
    // echo $id;
    // get all the varible from the database for personal information 
    include('../includes/cus-info.php');

    include('../includes/dash-header.php');

    // now i have to check if he canceled out on the codes 

}

?>

<body><?php include('../includes/side-nav.php');
        ?><div class="main-content" id="panel">
        <?php include('../includes/top-nav.php');

        ?><div class="header pb-4">
            <div class="container-fluid">
                <div class="header-body"></div>
            </div>
        </div>

        <div class="header pb-6 d-flex align-items-center" style="min-height: 300px; background-image: url(../asset/images/shutterstock_1145329577-scaled.jpg); background-size: cover; background-position: center top;">
            Mask <span class="mask bg-gradient-default opacity-4"></span>
        </div>
        <div class="container-fluid mt--6">
            <div class="content-wrapper">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card bg-white">
                            <div class="card-body">
                                <div class="">
                                    <h3 class="">Bank Transfer</h3>
                                    <p>
                                        <marquee direction="left">Be sure to verify details before executing transfer !</marquee>
                                    </p>
                                </div><br />
                                <div class='row'>
                                    <div class='col-6'><a href="other_bank_dom" class="btn btn-primary btn-lg active w-100" role="button" aria-pressed="true"><i class="ni ni-air-baloon"></i>Domestic Transfer</a></div>
                                    <div class='col-6'><a href="other_bank" class="btn btn-success btn-lg active w-100" role="button" aria-pressed="true"><i class="ni ni-planet"></i>International Transfer</a></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card">
                    <div class="card-header header-elements-inline">
                        <h2 class="mb-0 text-center">Domestic Funds Transfer </h2>
                        <div class="header-elements">
                            <div class="list-icons"></div>
                        </div>
                    </div>
                    <div class="card-body">
                        <form method="POST" id="modal-details"><input type="hidden" name="_token" value="49hYQTXTsdaFOzisXtoK8nPzgIIXDezzuR">
                            <div class="form-group row">
                                <div class="col-lg-12"><input type="text" class="form-control" style='text-align: center' value='<?php echo $account_no; ?> ($<?php echo number_format($avaliable_balance, 2) ?>)' readonly></div>
                            </div>
                            <div class="form-group row"><label class="col-form-label col-lg-2">Beneficiary Names</label>
                                <div class="col-lg-10"><input type="text" name="name" id='accountName' class="form-control" required="" Placeholder='Beneficiary Names'></div>
                            </div>
                            <div class="form-group row"><label class="col-form-label col-lg-2">Beneficiary Account</label>
                                <div class="col-lg-10">
                                    <div class="input-group"><span class="input-group-prepend"><span class="input-group-text">#</span></span><input type="alphanumeric" name="acct_nu" maxlength="100" class="form-control" required="" placeholder="Beneficiary Account Number"></div>
                                </div>
                            </div>
                            <div class="form-group row"><label class="col-form-label col-lg-2">Bank name</label>
                                <div class="col-lg-10"><input type="text" name="bank" class="form-control" required="" placeholder="Bank name"></div>
                            </div>
                            <div class="form-group row"><label class="col-form-label col-lg-2">Bank address</label>
                                <div class="col-lg-10"><input type="text" name="address" class="form-control" required="" placeholder="Bank Address"></div>
                            </div>
                            <div class="form-group row"><label class="col-form-label col-lg-2">Receiver`s Email</label>
                                <div class="col-lg-10"><input type="email" name="b_email" class="form-control" required="" placeholder="Receiver Email"></div>
                            </div>
                            <div class="form-group row"><label class="col-form-label col-lg-2">Amount</label>
                                <div class="col-lg-10">
                                    <div class="input-group"><span class="input-group-prepend"><span class="input-group-text">$</span></span><input type="number" class="form-control" name="amount" id="test_over" placeholder="0000.00" required=""></div>
                                </div>
                            </div>
                            <div class="form-group row"><label class="col-form-label col-lg-2">Narrative/Purpose of Transfer</label>
                                <div class="col-lg-10"><textarea name="desc" class="form-control" rows="4" required=""></textarea></div>
                            </div>
                            <div class="text-right"><a href="#" data-toggle="modal" data-target="#modal-form" class="btn btn-primary">Transfer<i class="icon-paperplane ml-2"></i></a></div>
                            <style>
                                .noteInput {
                                    border: none;
                                }
                            </style>
                            <div class="modal fade" id="modal-form" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
                                <div class="modal-dialog modal- modal-dialog-centered modal-sm" role="document">
                                    <div class="modal-content">
                                        <div class="modal-body p-0">
                                            <div class="card bg-white border-0 mb-0">
                                                <div class="card-header bg-transparent pb-2ß">
                                                    <h5 class='text-center'>Enter Pin</h5>
                                                    <div class="text-center text-dark"><i class="ni ni-key-25 icon-2x"></i></div>
                                                </div>
                                                <div class="card-body px-lg-5 py-lg-5">
                                                    <div class="form-group">
                                                        <div class="input-group input-group-merge input-group-alternative">
                                                            <div class="input-group-prepend"><span class="input-group-text"><i class="ni ni-lock-circle-open text-dark"></i></span></div><input class="form-control" placeholder="pin" type="password" name="pin">
                                                        </div>
                                                    </div>
                                                    <div class="text-right"><button type="submit" name='transfer_submit' class="btn btn-primary" form="modal-details">Submit</button></div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <footer class="footer pt-0"></footer>
    </div>
    </div><?php include('../includes/dash_footer.php') ?>
</body><?php function swal_success()
        {
            echo "
<script>$(document).ready(function() {
            Swal.fire( {
                    title: 'Success',
                    text: 'Success! IMF Code Correct',
                    icon: 'success',
                    showCancelButton: false,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Continue'
                }

            ).then((result)=> {
                    if (result.isConfirmed) {
                        window.location.replace('other_bank2');
                    }
                }

            )
        }

    );
    // this is the end of the swal jquery in the php function page 
    </script>";
        }

        function swal_error($msg)
        {

            echo "
<script>$(document).ready(function() {
            Swal.fire( {
                    icon: 'error',
                    title: 'Oops...',
                    text: '" . $msg . "',
                }

            )
        }

    );
    </script>";
        }



        if (isset($_POST['transfer_submit'])) {


            $name_bene = $db_conx->real_escape_string($_POST['name']);
            $account_bene = $db_conx->real_escape_string($_POST['acct_nu']);
            $swift_code = $swift;
            $name_bank = $db_conx->real_escape_string($_POST['bank']);
            $address = $db_conx->real_escape_string($_POST['address']);
            $b_email = $db_conx->real_escape_string($_POST['b_email']);
            $trans_amount = $db_conx->real_escape_string($_POST['amount']);
            $b_country = 'USA';
            $pin = $db_conx->real_escape_string($_POST['pin']);
            $description = $db_conx->real_escape_string($_POST['desc']);


            // now we have to check if the amount entered is greater than what he has on the account 

            if (empty($name_bene) || empty($account_bene) || empty($swift_code) || empty($name_bank) || empty($b_email) || empty($b_country)) {
                $msg = ' Fill all fields';
                swal_error($msg);
            } elseif ($trans_amount > $avaliable_balance) {
                $msg = 'Insufficient balance';
                swal_error($msg);
            } elseif ($pin != $otp_code) {
                $msg = 'Invalid Pin';
                swal_error($msg);
            } elseif ($swift_code != $swift) {
                $msg = 'Invalid Swift Code';
                swal_error($msg);
            } else {



                $transaction_id = rand(1, 100099999);

                $new_amount = $avaliable_balance - $trans_amount;
                $_SESSION['name_bene'] = $name_bene;
                $_SESSION['account_bene'] = $account_bene;
                $_SESSION['swift_code'] = $swift_code;
                $_SESSION['name_bank'] = $name_bank;
                $_SESSION['address'] = $address;
                $_SESSION['b_email'] = $b_email;
                $_SESSION['trans_amount'] = $trans_amount;
                $_SESSION['b_country'] = $b_country;
                $_SESSION['pin'] = $pin;
                $_SESSION['description'] = $description;
                $_SESSION['new_amount'] = $new_amount;
                $_SESSION['transaction_id'] = $transaction_id;
                $_SESSION['transaction_type'] = 'Domestic';



                // i need to check if withdraw is active
                if ($withdraw_active == 1) {

                    if ($tc_active == 1) {
                        header("location:other_bank2");
                    } else {
                        header("location:other_bank7");
                    }
                } else {
                    header("location:unable");
                }
            }
        }



        ?>

</html>
<script type="text/javascript">
    $('.preloader').fadeOut(1000);
</script><?php ob_end_flush();
            ?>