<?php

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

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

    $userID = $_GET['user'];
}

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

$balance = $user[0]['balance'];


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

$amount = $db_handle->sanitize($_POST['amount']);

$balance += $amount;

$update = $db_handle->update("update users SET balance = ? WHERE id = ?","si",array($balance,$userID));

if($update){
   

    $msg =  "<div class='alert alert-success text-center'>Account Balance funded successfully.</div>";
        
    }

    }






 ?>
 <div class="main-content app-content">
<div class="container-fluid">
                            
                            <!--Modal: order-modal-->
                          
                                <h5 class="text-uppercase">
        Account Settings</h5>
    <div class="row settings mt-3">
        
        <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">Fund Account</h5>
                                    </div>
                                    <form method="POST"
                                        action=""
                                        enctype="multipart/form-data">
                                        
                                        <?php echo $msg; ?>
                                        <?php echo $csrf->csrfInput(); ?>                                        
                                            
                                            <div class="form-group mb-3">
                                                <label class="form-label">Amount<span
                                                        class="text-danger"> * </span></label>
                                                <input type="text" class="form-control modern-input" name="amount"
                                                    
                                                    placeholder="Amount to Fund" required>

                                            </div>
                                           
                                           
                                                                                        <div class="form-group text-end">
                                                <button
                                                    class="btn btn-secondary  "
                                                     type="submit" name="fund" >Fund</button>
                                            </div>
                                       
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
               



                                                                                                                                                                                                                                                                                                     

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

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