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

if ($_POST){
	$parent_tt_id = $_POST["parent_tt_id"];
	$newcomment = $_POST["newcomment"];
}
?>
<?php require_once('include/connections.php'); ?>
<?php
mysql_select_db($database, $conn);
//handle if form submitted, and post data
	if($_POST) {
	//post to db
		//figure out the bywho
		if ($usertype=="E") {$bywho = 'C';} else {$bywho='Y';}	//if user=Employee, Click else You
		//add signature to comment
			$newcomment .= '<br><br>By: '.$signature;
		//add comment to table
		  $insertSQL = "INSERT INTO tt_tickets (p_id, comment, bywho, parent_tt_id) VALUES ($p_id, '$newcomment', '$bywho','$parent_tt_id')";          
		  //echo $insertSQL;
		  $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
		//see if user wanted to close ticket, if so, need to UPDATE the parent ticket
			if(isset($_POST["Closed"])) {	//update ticket status
				  $updateSQL = "UPDATE tt_tickets SET status='C' WHERE tt_id = $parent_tt_id";          
				  $Result2 = mysql_query($updateSQL, $conn) or die(mysql_error());
			}
		//sendmail
			////to click
			$newcomment = str_replace('<br>', chr(10), $newcomment); 
			mail($EmailTo,"Ticket Updated","Ticket id: ".$parent_tt_id."  New comment: ".$newcomment,"From:".$EmailFrom);
			////to user
			//mysql_select_db($database, $conn);
			$query_client_email = "SELECT Email FROM tt_users WHERE UserID = $p_id";
			//echo $query_client_email;
			$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);
			mail($row_client_email['Email'],"Ticket Update Received","Thanks, we have received your ticket update.  Your comment follows. " . $newcomment,"From:".$EmailFrom);
	//redirect user
	header("Location:my_tickets_viewall.php");
	}
?>

<?php
$query_ticket_list = "SELECT tt_id, parent_tt_id, cl_id, p_id, date_format(datetimestamp,'%m-%d-%Y %r') as datetimestamp, status, urgency,subject FROM tt_tickets WHERE tt_id = " . $_GET['tt_id'] . " AND p_id = $p_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);

$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);
?>
<?php include("welcome.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>Tech Tickets</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<link href="include/style.css" type="text/css" rel="stylesheet" />
</head>

<body topmargin="0">
<?php include("header.php"); ?>

      <h1 align="center"><font face="Verdana, Arial, Helvetica, sans-serif">Ticket 
        Detail </font></h1>
      <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 $parent_tt_id = $row_ticket_list['tt_id'];?>
            <?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=="C")  {$fullstatus="Closed";} elseif ($status=="P")  {$fullstatus="Pending";} 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>
        <?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 "You said: ";} else {echo "We 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>
      <p><?php 
	  //if status is not closed, show add box
	  if($status!=='C') {
	  	//ticket still open, show box
	  ?>
	  <table align="center" border="0" width="90%">
	  <form action="my_tickets_viewone.php?tt_id=<?php echo $_GET['tt_id']; ?>" method="post">
	  <input type="hidden" name="action" value="save">
	  <tr><td><textarea name="newcomment" cols="50" 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>
			  <input type="hidden" name="parent_tt_id" value="<?php echo $parent_tt_id; ?>">
	  <tr><td><input type="submit" value="Submit" name="Submit"></td></tr>
	  
	  </form>
	  </table>
	  <?php
	  //end show box
	  }; 
	  ?></p>
	  <p align="center">&nbsp;</p>
	  
<?php include("footer.php"); ?>  
</body>
</html>
<?php
mysql_free_result($ticket_list);

mysql_free_result($ticket_comments);
?>
Return current item: Tech Tickets