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

include ("connect.php");
	$leaveNo = $_POST["leaveNo"];
	$leaveApprove = $_POST["leaveApprove"];
	
	if($_POST["Submit"] == "Submit")
	{
	$result = mysql_query("UPDATE staffleave SET leaveApprove='$leaveApprove' WHERE leaveNo = '$leaveNo'");
	
	
	$db = mysql_close();
	echo "<script language='javascript'>alert('Leave Application is updated.')</script>";
	echo "<script language='javascript'>window.location='leavemain.php'</script>";
}
	
if($_POST["Cancel"] == "Cancel")
{
	echo "<script language='javascript'>window.location='leavemain.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"/>

<script language="Javascript">
	function showPreview(ele)
	{
		document.addbook.imgAvatar.src=ele.value;
	}
</script>
</head>

<body>

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

<center>
<h2>Daily Bookstore Management - Apply Leave</h2>
</center>

<div id="mainpage">
<table width="90%">
<tr>
<td width="15%" valign="top">
<fieldset>
<legend><img src="Picture/leave.gif" width="30" height="30">Leave</legend>
<table>
<td valign="top">
<a href="leavemain.php"><img src="Picture/leave.gif" width="30" height="30" alt="leave"><a href="leavemain.php">New Leave List</a><br/>
<br/>
<a href="addleave.php"><img src="Picture/apply.gif" width="30" height="30" alt="apply"><a href="addleave.php">Apply Leave</a><br/>
<br/>
<a href="leaveoldlist.php"><img src="Picture/record.gif" width="30" height="30" alt="apply"><a href="leaveoldlist.php">Leave Record</a><br/>
</td>
</tr>
</table>
</fieldset>
</td>

<td width="75%">
<center>
<form name="salarypay" method="post">
<fieldset style="width:80%">
<legend><img src="Picture/leave.gif" width="30" height="30">Apply Leave</legend>

<table align="center">
<?php
include("connect.php");
$leaveNo = $_GET['leaveNo'];
$result = mysql_query("SELECT * FROM staffLeave WHERE leaveNo = '$leaveNo'");

$row = mysql_fetch_array($result);

echo "<tr>";
echo "<td>Form ID: </td>";
echo "<td>";
echo "<input type='hidden' name='leaveNo' ID='leaveNo' value='$leaveNo'>$leaveNo";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Your Name: </td>";
echo "<td>".$row['staffName']."";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>Period: </td>";
echo "<td>".$row['leaveStartDate']." To ".$row['leaveEndDate']."</td>";
echo "</tr>";

if($row['leaveStartTime'] != '00:00:00'){
echo "<tr>";
echo "<td>Time: </td>";
echo "<td>".$row['leaveStartTime']." To ".$row['leaveEndTime']."</td>";
echo "</tr>";
}else{
}

echo "<tr>";
echo "<td>Reason: </td>";
echo "<td>".$row['leaveReason']."</td>";
echo "</tr>";
?>

<tr>
<td>Approve: </td>
<td>
<select name="leaveApprove">
<option value="">Choose One</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</td>
</tr>

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

</table>
</fieldset>
</form>
</center>
</body>
</html>
<?php
}else{
	echo "<script language='javascript'>alert ('Please login.')</script>";
	echo "<script language='javascript'>window.location='index.php'</script>";
}
?>