<?php 
    include 'header.php';

    if (isset($_POST['approve'])) {

        $email = trim($_POST['email']);
        $query = mysqli_query($link, "SELECT * FROM kyc WHERE email = '$email' ");
        if (mysqli_num_rows($query) > 0) {
            $row = mysqli_fetch_assoc($query);
    
            $query = "UPDATE users SET status ='Verified' WHERE email = '$email' ";
            $run = mysqli_query($link, $query);
            if ($run == true) {
                $run = mysqli_query($link, "UPDATE kyc SET status = 'Verified'   WHERE email = '$email' ");

                echo "<script> 
                    alert('kyc approved');
                    </script>";
            } else {
                echo "<script> 
                    alert('Failed To rejected');
                    </script>";
            }
        }
    
    
    }


    if (isset($_POST['reject'])) {
   
        $email = trim($_POST['email']);
        $query = mysqli_query($link, "SELECT * FROM users WHERE email = '$email' ");
        if (mysqli_num_rows($query) > 0) {
            $row = mysqli_fetch_assoc($query);
    
            $query = "UPDATE kyc SET status='rejected' WHERE email = '$email' ";
            $run = mysqli_query($con, $query);
            if ($run == true) {
    
                echo "<script> 
                    alert('KYC Rejected');
                    </script>";
            } else {
                echo "<script> 
                    alert('Failed To rejected');
                    </script>";
            }
        }
    
    
    }
    


 
 ?>

<!-- Card start -->
     <div class="card">
                  <div class="card-header">
                    <div class="card-title"></div>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table id="scrollVertical" class="table custom-table">
                        <thead>
                          <tr>
                            <th>#</th>
                            <th>Document Type</th>
                            <th>Document Image</th>
                            <th>Date Submited</th>
                            <th>Action</th>
                          </tr>
                        </thead>
                        <tbody>
                 <?php
                      $i = 0;
                        $select = mysqli_query($link, "SELECT * FROM  kyc WHERE status = 'Unverified'  ");
                          if (mysqli_num_rows($select) > 0) {
                            while ($row = mysqli_fetch_assoc($select)) {
                              $id = $row ['id'];
                             
                     $i++         
                   ?>  
                          <tr>
                            <td><?php echo $i  ?></td>
                            <td><?php echo $row['document_type']  ?></td>
                            <td><a target="_blank" href="../wallet/upload/<?php echo $row['document_image']  ?>"><img height="80" width="80" src="../wallet/upload/<?php echo $row['document_image']  ?>"></a>
                           </td>	
                            <td><?php echo $row['date']  ?></td>
                            <td>
                             <?php echo $row['status']  ?>
                            </td>

                  <td>
                    <form action="pendingkyc.php" method="POST">
                      <input type="submit" class="btn btn-sm btn-success" name="approve" value="Approve">
                      <input type="submit" class="btn btn-sm btn-danger" name="reject" value="reject">
                      <input type="hidden" name="email" value="<?php echo $row['email'] ?>">

                    </form>
                  </td>
                            
                        
                       

                          
                     
                        </tr>
                    
                      <?php }} ?>
                      </tbody>
                  </table>
              </div>
          </div>
      </div>
  </div>
<?php
    include 'footer.php';
?>