<?php
session_start();
$username = $_SESSION['staff'];

if($_SESSION['staff']!= null)
{
?>
<html>
<head>
<title>Daily Bookstore - Management System</title>
<!--include css file-->
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>
</head>

<body>

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

<center>
<h2>Bookstore Staff List</h2>
</center>

<center>
<div id="mainpage">
<table width="90%">
<tr>
<td width="15%" valign="top">
<fieldset style="margin:0 5 0 0">
<legend><img src="Picture/admin.gif" width="30" height="30">Admin Control</legend>
<table>
<tr>
<td valign="top">
<a href="stafflist.php"><img src="Picture/list.gif" width="30" height="30" alt="admin control"><a href="stafflist.php">Staff List</a><br/>
<br/>
<a href="addstaff.php"><img src="Picture/addadmin.gif" width="30" height="30" alt="add staff"><a href="addstaff.php">Add Staff</a><br/>
<br/>
</td>
</tr>
</table>
</fieldset>
</td>

<td width="75%">

<?php
include("connect.php");

if($_POST["search"] == "Search")
{	
	$searchBy = $_POST["searchBy"];
	$keywords = $_POST["keywords"];
	$result = mysql_query("SELECT * FROM staff WHERE ".$searchBy." LIKE '%".$keywords."%' ORDER BY num");
	
}
else if($_POST["showAll"] == "Show All")
{
	$result = mysql_query("SELECT * FROM staff ORDER BY num");
	
}
else
{
	$result = mysql_query("SELECT * FROM staff ORDER BY num");
	
}

$num_results = mysql_num_rows($result);

echo "<p>Number of Staff(s) : ".$num_results."</p>";

echo "<table border='1' cellspacing='0' cellpadding='5' bordercolor='white' width='100%' align='center'>";
echo "<tr bgcolor='black' style='color:white'>";
echo "<td>num</td>";
echo "<td>Staff ID</td>";
echo "<td>Name</td>";
echo "<td>Phone</td>";
echo "<td>Job Title</td>";
echo "<td>Category</td>";
echo "<td>Edit Data</td>";
echo "<td>Delete Data</td>";
echo "</tr>";

for ($i=0; $i <$num_results; $i++)
{
	$row = mysql_fetch_array($result);
	echo "<tr>";
	echo "<td>".$row["num"]."</td>";
	echo "<td>".$row["staffID"]."</td>";
	echo "<td>".$row["staffName"]."</td>";
	echo "<td>".$row["staffPhone"]."</td>";
	echo "<td>".$row["staffJobTitle"]."</td>";
	echo "<td>".$row["staffCategory"]."</td>";
	echo "<td><a href='editstaff.php?staffID=".$row["staffID"]."&&username=$username'>Edit</a></td>";
	echo "<td><a href='staffdelete.php?staffID=".$row["staffID"]."&&username=$username'>Delete</a></td>";
	echo "</tr>";
}
echo "</table>";

$db = mysql_close();

?>

</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>