<?Php
/*
* @author Istvan Franko
* @copyright 2014
*/

session_start();

if (!isset($_SESSION['cart'])) 
{
  $_SESSION['cart']=array(); 
}

if (!isset($_SESSION['loggedin'])) 
{
  $_SESSION['loggedin'] = '0'; 
}
?>

<html>

<?php include 'head.php'; ?>

	
<div id="aside">
	<!--Link for navigation-->
	<a href="product-list.php"><p style="text-align:center">Back to list</a></p>		

	<br><fieldset style="width:85%"><legend>HELP</legend>
	<p>Your orders are listed here.</p>
	<p>Here you can check them with the <span class="red">-Details-</span> links. </p>
	</fieldset><br>
</div>

<div id="content">

<br>
<fieldset style="width:95%"><legend>ORDER LIST</legend><br>

<?php

$con = mysql_connect("localhost","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("university", $con);

//Get email address from user table 
$userid = $_SESSION['loggedin'];

$query = mysql_query("SELECT * FROM users WHERE UserID='$userid'");
$row = mysql_fetch_object($query);
echo mysql_error();

//get the value of each column and add to local variables
$Email = $row->Email;

//sql command
$sql = mysql_query("SELECT * FROM natty_orders 
	WHERE OrderEmail LIKE '%$Email%'");


//display a table
echo "<table align='center' border='1'>";

//table head
echo "
	<tr><td width='70'><b>Order ID</b></td>
	<td width='150'><b>Customer Name</b></td>
	<td width='180'><b>Customer Email</b></td>
	<td width='120' align='center'><b>Details Link</b></td>
	<td width='80' align='center'><b>Order State</b></td></tr>
	";

$i=0;

//loop for sql result
while($row = mysql_fetch_array($sql))
{

if ($i % 2 == 0)
{
echo "<tr bgcolor='#e1e0e0'>";
}
else
{
echo "<tr bgcolor='#f7f7f7'>";
}


//Order ID
echo "<td width='70'>";
echo $row['OrderNum'];
echo "</td>";

//Customer Name
echo "<td width='150'>";
echo $row['OrderName'];
echo "</td>";

//Customer Email
echo "<td width='180'>";
echo $row['OrderEmail'];
echo "</td>";


//Details Link
echo "<td width='120' align='center'>";
echo "<a href=\"order-details.php?id=";
echo $row['OrderNum'];
echo "\">";
echo ' Details ';
echo "</a>";
echo "</td>";

//Order State
echo "<td width='80' align='center'>";
echo $row['OrderState'];
echo "</td>";

echo "</tr>";
$i++;
}
echo "</table><br>";


//close connection
mysql_close($con);

?>

</fieldset>
</div>

<div id="footer">
<p align="center">Copyright &#169; Istvan Franko, 2014</p>
</div>


</div>
</body
</html>