<?php
include('header.php');
if ($_SESSION['usertype'] != "ADMIN") {
    ?>
        <script>
            window.location.href = 'index.php';
        </script>
        <?php

        
        die;
    }
    

if (isset($_GET['userid']) && $_GET['userid'] != NULL) {
    $id = base64_decode($_GET['userid']);
    $res = mysqli_query($conn, "SELECT * FROM `usertable` WHERE userid='$id'");
    $data = mysqli_fetch_assoc($res);
}


if (isset($_POST['ahkweb'])  && $_POST['ahkweb'] == "ahkwebsolutions") {
    $name = mysqli_real_escape_string($conn,$_POST['name']);
    $email = mysqli_real_escape_string($conn,$_POST['email']);
    $status = mysqli_real_escape_string($conn,$_POST['status']);
    $userid = mysqli_real_escape_string($conn,$_POST['userid']);
    $city = mysqli_real_escape_string($conn,$_POST['city']);
    $state = mysqli_real_escape_string($conn,$_POST['state']);
    $phone = mysqli_real_escape_string($conn, $_POST['phone']);
    $walletamount = mysqli_real_escape_string($conn,$_POST['walletamount']);
    $birth_fee = mysqli_real_escape_string($conn,$_POST['birth_fee']);
    $death_fee = mysqli_real_escape_string($conn,$_POST['death_fee']);
    $b_fee = mysqli_real_escape_string($conn,$_POST['b_fee']);
    $pfee = mysqli_real_escape_string($conn,$_POST['pfee']);
    $pdffee = mysqli_real_escape_string($conn,$_POST['pdffee']);
    $e_pdf_fee = mysqli_real_escape_string($conn,$_POST['e_pdf_fee']);
    $fullnamefee = mysqli_real_escape_string($conn,$_POST['fullnamefee']);
    $usertype = mysqli_real_escape_string($conn,$_POST['usertype']);

    $username = $_SESSION['phone'];
    $ires = mysqli_query($conn,"UPDATE `usertable` SET `name`='$name', `emailid`='$email', phone='$phone', `walletamount`='$walletamount',`state`='$state',`city`='$city',`userid`='$userid',`status`='$status',`birth_fee`='$birth_fee',`death_fee`='$death_fee',`b_fee`='$b_fee',`pfee`='$pfee',`pdffee`='$pdffee',`e_pdf_fee`='$e_pdf_fee', `fullnamefee`='$fullnamefee', `usertype`='$usertype' WHERE userid='$id' ");    

    if($ires){
        ?>
        <script>
            $(function(){
                Swal.fire(
                    'Success',
                    'User Updated Successfully',
                    'success'
                )
            });
            window.setTimeout(function() {
  window.location.href = "userlist.php";
  }, 1500);
        </script>
        <?php
    }else{
        ?>
        <script>
            $(function(){
                Swal.fire(
                    'Opps',
                    'Internal Server Error Please try Agin Later',
                    'error'
                )
            });
        </script>
        <?php
    }
}
?>


<!-- HTML content for the wallet history page -->
<div class="content-wrapper">
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">Edit User Information</h3>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">
                        <!-- form start -->
                        <form method="post" action="" autocomplete="off" enctype="multipart/form-data">
                            <input type="hidden" name="_token" value="1TDde6CMH369W5RCLWCgTOjV8fR50kKPMlAfDgjN"> <input type="hidden" name="_method" value="PUT">
                            <input type="hidden" name="ahkweb" value="ahkwebsolutions">
                            <div class="card-body row">
                                
                            
                               
                                <div class="form-group col-md-3">
                                    <label for="name">Full Name <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="name" name="name" placeholder="FULL NAME" value="<?php echo $data['name'] ?>" required="">
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="walletamount">Wallet Balance</label>
                                    <input type="text" class="form-control" id="walletamount" name="walletamount" placeholder="walletamount" value="<?php echo $data['walletamount'] ?>">
                                </div>      

                                <div class="form-group col-md-3">
                                    <label for="death_address">User Type<span class="text-danger">*</span></label>
                                    <select class="form-control" name="usertype" id="">
                                        <option  value="">Select Usertype</option>
                                        <option <?php if($data['usertype'] == 'OPERATOR'){ echo 'selected';} ?> value="OPERATOR">OPERATOR</option>
                                        <option <?php if($data['usertype'] == 'ADMIN2'){ echo 'selected';} ?> value="ADMIN2">DISTRIBUTOR</option>
                                        <option <?php if($data['usertype'] == 'MOBILEOPERATOR'){ echo 'selected';} ?> value="MOBILEOPERATOR">MOBILE OPERATOR</option>
                                        <option <?php if($data['usertype'] == 'ADDRESSOPERATOR'){ echo 'selected';} ?> value="ADDRESSOPERATOR">ADDRESS OPERATOR</option>
                                        <option <?php if($data['usertype'] == 'CHILDOPERATOR'){ echo 'selected';} ?> value="CHILDOPERATOR">CHILD OPERATOR</option>
                                        <option <?php if($data['usertype'] == 'NAMEOPERATOR'){ echo 'selected';} ?> value="NAMEOPERATOR">NAME OPERATOR</option>
                                        <option <?php if($data['usertype'] == 'DOBOPERATOR'){ echo 'selected';} ?> value="DOBOPERATOR">DOB OPERATOR</option>
                                    </select>
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="status">Status<span class="text-danger">*</span></label>
                                    <select class="form-control" name="status" id="">
                                        <option  value="">Select status</option>
                                        <option <?php if($data['status'] == 'verified'){ echo 'selected';} ?> value="verified">ACTIVE</option>
                                        <option <?php if($data['status'] == 'unverified'){ echo 'selected';} ?> value="unverified">BLOCK</option>
                                    </select>
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="email">Email<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="email" name="email" placeholder="email" value="<?php echo $data['emailid'] ?>"required="">
                                </div>

                                <div class="form-group col-md-3">
                                    <label for="phone">Mobile No.<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="phone" name="phone" placeholder="phone" value="<?php echo $data['phone'] ?>"required="">
                                </div>

                                <div class="form-group col-md-3">
                                    <label for="userid">User Id<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="userid" name="userid" placeholder="userid" value="<?php echo $data['userid'] ?>">
                                
                                </div>

                                <div class="form-group col-md-3">
                                    <label for="state">State<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="state" name="state" placeholder="state" value="<?php echo $data['state'] ?>"required="">
                                </div>   

                            <!--    <div class="form-group col-md-3">
                                    <label for="city">City<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="city" name="city" placeholder="city" value="<?php echo $data['city'] ?>"required="">
                                </div>    -->
                                <div class="form-group col-md-3">
                                    <label for="birth_fee">Child Rate<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="birth_fee" name="birth_fee" placeholder="birth_fee" value="<?php echo $data['birth_fee'] ?>"required="">
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="death_fee">Mobile Rate<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="death_fee" name="death_fee" placeholder="death_fee" value="<?php echo $data['death_fee'] ?>"required="">
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="b_fee">Address Rate<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="b_fee" name="b_fee" placeholder="b_fee" value="<?php echo $data['b_fee'] ?>"required="">
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="pdffee">Name Rate<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="pdffee" name="pdffee" placeholder="pdffee" value="<?php echo $data['pdffee'] ?>"required="">
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="pfee">Dob rate<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="pfee" name="pfee" placeholder="pfee" value="<?php echo $data['pfee'] ?>"required="">
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="e_pdf_fee">Pdf rate<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="e_pdf_fee" name="e_pdf_fee" placeholder="e_pdf_fee" value="<?php echo $data['e_pdf_fee'] ?>"required="">
                                </div>
                                <div class="form-group col-md-3">
                                    <label for="fullnamefee">Full Name rate<span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="fullnamefee" name="fullnamefee" placeholder="fullnamefee" value="<?php echo $data['fullnamefee'] ?>"required="">
                                </div>
                                
                                

                              

                            </div>
                            <!-- /.card-body -->

                            <div class="card-footer text-right pt-3 pb-3 mt-2">
                                <button type="submit" class="btn btn-primary btn-lg">Update</button>
                            </div>
                        </form>
                   </div>
                        <!-- /.card-body -->
                    </div>
                    <!-- /.card -->
                </div>
            </div>

        </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->


</div>
<!-- /.content-wrapper -->

<!-- <footer class="main-footer">
    <strong>Copyright &copy; 2014-2021 <a href="https://adminlte.io">AdminLTE.io</a>.</strong>
    All rights reserved.
    <div class="float-right d-none d-sm-inline-block">
      <b>Version</b> 3.1.0
    </div>
  </footer> -->

<!-- Control Sidebar -->
<!-- <aside class="control-sidebar control-sidebar-dark"> -->
<!-- Control sidebar content goes here -->
<!-- </aside> -->
<!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="../logout.php">Logout</a>
                </div>
            </div>
        </div>
    </div>
<script>
$(document).ready(function() {
            $('#table_id').DataTable({

                dom: 'Bfrtip',
                responsive: true,
                pageLength: 25,
                // lengthMenu: [0, 5, 10, 20, 50, 100, 200, 500],

                buttons: [
                    'copy', 'csv', 'excel', 'pdf', 'print'
                ]

            });
        });
</script>
<!-- jQuery -->
<script src="plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- Select2 -->
<script src="plugins/select2/js/select2.full.min.js"></script>

<!-- SweetAlert -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.all.min.js"></script>

<!-- DataTables  & Plugins -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>

<script src="plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="plugins/datatables-buttons/js/buttons.colVis.min.js"></script>

<!-- ChartJS -->
<script src="plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="plugins/moment/moment.min.js"></script>
<script src="plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="dist/js/pages/dashboard.js"></script>

<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js" integrity="sha512-37T7leoNS06R80c8Ulq7cdCDU5MNQBwlYoy1TX/WUsLFC2eYNqtKlV0QjH7r8JpG/S0GUMZwebnVFLPd6SU5yg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.js" integrity="sha512-zlWWyZq71UMApAjih4WkaRpikgY9Bz1oXIW5G0fED4vk14JjGlQ1UmkGM392jEULP8jbNMiwLWdM8Z87Hu88Fw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<script>
    function alertMessage(type, message) {
        if (type == 'error') {
            type = 'danger';
        }

        return "<div class='alert alert-" + type + " alert-dismissible'> <a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a> " + message + " </div>";
    }
</script>

<script>
    $(function() {
        $('#example2').DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true,
            "autoWidth": false,
            "responsive": true,
        });
    });

    function deleteRecord(th) {
        Swal.fire({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            icon: 'warning',
            showCancelButton: true,
            showConfirmButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
            if (result.value == 1) {
                $(th).parent().submit();
            }
        });
    }
</script>

</body>

</html>