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

session_start();

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

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

<html>

<head>
<title>Natty Notebooks Inc.</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>

<body>

<div id="container">

	<div id="header">
	<! header picture in css >
	</div>
	
	<div id="navigation">
		<?php include 'navigation-bar.php'; ?>
	</div>
	
<div id="aside">
	<!--Link for navigation-->
	<a href="product-list.php"><p style="text-align:center">Back to list</a></p>
	
	<fieldset style="width:85%"><legend>HELP</legend>
	<p>Your order history is listed here. You can review the details.</p>
	</fieldset>
</div>

<div id="content">

<br>
<fieldset style="width:95%"><legend>CHECK OUT</legend>
<br>
<p><img width="120" src="images/shopping-cart.png" alt="Shopping Cart" style="float:left">


<?php

//get the ID from the querystring.

$id=$_GET['id']; //get the value from the address bar
if(!is_numeric($id))
{ //check is a number.
echo "Sorry, there appears to have been an error.";
echo "<a href='index.php'><p style='text-align:center'>Go back to home</a></p>";
exit;
}

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

mysql_select_db("university", $con);


$query=Mysql_query("SELECT * FROM natty_orders WHERE OrderNum=$id ");
$row=mysql_fetch_object($query);
echo mysql_error();


//get the value of each column and add to local variables
$OrderNum = $row->OrderNum;
$OrderName = $row->OrderName;
$OrderEmail = $row->OrderEmail;
$OrderPhone = $row->OrderPhone;
$OrderItemInCart = $row->OrderItemInCart;
$OrderTime = $row->OrderTime;
$OrderState = $row->OrderState;

//convert order time to UK date format
$newDate = date("d-m-Y", strtotime($OrderTime));


echo "You have " . $OrderItemInCart . " type item(s) in you order.</p><hr/><br><br><br>";

//loop for get required numbers 
if ($OrderItemInCart > 0)
	{
	$OrderItemID[0] = $row->OrderItemID1;
	$ItemNumMbro[0] = $row->OrderFromMbro1;
	$ItemNumStock[0] = $row->OrderFromStock1;
	}

if ($OrderItemInCart > 1)
	{
	$OrderItemID[1] = $row->OrderItemID2;
	$ItemNumMbro[1] = $row->OrderFromMbro2;
	$ItemNumStock[1] = $row->OrderFromStock2;
	}

if ($OrderItemInCart > 2)
	{
	$OrderItemID[2] = $row->OrderItemID3;
	$ItemNumMbro[2] = $row->OrderFromMbro3;
	$ItemNumStock[2] = $row->OrderFromStock3;
	}

if ($OrderItemInCart > 3)
	{
	$OrderItemID[3] = $row->OrderItemID4;
	$ItemNumMbro[3] = $row->OrderFromMbro4;
	$ItemNumStock[3] = $row->OrderFromStock4;
	}

if ($OrderItemInCart > 4) 
	{
	$OrderItemID[4] = $row->OrderItemID5;
	$ItemNumMbro[4] = $row->OrderFromMbro5;
	$ItemNumStock[4] = $row->OrderFromStock5;
	}	
	
for ($x=0; $x != $OrderItemInCart; $x++)
{
$id = $OrderItemID[$x];

$query=Mysql_query("SELECT * FROM natty WHERE ItemID=$id ");
$row=mysql_fetch_object($query);
echo mysql_error();

//display cart details in a table
echo"
<table border='0' align='center'  cellspacing='5' cellpadding='5' style='width:650px;'>
	<tbody>
		<tr bgcolor='#e1e0e0'>
			<td class=border colspan='3' style='text-align: center;'>
				<a href='details.php?id=$row->ItemID'><h2>$row->ItemName</h2></a></td>
		</tr>
		<tr bgcolor='#e1e0e0'>
			<td class=border colspan='1' rowspan='3' style='width: 130px;'>
				<a href='images/$row->ItemPicture1'><img width='120' src='images/$row->ItemPicture1'></img></a></td>
			<td class=border colspan='2' rowspan='1' style='width: 510px; text-align: center;'>
				<p>Ordered quantity from each stock</p></td>
		</tr>
		<tr bgcolor='#e1e0e0'>
			<td class=border style='width: 400px;'><p>
				From Middlesbrough Store</p></td>
			<td class=border style='width: 90px; text-align: center;'>
			<p>";
			echo $ItemNumMbro[$x];
			echo "
			</p></td>
		</tr>
		<tr bgcolor='#e1e0e0'>
			<td class=border style='width: 400px;'><p>
				From Stockton Store</p></td>
			<td class=border style='width: 90px; text-align: center;'>
			<p>";
			echo $ItemNumStock[$x];
			echo "
			</p></td>
		</tr>
		<tr bgcolor='#e1e0e0'>
			<td class=border style='width: 130px; text-align: center;'>
				<b><span class='red'>&#163;$row->ItemPrice</span></b></td>
			<td class=border colspan='2' rowspan='1' style='width: 400px;'><p>
				$row->ItemMem RAM and  $row->ItemHdd HDD</p></td>
		</tr>
		<tr bgcolor='#e1e0e0'>
			<td class=border style='width: 130px;'><p>
			State: ";
				echo $OrderState;
			echo "</p></td>
			<td class=border rowspan='1' style='width: 400px;'><p>
				Screen: $row->ItemScreenSize </p></td>
			<td class=border rowspan='1' style='width: 90px;'><p>
			";
				echo $newDate;
			echo "</p></td>
		</tr>
	</tbody>
</table><hr>
";
}

?>

</fieldset>

</div>

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


</div>

</body>
</html>