<?php
session_start();

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

if ($_POST["submit"] == 1)
{
	$staffid = $_POST["staffid"];
	$firstname = $_POST["firstname"];
	$lastname = $_POST["lastname"];
	$staffname = $_POST["staffname"];
	$staffpass = $_POST["password1"];
	$recep = $_POST["recep"];
	
	$query = "update staff set firstname='$firstname', lastname='$lastname', staffname='$staffname', recep='$recep' where staffid='$staffid'";
	mysql_query($query) or die (mysql_error());
	
	if ($staffpass)
	{
		$query = "update staff set staffpass='$staffpass' where staffid='$staffid'";
		mysql_query($query) or die (mysql_error());
	}
	
	header ("location: staff.php");
}
?>

<?php
include "header.php";

$staffid = $_POST["staffid"];

$query = "select firstname, lastname, staffname, recep from staff where staffid='$staffid'";
$result = mysql_query($query) or die (mysql_error());
if ($row = mysql_fetch_array($result))
{
	$firstname = $row[0];
	$lastname = $row[1];
	$staffname = $row[2];
	$recep = $row[3];
}
?>

<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 != 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="hidden" name="staffid" value="<?php echo $staffid; ?>"><input type="submit" value="Modify">&nbsp;<input type="reset" value="Cancel"></td>
  </tr>
</table>
</form>
</center>

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