<?php
	$puzzles = scandir('./puzzles/');
	unset($puzzles[0]);
	unset($puzzles[1]);

	$_GET['puzzle'] = $_GET['puzzle'] ? $_GET['puzzle'] : $puzzles[array_rand($puzzles)];
?>
<html>
<head>
	<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=1"/>
    <meta http-equiv="content-type" content="text/html; charset=UTF8">
    <meta name="author" content="franga2000">
    
    <title>UGM Sestavljanka</title>
	
	<!--[if IE]><!-->
		<script src="//cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/excanvas.min.js"></script>
	<!--<![endif]-->
	
    <script src="js/game.js" charset="UTF-8"></script>
    <script>
    <?php
        $data = array_merge(json_decode(file_get_contents("puzzles/" . $_GET['puzzle'] . "/info.json"), true), Array("ID" => $_GET['puzzle']));
        if (empty($_GET['tiles'])) $_GET['tiles'] = $data['Stopnje']["Lahko"];
        
        while (!isset($next) || $next == $data['ID']) $next = $puzzles[array_rand($puzzles)];
            
        
		echo "const PUZZLE_DIFFICULTY = " . $_GET['tiles'] . ";
	var ID = \"" . $data['ID'] . "\";
	var next = \"" . $next . "\";
	init(); \n";
	?>
    </script>
</head>
 
<body>
    <table id="content">
		<td><canvas id="canvas"></canvas></td>
		<td id="extra">
			<h1 id="naslov"><?php echo $data['Naslov']; ?></h1>
			<h3 id="avtor"><?php echo $data['Avtor']; ?></h3>
			<p id="info">
				<?php echo $data['Opis']; ?>
			</p>
			<form style="display:inline;" action="" method="GET">
				<!-- <input type="hidden" name="puzzle" value="<?php echo $data['ID']; ?>" />  -->
				<label for="tiles">Težavnost: </label>
				<select name="tiles" id="tezavnost" onChange="this.form.submit()">
				<?php
					foreach($data['Stopnje'] as $stopnja => $tiles) {
						echo '<option value="' . $tiles . '" ' . ($tiles == $_GET['tiles'] ? 'selected' : '') . '>' . $stopnja . "</option>";
					}
				?>
				</select>
			</form>
			<p id="cas">Čas: 0s</p>
			<p id="premiki">Premiki: 0</p>
		</td>
	</table>
</body>
 
<style>
	html {
		font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
	}
	
	#content {
		padding: 10px;
		border: 1px solid #BCE8F1;
		border-radius: 5px;
		background: #D9EDF7;
		display: block;
		margin: auto;
	}
	
	#content td {
		padding: 10px;
		vertical-align: top;
	}
	
	#extra {
		display: inline-block;
	}
</style>
</html>
<!-- 
	Copyright © 2014 Miha Frangež ("franga2000")
		http://franga2000.com 
-->