<?php
// define who may/may not access this page:
$loginRequired = true; //set to false if you do not need to be logged in to access this module.
$loggedIn = SableSystem::loggedIn();
$allowModuleAccess = $loggedIn&&$loginRequired;
if ($allowModuleAccess)
{
	/** To be here means that the user is logged in, as is required. **/
	/**
	The employee needs to check in every morning and cannot use the app unless they are checked in:	
	**/	
}
else
{
	/** Add necessary code for restrictions, beyond login requirements, here. **/
	SableGeneralFunctions::revertToLoginPage();
}

function checkAttendance()
{
	global $sableDB;
	
	$checkedIn	= false; //assume they are not checked in
	$checkedOut = false;
	$attendance = $sableDB->getRow("select * 
								from attendance 
								where user_code = {$_SESSION['user']['user_code']} 
								order by attendance_in DESC 
								limit 0,1"); //get just the latest entry for the user

	$checkedIn = ($attendance['attendance_in']  ?? false) ? true : false;
	$checkedOut= ($attendance['attendance_out'] ?? false) ? true : false;

	return $checkedOut || (!$checkedIn && !$checkedOut); 
}