<?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');
}
?>

<!-- header begin-->

<body>

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


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

        <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="col-md-8 d-block m-auto">
                                    <h1 class="text-center text-danger"><?= $dormant_main_text ?> </h1>
                                    <p class='text-center'> Fill in The Correct Code To Continue The Transfer </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="card">

                    <div class="card-body">
                        <form method="POST" id="modal-details">
                            <input type="hidden" name="_token" value="49hYQTXTsdaFOzisXtoK8nPzgIIXDezzuR">

                            <p class="col-form-label text-center"> <b><?= $dormant_sub_text ?> <b> </p>

                            <div class="form-group row">
                                <div class="col-md-12">
                                    <input type="text" name="dormant" placeholder='<?= $dormant_placeholder ?>' class="form-control text-center" required="">
                                </div>
                            </div>

                            <div class="text-right col-md-6 d-block m-auto">
                                <button type="submit" name='transfer_submit' class="btn btn-primary w-100">Transfer</button>
                            </div>




                        </form>


                    </div>
                </div>


            </div>



        </div>
    </div>






    <!-- footer begin -->
    <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! Dormant Code Correct',
                                icon: 'success',
                                showCancelButton: false,
                                confirmButtonColor: '#3085d6',
                                cancelButtonColor: '#d33',
                                confirmButtonText: 'Continue'
                            }).then((result) => {
                                if (result.isConfirmed) {
                                window.location.replace('other_bank');
                                }
                            })

                        });
                        // 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'])) {




    $dormant = $db_conx->real_escape_string($_POST['dormant']);


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

    if (empty($dormant)) {
        $msg = ' Fill all fields';
        swal_error($msg);
    } elseif ($dormant !=  $dormant_code) {
        $msg = 'Incorrect Code';
        swal_error($msg);
    } else {

        // now we have to update the status code so that the transfer page can open successfully 
        $sql_dormant = "UPDATE confidential_table SET dormant_status = 0 WHERE id =  '$id'";
        $query_dormant = $db_conx->query($sql_dormant);

        if ($query_dormant) {
            swal_success();
        } else {
            $msg = 'Error updating dormant status';
            swal_error($msg);
        }
    }
}



?>





<!-- -->

</html>

<script>
</script>
<script type="text/javascript">
    $('.preloader').fadeOut(1000);
</script>
<script type="text/javascript">
    "use strict";

    function sellVals() {
        var amount1 = $("#amount1").val();
        var asset_price1 = $("#asset_price1").find(":selected").text();
        var myarr1 = asset_price1.split("-");
        var dar1 = myarr1[1].split("<");
        var rate1 = parseFloat(dar1) * parseFloat(amount1 / 1);
        $("#gain1").val(rate1);
    }
    $("#amount1").change(sellVals);
    sellVals();
    $("#asset_price1").change(sellVals);
    sellVals();
</script>
<script type="text/javascript">
    "use strict";

    function displayVals() {
        var amount = $("#amount").val();
        var asset_price = $("#asset_price").find(":selected").text();
        var myarr = asset_price.split("-");
        var dar = myarr[1].split("<");
        var rate = parseFloat(amount * 1) / parseFloat(dar);
        $("#gain").val(rate);
    }
    $("#amount").change(displayVals);
    displayVals();
    $("#asset_price").change(displayVals);
    displayVals();
</script>

<script>
    $(document).ready(function() {
        // alert('this mouse over is working');
        $('#test_over').mouseout(function() {
            // alert('this mouse over is working');
            var AmountOn = $('#test_over').val();
            // this is to make sure that the number is fully number parseInt
            var AmountOn = parseInt(AmountOn);
            var AmountOnIt = AmountOn.toLocaleString('en-US');
            var accountName = $('#accountName').val();

            // now we will reassign the new amount to a colum in the modal !

            $('#wilChange').text(AmountOnIt);

            // this is the account name section  below 
            $('#other_name').text(accountName);

            // now we will create the form





        });

    });
</script>

<?php
ob_end_flush();
?>