<?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">
	<!--Links 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 edit this item's details on this page.</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 WHERE ItemID=$id ");
$row=mysql_fetch_object($query);
echo mysql_error();


//get the value of each column and add to local variables
$ItemID = $row->ItemID;
$ItemName = $row->ItemName;
$ItemInMbro = $row->ItemInMbro;
$ItemInStockton = $row->ItemInStockton;
$ItemAvailable = $row->ItemAvailable;
$ItemSpecialOffer = $row->ItemSpecialOffer;
$ItemPrice = $row->ItemPrice;
$ItemCategory = $row->ItemCategory;
$ItemBrand = $row->ItemBrand;
$ItemModelNum = $row->ItemModelNum;
$ItemOpSys = $row->ItemOpSys;
$ItemCpu = $row->ItemCpu;
$ItemMem = $row->ItemMem;
$ItemHdd = $row->ItemHdd;
$ItemScreenSize = $row->ItemScreenSize;
$ItemShortDesc = $row->ItemShortDesc;
$ItemDesc = $row->ItemDesc;
$ItemPicture1 = $row->ItemPicture1;
$ItemPicture2 = $row->ItemPicture2;
$ItemPicture3 = $row->ItemPicture3;
$ItemPicture4 = $row->ItemPicture4;
$ItemPicture5 = $row->ItemPicture5;
$ItemOfficialUrl = $row->ItemOfficialUrl;

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

<br>
<fieldset style="width:90%"><legend>UPDATE AN ITEM</legend>

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

Item ID: <input type="text" name="ItemID" size="20" value="<?php echo $ItemID; ?>" readonly="readonly"><span class="red"> -readonly</span><br><br>
Item name: <input type="text" name="ItemName" size="50" value="<?php echo $ItemName; ?>"><br><br>
Item in Mbro: <input type="text" name="ItemInMbro" size="20" value="<?php echo $ItemInMbro; ?>"><span class="red"> -only numbers allowed</span><br><br>
Item in Stockton: <input type="text" name="ItemInStockton" size="20" value="<?php echo $ItemInStockton; ?>"><span class="red"> -only numbers allowed</span><br><br>
Item available: <input type="radio" name="ItemAvailable" value="1" <?php if ($ItemAvailable != "0") {echo "checked";} ?>>Yes
				<input type="radio" name="ItemAvailable" value="0" <?php if ($ItemAvailable != "1") {echo "checked";} ?>>No<span class="red"> -you must choose one of them</span><br><br>
Special Offer: <input type="radio" name="ItemSpecialOffer" value="1" <?php if ($ItemSpecialOffer != "0") {echo "checked";} ?>>Yes
				<input type="radio" name="ItemSpecialOffer" value="0" <?php if ($ItemSpecialOffer != "1") {echo "checked";} ?>>No<span class="red"> -you must choose one of them</span><br><br>
Price: <input type="text" name="ItemPrice" size="20" value="<?php echo $ItemPrice; ?>"><span class="red"> -only double allowed, for example 199.99</span><br><br>
Category: 	<select name="ItemCategory">
			<?php 
			if ($ItemCategory == 'Laptop')
			{
			echo "<option value='Laptop' selected='selected'>Laptop</option>";
			}
			else
			{
			echo "<option value='Laptop'>Laptop</option>";
			}
			
			if ($ItemCategory == 'Netbook')
			{
			echo "<option value='Netbook' selected='selected'>Netbook</option>";
			}
			else
			{
			echo "<option value='Netbook'>Netbook</option>";
			}

			if ($ItemCategory == 'Tablet')
			{
			echo "<option value='Tablet' selected='selected'>Tablet</option>";
			}
			else
			{
			echo "<option value='Tablet'>Tablet</option>";
			}
			if ($ItemCategory == 'E-reader')
			{
			echo "<option value='E-reader' selected='selected'>E-reader</option>";
			}
			else
			{
			echo "<option value='E-reader'>E-reader</option>";
			}
			?>

			</select><br><br>

Brand: <input type="text" name="ItemBrand" size="40" value="<?php echo $ItemBrand; ?>"><br><br>
Model Number: <input type="text" name="ItemModelNum" size="40" value="<?php echo $ItemModelNum; ?>"><br><br>
Operation System: <input type="text" name="ItemOpSys" size="60" value="<?php echo $ItemOpSys; ?>"><br><br>
CPU: <input type="text" name="ItemCpu" size="40" value="<?php echo $ItemCpu; ?>"><br><br>
Memory: <input type="text" name="ItemMem" size="20" value="<?php echo $ItemMem; ?>"><br><br>
HDD Size: <input type="text" name="ItemHdd" size="20" value="<?php echo $ItemHdd; ?>"><br><br>
Screen Size: <input type="text" name="ItemScreenSize" size="40" value="<?php echo $ItemScreenSize; ?>"><br><br>
Short Description: <br><textarea name="ItemShortDesc" rows="5" cols="70" ><?php echo $ItemShortDesc; ?></textarea><br><br>
Description: <br><textarea name="ItemDesc" rows="10" cols="70" ><?php echo $ItemDesc; ?></textarea><br><br>
<span class="red">For the pictures only file names allowed, for example image.jgp</span><br><br>
Picture: <input type="text" name="ItemPicture1" size="40" value="<?php echo $ItemPicture1; ?>"><br><span class="red"> the first picture must be .png with transparent background</span><br><br>
Picture: <input type="text" name="ItemPicture2" size="40" value="<?php echo $ItemPicture2; ?>"><br><br>
Picture: <input type="text" name="ItemPicture3" size="40" value="<?php echo $ItemPicture3; ?>"><br><br>
Picture: <input type="text" name="ItemPicture4" size="40" value="<?php echo $ItemPicture4; ?>"><br><br>
Picture: <input type="text" name="ItemPicture5" size="40" value="<?php echo $ItemPicture5; ?>"><br><br>
Official UR: <input type="text" name="ItemOfficialUrl" size="60" value="<?php echo $ItemOfficialUrl; ?>"><br><span class="red"> whole URL eg http://wwww.example.com</span><br><br>





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

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

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


</div>
</body
</html>
