<?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>The search function searches through the given word from the name, category, 
	type, operating system, the processor, hard disc drive, memory, and screen size
	of the products. If it finds any match it will display these products.</p>
	</fieldset><br>
</div>
	
<div id="content">

<br>
<fieldset style="width:90%"><legend>SEARCH</legend>

<?php
if(!empty($_POST)) {

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

	mysql_select_db("university", $con);
	
	//get searched word
	$word = $_POST['Word'];
	
	//sql command
	$sql="SELECT * from natty 
	WHERE ItemAvailable=1 AND
	ItemName LIKE '%$Word%' OR
	ItemCategory LIKE '%$Word%' OR
	ItemBrand LIKE '%Word%' OR
	ItemOpSys LIKE '%$Word%' OR
	ItemCpu LIKE '%$Word%' OR
	ItemHdd LIKE '%$Word%' OR
	ItemMem LIKE '%$Word%' OR
	ItemScreenSize LIKE '%$Word%' ";
	
	$result = mysql_query($sql);
	
echo "We found the follows: to <span class='red'>&#34;" . $Word . "&#34;</span> word.<hr/>";
	

echo "<table border='1' cellpadding='5'>";

echo "
	<tr><td width='200' align='center'><b>Name</b></td>
	<td width='70' align='center'><b>Picture</b></td>
	<td width='70' align='center'><b>Price</b></td>
	<td width='90' align='center'><b>Update Link</b></td>
	<td width='90' align='center'><b>Delete Link</b></td>
	<td width='100' align='center'><b>In Catalogue</b></td></tr>
	";

$i=0;
while ($row = mysql_fetch_array($result))
{

if ($i % 2 == 0)
{
echo "<tr bgcolor='#e1e0e0'>";
}
else
{
echo "<tr bgcolor='#f7f7f7'>";
}


//item title
if ($row['ItemSpecialOffer'] != '0')
{ 
echo "<td width='160' align='right' background='../images/special_offer.png' ";
echo "style='background-repeat:no-repeat;background-position:left top;' ><br><br>";
}
else
{
echo "<td width='160'>";
}
echo "<b>";
echo "<a href=\"details.php?id=";
echo $row['ItemID'];
echo "\">";
echo $row['ItemName'];
echo "</a>";
echo "</b></td>";

//item thumbnail
echo "<td width='70' align='center'>";
echo "<a href=\"../images/";
echo $row['ItemPicture1'];
echo "\">";
echo "<img width='60' src=\"../images/";
echo $row['ItemPicture1'];
echo "\" >";
echo "</a>";
echo "</p>";
echo "</td>"; 

//Item price
echo "<td width='70' align='center'>";
echo $row['ItemPrice'];
echo "</td>";


//Update item
echo "<td width='90' align='center'>";
echo "<a href=\"update-form.php?id=";
echo $row['ItemID'];
echo "\">";
echo ' Update ';
echo "</a>";
echo "</td>";

//Delete item
echo "<td width='90' align='center'>";
echo "<a href=\"delete.php?id=";
echo $row['ItemID'];
echo "\">";
echo ' Delete ';
echo "</a>";
echo "</td>";

//Item in catalogue
echo "<td width='100' align='center'>";
if ($row['ItemAvailable'] != '0'){ echo "Yes";} else { echo "No";}
echo "</td>";

echo "</tr>";
$i++;
}
echo "</table>";

mysql_close($con);

} else {
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Word: <input type="text" size="40" name="Word">
<input type="submit" name="Submit" value="Search">
</form>

<?php } ?>

</fieldset>
</div>

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

</div>
</body>
</html>
	

