<?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');
	
	$today="";
	$datetimenow = date('Y-m-d')." ".strftime("%H:%M:%S");
	$help_id = $_GET['help_id'];
	$help_desc = $_POST['help_desc'];
	
	//select a database
	$db = mysql_select_db('helpcalls', $helpConn) or die ("<p>Unable to select helpcalls database.</p>");

	//sql statements
	$query= "SELECT * FROM log WHERE Help_ID='$help_id'" ;
	$result = mysql_query($query, $helpConn) or die("Couldn't execute query $query.");
	
	$query2 = "SELECT help_type FROM help_catagories ORDER BY help_type" ;
	$result2 = mysql_query($query2, $helpConn) or die("Couldn't execute query: $query2");

	while ($row = mysql_fetch_array($result))
	{
		$help_id = $row['Help_ID'];
		$date_arrived = $row['Date_Arrived'];
		$help_desc = $row['Help_Desc'];
		$help_dept = $row['Help_Dept'];
		$help_user = $row['Help_User'];
		$help_user_id = $row['Help_User_ID'];
		$user_email = $row['Email'];
		$help_resolution = $row['Help_Resolution'];
		$help_tech = $row['Help_Tech'];
	}
	//sql to statement to log
	$sql_useraccess = "INSERT INTO HelpcallsUserAccessLog 
	   				   VALUES ('', '$suser', ''$help_id', '$date_arrived', '$completed', '$help_desc', 
					   	'$help_dept', '$help_user', '$help_resolution', '$help_phone'', '$datetimenow')";
	
	//log user access
	mysql_query($sql_useraccess, $helpConn);

 	echo "
	<h2><b>Edit Help Call Ticket [ '$help_id' ]</b></h1>
	<form name='edit_this_ticket' method='POST' action='update_helpcalls.php'>
	  <input name='help_id' value='$help_id' type='hidden' />
	  <input name='user_email' value='$user_email' type='hidden' />
  	  <input name='help_user_id' value='$help_user_id' type='hidden' />

	  <table width='75%' border='0'>
	    <tr> 
	      <td><strong>User:</strong><br />
		  	<input class='disabled' type='text' name='help_user' value='$help_user' size=30 readonly /></td>
	      <td><strong>Department:</strong><br />
		  	<input class='disabled' type='text' name='depttext' value='$help_dept' size=35 readonly /></td>
	      <td><strong>Date Arrived:</strong><br /> 
	        <input  class='disabled' type='text' name='datetext' value='$date_arrived' size=20 readonly /></td>
	    </tr>
	    <tr> 
	      <td colspan='3'>&nbsp;</td>
	    </tr>
	    <tr>
		
          <td>
		    <p><strong>Help Category:</strong><br />
			<select name='help_catagory'>
  			  <option selected value=''>Select.....</option> ";
							
	while ($row = mysql_fetch_array($result2)) 
	{
		$help_type = $row["help_type"];
		echo"<option>$help_type</option>";
	}				
?>							
            </select></p>
		  </td>
<?php
	     echo" <td><strong>Technician:</strong><br /><select name='technician' onChange='NewTech()'>";  
	if ($help_tech == '') //no tech name selected
		echo "<option value=''>-- Select One --</option>";
		
	$sql_techs = "SELECT tech_name FROM techs WHERE status='1' ORDER BY tech_name";
	$techs_result = mysql_query($sql_techs, $helpConn) or die ("Unable to exercute query. <p>$sql_techs</p>");
	
	while($row = mysql_fetch_array($techs_result))
	{
		$tech = $row['tech_name'];
		echo "<OPTION value='$tech'>$tech</OPTION>";	
	}
?>

          </td>
<?php
	echo"</tr>
	    <tr> 
		<tr> 
	      <td colspan='3'>
	        <strong>Description:</strong><br />
	        <textarea name='desctext' cols=60 rows=10>$help_desc</textarea></td>
	    </tr> 
		<tr>
	      <td colspan='3'> 
		    <br />
	        <input type='submit' name='Submit' value='Update Call $help_id'></td>
	    </tr>
	  </table>
	</form>";
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php');
?>
<script type="text/javascript">
function NewTech()
{
	document.edit_this_ticket.new_tech.value = "true";
	//window.alert("there is a new tech");
}
</script>