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

session_start();

if (!isset($_SESSION['cart'])) 
{
  $_SESSION['cart']=array(); 
}

if (!isset($_SESSION['loggedin'])) 
{
  $_SESSION['loggedin'] = '0'; 
}
?>

<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 'navigation-bar.php'; ?>
</div>
	
<div id="aside">
	<!--Links for navigation-->
	<a href="product-list.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)) {

$Word = $_POST['Word'];

$con = mysql_connect("localhost","*****","*****");

if (!$con)
	{
	die('Could not connect: ' . mysql_error());
	}

	mysql_select_db("university", $con);
	
	//sql query string
	$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 align='center'  cellspacing='10' cellpadding='5'>";
echo "<tr bgcolor='#e1e0e0'>";

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


//item thumbnail and special offer stamp
if ($row['ItemSpecialOffer'] != '0')
{ 
echo "<td width='150' class=border background='images/special_offer.png' ";
echo "style='background-repeat:no-repeat; background-position:left top;' align='center'><br>";
}
else
{
echo "<td width='150' class=border align='center'>";
}
echo "<a href=\"images/";
echo $row['ItemPicture1'];
echo "\">";
echo "<img width='100' src=\"images/";
echo $row['ItemPicture1'];
echo "\" >";
echo "</a>";
echo "</p>";

//Item price
echo "<b><span class='red'>&#163;";
echo $row['ItemPrice'];
echo "</span></b>";

//item title
echo "<br>";
echo "<a href=\"details.php?id=";
echo $row['ItemID'];
echo "\">";
echo $row['ItemName'];
echo "</a><br>";


//Item CPU and MEM
echo "<span class='blue'><br>";
echo $row['ItemCpu'];
echo "<br>";
echo $row['ItemMem'];
echo " RAM";
echo "</span>";

//Details button
echo "<br><a href=\"details.php?id=";
echo $row['ItemID'];
echo "\">";
echo "<img width='66' src=\"images/Details-button.PNG";
echo "\" >";
echo "</a>";

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

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

//close sql connection
mysql_close($con);

} else {
?>

<!--form with search field-->
<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>
</div>
	

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

