<?php


// We have to start our session every time we're
// going to call our session variable for a
// logged in issue.
session_start();

// Let's also make sure the user is logged in at all
// If the PHP $_SESSION[] array is not (!) set
if(!isset($_SESSION['username'])){
    //Then redirect them to the login page
    header( 'Location: index.html' );
}
?>
<?php require_once('unibenkgh.php'); ?>
<?php
###################
require_once('dbconnect.php');
##########################
//define a maximum size for the uploaded images in Kb
define ("MAX_SIZE","200"); 
##########################
##########################
//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

//This variable is used as a flag. The value is initialized with 0 (meaning no error found) 
//and it will be changed to 1 if an errro occures. 
//If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['button'])) 
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image) 
{
//get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file, 
//otherwise we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
{
//print error message
echo '<h1>File type not supported!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file
//in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*2048)
{
echo '<h1>You have exceeded the size limit of 200kb!</h1>';
$errors=1;
}

//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) 
{
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}}}}

//If no errors registred, print the success message
if(isset($_POST['button']) && !$errors) 
{
	$cnum = $_POST['customernum'];
	$insertsql = "UPDATE ibank SET `imglink` = '$newname' WHERE `id` = '$cnum'";
	
	mysql_query($insertsql) or die(mysql_error());
	
$uploadstatus =  "Image Uploaded Successfully!";

}

?>
<?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_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE ibank SET password=%s, email=%s, customernum=%s, accholder=%s, idnum=%s, startprd=%s, openbal=%s, acctype=%s, `currency`=%s, transpin=%s WHERE id=%s",
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['customernum2'], "text"),
                       GetSQLValueString($_POST['accholder'], "text"),
                       GetSQLValueString($_POST['idnum'], "text"),
                       GetSQLValueString($_POST['startprd'], "text"),
                       GetSQLValueString($_POST['openbal'], "text"),
                       GetSQLValueString($_POST['acctype'], "text"),
                       GetSQLValueString($_POST['currency'], "text"),
                       GetSQLValueString($_POST['transpin'], "text"),
                       GetSQLValueString($_POST['idd'], "int"));

  mysql_select_db($database_unibenkgh, $unibenkgh);
  $Result1 = mysql_query($updateSQL, $unibenkgh) or die(mysql_error());

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

$colname_correction = "-1";
if (isset($_POST['customernum'])) {
  $colname_correction = $_POST['customernum'];
}
mysql_select_db($database_unibenkgh, $unibenkgh);
$query_correction = sprintf("SELECT * FROM ibank WHERE customernum = %s", GetSQLValueString($colname_correction, "text"));
$correction = mysql_query($query_correction, $unibenkgh) or die(mysql_error());
$row_correction = mysql_fetch_assoc($correction);
$totalRows_correction = mysql_num_rows($correction);



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Digital Banking - Login step 1</title>
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:1;
	left: 23px;
	top: 19px;
}
.bold {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 18px;
	color: #036;
}
-->
</style>
<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#apDiv2 {
	position:absolute;
	width:200px;
	height:115px;
	z-index:2;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
-->
</style>
</head>

<body>
<h1 class="bmhead">Welcome to bank manager</h1>
<p>&nbsp;</p>
<p><a href="vd.php" target="_blank"><strong>View Database </strong></a>~ <a href="credit.php"><strong>Credit Account</strong></a> ~ <a href="update.php"><strong>Update Customer Account</strong></a> ~ <a href="delete.php"><strong>Delete Account</strong></a> ~<strong> <a href="changepass.php">Change Password</a> </strong>~ <a href="logout.php"><strong>Logout</strong></a></p>
<p><strong><a href="cinfo.php">Send Activation mail </a></strong> ~ <a href="index.php"><strong>Home</strong></a><strong></strong></p>
<p><strong>=================================================================</strong>======================================================</p>
<form id="form1" name="form1" method="post" action="">
  <p id="form1">Client's Account Number&nbsp;&nbsp;&nbsp;&nbsp;
<label for="customernum"></label>
    <input type="text" name="customernum" id="customernum" />
    <input type="submit" name="button2" id="button2" value="Fill Form" />
  </p>
</form>
<p>&nbsp;</p>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form2" id="form2">
  <p>
    <label> Account Holder:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="accholder" type="text" id="accholder" value="<?php echo $row_correction['accholder']; ?>" />
      <br />
      <br />
  E-mail:	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input name="email" type="text" id="email" value="<?php echo $row_correction['email']; ?>" />
  <br />
      <br />
      Account Number:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="customernum2" type="text" id="customernum2" value="<?php echo $row_correction['customernum']; ?>" />
      &nbsp;
      <input type="button" value="Generate Account#" onClick="javascript:this.form.customernum.value=randomString();">&nbsp;&nbsp;Allocate Account number to username&nbsp;</label>
    e.g. 0541300000123445
</p>
  <p>Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <label>
      <input name="password" type="text" id="password" value="<?php echo $row_correction['password']; ?>" />
    </label>
  </p>
  <p>Login PIN:  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <label for="transpin"></label>
    <input name="transpin" type="text" id="transpin" value="<?php echo $row_correction['transpin']; ?>" />
  </p>
  <p>Account Type: 
    <label>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <select name="acctype" id="acctype">
        <option value="Checking Account">Checking Account</option>
        <option value="Savings Account">Savings Account</option>
        <option value="Money Market Account">Money Market Account</option>
        <option value="Certificate of Deposit CDs">Certificate of Deposit CDs</option>
        <option value="Grant Settlements Account">Grant Settlements Account</option>
      </select>
    </label>
  </p>
  <p>Currency: 
    <label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <label>
      <select name="currency" id="currency">
        <option value="GBP">GBP</option>
        <option value="USD" selected="selected">USD</option>
        <option value="EUR">EUR</option>
        <option value="YEN">YEN</option>
      </select>
    </label>
  </p>
  <p>
    <label>Account Opening Date:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="startprd" type="text" id="startprd" value="<?php echo $row_correction['startprd']; ?>" />
    </label>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dd/mm/yyyy</p>
  <p>
    <label>Opening Balance:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input name="openbal" type="text" id="openbal" value="<?php echo $row_correction['openbal']; ?>" />
    </label>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Example: 300000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Don't add commas, type just numbers.</p>
  <p>Identification Number:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<label for="idnum"></label>
    <input name="idnum" type="text" id="idnum" value="<?php echo $row_correction['idnum']; ?>" />
  </p>
  <p>Customer Picture:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <label for="image"></label>
    <input name="image" type="file" id="image" value="<?php echo $row_correction['imglink']; ?>" />
  </p>
  <p>
    <label></label>
    <label>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="submit" name="button" value="Update Details" id="button" />
    </label>
  </p>
  <p><?php echo $row_correction['id']; ?> </p>
  <input type="hidden" name="MM_update" value="form2" />
  <input name="idd" type="hidden" id="idd" value="<?php echo $row_correction['id']; ?>" />
</form>
<script language="javascript" type="text/javascript">
function randomString() {
	var chars = "98765432100000000000123456789";
	var string_length = 12;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}
</script>
<p>=============================== * <strong>Cross Online Banking Software </strong>* ====================================================================== </p>
</body>
</html>
<?php
mysql_free_result($correction);
?>
