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

<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>
        <br>
        <br>
        <!-- header end -->

        <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="">Customer support</h3>
                                    <a data-toggle="modal" data-target="#modal-formx" href="#" class="btn btn-sm btn-neutral"><i class="fa fa-arrow-right"></i> Create request</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="modal fade" id="modal-formx" tabindex="-1" role="dialog" aria-labelledby="modal-form" aria-hidden="true">
                            <div class="modal-dialog modal- modal-dialog-centered modal-lg" role="document">
                                <div class="modal-content">
                                    <div class="modal-body p-0">
                                        <div class="card bg-white border-0 mb-0">
                                            <div class="card-body px-lg-5 py-lg-5">
                                                <form method="post">
                                                    <input type="hidden" name="_token" value="49hYQTXTIsbhw5u0UFOzisXtoK8nPzgIIXDezzuR">
                                                    <div class="form-group row">
                                                        <label class="col-form-label col-lg-2">Subject</label>
                                                        <div class="col-lg-10">
                                                            <div class="input-group input-group-merge">
                                                                <input type="text" name="subject" maxlength="10" class="form-control" required="">
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label class="col-form-label col-lg-2">Priority</label>
                                                        <div class="col-lg-10">
                                                            <select class="form-control select" name="priority" data-dropdown-css-class="bg-slate-800" data-fouc required>
                                                                <option value="Low">Low</option>
                                                                <option value="Medium">Medium</option>
                                                                <option value="High">High</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label class="col-form-label col-lg-2">Details</label>
                                                        <div class="col-lg-10">
                                                            <textarea name="details" class="form-control" rows="4" required></textarea>
                                                        </div>
                                                    </div>
                                                    <div class="text-right">
                                                        <button type="submit" name='b_submit' class="btn btn-primary">Submit</button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                </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! Your transaction was successful',
                                                icon: 'success',
                                                showCancelButton: false,
                                                confirmButtonColor: '#3085d6',
                                                cancelButtonColor: '#d33',
                                                confirmButtonText: 'Continue'
                                            }).then((result) => {
                                                if (result.isConfirmed) {
                                                window.location.replace('ticket.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'])) {



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

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



    // collecting the passport uploaded 



    // now we need to check the amount the user inserted if it is above the account balance 

    $sql_withdraw24 = "INSERT INTO ticket(user_id,subject,priority,details,date) VALUES('$id','$subject','$priority','$details','$current_time')";
    $result_b24 = $db_conx->query($sql_withdraw24);
    if ($result_b24) {
        $sql_withdraw24 = "INSERT INTO ticket(user_id,amount,charges,details,method,ref,date) VALUES('$id','$amount','$charge','$details','$method','$ref','$current_time')";
        $result_b24 = $db_conx->query($sql_withdraw24);

        swal_success();
    } else {
        $msg = 'an error has occur';
        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>