Unsupported scripts and control panel web app for a hosting company
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

searchresults.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?PHP
  2. $sqlSelect = 'SELECT i.i_id, c.icat_name, i.i_title, i.i_status, u1.user_name AS i_assignee,
  3. u2.user_name AS i_submitter, i.i_priority, i.i_added, i.i_deadline, i.i_updated
  4. FROM issues_issues AS i
  5. LEFT JOIN issues_categories AS c ON i.icat_id = c.icat_id
  6. LEFT JOIN users AS u1 ON i.i_assignee = u1.user_id
  7. LEFT JOIN users AS u2 ON i.i_submitter = u2.user_id
  8. WHERE 1';
  9. $sqlCount = 'SELECT COUNT(*) FROM issues_issues AS i WHERE 1';
  10. $sql = '';
  11. //keywords
  12. if (isset($search['keywords']) && !empty($search['keywords'])) {
  13. switch ($search['keywordloc']) {
  14. case 'title':
  15. $target = 'i_title';
  16. break;
  17. case 'notes':
  18. $target = 'i_text';
  19. break;
  20. default:
  21. $target = 'CONCAT(i_title,i_text)';
  22. }
  23. $sql .= ' AND '.$target.' LIKE \'%'.m($search['keywords']).'%\'';
  24. }
  25. //submitter
  26. if ($search['submitter'] != 'any' && !empty($search['submitter'])) {
  27. $sql .= ' AND i_submitter = \''.m($search['submitter']).'\'';
  28. }
  29. //assignee
  30. if ($search['assignee'] != 'any' && !empty($search['assignee'])) {
  31. $sql .= ' AND i_assignee = \''.m($search['assignee']).'\'';
  32. }
  33. //added
  34. if ($search['added'] != 'any' && !empty($search['added'])) {
  35. $sql .= ' AND i_added > '.strtotime('-1 '.$search['added']);
  36. }
  37. //updated
  38. if ($search['updated'] != 'any' && !empty($search['updated'])) {
  39. $sql .= ' AND i_updated > '.strtotime('-1 '.$search['updated']);
  40. }
  41. //deadline
  42. if ($search['deadline'] != 'any' && !empty($search['deadline'])) {
  43. $sql .= ' AND i_deadline < '.strtotime('+1 '.$search['deadline']);
  44. }
  45. //priority
  46. $sql .= ' AND (0';
  47. foreach ($search['priority'] as $k => $v) {
  48. $sql .= ' OR i_priority = \''.m($v).'\'';
  49. }
  50. $sql .= ')';
  51. //status
  52. $sql .= ' AND (0';
  53. foreach ($search['status'] as $k => $v) {
  54. $sql .= ' OR i_status = \''.m($v).'\'';
  55. }
  56. $sql .= ')';
  57. //categories
  58. $sql .= ' AND (0';
  59. foreach ($search['categories'] as $k => $v) {
  60. $sql .= ' OR i.icat_id = '.m($v);
  61. }
  62. $sql .= ')';
  63. //order
  64. if (isset($search['order']) && !empty($search['order'])) {
  65. switch ($search['order']) {
  66. case 'added':
  67. $order = 'i_added';
  68. break;
  69. case 'addeddesc':
  70. $order = 'i_added DESC';
  71. break;
  72. case 'updated':
  73. $order = 'i_updated';
  74. break;
  75. case 'updateddesc':
  76. $order = 'i_updated DESC';
  77. break;
  78. case 'status':
  79. $order = 'i_status';
  80. break;
  81. case 'priority':
  82. $order = 'i_priority';
  83. break;
  84. case 'category':
  85. $order = 'i_category';
  86. break;
  87. case 'dealine':
  88. $order = 'i_deadline';
  89. break;
  90. case 'status':
  91. $order = 'i_status';
  92. break;
  93. default:
  94. $order = 'i_added';
  95. }
  96. $sql .= ' ORDER BY '.m($order);
  97. }
  98. //limit
  99. if (ctype_digit(''.$search['limit'])) {
  100. if ($search['limit'] > 0) {
  101. $sql .= ' LIMIT 0,'.m($search['limit']);
  102. }
  103. }
  104. $res = mysql_query($sqlSelect.$sql) or print(mysql_error().'<hr>'.$sqlSelect.$sql);
  105. $res2 = mysql_query($sqlCount.$sql) or print(mysql_error().'<hr>'.$sqlCount.$sql);
  106. $data2 = mysql_fetch_array($res2);
  107. ?>
  108. <div class="block">
  109. <h2><?php echo ((isset($search['title'])) ? $search['title'] : 'Search Results'); ?></h2>
  110. <table class="innerblock">
  111. <tr>
  112. <th>ID</th>
  113. <th>Category</th>
  114. <th>Title</th>
  115. <th>Status</th>
  116. <th>Priority</th>
  117. <th>Submitter</th>
  118. <th>Assignee</th>
  119. <th>Updated</th>
  120. <th>Deadline</th>
  121. </tr>
  122. <?PHP
  123. $i = 0;
  124. if (isset($res) && mysql_num_rows($res) == 0) {
  125. echo '<tr><td colspan="10" style="text-align: center; font-style: italic;">';
  126. echo 'No results returned</td></tr>';
  127. } else {
  128. while ($row = mysql_fetch_assoc($res)) {
  129. $i = 1 - $i;
  130. ?>
  131. <tr class="<?PHP echo ($i == 1) ? 'even' : 'odd'; ?>">
  132. <td><a href="<?PHP echo CP_PATH.'viewissue/'.$row['i_id']; ?>"><?PHP echo $row['i_id']; ?></a></td>
  133. <td><?PHP echo h($row['icat_name']); ?></td>
  134. <td><?PHP echo h($row['i_title']); ?></td>
  135. <td><?PHP echo h($row['i_status']); ?></td>
  136. <td><?PHP echo h($row['i_priority']); ?></td>
  137. <td><?PHP echo n($row['i_submitter']); ?></td>
  138. <td><?PHP echo n($row['i_assignee']); ?></td>
  139. <td><?PHP echo d('Y-m-d H:i',$row['i_updated']); ?></td>
  140. <td>
  141. <?PHP
  142. if ($row['i_deadline'] == 0) {
  143. echo '<span style="text-style: italic">None</span>';
  144. } elseif ($row['i_deadline'] - time() < 0) {
  145. echo '<span style="color: red">Overdue</span>';
  146. } else {
  147. echo duration(time()-$row['i_deadline']);
  148. }
  149. ?>
  150. </td>
  151. </tr>
  152. <?PHP
  153. }
  154. }
  155. ?>
  156. </table>
  157. <h2>Total Results (without limit): <?php echo $data2[0]; ?></h2>
  158. </div>