<?php

include("includes/header.php"); 
include("includes/sidebar.php");

 

$users = $db_handle->runBaseQuery("SELECT * FROM users ORDER BY id DESC");

 ?>
 <div class="main-content app-content">
 	<div class="container-fluid">
        <?php if (isset($_SESSION['msg-s'])) { ?>
        <div class="alert alert-success alert-dismissible">
                    <button type="button" class="close" data-bs-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-check"></i> Success!</h4> <?php echo $_SESSION['msg-s']; ?>
                </div>
<?php unset($_SESSION['msg-s']); } ?>

<?php if (isset($_SESSION['msg-e'])) { ?>
        <div class="alert alert-danger alert-dismissible" role="alert">
                    <button type="button" class="close" data-bs-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-check"></i> Error!</h4> <?php echo $_SESSION['msg-e']; ?>
                </div>
<?php unset($_SESSION['msg-e']); } ?>
<div class="row mt-3">
            <div class="col-xl-12">
                <div class="card custom-card">
                    
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table text-nowrap table-bordered" id="TableTab">
                                <thead>
                                    <tr>
                                        <th scope="col">#</th>
                                       <th scope="col">Name</th>
                                        <th scope="col">Email</th>
                                        <th scope="col">Account Balance</th>
                                        <th scope="col">Phone Number</th>
                                        <th scope="col">Gender</th>
                                        <th scope="col">BVN</th>
                                        <th scope="col">Identity Type</th>
                                        <th scope="col">Identity Number</th>
                                        <th scope="col">Address</th>
                                        
                                        <th scope="col">Date Registered</th>
                                        <th scope="col">View ID</th>
                                        <th scope="col">Fund</th>
                                        <th scope="col">Action</th>
                                       
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    if($users){
                                        $i = 1;
                                    foreach($users as $user){
                                       
                                   echo "<tr>";
                                    echo '<td class="fw-medium">'.$i.'</td>';
                                    echo '<td class="fw-medium">'.$user['first_name']." ".$user['surname'].'</td>';
                                      echo '<td class="fw-medium">'.$user['email'].'</td>';
                                      echo '<td class="fw-medium">NGN '.number_format($user['balance'],2).'</td>';
                                      echo '<td class="fw-medium">'.$user['phone'].'</td>';
                                      echo '<td class="fw-medium">'.$user['gender'].'</td>';
                                      echo '<td class="fw-medium">'.$user['bvn'].'</td>';
                                      echo '<td class="fw-medium">'.$user['id_type'].'</td>';
                                      
                                      echo '<td class="fw-medium">'.$user['id_number'].'</td>';

                                        echo '<td> <span class="fw-medium">'.$user['address'].'</span></td>';
                                       
                                        
                                        echo '<td> <span class="">'.$user['date_registered'].'</span> </td>';
                                        
                                       echo "<td class='tdSpace'>";
                                  
                                    
                                    echo "<a href=". "users.php?view=". $user['id'] ."> ";
                                    echo "<button  class='bg-primary text-white' data-toggle='' data-target='#staticBackdrop' 
                                        style='font-size:0.85em;padding:5px 30px 2px 30px;outline:none;border:none'>";
                                    echo "<i class='fa fa-eye'></i> View Identity Photo</button>";
                                    echo "</a>";
                                    echo "</td>";
                                    
                                     echo '<td>
                                            <div class="btn-list"> <a href="fund?page=users&user='.$user['id'].'">';
                                            echo "<button  class='bg-primary text-white' style='font-size:0.85em;padding:5px 30px 2px 30px;outline:none;border:none'>";
                                        echo "<i class='fa fa-eye'></i>Fund User</button>";
                                    echo "</a>";
                                    echo "</td>";

                                        echo '<td>
                                            <div class="btn-list"> <a href="edit-user.php?page=users&user='.$user['id'].'"><button class="btn btn-sm btn-icon btn-success-light rounded-circle" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Edit"><i class="ri-pencil-line lh-1 align-middle"></i></button></a> <button class="btn btn-sm btn-icon btn-danger-light rounded-circle" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Delete"><i class="ri-delete-bin-line lh-1 align-middle"></i></button> </div>
                                        </td>';
                                       
                                    echo '</tr>';

                                    $i++;
                                    
                                    }

                                }

                                ?>
                                    
                                   
                                   
                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
 </div>
 <?php

if(isset($_GET['view'])){
    $chk = $_GET['view'];
    
    

    $row = $db_handle->runBaseQuery("SELECT * FROM users WHERE id = '$chk' ");
            
    $pic = "../identification_photos/".$row[0]['id_photo'];
   
    
        
?>


<div class="modal fade" id="staticBackdrop" 
     data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
    <div class="modal-content">
        <div class="modal-header">

            <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="outline:none;" onclick="reload()">
              <i aria-hidden="true" class="fa fa-window-close" style="color:#9e0000"></i>
          </button>
        </div>
        <div class="modal-body">


            <?php 
            
            echo "<img class='img-fluid' src='". $pic. "' alt='img'/>";     
            ?>
            
            
        </div>
        <div class="modal-footer" style="margin-top:30px;">
            
        </div>
    </div>
  </div>
</div>


<?php } ?>
  <?php

include("includes/footer.php"); 
 ?>
 
 <?php 
        if (isset($_GET['view'])) {
            ?>
            <script type='text/javascript'>
                $(function () {
                    $('#staticBackdrop').modal('show');
                });
            </script>
            <?php
        }
    ?>
    
    <script>
        function reload() {
            window.location.href = "users";
        }
    </script>
    