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

session_start();
if (isset($_SESSION['adminlogin'])){
	//user in logen 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">
	<!--Link for navigation-->
	<a href="orders-list.php"><p style="text-align:center">Back to orders list</a></p>	
	
	<fieldset style="width:85%"><legend>HELP</legend>
	<p>You can see this page only if you updated an order in our shop.</p> 
	</fieldset><br>

</div>

<div id="content">
<br>
<fieldset style="width:95%"><legend>ORDER UPDATE</legend>

<?php

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

mysql_select_db("university", $con);

//get the value of each column and add to local variables
$OrderNum = $_POST['OrderNum'];
$OrderName = $_POST['OrderName'];
$OrderEmail = $_POST['OrderEmail'];
$OrderPhone = $_POST['OrderPhone'];
$OrderItemInCart = $_POST['OrderItemInCart'];
$OrderTime = $_POST['OrderTime'];
$OrderState = $_POST['OrderState'];

//if only 1 type item in onder
if ($OrderItemInCart > 0)
{ 
$OrderItemID1 = $_POST['OrderItemID1'];
$OrderFromMbro1 = $_POST['OrderFromMbro1'];
$OrderFromStock1 = $_POST['OrderFromStock1'];

$sql="UPDATE natty_orders SET OrderNum='$OrderNum', OrderName='$OrderName', OrderEmail='$OrderEmail',  OrderPhone='$OrderPhone',
OrderItemInCart='$OrderItemInCart', OrderItemID1='$OrderItemID1', OrderFromMbro1='$OrderFromMbro1', 
OrderFromStock1='$OrderFromStock1', OrderState='$OrderState'
WHERE OrderNum='$OrderNum' ";

if (!mysql_query($sql,$con))
{
die ('Error: ' . mysql_error());
}
}

//if more then 1 type items in order
if ($OrderItemInCart > 1)
{
$OrderItemID2 = $_POST['OrderItemID2'];
$OrderFromMbro2 = $_POST['OrderFromMbro2'];
$OrderFromStock2 = $_POST['OrderFromStock2'];
$sql="UPDATE natty_orders SET OrderItemID2='$OrderItemID2', OrderFromMbro2='$OrderFromMbro2', OrderFromStock2='$OrderFromStock2' 
WHERE OrderNum='$OrderNum' ";

if (!mysql_query($sql,$con))
{
die ('Error: ' . mysql_error());
}
}
if ($OrderItemInCart > 2)
{
$OrderItemID3 = $_POST['OrderItemID3'];
$OrderFromMbro3 = $_POST['OrderFromMbro3'];
$OrderFromStock3 = $_POST['OrderFromStock3'];
$sql="UPDATE natty_orders SET OrderItemID3='$OrderItemID3', OrderFromMbro3='$OrderFromMbro3', OrderFromStock3='$OrderFromStock3' 
WHERE OrderNum='$OrderNum' ";

if (!mysql_query($sql,$con))
{
die ('Error: ' . mysql_error());
}
}

//if more then 2 type items in order
if ($OrderItemInCart > 3)
{
$OrderItemID4 = $_POST['OrderItemID4'];
$OrderFromMbro4 = $_POST['OrderFromMbro4'];
$OrderFromStock4 = $_POST['OrderFromStock4'];
$sql="UPDATE natty_orders SET OrderItemID4='$OrderItemID4', OrderFromMbro4='$OrderFromMbro4', OrderFromStock4='$OrderFromStock4' 
WHERE OrderNum='$OrderNum' ";

if (!mysql_query($sql,$con))
{
die ('Error: ' . mysql_error());
}
}

//if more then 3 type item in order
if ($OrderItemInCart > 4)
{
$OrderItemID5 = $_POST['OrderItemID5'];
$OrderFromMbro5 = $_POST['OrderFromMbro5'];
$OrderFromStock5 = $_POST['OrderFromStock5'];
$sql="UPDATE natty_orders SET OrderItemID5='$OrderItemID5', OrderFromMbro5='$OrderFromMbro5', OrderFromStock5='$OrderFromStock5' 
WHERE OrderNum='$OrderNum' ";

if (!mysql_query($sql,$con))
{
die ('Error: ' . mysql_error());
}
}

echo "<h2>1 record was just updated in the database.</h2>";

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

</fieldset>
</div>

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


</div>
</body
</html>