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

<html>
<body>

<fieldset style="width:85%"><legend>FILTERS</legend>

<form  method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<?php
$con = mysql_connect("localhost","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("university", $con);
?>

<br>
<!--HTML form for item order inputs-->
Order: <select name="OrderBy" style="width: 60px;">
<option value="ItemPrice ASC">Price Low-High</option>
<option value="ItemPrice DESC">Price High-Low</option>
<option value="ItemName ASC">ABC</option>
<option value="ItemName DESC">ZYX</option>
<option value="ItemID" selected>ID</option>
</select><br><br>

<!--HTML form for item brand inputs, has build from sql table-->
Brand: 
<select name="Brand" style="width: 60px;">
<option value="%" selected>All</option>
<?php
$sql = mysql_query("SELECT ItemBrand FROM natty WHERE ItemCategory='$cat' AND ItemAvailable=1")  or die(mysql_error());  

$brand = array();
while ($row = mysql_fetch_array($sql)) 
{ 
if (!(in_array($row['ItemBrand'],$brand)))
{ 
array_push($brand,$row['ItemBrand']);
}
}
asort($brand);
foreach ($brand as $key => $val)
{
echo "<option value=".$val.">".$val."</option>"; 
}
?>
</select><br><br>

<!--HTML form for item software inputs, has build from sql table-->
Software: 
<select name="Software" style="width: 60px;">
<option value="%" selected>All</option>
<?php
$sql = mysql_query("SELECT ItemOpSys FROM natty WHERE ItemCategory='$cat' AND ItemAvailable=1")  or die(mysql_error());  

$software = array();
while ($row = mysql_fetch_array($sql)) 
{ 
if (!(in_array($row['ItemOpSys'],$software)))
{ 
array_push($software,$row['ItemOpSys']);
}
}
asort($software);
foreach ($software as $key => $val)
{
echo "<option value=".$val.">".$val."</option>"; 
}
?>
</select><br><br>

<!--HTML form for item processor inputs, has build from sql table-->
CPU: 
<select name="Cpu" style="width: 60px;">
<option value="%" selected>All</option>
<?php
$sql = mysql_query("SELECT ItemCpu FROM natty WHERE ItemCategory='$cat' AND ItemAvailable=1")  or die(mysql_error());  

$cpu = array();
while ($row = mysql_fetch_array($sql)) 
{ 
if (!(in_array($row['ItemCpu'],$cpu)))
{ 
array_push($cpu,$row['ItemCpu']);
}
}
asort($cpu);
foreach ($cpu as $key => $val)
{
echo "<option value=".$val.">".$val."</option>"; 
}
?>
</select><br><br>

<!--HTML form for item memory inputs, has build from sql table-->
Memory: 
<select name="Mem" style="width: 60px;">
<option value="%" selected>All</option>
<?php
$sql = mysql_query("SELECT ItemMem FROM natty WHERE ItemCategory='$cat' AND ItemAvailable=1")  or die(mysql_error());  

$memory = array();
while ($row = mysql_fetch_array($sql)) 
{ 
if (!(in_array($row['ItemMem'],$memory)))
{ 
array_push($memory,$row['ItemMem']);
}
}
asort($memory);
foreach ($memory as $key => $val)
{
echo "<option value=".$val.">".$val."</option>"; 
}
?>
</select><br><br>


<!--HTML form for item HDD inputs, has build from sql table-->
HDD: 
<select name="Hdd" style="width: 60px;">
<option value="%" selected>All</option>
<?php
$sql = mysql_query("SELECT ItemHdd FROM natty WHERE ItemCategory='$cat' AND ItemAvailable=1")  or die(mysql_error());  

$hdd = array();
while ($row = mysql_fetch_array($sql)) 
{ 
if (!(in_array($row['ItemHdd'],$hdd)))
{ 
array_push($hdd,$row['ItemHdd']);
}
}
asort($hdd);
foreach ($hdd as $key => $val)
{
echo "<option value=".$val.">".$val."</option>"; 
}
?>
</select><br><br>

<!--HTML form for item screen size inputs, has build from sql table-->
Screen: 
<select name="Screen" style="width: 60px;">
<option value="%" selected>All</option>
<?php
$sql = mysql_query("SELECT ItemScreenSize FROM natty WHERE ItemCategory='$cat' AND ItemAvailable=1")  or die(mysql_error());  

$screen = array();
while ($row = mysql_fetch_array($sql)) 
{ 
if (!(in_array($row['ItemScreenSize'],$screen)))
{ 
array_push($screen,$row['ItemScreenSize']);
}
}
asort($screen);
foreach ($screen as $key => $val)
{
echo "<option value=".$val.">".$val."</option>"; 
}
?>
</select><br><br>

<input type="hidden" name="cat" value="<?php echo $cat; ?>">
<input type="submit" name="Submit" value="Send"><br>
<?php
mysql_close($con);
?>

</form>
<hr/>
<!--Links for navigation-->
<a href="catalogue.php"><p style="text-align:center">Back to catalogue</a></p>
<a href="product-list.php"><p style="text-align:center">All items</a></p>
</fieldset>

</body>
</html>