<?php
/*$onoroff = $_GET["state"]; // Declares the request from index.html as a variable
$textfile = "LEDstate.txt"; // Declares the name and location of the .txt file
$fileLocation = "$textfile";
$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and repla
$stringToWrite = "$onoroff"; // Write either 1 or 0 depending on request from index.html
fwrite($fh, $stringToWrite); // Writes it to the .txt file
fclose($fh);
header("Location: index.html"); // Return to frontend (index.html)*/

if (isset($_REQUEST['state'])) {
	$state = $_REQUEST['state'];

	//Red

	if($state=='1'){
		$textfile = "LEDstatered.txt"; // Declares the name and location of the .txt file
		$fileLocation = "$textfile";
		$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and repla
		$stringToWrite = 1; // Write either 1 or 0 depending on request from index.html
		fwrite($fh, $stringToWrite); // Writes it to the .txt file
		fclose($fh);
	}
	else if ($state=='0') {
		$textfile = "LEDstatered.txt"; // Declares the name and location of the .txt file
		$fileLocation = "$textfile";
		$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and repla
		$stringToWrite = 0; // Write either 1 or 0 depending on request from index.html
		fwrite($fh, $stringToWrite); // Writes it to the .txt file
		fclose($fh);
	}

	//Green

	if($state=='1'){
		$textfile = "LEDstategreen.txt"; // Declares the name and location of the .txt file
		$fileLocation = "$textfile";
		$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and repla
		$stringToWrite = 1; // Write either 1 or 0 depending on request from index.html
		fwrite($fh, $stringToWrite); // Writes it to the .txt file
		fclose($fh);
	}
	else if ($state=='0') {
		$textfile = "LEDstategreen.txt"; // Declares the name and location of the .txt file
		$fileLocation = "$textfile";
		$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and repla
		$stringToWrite = 0; // Write either 1 or 0 depending on request from index.html
		fwrite($fh, $stringToWrite); // Writes it to the .txt file
		fclose($fh);
	}


	//Yellow

	if($state=='1'){
		$textfile = "LEDstateyellow.txt"; // Declares the name and location of the .txt file
		$fileLocation = "$textfile";
		$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and repla
		$stringToWrite = 1; // Write either 1 or 0 depending on request from index.html
		fwrite($fh, $stringToWrite); // Writes it to the .txt file
		fclose($fh);
	}
	else if ($state=='0') {
		$textfile = "LEDstateyellow.txt"; // Declares the name and location of the .txt file
		$fileLocation = "$textfile";
		$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and repla
		$stringToWrite = 0; // Write either 1 or 0 depending on request from index.html
		fwrite($fh, $stringToWrite); // Writes it to the .txt file
		fclose($fh);
	}
	header("Location: index.html");
}
?>