<?php
	include ("includes/dbconfig.php");
	
	if (!isset($_SESSION['connecteduserid']))
	{	
?>
		<script>
			location.href="index.php";
		</script>
<?php
		exit();
	}
	else
	{
		$row = DB::queryFirstRow("SELECT is_loggedin FROM personnel_details WHERE id=%i LIMIT 1", $_SESSION["connecteduserid"]);
		
		if($row['is_loggedin'] == 0)
		{
			@session_start();
			session_destroy();
?>
				<script>
					location.href="index.php";
				</script>
<?php
			exit();
		}
		else
		{
			@session_start();
			DB::query("UPDATE personnel_details SET is_loggedin=0, last_logout_date = current_timestamp() WHERE id=%i", $_SESSION["connecteduserid"]);
			session_destroy();
			header("Location: index.php");
		}
	}

?>