<?php
include("functions.php");
include("userdata.php");
if (isset($_POST)) {
	$fullname = filterString($_POST['fullname']); 
	$iban = filterString($_POST['iban']);
sleep(3);
if($_POST['accountnumber'] != ""){
if(empty($_SESSION['getbank'])){
	$accountholder = filterString($_POST['accountholder']);  $bankname = filterString($_POST['bankname']);
    if(empty($accountholder)){echo"<script>document.getElementById('accountholder').style.borderColor='red';</script>";
    	    }else{echo"<script>document.getElementById('accountholder').style.borderColor='green'";}
     if(empty($bankname)){echo"<script>document.getElementById('bankname').style.borderColor='red';</script>";
    	    }else{echo"<script>document.getElementById('bankname').style.borderColor='green';</script>";}

    	    if ($accountholder != "" & $bankname != "") {
    	    	$_SESSION['getbank'] = "setted";
    	    	$_SESSION['accountholderB'] = $accountholder; 
    	    	$_SESSION['banknameB'] = $bankname;
    	    }	 	       	    
  }}

     if(empty($fullname)){echo"<script>document.getElementById('fullname').style.borderColor='red';</script>";
    	    }else{echo"<script>document.getElementById('fullname').style.borderColor='green';</script>";}	 	
     if(empty($iban)){echo"<script>document.getElementById('iban').style.borderColor='red';</script>";
    	    }else{echo"<script>document.getElementById('iban').style.borderColor='green';</script>";}
     if(empty($account)){echo"<script>document.getElementById('account').style.borderColor='red';</script>";}
    	    else{echo"<script>document.getElementById('account').style.borderColor='green';</script>";}

     if (empty($fullname) || empty($iban) || empty($_POST['accountnumber'])) {
      	echo "<script>
         Swal.fire('All fields are required!', 'You are required to fill all empty fields', 'error');        
      	</script>";
      	die();
      } 
     $errorMsg = 0; 

    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo"<script>
    document.getElementById('email').style.borderColor='green';
    </script>";} else {
     $errorMsg = 1;	
    echo"<script>toastr.error('Valid email address is required', 'Invalid email address', {'progressBar': true});
    document.getElementById('email').style.borderColor='red';
    </script>";
    }

    if (strlen($address) <= 8) {
     $errorMsg = 1;	
    echo"<script>toastr.error('A valid recipient address is required', 'Address too short', {'progressBar': true});
    document.getElementById('address').style.borderColor='red';
    </script>";
    }else{
    	 echo"<script>
    document.getElementById('address').style.borderColor='green';
    </script>";
    }
   
    if ($errorMsg == 0 && $_SESSION['getbank'] == "setted") {
        $_SESSION['country'] = $country; $_SESSION['state']= $state; $_SESSION['city'] = $city; $_SESSION['address']=$address; $_SESSION['zipcode']=$zipcode; $_SESSION['email'] =$email; $_SESSION['phone'] = $phone; $_SESSION['fullname']= $fullname; $_SESSION['type'] = $type; $_SESSION['iban'] = $iban; $_SESSION['swiftcode'] = $swiftcode;
        ?>
        <script type="text/javascript">
         		$("#myModal").modal("show");
                 jQuery("#myModal").on("shown.bs.modal", function() {
                 jQuery(this).data("bs.modal").options.backdrop = "static";
                 jQuery(this).data("bs.modal").options.keyboard = false;
                  });
         	</script>
         <div class="modal fade" tabindex="-1" role="dialog" id="myModal" data-keyboard="false" data-backdrop="static">
        <div class="modal-dialog modal-dialog-centered modal-md" role="document">
            <div class="modal-content">
                <div class="modal-body modal-body-lg">
                    <div class="nk-block-head nk-block-head-xs text-center">
                        <h5 class="nk-block-title">Review Recipient details</h5>
                        <div class="nk-block-text">
                            <div class="caption-text">
                            	<strong>Kindly ensure that all the recipient's details are entered correctly before continuing</strong>
                        </div>
                    </div>
                    <div class="nk-block">
                        <div class="buysell-overview">
                            <ul class="buysell-overview-list">
                                <li class="buysell-overview-item">
                                    <span class="pm-title">Recipient Name</span>
                                    <span class="pm-currency"><span><?php echo$_POST['fullname']?></span></span>
                                </li>
                                </ul>
                                <p>
                                <b>Recipient's banking details</b>
                                </p>
                                <ul class="buysell-overview-list">
                                
                                 <li class="buysell-overview-item">
                                    <span class="pm-title">Bank Name</span>
                                    <span class="pm-currency"><?php echo$_SESSION['banknameB'] ?></span>
                                </li>
                                <li class="buysell-overview-item">
                                    <span class="pm-title">Account Holder</span>
                                    <span class="pm-currency"><?php echo$_SESSION['accountholderB'] ?></span>
                                </li>
                                <li class="buysell-overview-item">
                                    <span class="pm-title">Account Number</span>
                                    <span class="pm-currency"><?php echo$_POST['accountnumber'] ?></span>
                                </li>
                                 <li class="buysell-overview-item">
                                    <span class="pm-title">Iban/Swift Code</span>
                                    <span class="pm-currency"><?php echo$_POST['iban'] ?></span>
                                </li>
                            </ul>
                         </div>
                        <div class="buysell-field form-group">
                            <div class="form-label-group">
                                <label class="form-label">Choose payment account</label>
                            </div>
                               <input type="hidden" value="btc" name="bs-currency" id="buysell-choose-currency-modal">
                            <div class="dropdown buysell-cc-dropdown">
                                <a href="#" class="buysell-cc-choosen dropdown-indicator" data-toggle="dropdown">
                                    <div class="coin-item coin-btc">
                                        <div class="coin-icon">
                                            <em class="icon ni ni-wallet-out"></em>
                                        </div>
                                        <div class="coin-info">
                                            <span class="coin-name"><?php echo$accounttype ?></span>
                                            <span class="coin-text">Balance(<?php echo$money; echo$accountbalance ?>)</span>
                                        </div>
                                    </div>
                                </a>
                            <div class="dropdown-menu dropdown-menu-auto dropdown-menu-mxh">
                                    <ul class="buysell-cc-list">
                                        <li class="buysell-cc-item selected">
                                            <a href="#" class="buysell-cc-opt" data-currency="btc">
                                                <div class="coin-item coin-btc">
                                                    <div class="coin-icon">
                                                        <em class="icon ni ni-wallet-out"></em>
                                                    </div>
                                                    <div class="coin-info">
                                                        <span class="coin-name"><?php echo$accounttype ?></span>
                                                        <span class="coin-text"><?php echo substr($accountnumber, 0,4); echo"*****"; ?></span>
                                                    </div>
                                                </div>
                                            </a>
                                        </li> <!-- .buysell-cc-item -->
                                    </ul>
                                </div>
                            </div><!-- .dropdown -->
                        </div><!-- .buysell-field -->
                        <div class="buysell-field form-action text-left">
                        	<hr>
                        	<strong class="text-dark">I confirmed that the information provided about this recipient is accurate and complete.</strong><br>
                        	<strong class="text-dark">I aknowledged that the transfer maybe refused by the recipient bank if the informaton is inaccurate. The recipient will then have to be deleted and the information will be entered again since the modification feature for international recipient is not available at the moment.</strong>
                        	<hr>

                            <div> 
                            	 <?php 
                            	$ref = randomString(54);
                            	$_SESSION['recipientDetails'] = array($country, $state, $city, $address, $zipcode, $email, $phone, $fullname, $type, $iban, $_SESSION['accounttypeB'], $_SESSION['accountholderB'], $_SESSION['banknameB'], $_POST['email'], $_POST['phone'], $_POST['swiftcode'], $_POST['accountnumber'], $ref);
                            	?>
                                <a href="recipient_added?ref=<?php echo$ref ?>" class="btn btn-primary btn-lg btn-block" name="Confirm_payee" >submit</a>
                                </form>
                            </div>
                            <div class="pt-3">
                                <a href="#" data-dismiss="modal" class="btn btn-sm btn-danger">Cancel</a>
                            </div>
                        </div>
                    </div><!-- .nk-block -->
                </div><!-- .modal-body -->
            </div><!-- .modal-content -->
        </div><!-- .modla-dialog -->
    </div><!-- .modal -->
        


        <?php
      
    	
    }

}
?>