<?php
//create session
session_start();
session_register('staff');
session_register('staff_level');
session_register('session_staffID');

if(isset($_POST["submit"]))
{
	$staffID = $_POST["staffID"];
	$staffPassword = $_POST["staffPassword"];
	
	include ("connect.php");
	
	if($staffID!= "" && $staffPassword != "")
	{
		$result =  mysql_query("SELECT staffID, staffPassword, staffstatus FROM staff WHERE staffID = '$staffID' AND staffPassword = '$staffPassword' AND staffstatus = 'Available'"); 
		if(mysql_num_rows($result)>0)
		{
			$validate = mysql_fetch_assoc($result);
			//$validate = $result->fetch_assoc();
			$_SESSION['staff'] = $validate['staffID'];
			$_SESSION['staff_level'] = "staff";
			$_SESSION['session_id'] = session_id;
			echo "<script language='javascript'>window.location='cashiermain.php'</script>"; 
		}
		
	}
}
?>

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

<!--form validation java script-->
<script type="text/javascript">
function validate_form()
{
	valid=true;
	
	if((document.loginForm.staffID.value=="")||(document.loginForm.staffPassword.value==""))
	{alert("Please fill your login details.");
		valid=false;}
	
}
</script>

<!--clock function-->
<script type="text/javascript">
function init ( )
{
  timeDisplay = document.createTextNode ( "" );
  document.getElementById("clock").appendChild ( timeDisplay );
}

function updateClock ( )
{
  var currentTime = new Date ( );

  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}

// -->
</script>
</head>

<body onload="updateClock(); setInterval('updateClock()', 1000 )">
<table border="0" width="100%">

<tr>
<td><img src="Picture/Logo.gif"></td>
</tr>

<tr>
<td>&nbsp;</td>
</tr>

<tr>
<td colspan="2"><h2>Daily Bookstore - Cashier System</h2></td>
<td align="right"><h3>Current Time:<span id="clock">&nbsp;</span></h3></td>
</tr>

</table>
<!--User login form-->
<form name="loginForm" method="post" onsubmit="return validate_form ( );">
<center>
<fieldset style="width:250pt">
<legend><img src="Picture/cashierlogin.gif" width="50" height="50">Staff Login</legend>

<table border="0" cellpadding="5" cellspacing="0" style="color:brown" align="center" frame="void" width="25%">

<tr>
<td colspan="4"><center>Cashier please login at here.</center></td>
</tr>

<tr>
	<td align="center">Staff ID: </td>
	<td><input type="text" name="staffID" maxlength="30"></td>
</tr>

<tr>
	<td align="center">Password: </td>
	<td><input type="password" name="staffPassword" maxlength="8"></td>
</tr>

<tr>
	<td>&nbsp;</td>
	<td align="right"><input type="submit" name="submit" value="Login">
	<input type="reset" name="reset" value="Reset"><td>
</tr>

</table>

</fieldset>
</center>
</form>

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