<?php

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

if(isset($_GET['withdrawal'])){

    $withdrawalID = $_GET['withdrawal'];
}

$withdrawal = $db_handle->runBaseQuery("SELECT * FROM withdrawals WHERE id = $withdrawalID");

if(isset($_POST['update'])){
     if (!isset($_POST['csrf_token']) || !$csrf->validateToken($_POST['csrf_token'])) {
        die("CSRF token validation failed!");
    }
    $status = $db_handle->sanitize($_POST['status']);
    

  
    $update = $db_handle->update("UPDATE withdrawals SET status = ? WHERE id = ?","si",array($status,$withdrawalID));

if($update){

$_SESSION['msg-s'] = "Withdrawal status updated successfully.";
}else{
$_SESSION['msg-e'] = "Could not update withdrawal.";
}
}

 ?>
 <div class="main-content app-content">
<div class="container-fluid">
                            
                            <!--Modal: order-modal-->
                           
                                <h5 class="text-uppercase">
        Edit Admin</h5>
    <div class="row settings mt-3">

        

        <?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="col-xl-12">
            <div id="settingmenuContent">
                
                                <div id="editprofile">
                    <div class="row mb-5">
                        <div class="col-12">
                            <div class="card border-0 box-shadow">
                                <div class="card-body pb-0">
                                    <div class="d-flex align-items-center mb-3">
                                        <h5 class="text-uppercase">Edit Admin</h5>
                                    </div>
                                    <form method="POST"
                                        action=""
                                        enctype="multipart/form-data">
                                        <?php echo $csrf->csrfInput(); ?>                                       <div class="row">
                                           
                                                 
                                    <div class="form-group col-md-12">
                                    <label for="city" class="form-label">Withdrawal Status<span class="text-danger">* </span></label>
                                                    <select name="status" class="form-select" id="role" required>
                        <option value="1" >APPROVED</option>
                        <option value="2" >DECLINED</option>
                        <option value="0" >PENDING</option>
                                                    </select>
                                                </div>
                                                <br>
                                                
                                                                                <div class="form-group text-end">
                                                <button
                                                    class="btn btn-secondary  "
                                                     type="submit" name="update" value="1" >Update Transactions</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
               



                                                                                                                                                                                                                                                                                                    <div id="delete_profile">
                        
                    </div>
                  
                               

            </div>
        </div>
    </div>
    
    
                        </div>
                    </div>
                </div>
  <?php

include("includes/footer.php"); 
 ?>