<?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">
	<!--Link for navigation-->
	<a href="admin.php"><p style="text-align:center">Back to list</a></p>	
	
	<fieldset style="width:85%"><legend>HELP</legend>
	<p>You can see this page only if you updated an item in our shop.</p> 
	</fieldset><br>
</div>

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

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

mysql_select_db("university", $con);

//get  the values posted from the form (i.e. what user entered in the form) and add them to local variables
$ItemID = test_input($_POST["ItemID"]);
$ItemName = test_input($_POST["ItemName"]);
$ItemInMbro = test_input($_POST["ItemInMbro"]);
$ItemInStockton = test_input($_POST["ItemInStockton"]);
$ItemAvailable = test_input($_POST["ItemAvailable"]);
$ItemSpecialOffer = test_input($_POST["ItemSpecialOffer"]);
$ItemPrice = test_input($_POST["ItemPrice"]);
$ItemCategory = test_input($_POST["ItemCategory"]);
$ItemBrand = test_input($_POST["ItemBrand"]);
$ItemModelNum = test_input($_POST["ItemModelNum"]);
$ItemOpSys = test_input($_POST["ItemOpSys"]);
$ItemCpu = test_input($_POST["ItemCpu"]);
$ItemMem = test_input($_POST["ItemMem"]);
$ItemHdd = test_input($_POST["ItemHdd"]);
$ItemScreenSize = test_input($_POST["ItemScreenSize"]);
$ItemShortDesc = test_input($_POST["ItemShortDesc"]);
$ItemDesc = test_input($_POST["ItemDesc"]);
$ItemPicture1 = test_input($_POST["ItemPicture1"]);
$ItemPicture2 = test_input($_POST["ItemPicture2"]);
$ItemPicture3 = test_input($_POST["ItemPicture3"]);
$ItemPicture4 = test_input($_POST["ItemPicture4"]);
$ItemPicture5 = test_input($_POST["ItemPicture5"]);
$ItemOfficialUrl = test_input($_POST["ItemOfficialUrl"]);

function test_input($data)
{
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}

//replace single quotes from text field to insert to sql
$ItemShortDesc2 = str_replace("'", "''", $ItemShortDesc);
$ItemDesc2 = str_replace("'", "''", $ItemDesc);


$sql="UPDATE natty SET ItemName='$ItemName', ItemInMbro='$ItemInMbro', ItemInStockton='$ItemInStockton',  ItemAvailable='$ItemAvailable',
ItemSpecialOffer='$ItemSpecialOffer', ItemPrice='$ItemPrice', ItemCategory='$ItemCategory', 
ItemBrand='$ItemBrand', ItemModelNum='$ItemModelNum', ItemOpSys='$ItemOpSys', ItemCpu='$ItemCpu', 
ItemMem='$ItemMem', ItemHdd='$ItemHdd', ItemScreenSize='$ItemScreenSize', ItemShortDesc='$ItemShortDesc2', 
ItemDesc='$ItemDesc2', ItemPicture1='$ItemPicture1', ItemPicture2='$ItemPicture2', ItemPicture3='$ItemPicture3', 
ItemPicture4='$ItemPicture4', ItemPicture5='$ItemPicture5', ItemOfficialUrl='$ItemOfficialUrl'
WHERE ItemID='$ItemID' ";

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>