home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / ticketsmith / index.php < prev    next >
Encoding:
PHP Script  |  2004-01-31  |  7.7 KB  |  217 lines

  1. <?php  /* TICKETSMITH $Id: index.php,v 1.21 2004/01/31 04:43:44 ajdonnison Exp $ */
  2.  
  3. if (!$canRead) {
  4.     $AppUI->redirect( "m=public&a=access_denied" );
  5. }
  6.  
  7. $type = dPgetParam( $_GET, 'type', '' );
  8. $column = dPgetParam( $_GET, 'column', 'timestamp' );
  9. $direction = dPgetParam( $_GET, 'direction', 'DESC' );
  10. $offset = dPgetParam( $_GET, 'offset', '' );
  11. $action = dPgetParam( $_REQUEST, 'action', null );
  12.  
  13. if($type == ''){
  14.     if($AppUI->getState("ticket_type")){
  15.         $type = $AppUI->getState("ticket_type");
  16.     } else {
  17.         $type = "Open";
  18.     }
  19. } else {
  20.     $AppUI->setState("ticket_type", $_GET["type"]);
  21. }
  22.  
  23. // setup the title block
  24. $titleBlock = new CTitleBlock( 'Trouble Ticket Management', 'gconf-app-icon.png', $m, "$m.$a" );
  25. if ($canEdit) {
  26.     $titleBlock->addCell(
  27.         '<input type="submit" class="button" value="'.$AppUI->_('new ticket').'">', '',
  28.         '<form name="ticketform" action="?m=ticketsmith&a=post_ticket" method="post">', '</form>'
  29.     );
  30. }
  31. $titleBlock->show();
  32.  
  33. require("modules/ticketsmith/config.inc.php");
  34. require("modules/ticketsmith/common.inc.php");
  35.  
  36. /* expunge deleted tickets */
  37. if (@$action == "expunge") {
  38.     $deleted_parents = column2array("SELECT ticket FROM tickets WHERE type = 'Deleted'");
  39.     for ($loop = 0; $loop < count($deleted_parents); $loop++) {
  40.         do_query("DELETE FROM tickets WHERE ticket = '$deleted_parents[$loop]'");
  41.         do_query("DELETE FROM tickets WHERE parent = '$deleted_parents[$loop]'");
  42.     }
  43. }
  44.  
  45. /* setup table & database field stuff */
  46. if ($dPconfig['link_tickets_kludge']) {
  47.     $fields = array("headings" => array("View", "Author", "Subject", "Date", 
  48.                                     "Followup", "Status", "Priority", "Owner", "Link"),
  49.  
  50.                 "columns"  => array("ticket", "author", "subject", "timestamp", 
  51.                                     "activity", "type", "priority", "assignment", "ticket"),
  52.  
  53.                 "types"    => array("view", "email", "normal", "open_date", 
  54.                                     "activity_date", "normal", "priority_view", "user", "attach"),
  55.                               
  56.                 "aligns"   => array("center", "left", "left", "left", "left", 
  57.                                     "center", "center", "center", "center"));
  58. } else {
  59.     $fields = array("headings" => array("View", "Author", "Subject", "Date", 
  60.                                     "Followup", "Status", "Priority", "Owner"),
  61.  
  62.                 "columns"  => array("ticket", "author", "subject", "timestamp", 
  63.                                     "activity", "type", "priority", "assignment"),
  64.  
  65.                 "types"    => array("view", "email", "normal", "open_date", 
  66.                                     "activity_date", "normal", "priority_view", "user"),
  67.                               
  68.                 "aligns"   => array("center", "left", "left", "left", "left", 
  69.                                     "center", "center", "center"));
  70. }
  71.                                                 
  72. /* set up defaults for viewing */
  73. if($type == "my"){
  74.     $title = "My Tickets";
  75. }
  76. else{
  77.     $title = "$type Tickets";
  78. }
  79. $column = @$column ? $column : $CONFIG["order_by"];
  80. $direction = @$direction ? $direction : $CONFIG["message_order"];
  81. $offset = @$offset ? $offset : 0;
  82. $limit = @$limit ? $limit : $CONFIG["view_rows"];
  83.  
  84. /* count tickets */
  85. $query = "SELECT COUNT(*) FROM tickets WHERE parent = '0'";
  86. if ($type != 'All') {
  87.     $query .= " AND type = '$type'";
  88. }
  89. $ticket_count = query2result($query);
  90.  
  91. /* paging controls */
  92. if (($offset + $limit) < $ticket_count) {
  93.     $page_string = ($offset + 1) . " to " . ($offset + $limit) . " of $ticket_count";
  94. }
  95. else {
  96.     $page_string = ($offset + 1) . " to $ticket_count of $ticket_count";
  97. }
  98.  
  99. /* start table */
  100. ?>
  101.  
  102. <table class="tbl" width="100%">
  103. <tr>
  104.     <td colspan="<?php echo count( $fields["headings"] );?>" align="center">
  105.         <table width="100%" border="0" cellspacing="1" cellpadding="1">
  106.         <tr>
  107.             <td width="33%"></td>
  108.             <td width="34%" align="center"><strong><?php echo $AppUI->_($title);?></strong></td>
  109.             <td width="33%" align="right" valign="middle">
  110. <?php
  111. if ($ticket_count > $limit) {
  112.     if ($offset - $limit >= 0) {
  113.         print("<a href=index.php?m=ticketsmith&type=$type&column=$column&direction=$direction&offset=" . ($offset - $limit) . "><img src=images/navleft.gif border=0></a> | \n");
  114.     }
  115.     print($AppUI->_("$page_string")."\n");
  116.     if ($offset + $limit < $ticket_count) {
  117.         print(" | <a href=index.php?m=ticketsmith&type=$type&column=$column&direction=$direction&offset=" . ($offset + $limit) . "><img src=images/navright.gif border=0></a>\n");
  118.     }
  119. }
  120. ?>
  121.             </td>
  122.         </tr>
  123.         </table>
  124.     </td>
  125. </tr>
  126.  
  127. <?php
  128. /* form query */
  129. $select_fields= join(", ", $fields["columns"]);
  130. $query = "SELECT $select_fields FROM tickets WHERE ";
  131. if ($type == "My") {
  132.     $query .= "type = 'Open' AND (assignment = '$AppUI->user_id' OR assignment = '0') AND ";
  133. }
  134. elseif ($type != "All") {
  135.     $query .= "type = '$type' AND ";
  136. }
  137. $query .= "parent = '0' ORDER BY " . urlencode($column) . " $direction LIMIT $offset, $limit";
  138.  
  139. /* do query */
  140. $result = do_query($query);
  141. $parent_count = number_rows($result);
  142.  
  143. /* output tickets */
  144. if ($parent_count) {
  145.     print("<tr>\n");
  146.     for ($loop = 0; $loop < count($fields["headings"]); $loop++) {
  147.         print("<th align=" . $fields["aligns"][$loop] . ">");
  148.         print("<a href=index.php?m=ticketsmith&type=$type");
  149.         print("&column=" . $fields["columns"][$loop]);
  150.         if ($column != $fields["columns"][$loop]) {
  151.             $new_direction = "ASC";
  152.         }
  153.         else {
  154.             if ($direction == "ASC") {
  155.                 $new_direction = "DESC";
  156.             }
  157.             else {
  158.                 $new_direction == "ASC";
  159.             }
  160.         }
  161.         print("&direction=$new_direction");
  162.         print(' class="hdr">' . $AppUI->_($fields["headings"][$loop]) . "</a></th>\n");
  163.     }
  164.     print("</tr>\n");
  165.     while ($row = result2hash($result)) {
  166.         print("<tr height=25>\n");
  167.         for ($loop = 0; $loop < count($fields["headings"]); $loop++) {
  168.             print("<td  bgcolor=white align=" . $fields["aligns"][$loop] . ">\n");
  169.  
  170.             //translate some information, some not
  171.             if ($fields["headings"][$loop] == "Status"){
  172.             print($AppUI->_(format_field($row[$fields["columns"][$loop]], $fields["types"][$loop], $row[$fields["columns"][0]])) . "\n");
  173.         }
  174.         else {
  175.             print(format_field($row[$fields["columns"][$loop]], $fields["types"][$loop], $row[$fields["columns"][0]]) . "\n");
  176.         }
  177.             print("</td>\n");
  178.         }
  179.         print("</tr>\n");
  180.     }
  181. }
  182. else {
  183.     print("<tr height=25>\n");
  184.     print("<td align=center colspan=" . count($fields["headings"]) . ">\n");
  185.     print($AppUI->_('There are no')." ");
  186.     print($type == "All" ? "" : strtolower($AppUI->_($type)) . " ");
  187.     print($AppUI->_('tickets').".\n");
  188.     print("</td>\n");
  189.     print("</tr>\n");
  190. }
  191.  
  192. /* output action links */
  193. print("<tr>\n");
  194. print("<td><br /></td>\n");
  195. print("<td colspan=" . (count($fields["headings"]) - 1) . " align=right>\n");
  196. print("<table width=100% border=0 cellspacing=0 cellpadding=0>\n");
  197. print("<tr height=25><td align=left>");
  198. $types = array("My","Open","Processing","Closed","Deleted","All");
  199. for ($loop = 0; $loop < count($types); $loop++) {
  200.     $toggles[] = "<a href=index.php?m=ticketsmith&type=" . $types[$loop] . ">" . $AppUI->_($types[$loop]) . "</a>";
  201. }
  202. print(join(" | ", $toggles));
  203. print(" ".$AppUI->_('Tickets')."</td>\n");
  204. if ($type == "Deleted" && $parent_count) {
  205.     print("<td align=center><a href=index.php?m=ticketsmith&type=Deleted&action=expunge>".$AppUI->_('Expunge Deleted')."</a></td>");
  206. }
  207. print("<td align=right><a href=index.php?m=ticketsmith&a=search>".$AppUI->_('Search')."</a> | 
  208. <a href=index.php?m=ticketsmith&type=$type>".$AppUI->_('Back to top')."</a></td></tr>\n");
  209. print("</table>\n");
  210. print("</td>\n");
  211. print("</tr>\n");    
  212.  
  213. /* end table */
  214. print("</table>\n");
  215.  
  216. ?>
  217.