<?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');	

	// FORM Data
	$dept = $_GET['dept'];
	$type = $_GET['type'];

	// Establish Database Connection
	$dbConn = mysql_select_db("helpcalls", $helpConn) or die("Couldn't select database");
	
	// Query Database
	
	//use if dept=0 and if type=0 to modify sql query
	
	if ($dept != 0 and $type != 0) 
		$sql_where = "departments.dept_id = $dept and help_catagories.help_type_id = $type and completed=0";
	if ($dept == 0 and $type != 0) 
		$sql_where = "help_catagories.help_type_id = $type and completed=0";
	if ($dept != 0 and $type == 0) 	
		$sql_where = "departments.dept_id = $dept and completed=0";
	if ($dept == 0 and $type == 0) 
		$sql_where = "completed=0";
	
	$sql_main = "
	SELECT log.Help_Id, log.Date_Arrived as date, departments.dept_name as dept , help_catagories.help_type as type, log.Help_User as emp 
	FROM log 
	LEFT JOIN departments on log.Help_Dept = departments.dept_name 
	LEFT JOIN help_catagories on log.Help_Catagory = help_catagories.help_type 
	WHERE $sql_where";
	
	//echo "$sql_main<br>";
	//echo "$sql_where<br>";
	$result_main = @mysql_query($sql_main, $helpConn) or die ("Unable to query: $sql_main");
	
	$sql_count = "SELECT count(*) as count FROM log WHERE $sql_where";
	
	$list_count = mysql_numrows($result_main);
?>
	
	<table cellspacing="2" cellpadding="2" border="1" bordercolor="#FFFFFF">
	  <tr >
<!--if ("$status" == "0") {  -->
	    <font size="-1">
	    <td bordercolor="#666666"><strong><font size="-1">Open</font></strong></td> 
	    <td bordercolor="#666666"><strong><font size="-1">Date Submitted</font></strong></td>
	    <td bordercolor="#666666">Department</td>
	    <td bordercolor="#666666">Type</td>
	    <td bordercolor="#666666">Personnnel</td>
         </tr>	
	  <a href="javascript:history.back()"><strong>Main Page</strong></a>
	
<?php
	echo "<br><br><strong>$list_count</strong> Total Help Calls NOT Completed <br><br>";	 
	// $i = 0;
		while($row = @mysql_fetch_array($result_main))
		{
			$list_id = $row['Help_Id'];
			$list_date = $row['date'];
			$list_dept = $row['dept'];
			$list_type = $row['type'];
			$list_emp = $row['emp'];
			  
			if ("$date" == "") 
				$date = "<empty>"; 
			if ("$list_dept" == "") 
				$dept = "<empty>";
			if ("$list_type" == "") 
				$type = "<empty>";
			if ("$list_emp" == "") 
				$emp = "<empty>";
?>


	  <tr>
<!--if ("$status" == "0") --> 
	  	<td nowrap bordercolor="#666666">
<?php 	
	echo"<a href='edit.php?id=$list_id'>open</a>
	</td>";
?>	
		<td nowrap bordercolor="#666666">
		  <font size="-1"><?php echo $list_date; ?></font>
		</td>
		
		<td nowrap bordercolor="#666666">
		  <font size="-1"><?php echo $list_dept; ?></font>
		</td>
		
		<td nowrap bordercolor="#666666">
		  <font size="-1"><?php echo $list_type; ?></font>
		</td>
		
		<td nowrap bordercolor="#666666">
		  <font size="-1"><?php echo $list_emp; ?></font>
		</td>
	
<?php
	$i++;
	}
?>
	  </tr>
	</table>

<?php include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); ?>