<?php

// error_reporting(E_ALL);
// ini_set('display_errors',1);


require_once("includes/initialize.php");
//if ($session->is_logged_in()){redirect_to("dashboard.php");}
$message="";
$email="";
$username="";
$password="";
$logout="";
$errors = array();

if (isset($_GET['logout']) and $_GET['logout']==1){
	
	$message="You are now logged out";
}
	


if(isset($_POST['login'])){
	$email = ($_POST['email']);
	$password = ($_POST['password']);
	//if (count($errors)== 0)
	//{
        $found_user = ADMINACCOUNT::authenticate_by_email($email, $password);
        if ($found_user)
        {
           
           $access_level = $found_user->accessed_Level;
			if ($found_user->status=="notactive"){
			     $session->login($found_user);
			     
			     $_SESSION['access_level']= $access_level;
				//redirect_to("account_updata.php");
				redirect_to("dashboard.php");
			}else if ($found_user->status=="active"){
			     $session->login($found_user);
			      $_SESSION['access_level']= $access_level;
               redirect_to("dashboard.php");
			}else {
			    redirect_to("index.php");
			}
        }
        else
        {
            $message="Email Address/Password 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" style="margin-bottom: 50px" />

</div>
<div style="width:30%;
	height: auto;
	margin:0px auto;
	padding: 10px;
	background-color: #064dde;
	/*background-color: #F8F8FF;*/
	
	border:1px solid #80C4DE;
	border-bottom:none;
	border-radius:10px 10px 0px 0px;
	padding:0px;
	">
<h2 style="font-weight: bolder;text-align: center;color: #FFF">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>Email</label>
<input type="text" name="email" value="<?php echo htmlentities($email);?>" />
</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="login" id = "login" class="btn" style="background-color: #064dde; padding: 10px 20px 10px 20px; font-weight: bolder;">Login</button>
</div>
</form>
</body>
</html>
