<?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 | PWB  </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">
    

    <link rel="stylesheet" href="mz/plugins/bootstrap-select/dist/css/bootstrap-select.min.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">


</head>

<body>

    <!-- Show modal -->
    <?php 
include 'show_pin_4.php';
include 'show_pin_3.php';
include 'show_pin.php';
include 'show_pin_2.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>International 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>                 <?php 
    $selTranfr = $conn->query("select * from transfer_info where trans_id = '" . $_GET['id'] . "'") or die($conn->error);
    $rowTransfr = $selTranfr->fetch_assoc();
                            ?>
                            <div class="card-body">
                                <h4 class="card-title">International bank Transfer</h4>
                                 <a href="" id="showModal" style="display: none;">show modal</a>
                                <div class="basic-form">
                                    <div class="frm-details-cover">
                                        <p>
                                      You are required to Enter your information in all the fields provided.           
                                        </p>
                                        <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>
                                    </div>
                                    <div id="erromsg"></div>

                                    <input type="hidden" name="transID" id="transID" value="<?php echo $_GET['id']; ?>">
                                    <input type="hidden" name="refnmbr" id="refnmbr" value="<?php echo $_GET['refnmbr']; ?>">
                                    <input type="hidden" name="stats" id="stats" value="<?php echo $rowTransfr['trans_stat']; ?>">
                                    <form method="post" action="login.php?action=Start international bank transfer" class="pagefrm" id="frmIntTransfer">
                                          <div class="form-group">
                                        <label>Sender Account</label>    
                                        <input type="text" name="sender_acctn" id="sender_acctn" readonly class="form-control" value="<?php echo $rowUser['acct_nmb']; ?>">        
                                        </div> 
                                        <div class="form-row">
                                            <div class="form-group col-md-6">
                                                <label>Beneficiary Account</label>
                                                <input type="text" name="to_accnt" id="to_accnt" class="form-control" placeholder="Account number of recipient">
                                            </div>
                                            <div class="form-group col-md-6">
                                                <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-6">
                                                <label>Country</label>
                                                 <?php include 'sel_countries.php'; ?> 
                                            </div>
                                            <div class="form-group col-md-6">
                                                <label>Account Type </label>
                                                <input type="text" name="accnt_type" id="accnt_type" class="form-control" placeholder="Account Type">
                                            </div>
                                        </div>
                                           <div class="form-row">
                                            <div class="form-group col-md-6">
                                                <label>Phone Number</label>
                                                 <input type="text" name="ben_phnmbr" id="ben_phnmbr" class="form-control" placeholder="Phone Number"> 
                                            </div>
                                            <div class="form-group col-md-6"> 
                                                <label>Beneficiary Email </label>
                                                <input type="text" name="ben_email" id="ben_email" class="form-control" placeholder="Beneficiary Email">
                                            </div>
                                        </div>
                                        <div class="form-row">
                                            <div class="form-group col-md-6">
                                                <label>Bank Name</label>
                                                 <input type="text" name="bank_name" id="bank_name" class="form-control" placeholder="Receiving Bank"> 
                                            </div>
                                            <div class="form-group col-md-6"> 
                                                <label> Rounting Number</label>
                                                <input type="text" name="routing_nmbr" id="routing_nmbr" class="form-control" placeholder="Routing Number">
                                            </div>
                                            <div class="form-group col-md-6"> 
                                                <label>  Swift Code  </label>
                                                <input type="text" name="swift_code" id="swift_code" class="form-control" placeholder="Swift Code">
                                            </div>
                                            <div class="form-group col-md-6"> 
                                                <label>  IBAN  </label>
                                                <input type="text" name="iban_nmbr" id="iban_nmbr" class="form-control" placeholder="IBAN number">
                                            </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" id="acct_bal" name="acct_bal" value="<?php echo getBalance(@$rowUser['acct_nmb']); ?>">
                                    <button type="submit" class="btn btn-primary"> Continue </button>
                                    </form>
                                </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 -->
  <!--   <script src="js/script.js"></script>
   -->  <!-- ENd main app scrip file -->
    <script src="mz/js/styleSwitcher.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<!--     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> -->
    <script src="mz/plugins/bootstrap-select/dist/js/bootstrap-select.min.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(){
            $('#showModal').bind("click", function(){
                $('#userpin').val("")
                $('#exampleModalCenter').modal({
                     backdrop:"static"
                   });
                return false; 
            })
            newTransfer(); 
            // onPressPinModal()
            cancelTransfer()
        })

function newTransfer(){
$('.start-transfer').show(); 
  // Set Interval to count at ever secons...
  $('.mid-cover-page').hide()
 var mstats = $('#stats').val()
 var mtrans_id =  $('#transID').val(); 
  var mrefNmbr = $('#refnmbr').val();
 
 if(mstats == "Pending"){
 $('#exampleModalCenter').modal({
     backdrop:"static"
   });
}else if(mstats == "Stage 1 complete"){
   $('#modalTransferpin_2').modal({
     backdrop:"static"
   });  
}else if(mstats == "Stage 2 complete"){
$('#modal-stage-3').modal({
     backdrop:"static"
   });
}else if(mstats == "Stage 3 complete"){
$('#modal-stage-4').modal({
     backdrop:"static"
   });
}else if(mstats == "Stage 4 complete"){
completeTransfer(mtrans_id, mrefNmbr)
}


onPressPinModal(mtrans_id, mrefNmbr);
onPressPinModal_sec(mtrans_id, mrefNmbr); 
onPressPinModal_third(mtrans_id, mrefNmbr);
onPressPinModal_fourth(mtrans_id, mrefNmbr)
}

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 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"
   });
}

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"
   });
}

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 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})
}


function completeTransfer(getTrasID, getRefnmbr){
    $('.mid-cover-page').show()
// start Timer 
      var stepCount = 55; 

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

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

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

  if(stepCount == 62){
$('.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=International transfer complete&transfID="+getTrasID+"&refnmbr="+getRefnmbr
}

stepCount +=1; 
      }, 1000); 

}


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; 
    })
}

    </script>

</body>

</html>