<?php
session_start();
include 'include/config.php';

if(!isset($_SESSION['id'])){
 echo "<script> window.location.href = 'index.php' </script>";
  }
?>

<?php  include 'include/head.php'; ?>
                    
                      <!-- Start Content-->
                      <div class="container-fluid">
                        
                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box">
                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
                                            <li class="breadcrumb-item active">Users</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title"> All Users</h4>
                                </div>
                            </div>
                        </div>
                         <!--end page title -->
                          <div>
                              <!--<a href="add_user.php"  class="btn btn-success"> Add New User</a>-->
                          </div>

                        <div class="row">
                            <div class="col-12">
                                <div class="card">
                                    <div class="card-body">
                                        
                                        <?php
                                        if(isset($_GET['user'])){
                                            $id = $_GET['user'];
                                        
                                            $sql = "DELETE FROM `user` WHERE id='$id'";
                                           // print_r($sql);
                                            if(mysqli_query($conn,$sql)){
                                             echo "<script>alert('Your Data deleted successfully');</script>";
                                            // echo "<script>document.location('user.php');</script>";
                                            echo "<script>window.location.href='user.php';</script>";
                                            }
                                           
                                        }
                                        ?>
                                        <div class="table-responsive">
                                            <div class="tab-pane show active" id="basic-datatable-preview">
                                                <table id="datatable" class="table table-striped dt-responsive nowrap w-100">
                                                    <thead>
                                                        <tr>
                                                            <th>Sr. No.</th>
                                                            <th>User ID</th>
                                                            <th>Name</th>
                                                             <th>Email</th>
                                                             <th>Phone Number</th>
                                                             <th>City</th>
                                                             <th>Pincode</th>
                                                             <th>Image</th>
                                                             <!--<th>Pan Number:</th>-->
                                                             <!--<th>Guarantor Name:</th>-->
                                                             <!--<th>Payment Mode:</th>-->
                                                             <!--<th>Payment Mode Number:</th>-->
                                                             <!--<th>Joining Date:</th>-->
                                                             <!--<th>Joining Month:</th>-->
                                                             <!--<th>Profile Image:</th>-->
                                                             <!--<th>Aadhar Front Image:</th>-->
                                                             <!--<th>Aadhar Back Image:</th>-->
                                                             <!--<th>Pan Card Image:</th>-->
                                                             <!--<th>Electricity Bill Image:</th>-->
                                                             <!--<th>Signature Image:</th>-->
                                                             <!--<th>Rent Agreement Image:</th>-->
                                                             <!--<th>Bank Statment Image:</th>-->
                                                             <!--<th>Pass Book Image:</th>-->
                                                             <!--<th>Bank Account Number:</th>-->
                                                            
                                                            <th>Action</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    <?php
                                                    $sql = "SELECT * FROM `user_details` ORDER BY id DESC";
                                                    $res = mysqli_query($conn, $sql);
                                                    $i = 1;
                                                    while ($row = mysqli_fetch_assoc($res)) {
                                                    ?>
                                                        <tr>
                                                            <td><?= $i; ?></td>
                                                            <td><?= $row['id'] ?></td>
                                                            <td><?= $row['name'] ?></td>
                                                            <td><?= $row['email'] ?></td>
                                                            <td><?= $row['phone'] ?></td>
                                                            <td><?= $row['city'] ?></td>
                                                            <td><?= $row['pincode'] ?></td>
                                                          
                                                            <?php
                                                              $guarantor_id = mysqli_real_escape_string($conn, $row['guarantor_id']);
                                                             // print_r($guarantor_id);
                                                              $select_gur = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM `user_details` WHERE `id`='$guarantor_id'"));
                                                              ?>
                                                            
                                                          
                                                           <td><?= $row['bank_account'] ?></td>
                                                            <td>
                                                                <!--<a href="useredit.php?id=<?=$row['id']?>" class="action-icon"> <i class="mdi mdi-square-edit-outline"></i></a>-->
                                                                <a href="user.php?user=<?= $row['id'] ?>" onclick="return confirm('Are You Sure Want To Delete This?');" class="action-icon"> <i class="mdi mdi-delete"></i></a>

                                                            </td>
                                                         </tr>
                                                        <?php
                                                       $i++;  } 
                                                        ?>
                                                    </tbody>
                                                </table>                                           
                                            </div> <!-- end preview-->
                                        
                                            
                                        </div> <!-- end tab-content-->

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

                    
                    </div> <!-- container -->


<?php  
include 'include/footer.php'; 
?>