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

	//Select a database
	$db1 = mysql_select_db('helpcalls', $helpConn) or die("Couldn't select helpcalls database ");
	
	//$db1 = @mysql_select_db($dbhelp, $connection1);	
	$sql_date = "SELECT DISTINCT Date_Arrived AS 'AvailDate' FROM log ORDER BY Date_Arrived Desc";
	$sql_calls = "Select DISTINCT help_catagories.help_type AS 'Catagories' From help_catagories";
	$date_result = mysql_query($sql_date, $helpConn);
?>
		<H1>KnowledgeBase</H1>
		<br><br>
		<form action='process_calls.php' method='post' name='hreport_form' onSubmit='return validator();'>
		<table width='90%' border='1' cellspacing='2' cellpadding='2'>
		  <tr>
		    <td width='30%'>Beginning Date: </td>
		    <td colspan='*%'>
		        <select name='bdate' id='bdate'>	
<?php				
	if ($date_result) 
	{
		echo "<p>".mysql_error()."</p>";
		while ($row = mysql_fetch_array($date_result))
		{
			$datelist = $row['AvailDate'];
			echo "\n<option value='$datelist'>$datelist</option>";
		}
	}
?>
		        </select></td>
		  </tr>
		  <tr>
		    <td>Ending Date:</td>
		    <td colspan='3'>
		        <select name='edate' id='edate'>
<?php
			$date_result = mysql_query($sql_date, $helpConn);
			if (!$date_result)
			{
				echo "<p>".mysql_error()."</p>";
			}
			else
			{
	 			while ($row = mysql_fetch_array($date_result))
				{
					$datelist = $row['AvailDate'];
					echo "\n<option value='$datelist'>$datelist</option>";
				}
			}
?>
				</select>
			</td>
		  </tr>
		  <tr>
		   <td>Service Area:</td>
		    <td colspan='3'>
		        <select name='catagory' id='catagory'>
<?php
			$cat_result = mysql_query($sql_calls, $helpConn);
			if (!$cat_result)
			{
				echo "<p>".mysql_error()."</p>";
			}
			else
			{
	 			while ($row = mysql_fetch_array($cat_result))
				{
					$catlist = $row['Catagories'];
					echo "\n<option value='$catlist'>$catlist</option>";
				}
			}
?>
				</select>
				</td>
		  </tr>
		   <tr>
		   <td>Search Term:</td>
		    <td colspan='3'>
			<textarea name="term" cols="40" rows="5"></textarea></td>
		  </tr>
		  
		  <tr>
		    <td colspan='4'><input name='submit' type='submit' value='Create Report'></td>
		  </tr>
		</table>
		</form>	
<script language='javascript'>
function validator()
{
	var obj = document.hreport_form;
	var msgError = 'Please enter a value for the following fields';

	if ((obj.bdate.value != '' && obj.edate.value != '') && (obj.bdate.value != '0000-00-00' && obj.edate.value != '0000-00-00'))
	{	//Start Date is greater than Ending Date
		return true;	
	}
	else
	{
		if(obj.bdate.value > obj.edate.value)
		{
			alert('Starting Date cannot be later than Ending Date.');
			return false;
		}

		var NoErrors = false;

		if(obj.help_catagory.value == '')
			msgError += '\\nHelp Catagory';
			
	}

	if (!NoErrors) //field/s is empty
		return NoErrors;

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