Location: PHPKode > projects > Tech Tickets > technician/tt_view_one.php
<?php
$sess = session_start();
$p_id = $_SESSION['pid'];
$usertype = $_SESSION["type"];
$signature = $_SESSION["firstname"];

if ($_GET){
	$tt_id =  $_GET["tt_id"];
}

if ($_POST){
	if(isset($_POST["parent_tt_id"])){$parent_tt_id = $_POST["parent_tt_id"];}else{$parent_tt_id = "";}
	if(isset($_POST["newcomment"])){$newcomment = $_POST["newcomment"];}else{$newcomment = "";}
	if(isset($_POST["client_pid"])){$client_pid = $_POST["client_pid"];}else{$client_pid = "";}
	if(isset($_POST["escalate"])){$escalate = $_POST["escalate"];}else{$escalate = "";}
	if(isset($_POST["escalate_to"])){$escalate_to = $_POST["escalate_to"];}else{$escalate_to = "";}
}
?>
<?php include("../include/secure.php"); ?>
<?php require_once('../include/connections.php'); ?>
<?php
mysql_select_db($database, $conn);
//handle if form submitted, and post data
	if(isset($_POST["Submit"])) {
		// Save the Ticket 
		if ($usertype=="E") {$bywho = 'C';} else {$bywho='Y';}	//if user=Employee, Click else You
		$newcomment .= '<br><br>By: ' . $signature; //add signature to comment
		//add comment to table
		$insertSQL = "INSERT INTO tt_tickets (p_id, comment, bywho,parent_tt_id) VALUES ($p_id, '$newcomment', '$bywho',$parent_tt_id)";          
		$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
		if(isset($_POST["Closed"])) {	//see if user wanted to close ticket, if so, need to UPDATE the parent ticket
			$updateSQL = "UPDATE tt_tickets SET status='C', closeddate = NOW() WHERE tt_id = $parent_tt_id";          
			$Result2 = mysql_query($updateSQL, $conn) or die(mysql_error());
		}
		if(isset($_POST["escalate"])) {	//update ticket status
			$updateSQL = "UPDATE tt_tickets SET status='E', cl_id = $escalate_to WHERE tt_id = $parent_tt_id";          
			$Result2 = mysql_query($updateSQL, $conn) or die(mysql_error());
			 
			$query_client_email = "SELECT VendorEmail as Email FROM tt_vendors WHERE VendorID = $escalate_to";
			$client_email = mysql_query($query_client_email, $conn) or die(mysql_error());
			$row_client_email = mysql_fetch_assoc($client_email);
			$totalRows_client_email = mysql_num_rows($client_email);
			$newcomment = str_replace('<br>', chr(10), $newcomment); 
			mail($row_client_email['Email'],"Ticket Escalated","Your ticket has been escalated: ".$newcomment,"From:".$EmailFrom);
		}
		//sendmail to user
		$query_client_email = "SELECT u.Email FROM tt_users u INNER JOIN tt_tickets t ON u.UserID = t.p_id WHERE t.tt_id = $parent_tt_id";
		$client_email = mysql_query($query_client_email, $conn) or die(mysql_error());
		$row_client_email = mysql_fetch_assoc($client_email);
		$totalRows_client_email = mysql_num_rows($client_email);
		$newcomment = str_replace('<br>', chr(10), $newcomment); 
		mail($row_client_email['Email'],"Ticket Updated","Your ticket has been updated: ".$newcomment,"From:".$EmailFrom);
	header("Location:tt_view_open.php");
	}elseif (isset($_POST["OpenSubmit"])) {
		// Open the Ticket
		if ($usertype=="E") {$bywho = 'C';} else {$bywho='Y';}
		
		$newcomment = "";
		if(isset($_POST["Open"])) {
			$newcomment .= 'Ticket Opened By: '.$signature;
			$updateSQL = "UPDATE tt_tickets SET status='O' WHERE tt_id = $parent_tt_id";          
			mysql_query($updateSQL, $conn) or die(mysql_error());
		}
		if(isset($_POST["assign"])) {
			if($newcomment != ""){$newcomment .= "<br>";}
			$newcomment .= 'Ticket Assigned to '.$_POST["UserName"].' by '.$signature;
			$updateSQL = "UPDATE tt_tickets SET tech_id = ".$_POST["assign_to"]." WHERE tt_id = $parent_tt_id";          
			mysql_query($updateSQL, $conn) or die(mysql_error());
		}
		$insertSQL = "INSERT INTO tt_tickets (p_id, comment, bywho,parent_tt_id) VALUES ($p_id, '$newcomment', '$bywho',$parent_tt_id)";          
		mysql_query($insertSQL, $conn) or die(mysql_error());
			
	header("Location:tt_view_one.php?tt_id=$parent_tt_id");
	}elseif (isset($_POST["ReAssignSubmit"])) {
		// Re-assign Tech
		if ($usertype=="E") {$bywho = 'C';} else {$bywho='Y';}
		$newcomment .= 'Ticket Assigned to '.$_POST["UserName"].' by '.$signature;
		
		$updateSQL = "UPDATE tt_tickets SET tech_id = ".$_POST["assign_to"]." WHERE tt_id = $parent_tt_id";          
		mysql_query($updateSQL, $conn) or die(mysql_error());
		
		$insertSQL = "INSERT INTO tt_tickets (p_id, comment, bywho,parent_tt_id) VALUES ($p_id, '$newcomment', '$bywho',$parent_tt_id)";          
		mysql_query($insertSQL, $conn) or die(mysql_error());
			
	header("Location:tt_view_one.php?tt_id=$parent_tt_id");
	}elseif (isset($_POST["ArchiveSubmit"])) {
		// Archive Ticket
		if ($usertype=="E") {$bywho = 'C';} else {$bywho='Y';}
		
		$newcomment = "";
		if(isset($_POST["Open"])) {
			$newcomment .= 'Ticket Archived By: '.$signature;
			$updateSQL = "UPDATE tt_tickets SET archived='1' WHERE tt_id = $parent_tt_id";          
			mysql_query($updateSQL, $conn) or die(mysql_error());
		}
		$insertSQL = "INSERT INTO tt_tickets (p_id, comment, bywho,parent_tt_id) VALUES ($p_id, '$newcomment', '$bywho',$parent_tt_id)";          
		mysql_query($insertSQL, $conn) or die(mysql_error());
			
	header("Location:tt_view_one.php?tt_id=$parent_tt_id");
	}
	
	
?>

<?php
// get the ticket
$query_ticket_list = "SELECT tt_id, parent_tt_id, cl_id, p_id, date_format(datetimestamp,'%m-%d-%Y %r') as datetimestamp, t.status, urgency, subject, archived, u_tech.FirstName, u_tech.LastName, u_client.FirstName as c_FirstName, u_client.LastName as c_LastName FROM tt_tickets t LEFT OUTER JOIN tt_users u_tech ON t.tech_id = u_tech.UserID LEFT OUTER JOIN tt_users u_client ON t.p_id = u_client.UserID WHERE tt_id = " . $_GET['tt_id'] . " ORDER BY datetimestamp DESC";
$ticket_list = mysql_query($query_ticket_list, $conn) or die(mysql_error());
$row_ticket_list = mysql_fetch_assoc($ticket_list);
$totalRows_ticket_list = mysql_num_rows($ticket_list);
?>
<?php
// Get the comments
$query_ticket_comments = "SELECT tt_id, parent_tt_id, cl_id, p_id, date_format(datetimestamp,'%m-%d-%Y %r') as datetimestamp, comment,bywho FROM tt_tickets WHERE ((tt_id = " . $HTTP_GET_VARS['tt_id'] . " OR parent_tt_id = " . $HTTP_GET_VARS['tt_id'] . "))  ORDER BY tt_id ASC";
$ticket_comments = mysql_query($query_ticket_comments, $conn) or die(mysql_error());
$row_ticket_comments = mysql_fetch_assoc($ticket_comments);
$totalRows_ticket_comments = mysql_num_rows($ticket_comments);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>Open Ticket</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<link href="../include/style.css" type="text/css" rel="stylesheet" />
	<script>
	function setdefault(){
		if(document.getElementById("escalate").checked == false)
			hide();
	}
		
	function showhideEsc(){
		if (document.getElementById("escalate").checked == true)
		{
			show(document.getElementById("show_escalation"));
		}else{
			hide(document.getElementById("show_escalation"));
		} 
	}
	
	function showhideAssign(){
		if (document.getElementById("assign").checked == true)
		{
			show(document.getElementById("show_assign"));
		}else{
			hide(document.getElementById("show_assign"));
		} 
	}
	
	function show(o){
		o.style.visibility = "visible";
	}
	
	function hide(o){
		o.style.visibility = "hidden";
	}
	</script>
</head>

<body topmargin="0">
<?php include("header.php"); ?>
<table width="100%" bgcolor="#efefef">
<tr>
	<td align="right">
	<?php echo "Welcome " . $HTTP_SESSION_VARS["uid"];?>
	</td>
</tr>
</table>
	  
      <h1 align="center"><font face="Verdana, Arial, Helvetica, sans-serif">Ticket Detail</font></h1>
      <h3 align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_ticket_list['c_FirstName']." ".$row_ticket_list['c_LastName'];; ?>&nbsp;</font></h3>
      <br>
	  <table border="0" cellpadding="2" cellspacing="2" align="center" width="90%">
        <tr bgcolor="#666666"> 
          <td bgcolor="#666666"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Ticket Number </font></strong></td>
          <td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
		  <?php $client_pid = $row_ticket_list['p_id'];?>
		  <?php $parent_tt_id = $row_ticket_list['tt_id'];?>
		  <?php $archived = $row_ticket_list['archived'];?>
		  <?php echo $parent_tt_id; ?></font></td>
        </tr>
        <?php do { ?>
        <tr bgcolor="#CCCCCC"> 
          <td bgcolor="#666666"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Submitted</font></strong></td>
          <td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_ticket_list['datetimestamp']; ?></font></td>
        </tr>
        <tr bgcolor="#CCCCCC"> 
          <td bgcolor="#666666"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Subject</font></strong></td>
          <td bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_ticket_list['subject']; ?></font></td>
        </tr>
        <tr bgcolor="#CCCCCC"> 
          <td bgcolor="#666666"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Status</font></strong></td>
          <td bgcolor="#CCCCCC">
		  <?php $status = $row_ticket_list['status'];?>
		  <?php if ($status=="O") {$fullstatus="Open";} elseif($status=="P") {$fullstatus="Pending";} elseif($status=="C") {$fullstatus="Closed";} elseif($status=="E") {$fullstatus="Escalated";} ?>
		  <font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="<?php if ($fullstatus=='Open') {echo '#009900';} else {echo '#000000';}?>">
		  <?php echo $fullstatus; ?></font></td>
        </tr>
        <tr bgcolor="#CCCCCC"> 
          <td bgcolor="#666666"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Urgency</font></strong></td>
          <td bgcolor="#CCCCCC">
		  <?php 
		  $theurgency = $row_ticket_list['urgency'];
		  if ($theurgency=='E') {$urgency='Emergency';} elseif ($theurgency=='A') {$urgency='ASAP';} else {$urgency='Next Visit';}?>
		<font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="<?php if ($urgency=='Emergency') {echo '#993300';} elseif ($urgency=='ASAP') {echo '#cc6600';} else {echo '#000000';}?>">
		  <?php echo $urgency; ?></font></td>
        </tr>
		<tr bgcolor="#CCCCCC"> 
          <td bgcolor="#666666"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Assigned Technican</font></strong></td>
          <td bgcolor="#CCCCCC">
		  	<?php if (isset($_GET["ut"])){ ?>
				<form action="tt_view_one.php?tt_id=<?php echo $tt_id; ?>" method="post">
				<input type="hidden" name="parent_tt_id" value="<?php echo $parent_tt_id; ?>">
				<select name="assign_to" id="assign_to" onChange="updateUserName(this.selectedIndex);">
				<?php
				$sql = "SELECT UserID, FirstName, LastName FROM tt_users WHERE Status <> 0 AND Role = 'T' ORDER BY FirstName, LastName";
				$rs = mysql_query($sql, $conn) or die(mysql_error());
				$row = mysql_fetch_assoc($rs);
				do {  
				?>
				<option value="<?php echo $row['UserID']; ?>" <?php if($row['UserID'] == $p_id){ echo "selected";} ?>><?php echo $row['FirstName']." ".$row['LastName'];?></option>
				<?php
				} while ($row = mysql_fetch_assoc($rs));
				  $count = mysql_num_rows($rs);
				  if($count > 0) {
					  mysql_data_seek($rs, 0);
					  $row = mysql_fetch_assoc($rs);
				  }
				?>
				</select>
				<input type="hidden" name="UserName" id="Assign_UserName">
				<input type="submit" value="Submit" name="ReAssignSubmit">
				</form>
				<script>
				function updateUserName(o){
					var un = document.getElementById("Assign_UserName")
					var at = document.getElementById("assign_to")
					un.value = at.options[o].text;
				}
				updateUserName(document.getElementById("assign_to").selectedIndex)
				</script>
			<?php }else{ ?>
				<font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000000">
		  		<?php echo $row_ticket_list['FirstName']." ".$row_ticket_list['LastName']; ?> (<a href="tt_view_one.php?tt_id=<?php echo $_GET["tt_id"]; ?>&ut=1">change</a>)</font>
			<?php } ?>
		  </td>
       	</tr>
        <?php } while ($row_ticket_list = mysql_fetch_assoc($ticket_list)); ?>
      </table>
      <br>
      
      <table border="0" cellpadding="2" cellspacing="2" align="center" width="90%">
        <?php do { ?>
        <tr <?php if($row_ticket_comments['bywho']=="Y") {echo 'bgcolor="#CCCCCC"';} else {echo 'bgcolor="#deeaff"';}?>> 
          <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> 
            <?php if ($row_ticket_comments['bywho']=="Y") {echo "Client said: ";} else {echo "Tech said: ";} ?>
            </font>
		  </td>
          <td><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_ticket_comments['datetimestamp']; ?>&nbsp;</font></div></td>
        </tr>
        <tr <?php if($row_ticket_comments['bywho']=="Y") {echo 'bgcolor="#CCCCCC"';} else {echo 'bgcolor="#deeaff"';}?>> 
          <td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_ticket_comments['comment']; ?></font></td>
        </tr>
		<tr>
			<td colspan="2">&nbsp;</td></tr>
        <?php } while ($row_ticket_comments = mysql_fetch_assoc($ticket_comments)); ?>
      </table>
      <?php 
	  //if status is not closed, show add box
	 if (!isset($_GET["ut"])){
	  if($status=="P"){
	  ?>
	  <table align="center" border="0" width="90%">
	  <form action="tt_view_one.php?tt_id=<?php echo $tt_id; ?>" method="post">
	  <input type="hidden" name="parent_tt_id" value="<?php echo $parent_tt_id; ?>">
	  <tr>
		<td colspan="2">
			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Open Ticket:</font> 
            <input type="checkbox" name="Open">
		</td>
	  </tr>	
	  <tr>
		<td width="125">
			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Assign Ticket:
            <input type="checkbox" id="assign" name="assign" onClick="showhideAssign();">
		</td>
		<td>
			<div id="show_assign" style="visibility:hidden;">
			to:
			<select name="assign_to" id="assign_to" onChange="updateUserName(this.selectedIndex);">
			<?php
			$sql = "SELECT UserID, FirstName, LastName FROM tt_users WHERE Status <> 0 AND Role = 'T' ORDER BY FirstName, LastName";
			$rs = mysql_query($sql, $conn) or die(mysql_error());
			$row = mysql_fetch_assoc($rs);
			do {  
			?>
            <option value="<?php echo $row['UserID']; ?>" <?php if($row['UserID'] == $p_id){ echo "selected";} ?>><?php echo $row['FirstName']." ".$row['LastName'];?></option>
            <?php
			} while ($row = mysql_fetch_assoc($rs));
			  $count = mysql_num_rows($rs);
			  if($count > 0) {
				  mysql_data_seek($rs, 0);
				  $row = mysql_fetch_assoc($rs);
			  }
			?>
			</select>
			<input type="hidden" name="UserName" id="UserName">
			</div>
			</font> 
			<script>
			function updateUserName(o){
				var un = document.getElementById("UserName")
				var at = document.getElementById("assign_to")
				un.value = at.options[o].text;
			}
			updateUserName(document.getElementById("assign_to").selectedIndex)
			</script>
		</td>
	  </tr>  
	  <tr>
		<td colspan="2"><input type="submit" value="Submit" name="OpenSubmit"></td>
	  </tr>
	  </form>
	  </table>
	  <?php
	  }elseif($status!=='C') {
	  	//ticket still open, show box
	  ?>
	  <table align="center" border="0" width="90%">
	  <form action="tt_view_one.php?tt_id=<?php echo $tt_id; ?>" method="post">
	  <input type="hidden" name="parent_tt_id" value="<?php echo $parent_tt_id; ?>">
      <input type="hidden" name="client_pid" value="<?php echo $client_pid; ?>">
	  <tr><td><textarea name="newcomment" cols="76" rows="10"></textarea></td></tr>
	  <tr>
		<td>
			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Mark this ticket Closed:</font> 
            <input type="checkbox" name="Closed">
		</td>
	  </tr>	
	  <tr>
		<td nowrap>
			<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Escalate this Case:
            <input type="checkbox" id="escalate" name="escalate" onClick="showhideEsc();">
			<div id="show_escalation" style="visibility:hidden;">
			to:
			<select name="escalate_to">
			<?php
			$sql = "SELECT VendorID, VendorName FROM tt_vendors WHERE Status <> 0 ORDER BY VendorName";
			$rs = mysql_query($sql, $conn) or die(mysql_error());
			$row = mysql_fetch_assoc($rs);
			do {  
			?>
            <option value="<?php echo $row['VendorID'] ?>"><?php echo $row['VendorName']?></option>
            <?php
			} while ($row = mysql_fetch_assoc($rs));
			  $count = mysql_num_rows($rs);
			  if($count > 0) {
				  mysql_data_seek($rs, 0);
				  $row = mysql_fetch_assoc($rs);
			  }
			?>
			</select>
			</div>
			</font> 
		</td>
	  </tr>  
	  <tr>
		<td><input type="submit" value="Submit" name="Submit"></td>
	  </tr>
	  </form>
	  </table>
	  <?php
	  //end show box
	  }else{
	  	if($archived == 0){
	  	?>
		<table align="center" border="0" width="90%">
		<form action="tt_view_one.php?tt_id=<?php echo $tt_id; ?>" method="post">
		<input type="hidden" name="parent_tt_id" value="<?php echo $parent_tt_id; ?>">
		<tr>
			<td colspan="2" nowrap>
				<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Archive Ticket:</font> 
				<input type="checkbox" name="Open">
			</td>
		</tr>	 
		<tr>
			<td colspan="2"><input type="submit" value="Submit" name="ArchiveSubmit"></td>
		</tr>
		</form>
		</table>
	  	<?php
	    }
	  }
	 }
	  ?>
      <p>&nbsp;</p>

<?php include("footer.php"); ?>
</body>
</html>
<?php
mysql_free_result($ticket_list);

mysql_free_result($ticket_comments);

//mysql_free_result($client_company);
?>


Return current item: Tech Tickets