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

// Sending time stamp from display program -------------------updated Jul 15, 2019-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

date_default_timezone_set('America/Toronto');                                                                            // required !
$dateToday = getdate();
$currentTimeH = $dateToday['hours'];                                                                                           // get current hours
$currentTimeM = $dateToday['minutes']; 
$timeStamp = $currentTimeH*60 + $currentTimeM;                                                                    //  time in minutes

$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( $timeStamp) . ":" . $currentDate;                                                           // convert to text format and ad date
echo("Registered"); 
// echo("Not registered");

$monitorFileName = "../saturndm.com/time_stamps/85-The-East-Mall-Etobicoke-0_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.106';
$id = $_POST["ID"];                                                // user port id

 if($ip_address != '52.16.60.102') {  
	$dataFileName = "buildings/85-The-East-Mall-Etobicoke-0.std";
	$fh = fopen($dataFileName, 'w') or die("can't open file");
	fwrite($fh, $ip_address.','.$id);                                                                                                                          // save the file
	fclose($fh);
 }

?>