<?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'];
	
	//sql statement
	$query= "SELECT * FROM log WHERE Help_ID='$help_id'" ;
	
	//select a database
	$dbselected = mysql_select_db('helpcalls', $helpConn) or die ("<p>Unable to select helpcalls database.</p>");
		
	//run query sql statement
	$result = mysql_query($query, $helpConn) or die("Couldn't execute query $query.");
			
	$row = mysql_fetch_array($result);
	
	$help_id=$row['Help_ID'];
	$date_arrived = $row['Date_Arrived'];
	$completed = $row['Completed'];
	$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'];
	$help_phone = $row['Help_Phone'];
	
	
	//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_ticket.php'>
	  <input type='hidden' name='help_id' value='$help_id' size=30>
	  <input type='hidden' name='help_tech' value='$help_tech' size=30>
  	  <input type='hidden' name='new_tech' value='' size=30>

	  <table width='70%' border='0'>
	    <tr> 
	      <td><strong>User:</strong><br><input type='text' name='usertext' value='$help_user' size=30 disabled></td>
	      <td><strong>Department:</strong><br><input type='text' name='depttext' value='$help_dept' size=35 disabled> </td>
	      <td><strong>Date Arrived:</strong><br> 
	        <input type='text' name='datetext' value='$date_arrived' size=20 disabled></td>
	    </tr>
	    <tr> 
	      <td colspan='3'>&nbsp;</td>
	    </tr>
	    <tr> 
	      <td><input type='checkbox' name='completebox' >
	        <strong>Completed</strong></td>
	      <td><strong>Technician:</strong><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'];
		if ($help_tech == $tech) 
			echo "<OPTION value='$tech' selected>$tech</OPTION>";	
		else 
			echo "<OPTION value='$tech'>$tech</OPTION>";	
	}
	echo "
	    </select></td>
		
	     <td><strong>Phone Number:</strong><br><input type='text' name='phonetext' value='$help_phone' size=30 disabled></td>
	    </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'><strong>Resolution:</strong><br>
	        <textarea name='restext' cols=60 rows=10>$help_resolution</textarea></td>
		</tr>
	    <tr> 
	      <td  colspan='3'> 
	        <input type='button' name='Submit' value='Update Call $help_id' onClick='CheckForSubmit()'></td>
	    </tr>
	  </table>
	  <p>&nbsp;</p>
	  <p>&nbsp; </p>
	</form>";
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php');
?>
<script type="text/javascript">
function CheckForSubmit()
{
	var x = document.edit_this_ticket.completebox.checked;
	var y = document.edit_this_ticket.restext.value;
	if(x == true )
	{
		if(y == "")
			window.alert("You check this ticket as completed, but you do not have a resolution.\nPlease enter your resolution");
		else
		{
			document.edit_this_ticket.submit();
		}

	}
	else
	{
			document.edit_this_ticket.submit();

	}
}
function NewTech()
{
	document.edit_this_ticket.new_tech.value = "true";
	//window.alert("there is a new tech");
}
</script>