<?php
session_name('library');
session_start();

include("functions.php");
head('List of My Orders');
?>

<body>
<div id="main">

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

	<div id="entire_panel">
		<h1>Zoznam výpožičiek</h1> 
		<?php
		if (isset($_SESSION['user'])) {
		
					$link = connect_db();
					$sql = "SELECT * FROM book_orders WHERE uid = '".$_SESSION['uid']."'";
					$result = mysql_query($sql, $link);
					if ($result) {
						echo '<table border="1" class="center_page">';
						echo '<tr><th>&nbsp;ID&nbsp;</th><th>&nbsp;NÁZOV&nbsp;</th><th>&nbsp;AUTOR&nbsp;</th><th>&nbsp;DÁTUM VÝPOŽIČKY&nbsp;</th><th>&nbsp;DÁTUM VRÁTENIA&nbsp;</th><th>&nbsp;STAV PÔŽIČKY&nbsp;</th></tr>';
						while ($row = mysql_fetch_assoc($result)) {
							echo '<tr><td>&nbsp;' . $row['book_id'] . '&nbsp;</td>';
							$sql2 = "SELECT * FROM books WHERE id_book = '".$row['book_id']."'";
							$result2 = mysql_query($sql2, $link);
							$row2 = mysql_fetch_assoc($result2);
							echo '<td>&nbsp;' . $row2['name'] . '&nbsp;</td><td>&nbsp;' . $row2['author'] . '&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 '<img src="images/waiting.png" height="32" width="32">';
							} else {
								echo '<img src="images/ok.png" height="32" width="32">';
							}
							echo '</td></tr>';
						}
						echo '</table><br /><br />';
						echo '<p id="bold">Celkový počet vypožičaných publikácii: ' . 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><strong>K tejto stránke nemáte prístup. Najprv sa musíte prihlásiť.</strong></p>'; 
		}
		
		?>
		
		</div>


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

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