<?php
	include 'top.php';
	
	$Text = "";
	$TextErr = "";
	$error = 0;
	
	if ($_SERVER["REQUEST_METHOD"] == "POST") {
		if (empty($_POST['text'])) {
			$TextErr = "TextBox must have text!";
			$error++;
		}
		else {
			$Text = $_POST['text'];
		}
		
		if ($error == 0) {
			WriteFile($Text);
		}
	}
	
	function WriteFile($Text)
	{
		$File = fopen("../txt/AboutText.txt", "w");
		fwrite($File, $Text);
		fclose($File);
		echo("<script>alert('Done');</script>");
	}
?>
<!DOCTYPE html>
<html>
	<head>
    	<link rel="stylesheet" type="text/css" href="body.css">
        <link rel="stylesheet" type="text/css" href="AdminSideBar.css">
        <style>
			.error {color: red;}
		</style>
    </head>
    <body class="background">
    	<div class="sidebar">
            <div class="infoContainer"><a href="AccountManager.php">Account Manager</a></div>
            <div class="infoContainer"><a href="TextEdit.php">Page Text Editor</a></div>
            <div class="infoContainer"><a href="APhotoManager.php">Photos</a></div>
            <div class="infoContainer"><a href="AReview.php">Review Manager</a></div>
            <div class="infoContainer"><a href="ALogOut.php">LogOut</a></div>
        </div>
        <div class="bodyContainer">
        	<form method="post" action="<?php htmlspecialchars($_SERVER['PHP_SELF']);?>">
            	<span class="error">* <?php echo($TextErr);?></span>
            	<?php
					$File = fopen("../txt/AboutText.txt", "r") or die("<script>alert('Error opening HomeText.txt');</script>");
					echo ("<textarea cols='160' rows='30' name='text' style='margin: 0px auto;'>");
					echo fread($File, filesize("../txt/AboutText.txt"));
					echo ("</textarea>");
					fclose($File);
				?>
                <input type="submit" name="submit" value="Submit" style="float: bottom;">
            </form>
        </div>
        <div class="sidebarRight">
        	<div class="infoContainer"><a href="HomeTextEditor.php">Home Text Edit</a></div>
            <div class="infoContainer"><a href="#">About Text Edit</a></div>
        </div>
    </body>
</html>