home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / ticketsmith / view.php < prev   
Encoding:
PHP Script  |  2004-01-29  |  13.2 KB  |  342 lines

  1. <?php /* $Id: view.php,v 1.23 2004/01/29 03:26:48 ajdonnison Exp $ */
  2.  
  3. if (!$canRead) {
  4.     $AppUI->redirect( "m=public&a=access_denied" );
  5. }
  6.  
  7. $ticket = dPgetParam( $_GET, 'ticket', '' );
  8. $ticket_type = dPgetParam( $_GET, 'ticket_type', '' );
  9.  
  10. $type_toggle = dPgetParam( $_POST, 'type_toggle', '' );
  11. $priority_toggle = dPgetParam( $_POST, 'priority_toggle', '' );
  12. $assignment_toggle = dPgetParam( $_POST, 'assignment_toggle', '' );
  13.  
  14. // setup the title block
  15. $titleBlock = new CTitleBlock( 'View Ticket', 'gconf-app-icon.png', $m, "$m.$a" );
  16. $titleBlock->addCrumb( "?m=ticketsmith", "tickets list" );
  17. $titleBlock->addCrumb( "?m=ticketsmith&type=My", "my tickets" );
  18. $titleBlock->show();
  19.  
  20. require("./modules/ticketsmith/config.inc.php");
  21. require("./modules/ticketsmith/common.inc.php");
  22.  
  23. /* Centralize references */
  24. $app_root = $AppUI->getConfig( 'base_url' );
  25.  
  26. /* initialize fields */
  27. if ($ticket_type == "Staff Followup" || $ticket_type == "Client Followup") {
  28.  
  29.     $title = $AppUI->_($ticket_type)." ".$AppUI->_('to Ticket')." #$ticket_parent";
  30.  
  31.     $fields = array("headings" => array("From", "To", "Subject", "Date", "Cc", "<br />"),
  32.                     "columns"  => array("author", "recipient", "subject", "timestamp", "cc", "body"),
  33.                     "types"    => array("email", "original_author", "normal", "elapsed_date", "email", "body"));
  34.  
  35. }
  36. elseif ($ticket_type == "Staff Comment") {
  37.  
  38.     $title = $AppUI->_($ticket_type)." ".$AppUI->_('to Ticket')." #$ticket_parent";
  39.  
  40.     $fields = array("headings" => array("From", "Date", "<br />"),
  41.                     "columns"  => array("author", "timestamp", "body"),
  42.                     "types"    => array("email", "elapsed_date", "body"));
  43.  
  44. }
  45. else {
  46.  
  47.     $title = $AppUI->_('Ticket')." #$ticket";
  48.  
  49.     $fields = array("headings" => array("From", "Subject", "Date", "Cc", "Status",
  50.                                         "Priority", "Owner", "<br />"),
  51.  
  52.                     "columns"  => array("author", "subject", "timestamp", "cc",
  53.                                         "type", "priority", "assignment", "body"),
  54.  
  55.                     "types"    => array("email", "normal", "elapsed_date", "email",
  56.                                         "status", "priority_select", "assignment", "body"));
  57. }
  58.  
  59. /* perform updates */
  60. $orig_assignment = dPgetParam( $_POST, 'orig_assignment', '' );
  61. $author = dPgetParam( $_POST, 'author', '' );
  62. $priority = dPgetParam( $_POST, 'priority', '' );
  63. $subject = dPgetParam( $_POST, 'subject', '' );
  64.  
  65. if (@$type_toggle || @$priority_toggle || @$assignment_toggle) {
  66.     do_query("UPDATE tickets SET type = '$type_toggle', priority = '$priority_toggle', assignment = '$assignment_toggle' WHERE ticket = '$ticket'");
  67.     if(@$assignment_toggle != @$orig_assignment)
  68.     {
  69.         $mailinfo = query2hash("SELECT user_first_name, user_last_name, user_email from users WHERE user_id = $assignment_toggle");
  70.  
  71.         if (@$mail_info['user_email']) {
  72.             $boundary = "_lkqwkASDHASK89271893712893";
  73.             $message = "--$boundary\n";
  74.             $message .= "Content-disposition: inline\n";
  75.             $message .= "Content-type: text/plain\n\n";
  76.             $message .= $AppUI->_('Trouble ticket assigned to you') . ".\n\n";
  77.             $message .= "Ticket ID: $ticket\n";
  78.             $message .= "Author   : $author\n";
  79.             $message .= "Subject  : $subject\n";
  80.             $message .= "View     : $app_root/index.php?m=ticketsmith&a=view&ticket=$ticket\n";
  81.             $message .= "\n--$boundary\n";
  82.             $message .= "Content-disposition: inline\n";
  83.             $message .= "Content-type: text/html\n\n";
  84.             $message .= "<html>\n";
  85.             $message .= "<head>\n";
  86.             $message .= "<style>\n";
  87.             $message .= ".title {\n";
  88.             $message .= "    FONT-SIZE: 18pt; SIZE: 18pt;\n";
  89.             $message .= "}\n";
  90.             $message .= "</style>\n";
  91.             $message .= "<title>".$AppUI->_('Trouble ticket assigned to you')."</title>\n";
  92.             $message .= "</head>\n";
  93.             $message .= "<body>\n";
  94.             $message .= "\n";
  95.             $message .= "<TABLE border=0 cellpadding=4 cellspacing=1>\n";
  96.             $message .= "    <TR>\n";
  97.             $message .= "    <TD valign=top><img src=$app_root/images/icons/ticketsmith.gif alt= border=0 width=42 height=42></td>\n";
  98.             $message .= "        <TD nowrap><span class=title>".$AppUI->_('Trouble Ticket Management')."</span></td>\n";
  99.             $message .= "        <TD valign=top align=right width=100%> </td>\n";
  100.             $message .= "    </tr>\n";
  101.             $message .= "</TABLE>\n";
  102.             $message .= "<TABLE width=600 border=0 cellpadding=4 cellspacing=1 bgcolor=#878676>\n";
  103.             $message .= "    <TR>\n";
  104.             $message .= "        <TD colspan=2><font face=arial,san-serif size=2 color=white>".$AppUI->_('Ticket assigned to you')."</font></TD>\n";
  105.             $message .= "    </tr>\n";
  106.             $message .= "    <TR>\n";
  107.             $message .= "        <TD bgcolor=white nowrap><font face=arial,san-serif size=2>".$AppUI->_('Ticket ID').":</font></TD>\n";
  108.             $message .= "        <TD bgcolor=white nowrap><font face=arial,san-serif size=2>$ticket</font></TD>\n";
  109.             $message .= "    </tr>\n";
  110.             $message .= "    <TR>\n";
  111.             $message .= "        <TD bgcolor=white><font face=arial,san-serif size=2>".$AppUI->_('Author').":</font></TD>\n";
  112.             $message .= "        <TD bgcolor=white><font face=arial,san-serif size=2>" . str_replace(">", ">", str_replace("<", "<", str_replace('"', '', $author))) . "</font></TD>\n";
  113.             $message .= "    </tr>\n";
  114.             $message .= "    <TR>\n";
  115.             $message .= "        <TD bgcolor=white><font face=arial,san-serif size=2>".$AppUI->_('Subject').":</font></TD>\n";
  116.             $message .= "        <TD bgcolor=white><font face=arial,san-serif size=2>$subject</font></TD>\n";
  117.             $message .= "    </tr>\n";
  118.             $message .= "    <TR>\n";
  119.             $message .= "        <TD bgcolor=white nowrap><font face=arial,san-serif size=2>".$AppUI->_('View').":</font></TD>\n";
  120.             $message .= "        <TD bgcolor=white nowrap><a href=\"$app_root/index.php?m=ticketsmith&a=view&ticket=$ticket\"><font face=arial,sans-serif size=2>$app_root/index.php?m=ticketsmith&a=view&ticket=$ticket</font></a></TD>\n";
  121.             $message .= "    </tr>\n";
  122.             $message .= "</TABLE>\n";
  123.             $message .= "</body>\n";
  124.             $message .= "</html>\n";
  125.             $message .= "\n--$boundary--\n";
  126.  
  127.  
  128.             mail($mailinfo["user_email"], $AppUI->_('Trouble ticket')." #$ticket ".$AppUI->_('has been assigned to you'), $message, "From: " . $CONFIG['reply_to'] . "\nContent-type: text/alternative; boundary=\"$boundary\"\nMime-Version: 1.0");
  129.         } // End of check for valid email
  130.     } // End of check for toggle of assignee
  131.  
  132. } // End of check for change in header fields
  133.  
  134. /* start table */
  135. ?>
  136.  
  137. <table class="std" cellspacing="2" cellpadding="3" border="0" width="100%">
  138. <tr>
  139.     <th colspan="2" align="center"><?php echo $title;?></th>
  140. </tr>
  141.  
  142. <form name="ticketform" action="index.php?m=ticketsmith&a=view&ticket=<?php echo $ticket;?>" method="post">
  143. <input type="hidden" name="ticket" value="$ticket" />
  144.  
  145. <?php
  146. /* start form */
  147.  
  148. /* get ticket */
  149. $ticket_info = query2hash("SELECT * FROM tickets WHERE ticket = $ticket");
  150.  
  151. print("<input type=\"hidden\" name=\"orig_assignment\" value='" . $ticket_info["assignment"] . "' />\n");
  152. print("<input type=\"hidden\" name=\"author\" value='" . $ticket_info["author"] . "' />\n");
  153. print("<input type=\"hidden\" name=\"priority\" value='" . $ticket_info["priority"] . "' />\n");
  154. print("<input type=\"hidden\" name=\"subject\" value='" . $ticket_info["subject"] . "' />\n");
  155.  
  156. /* output ticket */
  157. for ($loop = 0; $loop < count($fields["headings"]); $loop++) {
  158.     print("<tr>\n");
  159.     if ( $fields["headings"][$loop] !== "<br />") {
  160.     $fields["headings"][$loop] = $AppUI->_($fields["headings"][$loop]);
  161.     }
  162.     print("<td align=\"right\">" . $fields["headings"][$loop] . "</td>");
  163.     print("<td align=\"left\" class=\"hilite\">" . format_field($ticket_info[$fields["columns"][$loop]], $fields["types"][$loop]) . "</td>\n");
  164.     print("</tr>\n");
  165. }
  166. $ticket_info["assignment"];
  167.  
  168. /* output attachment indicator */
  169. $attach_count = query2result("SELECT attachment FROM tickets WHERE ticket = '$ticket'");
  170.  
  171. if ($attach_count == 1) {
  172.     print("<tr>\n");
  173.     print("<td align=\"left\"><strong>Attachments</strong></td>");
  174.     print("<td align=\"left\">This email had attachments which were removed.</td>\n");
  175.     print("</tr>\n");
  176. } else if ($attach_count == 2) {
  177.   $result = do_query("SELECT file_id, file_name from files, tickets where ticket = '$ticket'
  178.   and file_task = ticket and file_project = 0");
  179.   if (number_rows($result)) {
  180.        print("<tr>\n");
  181.       print("<td align=\"left\"><b>Attachments</b></td>");
  182.       print("<td align=\"left\">");
  183.           while ($row = result2hash($result)) {
  184.               echo "<a href='fileviewer.php?file_id=" . $row["file_id"] . "'>";
  185.               echo $row["file_name"];
  186.             echo "</a><br>\n";
  187.         }
  188.         print("</td>\n");
  189.         print("</tr>\n");
  190.     }
  191. }
  192.  
  193. /* output followup navigation */
  194. if ($ticket_type != "Staff Followup" && $ticket_type != "Client Followup" && $ticket_type != "Staff Comment") {
  195.  
  196.     /* output followups */
  197.     print("<tr>\n");
  198.     print("<td align=\"left\" valign=\"top\"><strong>".$AppUI->_('Followups')."</strong></td>\n");
  199.     print("<td align=\"left\" valign=\"top\">\n");
  200.  
  201.     /* grab followups */
  202.     $query = "SELECT ticket, type, timestamp, author FROM tickets WHERE parent = '$ticket' ORDER BY ticket " . $CONFIG["followup_order"];
  203.     $result = do_query($query);
  204.  
  205.     if (number_rows($result)) {
  206.  
  207.         /* print followups */
  208.         print("<table width=\"100%\" border=\"1\" cellspacing=\"5\" cellpadding=\"5\">\n");
  209.         while ($row = result2hash($result)) {
  210.  
  211.             /* determine row color */
  212.             $color = (@$number++ % 2 == 0) ? "#d3dce3" : "#dddddd";
  213.  
  214.             /* start row */
  215.             print("<tr>\n");
  216.  
  217.             /* do number/author */
  218.             print("<td bgcolor=\"$color\">\n");
  219.             print("<strong>$number</strong> : \n");
  220.             $row["author"] = ereg_replace("\"", "", $row["author"]);
  221.             $row["author"] = htmlspecialchars($row["author"]);
  222.             print($row["author"] . "\n");
  223.             print("</td>\n");
  224.  
  225.             /* do type */
  226.             print("<td bgcolor=\"$color\"><a href=\"index.php?m=ticketsmith&a=view&ticket=" . $row["ticket"] . "\">" . $AppUI->_($row["type"]) . "</a></td>\n");
  227.  
  228.             /* do timestamp */
  229.             print("<td bgcolor=\"$color\">\n");
  230.             print(get_time_ago($row["timestamp"]));
  231.             print("</td>\n");
  232.  
  233.             /* end row */
  234.             print("</tr>\n");
  235.  
  236.         }
  237.         print("</table>\n");
  238.  
  239.     }
  240.     else {
  241.         print("<em>".$AppUI->_('none')."</em>\n");
  242.     }
  243.  
  244.     print("</td>\n</tr>\n");
  245.  
  246. }
  247.  
  248. else {
  249.  
  250.     /* get peer followups */
  251.     $results = do_query("SELECT ticket, type FROM tickets WHERE parent = '$ticket_parent' ORDER BY ticket " . $CONFIG["followup_order"]);
  252.  
  253.     /* parse followups */
  254.     while ($row = result2hash($results)) {
  255.         $peer_tickets[] = $row["ticket"];
  256.     }
  257.  
  258.     /* count peers */
  259.     $peer_count = count($peer_tickets);
  260.  
  261.     if ($peer_count > 1) {
  262.  
  263.         /* start row */
  264.         print("<tr>\n");
  265.         print("<td><strong>Followups</strong></td>\n");
  266.  
  267.         /* start cell */
  268.         print("<td valign=\"middle\">");
  269.  
  270.         /* form peer links */
  271.         for ($loop = 0; $loop < $peer_count; $loop++) {
  272.             if ($peer_tickets[$loop] == $ticket) {
  273.                 $viewed_peer = $loop;
  274.                 $peer_strings[$loop] = "<strong>" . ($loop + 1) . "</strong>";
  275.             }
  276.             else {
  277.                 $peer_strings[$loop] = "<a href=\"index.php?m=ticketsmith&a=view&ticket=$peer_tickets[$loop]\">" . ($loop + 1) . "</a>";
  278.             }
  279.         }
  280.  
  281.         /* previous navigator */
  282.         if ($viewed_peer > 0) {
  283.             print("<a href=\"index.php?m=ticketsmith&a=view&ticket=" . $peer_tickets[$viewed_peer - 1] . "\">");
  284.             print($CONFIG["followup_order"] == "ASC" ?  $AppUI->_("older") : $AppUI->_("newer"));
  285.             print("</a> | ");
  286.         }
  287.  
  288.         /* ticket list */
  289.         print(join(" | ", $peer_strings));
  290.  
  291.         /* next navigator */
  292.         if ($peer_count - $viewed_peer > 1) {
  293.             print(" | <a href=\"index.php?m=ticketsmith&a=view&ticket=" . $peer_tickets[$viewed_peer + 1] . "\">");
  294.             print($CONFIG["followup_order"] == "ASC" ?  "newer" : "older");
  295.             print("</a>");
  296.         }
  297.  
  298.         /* end cell */
  299.         print("</td>\n");
  300.  
  301.         /* end row */
  302.         print("</tr>\n");
  303.  
  304.     }
  305.  
  306. }
  307.  
  308. /* output action links */
  309. print("<tr>\n");
  310. print("<td><br /></td>\n");
  311. print("<td>\n");
  312. print("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
  313. if ($ticket_type == "Staff Followup" || $ticket_type == "Client Followup" || $ticket_type == "Staff Comment") {
  314.     if ($canEdit) {
  315.         print("<tr><td align=\"left\"><a href=index.php?m=ticketsmith&a=followup&ticket=$ticket>".$AppUI->_("Post followup (emails client)")."</a> | ");
  316.         print("<a href=index.php?m=ticketsmith&a=comment&ticket=$ticket>".$AppUI->_('Post internal comment')."</a> | ");
  317.         print("<a href=index.php?m=ticketsmith&a=view&ticket=$ticket_parent>".$AppUI->_('Return to parent')."</a> | ");
  318.     }
  319.     else {
  320.     print("<tr><td align=\"left\"><a href=index.php?m=ticketsmith&a=view&ticket=$ticket_parent>".$AppUI->_('Return to parent')."</a>");
  321.     }
  322.  
  323. }
  324. else {
  325.     if ($canEdit) {
  326.         print("<tr><td align=\"left\"><a href=index.php?m=ticketsmith&a=followup&ticket=$ticket>".$AppUI->_("Post followup (emails client)")."</a> | ");
  327.         print("<a href=index.php?m=ticketsmith&a=comment&ticket=$ticket>".$AppUI->_('Post internal comment')."</a> | ");
  328.     }
  329. }
  330. print("</td>");
  331. print('<td align="right"><a href="index.php?m=ticketsmith&a=view&ticket='.$ticket.'">'.$AppUI->_('Back to top').'</a></td></tr>');
  332. print("</table>\n");
  333. print("</td>");
  334. print("</tr>\n");
  335.  
  336. /* end table */
  337. print("</table>\n");
  338.  
  339. /* end form */
  340. print("</form>\n");
  341. ?>
  342.