<?php
session_start();

include "../functions.php";
checkAdmin(session_id());

if ($_POST["submit"] == 1)
{
	$firstname = $_POST["firstname"];
	$lastname = $_POST["lastname"];
	$staffname = $_POST["staffname"];
	$staffpass = $_POST["password1"];
	$recep = $_POST["recep"];
	
	$query = "insert into staff(firstname, lastname, staffname, staffpass, recep) values ('$firstname', '$lastname', '$staffname', '$staffpass', '$recep')";
	mysql_query($query) or die (mysql_error());
	header ("location: staff.php");
}

include "header.php";
?>

<script language="javascript">
function checkform(form)
{
	if (form.firstname.value=="")
	{
		alert ("please input first name");
		form.firstname.focus();
		return false;
	}
	if (form.lastname.value=="")
	{
		alert ("please input last name");
		form.lastname.focus();
		return false;
	}
	if (form.staffname.value=="")
	{
		alert ("please input access name");
		form.staffname.focus();
		return false;
	}
	if (form.password1.value=="")
	{
		alert ("please input password");
		form.password1.focus();
		return false;
	}
	if (eval(form.password1).value.length < 6)
	{
		alert ("password cannot be less than 6 characters");
		form.password1.value = "";
		form.password1.focus();
		return false;
	}
	if (form.password1.value != form.password2.value)
	{
		alert ("the two passwords you input are different");
		form.password1.value="";
		form.password2.value=""
		form.password1.focus();
		return false;
	}
}
</script>

<center>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" onsubmit="return checkform(this)">
<table  cellspacing=0 cellpadding=3 border=0>
  <tr>
    <td>First Name</td>
    <td><input type="text" name="firstname" value="<?php echo $firstname; ?>"></td>
  </tr>

  <tr>
    <td>last Name</td>
    <td><input type="text" name="lastname" value="<?php echo $lastname; ?>"></td>
  </tr>  

<tr>
    <td>Recep</td>
    <td><input type="checkbox" name="recep" value="1" <?php if ($recep == 1) echo "checked"; ?>></td>
  </tr>  
  
  <tr>
    <td>Access Name</td>
    <td><input type="text" name="staffname" value="<?php echo $staffname; ?>"></td>
  </tr>

  <tr>
    <td>Password</td>
    <td><input type="password" name="password1"></td>
  </tr>

  <tr>
    <td>Confirm Password</td>
    <td><input type="password" name="password2"></td>
  </tr>
   
  <tr>
    <td colspan=2 align="center"><input type="hidden" name="submit" value=1><input type="submit" value=" Add ">&nbsp;<input type="reset" value="Cancel"></td>
  </tr>
</table>
</form>
</center>

<?php
include "footer.php";
?>