<?php
require_once("includes/initialize.php");
if ($session->is_logged_in()){redirect_to("dashboard.php");}
$message="";

$username="";
$password="";
$errors = array();

if (isset($_POST['submit'])){
	
$username = mysql_real_escape_string($_POST['username']);	
$password =  mysql_real_escape_string($_POST['password']);
//echo "Done";
if (empty($username)){
	array_push($errors, "Username is required");
}if (empty($password)){
	array_push($errors, "Password is required");
}
if (count($errors)== 0){
$found_user = ADMINACCOUNT::authenticate($username, $password);

if ($found_user){ 
	
	$session->login($found_user);
	
	
	redirect_to("dashboard.php");
}else {
$message="Username/email address combination incorrect";	
	}
}
}

 ?>	
<!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>OSCOTECHADMIN:index</title>
<link href="stylesheet/style.css" type="text/css" rel="stylesheet" />
</head>

<body>
<div class="setimage">
<img src="images/icon.png" />

</div>
<div class="header">
<h2>Login</h2>
</div>
<form method="post" action="index.php">
<?php if (count($errors)>0){?>
<div class="error">

<?php foreach ($errors as $error){?>
<p><?php echo $error; ?></p>
<?php } ?>

</div>
<?php }?>	
<?php if ($message !=''){
	 echo output_message($message);
}?>

<div class="input-group">

<label>Username</label>
<input type="text" name="username" value="<?php echo htmlentities($username);?>" />
</div>

<div class="input-group">

<label>Password</label>
<input type="password" name="password" value="<?php echo htmlentities($password)?>";/>
</div>

<div class="input-group">
<button type="submit" name="submit" class="btn">Login</button>
</div>
</form>
</body>
</html>