<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Credentials: true');

$orientation = 'P';

// Sending time stamp from display program -------------------updated Jan 31, 2024-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
$id = '';
if(array_key_exists('ID', $_POST)) $id = $_POST["ID"];                                                                                  // user port id

date_default_timezone_set('America/Toronto');                                                                                                   // required !
$dateToday = getdate();

$unixTsCurrent = mktime($dateToday['hours'], $dateToday['minutes'], $dateToday['seconds'], $dateToday['mon'] , $dateToday['mday'] , $dateToday['year']);

$currentDate = $dateToday['year'] . "/";
if ( $dateToday['mon'] < 10)                                                                                                                                               // convert date to format yyyymmdd 
    { 
	    $dateToday['mon'] = "0" . $dateToday['mon'] . "/"; 
	}
else $dateToday['mon'] .= "/";
$currentDate .= $dateToday['mon'];

if ( $dateToday['mday'] < 10)
    { 
         $dateToday['mday'] = "0" . $dateToday['mday']; 
	}

$currentDate .= $dateToday['mday'];

$timeStampTxt = strval( $unixTsCurrent) . ":" . $currentDate;                                                                          // convert to text format and ad date
echo("Registered"); 
// echo("Not registered");

$monitorFileName = "../monitoring/time_stamps/460-Springbank-Dr-London-Demo_monitor.txt";
$fh = fopen($monitorFileName, 'w') or die("can't open file");
fwrite($fh, $timeStampTxt);                                                                                                                                       // save the file on the server
fclose($fh);

// get user details
// $ip_address = $_SERVER["REMOTE_ADDR"];        // user ip adderss
$ip_address = '192.168.2.55';

 if(($ip_address != '52.16.60.102')  && ($id != '')) {  
	$dataFileName = "buildings/460-Springbank-Dr-London-Demo.std";
	$fh = fopen($dataFileName, 'w') or die("can't open file");
	fwrite($fh, $ip_address.','.$id.','.$orientation);                                                                                                                              // save the file on the server
	fclose($fh);
 }

include ('../monitoring/Screen_status.php');

?>