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

	$staffID = $_POST["staffID"];
	$staffName = $_POST["staffName"];
	$staffAddress = $_POST["staffAddress"];
	$staffPhone = $_POST["staffPhone"];
	$staffEmail = $_POST["staffEmail"];
	$staffDOB = $_POST["staffDOB"];
	$staffIC = $_POST["staffIC"];
	$staffSex = $_POST["staffSex"];
	$staffRace = $_POST["staffRace"];
	$staffMarital = $_POST["staffMarital"];
	$staffJobTitle = $_POST["staffJobTitle"];
	$staffCategory = $_POST["staffCategory"];
	$staffDateJoin = $_POST["staffDateJoin"];
	$staffSalary = $_POST["staffSalary"];
	$staffBank = $_POST["staffBank"];
	$staffAccount = $_POST["staffAccount"];
	$staffEPF = $_POST["staffEPF"];
	$staffSocso = $_POST["staffSocso"];
	$staffPassword = $_POST["staffPassword"];
	$staffstatus = $_POST["staffstatus"];
	$staffPayLeave = $_POST["staffPayLeave"];
	$leaveBalance = $_POST["leaveBalance"];

if($_POST["Save"] == "Save")
{
include ("connect.php");
	$result = mysql_query("UPDATE staff SET 
	staffName = '$staffName',
	staffAddress = '$staffAddress',
	staffPhone = '$staffPhone',
	staffEmail = '$staffEmail',
	staffDOB = '$staffDOB',
	staffIC = '$staffIC',
	staffSex = '$staffSex',
	staffRace = '$staffRace',
	staffMarital = '$staffMarital',
	staffJobTitle = '$staffJobTitle',
	staffCategory = '$staffCategory',
	staffDateJoin = '$staffDateJoin',
	staffSalary = '$staffSalary',
	staffBank = '$staffBank',
	staffAccount = '$staffAccount',
	staffEPF = '$staffEPF',
	staffSocso = '$staffSocso',
	staffPassword = '$staffPassword',
	staffPayLeave = '$staffPayLeave',
	leaveBalance = '$leaveBalance',
	staffstatus = '$staffstatus'
	WHERE staffID = '$staffID'");
	
	
	$db = mysql_close();
	echo "<script language='javascript'>alert('Staff Data Update success')</script>";
	echo "<script language='javascript'>window.location='stafflist.php'</script>";
}


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");
?>
</div>
</fieldset>
</td>
</tr>
</table>

<hr/>
<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");
$staffID=$_GET['staffID'];

$result = mysql_query("SELECT * FROM staff WHERE staffID = '$staffID'");

$row = mysql_fetch_array($result);

echo "<div id='mainpage'>";
echo "<form name='seditform' method='post'>";

echo "<fieldset style='width:70%'>";
echo "<legend><img src='Picture/admin.gif' width='30' height='30'>&nbsp;Edit Employee</legend>";
echo "<br/>";
echo "<center>";

echo "<table align='center'>";
echo "<tr>";
echo "<td>Staff ID: </td>";
echo "<td>".$row["staffID"]."<input type='hidden' name='staffID' value='".$row["staffID"]."'/>";
echo "<font color='red'>&nbsp;&nbsp;&nbsp;Staff ID cannot edited.</font>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Name: </td>";
echo "<td><input type='text' name='staffName' size='50' maxlength='50' value='".$row["staffName"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Address: </td>";
echo "<td><input type='text' name='staffAddress' size='50' maxlength='100' value='".$row["staffAddress"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Phone No: </td>";
echo "<td><input type='text' name='staffPhone' size='20' maxlength='15' value='".$row["staffPhone"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Email: </td>";
echo "<td><input type='text' name='staffEmail' size='20' maxlength=20' value='".$row["staffEmail"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>DOB: </td>";
echo "<td><input type='text' name='staffDOB' size=20' value='".$row["staffDOB"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>IC NO.: </td>";
echo "<td><input type='text' name='staffIC' size='20' maxlength='12' value='".$row["staffIC"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Gender: </td>";
echo "<td><input type='radio' name='staffSex' value='M'";
if($row["staffSex"]=="M")
{
echo "checked";
}else{
echo "";
}
echo "/>Male";

echo "<input type='radio' name='staffSex' value='F'";
if($row["staffSex"]=="F")
{
echo "checked";
}else{
echo "";
}
echo "/>Female";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Race: </td>";
echo "<td><name='staffRace' value='".$row["staffRace"]."'>";
echo "<select name='staffRace'>";
$sraceArray = array("Chinese", "Malay", "Indian", "Others");
for($i = 0; $i < 4 ; $i++)
{if($row["staffRace"] == $sraceArray[$i])
	{echo "<option selected>".$sraceArray[$i];
	}else
	{echo "<option>".$sraceArray[$i];
	}
}
echo "</select></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Marital: </td>";
echo "<td><input type='radio' name='staffMarital' value='Y'";
if($row["staffMarital"]=="Y")
{
echo "checked";
}else{
echo "";
}
echo "/>Yes";

echo "<input type='radio' name='staffMarital' value='N'";
if($row["staffMarital"]=="N")
{
echo "checked";
}else{
echo "";
}
echo "/>No";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Job Title: </td>";
echo "<td><input type='text' name='staffJobTitle' size='20' maxlength='20' value='".$row["staffJobTitle"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Job Category: </td>";
echo "<td><name='staffCategory' value='".$row["staffCategory"]."'>";
echo "<select name='staffCategory'>";
$scateArray = array("IT Staff", "Cashier", "Stock Control", "Management");
for($i = 0; $i < 4 ; $i++)
{if($row["staffCategory"] == $scateArray[$i])
	{echo "<option selected>".$scateArray[$i];
	}else
	{echo "<option>".$scateArray[$i];
	}
}
echo "</select></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Date Join: </td>";
echo "<td><input type='text' name='staffDateJoin' size='20' maxlength='20' value='".$row["staffDateJoin"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Base Salary: RM </td>";
echo "<td><input type='text' name='staffSalary' size='10' maxlength='5' value='".$row["staffSalary"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Bank: </td>";
echo "<td><name='staffBank' value='".$row["staffBank"]."'>";
echo "<select name='staffBank'>";
$sbankArray = array("Maybank", "CIMB", "RHB", "Hong Leong", "Other");
for($i = 0; $i < 5 ; $i++)
{if($row["staffBank"] == $sbankArray[$i])
	{echo "<option selected>".$sbankArray[$i];
	}else
	{echo "<option>".$sbankArray[$i];
	}
}
echo "</select></td>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Bank Account No.: </td>";
echo "<td><input type='text' name='staffAccount' size='20' maxlength='20' value='".$row["staffAccount"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>EPF: </td>";
echo "<td><input type='text' name='staffEPF' size='20' maxlength='20' value='".$row["staffEPF"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Socso: </td>";
echo "<td><input type='text' name='staffSocso' size='20' maxlength='20' value='".$row["staffSocso"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Pay Leave (Hours): </td>";
echo "<td><input type='text' name='staffPayLeave' size='20' maxlength='20' value='".$row["staffPayLeave"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Pay Leave Balance: </td>";
echo "<td><input type='text' name='leaveBalance' size='20' maxlength='20' value='".$row["leaveBalance"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Password: </td>";
echo "<td><input type='text' name='staffPassword' size='20' maxlength='20' value='".$row["staffPassword"]."'/></td>";
echo "</tr>";

echo "<tr>";
echo "<td>Status: </td>";
echo "<td><name='staffstatus' value='".$row["staffstatus"]."'>";
echo "<select name='staffstatus'>";
$statusArray = array("Available", "Cancel");
for($i = 0; $i < 2 ; $i++)
{if($row["staffRace"] == $statusArray[$i])
	{echo "<option selected>".$statusArray[$i];
	}else
	{echo "<option>".$statusArray[$i];
	}
}
echo "</select></td>";
echo "</tr>";

?>

<tr>
<td colspan="2" align="center"><input type="submit" name="Save" value="Save"></td>
</tr>
</table>
</center>

</div>
</fieldset>
</form>
</div>
</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>