<?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');
		
	$query = "SELECT help_type FROM help_catagories ORDER BY help_type" ;
	$db = mysql_select_db("helpcalls", $helpConn) or die("Couldn't select database. helpcalls");
	$sql_result = mysql_query($query, $helpConn) or die("Couldn't execute query: $query");

	$query_per = "SELECT personnel_id, last_name, first_name FROM personnel WHERE removed = 0 ORDER BY last_name" ; 	
	$db3 = mysql_select_db("uclit_db", $uclit_dbConn) or die("Couldn't select database. uclit_db");		
	$sql_per = mysql_query($query_per, $uclit_dbConn) or die("Couldn't execute query: $query_per");

	if (!$sql_result || !sql_per) 
	{
?>
		<font color="red"><p>Couldn't get list!</p></font>
<?php
	}
	else 
	{
?>					
		<form method="post" action="add_help_ticket.php" name="ticket_form" onSubmit="return validator();">
			<table border="1" width="90%">
				<tr>
					<td valign="top">
						<P><strong>&nbsp;&nbsp; User's Name:</strong><BR>
							<select name="per" onChange="CheckDisabled()">
								<option value="0" selected>Select...</option> 
								<option value="">Student/Other</option> 						
<?php
								$ln = "";
								$fn = "";
								while ($row = mysql_fetch_array($sql_per)) 
								{
									$per_id = $row["personnel_id"];
									$ln = $row["last_name"];
									$fn = $row["first_name"];									
									echo"<option value=$per_id> $ln, $fn </option>";					
								}
?>							
				
					</select><font color="#ff0000" size="3">*</font>
					<input type="hidden" name="username" value="$fn $ln">
					</td>
					<td valign="top">
						<P><strong>&nbsp;&nbsp; Department:</strong><BR>
							<select name="help_dept" ID="Select1">
								<option selected value="0">Select...</option> 
<?php
	$query2 = "SELECT dept_name FROM departments ORDER BY dept_name" ;
		
	$db2 = mysql_select_db("uclit_db", $uclit_dbConn) or die("Couldn't select uclit_db database.");
	$sql_result2 = mysql_query($query2, $uclit_dbConn) or die("Couldn't execute query. <p>$query2</p>");
	
	
								while ($row = mysql_fetch_array($sql_result2))
								{
									$dept_name = $row["dept_name"];
									echo"<option>$dept_name</option>";
								}
?>								
					</select><font color="#ff0000" size="3">*</font>
					</td>
					<td>
							<p><strong>&nbsp;&nbsp; Phone Number:</strong><BR><font color="#ff0000" size="3"> </font> 
					          <input type="text" name="help_phone" size="25" maxlength="25"></p>
					</td>
					
				</tr>
				<tr >
					<td valign="top" colspan="3" align="center">
						<P><strong>&nbsp;&nbsp; Help Call Description:</strong><BR>
							<textarea name="help_desc" cols="45" rows="5" wrap="virtual"></textarea><font color="#ff0000" size="3">*</font></P>
						</td>
				</TR>	
				<tr>
					<td> E-mail(If Student/Other selected): </td>
					<td><input name="email" type="text" size="50" disabled></td>	
				</tr>
				<tr>
					<td> URL (If Necessary): </td>
					<td><input name="help_url" type="text" size="50"></td>	
				</tr>			
				<tr>
						<td><input type="button" value="Submit Help Call" onClick="CheckBeforeSumbit()"></td>
						<td><font color="#ff0000" size="3">* fields required</font></td>
				</tr>
			
			</table>
		</form>
<?php				
	}
?>
<script type="text/javascript">

function CheckBeforeSumbit()
{
	var x = document.ticket_form;
	if(x.per.value == "0" || x.help_dept.value == "0" || x.help_desc.value == "")
	{
		window.alert("Please fill in all of the following items:\nUser\nDepartment\nHelp Description");
	}
	else
	{
		if(x.email.value == "")
		{
			if(x.per.value == "")
				window.alert("Student/Other needs to provide email\n in order to have email services for this helpcall");			
			else
			{
				x.submit();
				
			}
		}
		else
		{//check for correctness of the email
			var email = x.email.value;
			var reg1 = new RegExp("[0-9a-zA-Z]+@[a-zA-Z]+");
			if(reg1.test(email))
			{
				//window.alert("Good email");
				x.submit();
				
			}
			else
			{
				//bad email or empty email
				window.alert("Please enter a valid email address");
			}
		}
	}
}
function CheckDisabled()
{
	var x = document.ticket_form;
	if(x.per.value == "")
	{
		x.email.value = "";
		x.email.disabled = false;
	}
	else
	{
		x.email.value = "";
		x.email.disabled = true;
	}
	
}
</script>

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