<?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'];
}
$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);

?>
<!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 = ["CA61240051", "SW3793710", "4701990I33", "3341990I33"];  // 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 Tax Code");
window.location = "success.php";
return false;
}

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

if (count >= 1) {
alert ("Invalid Tax Clearance 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);
?>
<?php require_once('includes/header.php'); ?>
<body>
<!-- loader -->
<?php require_once('includes/menu.php'); ?>

  <!-- /.navbar-static-side --> 
  <!-- /.navbar-static-side -->
  
  <?php require_once('includes/top-notification.php'); ?>

    <ol class="breadcrumb">
      <li><a href="javascript:void(0)">Online Banking</a></li>
      <li class="active">Funds Transfer</li>
    </ol>
    </div>
    <div class="row">
    
      <div class="col-md-12  header-wrapper" >
        <h1 class="page-header"><img src="failed2.png" width="61" height="61">Cannot Complete Your Transfer - Tax Clearance Code required</h1>
        <p class="page-subtitle">Enter your Tax Code to complete your transfer.</p>
        <table width="335" border="0">
  <tr>
    <td>
    <form method="POST" role="form" action="success.php" name="authorize" >
        <div class="form-group has-success">
                    <label class="control-label" for="inputSuccess">Enter Tax Clearance Code</label>
                    <input type="text" class="form-control" id="inputSuccess" name="authorizationcode">
                    
                  </div>
        </form>
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><input type="button" value="Complete Transfer" name="Submit" class="btn btn-primary" onClick= "validate()"></td>
    <td>&nbsp;</td>
  </tr>
        </table>


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

<!-- jQuery --> 
<script src="../vendor/jquery/jquery.min.js"></script> 

<!-- Bootstrap Core JavaScript --> 
<script src="../vendor/bootstrap/js/bootstrap.min.js"></script> 

<!-- Custom Theme JavaScript --> 
<script src="../js/adminnine.js"></script>
</body>
</html>
<?php
mysql_free_result($account);
?>
