<?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_comments.php');
	include('/var/www/html/uclit/protected/connections/db_pers.php');

	$dbConn = mysql_select_db('comments', $commentsConn) or die("Couldn't select database");
	
	$get_id = $_GET['idnum'];
		
	$sql_main = "
	Select comments.comments.id, comments.comments.lib, comments.comments.visit_date, comments.comments.comment_date, comments.comments.patron_type, comments.comments.rating, comments.comments.`comment`, comments.comments.resolution, comments.comments.comment_type, comments.comments.`status`, comments.comments.assigned_personnel, comments.comments.email_check, comments.comments.name, comments.comments.email, comments.comment_type.id, comments.comment_type.description, comments.comment_type.symbol, comments.followup_action.id, comments.followup_action.`desc` AS description2, comments.followup_rating.id, comments.followup_rating.`desc`, uclit_db.departments.dept_id, uclit_db.departments.dept_name
From comments.comments Inner Join comments.comment_type ON comments.comment_type.id = comments.comments.comment_type Inner Join comments.followup_action ON comments.followup_action.id = comments.comments.`status` Inner Join comments.followup_rating ON comments.followup_rating.id = comments.comments.rating Inner Join uclit_db.departments ON uclit_db.departments.dept_id = comments.comments.lib
Where comments.comments.id = $get_id";
	
	
	//echo"$sql_main";
	
	$result_main = mysql_query($sql_main, $commentsConn) or die("Couldn't execute query.<p>$query1</p>");
	$row = mysql_fetch_array($result_main);
	
	$id = $row['id'];
	$lib = $row['lib'];
	$visit_date = $row['visit_date'];
	$comment_date = $row['comment_date'];
	$patron_type = $row['patron_type'];
	$rating = $row['rating'];
	$comment = $row['comment'];
	$response = $row['resolution'];
	$comment_type = $row['comment_type'];
	$status= $row['status'];
	$assigned_personnel = $row['assigned_personnel'];
	$email_check = $row['email_check'];
	$name = $row['name'];
	$email = $row['email'];
	$type_id = $row['id'];
	$type_desc = $row['description'];
	$type_symbol = $row['symbol'];
	$action_id = $row['id'];
	$action_desc = $row['description2'];
	$rating_id = $row['id'];
	$rating = $row['desc'];
	$dept_name = $row['dept_name'];
	
	//echo"$id </br>";
	//echo"$lib </br>";
	//echo"$visit_date </br>";
	//echo"$comment_date </br>";
	//echo"$patron_type </br>";
	//echo"$rating </br>";
	//echo"$comment </br>";
	//echo"$comment_type </br>";
	//echo"$status </br>";
	//echo"$assigned_personnel </br>";
	//echo"$email_check </br>";
	//echo"$name </br>";
	//echo"$email </br>";
	//echo"$type_id </br>";
	//echo"$type_desc </br>";
	//echo"$type_symbol </br>";
	//echo"$action_id </br>";
	//echo"$action_desc </br>";
	//echo"$rating_id </br>";
	//echo"$rating </br>";
	//echo"$dept_name </br>";
?>
	<form name='edit_this_comment' action="process.php" method="post">
	   <p><a href="javascript:history.back()"><strong>Back</strong></a>
         <input type="hidden" name="id" value="<?php echo $get_id ?>">
		 <input type="hidden" name="new_tech" value="" size="30">
	   </p>
	   <table cellspacing="2" cellpadding="2" border="1">
	   <tr><td colspan="2"><H2>Comment Information</H2></td><td colspan="2"><H2>Comment Action</H2></td>       
	   <tr>
	     <td width="115" height="36">Comment Date:</td>
         <td width="292"><?php echo $comment_date; ?></td>
		 <td width="135">Comment Type:</td>
	     <td width="290"><?php echo $type_desc; ?></td>
	    </tr>
		<tr>
		  <td>Library:</td>
	  	  <td><?php echo $dept_name; ?></td>
		   <td colspan="2">
		    Comment:<br>
			<textarea disabled = "true" cols="40" rows="4" name="text_request"><?php echo $comment;?></textarea>		  </td>
		</tr>

		<tr>
	      <td>Visit Date:</td>
		  <td><?php echo $visit_date; ?></td>
		   <td colspan="2">
			Response:<br>
			<textarea cols="40" rows="4" name="text_response"><?php echo $response;?></textarea>		  </td>
		</tr>
		<tr>
		  <td>Patron Name:</td>
		  <td><?php echo $name; ?></td>
		   <td width="135">Assigned to:</td>
		   <td><select name='technician' onChange='NewTech()'>
		  <?php if ($assigned_personnel == '') //no tech name selected
		echo "<Option value=''>-- Select One --</Option>";
		$dbTech = mysql_select_db('uclit_db', $uclit_dbConn) or die("Couldn't select database");
		$sql_techs = "SELECT personnel_id, first_name, last_name FROM personnel WHERE removed='0' ORDER BY last_name";
		$techs_result = mysql_query($sql_techs, $uclit_dbConn) or die ("Unable to exercute query. <p>$sql_techs</p>");
	
	while($row = mysql_fetch_array($techs_result))
	{
		$personnel_id = $row['personnel_id'];
		$last_name = $row['last_name'];
		$first_name = $row['first_name'];
		
		if ($personnel_id == $assigned_personnel) 
			{
			echo "<OPTION value='$personnel_id' selected>$last_name"; echo","; echo"$first_name</OPTION>";	
			}
		else
			{
			echo "<OPTION value='$personnel_id'>$last_name"; echo","; echo"$first_name</OPTION>";
			}	
	}
	?>
	</select>
		
		   </td>
		   
		  </tr>
		<tr>
		  <td>Patron Type:</td>
		  <td><?php echo $patron_type; ?></td>
		  <td width="135">Current Status:</td>
		  <td width="290"><select name='status2'>
		  <?php 
		  
		$dbstatus = mysql_select_db('comments', $commentsConn) or die("Couldn't select database");
		$sql_status = "Select followup_action.id, followup_action.`desc`
From followup_action
Order By followup_action.`desc` Asc";
		$status_result = mysql_query($sql_status, $commentsConn) or die ("Unable to exercute query. <p>$sql_status</p>");
	
	while($row = mysql_fetch_array($status_result))
	{
		$status_id = $row['id'];
		$status_desc = $row['desc'];
				
		if ($status == $status_id) 
			{
			echo "<OPTION value='$status_id' selected>$status_desc</OPTION>";	
			}
			
		else
			{
			echo "<OPTION value='$status_id'>$status_desc";
			}	
	}
	?>
	</select>
	</td>
		</tr>
		<tr>
		  <td height="25"><p>Receive Email :</p>	      </td>
		  <td><?php if ($email_check == 0) echo "No"; Else echo "Yes"; ?></td>
		  <td width="135">Rating:</td>
		  <td width="290"><select name='rating'>
		  <?php 
		  
		$dbrating = mysql_select_db('comments', $commentsConn) or die("Couldn't select database");
		$sql_rating = "Select followup_rating.id, followup_rating.`desc`
From followup_rating
Order By followup_rating.`desc` Asc";
		$rating_result = mysql_query($sql_rating, $commentsConn) or die ("Unable to exercute query. <p>$sql_status</p>");
	
	while($row = mysql_fetch_array($rating_result))
	{
		$rating_id2 = $row['id'];
		$rating_desc = $row['desc'];
				
		if ($rating_id == $rating_id2) 
			{
			echo "<OPTION value='$rating_id2' selected>$rating_desc</OPTION>";	
			}
			
		else
			{
			echo "<OPTION value='$rating_id2'>$rating_desc";
			}	
	}
	
	?>
	</select></td>
	    </tr>
		 <tr>
		  <td>Patron Email:</td>
		  <td><?php echo $email; ?></td>
		   <td colspan="2" align="center">
			  <input type="submit" name="response" value="Submit" style="width: 9em;">&nbsp;&nbsp;
	    </tr>
		
			  </table>
		<input type="hidden" name="dept" value="<?php echo $get_dept; ?>">
		<input type="hidden" name="type" value="<?php echo $get_type; ?>">
		<input type="hidden" name="status" value="<?php echo $get_status; ?>">
	</form>
<?php include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); ?>

<script type="text/javascript">
function NewTech()
{
	document.edit_this_comment.new_tech.value = "true";
	
}
</script>