<?php 
	include('/var/www/html/uclit/protected/common/login/check.php');
	include('/var/www/html/uclit/protected/common/css_login/css_head2.php');
	include('/var/www/html/uclit/protected/connections/db_help.php');
	
	ob_start();
	global $dbserver, $dbuser, $dbpass, $sqlConn;
	global $room, $dept, $building, $dept_id, $assoc_dean_id, $assoc_dean_email;
?>
<style>
td.str{
	font: bold;
	text-align: center; 
}
</style>

<h1>Help Calls by Department</h1>
<form name="dept" action="show_dept.php" method="POST">
<strong>Department:</strong>
<select name="show_dept" onChange="submitDept()">
<?php
	$match = $_POST['show_dept'];
	$db = mysql_select_db("helpcalls", $helpConn) or die("Couldn't select database");
	
	//fill up the personnel drop down box
	$sql_dept = "SELECT distinct Help_Dept FROM log ORDER BY Help_Dept";
	$dept_result = mysql_query($sql_dept, $helpConn) or die ("Unable to query: $sql_dept");
	echo "<option value='0' selected>Select...</option>";	
	while($dept_row = mysql_fetch_array($dept_result))
	{
		$dept = $dept_row['Help_Dept'];
		if($match == $dept)
			echo "<option value='$dept' selected>$dept</option>";
		else
			echo "<option value='$dept'>$dept</option>";	
	}
?>
</select>
</form>
<table border="1" width="100%">
	<tr>
		<td class="str">Date Arrived</td>
		<td class="str">Department</td>
		<td class="str">Engineer</td>
		<td class="str">Description</td>
		<td class="str">User</td>
		<td class="str">Phone</td>
	</tr>

<form name="getquerry" action="" method="">

<?php
	$get_dept = $_POST['show_dept'];
	if($get_dept != NULL || $get_dept != 0 || $get_dept != "")
	{
		//fill up the personnel drop down box
		$sql_details = "SELECT Help_ID, Date_Arrived, Help_Dept, Help_Tech, Help_Desc, Help_User, Help_Phone FROM log WHERE Help_Dept = '$get_dept' and Completed = 0";
		$details_result = @mysql_query($sql_details, $helpConn) or die ("Unable to query: $sql_details");
		$x=0;
		$id;
		while($dept_row = @mysql_fetch_array($details_result))
		{
			$x++;
			$id =   $dept_row['Help_ID'];
			$date = $dept_row['Date_Arrived'];
			$dept = $dept_row['Help_Dept'];
			$tech = $dept_row['Help_Tech'];
			$desc = $dept_row['Help_Desc'];
			$user = $dept_row['Help_User'];
			$phon = $dept_row['Help_Phone'];
			echo "<tr>";
			echo "<td nowrap>$date</td>";
			echo "<td>$dept</td>";
			echo "<td>$tech</td>";
			echo "<td>$desc</td>";
			echo "<td>$user</td>";
			if($phon != "" || $phon != NULL)
				echo "<td nowrap>$phon</td>";
			else
				echo "<td>None</td>";	
			echo "</tr>";
		}
	}
	echo "Total: $x";
?>

</form>
</table>

<script type="text/javascript">
function submitDept()
{
	document.dept.submit();
}
</script>
<?php 
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>