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

  1. <?php /* $Id: search.php,v 1.10 2004/01/28 05:47:36 ajdonnison Exp $ */
  2.  
  3. if (!$canRead) {
  4.     $AppUI->redirect( "m=public&a=access_denied" );
  5. }
  6.  
  7.  
  8. require("modules/ticketsmith/config.inc.php");
  9. require("modules/ticketsmith/common.inc.php");
  10. if(empty($search_pattern)) $search_pattern = "";
  11. if(empty($search_field)) $search_field = "";
  12. if(empty($search_depth)) $search_depth = "";
  13. if(empty($sort_column)) $sort_column = "";
  14. /* set title */
  15. $title = "Search Tickets";
  16.  
  17. /* start form */
  18. print("<form name='ticketform' action=index.php?m=ticketsmith&a=search method=\"post\">\n");
  19.  
  20. /* start table */
  21. print("<table class=maintable bgcolor=\"#eeeeee\" width=95%>\n");
  22. print("<tr>\n");
  23. print("<td colspan=\"2\" align=\"center\" bgcolor=#878676 width=100%>\n");
  24. print("<div class=\"heading\">".$AppUI->_($title)."</div>\n");
  25. print("</td>\n</tr>\n");
  26.  
  27. /* field select */
  28. print("<tr>\n");
  29. print("<td align=\"right\"><strong>".$AppUI->_('Field')."</strong></td>\n");
  30. print("<td>");
  31. $field_choices = array("author"  => $AppUI->_("Author"),
  32.                        "body"    => $AppUI->_("Body"),
  33.                        "subject" => $AppUI->_("Subject"));
  34.  
  35.  
  36. $field_selectbox = create_selectbox("search_field", $field_choices, $search_field);
  37. print("$field_selectbox\n");
  38. print("</td>\n");
  39. print("</tr>\n");
  40.  
  41. /* pattern select */
  42. $search_pattern = dPformSafe( $search_pattern, true );
  43. print("<tr>\n");
  44. print("<td align=\"right\"><strong>".$AppUI->_('Pattern')."</strong></td>\n");
  45. print("<td><input type=\"text\" name=\"search_pattern\" value=\"$search_pattern\"></td>\n");
  46. print("</tr>\n");
  47.  
  48. /* depth select */
  49. print("<tr>\n");
  50. print("<td align=\"right\"><strong>".$AppUI->_('Depth')."</strong></td>\n");
  51. print("<td>");
  52. $depth_choices = array("All"     => $AppUI->_("All Tickets"),
  53.                        "Open"    => $AppUI->_("Open Parents"),
  54.                        "Closed"  => $AppUI->_("Closed Parents"),
  55.                        "Deleted" => $AppUI->_("Deleted Parents"),
  56.                        "Child"   => $AppUI->_("Followups")." & ".$AppUI->_("Comments"));
  57.  
  58. $depth_selectbox = create_selectbox("search_depth", $depth_choices, $search_depth);
  59. print("$depth_selectbox\n");
  60. print("</td>\n");
  61. print("</tr>\n");
  62.  
  63. /* sort select */
  64. print("<tr>\n");
  65. print("<td align=\"right\"><strong>".$AppUI->_('Sort By')."</strong></td>\n");
  66. print("<td>");
  67. $sort_choices = array("ticket"     => $AppUI->_("Ticket"),
  68.                       "author"     => $AppUI->_("Author"),
  69.                       "subject"    => $AppUI->_("Subject"),
  70.                       "timestamp"  => $AppUI->_("Date"),
  71.                       "activity"   => $AppUI->_("Activity"),
  72.                       "type"       => $AppUI->_("Type"),
  73.                       "priority"   => $AppUI->_("Priority"),
  74.                       "assignment" => $AppUI->_("Owner"));
  75.  
  76. $sort_selectbox = create_selectbox("sort_column", $sort_choices, $sort_column);
  77. print($sort_selectbox);
  78. print(" <input type=\"radio\" name=\"sort_direction\" value=\"ASC\"> ".$AppUI->_('Ascending'));
  79. print(" <input type=\"radio\" name=\"sort_direction\" value=\"DESC\" checked> ".$AppUI->_('Descending'));
  80. print("</td>\n");
  81. print("</tr>\n");
  82.  
  83. /* submit button */
  84. print("<tr>\n");
  85. print("<td><br /></td>\n");
  86. print('<td><input type="submit" value="'.$AppUI->_('Search').'"></td>');
  87. print("</tr>\n");
  88.  
  89. /* output footer */
  90. print("<tr>\n");
  91. print("<td><br /></td>\n");
  92. print("<td><a href=index.php?m=ticketsmith>".$AppUI->_('Return to ticket list')."</a></td>\n");
  93. print("</tr>\n");
  94.  
  95. /* end table */
  96. print("</table>\n");
  97.  
  98. if ($search_pattern) {
  99.  
  100.     /* set fields */
  101.     $fields = array("columns"  => array("ticket", "author", "subject", "timestamp", "type"),
  102.                     "types"    => array("view", "email", "normal", "elapsed_date", "normal"),
  103.                     "aligns"   => array("center", "left", "left", "left", "center"));
  104.     
  105.     /* start results table */
  106.     print("<p>\n");
  107.     print("<table width=\"95%\" border=\"1\" cellspacing=\"5\" cellpadding=\"5\">\n");
  108.  
  109.     /* form search query */
  110.     $select_columns = join(", ", $fields["columns"]);
  111.     $search_pattern = "%" . escape_string($search_pattern) . "%";
  112.     $query = "SELECT $select_columns FROM tickets WHERE $search_field LIKE '$search_pattern'";
  113.     if ($search_depth == "Child") {
  114.         $query .= " AND parent != 0";
  115.     }
  116.     elseif ($search_depth != "All") {
  117.         $query .= " AND type = '$search_depth'";
  118.     }
  119.     $query .= " ORDER BY $sort_column $sort_direction";
  120.     
  121.     /* perform search */
  122.     $result = do_query($query);
  123.     
  124.     /* display results */
  125.     $result_count = number_rows($result);
  126.     if ($result_count) {
  127.         print("<tr><td colspan=\"5\">".$AppUI->_('There were')." ".$result_count." ".$AppUI->_('results')." ".$AppUI->_('in the given search').".</td></tr>\n");
  128.         while ($row = result2hash($result)) {
  129.             print("<tr>");
  130.             for ($loop = 0; $loop < count($fields["columns"]); $loop++) {
  131.                 print("<td align=\"" . $fields["aligns"][$loop] . "\">");
  132.                 print(format_field($row[$fields["columns"][$loop]], $fields["types"][$loop]));
  133.                 print("</td>");
  134.             }
  135.             print("</tr>\n");
  136.         }
  137.     }
  138.     else {
  139.         print("<tr><td>".$AppUI->_('There were')." ".$AppUI->_('no results')." ".$AppUI->_('in the given search').".</td></tr>\n");
  140.     }
  141.     
  142.     /* end results table */
  143.     print("</table>\n");
  144.  
  145. }
  146.  
  147. /* end form */
  148. print("</form>\n");
  149. ?>
  150.