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

$name_bene = $_SESSION['name_bene'];
?>

<!-- header begin-->

<body>

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


        <style>
            @media (min-width: 576px) {
                .modal-sm {
                    max-width: 450px;
                }
            }
        </style>

        <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="">
                                    <h3 class="">Bank Transfer</h3>
                                    <p>
                                        <marquee direction="left">Be sure to verify details before executing transfer!</marquee>
                                    </p>
                                    <?php

                                    if (empty($name_bene)) {
                                        header('location: other_bank?stats=notAvailable');
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>
                    </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: 'Correct Swift code',
                                icon: 'success',
                                showCancelButton: false,
                                confirmButtonColor: '#3085d6',
                                cancelButtonColor: '#d33',
                                confirmButtonText: 'Continue'
                            }).then((result) => {
                                if (result.isConfirmed) {
                                window.location.replace('other_bank3');
                                }
                            })

                        });
                        // 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>
                        ";
}





?>

<?php
if (!isset($_SESSION['current_row'])) {
    $_SESSION['current_row'] = 0; // Start from the first row
}
$current_row = $_SESSION['current_row'];
// Fetch the code for the current row
$query_tc = "SELECT * FROM tc WHERE user_id = '$id' LIMIT 1 OFFSET $current_row ";
$result_tc = $db_conx->query($query_tc);
// Check if the query was successful
if (!$result_tc) {
    die("Query failed: " . $db_conx->error);
}

if ($result_tc->num_rows > 0) {
    $row_tc = $result_tc->fetch_assoc();
    $code_tc = $row_tc['code'];
    $code_details_tc = $row_tc['code_details'];
} else {
    echo "No more codes available.";
    $_SESSION['current_row'] = 0; // Reset to the first row

    header('location:other_bank7?status=true');

    // exit();
}

// echo $code_tc;
echo '<br/>';

if (isset($_POST['submit_nc'])) {
    $input_code = $db_conx->real_escape_string($_POST['code']);

    // echo $input_code;

    if (
        $input_code === $code_tc
    ) {
        // Correct code, move to the next row
        $_SESSION['current_row']++;
        header("Location: " . $_SERVER['PHP_SELF']); // Refresh the page to load the next code
        // exit();
    } else {
        $error_message = "INCORRECT CODE, PLEASE TRY AGAIN.";
        swal_error($error_message);
    }
}



?>

<?php if (isset($error_message)) {
    $msg = $error_message;
    swal_error($msg);
} ?>


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


    <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">
                            <div class="text-dark text-center mt-2 mb-3 ">

                                <h2>
                                    <b class='text-danger'>
                                        <?= $code_details_tc ?>
                                    </b>
                                </h2>
                            </div>
                            <div class="text-center text-dark"><i class="ni ni-key-25 icon-2x"></i></div>
                        </div>
                        <div class="card-body">
                            <div class="form-group">
                                <label class='text-muted text-center w-100'> Fill in the Current Code to Continue</label>

                                <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="Enter code to continue" type="text" name="code">
                                </div>
                            </div>
                            <div class="text-right">
                                <button type="submit" name='submit_nc' class="btn btn-primary" form="modal-details">Continue Transfer</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    $(document).ready(function() {
        $("#modal-form").modal('show');
    });
    $("#modal-form").modal({
        backdrop: 'static',
        keyboard: false
    });
</script>





</html>

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


<?php
ob_end_flush();
?>