<?php 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');
}
?>
<style>
    img {
        max-width: 100%;
        max-height: 100%;
    }
</style>
<!-- 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 -->
        <br>
        <br>


        <div class="container-fluid mt--6">
            <div class="content-wrapper">
                <div class="row">
                    <div class="col-md-8">
                        <div class="card">
                            <div class="card-header header-elements-inline">
                                <h3 class="mb-0">Upload proof</h3>
                                <div class="header-elements">
                                </div>
                            </div>
                            <div class="card-body">
                                <form method="post" enctype="multipart/form-data">
                                    <input type="hidden" name="_token" value="FEASRkcTKbUx4Cghv3Hw4OIXq2LTHkCPKNYM8pCp">
                                    <div class="form-group row">
                                        <div class="col-lg-12">
                                            <div class="input-group">
                                                <span class="input-group-prepend">
                                                    <span class="input-group-text">$</span>
                                                </span>
                                                <input type="number" step="any" name="amount" max-length="10" class="form-control" placeholder="amount">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-lg-12">
                                            <textarea type="text" class="form-control" rows="3" placeholder="Details" name="details" required=""></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="custom-file">
                                            <input type="file" class="custom-file-input" id="customFileLang1" name="file" lang="en">
                                            <label class="custom-file-label" for="customFileLang1">Transfer proof</label>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <div class="text-right">
                                                    <button type="submit" name='b_submit' class="btn btn-primary">Proceed</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <?php

                    $sql_details4 = 'SELECT * FROM pay_details WHERE id =  4';
                    $query_details4 = $db_conx->query($sql_details4);
                    $row_PD4 = mysqli_fetch_assoc($query_details4);
                    $details_p1 = $row_PD4['details1'];
                    $details_p2 = $row_PD4['details2'];
                    $details_p3 = $row_PD4['details3'];
                    $details_p4 = $row_PD4['details4'];
                    $details_p5 = $row_PD4['details5'];
                    $details_p6 = $row_PD4['details6'];
                    $PD_status_p = $row_PD4['status'];
                    $PD_image_p = $row_PD4['image'];


                    ?>
                    <div class="col-md-4">
                        <div class="card bg-white">
                            <div class="card-body">
                                <div class="d-sm-flex align-item-sm-center flex-sm-nowrap">
                                    <div>
                                        <h3 class="card-title mb-3 text-primary"><?= $details_p1 ?> Details </h3>
                                        <div class="text-center col-6">
                                            <img src="../a/pay_image/<?= $PD_image_p ?>" class="rounded" alt="<?php echo $sitename ?>">
                                        </div>
                                        <br />
                                        <ul class="list list-unstyled mb-0 text-dark">
                                            <li>Name: <?= $details_p1 ?></li>
                                            <li>Wallet/ID: <?= $details_p2 ?></li>

                                        </ul>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                </div>


                <!-- footer begin -->
                <footer class="footer pt-0">

                </footer>
            </div>
        </div>
    </div>

    <!-- Argon Scripts -->
    <!-- Core -->
    <script src="../asset/dashboard/vendor/jquery/dist/jquery.min.js"></script>
    <script src="../asset/dashboard/vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="../asset/dashboard/vendor/js-cookie/js.cookie.js"></script>
    <script src="../asset/dashboard/vendor/jquery.scrollbar/jquery.scrollbar.min.js"></script>
    <script src="../asset/dashboard/vendor/jquery-scroll-lock/dist/jquery-scrollLock.min.js"></script>
    <!-- Optional JS -->
    <script src="../asset/dashboard/vendor/chart.js/dist/Chart.min.js"></script>
    <script src="../asset/dashboard/vendor/chart.js/dist/Chart.extension.js"></script>
    <script src="../asset/dashboard/vendor/jvectormap-next/jquery-jvectormap.min.js"></script>
    <script src="../asset/dashboard/js/vendor/jvectormap/jquery-jvectormap-world-mill.js"></script>
    <script src="../asset/dashboard/vendor/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="../asset/dashboard/vendor/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
    <script src="../asset/dashboard/vendor/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="../asset/dashboard/vendor/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js"></script>
    <script src="../asset/dashboard/vendor/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="../asset/dashboard/vendor/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="../asset/dashboard/vendor/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="../asset/dashboard/vendor/datatables.net-select/js/dataTables.select.min.js"></script>
    <script src="../asset/dashboard/vendor/clipboard/dist/clipboard.min.js"></script>
    <script src="../asset/dashboard/vendor/select2/dist/js/select2.min.js"></script>
    <script src="../asset/dashboard/vendor/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <script src="../asset/dashboard/vendor/nouislider/distribute/nouislider.min.js"></script>
    <script src="../asset/dashboard/vendor/quill/dist/quill.min.js"></script>
    <script src="../asset/dashboard/vendor/dropzone/dist/min/dropzone.min.js"></script>
    <script src="../asset/dashboard/vendor/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
    <!-- Argon JS -->
    <script src="../asset/dashboard/js/argon9f1e.js?v=1.1.0"></script>
    <!-- Demo JS - remove this in your project -->
    <script src="../asset/dashboard/js/demo.min.js"></script>
    <script src="../asset/js/sweetalert.js"></script>
    <script src="../asset/js/googl-translate.js"></script>

    <script src="../asset/js/sweetalert.js"></script>

    <script>
        $(document).ready(function() {

            // Swal.fire({
            //     title: 'Success',
            //     text: '" . $msg . "',
            //     icon: 'success',
            //     showCancelButton: false,
            //     confirmButtonColor: '#3085d6',
            //     cancelButtonColor: '#d33',
            //     confirmButtonText: 'Continue'
            // }).then((result) => {
            //     if (result.isConfirmed) {
            //         window.location.replace('".$link."');
            //     }
            // });

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




    <?php




    function swal_success()
    {
        echo "
                                        <script> 
                                            $(document).ready(function(){
                                            Swal.fire({
                                                title: 'Success',
                                                text: 'Success! Your transaction was successful',
                                                icon: 'success',
                                                showCancelButton: false,
                                                confirmButtonColor: '#3085d6',
                                                cancelButtonColor: '#d33',
                                                confirmButtonText: 'Generate receipt'
                                            }).then((result) => {
                                                if (result.isConfirmed) {
                                                window.location.replace('receipt_bank.php');
                                                }
                                            })

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




        $amount = $db_conx->real_escape_string($_POST['amount']);
        $details = $db_conx->real_escape_string($_POST['details']);
        $amount = $db_conx->real_escape_string($_POST['amount']);
        $method = 'PayPal';
        $charge = 3;


        // collecting the passport uploaded 
        $files = $_FILES['file'];

        // this code is for the file 
        $fileName = $files['name'];
        $fileTmpName = $files['tmp_name'];
        $fileSize = $files['size'];
        $fileError = $files['error'];
        $fileType = $files['type'];

        $permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

        $rand_val =  substr(str_shuffle($permitted_chars), 0, 15);

        $fileExt = explode('.', $fileName);
        $fileActualExt = strtolower(end($fileExt)); //the end get the last peice of data in an array 

        //creating an array of the information we want to allow 
        $allowed = array('jpg', 'jpeg', 'png', 'pdf');

        if (in_array($fileActualExt, $allowed)) {
            if ($fileError === 0) {
                if ($fileSize < 2000000000) {
                    // main upload file code 
                    // we have to rename it so that it will not have same name for different images
                    $fileNameNew =  $rand_val . "." . $fileActualExt;
                    $fileDestination = 'proof/' . $fileNameNew;
                    //main upload code
                    move_uploaded_file($fileTmpName, $fileDestination);
                }
            }
        } //end if for in_array

        $_SESSION['amount'] = $amount;
        $_SESSION['details'] = $details;
        $_SESSION['charge'] = $charge;
        $_SESSION['method'] = $method;


        // now we will put it into the admin 
        $sql_b = "INSERT INTO deposit_logs(user_id,ref_id,amount,method,status,charge,date_created,last_updated,details,proof) VALUES('$id','$rand_val','$amount','$method',0,'$charge','$current_time','$current_time','$details','$fileNameNew')";
        $result_b = $db_conx->query($sql_b);

        swal_success();
    }

    ?>

</body>


<!-- -->

</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>