<?php
ob_start();
include('../include/db_conx.php');
isset($_SESSION['admin_login']);
if (!isset($_SESSION['admin_login'])) {
    header("location: auth-login.php");
    exit();
} else {
    include('../include/admin_head.php');

    include('../include/admin_action/info.php');

    $success = $_GET['success'];
    if ($success == 'true') {
        $msg = 'Visa Registered Successfully';
        $link = 'add_visa.php';
        swal_success($msg, $link);
    }
?>



    <body>

        <!-- <body data-layout="horizontal"> -->

        <!-- Begin page -->
        <div id="layout-wrapper">

            <?php include('../include/admin_header.php'); ?>

            <!-- ========== Left Sidebar Start ========== -->

            <!-- Left Sidebar End -->
            <?php include('../include/admin_sidebar.php'); ?>



            <!-- ============================================================== -->
            <!-- Start right Content here -->
            <!-- ============================================================== -->
            <div class="main-content">

                <div class="page-content">
                    <div class="container-fluid">

                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                                    <h4 class="mb-sm-0 font-size-18">Add new visa below </h4>

                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="javascript: void(0);">Visa</a></li>
                                            <li class="breadcrumb-item active">Visa Creation</li>
                                        </ol>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <!-- end page title -->




                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title"> Kindly fill all input to complete Creation</h4>
                            </div>
                            <div class="card-body p-4">

                                <div class="row">
                                    <form method="POST" autocomplete="off" enctype="multipart/form-data">
                                        <div class="col-lg-12 d-block m-auto">


                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Tracking Code</label>
                                                    <input class="form-control" type="text" name="tracking_code">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Final Decision Date</label>
                                                    <input class="form-control" type="text" name="final_decision_date">
                                                </div>

                                            </div>

                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Principal Applicant</label>
                                                    <input class="form-control" type="text" name="principal_applicant">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">UCI</label>
                                                    <input class="form-control" type="text" name="uci">
                                                </div>

                                            </div>

                                            <!-- end each row -->


                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Application Number</label>
                                                    <input class="form-control" type="text" name="application_number">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Date Received</label>
                                                    <input class="form-control" type="text" name="date_received">
                                                </div>

                                            </div>

                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Biometrics Number</label>
                                                    <input class="form-control" type="text" name="biometrics_number">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Date of Biometrics Enrolment</label>
                                                    <input class="form-control" type="text" name="date_biometrics_enrolment">
                                                </div>

                                            </div>

                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Expiry Date</label>
                                                    <input class="form-control" type="text" name="expiry_date">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Detail Status</label>
                                                    <input class="form-control" type="text" name="details_status">
                                                </div>

                                            </div>

                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Review Of Eligibility</label>
                                                    <input class="form-control" type="text" name="review_of_eligibility">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Review of Medical</label>
                                                    <input class="form-control" type="text" name="review_of_medical">
                                                </div>

                                            </div>

                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Review of Additional Document</label>
                                                    <input class="form-control" type="text" name="review_of_additoinal_doc">
                                                </div>


                                            </div>

                                            <!-- end each row -->



                                            <!-- end each row -->

                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label">Interview </label>
                                                    <input class="form-control" type="text" name="interview">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Biometrics </label>
                                                    <input class="form-control" type="text" name="biometrics">
                                                </div>

                                            </div>

                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Background Check</label>
                                                    <input class="form-control" type="text" name="background_check">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Final Decision</label>
                                                    <input class="form-control" type="text" name="final_decision">
                                                </div>

                                            </div>

                                            <!--  -->


                                            <!-- end each row -->




                                            <div class="md-6">
                                                <!-- just a break -->
                                            </div>

                                            <button type="submit" class="btn btn-primary" name="submit">Click Here to create Visa <i class="fas fa-chart-line"></i></button>


                                        </div>
                                    </form>

                                    <?php
                                    if (isset($_POST['submit'])) {
                                        $tracking_code = $db_conx->real_escape_string($_POST['tracking_code']);
                                        $final_decision_date = $db_conx->real_escape_string($_POST['final_decision_date']);
                                        $principal_applicant = $db_conx->real_escape_string($_POST['principal_applicant']);
                                        $uci = $db_conx->real_escape_string($_POST['uci']);
                                        $application_number = $db_conx->real_escape_string($_POST['application_number']);
                                        $date_received = $db_conx->real_escape_string($_POST['date_received']);
                                        $biometrics_number = $db_conx->real_escape_string($_POST['biometrics_number']);
                                        $date_biometrics_enrolment = $db_conx->real_escape_string($_POST['date_biometrics_enrolment']);
                                        $expiry_date = $db_conx->real_escape_string($_POST['expiry_date']);
                                        $details_status = $db_conx->real_escape_string($_POST['details_status']);
                                        $review_of_eligibility = $db_conx->real_escape_string($_POST['review_of_eligibility']);
                                        $review_of_medical = $db_conx->real_escape_string($_POST['review_of_medical']);
                                        $review_of_additoinal_doc = $db_conx->real_escape_string($_POST['review_of_additoinal_doc']);
                                        $interview = $db_conx->real_escape_string($_POST['interview']);
                                        $biometrics = $db_conx->real_escape_string($_POST['biometrics']);
                                        $background_check = $db_conx->real_escape_string($_POST['background_check']);
                                        $final_decision = $db_conx->real_escape_string($_POST['final_decision']);



                                        $pname = rand(10000, 100000000);





                                        // now i will make sure that the code is not duplicated  
                                        $sql_code = "SELECT * FROM clients WHERE tracking_code = '$tracking_code'";
                                        $query_code = $db_conx->query($sql_code);
                                        $code_check = mysqli_num_rows($query_code);
                                        if ($code_check > 0) {
                                            swal_error('Tracking Code Duplicate');
                                        } else {


                                            // creating a visa record
                                            $sql_test = "INSERT INTO clients(tracking_code,final_decision_date,principal_applicant,uci,application_number,date_received,biometrics_number,date_biometrics_enrolment,expiry_date,details_status,review_of_eligibility,review_of_medical,review_of_additoinal_doc,interview,biometrics,background_check,final_decision,date_created)
                                            VALUES('$tracking_code','$final_decision_date','$principal_applicant','$uci','$application_number','$date_received','$biometrics_number','$date_biometrics_enrolment','$expiry_date','$details_status','$review_of_eligibility','$review_of_medical','$review_of_additoinal_doc','$interview','$biometrics','$background_check','$final_decision','$today')";


                                            $result = $db_conx->query($sql_test);
                                            if ($result) {
                                                header('location:add_visa.php?success=true');
                                                // echo 'success 1';
                                            } else {
                                                echo 'An error has occurred please contact admin';
                                            }
                                        }
                                    }

                                    ?>


                                </div>
                                <!-- end row -->
                            </div>
                        </div>



                    </div> <!-- container-fluid -->
                </div>
                <!-- End Page-content -->


                <?php include('../include/admin_footer.php'); ?>
            </div>
            <!-- end main content-->

        </div>
        <!-- END layout-wrapper -->




        <!-- Right bar overlay-->
        <div class="rightbar-overlay"></div>

        <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
        <script src="assets/libs/metismenu/metisMenu.min.js"></script>
        <script src="assets/libs/simplebar/simplebar.min.js"></script>
        <script src="assets/libs/node-waves/waves.min.js"></script>
        <script src="assets/libs/feather-icons/feather.min.js"></script>
        <!-- pace js -->
        <script src="assets/libs/pace-js/pace.min.js"></script>

        <!-- flatpickr js -->
        <script src="assets/libs/flatpickr/flatpickr.min.js"></script>

        <!-- Required datatable js -->
        <script src="assets/libs/datatables.net/js/jquery.dataTables.min.js"></script>
        <script src="assets/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>

        <!-- Responsive examples -->
        <script src="assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
        <script src="assets/libs/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js"></script>

        <!-- init js -->
        <script src="assets/js/pages/invoices-list.init.js"></script>

        <script src="assets/js/app.js"></script>
    </body>

    </html>

<?php  }
ob_end_flush();
?>