<?php 
  $link_status1 = "";
  $link_status2 = "";
  $link_status3 = "active";
  
  include("includes/top-header.php"); 
  
  if(isset($_POST['mp'])){
        $bank = $_POST['bName'];			//beneficiary bank
        $anu = $_POST['accNum'];	//beneficiary account number
        $anm = $_POST['accName'];		//beneficiary account name
        $ammt = $_POST['amount'];		
        $rout = $_POST['rout'];		
        $swf = $_POST['swf'];	
        $rem = $_POST['rem'];	
        $abal_ = $_POST['abal'];	 
        
        $pyee = $_POST['pAcc']; //sender account number
        
        $ssl = "select * from account where aNum='".$pyee."'"; 
        $rs_t =  $conn->query($ssl); //run the query
        while($row = $rs_t->fetch_assoc()) { 
            $ab=$row['aBal'];
            $an=$row['aName'];
            $gotten_sym=$row['symbol'];
            $gotten_cur=$row['currency'];
        }
        
        
        // $_SESSION['b_n'] = $bank; 
        // $_SESSION['a_n'] = $anu; 
        // $_SESSION['reci'] = $anm;

        $t_limit = $abal_ - $ammt;
            
        $datt = date("Y-m-d h:i:s");				
            
        if($t_limit < 50){
            echo "<script>alert('Transaction Error! You have insufficient funds to make this transfer.')</script>";
            echo "<script>window.location='send-money.php?account=".$pyee."';</script>";
        }else{
            $full_narration = "FSB:TRF/".$rem."/".$anu."-".$rout."-".$swf."/via ".$bank;
            
            $sqtr="INSERT INTO trans(memID, tDate, pAccno, amount, narration)values('".$member_id."', '$datt', '$pyee', '$ammt', '".mysqli_real_escape_string($conn, $full_narration)."')";												
            $resultr=mysqli_query($conn,$sqtr);
                                
            if ($resultr) {
                $last_id = mysqli_insert_id($conn);
                    
                $token = chr(rand(97,122))."".rand(1,9)."".chr(rand(97,122))."".rand(1,9)."".rand(11,99);
                $_SESSION['token'] = $token;
                
                echo "<meta http-equiv='refresh' content='120; url=send-money-confirm.php?tid=".$last_id."' >";
            } else {
                echo "<script>alert('Transaction Error! Try again later.')</script>";
                echo "<script>window.location.href = 'send-money.php?account=".$pyee."';</script>";
            }
        }
  }else{
    // header("Location: send-money.php?account=".$pyee."");
  }
  
    if(isset($_GET['tid'])){
        $delete_id=$_GET['tid'];
    
        $deletetrans="delete from trans where tid='$delete_id'";
        $run2 = $conn->query($deletetrans);
    
        unset($_SESSION['b_n']);
        unset($_SESSION['a_n']);
        unset($_SESSION['reci']);
    
        echo "<script>window.location.href = 'send-money.php?account=".$pyee."';</script>";
    	
    }
?>
  
  <!-- Content
  ============================================= -->
  <div id="content" class="py-4">
    <div class="container"> 
      
      <!-- Steps Progress bar -->
      <div class="row mt-4 mb-5">
        <div class="col-lg-11 mx-auto">
        <div class="row widget-steps">
          <div class="col-3 step active">
              <div class="step-name">Account</div>
              <div class="progress">
                <div class="progress-bar"></div>
              </div>
              <a href="#" class="step-dot"></a> </div> 
            <div class="col-3 step active">
              <div class="step-name">Details</div>
              <div class="progress">
                <div class="progress-bar"></div>
              </div>
              <a href="#" class="step-dot"></a> </div>
            <div class="col-3 step active">
              <div class="step-name">Confirm</div>
              <div class="progress">
                <div class="progress-bar"></div>
              </div>
              <a href="#" class="step-dot"></a> </div>
            <div class="col-3 step disabled">
              <div class="step-name">Success</div>
              <div class="progress">
                <div class="progress-bar"></div>
              </div>
              <a href="#" class="step-dot"></a> </div>
          </div>
        </div>
      </div>
      <h2 class="fw-400 text-center mt-3">Transfer Funds</h2>
      <p class="lead text-center mb-4">Confirm your transaction details to complete this transfer</p>
      <div class="row">
        <div class="col-md-9 col-lg-7 col-xl-6 mx-auto">
          <div class="bg-white shadow-sm rounded p-3 pt-sm-4 pb-sm-5 px-sm-5 mb-4">
            <!-- Send Money Confirm
            ============================================= -->
            <form id="form-send-money" method="post">
              <h3 class="text-5 fw-400 mb-3 mb-sm-4">Confirm Details</h3>
              <hr class="mx-n3 mx-sm-n5 mb-4">
              <p class="mb-1">Source Account <span class="text-3 float-end"><?php echo $pyee; ?></span></p>
              <p class="mb-1">Source Account Name<span class="text-3 float-end"><?php echo $an; ?></span></p>
              <p class="mb-1">Beneficiary Account <span class="text-3 float-end"><?php echo $anu; ?></span></p>
              <p class="mb-1">Beneficiary Account Name <span class="text-3 float-end"><?php echo $anm; ?></span></p>
              <p class="mb-1">Bank <span class="text-3 float-end"><?php echo $bank; ?></span></p>
              <p class="mb-1">Narration <span class="text-3 float-end"><?php echo $rem; ?></span></p>
              <hr>
              <p class="text-4 fw-500">Transaction Amount<span class="float-end"><?php echo number_format($ammt, 2); ?> <?php echo $gotten_cur; ?></span></p>
              <div class="d-grid">
                  <a href="processing.php?request=fund_transfer&tid=<?php echo $last_id; ?>" class="btn btn-primary">Continue</a>
                  <br>
                  <a href="send-money-confirm.php?tid=<?php echo $last_id; ?>" class="btn btn-danger">Cancel Transaction</a>
                  <p>
                      <small>This session will expire in 2 mins.</small>
                  </p>
                </div>
            </form>
            <!-- Send Money Confirm end --> 
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- Content end --> 
  
  <!-- Footer
  ============================================= -->
  <?php include("includes/footer.php"); ?>
  <!-- Footer end --> 
  
</div>
<!-- Document Wrapper end --> 

<!-- Back to Top
============================================= --> 
<a id="back-to-top" data-bs-toggle="tooltip" title="Back to Top" href="javascript:void(0)"><i class="fa fa-chevron-up"></i></a> 

<!-- Styles Switcher -->

<!-- Styles Switcher End --> 

<!-- Script --> 
<script src="vendor/jquery/jquery.min.js"></script> 
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script> 
<script src="vendor/bootstrap-select/js/bootstrap-select.min.js"></script> 
<!-- Style Switcher --> 
<script src="js/switcher.min.js"></script> 
<script src="js/theme.js"></script>
</body>
</html>