<?php
	session_start();
	header('Content-type: application/json');
	include_once 'db/db.php';
	$response = array();

	if ($_POST) {
		
		$user = trim($_POST['user']);
		$pass = trim($_POST['password']);
		
		$uname = strip_tags($user);
		$upass = strip_tags($pass);
		
		$password = hash('sha256', $upass);
				
		$sql = mysqli_query($conn, "SELECT * FROM user_acc_tbl WHERE user='$uname' and access=1");	
		$row = mysqli_fetch_assoc($sql);
		
		if(mysqli_num_rows($sql) == 1) {			
			
			if($row['pass']== $password){
				
				$response['status'] = 'ok'; // log in
				$_SESSION['user'] = $row['user'];
				$_SESSION['emp_id'] = $row['emp_id'];
			
			} else{
				$response['status'] = 'error';
				 // wrong details
				$response['message'] = '<span class="glyphicon glyphicon-info-sign"></span> &nbsp; Username or Password does not match.'; 
			}
		}
		
		else{
			$response['status'] = 'error';
			// wrong details
			$response['message'] = '<span class="glyphicon glyphicon-info-sign"></span> &nbsp; Username or Password does not match.'; 
		}
		
	}
	
	echo json_encode($response);
?>