<?php
	session_name('library');
	session_start();
	
	include("functions.php");
	
	head('Orders List');
?>

<body>
<div id="main">

	<?php
		include("header.php");
		include("menu.php");
	?>

		
	

<div id="entire_panel">
		<h1>Výpis výpožičiek</h1>
		<?php
			 

if ($_SESSION['admin'] == 1) {
	
					$link = connect_db();
					$sql = "SELECT * FROM book_orders";
					$result = mysql_query($sql, $link);
					if ($result) {
						echo '<table border="1">';
						echo '<tr><th>&nbsp;ID&nbsp;</th><th>&nbsp;NÁZOV&nbsp;</th><th>&nbsp;AUTOR&nbsp;</th><th>&nbsp;USERNAME&nbsp;</th><th>&nbsp;DATE ORDERED&nbsp;</th><th>&nbsp;DATE BACK&nbsp;</th><th>&nbsp;STAV PÔŽIČKY&nbsp;</th><th>&nbsp;AKCIA&nbsp;</th></tr>';
						while ($row = mysql_fetch_assoc($result)) {
						
							$sql2 = "SELECT * FROM books WHERE id_book='" . $row['book_id'] . "'";
							$result2 = mysql_query($sql2, $link) or die(mysql_error());
							$row2 = mysql_fetch_assoc($result2);
							
							$sql3 = "SELECT * FROM users WHERE uid='" . $row['uid'] . "'";
							$result3 = mysql_query($sql3, $link) or die(mysql_error());
							$row3 = mysql_fetch_assoc($result3);
						
							echo '<tr><td>&nbsp;' . $row['id_order'] . '&nbsp;</td><td>&nbsp;' . $row2['name'] . '&nbsp;</td><td>&nbsp;' . $row2['author'] . '&nbsp;</td><td>&nbsp;' . $row3['username'] . '&nbsp;</td><td>&nbsp;';
							if ($row['provided'] == 1) { 
								echo $row['date_ordered'] . '&nbsp;</td><td>&nbsp;' . $row['date_back'];
							} else {
								echo '???&nbsp;</td><td>&nbsp;???';
							}
							echo '&nbsp;</td><td>';
							if ($row['provided'] == 0) {
								echo '<a href="accept_order.php?id=' . $row['id_order'] . '" title="Uprav"><img src="images/waiting.png" height="32" width="32"></a>';
							} else {
								echo '<img src="images/ok.png" height="32" width="32">';
							}
							echo '</td><td>';
							echo '<a href="remove_order.php?id=' . $row['id_order'] . '" title="Vymaž"><img src="images/delete.png" height="32" width="32"></a>';
							echo '</td></tr>';
						}
						echo '</table><br /><br />';
						echo '<p id="bold">Celkový počet momentálnych výpožičiek: ' . mysql_num_rows($result) . '</p><br/>';
						mysql_free_result($result);
					} else {
						echo '<p id="red">Nastal problém pri získavaní údajov z databázy - ' . mysql_errno($link) . ': ' . mysql_error($link) . '</p>';
					}
				mysql_close($link);
	
} else {
	echo '<p id="red">K tejto stránke nemáte dostatočné oprávnenia</p>';
}    
		?>				
</div>

	<?php include("footer.php"); ?>

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

