<?php
//session
session_start();
include ("connect.php");
$username = $_SESSION['staff'];

$searchBy = $_GET["searchBy"];
$keyword = $_GET["keyword"];

if($_GET["sort"]!=""){
$sort = $_GET["sort"];
}else{
$sort = num;
}

if($_SESSION['staff']!= null)
{
?>

<html>
<head>
<title>Daily Bookstore - Management System</title>
<!--include css file-->
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="paginate.css">
</head>

<body>

<?php
include ("stafffunctionbar.php");
?>

<center>
<form action="book.php" name="searchform" method="GET">
Search:<input type="text" size="100" name="keyword" value="Type your keyword here."/>

<select name="searchBy">
	<option value="">Select One</option>
	<option value="itemAuthor">Author</option>
	<option value="itemPublisher">Publisher</option>
	<option value="itemName">Book Name</option>
	<option value="itemCategory">Category</option>
	</select>

<input type="submit" name="search" value="Search"/>
</form>

<div id="mainpage">
<?php
include("bookfunction.php")
?>
</fieldset>
</td>

<td width="75%">

<?php
include ("connect.php");
if($_GET["search"] == "Search")
{	
	$searchBy = $_GET["searchBy"];
	$keyword = $_GET["keyword"];
	if($_GET["sort"]!=""){
	$sort = $_GET["sort"];
	}else{
	$sort = num;
	}
	if(($keyword=="")||($searchBy=="")){
	echo "<script language='javascript'>alert('Please insert your keyword and search category.')</script>";
	echo "<script language='javascript'>window.location='book.php'</script>"; 
	}else{
	$result = mysql_query("SELECT * FROM item WHERE ".$searchBy." LIKE '%".$keyword."%' ORDER BY ".$sort."");
	
}
}
else if($_GET["reset"] == "Reset Result")
{
	$result = mysql_query("SELECT * FROM item ORDER BY num");
	
}
else
{
	$result = mysql_query("SELECT * FROM item ORDER BY ".$sort."");   
	
}
include ("stockbook.php");
?>

</td>
</tr>
</table>
</center>

<?php
}else{
	echo "<script language='javascript'>alert ('Please login.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>
<hr/>

<center>
<div id="bottom">
<br/>
Copyright &#169; with Tian Tian Bookstore 2011. All Rights Reserved.
<br/>
Website:<a href="../bookstore" target="_blank">www.dailybook.com.my
</div>
</center>

</body>
</html>