<?php 
require 'session.php';
require_once '../dao/Auth.php';
require '../dao/Profile.php';
$valid = '';
$response = 0;

if (isset($_POST['auth'])) {
	$username = $_POST['username'];
	$password = $_POST['password'];
	$valid = $auth->auth($username,md5($password));

	//print_r($auth->auth($username,$password));
	if ($valid) { 
		$hash = md5(microtime()); 
		$data = array("hash"=>$hash);
		// $auth->update($data,$staff_id);
		if ($valid[0]['role']=="Admin") {
			$_SESSION['isAdmin'] = "ADMIN";
			$response = 1;

		}else if($valid[0]['role']=="Root"){
			$_SESSION['isAdmin'] = "ADMIN";
			$response = 3;
		}
		else if($valid[0]['role']=="Teacher"){
			$_SESSION['isAdmin'] = "";
			$response = 2;
		}else if($valid[0]['role']=="Form Master"){
			$_SESSION['isAdmin'] = "";
			$response = 3;
		}
		
		$_SESSION['hash'] = $hash;
		$_SESSION['staff_id'] = $valid[0]['staff_id'];
		$get_staff_detail = $profile->get_staff_detail($_SESSION['staff_id']);
		$_SESSION['name'] = $get_staff_detail[0]['first_name'].' '.$get_staff_detail[0]['last_name'];
		 $_SESSION['pic'] = $get_staff_detail[0]['picture'];
		 $_SESSION['role'] = $get_staff_detail[0]['role'];
		 $_SESSION['phone'] = $get_staff_detail[0]['phone'];
		echo $response;
	}else{
		//echo "error";
	}
}
 ?>
