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

    $updateCode = $_GET['updateCode'];
    if ($updateCode == 'true') {
        $msg = 'Codes Successfully Changed';
        $link = 'edit_info.php?userID=' . $user_id;
        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">Edit Info </h4>

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

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



                        <div class="row">
                            <div class="col-lg-12">
                                <div class="card">
                                    <div class="card-body">
                                        <div class="row">
                                            <div class="col-sm order-2 order-sm-1">
                                                <div class="d-flex align-items-start mt-3 mt-sm-0">
                                                    <div class="flex-shrink-0">
                                                        <div class="avatar-xl me-3">
                                                            <?php

                                                            if (empty($passport_photo)) {

                                                            ?>
                                                                <img src="p3.jpg" alt="" class="img-fluid rounded-circle d-block">
                                                            <?php  } else {
                                                            ?>

                                                                <img src="<?php echo 'photo/' . $passport_photo ?>" alt="" class="img-fluid rounded-circle d-block">

                                                            <?php

                                                            } ?>

                                                        </div>
                                                    </div>
                                                    <div class="flex-grow-1">
                                                        <div>
                                                            <h5 class="font-size-16 mb-1"><?php echo $tracking_code  ?> </h5>
                                                            <p class="text-muted font-size-13"> Tracking Code</p>


                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-auto order-1 order-sm-2">
                                                <div class="d-flex align-items-start justify-content-end gap-2">
                                                    <a href='client_dashboard.php?userID=<?php echo $user_id ?>'>
                                                        <button type="button" class="btn btn-primary"><i class="me-1"></i> <i class="fas fa-chevron-left "></i> Return to details </button>
                                                    </a>

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

                                        <ul class="nav nav-tabs-custom card-header-tabs border-top mt-4" id="pills-tab" role="tablist">
                                            <li class="nav-item">
                                                <a class="nav-link px-3 active" data-bs-toggle="tab" href="#overview" role="tab">Edit Information Section</a>
                                            </li>

                                        </ul>
                                    </div>
                                    <!-- end card body -->
                                </div>
                                <!-- end card -->
                            </div>
                            <!-- end col -->
                        </div>
                        <!-- end row -->

                        <div class="card">

                            <div class="card-body p-4">

                                <div class="row">
                                    <form method="POST" autocomplete="off" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
                                        <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" value='<?php echo $tracking_code ?>' type="text" name="new_tracking_code">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Final Decision Date </label>
                                                    <input class="form-control" value='<?php echo $final_decision_date ?>' type="text" name="new_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" value='<?php echo $principal_applicant ?>' type="text" name="new_principal_applicant">
                                                </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">UCI</label>
                                                    <input class="form-control" value='<?php echo $uci ?>' type="text" name="new_uci">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Application Number</label>
                                                    <input class="form-control" value='<?php echo $application_number ?>' type="text" name="new_application_number">
                                                </div>

                                            </div>

                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Date Received</label>
                                                    <input class="form-control" value='<?php echo $date_received ?>' type="text" name="new_date_received">
                                                </div>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Biometrics Number</label>
                                                    <input class="form-control" value='<?php echo $biometrics_number ?>' type="text" name="new_biometrics_number">
                                                </div>



                                            </div>

                                            <!-- end each row -->

                                            <div class='row mb-3'>


                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Date Biometrics Enrolment</label>
                                                    <input class="form-control" value='<?php echo $date_biometrics_enrolment ?>' type="text" name="new_date_biometrics_enrolment">
                                                </div>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Expiry Date </label>
                                                    <input class="form-control" value='<?php echo $expiry_date ?>' type="text" name="new_expiry_date">
                                                </div>

                                            </div>

                                            <!-- this is the work visa area -->
                                            <!-- end each row -->
                                            <div class='row mb-3'>
                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Detail Status</label>
                                                    <input class="form-control" value='<?php echo $details_status ?>' type="text" name="new_details_status">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Review of Eligibility</label>
                                                    <input class="form-control" value='<?php echo $review_of_eligibility ?>' type="text" name="new_review_of_eligibility">
                                                </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"> Review of Medical</label>
                                                    <input class="form-control" value='<?php echo $review_of_medical ?>' type="text" name="new_review_of_medical">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Review of Additional Document</label>
                                                    <input class="form-control" value='<?php echo $review_of_additoinal_doc ?>' type="text" p name="new_review_of_additoinal_doc">
                                                </div>

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

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Biometrics</label>
                                                    <input class="form-control" value='<?php echo $biometrics ?>' type="text" name="new_biometrics">
                                                </div>

                                            </div>
                                            <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" value='<?php echo $background_check ?>' type="text" name="new_background_check">
                                                </div>

                                                <div class="col-md-6">
                                                    <label for="example-search-input" class="form-label"> Final Decision</label>
                                                    <input class="form-control" value='<?php echo $final_decision ?>' type="text" name="new_final_decision">
                                                </div>


                                                <input class="form-control" value='<?php echo $user_id ?>' type="text" name="user_id" style='display:none'>

                                            </div>




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

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


                                        </div>
                                    </form>

                                    <br />


                                    <?php
                                    extract($_POST);
                                    if (isset($_POST['submit'])) {


                                        //--------------------------------------possibility----------------------------



                                        $sql_trans_update = "UPDATE clients SET 
                                                tracking_code = '$new_tracking_code',
                                                final_decision_date = '$new_final_decision_date',
                                                principal_applicant = '$new_principal_applicant',
                                                uci = '$new_uci',
                                                application_number = '$new_application_number',
                                                date_received = '$new_date_received',
                                                biometrics_number = '$new_biometrics_number',
                                                date_biometrics_enrolment ='$new_date_biometrics_enrolment',
                                                expiry_date = '$new_expiry_date',
                                                details_status = '$new_details_status',
                                                review_of_eligibility = '$new_review_of_eligibility',
                                                review_of_medical = '$new_review_of_medical',
                                                review_of_additoinal_doc = '$new_review_of_additoinal_doc',
                                                interview = '$new_interview',
                                                biometrics = '$new_biometrics',
                                                background_check = '$new_background_check',
                                                final_decision = '$new_final_decision'
                                                WHERE id = '$user_id' ";

                                        $query_trans_pos = $db_conx->query($sql_trans_update);



                                        if ($query_trans_pos) {
                                            header('location:edit_info.php?updateCode=true&userID=' . $user_id);
                                        } 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();

?>