<?php
session_start();
require_once('classes/conf.php');
include_once('classes/users.php');
if($_SESSION['loggedIn'])
  header('Location: index.php' ) ;

$users = new users(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

if($_POST)
	if($users->login($_POST['username'], $_POST['password']))
		header('Location: index.php' ) ;
	else
		$failed = true;

include("classes/header.php");

if($failed)
	echo "Please check you Userame / Password";

?>

<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery.sha256.js"></script>
<script type="text/javascript">                                         
function readText (form) {
    form.password.value = $.sha256(form.password.value+form.username.value);
}
</script>
<form id='login' name='login' action='login.php' method='POST' accept-charset='UTF-8'>
	<fieldset>
		<legend>Login</legend>
		<input type='hidden' name='submitted' id='submitted' value='1' />

		<div class="clearfix">
			<label for='username'>UserName:</label>
			<div class="input">
				<input type='text' name='username' id='username' maxlength="50" required />
			</div>
		</div>

		<div class="clearfix">
			<label for='password'>Password:</label>
			<div class="input">
				<input type='password' name='password' id='password' onfocus="this.value = '';" />
			</div>
		</div>

		<div class="actions">
			<button type="submit" class="btn primary" onClick="readText(this.form)">Login</button>
			<button type="reset" class="btn">Cancel</button>
		</div>

	</fieldset>
</form>


<?php include("classes/footer.php"); ?>
