<?php require('header.php');?>
<style>
    span{
        color:blue;
    }
</style>
<?php
//Direct Transfer   
     if ($_SERVER["REQUEST_METHOD"]=="POST") {

$receiver_acct = mysqli_real_escape_string($db,$_POST["b_acct_number"]);
$amount = mysqli_real_escape_string($db, $_POST["direct_amt"]);
$pin = mysqli_real_escape_string($db,$_POST["transaction_pin"]);


$cpass =  mysqli_fetch_array(mysqli_query($db,"SELECT pin FROM user WHERE accountnumber='".$accountnumber."'"));

$cpas =  mysqli_fetch_array(mysqli_query($db,"SELECT accountnumber, wallet, firstname, lastname FROM user WHERE accountnumber='".$receiver_acct."'"));

//Check if the pin matches
if ($cpass[0]!=$pin){$err1=1;}

//Check if the beneficiary account matches
if ($cpas[0]!=$receiver_acct){$err2=1;}


$error = $err1+$err2;


if ($error == 0){
    
if($wallet < $amount){

$msg="<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>
<b>Insufficient Fund.</b>
<br>You have only &#36;$wallet left in your account.

</div>";


}

if($wallet >= $amount){ 

$description = "Direct Transfer Of &#36;$amount To $receiver_acct $cpas[2] $cpas[3]";
$descriptionn = "$accountnumber $firstname $lastname Transffered &#36;$amount To You";
$newbal = $wallet - $amount;
$newball = $cpas[1] + $amount;

$res = mysqli_query($db,"UPDATE user SET wallet='".$newbal."' WHERE accountnumber='".$accountnumber."'");
$res = mysqli_query($db,"UPDATE user SET wallet='".$newball."' WHERE accountnumber='".$receiver_acct."'");
 
 mysqli_query($db,"INSERT INTO transaction SET accountnumber='".$accountnumber."', amount='".$amount."', prebalance='".$wallet."', postbalance='".$newbal."', status='Successful', ref='".$trx."', date='".$date."', time='".$time."', description='".$description."', sig='-'");
 
  mysqli_query($db,"INSERT INTO transaction SET accountnumber='".$receiver_acct."', amount='".$amount."', prebalance='".$cpas[1]."', postbalance='".$newball."', status='Successful', ref='".$trx."', date='".$date."', time='".$time."', description='".$descriptionn."', sig='+'");
 
$msg =  '<div class="alert alert-success" role="alert"><b style="word-spacing:5px;"><img style="width=:20px;height:20px;" src="assets/images/icosucces.png"> &nbsp; You Have Successfully Transferred <span>&#36;'.$amount.'</span> To '.$receiver_acct.' '.$cpas[2] .' '.$cpas[3].'!. </b>
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button></div>'

;

}
}else {

if ($err1 == 1){
$msg =  "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	

Your Transaction Pin Is Incorrect.

</div>";
}
if ($err2 == 1){
$msg =  "<div class=\"alert alert-danger alert-dismissable\">
<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>	

$receiver_acct is not registered with us

</div>";
}
}
}
//End Of Direct Transfer  

?> 


        <!-- partial -->
        <div class="main-panel">
          <div class="content-wrapper">
            <div class="page-header">
              <h3 class="page-title"> DIRECT TRANSFER</h3>
              <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                  <li class="breadcrumb-item active" aria-current="page">Direct Fund Transfer</li>
                </ol>
              </nav>
            </div>
            <div class="row">

            
              <div class="col-12 grid-margin">
                <div class="card">
                  <div class="card-body">
                    <h4 class="card-title">Details</h4>
                    <br>
                    
<?php echo $msg;?>
                    <form class="form-sample" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST" name="form" onsubmit="return Traficate()">
                    
                      <!--<p class="card-description"> Address </p>-->

                      <div class="row">
                        
                    
                        <div class="col-md-6">
                          <div class="form-group row">
                            <label class="col-sm-3 col-form-label">Beneficiary Account</label>
                            <div class="col-sm-9">
                              <input type="text" name="b_acct_number" class="form-control" required/>
                            </div>
                          </div>
                        </div>
                  
 <div class="col-md-6">
                          <div class="form-group row">
                            <label class="col-sm-3 col-form-label">Amount</label>
                            <div class="col-sm-9">
                              <input type="text" name="direct_amt" class="form-control" required>
                            </div>
                          </div>
                        </div>
                      </div>
                      
                                            <div class="row">
                        
                    
                        <div class="col-md-6">
                          <div class="form-group row">
                            <label class="col-sm-3 col-form-label">Transaction Pin</label>
                            <div class="col-sm-9">
                              <input type="text" name="transaction_pin" class="form-control" required/>
                            </div>
                          </div>
                        </div>
                  
 
                      </div>

                      <br>
                       <div class="input-group-append">
<button type="submit" class="button-86" id="verify" role="button">Submit</button>
                        </div>
                    </form>
                  </div>
                </div>
              </div>
              
            </div>
          </div>
          <style>
            

/* CSS */
.button-86 {
  all: unset;
  width: 100px;
  height: 30px;
  font-size: 16px;
  background: transparent;
  border: none;
  position: relative;
  color: #f0f0f0;
  cursor: pointer;
  z-index: 1;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.button-86::after,
.button-86::before {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  z-index: -99999;
  transition: all .4s;
}

.button-86::before {
  transform: translate(0%, 0%);
  width: 100%;
  height: 100%;
  background: #28282d;
  border-radius: 10px;
}

.button-86::after {
  transform: translate(10px, 10px);
  width: 35px;
  height: 35px;
  background: #ffffff15;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border-radius: 50px;
}

.button-86:hover::before {
  transform: translate(5%, 20%);
  width: 110%;
  height: 110%;
}

.button-86:hover::after {
  border-radius: 10px;
  transform: translate(0, 0);
  width: 100%;
  height: 100%;
}

.button-86:active::after {
  transition: 0s;
  transform: translate(0, 5%);
}
          </style>
          <!-- content-wrapper ends -->
          <!-- partial:../../partials/_footer.html -->
          
            <script>
function Traficate(){


        $("#verify").html("Processing...");
        return true;
        
    }
    
</script>
<?php require('footer.php');?>
