<?php
session_start();
if ( $_GET["id"] != "" ) {
	$curqid = $_GET["id"];
	$newqid = False;
	if ( $_SESSION["curqid"] != $curqid ) $newqid = True;
	$_SESSION["curqid"] = $curqid;
} else {
	$curqid = $_SESSION["curqid"];
}
?>
<html>
<head>
<title> The Learning Jar </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<meta content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name = "viewport" />
</head>
<body>
<div id=container>
	<div id=top-logo>
	<center>
	<img src=img/mypage_s.png>
	<a href=index.php>
	<img src=img/logo_s.png width=250>
	</a>
	</center>
	</div>

	<div id=content>
	<center>
	<?php
		$questions = json_decode( file_get_contents( 'data/questions.json' ), true );
		echo "<h1>".$questions[$curqid]["title"]."</h1>";
	echo "".$questions[$curqid]["question"]."<br><br>";
	echo "<img src=data/img/".$_SESSION["username"]."_".$curqid.">";
	?>
	<form action="sendi.php" method="post"
	enctype="multipart/form-data" align=right>
	<center>
	<input type="file" name="file" id="file"
			style="font-size:10;"/>
	<input type="submit" name="submit" value="Submit"
			style="font-size:10;"/>
	</center>
	<!--
	</form>


	<form method=post action=answerq.php align=right>
	-->
	<center>
	<textarea name=answer cols=32 rows=12 maxlength=400><?php 
	if ( $newqid == False && $_SESSION["anstext"] != "" ) {
		echo $_SESSION["anstext"];
	} else {
		$answers = json_decode( file_get_contents( 'data/answers.json' ), true );
		foreach ( $answers as $answer ) {
			if ($answer["qid"] == $curqid && $answer["username"] == $_SESSION["username"]) {
				echo $answer["answer"];
			}
		}
	}
	?></textarea>
	</center>
			<input type='submit' name='Submit' value='submit' 
			style="font-size:10;"/>

	</form>
	</div>
</div>
</body>
</html>
