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

session_start();

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

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

<html>

<?php include 'head.php'; ?>


<div id="aside">
 <?php include 'filter.php'; ?>
 <br>
 <fieldset style="width:85%"><legend>HELP</legend>
 <p>Special offers are listed on this page. You can check all the special offers.</p> 
 <p>The products listed here stand out for their good price performance.</p> 
 <p>With the filter found at the top, you can further categorise these goods.</p>
 </fieldset><br>
 </div>

<div id="content">
<br>
<h1> WELCOME TO OUR WEBSITE </h1><hr/>

<fieldset style="width:95%"><legend>SPECIAL OFFERS</legend>
<?php

//define variables 
$OrderBy = "ItemID";
$Category = "%";
$Brand = "%";
$Software = "%";
$Cpu = "%";
$Mem = "%";
$Hdd = "%";
$Screen = "%";

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
  $OrderBy = test_input($_POST["OrderBy"]);
  $Category = test_input($_POST["Category"]);
  $Brand = test_input($_POST["Brand"]);
  $Software = test_input($_POST["Software"]);
  $Cpu = test_input($_POST["Cpu"]);
  $Mem = test_input($_POST["Mem"]);
  $Hdd = test_input($_POST["Hdd"]);
  $Screen = test_input($_POST["Screen"]);  
}

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

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

mysql_select_db("university", $con);

//sql query
$result = mysql_query("
SELECT * FROM natty 
WHERE ItemAvailable=1 AND
ItemSpecialOffer=1 AND 
ItemCategory LIKE '%$Category%' AND
ItemBrand LIKE '%$Brand%' AND
ItemOpSys LIKE '%$Software%' AND
ItemCpu LIKE '%$Cpu%' AND
ItemMem LIKE '%$Mem%' AND
ItemHdd LIKE '%$Hdd%' AND
ItemScreenSize LIKE '%$Screen%' 
ORDER BY $OrderBy");

echo "<table align='center'  cellspacing='10' cellpadding='5'>";
echo "<tr bgcolor='#e1e0e0'>";

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


//item thumbnail
echo "<td width='150' class=border background='images/special_offer.png' ";
echo "style='background-repeat:no-repeat; background-position:left top;' align='center'><br>";
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);

?>
</fieldset>

</div>

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

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