<?php
session_start();
include "conn.php";
isloggedin(session_id());
?>
<html><head><title>Generate Report</title><script language='javascript' src="js/popcalendar.js"></script></head>
<body>
<center>
<table width=80% cellspacing=1 cellpadding=3 border=0>
<form action=report.php method=post name=form1 target=_blank>
<tr>
<td width=1% nowrap><b>From:</b><br><input type="text" size=10 name="from" readonly onfocus='popUpCalendar(this, form1.from, "yyyy-mm-dd")'></td>
<td width=1% nowrap><b>To:</b><br><input type="text" size=10 name="to" readonly onfocus='popUpCalendar(this, form1.to, "yyyy-mm-dd")'></td>
<td width=1% nowrap><b>Type:</b><br><?php movetype() ?></td>
<td width=1% nowrap><b>Staff:</b><br><?php staff() ?></td>
<td width=1% nowrap valign=bottom><input type=submit value="Generate Report"></td>
<td>&nbsp;</td>
</tr>
</form>
</table>
</center>
<?php

function movetype()
{
	echo "<select name=\"typeid\">
		<option value=0>All Types</option>";
	$query = "select typeid, typename from movetype";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result))
	{
		$typeid = $row[0];
		$typename = $row[1];
		echo "<option value=\"$typeid\">$typename</option>";
	}
	echo "</select>";
}

function staff()
{
	echo "<select name=\"staffid\">
		<option value=0>All Staffs</otion>";
	$query = "select staffid, firstname, lastname from staff order by firstname asc";
	$result = mysql_query($query) or die (mysql_error());
	while ($row = mysql_fetch_array($result))
	{
		$staffid = $row[0];
		$name = $row[1] . "," . $row[2];
		echo "<option value=\"$staffid\">$name</option>";
	}
	echo "</select>";
}

function isloggedin($sessid)
{
	include_once "conn.php";
	
	$query = "select loginstaff.staffid from loginstaff, staff where loginstaff.sessid='$sessid' and loginstaff.staffid=staff.staffid";
	$result = mysql_query($query) or die (mysql_error());
	if ($row = mysql_fetch_array($result))
	{
		$staffid = $row[0];
		return $staffid;
	}
	
	header ("location: staffarea.php");
}
?>