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

session_start();
if (isset($_SESSION['adminlogin'])){
	//user in logged in. Show a message on the screen
} else {
	//redirect the user to the login form.
	session_destroy();
	header('Location: index.php');
}
?>

<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 'admin-nav-bar.php'; ?>
</div>


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

	<br><fieldset style="width:85%"><legend>HELP</legend>
	<p>Here you can edit the order details.</p>
	<p><span class="red">If the item has been collected, we must change order state to -Collected- and update it.</span></p>
	</fieldset><br>
</div>

<div id="content">

<?php

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

mysql_select_db("university", $con);

//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.";
exit;
}

$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;
$OrderItemID1 = $row->OrderItemID1;
$OrderFromMbro1 = $row->OrderFromMbro1;
$OrderFromStock1 = $row->OrderFromStock1;
$OrderItemID2 = $row->OrderItemID2;
$OrderFromMbro2 = $row->OrderFromMbro2;
$OrderFromStock2 = $row->OrderFromStock2;
$OrderItemID3 = $row->OrderItemID3;
$OrderFromMbro3 = $row->OrderFromMbro3;
$OrderFromStock3 = $row->OrderFromStock3;
$OrderItemID4 = $row->OrderItemID4;
$OrderFromMbro4 = $row->OrderFromMbro4;
$OrderFromStock4 = $row->OrderFromStock4;
$OrderItemID5 = $row->OrderItemID5;
$OrderFromMbro5 = $row->OrderFromMbro5;
$OrderFromStock5 = $row->OrderFromStock5;
$OrderTime = $row->OrderTime;
$OrderState = $row->OrderState;

?> 

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

<form action="order-update.php" method="post">

<?php
echo "
Order Number: <input type='text' name='OrderNum' size='20' value='$OrderNum' readonly='readonly'><br><br>
User Name: <input type='text' name='OrderName' size='50' value='$OrderName'><br><br>
User Email: <input type='text' name='OrderEmail' size='60' value='$OrderEmail'><br><br>
User Phone: <input type='text' name='OrderPhone' size='20' value='$OrderPhone'><br><br>
Item in cart: <input type='text' name='OrderItemInCart' size='20' value='$OrderItemInCart' readonly='readonly'><br><br>
";
if ($OrderItemInCart > 0)
{ 
$query=Mysql_query("SELECT * FROM natty WHERE ItemID=$OrderItemID1");
$row=mysql_fetch_object($query);
echo mysql_error();
echo"
Ordered ItemID1: <input type='text' name='OrderItemID1' size='20' value='$OrderItemID1'>
<a href='details.php?id=$OrderItemID1'>$row->ItemName</a><br><br>
Ordered From Mbro1: <input type='text' name='OrderFromMbro1' size='20' value='$OrderFromMbro1'><br><br>
Ordered From Stock1: <input type='text' name='OrderFromStock1' size='20' value='$OrderFromStock1'><br><br>
";}
if ($OrderItemInCart > 1)
{ 
$query=Mysql_query("SELECT * FROM natty WHERE ItemID=$OrderItemID2");
$row=mysql_fetch_object($query);
echo mysql_error();
echo"
Ordered ItemID2: <input type='text' name='OrderItemID2' size='20' value='$OrderItemID2'>
<a href='details.php?id=$OrderItemID2'>$row->ItemName</a><br><br>
Ordered From Mbro2: <input type='text' name='OrderFromMbro2' size='20' value='$OrderFromMbro2'><br><br>
Ordered From Stock2: <input type='text' name='OrderFromStock2' size='20' value='$OrderFromStock2'><br><br>
";}
if ($OrderItemInCart > 2)
{ 
$query=Mysql_query("SELECT * FROM natty WHERE ItemID=$OrderItemID3");
$row=mysql_fetch_object($query);
echo mysql_error();
echo"
Ordered Item ID3: <input type='text' name='OrderItemID3' size='20' value='$OrderItemID3'>
<a href='details.php?id=$OrderItemID3'>$row->ItemName</a><br><br>
Ordered From Mbro3: <input type='text' name='OrderFromMbro3' size='20' value='$OrderFromMbro3'><br><br>
Ordered From Stock3: <input type='text' name='OrderFromStock3' size='20' value='$OrderFromStock3'><br><br>
";}
if ($OrderItemInCart > 3)
{ 
$query=Mysql_query("SELECT * FROM natty WHERE ItemID=$OrderItemID4");
$row=mysql_fetch_object($query);
echo mysql_error();
echo"
Ordered ItemID4: <input type='text' name='OrderItemID4' size='20' value='$OrderItemID4'>
<a href='details.php?id=$OrderItemID4'>$row->ItemName</a><br><br>
Ordered From Mbro4: <input type='text' name='OrderFromMbro4' size='20' value='$OrderFromMbro4'><br><br>
Ordered From Stock4: <input type='text' name='OrderFromStock4' size='20' value='$OrderFromStock4'><br><br>
";}
if ($OrderItemInCart > 4)
{ 
$query=Mysql_query("SELECT * FROM natty WHERE ItemID=$OrderItemID5");
$row=mysql_fetch_object($query);
echo mysql_error();
echo"
Ordered ItemID5: <input type='text' name='OrderItemID5' size='20' value='$OrderItemID5'>
<a href='details.php?id=$OrderItemID5'>$row->ItemName</a><br><br>
Ordered From Mbro5: <input type='text' name='OrderFromMbro5' size='20' value='$OrderFromMbro5'><br><br>
Ordered From Stock5: <input type='text' name='OrderFromStock5' size='20' value='$OrderFromStock5'><br><br>
";}
echo"
Order Time: <input type='text' name='OrderTime' size='40' value='$OrderTime' readonly='readonly'><br><br>


Order State:
<select name='OrderState'>
";
if ($OrderState=='Live')
{ echo "<option selected='selected' value='Live'>Live</option>";}
else { echo "<option value='Live'>Live</option>";}

if ($OrderState=='Expired')
{ echo "<option selected='selected' value='Expired'>Expired</option>";}
else { echo "<option value='Expired'>Expired</option>";}

if ($OrderState=='Collected')
{ echo "<option selected='selected' value='Collected'>Collected</option>";}
else { echo "<option value='Collected'>Collected</option>";}

echo"
</select><br><br>

<input type='submit' value='Update'>
";


//close the connection to the database.
mysql_close($con);
?>

</form>
</fieldset>
</div>

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


</div>
</body
</html>
