<?php

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

$funds = $db_handle->runBaseQuery("SELECT * FROM account_funding WHERE status = 'PENDING' ORDER BY id DESC");

$date = date("d-m-Y h:i:sa");

$msg ="";
if (isset($_GET['confirm'])) {
    
    $paymentID = $_GET['confirm'];
    $userIDforPayment = $_GET['user'];
    
    
    
    
        
       $upd =  $db_handle->update("UPDATE account_funding SET status = 1 WHERE id= ?", "i",array($paymentID));

       if($upd){
           
        $url  = "fundings?page=fundings";
        echo '<META HTTP-EQUIV="refresh" content="3; URL='.$url.'">';  
        $msg = "<div class='alert alert-success text-center'> Payment verified successfully</div>";
        # code...
       }
        
    }

if(isset($_GET['decline'])){
    $id = $_GET['decline'];
    
    
    
    
    $upd =  $db_handle->update("UPDATE account_funding SET status = 2 WHERE id= ?", "i",array($id));
    $url  = "fundings?page=fundings";
    echo '<META HTTP-EQUIV="refresh" content="3; URL='.$url.'">';  
    $msg = "<div class='alert alert-success text-center'> Deposit has been declined.</div>";
}


 ?>
 <div class="main-content app-content">
    <div class="container-fluid">
<div class="row mt-3">
            <div class="col-xl-12">
                <div class="card custom-card">
                    <div class="card-header justify-content-between border-bottom-0">
                        <div class="card-title"> Your Transactions </div>
                        
                    </div>
                    <div class="card-body p-3">
                        <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">Amount</th>
                                       
                                        <th scope="col">Status</th>
                                        <th scope="col">Date</th>
                                        
                                        <th scope="col">View Proof</th>
                                        <th scope="col">Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                        if($funds){
                                            
                                            $i = 1;
                                            foreach($funds as $fund){
                                                $userID = $fund['userID'];

                                                    $user = $db_handle->runBaseQuery("SELECT * FROM users WHERE id = $userID");

                                                    $name = $user[0]['first_name']." ".$user[0]['surname'];
                                                    
                                                     if($fund['status'] == 0){
                                                $status = "PENDING";
                                            }elseif($fund['status'] == 1){
                                                $status = "APPROVED";
                                            }else{
                                                $status = "DECLINED";

                                            }
                                                
                                   echo "<tr>";
                                   echo '<td> <span class="fw-medium">'.$i.'</span> </td>';
                                       
                                        
                                        echo '<td> <span class="fw-medium">'.$name.'</span> </td>';
                                        echo '<td class="fw-medium">₦'.number_format($fund['amount']).'</td>';
                                       
                                       
                                       echo '<td> <span class="">'.$status.'</span> </td>';
                                        echo '<td> <span class="">'.$fund['date'].'</span> </td>';
                                        echo "<td class='tdSpace'>";
                                  
                                    
                                    echo "<a href=". "fundings?view=". $fund['id'] ."&page=fundings> ";
                                    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 Info</button>";
                                    echo "</a>";
                                    echo "</td>";
                                    
                                        
                                         echo "<td class='tdSpace'>";
                                    echo "<a href=". "fundings?confirm=". $fund['id'] ."&user=".$userID."&page=fundings>";
                                    echo "<button class='bg-secondary text-white' style='font-size:0.85em;padding:5px 30px 2px 30px;outline:none;border:none'>";
                                    echo "<i class='fa fa-check-circle'></i> Confirm</button>";
                                    echo "</a>";
                                    echo " ";
                                    echo "<a href=". "fundings?decline=". $fund['id']."&page=fundings>";
                                    echo "<button class='bg-danger text-white' style='font-size:0.85em;padding:5px 30px 2px 30px;outline:none;border:none'>";
                                    echo "<i class='fa fa-times-circle'></i> Decline</button>";
                                    echo "</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 account_funding WHERE id = '$chk' ");
            
    $pic = "../proofs/".$row[0]['proof'];
   
    $amount = $row[0]['amount'];
        
?>


<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'/>";     
            ?>
            
            <h5 class="hashIDDisplay">
                <?php  echo "Amount Deposited: "."$". number_format($amount);?>
                
            </h2>
        </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 = "fundings?page=fundings";
        }
    </script>
  
 