<?php 
session_start();
require('db.php'); 
include('inc/func.php');
include('inc/logo.php');
?> 
<?php include('inc/header.php');?>
        <!-- ============================================================== -->
        <!-- end navbar -->
        <!-- ============================================================== -->
      
        <!-- ============================================================== -->
        <!-- left sidebar -->
        <!-- ============================================================== -->
        <?php include('inc/nav.php');?>
        <!-- ============================================================== -->
        <!-- end left sidebar -->
        <!-- ============================================================== -->
        <!-- ============================================================== -->
        <!-- wrapper  -->
        <!-- ============================================================== -->
        <div class="dashboard-wrapper">
            <div class="dashboard-ecommerce">
                <div class="container-fluid dashboard-content ">
                    <!-- ============================================================== -->
               
                    <!-- pageheader  -->
                    <!-- ============================================================== -->
                   <div class="row">
                        <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                            <div class="page-header">
                                <h2 class="pageheader-title"><li class="fas fa-fw fa-money-bill-alt"></li> Credit Wallet </h2>
                        
                            </div>
                        </div>
                    </div>
                    <!-- ============================================================== -->
                    <!-- end pageheader  -->
                    <!-- ============================================================== -->
                    <div class="ecommerce-widget">

                        <div class="row"></div>
                        <div class="row">
                            <!-- ============================================================== -->
                      
                            <!-- ============================================================== -->

                                          <!-- recent orders  -->
                            <!-- ============================================================== -->
                            <div class="col-xl-9 col-lg-12 col-md-6 col-sm-12 col-12">
                            
                                <div class="card">
                                          
                                    <h5 class="card-header"></h5>
                                    <div class="card-body">
                                     <?php
                                    
                                   
					if(isset($_GET['reff'])){
								       echo'<div class="alert alert-success">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Transaction Successful</strong>  
									</div>'; 
									
									echo '<script>
									setTimeout(function(){ window.location.href="dashboard.php" }, 5000);</script>';
									
					}elseif(isset($_GET['funded'])){
								       echo'<div class="alert alert-success">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Transaction Successful and wallet Funded</strong>  
									</div>'; 
									
									echo '<script>
									setTimeout(function(){ window.location.href="dashboard.php" }, 5000);</script>';
									
					}elseif(isset($_GET['fail'])){
								       echo'<div class="alert alert-danger">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Transaction Failed</strong>  
									</div>'; 
									
									echo '<script>
									setTimeout(function(){ window.location.href="dashboard.php" }, 5000);</script>';					
					   
										
									      
								        }		
						

					$servName = $_SERVER['HTTP_HOST'];
									
									if(isset($_POST['topup'])){
										
										$username = $_SESSION['user'];
										
										$amount = $_POST['amount'];
										$meth = $_POST['method'];
										
$amount = filter_var($amount, FILTER_SANITIZE_STRING);
$meth = filter_var($meth, FILTER_SANITIZE_STRING);

$username = mysqli_real_escape_string ($conn, $username);
$amount = mysqli_real_escape_string ($conn, $amount);
$meth = mysqli_real_escape_string ($conn, $meth);
$xamount = str_replace( array( '+', ',', '-', '/', '(', ')',  "'", '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $amount);


										
if(!empty($xamount) && !empty($meth) ){


if($amount >= 100 ){											
								
											$token = uniqid();
											$stat = "Pending";
											$pro = "Wallet Funding";
											
										      
                                                                                        
    $uid = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $uid);
$amount = str_replace( array( '+', ',', '-', '/', '(', ')',   '_', '//', 'drop', 'update', 'delete', 'insert', 'add',  '{',   '}',   '<',  '>',  '=', ' ', '  ', '   '), '', $amount);

$_SESSION['ref'] = $uid; 




$sql = mysqli_query($conn,"INSERT into deposit (ref,refer,amount,charge,user,email,status,token,method,service,feebearer,balanceB,balanceA,action,del,today,month,date,dateTime) VALUES ('$uid','$token','$xamount','$comm','$fname $lname','$username','$stat','$token','$meth','$pro','$feebearer','$bal','$bal','$action','$del','$today','$month','$date','$dateTime')") or die(mysqli_error());
								
								
							$request_dir = $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);	
							
								
								

$query_pay = mysqli_query($conn,"SELECT * FROM payment");
$apipay = mysqli_fetch_array($query_pay);

if($meth === 'Card'){
    
$Paymethod = "Card"; 

// payprocessor
if($apipay['activepay'] === 'paystack'){



}elseif($apipay['activepay'] === 'flutterwave'){
    
    
}elseif($apipay['activepay'] === 'GETPAY'){
include('inc/GetPay.php');

}else{
 
   
echo '<div class="alert alert-warning">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Dear User, There was an Error initiating your wallet funding through Card. <br>
Please Contact the Site Administrator or try again later.<br> 
Thank You.<br> THE ADMIN TEAM</strong> <br>
<a href="buy_credit.php">Click here to Try Again or use other payment methods.</a> </div>'; 
    
}


						
}



     
if($meth === 'Transfer'){
         
$Paymethod = "Transfer";   
include('inc/GetPay.php');

}
                                        

// }elseif($meth === 'cash'){
     
if($meth === 'Manual'){       
     
   
	 
echo '<div class="card-body border-top">
                                            
                                             <div class="alert alert-primary" role="alert">
                                      		<h4 class="alert-heading">ADMIN PAYMENT DETAILS</h4>
                                               <p> To fund your wallet,
                                               Kindly pay &#x20A6;'.$xamount.' into any of our bank accounts below through bank deposit/transfer, online transfer, mobile app transfer etc.</p>
                                                <hr>
                                                <p class="mb-0"><strong>Account Name:</strong> '.$bank['AccName'].' <br>
                                                
                                            <strong>Account Number:</strong> '.$bank['AccNo'].' <br>    
                                               
                                               <strong>Bank Name:</strong> '.$bank['BankName'].' <br> 

<hr>
                                            <strong>Account Name:</strong> '.$bank['AccName2'].' <br>
                                                
                                            <strong>Account Number:</strong> '.$bank['AccNo2'].' <br>    
                                               
                                               <strong>Bank Name:</strong> '.$bank['BankName2'].' <br> 
<hr>
                                              <strong>Account Name:</strong> '.$bank['AccName3'].' <br>
                                                
                                            <strong>Account Number:</strong> '.$bank['AccNo3'].' <br>    
                                               
                                               <strong>Bank Name:</strong> '.$bank['BankName3'].' <br> 
                                                </p>
                                                <hr>
                                                <p class="mb-0">After payment is made, send depositor name, amount paid and your email address on '.$settings['sitename'].' to '.$settings['mobile'].' or <a href="paynotify.php"><font color="red">Click here.</font></a> to fill and submit a payment notification Form. <br>
                                                Your wallet will be credited once payment is confirmed.<br> Thank you!
                                            </p>
                                            </div>
                                        </div>'; 

	 
	 }
                                        
                                
 if($meth === 'Airtime'){
                                    
                 ?> <script>
setTimeout(function(){ window.location.href='airtime2cash.php?amount=<?php echo $xamount;?>' }, 100);</script>
   <?php                       
                                    
                                }        
                                        
								
  
}else{
										echo'<div class="alert alert-danger">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>The Minimum Funding amount is N100</strong>  
									</div>'; }
									
										    
										    
										}else{
										echo'<div class="alert alert-danger">
										<button type="button" class="close" data-dismiss="alert">×</button>
										<strong>Enter amount</strong>  
									</div>'; }
									}
									
									 ?>
                       



 <div class="card-body">
                                    
                                        <form method="post" action="">
                                           
                                      <h5>Enter Amount <font color="red">(Min &#x20A6;100)</font></h5>
                                  <div class="input-group mb-3">
                                                <div class="input-group-prepend"><span class="input-group-text">&#x20A6;</span></div>
                                                <input type="text" class="form-control"onKeyUp="javascript:this.value=CommaZ(this.value);" id="amount" name="amount" min="100" required>
                                                <div class="input-group-append"><span class="input-group-text">.00</span></div>
                                            </div>
                                        
                                        <h5>How do you want to pay?</h5>
                                            <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" checked name="method" id="method-card" class="custom-control-input" value="Card" onclick="javascript:yesnoCheck();" id="yescard"><span class="custom-control-label">ATM Card</span>
                                            </label>
                                            
                                             <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="method" id="method-bank" class="custom-control-input"value="Transfer" onclick="javascript:yesnoCheck();" id="yesbank" ><span class="custom-control-label" >Bank Transfer</span>
                                            </label>
                                            
											
                                            <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="method" id="method-cash" class="custom-control-input"value="Manual" onclick="javascript:yesnoCheck();" id="yescash" ><span class="custom-control-label" >Manual Funding</span>
                                            </label>
                                            
                                            <label class="custom-control custom-radio custom-control-inline">
                                                <input type="radio" name="method" id="method-airtime" class="custom-control-input"value="Airtime" onclick="javascript:yesnoCheck();" id="yesairtime"><span class="custom-control-label" >Airtime Transfer</span>
                                            </label>
                                            
                                          
                                         
                                     <div class="col-sm-6 pl-0">
                                         
                                        
                                             
 <p class="text-center">
<button type="submit" name="topup" id="proceed-btn" class="btn btn-space btn-primary">Proceed</button>

 <!--<button type="button" class="btn btn-primary" id="proceed-btn">Proceed</button> -->
                                                    
                                                
                                                   
                                                </p>
                                                
                                                <p align="center">
                                                    
                                                    <img src="assets/images/paystack-secured.png" class="responsive">
                                                    
                                                     </p>
                                               
                                            </div>       </div>  


                                
                             

                                   
                                        

                                        
                                    </div>
                                </div>
                            </div>
                            <!-- ============================================================== -->
                            <!-- end recent orders  -->


<script>
							 
							 function Comma(Num)
 {
       Num += '';
       Num = Num.replace(/,/g, '');

       x = Num.split('.');
       x1 = x[0];

       x2 = x.length > 1 ? '.' + x[1] : '';

       
         var rgx = /(\d)((\d{3}?)+)$/;

       while (rgx.test(x1))

       x1 = x1.replace(rgx, '$1' + ',' + '$2');
     
       return x1 + x2;       
        
 }
 
 
 
 function yesnoCheck() {
    if (document.getElementById('yescard').checked) {
        document.getElementById('ifYes').style.visibility = 'visible';
    }
    
     if (document.getElementById('yescash').checked) {
        document.getElementById('ifYes').style.visibility = 'visible';
    }
    
     if (document.getElementById('yesairtime').checked) {
        document.getElementById('ifYes').style.visibility = 'visible';
    }
    
    

}



                            </script> 
                            <!-- ============================================================== -->
                            <!-- ============================================================== -->
                            <!-- customer acquistion  -->
                            <!-- ============================================================== -->
                              <?php include('inc/nav-right.php');?>    

                            <!-- ============================================================== -->
                            
                            
                            
                            <!-- end customer acquistion  -->
                      <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                        <div class="card">
                            <h5 class="card-header">Wallet Funding History</h5>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-striped table-bordered first">
                                        <thead>
                                            <tr>
                                                <th>Transaction ID</th>
                                                <th>Channel</th>
                                                <th>Amount</th>
                                                <th>Status</th>
                                                <th>Date</th>
                                               
                                            </tr>
                                        </thead>
                                        <tbody>
                                         <?php 
$GetHistory = "SELECT * FROM deposit WHERE email='$user' ORDER BY `date` DESC ";
	 
	 $qryHistory = $conn->query($GetHistory);
										
			 while($row = $qryHistory->fetch_assoc()){ 
										
											?>
                                            <tr>
                                           
                                                <td><?php echo $row['ref']; ?></td>
                                                <td><?php echo $row['method']; ?></td>
                                                <td><?php echo '&#x20A6;'.$row['amount'].' ';?></td>
                                                 <td><?php echo $row['status'];?></td>
                                                <td><?php echo $row['date'];?></td>
                                                
                                            </tr>
                                           
                                           <?php } ?>
                                          
                                           
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                               <th>Transaction ID</th>
                                                <th>Channel</th>
                                                <th>Amount</th>
                                                <th>Status</th>
                                                <th>Date</th>
                                                
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>      
                          
                            <!-- ============================================================== -->
                        </div>
                        <div class="row">
                            <!-- ============================================================== -->
              				                        <!-- product category  -->
                            <!-- ============================================================== -->
                            <!-- ============================================================== -->
                            <!-- end product category  -->

							





    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-Ogqועלxy8I7SINQXmA7PoQvWC+swt9wT7UnfIY6PwE1RLliWEoRNpTBoisNhoovN" crossorigin="anonymous"></script>
  
       <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-Ogqועלxy8I7SINQXmA7PoQvWC+swt9wT7UnfIY6PwE1RLliWEoRNpTBoisNhoovN" crossorigin="anonymous"></script>
    
    
    <script>
        $(document).ready(function() {
            // Handle proceed button click
            $("#proceed-btn").click(function() {
                // Get form values
                //const amount = $("#amount").val();
                
                 const amount = parseFloat($("#amount").val()); // Ensure amount is a number

    // Validate amount (optional)
    if (isNaN(amount) || amount <= 99) {
      alert("Please enter a valid amount starting from N100.");
      return; // Exit function early if validation fails
    }

               
    </script>
    
    
    
                  <!-- product sales  -->
                            <!-- ============================================================== -->
                            <!-- ============================================================== -->
                            <!-- end product sales  -->
                            <!-- ============================================================== -->
                        </div>

                        <div class="row">
                            <!-- ============================================================== -->
                            <!-- sales  -->
                            <!-- ============================================================== -->
                         
                          
                        </div>
                        <div class="row">
                            <!-- ============================================================== -->
                            <!-- total revenue  -->
                            <!-- ============================================================== -->
  
                        </div>
                        <div class="row">
                          <!-- ============================================================== -->
                            <!-- end sales traffice source  -->
                            <!-- ============================================================== -->
                          
                        </div>
                    </div>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
            <?php include('inc/footer.php');?>