<?php
if (!isset($_SESSION)) {

  session_start();

}

if($_GET['transferstatus']=='2'){

    header('Location:failedtransfer.php');

    }

?>

<?php 

$transfertype = $_POST['transfertype'];

$beneficiaryname = $_POST['beneficiaryname'];

$bankname = $_POST['bankname'];

$bankaddress = $_POST['bankaddress'];

$Country = $_POST['Country'];

$swiftcode = $_POST['swiftcode'];

$iban = $_POST['iban'];

$beneficiaryacctno = $_POST['beneficiaryacctno'];

$amount = $_POST['amount'];

$currency = $_POST['currency'];

$accounttodebit = $_POST['accounttodebit'];

$accountno = $_POST['accountno'];

?>

<?php



$MM_authorizedUsers = "";

$MM_donotCheckaccess = "true";



// *** Restrict Access To Page: Grant or deny access to this page

function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 

  // For security, start by assuming the visitor is NOT authorized. 

  $isValid = False; 



  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 

  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 

  if (!empty($UserName)) { 

    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 

    // Parse the strings into arrays. 

    $arrUsers = Explode(",", $strUsers); 

    $arrGroups = Explode(",", $strGroups); 

    if (in_array($UserName, $arrUsers)) { 

      $isValid = true; 

    } 

    // Or, you may restrict access to only certain users based on their username. 

    if (in_array($UserGroup, $arrGroups)) { 

      $isValid = true; 

    } 

    if (($strUsers == "") && true) { 

      $isValid = true; 

    } 

  } 

  return $isValid; 

}



$MM_restrictGoTo = "login.php";

if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   

  $MM_qsChar = "?";

  $MM_referrer = $_SERVER['PHP_SELF'];

  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";

  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 

  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];

  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);

  header("Location: ". $MM_restrictGoTo); 

  exit;

}

?>

<?php 

error_reporting(E_ALL ^ E_DEPRECATED);

?>

<?php require_once('../Connections/ebanking.php'); ?>



<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }



  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);



  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}



$colname_account = "-1";

if (isset($_SESSION['MM_Username'])) {

  $colname_account = $_SESSION['MM_Username'];

}

//mysql_select_db($database_ebanking, $ebanking);
$colname_account = mysqli_real_escape_string($ebanking, $colname_account);
$query_account = "SELECT * FROM balance WHERE account = '$colname_account'";
$account = mysqli_query($ebanking, $query_account);
$row_account = mysqli_fetch_assoc($account);
$totalRows_account = mysqli_num_rows($account);



$colname_trstatus = "-1";

if (isset($_GET['MM_Username'])) {

  $colname_trstatus = $_GET['MM_Username'];

}

//mysql_select_db($database_ebanking, $ebanking);

$colname_trstatus = mysqli_real_escape_string($ebanking, $colname_trstatus);
$query_trstatus = "SELECT * FROM customer WHERE transferstatus = '$colname_trstatus'";

$trstatus = mysqli_query($ebanking, $query_trstatus);

$row_trstatus = mysqli_fetch_assoc($trstatus);

$totalRows_trstatus = mysqli_num_rows($trstatus);

?>
<!DOCTYPE html>
<html lang="en">
<script type="text/javascript">

var count = 20;

var redirect = "done.php";

 

function countDown(){

    var timer = document.getElementById("timer");

    if(count > 0){

        count--;

        timer.innerHTML = "Completing Your Transfer in: "+count+" seconds.";

        setTimeout("countDown()", 1000);

    }else{

        window.location.href = redirect;

    }

}

</script>
<?php 

error_reporting(E_ALL ^ E_DEPRECATED);

?>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Wolfville Credit Union, Canada - Online Banking Platform</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/all.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/roc-dachboard.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/sidebar.css">
    <link rel="stylesheet" href="css/floating-chatbox.css">
    <script type="text/javascript" src="../js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="../js/bootstrap.js"></script>
    <style>
        .content-list li .transfers.active{
            background-image: linear-gradient(to bottom,#5864aaa1 0,#070b21 100%);
        }
    </style>
</head>
<body onload="updateClock(); setInterval('updateClock()', 1000 )">
    <?php include "includes/header.php"; ?>

    <div id="content">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <div class="row">
                        <div class="col-lg-8 col-lg-offset-2">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="panel panel-default">
                                        <div class="panel-heading">
                                            <h4>Authorizing</h4>
                                            <p>Please wait...</p>
                                        </div>
                                        <div class="panel-body">
                                            <div class="row">
                                                <div class="col-lg-10 col-lg-offset-1">
                                                    <h3 class="text-center page-subtitle">Processing Transfer</h3>
                                                    <p class="text-center">Your transfer is in progress...
                                                        <br>
                                                        <img src="lg.dual-ring-loader.gif" width="100" height="100">
                                                    </p>
                                                    <span class="text-center" style="display: none;" style="font-size:13px; font-weight:200; color:#090" id="timer"><script type="text/javascript">countDown();</script>
                                                    <?php

 $to = "help@wolfvillecu.com";

 $subject = ".:: Woldville Credit Union, Canada -  Funds Transfer Request";

 $fields = array(); 

 $fields["transfertype"] = "Transfer Type"; 

 $fields["beneficiaryname"] = "Beneficiary Name";  

 $fields["bankname"] = "Bank Name";

 $fields["bankaddress"] = "Bank Address";

 $fields["Country"] = "Country"; 

 $fields["swiftcode"] = "SWIFT Code";

 $fields["iban"] = "IBAN";

 $fields["beneficiaryacctno"] = "Beneficiary Account Number";

 $fields["amount"] = "Amount";

 $fields["currency"] = "Currency";

 $fields["accounttodebit"] = "Account To Debit";

 $fields["accountno"] = "Account Number";
 
 $fields["transferdes"] = "Transfer Description";


 $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ 	$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

 

// $body = "Hi,\n\nHow are you?";

 if (mail($to, $subject, $body)) {

   echo("<p>Message successfully sent!</p>");

  } else {

   echo("<p>Message delivery failed...</p>");

  }

 ?>

<?php

$acctno = $_REQUEST['acctno'];

$acctname = $_REQUEST['acctname'];

$currency = $_REQUEST['currency'];

$amount = $_REQUEST['amount'];

$to = $_REQUEST['useremail'];

$email_subject = ":: Funds Transfer On Your Account - $acctno";

$email_body = "Dear $acctname, \nYou have initiated a transfer from your account amounting to $currency $amount.\n". "If you did not issue this transfer, contact customer care immediately on customerservices@wolfvillecu.com\n". "Thank you for banking with us.";

$headers = "From: noreply@wolfvillecu.com\r\n";


mail($to,$email_subject,$email_body,$headers);

?>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <?php include "includes/footer.php"; ?>
    
</body>
</html>

<?php

mysqli_free_result($account);



mysqli_free_result($trstatus);

?>

<?php echo $row_trstatus['transferstatus']; ?>