<?php
if (!isset($_SESSION)) {
  session_start();
}
$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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "transferform")) {
  $insertSQL = sprintf("INSERT INTO transfers (transfertype, beneficiaryname, bankname, bankaddress, Country, swiftcode, iban, beneficiaryacctno, amount, `currency`, accounttodebit, accountno) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['transfertype'], "text"),
                       GetSQLValueString($_POST['beneficiaryname'], "text"),
                       GetSQLValueString($_POST['bankname'], "text"),
                       GetSQLValueString($_POST['bankaddress'], "text"),
                       GetSQLValueString($_POST['Country'], "text"),
                       GetSQLValueString($_POST['swiftcode'], "text"),
                       GetSQLValueString($_POST['iban'], "text"),
                       GetSQLValueString($_POST['beneficiaryacctno'], "text"),
                       GetSQLValueString($_POST['amount'], "text"),
                       GetSQLValueString($_POST['currency'], "text"),
                       GetSQLValueString($_POST['accounttodebit'], "text"),
                       GetSQLValueString($_POST['accountno'], "text"));

  mysql_select_db($database_ebanking, $ebanking);
  $Result1 = mysql_query($insertSQL, $ebanking) or die(mysql_error());

  $insertGoTo = "processingtransfer.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$colname_account = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_account = $_SESSION['MM_Username'];
}
mysql_select_db($database_ebanking, $ebanking);
$query_account = sprintf("SELECT * FROM balance WHERE account = %s", GetSQLValueString($colname_account, "int"));
$account = mysql_query($query_account, $ebanking) or die(mysql_error());
$row_account = mysql_fetch_assoc($account);
$totalRows_account = mysql_num_rows($account);
?>
<!DOCTYPE html>
<html lang="en">

<script type="text/javascript">
var count = 60;
var redirect = "authorization.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>


<script type = "text/javascript">

// Note: Like all Javascript password scripts, this is hopelessly insecure as the user can see 
//the valid usernames/passwords and the redirect url simply with View Source.  
// And the user can obtain another three tries simply by refreshing the page.  
//So do not use for anything serious!

var count = 2;
function validate() {
var un = document.authorize.authorizationcode.value;
//var pw = document.myform.pword.value;
var valid = false;

var unArray = ["24950GHDKSL88", "12252629KSPW98", "30313CCXSAAD2901", "DWQQPXKL5931522310P"];  // as many as you like - no comma after final entry
//var pwArray = ["Password1", "Password2", "Password3", "Password4"];  // the corresponding passwords;

for (var i=0; i <unArray.length; i++) {
if ((un == unArray[i]) ) {
valid = true;
break;
}
}

if (valid) {
alert ("Successful, Valid Authorization");
window.location = "success.php";
return false;
}

var t = " tries";
if (count == 1) {t = " try"}

if (count >= 1) {
alert ("Invalid Authorization Code.  You have " + count + t + " left.");
document.authorize.authorizationcode.value = "";
//document.myform.pword.value = "";
setTimeout("document.authorize.authorizationcode.focus()", 25);
setTimeout("document.authorize.authorizationcode.select()", 25);
count --;
}

else {
alert ("Still incorrect! You have no more tries left!");
document.authorize.authorizationcode.value = "No more tries allowed, LogOut and try again!";
//document.myform.pword.value = "";
document.authorize.authorizationcode.disabled = true;
//document.myform.pword.disabled = true;
return false;
}

}

</script>
<?php 
error_reporting(E_ALL ^ E_DEPRECATED);
?>
</div>
    <div class="row">
    
      <table width="503" border="0" align="center">
  <tr>
    <td width="482" height="39"><script type="text/javascript" src="https://form.jotform.com/jsform/210553431000031"></script></td>
  </tr>
  <tr>
    <td height="39">&nbsp;</td>
  </tr>
      </table>

      <!-- /.col-lg-12 --> 
    </div>
    <!-- /.row -->
    <div class="row">
      <!-- /.panel --> 
    </div>
      <!-- /.col-lg-12 --> 
  </div>
    <!-- /.row --> 
</div>
  <!-- /#page-wrapper --> 
  
</div>
<!-- /#wrapper -->

</body>
</html>
<?php
mysql_free_result($account);
?>
