<?php
include("../../db.php");
header("Access-Control-Allow-Origin: * ");

$idno = $_GET['idno'];
$app_token = $_GET['token'];	


$infoRow = $db->getRow("select is_staff_login_timebound,staff_login_start_time,staff_login_end_time from tbl_info");
    
$is_staff_login_timebound = $infoRow['is_staff_login_timebound'];
$start_time = $infoRow['staff_login_start_time'];
$end_time   = $infoRow['staff_login_end_time'];

$allow_login = 1;
  $login_message = "App can be used between $start_time - $end_time, Please try again in that timeframe";
if($is_staff_login_timebound == 1){
	    
    
    $allow_login = isWithInTime($start_time,$end_time);
    
}


$is_sdl_enable = $db->getVal("select is_staff_sdl_enable from tbl_info where id='1'");

 $sdl_token = $db->getVal("select sdl_token from staff where idno='$idno' ");
    
  $token_match = strcmp($sdl_token, $app_token);
  
  if($idno == '' || $app_token=='' || $is_sdl_enable==0){ $token_match=0;  }

	
	
echo json_encode(array('allow_login'=>$allow_login, "login_message"=>$login_message,"token_match"=>$token_match));    


function isWithInTime($start,$end) {

$time = date("H:i:s");

            if (($time >= $start )&& ($time <= $end)) {
               // echo 'OK';
                return 1;
            } else {
                //echo 'Not OK';
                return 0;
            }

}



?>