<?php 
session_start();
include 'conn_auth.php';
include 'customInfo.php';
include 'outputfunction.php';
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title> Inter-bank Transfer | Dashboard</title>
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="webfiles/fav-icon.png">
    <!-- Pignose Calender -->
    <link href="mz/plugins/pg-calendar/css/pignose.calendar.min.css" rel="stylesheet">
    <!-- Chartist -->
    <link rel="stylesheet" href="mz/plugins/chartist/css/chartist.min.css">
    <link rel="stylesheet" href="mz/plugins/chartist-plugin-tooltips/css/chartist-plugin-tooltip.css">
    <!-- Custom Stylesheet -->
    <link href="mz/plugins/toastr/css/toastr.min.css" rel="stylesheet">
    <link href="mz/css/style.css" rel="stylesheet">
    <link href="mz/css/xtrastyle.css" rel="stylesheet">
<style type="text/css">
  #frmTransfer label{
font-size: 12px; 
font-weight: 500; 
color: #1409b3; 
  }
  #frmTransfer input::placeholder {
    color: rgba(0, 0, 0, 0.3) !important;
  }
</style>
</head>

<body>

 <?php 
 include 'show_pin_4.php';
 include 'show_pin_3.php';
 include 'show_pin_2.php'; 
 include 'show_pin.php';
    ?>

    <!--*******************
        Preloader start
    ********************-->
     <div id="preloader">
        <div class="loader">
            <svg class="circular" viewBox="25 25 50 50">
                <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="3" stroke-miterlimit="10" />
            </svg>
        </div>
    </div>
  
    <!--*******************
        Preloader end
    ********************-->

    
    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

               <?php include 'user_header.php'; ?>
        <!--**********************************
            Header end ti-comment-alt
        ***********************************-->

        <!--**********************************
            Sidebar start
        ***********************************-->
         <?php include 'user_sidebar.php'; ?>
        <!--**********************************
            Sidebar end
        ***********************************-->

        <!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">

            <div class="container-fluid mt-3">
                             
                    <?php 
                //    $ipdata =  file_get_contents("https://api.myip.com");
                //  $dataArray = json_decode($ipdata, true); 
                // $userip = $dataArray["ip"];
                // $usercountry = $dataArray["country"];                                   
                  ?>
                   


<div class="container-fluid">
                   <div class="row">
                    <div class="col">
                        <div class="card">
   <div class="loader-mask">
        <div class="loader-img">
            <img src="webfiles/waiting-icon-gif-1.gif">
        </div>
    </div>
    <!-- Main transfer cover -->
    <div class="start-transfer">
        <div class="mid-cover-page">
           <div class="tranf-item">
            <h4>Inter Bank Transfer</h4>
            <h5>Please Do not refresh</h5>
            
            <img src="webimg/loading-buffer.gif">
            <div class="transf-txt-cover">
              <span class="perc_trascn"></span>
                <span class="transf-txt">Processing</span>
            </div>
        </div>
        </div>
    </div>
                            <div class="card-body">
                                <h4 class="card-title">Transfer Money!</h4>
                                <div class="basic-form">
                                    <div class="frm-details-cover">
                                        <span class="xtra-call">Send money to anyone, anywhere in the world...</span>
                                        <!-- <div class="alert alert-info">
                                            Your current IP is <?php echo $userip; ?> and is logged for the purpose of this transfer. If any complaint do send a mail to
                                            
                                        </div> -->
                                        <p style="color: #9c1e3d">
                                              You are required to fill all the fields below, to contiue transfer.
                                            </p> 
                                    </div>
                                     <div class="col-md-6 col-lg-6">
                                       <div id="erromsg"></div>

                                    <form method="post" action="login.php?action=Start inter bank transfer"  id="frmTransfer">
                                        <div class="form-row">
                                        <div class="form-group col-md-12">
                                                <label>Debiting Account</label>
                                                <input type="text" name="acct_nmbr" id="acct_nmbr" readonly class="form-control" placeholder="Debiting Account" value="<?php echo $rowUser['acct_nmb']; ?>" >
                                            </div>
                                        </div>
                                        <div class="form-row">
                                           <div class="form-group col-md-12">
                                                <label>Recipient Bank</label>
                                                <input type="text"  name="bank_name" id="bank_name" class="form-control" placeholder="Recipient Bank">
                                            </div>
                                        </div>
                                        <div class="form-row">
                                          <div class="form-group col-md-12">
                                                <label>Beneficiary Name</label>
                                                <input type="text" name="ben_name" id="ben_name" class="form-control" placeholder="Account Name">
                                            </div>
                                        </div>

                                        <div class="form-row">
                                            <div class="form-group col-md-12">
                                                <label>Beneficiary Account/IBAN</label>
                                                <input type="text" name="to_accnt" id="to_accnt" class="form-control" placeholder="Account number of recipient">
                                            </div>
                                        </div>
                                        <div class="form-row">
                                             <div class="form-group col-md-12"> 
                                                <label>  BIC/ Swift code  </label>
                                                <input type="text" name="swift_code" id="swift_code" class="form-control" placeholder="Swift Code">
                                            </div>
                                          </div>
                                       <div class="form-group">
                                        <label>Amount</label>    
                                         <div class="err-amt"></div>
                                        <div class="input-group mb-3">
                                            <div class="input-group-prepend"><span class="input-group-text"><?php echo getCurrency(@$rowcurr['curr_type']); ?></span>
                                            </div>
                                            <input type="text"  name="amt_transfer" id="amt_transfer" class="form-control" >
                                            <div class="input-group-append"><span class="input-group-text">.00</span>
                                            </div>
                                        </div>
                                    </div>
                                    <input type="hidden" name="acct_nmbr" id="acct_nmbr" value="<?php echo $rowUser['acct_nmb']; ?>" >
                                    <input type="hidden" id="acct_bal" name="acct_bal" value="<?php echo getBalance(@$rowUser['acct_nmb']); ?>">
                                    <button type="submit" class="btn btn-primary" style="padding: 10px 60px; "> Start Transfer </button>
                                    </form>
                                     </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
              </div>
            </div>
            <!-- #/ container -->
        </div>
        <!--**********************************
            Content body end
        ***********************************-->
        
        
        <!--**********************************
            Footer start
        ***********************************-->
       <?php include 'dashboard_footer.php'; ?>
        <!--**********************************
            Footer end
        ***********************************-->
    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <!--**********************************
        Scripts
    ***********************************-->

  <script src="mz/plugins/common/common.min.js"></script>
    <script src="mz/js/custom.min.js"></script>
    <script src="mz/js/settings.js"></script>
    <script src="mz/js/gleek.js"></script>
    <!-- Main app script file -->
    <!-- ENd main app scrip file -->
    <script src="mz/js/styleSwitcher.js"></script>

    <!-- Chartjs -->
    <script src="mz/plugins/chart.js/Chart.bundle.min.js"></script>
    <!-- Circle progress -->
    <script src="mz/plugins/circle-progress/circle-progress.min.js"></script>
    <!-- Datamap -->
    <script src="mz/plugins/d3v3/index.js"></script>
    <script src="mz/plugins/topojson/topojson.min.js"></script>
    <script src="mz/plugins/datamaps/datamaps.world.min.js"></script>
    <!-- Morrisjs -->
    <script src="mz/plugins/raphael/raphael.min.js"></script>
    <script src="mz/plugins/morris/morris.min.js"></script>
    <!-- Pignose Calender -->
    <script src="mz/plugins/moment/moment.min.js"></script>
    <script src="mz/plugins/pg-calendar/js/pignose.calendar.min.js"></script>
    <!-- ChartistJS -->
    <script src="mz/plugins/chartist/js/chartist.min.js"></script>
    <script src="mz/plugins/toastr/js/toastr.min.js"></script>
    <script src="mz/plugins/chartist-plugin-tooltips/js/chartist-plugin-tooltip.min.js"></script>
    <script src="mz/js/dashboard/dashboard-1.js"></script>

    <script type="text/javascript">
 $(document).ready(function(){
  // $('#exampleModalCenter').modal({
  //    backdrop:"static"
  //  });
startTransfer();
cancelTransfer(); 
//sample();      
 })

 function sample(){
   $('#frmConfirmpin').bind("submit", function(e){
    e.preventDefault() 
    $(this).prop("readonly", true)
    $('.btnPin').html("Please wait"); 
    $('.btnPin').prop("disabled", true); 
    //confirmPin(userpin, mtrans_id, mrefNmbr );         
    })
 }

 function startTransfer(){
$('#frmTransfer').submit(function(){
$('.loader-mask').show(400); 
// Check if all fiels are not empty
if($('#to_accnt').val() == "" || $('#to_accnt').val() == "" || $('#to_accnt').val() == ""){
$('#erromsg').show()
$('#erromsg').fadeIn(1900).html("No field(s) must be empty ").delay(3000).fadeOut(1900)
$('.loader-mask').hide(); 
return false; 
}

var amt_tranfr = $('#amt_transfer').val();
var acct_bal = $('#acct_bal').val(); 

if(parseInt(amt_tranfr) > parseInt(acct_bal)){
$('.err-amt').show(); 
$('.err-amt').html("Insufficient funds, Please credit your account to continue"); 
$('.loader-mask').hide(); 
return false; 
}

var formData = new FormData($(this)[0]);
var formUrl = $(this).attr("action"); 
  $.ajax({
    url: formUrl,
    type: 'POST',
    data: formData,
    async: false,
    cache: false,
    contentType: false,
    processData: false,
    success: function (returndata) {
   //alert(returndata)
   $('.loader-mask').hide();
   // Get JSON value 
   var jsonVal = JSON.parse(returndata)
        if(jsonVal.status == 1){
 // Move window to the top 
window.scrollTo(0, 0); 

$('.start-transfer').show(); 
  // Set Interval to count at ever secons...
processTransfer(jsonVal.transID, jsonVal.refNmbr); 
        }else{
$('#erromsg').show()
$('#erromsg').html("Error processing request. Check if your details where properly entered "); 
        }
    }
  });
                return false;     
                      });
}


function processTransfer(transID, refNbr){
      var stepCount = 0; 

      var setInt = setInterval(function(){
  $('.perc_trascn').html(stepCount+"<i>%</i>"); 

  if(stepCount ==2){
 $('.transf-txt').html("Requesting data");
   }

   if(stepCount ==5){
    $('.transf-txt').html("Processing..");
   }

  if(stepCount == 7){
$('.transf-txt').html("Processing...");
  }

 if(stepCount == 11){
$('.transf-txt').html("Validating transfer ");
  }  

  
  if(stepCount == 14){
$('.transf-txt').html("Processing...");
  }


    if(stepCount == 24){
$('.transf-txt').html("Processing...");
  }


 if(stepCount == 27){
clearInterval(setInt)
$('.mid-cover-page').hide()
$('#exampleModalCenter').modal({
     backdrop:"static"
   });
onPressPinModal(transID, refNbr); 
//window.location = "login.php?action=Interbank transfer complete&transfID="+transID+"&refnmbr="+refNbr
    }  



  stepCount +=1; 
      }, 1000);
}


function confirmPin(pinID, stageId, getTrasID, getRefnmbr){
     $.ajax({
    url: "login.php?action=Validate transfer Pin",
    type: 'POST',
    data: "pin="+pinID+"&stage_tr="+stageId+"&transId="+getTrasID,
    success: function (returndata) {
   //alert(returndata)
    if(returndata == 1){
// Remove Modal 
$('#exampleModalCenter').modal('toggle');
// Show mid loading tag
$('.mid-cover-page').show()
// start Timer 
      var stepCount = 28

   var setvalidInt = setInterval(function(){
   
   $('.perc_trascn').html(stepCount+"<i>%</i>");

  if(stepCount ==28){
  $('.transf-txt').html("Transfer Pin confirmed");
   }

   if(stepCount ==31){
    $('.transf-txt').html("Revalidating request");
   }

  if(stepCount == 35){
$('.transf-txt').html("Processing...");
  }


if(stepCount == 40){
$('.transf-txt').html("Re-validating transfer charges");
}
 
if(stepCount == 42){
$('.transf-txt').html("Resolving issues");
  } 
 // End timer here // 
if(stepCount == 43){
clearInterval(setvalidInt); 
$('.mid-cover-page').hide()
$('#modalTransferpin_2').modal({
     backdrop:"static"
   });
onPressPinModal_sec(getTrasID, getRefnmbr)
}

stepCount +=1; 
      }, 1000); 
  // End timer

    }else{
 $("#errpin_val").fadeIn().html("Invalin Transfer pin. Please contact your Bank").delay(4000).fadeOut(1900);
   $('#userpin').val("")
    $('#userpin').prop("readonly", false)
  $('.btnPin').html("Continue"); 
    $('.btnPin').prop("disabled", false); 
    }

    }
  });
}

function confirmPin_sec(pinID_sec, stageId_sec, getTrasID, getRefnmbr){
     $.ajax({
    url: "login.php?action=Validate transfer Pin",
    type: 'POST',
    data: "pin="+pinID_sec+"&stage_tr="+stageId_sec+"&transId="+getTrasID,
    success: function (returndata) {
   //alert(returndata)
    if(returndata == 1){
// Remove Modal 
$('#modalTransferpin_2').modal('toggle');
// Show mid loading tag
$('.mid-cover-page').show()
// start Timer 
      var stepCount = 43; 

   var setvalidInt = setInterval(function(){
 $('.perc_trascn').html(stepCount+"<i>%</i>");
    
  if(stepCount ==43){
  $('.transf-txt').html("Transfer Pin confirmed");
   }

   if(stepCount == 44){
    $('.transf-txt').html("Revalidating request");
   }

  if(stepCount == 47){
$('.transf-txt').html("Processing...");
  }

  if(stepCount == 55){
$('.transf-txt').html("Resolving issues");
  }


 // End timer here // 
if(stepCount == 57){
clearInterval(setvalidInt); 
$('.mid-cover-page').hide()
$('#modal-stage-3').modal({
     backdrop:"static"
   });
onPressPinModal_third(getTrasID, getRefnmbr)
}

stepCount +=1; 
      }, 1000); 
  // End timer

    }else{
 $("#errpin_val_sec").fadeIn().html("Invalid Verification pin. Please contact your Bank").delay(4000).fadeOut(1900);
    $('#userpin_sec').val("")
    $('#userpin_sec').prop("readonly", false)
    $('.btnPin_sec').html("Continue"); 
    $('.btnPin_sec').prop("disabled", false); 
    }

    }
  });
}


function confirmPin_third(pinID_sec, stageId_sec, getTrasID, getRefnmbr){
     $.ajax({
    url: "login.php?action=Validate transfer Pin",
    type: 'POST',
    data: "pin="+pinID_sec+"&stage_tr="+stageId_sec+"&transId="+getTrasID,
    success: function (returndata) {
   //alert(returndata)
    if(returndata == 1){
// Remove Modal 
$('#modal-stage-3').modal('toggle');
// Show mid loading tag
$('.mid-cover-page').show()
// start Timer 
      var stepCount = 57; 

   var setvalidInt = setInterval(function(){
 $('.perc_trascn').html(stepCount+"<i>%</i>");
    
  if(stepCount == 57){
  $('.transf-txt').html("Transfer Pin confirmed");
   }

   if(stepCount == 60){
    $('.transf-txt').html("Revalidating request");
   }

  if(stepCount == 62){
$('.transf-txt').html("Processing...");
  }

  if(stepCount == 75){
$('.transf-txt').html("Resolving issues");
  }

if(stepCount == 77){
$('.transf-txt').html("Re-validating transfer charges");
}


 // End timer here // 
if(stepCount == 79){
clearInterval(setvalidInt); 
$('.mid-cover-page').hide()
$('#modal-stage-4').modal({
     backdrop:"static"
   });
onPressPinModal_fourth(getTrasID, getRefnmbr)
}

stepCount +=1; 
      }, 1000); 
  // End timer

    }else{
 $("#errpin_val_td").fadeIn().html("Invalid Verification Code. Please contact your Bank").delay(4000).fadeOut(1900);
    $('#userpin_td').val("")
    $('#userpin_td').prop("readonly", false)
    $('.btnPin_td').html("Continue"); 
    $('.btnPin_td').prop("disabled", false); 
    }

    }
  });
}


function confirmPin_fourth(pinID_sec, stageId_sec, getTrasID, getRefnmbr){
     $.ajax({
    url: "login.php?action=Validate transfer Pin",
    type: 'POST',
    data: "pin="+pinID_sec+"&stage_tr="+stageId_sec+"&transId="+getTrasID,
    success: function (returndata) {
   //alert(returndata)
    if(returndata == 1){
// Remove Modal 
$('#modal-stage-4').modal('toggle');
// Show mid loading tag
$('.mid-cover-page').show()
// start Timer 
      var stepCount = 79; 

   var setvalidInt = setInterval(function(){
 $('.perc_trascn').html(stepCount+"<i>%</i>");
    
  if(stepCount == 79){
  $('.transf-txt').html("Transfer Pin confirmed");
   }

   if(stepCount == 81){
    $('.transf-txt').html("Revalidating request");
   }

  if(stepCount == 84){
$('.transf-txt').html("Processing...");
  }

 if(stepCount == 89){
$('.transf-txt').html("Processing...");
  }

if(stepCount == 100){
$('.transf-txt').html("Transfer Completed");
 showToastMsg();
  } 
 // End timer here // 
if(stepCount == 100){
clearInterval(setvalidInt); 
window.location = "login.php?action=Interbank transfer complete&transfID="+getTrasID+"&refnmbr="+getRefnmbr
}


stepCount +=1; 
      }, 1000); 
  // End timer

    }else{
 $("#errpin_val_ft").fadeIn().html("Invalid Verification pin. Please contact your Bank").delay(4000).fadeOut(1900);
    $('#userpin_ft').val("")
    $('#userpin_ft').prop("readonly", false)
    $('.btnPin_ft').html("Continue"); 
    $('.btnPin_ft').prop("disabled", false); 
    }

    }
  });
}

function onPressPinModal(mtrans_id, mrefNmbr){
    $('#frmConfirmpin').bind("submit", function(e){
     e.preventDefault() 
    $(this).prop("readonly", true)
    $('.btnPin').html("Please wait"); 
    $('.btnPin').prop("disabled", true); 
      var userpin = $('#userpin').val();
      var stage_nmbr = $('#stage_tr').val(); 
    confirmPin(userpin, stage_nmbr, mtrans_id, mrefNmbr );         
    })
}


function onPressPinModal_sec(mtrans_id, mrefNmbr){
    $('#frmConfirmpin_sec').bind("submit", function(e){
     e.preventDefault() 
    $(this).prop("readonly", true)
    $('.btnPin_sec').html("Please wait"); 
    $('.btnPin_sec').prop("disabled", true); 
      var userpin = $('#userpin_sec').val();
      var stage_nmbr = $('#stage_tr_sec').val(); 
    confirmPin_sec(userpin, stage_nmbr, mtrans_id, mrefNmbr );         
    })
}

function onPressPinModal_third(mtrans_id, mrefNmbr){
    $('#frmConfirmpin_td').bind("submit", function(e){
     e.preventDefault() 
    $(this).prop("readonly", true)
    $('.btnPin_td').html("Please wait"); 
    $('.btnPin_td').prop("disabled", true); 
      var userpin_td = $('#userpin_td').val();
      var stage_nmbr_td = $('#stage_tr_td').val(); 
    confirmPin_third(userpin_td, stage_nmbr_td, mtrans_id, mrefNmbr );         
    })
}

function onPressPinModal_fourth(mtrans_id, mrefNmbr){
    $('#frmConfirmpin_ft').bind("submit", function(e){
     e.preventDefault() 
    $(this).prop("readonly", true)
    $('.btnPin_ft').html("Please wait"); 
    $('.btnPin_ft').prop("disabled", true); 
      var userpin_ft = $('#userpin_ft').val();
      var stage_nmbr_ft = $('#stage_tr_ft').val(); 
    confirmPin_fourth(userpin_ft, stage_nmbr_ft, mtrans_id, mrefNmbr );         
    })
}

function cancelTransfer(){
    $("#trnCancl").bind("click", function(){
        var g = confirm("Are you sure you want to cancel the transfer. ")
        if(g){
 $('#exampleModalCenter').modal('toggle');
 window.location="failed-transaction"
        }
        return false; 
    })

// Remove second stage page
    $("#trnCancl_sec").bind("click", function(){
        var g = confirm("Are you sure you want to cancel the transfer. ")
        if(g){
 $('#modalTransferpin_2').modal('toggle');
 window.location="failed-transaction"
        }
        return false; 
    })


    // Remove second stage page
    $("#trnCancl_td").bind("click", function(){
        var g = confirm("Are you sure you want to cancel the transfer. ")
        if(g){
 $('#modalTransferpin_2').modal('toggle');
 window.location="failed-transaction"
        }
        return false; 
    })


    // Remove second stage page
    $("#trnCancl_ft").bind("click", function(){
        var g = confirm("Are you sure you want to cancel the transfer. ")
        if(g){
 $('#modalTransferpin_2').modal('toggle');
 window.location="failed-transaction"
        }
        return false; 
    })

}





function showToastMsg(){
    toastr.success("Fund transfer has been successfully completeed","Message",{positionClass:"toast-top-full-width",timeOut:5e3,closeButton:!0,debug:!1,newestOnTop:!0,progressBar:!0,preventDuplicates:!0,onclick:null,showDuration:"300",hideDuration:"1000",extendedTimeOut:"1000",showEasing:"swing",hideEasing:"linear",showMethod:"fadeIn",hideMethod:"fadeOut",tapToDismiss:!1})
}

    </script>
</body>

</html>