<?php
session_start();
?>

<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>
	<img src=img/jar_s.png width=50>
	<img src=img/logo_s.png width=250>
	</center>
	</div>
	<div id=user-bar align=right>
	<?php
		if ( $_SESSION["username"] == "" ) {
		?>
			<form id=login action=login.php method=post>
			<input type='text' name='username' style="font-size:10;margin-top:5px;"
			id='username' size=15 maxlength=20 />
			<input type='password' name='password' style="font-size:10;"
			id='password' size=15 maxlength=20 />
			<input type='submit' name='Submit' value='login' 
			style="font-size:10;"/>
			<a href=join.htm>join</a>
			</form>
		<?php
		} else {
		?>
			<a href=mypage.php>mypage</a> :
			<a href=logout.php>logout</a>
		<?php
		}
	?>
	</div>
	<div id=command-bar>
	subscribed tags:
	<?php
	$tags = explode(",",$_SESSION["tags"]);
	foreach($tags as $tag) {
		if ( $tag == "" ) continue;
		echo "<a href=taglist.php?r=$tag>$tag</a> ";
		echo "[<a href=addtag.php?r=$tag>x</a>] ";
	}
	?>
	<form id=addtag action=addtag.php method=post align=right>
	<input type='text' name='tag' style="font-size:10"
	id='tag' size=15 maxlength=15/>
	<input type='submit' name='submit' value='add tag'
	style="font-size:10;"/>
	</form>
	</div>
	<div id=content>
	Active Questions:
	<table width=100% style="font-size:11">
	<?php
		$mycount = 0;
		$questions = json_decode( file_get_contents( 'data/questions.json' ), true );
		foreach($questions as $q) {
			if ($mycount % 2 == 0 ) {
				echo "<tr bgcolor=#DDD>";
			} else {
				echo "<tr>";
			}
			echo "<td><a href=taglist.php?q=".($q['id']+1).">".
			$q['title']."</td>";
			echo "<td width=70px>";
			$qtags = explode(",", $q['tags']);
			foreach($qtags as $qt) {
				echo "<a href=taglist.php?r=".$qt.">"
					.$qt."</a>, ";
			}
			echo "</td>";

			echo "</tr>";

			$mycount += 1;
		}
	?>
	</table>
	</div>

	<div id=footer>
		contact:
	</div>

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