<?php
session_start();
ob_start();
date_default_timezone_set("Asia/Kolkata");
require "../model/configuration.php";
$err=NULL;
$message=array();
if(isset($_POST['uname']) && !empty($_POST['uname']))
{
    $uname = $db->sanitize($_POST['uname']);
}
else
{
    $message[]='Please enter username';
}

if(isset($_POST['password']) && !empty($_POST['password']))
{
    $password = $db->sanitize($_POST['password']);
}
else
{
    $message[]='Please enter password';
}
$countError=count($message);
if($countError > 0)
{
     for($i=0;$i<$countError;$i++)
	 {
              echo ucwords($message[$i]).'<br/>&nbsp;';
     }
}
else
{
	$usrqry = $db->execute("select * from users where BINARY user_name='$uname' and BINARY password='$password' and loginpermission='0' and del_status='0'");
    $checkUser = $usrqry->num_rows;
    if($checkUser > 0)
	{
		$_SESSION['LOGIN_STATUS']=true;
		$_SESSION['UNAME']=$uname;
		$_SESSION['title']="Welcome to Newlimara";
		$stfid=$usrqry->fetch_assoc();
		$_SESSION['user_id']=$stfid['staff_id'];
		$entrytime = date("h:i:s:A", time());
		$date=date("Y-m-d");
		$db->execute("INSERT INTO login_details(staff_username,staff_id,purpose,time,date) VALUES('".$_SESSION['UNAME']."','".$_SESSION['user_id']."','Login','$entrytime','$date')");
		echo 'correct';
    }else
	{
         echo ucwords('please enter correct user details');
    }
}
?>