<?php

function is_Date($value) {
	
    if (!$value) {
        return false;
    }

    try {
        new DateTime($value);
        return true;
    } catch (Exception $e) {
        return false;
    }
}
 
$show_all_fld=$prefix.'ShowAll';
$period_type_name=$prefix."period_type";
#$period_type="week";

$pFind=$prefix."FindWhat";
$RecsPP_fld=$prefix.'cboRecPP';
$HmApo_c_name=$prefix.'HmApo';
$HmEos_c_name=$prefix.'HmEos'; 

$SortFLD=$prefix.'srt';
$SortValue="";
$show_all_value="unchecked";
$pgNo=1;
$FindWhat="";
 
if(!isset($_COOKIE[$show_all_fld])) {$show_all_value="unchecked";} else { $show_all_value=$_COOKIE[$show_all_fld];} 
 
  $period_type=!isset($_COOKIE[$period_type_name]) ? '' : $_COOKIE[$period_type_name]; 
   $SortValue=!isset($_COOKIE[$SortFLD]) ? '': $_COOKIE[$SortFLD]; 
	  $RecsPP=!isset($_COOKIE[$RecsPP_fld]) ? 100: $_COOKIE[$RecsPP_fld]; 
	   $HmApo=!isset($_COOKIE[$HmApo_c_name]) ? date_create('now')->format('d/m/Y') : $_COOKIE[$HmApo_c_name]; 
	   $HmEos=!isset($_COOKIE[$HmEos_c_name]) ? date_create('now')->format('d/m/Y') : $_COOKIE[$HmEos_c_name]; 

//if (!is_Date($HmApo)) {$HmApo=date_create('now')->format('d/m/Y');}
//if (!is_Date($HmEos)) {$HmEos=date_create('now')->format('d/m/Y');}

if (isset($_GET[$prefix.'FindWhat'])) {
	$FindWhat = trim(filter_input(INPUT_GET, $prefix.'FindWhat', FILTER_SANITIZE_SPECIAL_CHARS));
	}

if (isset($_GET[$prefix.'pgNo'])) {
	$pgNo = trim(filter_input(INPUT_GET, $prefix.'pgNo', FILTER_SANITIZE_SPECIAL_CHARS));
	}

if(!is_numeric($pgNo)){ $pgNo=1;}

# ==============================
$the_date=date("Y-m-d");
$the_day_of_week = date("w",strtotime($the_date)); //sunday is 0 
$first_day_of_week = date("Y-m-d",strtotime( $the_date )-60*60*24*($the_day_of_week)+60*60*24*1 );
$last_day_of_week = date("Y-m-d",strtotime($first_day_of_week)+60*60*24*6 );
$first_day_of_week=strval(date("d/m/Y", strtotime($first_day_of_week)));
$last_day_of_week=strval(date("d/m/Y", strtotime($last_day_of_week)));

//echo "================ " .  $period_type . "  ,  " . $HmApo . "  ,  " . $HmEos;

if(!isset($_COOKIE[$period_type_name]))
		{ $period_type='week'; $HmApo=$first_day_of_week; $HmEos=$last_day_of_week; 
			setcookie($period_type_name, 'week' );
			setcookie($HmApo_c_name, $HmApo);
			setcookie($HmEos_c_name, $HmEos);
		}
		else
		{
			$period_type=!isset($_COOKIE[$period_type_name]) ? 'week' : $_COOKIE[$period_type_name]; 
		}	
 
?>

