PageRenderTime 81ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/MantisBT/core/filter_api.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 4685 lines | 4175 code | 243 blank | 267 comment | 409 complexity | 7d7a1ad67a7a71e514e4cddea3dc9153 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. # MantisBT - a php based bugtracking system
  3. # MantisBT is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # MantisBT is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * @package CoreAPI
  17. * @subpackage FilterAPI
  18. * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  19. * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  20. * @link http://www.mantisbt.org
  21. */
  22. /**
  23. * requires current_user_api
  24. */
  25. require_once( 'current_user_api.php' );
  26. /**
  27. * requires user_api
  28. */
  29. require_once( 'user_api.php' );
  30. /**
  31. * requires bug_api
  32. */
  33. require_once( 'bug_api.php' );
  34. /**
  35. * requires collapse_api
  36. */
  37. require_once( 'collapse_api.php' );
  38. /**
  39. * requires relationship_api
  40. */
  41. require_once( 'relationship_api.php' );
  42. /**
  43. * requires tag_api
  44. */
  45. require_once( 'tag_api.php' );
  46. /**
  47. * requires config_filter_defaults_inc
  48. */
  49. require_once( $g_absolute_path . 'config_filter_defaults_inc.php' );
  50. /**
  51. * Allow plugins to define a set of class-based filters, and register/load
  52. * them here to be used by the rest of filter_api.
  53. * @return array Mapping of field name to filter object
  54. */
  55. function filter_get_plugin_filters() {
  56. static $s_field_array = null;
  57. if ( is_null( $s_field_array ) ) {
  58. $s_field_array = array();
  59. $t_all_plugin_filters = event_signal( 'EVENT_FILTER_FIELDS' );
  60. foreach( $t_all_plugin_filters as $t_plugin => $t_plugin_filters ) {
  61. foreach( $t_plugin_filters as $t_callback => $t_plugin_filter_array ) {
  62. if ( is_array( $t_plugin_filter_array ) ) {
  63. foreach( $t_plugin_filter_array as $t_filter_class ) {
  64. if ( class_exists( $t_filter_class ) && is_subclass_of( $t_filter_class, 'MantisFilter' ) ) {
  65. $t_filter_object = new $t_filter_class();
  66. $t_field_name = $t_plugin . '_' . $t_filter_object->field;
  67. $s_field_array[ $t_field_name ] = $t_filter_object;
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. return $s_field_array;
  75. }
  76. /**
  77. * Get a permalink for the current active filter. The results of using these fields by other users
  78. * can be inconsistent with the original results due to fields like "Myself", "Current Project",
  79. * and due to access level.
  80. * @param array $p_custom_filter
  81. * @return string the search.php?xxxx or an empty string if no criteria applied.
  82. */
  83. function filter_get_url( $p_custom_filter ) {
  84. $t_query = array();
  85. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_PROJECT_ID] ) ) {
  86. $t_project_id = $p_custom_filter[FILTER_PROPERTY_PROJECT_ID];
  87. if( count( $t_project_id ) == 1 && $t_project_id[0] == META_FILTER_CURRENT ) {
  88. $t_project_id = array(
  89. helper_get_current_project(),
  90. );
  91. }
  92. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PROJECT_ID, $t_project_id );
  93. }
  94. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_FREE_TEXT] ) ) {
  95. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FREE_TEXT, $p_custom_filter[FILTER_PROPERTY_FREE_TEXT] );
  96. }
  97. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_CATEGORY] ) ) {
  98. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_CATEGORY, $p_custom_filter[FILTER_PROPERTY_CATEGORY] );
  99. }
  100. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_REPORTER_ID] ) ) {
  101. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_REPORTER_ID, $p_custom_filter[FILTER_PROPERTY_REPORTER_ID] );
  102. }
  103. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_STATUS_ID] ) ) {
  104. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_STATUS_ID, $p_custom_filter[FILTER_PROPERTY_STATUS_ID] );
  105. }
  106. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_MONITOR_USER_ID] ) ) {
  107. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_MONITOR_USER_ID, $p_custom_filter[FILTER_PROPERTY_MONITOR_USER_ID] );
  108. }
  109. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_HANDLER_ID] ) ) {
  110. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HANDLER_ID, $p_custom_filter[FILTER_PROPERTY_HANDLER_ID] );
  111. }
  112. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_NOTE_USER_ID] ) ) {
  113. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_NOTE_USER_ID, $p_custom_filter[FILTER_PROPERTY_NOTE_USER_ID] );
  114. }
  115. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_SEVERITY_ID] ) ) {
  116. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SEVERITY_ID, $p_custom_filter[FILTER_PROPERTY_SEVERITY_ID] );
  117. }
  118. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_RESOLUTION_ID] ) ) {
  119. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RESOLUTION_ID, $p_custom_filter[FILTER_PROPERTY_RESOLUTION_ID] );
  120. }
  121. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRIORITY_ID] ) ) {
  122. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRIORITY_ID, $p_custom_filter[FILTER_PROPERTY_PRIORITY_ID] );
  123. }
  124. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_VIEW_STATE_ID] ) ) {
  125. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_VIEW_STATE_ID, $p_custom_filter[FILTER_PROPERTY_VIEW_STATE_ID] );
  126. }
  127. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) ) {
  128. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SHOW_STICKY_ISSUES, $p_custom_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] );
  129. }
  130. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRODUCT_VERSION] ) ) {
  131. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRODUCT_VERSION, $p_custom_filter[FILTER_PROPERTY_PRODUCT_VERSION] );
  132. }
  133. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRODUCT_BUILD] ) ) {
  134. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRODUCT_BUILD, $p_custom_filter[FILTER_PROPERTY_PRODUCT_BUILD] );
  135. }
  136. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_FIXED_IN_VERSION] ) ) {
  137. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FIXED_IN_VERSION, $p_custom_filter[FILTER_PROPERTY_FIXED_IN_VERSION] );
  138. }
  139. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_TARGET_VERSION] ) ) {
  140. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TARGET_VERSION, $p_custom_filter[FILTER_PROPERTY_TARGET_VERSION] );
  141. }
  142. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
  143. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SORT_FIELD_NAME, $p_custom_filter[FILTER_PROPERTY_SORT_FIELD_NAME] );
  144. }
  145. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_SORT_DIRECTION] ) ) {
  146. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SORT_DIRECTION, $p_custom_filter[FILTER_PROPERTY_SORT_DIRECTION] );
  147. }
  148. if( !filter_field_is_any( $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] ) ) {
  149. if( $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] != config_get( 'default_limit_view' ) ) {
  150. $t_query[] = filter_encode_field_and_value( FILTER_PROPERTY_ISSUES_PER_PAGE, $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] );
  151. }
  152. }
  153. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] ) ) {
  154. if( $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] != config_get( 'default_show_changed' ) ) {
  155. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HIGHLIGHT_CHANGED, $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] );
  156. }
  157. }
  158. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_HIDE_STATUS_ID] ) ) {
  159. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HIDE_STATUS_ID, $p_custom_filter[FILTER_PROPERTY_HIDE_STATUS_ID] );
  160. }
  161. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_NOT_ASSIGNED] ) ) {
  162. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_NOT_ASSIGNED, $p_custom_filter[FILTER_PROPERTY_NOT_ASSIGNED] );
  163. }
  164. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) ) {
  165. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FILTER_BY_DATE, $p_custom_filter[FILTER_PROPERTY_FILTER_BY_DATE] );
  166. # The start and end dates are only applicable if filter by date is set.
  167. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_DAY] ) ) {
  168. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_DAY, $p_custom_filter[FILTER_PROPERTY_START_DAY] );
  169. }
  170. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_DAY] ) ) {
  171. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_DAY, $p_custom_filter[FILTER_PROPERTY_END_DAY] );
  172. }
  173. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_MONTH] ) ) {
  174. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_MONTH, $p_custom_filter[FILTER_PROPERTY_START_MONTH] );
  175. }
  176. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_MONTH] ) ) {
  177. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_MONTH, $p_custom_filter[FILTER_PROPERTY_END_MONTH] );
  178. }
  179. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_YEAR] ) ) {
  180. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_YEAR, $p_custom_filter[FILTER_PROPERTY_START_YEAR] );
  181. }
  182. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_YEAR] ) ) {
  183. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_YEAR, $p_custom_filter[FILTER_PROPERTY_END_YEAR] );
  184. }
  185. }
  186. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] ) ) {
  187. if( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] != -1 ) {
  188. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RELATIONSHIP_TYPE, $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] );
  189. }
  190. }
  191. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] ) ) {
  192. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RELATIONSHIP_BUG, $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] );
  193. }
  194. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_PLATFORM] ) ) {
  195. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PLATFORM, $p_custom_filter[FILTER_PROPERTY_PLATFORM] );
  196. }
  197. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_OS] ) ) {
  198. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_OS, $p_custom_filter[FILTER_PROPERTY_OS] );
  199. }
  200. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_OS_BUILD] ) ) {
  201. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_OS_BUILD, $p_custom_filter[FILTER_PROPERTY_OS_BUILD] );
  202. }
  203. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_TAG_STRING] ) ) {
  204. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TAG_STRING, $p_custom_filter[FILTER_PROPERTY_TAG_STRING] );
  205. }
  206. if( !filter_field_is_any( $p_custom_filter[FILTER_PROPERTY_TAG_SELECT] ) ) {
  207. $t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TAG_SELECT, $p_custom_filter[FILTER_PROPERTY_TAG_SELECT] );
  208. }
  209. if( isset( $p_custom_filter['custom_fields'] ) ) {
  210. foreach( $p_custom_filter['custom_fields'] as $t_custom_field_id => $t_custom_field_values ) {
  211. if( !filter_field_is_any( $t_custom_field_values ) ) {
  212. $t_query[] = filter_encode_field_and_value( 'custom_field_' . $t_custom_field_id, $t_custom_field_values );
  213. }
  214. }
  215. }
  216. # Allow plugins to add filter fields
  217. $t_plugin_filter_array = filter_get_plugin_filters();
  218. foreach( $t_plugin_filter_array as $t_field_name => $t_filter_object ) {
  219. if( !filter_field_is_any( $p_custom_filter[ $t_field_name ] ) ) {
  220. $t_query[] = filter_encode_field_and_value( $t_field_name, $p_custom_filter[ $t_field_name ], $t_filter_object->type );
  221. }
  222. }
  223. if( count( $t_query ) > 0 ) {
  224. $t_query_str = implode( $t_query, '&' );
  225. $t_url = config_get( 'path' ) . 'search.php?' . $t_query_str;
  226. } else {
  227. $t_url = '';
  228. }
  229. return $t_url;
  230. }
  231. /**
  232. * Encodes a field and it's value for the filter URL. This handles the URL encoding
  233. * and arrays.
  234. * @param string $p_field_name The field name.
  235. * @param string $p_field_value The field value (can be an array)
  236. * @return string url encoded string
  237. */
  238. function filter_encode_field_and_value( $p_field_name, $p_field_value, $p_field_type=null ) {
  239. $t_query_array = array();
  240. if( is_array( $p_field_value ) ) {
  241. $t_count = count( $p_field_value );
  242. if( $t_count > 1 || $p_field_type == FILTER_TYPE_MULTI_STRING || $p_field_type == FILTER_TYPE_MULTI_INT ) {
  243. foreach( $p_field_value as $t_value ) {
  244. $t_query_array[] = urlencode( $p_field_name . '[]' ) . '=' . urlencode( $t_value );
  245. }
  246. }
  247. else if( $t_count == 1 ) {
  248. $t_query_array[] = urlencode( $p_field_name ) . '=' . urlencode( $p_field_value[0] );
  249. }
  250. } else {
  251. $t_query_array[] = urlencode( $p_field_name ) . '=' . urlencode( $p_field_value );
  252. }
  253. return implode( $t_query_array, '&' );
  254. }
  255. # ==========================================================================
  256. # GENERAL FUNCTIONS =
  257. # ==========================================================================
  258. /**
  259. * Checks the supplied value to see if it is an ANY value.
  260. * @param string $p_field_value - The value to check.
  261. * @return bool true for "ANY" values and false for others. "ANY" means filter criteria not active.
  262. */
  263. function filter_field_is_any( $p_field_value ) {
  264. if( is_array( $p_field_value ) ) {
  265. if( count( $p_field_value ) == 0 ) {
  266. return true;
  267. }
  268. foreach( $p_field_value as $t_value ) {
  269. if(( META_FILTER_ANY == $t_value ) && ( is_numeric( $t_value ) ) ) {
  270. return true;
  271. }
  272. }
  273. } else {
  274. if( is_string( $p_field_value ) && is_blank( $p_field_value ) ) {
  275. return true;
  276. }
  277. if( is_bool( $p_field_value ) && !$p_field_value ) {
  278. return true;
  279. }
  280. if(( META_FILTER_ANY == $p_field_value ) && ( is_numeric( $p_field_value ) ) ) {
  281. return true;
  282. }
  283. }
  284. return false;
  285. }
  286. /**
  287. * Checks the supplied value to see if it is a NONE value.
  288. * @param string $p_field_value - The value to check.
  289. * @return bool true for "NONE" values and false for others.
  290. * @todo is a check for these necessary? if ( ( $t_filter_value === 'none' ) || ( $t_filter_value === '[none]' ) )
  291. */
  292. function filter_field_is_none( $p_field_value ) {
  293. if( is_array( $p_field_value ) ) {
  294. foreach( $p_field_value as $t_value ) {
  295. if(( META_FILTER_NONE == $t_value ) && ( is_numeric( $t_value ) ) ) {
  296. return true;
  297. }
  298. }
  299. } else {
  300. if( is_string( $p_field_value ) && is_blank( $p_field_value ) ) {
  301. return false;
  302. }
  303. if(( META_FILTER_NONE == $p_field_value ) && ( is_numeric( $p_field_value ) ) ) {
  304. return true;
  305. }
  306. }
  307. return false;
  308. }
  309. /**
  310. * Checks the supplied value to see if it is a MYSELF value.
  311. * @param string $p_field_value - The value to check.
  312. * @return bool true for "MYSELF" values and false for others.
  313. */
  314. function filter_field_is_myself( $p_field_value ) {
  315. return( META_FILTER_MYSELF == $p_field_value ? TRUE : FALSE );
  316. }
  317. /**
  318. * @param $p_count
  319. * @param $p_per_page
  320. * @return int
  321. */
  322. function filter_per_page( $p_filter, $p_count, $p_per_page ) {
  323. $p_per_page = (( NULL == $p_per_page ) ? (int) $p_filter[FILTER_PROPERTY_ISSUES_PER_PAGE] : $p_per_page );
  324. $p_per_page = (( 0 == $p_per_page || -1 == $p_per_page ) ? $p_count : $p_per_page );
  325. return (int) abs( $p_per_page );
  326. }
  327. /**
  328. * Use $p_count and $p_per_page to determine how many pages to split this list up into.
  329. * For the sake of consistency have at least one page, even if it is empty.
  330. * @param $p_count
  331. * @param $p_per_page
  332. * @return $t_page_count
  333. */
  334. function filter_page_count( $p_count, $p_per_page ) {
  335. $t_page_count = ceil( $p_count / $p_per_page );
  336. if( $t_page_count < 1 ) {
  337. $t_page_count = 1;
  338. }
  339. return $t_page_count;
  340. }
  341. /**
  342. * Checks to make sure $p_page_number isn't past the last page.
  343. * and that $p_page_number isn't before the first page
  344. * @param $p_page_number
  345. * @param $p_page_count
  346. */
  347. function filter_valid_page_number( $p_page_number, $p_page_count ) {
  348. if( $p_page_number > $p_page_count ) {
  349. $p_page_number = $p_page_count;
  350. }
  351. if( $p_page_number < 1 ) {
  352. $p_page_number = 1;
  353. }
  354. return $p_page_number;
  355. }
  356. /**
  357. * Figure out the offset into the db query, offset is which record to start querying from
  358. * @param int $p_page_number
  359. * @param int $p_per_page
  360. * @return int
  361. */
  362. function filter_offset( $p_page_number, $p_per_page ) {
  363. return(( (int) $p_page_number -1 ) * (int) $p_per_page );
  364. }
  365. /**
  366. * Make sure that our filters are entirely correct and complete (it is possible that they are not).
  367. * We need to do this to cover cases where we don't have complete control over the filters given.s
  368. * @param array $p_filter_arr
  369. * @return mixed
  370. * @todo function needs to be abstracted
  371. */
  372. function filter_ensure_valid_filter( $p_filter_arr ) {
  373. # extend current filter to add information passed via POST
  374. if( !isset( $p_filter_arr['_version'] ) ) {
  375. $p_filter_arr['_version'] = config_get( 'cookie_version' );
  376. }
  377. $t_cookie_vers = (int) utf8_substr( $p_filter_arr['_version'], 1 );
  378. if( utf8_substr( config_get( 'cookie_version' ), 1 ) > $t_cookie_vers ) {
  379. # if the version is old, update it
  380. $p_filter_arr['_version'] = config_get( 'cookie_version' );
  381. }
  382. if( !isset( $p_filter_arr['_view_type'] ) ) {
  383. $p_filter_arr['_view_type'] = gpc_get_string( 'view_type', 'simple' );
  384. }
  385. if( !isset( $p_filter_arr[FILTER_PROPERTY_ISSUES_PER_PAGE] ) ) {
  386. $p_filter_arr[FILTER_PROPERTY_ISSUES_PER_PAGE] = gpc_get_int( FILTER_PROPERTY_ISSUES_PER_PAGE, config_get( 'default_limit_view' ) );
  387. }
  388. if( !isset( $p_filter_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED] ) ) {
  389. $p_filter_arr[FILTER_PROPERTY_HIGHLIGHT_CHANGED] = config_get( 'default_show_changed' );
  390. }
  391. if( !isset( $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) ) {
  392. $p_filter_arr[FILTER_PROPERTY_SHOW_STICKY_ISSUES] = gpc_string_to_bool( config_get( 'show_sticky_issues' ) );
  393. }
  394. if( !isset( $p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
  395. $p_filter_arr[FILTER_PROPERTY_SORT_FIELD_NAME] = "last_updated";
  396. }
  397. if( !isset( $p_filter_arr[FILTER_PROPERTY_SORT_DIRECTION] ) ) {
  398. $p_filter_arr[FILTER_PROPERTY_SORT_DIRECTION] = "DESC";
  399. }
  400. if( !isset( $p_filter_arr[FILTER_PROPERTY_PLATFORM] ) ) {
  401. $p_filter_arr[FILTER_PROPERTY_PLATFORM] = array(
  402. 0 => META_FILTER_ANY,
  403. );
  404. }
  405. if( !isset( $p_filter_arr[FILTER_PROPERTY_OS] ) ) {
  406. $p_filter_arr[FILTER_PROPERTY_OS] = array(
  407. 0 => META_FILTER_ANY,
  408. );
  409. }
  410. if( !isset( $p_filter_arr[FILTER_PROPERTY_OS_BUILD] ) ) {
  411. $p_filter_arr[FILTER_PROPERTY_OS_BUILD] = array(
  412. 0 => META_FILTER_ANY,
  413. );
  414. }
  415. if( !isset( $p_filter_arr[FILTER_PROPERTY_PROJECT_ID] ) ) {
  416. $p_filter_arr[FILTER_PROPERTY_PROJECT_ID] = array(
  417. 0 => META_FILTER_CURRENT,
  418. );
  419. }
  420. if( !isset( $p_filter_arr[FILTER_PROPERTY_START_MONTH] ) ) {
  421. $p_filter_arr[FILTER_PROPERTY_START_MONTH] = gpc_get_string( FILTER_PROPERTY_START_MONTH, date( 'm' ) );
  422. }
  423. if( !isset( $p_filter_arr[FILTER_PROPERTY_START_DAY] ) ) {
  424. $p_filter_arr[FILTER_PROPERTY_START_DAY] = gpc_get_string( FILTER_PROPERTY_START_DAY, 1 );
  425. }
  426. if( !isset( $p_filter_arr[FILTER_PROPERTY_START_YEAR] ) ) {
  427. $p_filter_arr[FILTER_PROPERTY_START_YEAR] = gpc_get_string( FILTER_PROPERTY_START_YEAR, date( 'Y' ) );
  428. }
  429. if( !isset( $p_filter_arr[FILTER_PROPERTY_END_MONTH] ) ) {
  430. $p_filter_arr[FILTER_PROPERTY_END_MONTH] = gpc_get_string( FILTER_PROPERTY_END_MONTH, date( 'm' ) );
  431. }
  432. if( !isset( $p_filter_arr[FILTER_PROPERTY_END_DAY] ) ) {
  433. $p_filter_arr[FILTER_PROPERTY_END_DAY] = gpc_get_string( FILTER_PROPERTY_END_DAY, date( 'd' ) );
  434. }
  435. if( !isset( $p_filter_arr[FILTER_PROPERTY_END_YEAR] ) ) {
  436. $p_filter_arr[FILTER_PROPERTY_END_YEAR] = gpc_get_string( FILTER_PROPERTY_END_YEAR, date( 'Y' ) );
  437. }
  438. if( !isset( $p_filter_arr[FILTER_PROPERTY_FREE_TEXT] ) ) {
  439. $p_filter_arr[FILTER_PROPERTY_FREE_TEXT] = '';
  440. }
  441. if( !isset( $p_filter_arr[FILTER_PROPERTY_NOT_ASSIGNED] ) ) {
  442. $p_filter_arr[FILTER_PROPERTY_NOT_ASSIGNED] = gpc_get_bool( FILTER_PROPERTY_NOT_ASSIGNED, false );
  443. }
  444. if( !isset( $p_filter_arr[FILTER_PROPERTY_FILTER_BY_DATE] ) ) {
  445. $p_filter_arr[FILTER_PROPERTY_FILTER_BY_DATE] = gpc_get_bool( FILTER_PROPERTY_FILTER_BY_DATE, false );
  446. }
  447. if( !isset( $p_filter_arr[FILTER_PROPERTY_VIEW_STATE_ID] ) ) {
  448. $p_filter_arr[FILTER_PROPERTY_VIEW_STATE_ID] = gpc_get( FILTER_PROPERTY_VIEW_STATE_ID, '' );
  449. }
  450. else if( filter_field_is_any( $p_filter_arr[FILTER_PROPERTY_VIEW_STATE_ID] ) ) {
  451. $p_filter_arr[FILTER_PROPERTY_VIEW_STATE_ID] = META_FILTER_ANY;
  452. }
  453. if( !isset( $p_filter_arr[FILTER_PROPERTY_RELATIONSHIP_TYPE] ) ) {
  454. $p_filter_arr[FILTER_PROPERTY_RELATIONSHIP_TYPE] = gpc_get_int( FILTER_PROPERTY_RELATIONSHIP_TYPE, -1 );
  455. }
  456. if( !isset( $p_filter_arr[FILTER_PROPERTY_RELATIONSHIP_BUG] ) ) {
  457. $p_filter_arr[FILTER_PROPERTY_RELATIONSHIP_BUG] = gpc_get_int( FILTER_PROPERTY_RELATIONSHIP_BUG, 0 );
  458. }
  459. if( !isset( $p_filter_arr[FILTER_PROPERTY_TARGET_VERSION] ) ) {
  460. $p_filter_arr[FILTER_PROPERTY_TARGET_VERSION] = META_FILTER_ANY;
  461. }
  462. if( !isset( $p_filter_arr[FILTER_PROPERTY_TAG_STRING] ) ) {
  463. $p_filter_arr[FILTER_PROPERTY_TAG_STRING] = gpc_get_string( FILTER_PROPERTY_TAG_STRING, '' );
  464. }
  465. if( !isset( $p_filter_arr[FILTER_PROPERTY_TAG_SELECT] ) ) {
  466. $p_filter_arr[FILTER_PROPERTY_TAG_SELECT] = gpc_get_string( FILTER_PROPERTY_TAG_SELECT, '' );
  467. }
  468. # initialize plugin filters
  469. $t_plugin_filters = filter_get_plugin_filters();
  470. foreach( $t_plugin_filters as $t_field_name => $t_filter_object ) {
  471. if( !isset( $p_filter_arr[ $t_field_name ] ) ) {
  472. switch( $t_filter_object->type ) {
  473. case FILTER_TYPE_STRING:
  474. $p_filter_arr[ $t_field_name ] = gpc_get_string( $t_field_name, $t_filter_object->default );
  475. break;
  476. case FILTER_TYPE_INT:
  477. $p_filter_arr[ $t_field_name ] = gpc_get_int( $t_field_name, (int)$t_filter_object->default );
  478. break;
  479. case FILTER_TYPE_BOOLEAN:
  480. $p_filter_arr[ $t_field_name ] = gpc_get_bool( $t_field_name, (bool)$t_filter_object->default );
  481. break;
  482. case FILTER_TYPE_MULTI_STRING:
  483. $p_filter_arr[ $t_field_name ] = gpc_get_string_array( $t_field_name, array( 0 => META_FILTER_ANY ) );
  484. break;
  485. case FILTER_TYPE_MULTI_INT:
  486. $p_filter_arr[ $t_field_name ] = gpc_get_int_array( $t_field_name, array( 0 => META_FILTER_ANY ) );
  487. break;
  488. default:
  489. $p_filter_arr[ $t_field_name ] = META_FILTER_ANY;
  490. }
  491. }
  492. if ( ! $t_filter_object->validate( $p_filter_arr[ $t_field_name ] ) ) {
  493. $p_filter_arr[ $t_field_name ] = $t_filter_object->default;
  494. }
  495. }
  496. $t_custom_fields = custom_field_get_ids();
  497. # @@@ (thraxisp) This should really be the linked ids, but we don't know the project
  498. $f_custom_fields_data = array();
  499. if( is_array( $t_custom_fields ) && ( count( $t_custom_fields ) > 0 ) ) {
  500. foreach( $t_custom_fields as $t_cfid ) {
  501. if( is_array( gpc_get( 'custom_field_' . $t_cfid, null ) ) ) {
  502. $f_custom_fields_data[$t_cfid] = gpc_get_string_array( 'custom_field_' . $t_cfid, META_FILTER_ANY );
  503. } else {
  504. $f_custom_fields_data[$t_cfid] = gpc_get_string( 'custom_field_' . $t_cfid, META_FILTER_ANY );
  505. $f_custom_fields_data[$t_cfid] = array(
  506. $f_custom_fields_data[$t_cfid],
  507. );
  508. }
  509. }
  510. }
  511. # validate sorting
  512. $t_fields = helper_get_columns_to_view();
  513. $t_n_fields = count( $t_fields );
  514. for( $i = 0;$i < $t_n_fields;$i++ ) {
  515. if( isset( $t_fields[$i] ) && in_array( $t_fields[$i], array( 'selection', 'edit', 'bugnotes_count', 'attachment' ) ) ) {
  516. unset( $t_fields[$i] );
  517. }
  518. }
  519. $t_sort_fields = explode( ',', $p_filter_arr['sort'] );
  520. $t_dir_fields = explode( ',', $p_filter_arr['dir'] );
  521. for( $i = 0;$i < 2;$i++ ) {
  522. if( isset( $t_sort_fields[$i] ) ) {
  523. $t_drop = false;
  524. $t_sort = $t_sort_fields[$i];
  525. if( strpos( $t_sort, 'custom_' ) === 0 ) {
  526. if( false === custom_field_get_id_from_name( utf8_substr( $t_sort, utf8_strlen( 'custom_' ) ) ) ) {
  527. $t_drop = true;
  528. }
  529. } else {
  530. if( !in_array( $t_sort, $t_fields ) ) {
  531. $t_drop = true;
  532. }
  533. }
  534. if( !in_array( $t_dir_fields[$i], array( "ASC", "DESC" ) ) ) {
  535. $t_drop = true;
  536. }
  537. if( $t_drop ) {
  538. unset( $t_sort_fields[$i] );
  539. unset( $t_dir_fields[$i] );
  540. }
  541. }
  542. }
  543. if( count( $t_sort_fields ) > 0 ) {
  544. $p_filter_arr['sort'] = implode( ',', $t_sort_fields );
  545. $p_filter_arr['dir'] = implode( ',', $t_dir_fields );
  546. } else {
  547. $p_filter_arr['sort'] = "last_updated";
  548. $p_filter_arr['dir'] = "DESC";
  549. }
  550. # validate or filter junk from other fields
  551. $t_multi_select_list = array(
  552. FILTER_PROPERTY_CATEGORY => 'string',
  553. FILTER_PROPERTY_SEVERITY_ID => 'int',
  554. FILTER_PROPERTY_STATUS_ID => 'int',
  555. FILTER_PROPERTY_REPORTER_ID => 'int',
  556. FILTER_PROPERTY_HANDLER_ID => 'int',
  557. FILTER_PROPERTY_NOTE_USER_ID => 'int',
  558. FILTER_PROPERTY_RESOLUTION_ID => 'int',
  559. FILTER_PROPERTY_PRIORITY_ID => 'int',
  560. FILTER_PROPERTY_PRODUCT_BUILD => 'string',
  561. FILTER_PROPERTY_PRODUCT_VERSION => 'string',
  562. FILTER_PROPERTY_HIDE_STATUS_ID => 'int',
  563. FILTER_PROPERTY_FIXED_IN_VERSION => 'string',
  564. FILTER_PROPERTY_TARGET_VERSION => 'string',
  565. FILTER_PROPERTY_MONITOR_USER_ID => 'int',
  566. 'show_profile' => 'int',
  567. );
  568. foreach( $t_multi_select_list as $t_multi_field_name => $t_multi_field_type ) {
  569. if( !isset( $p_filter_arr[$t_multi_field_name] ) ) {
  570. if( FILTER_PROPERTY_HIDE_STATUS_ID == $t_multi_field_name ) {
  571. $p_filter_arr[$t_multi_field_name] = array(
  572. config_get( 'hide_status_default' ),
  573. );
  574. }
  575. else if( 'custom_fields' == $t_multi_field_name ) {
  576. $p_filter_arr[$t_multi_field_name] = array(
  577. $f_custom_fields_data,
  578. );
  579. } else {
  580. $p_filter_arr[$t_multi_field_name] = array(
  581. META_FILTER_ANY,
  582. );
  583. }
  584. } else {
  585. if( !is_array( $p_filter_arr[$t_multi_field_name] ) ) {
  586. $p_filter_arr[$t_multi_field_name] = array(
  587. $p_filter_arr[$t_multi_field_name],
  588. );
  589. }
  590. $t_checked_array = array();
  591. foreach( $p_filter_arr[$t_multi_field_name] as $t_filter_value ) {
  592. $t_filter_value = stripslashes( $t_filter_value );
  593. if(( $t_filter_value === 'any' ) || ( $t_filter_value === '[any]' ) ) {
  594. $t_filter_value = META_FILTER_ANY;
  595. }
  596. if(( $t_filter_value === 'none' ) || ( $t_filter_value === '[none]' ) ) {
  597. $t_filter_value = META_FILTER_NONE;
  598. }
  599. if( 'string' == $t_multi_field_type ) {
  600. $t_checked_array[] = db_prepare_string( $t_filter_value );
  601. }
  602. else if( 'int' == $t_multi_field_type ) {
  603. $t_checked_array[] = db_prepare_int( $t_filter_value );
  604. }
  605. else if( 'array' == $t_multi_field_type ) {
  606. $t_checked_array[] = $t_filter_value;
  607. }
  608. }
  609. $p_filter_arr[$t_multi_field_name] = $t_checked_array;
  610. }
  611. }
  612. if( is_array( $t_custom_fields ) && ( count( $t_custom_fields ) > 0 ) ) {
  613. foreach( $t_custom_fields as $t_cfid ) {
  614. if( !isset( $p_filter_arr['custom_fields'][$t_cfid] ) ) {
  615. $p_filter_arr['custom_fields'][$t_cfid] = array(
  616. META_FILTER_ANY,
  617. );
  618. } else {
  619. if( !is_array( $p_filter_arr['custom_fields'][$t_cfid] ) ) {
  620. $p_filter_arr['custom_fields'][$t_cfid] = array(
  621. $p_filter_arr['custom_fields'][$t_cfid],
  622. );
  623. }
  624. $t_checked_array = array();
  625. foreach( $p_filter_arr['custom_fields'][$t_cfid] as $t_filter_value ) {
  626. $t_filter_value = stripslashes( $t_filter_value );
  627. if(( $t_filter_value === 'any' ) || ( $t_filter_value === '[any]' ) ) {
  628. $t_filter_value = META_FILTER_ANY;
  629. }
  630. $t_checked_array[] = db_prepare_string( $t_filter_value );
  631. }
  632. $p_filter_arr['custom_fields'][$t_cfid] = $t_checked_array;
  633. }
  634. }
  635. }
  636. # all of our filter values are now guaranteed to be there, and correct.
  637. return $p_filter_arr;
  638. }
  639. /**
  640. * Get the standard filter that is to be used when no filter was previously saved.
  641. * When creating specific filters, this can be used as a basis for the filter, where
  642. * specific entries can be overridden.
  643. * @return mixed
  644. */
  645. function filter_get_default() {
  646. $t_hide_status_default = config_get( 'hide_status_default' );
  647. $t_default_show_changed = config_get( 'default_show_changed' );
  648. $t_filter = array(
  649. FILTER_PROPERTY_CATEGORY => Array(
  650. '0' => META_FILTER_ANY,
  651. ),
  652. FILTER_PROPERTY_SEVERITY_ID => Array(
  653. '0' => META_FILTER_ANY,
  654. ),
  655. FILTER_PROPERTY_STATUS_ID => Array(
  656. '0' => META_FILTER_ANY,
  657. ),
  658. FILTER_PROPERTY_HIGHLIGHT_CHANGED => $t_default_show_changed,
  659. FILTER_PROPERTY_REPORTER_ID => Array(
  660. '0' => META_FILTER_ANY,
  661. ),
  662. FILTER_PROPERTY_HANDLER_ID => Array(
  663. '0' => META_FILTER_ANY,
  664. ),
  665. FILTER_PROPERTY_PROJECT_ID => Array(
  666. '0' => META_FILTER_CURRENT,
  667. ),
  668. FILTER_PROPERTY_RESOLUTION_ID => Array(
  669. '0' => META_FILTER_ANY,
  670. ),
  671. FILTER_PROPERTY_PRODUCT_BUILD => Array(
  672. '0' => META_FILTER_ANY,
  673. ),
  674. FILTER_PROPERTY_PRODUCT_VERSION => Array(
  675. '0' => META_FILTER_ANY,
  676. ),
  677. FILTER_PROPERTY_HIDE_STATUS_ID => Array(
  678. '0' => $t_hide_status_default,
  679. ),
  680. FILTER_PROPERTY_MONITOR_USER_ID => Array(
  681. '0' => META_FILTER_ANY,
  682. ),
  683. FILTER_PROPERTY_SORT_FIELD_NAME => 'last_updated',
  684. FILTER_PROPERTY_SORT_DIRECTION => 'DESC',
  685. FILTER_PROPERTY_ISSUES_PER_PAGE => config_get( 'default_limit_view' ),
  686. );
  687. return filter_ensure_valid_filter( $t_filter );
  688. }
  689. /**
  690. * Deserialize filter string
  691. * @param string $p_serialized_filter
  692. * @return mixed $t_filter array
  693. * @see filter_ensure_valid_filter
  694. */
  695. function filter_deserialize( $p_serialized_filter ) {
  696. if( is_blank( $p_serialized_filter ) ) {
  697. return false;
  698. }
  699. # check to see if new cookie is needed
  700. $t_setting_arr = explode( '#', $p_serialized_filter, 2 );
  701. if(( $t_setting_arr[0] == 'v1' ) || ( $t_setting_arr[0] == 'v2' ) || ( $t_setting_arr[0] == 'v3' ) || ( $t_setting_arr[0] == 'v4' ) ) {
  702. # these versions can't be salvaged, they are too old to update
  703. return false;
  704. }
  705. # We shouldn't need to do this anymore, as filters from v5 onwards should cope with changing
  706. # filter indices dynamically
  707. $t_filter_array = array();
  708. if( isset( $t_setting_arr[1] ) ) {
  709. $t_filter_array = unserialize( $t_setting_arr[1] );
  710. } else {
  711. return false;
  712. }
  713. if( $t_filter_array['_version'] != config_get( 'cookie_version' ) ) {
  714. # if the version is not new enough, update it using defaults
  715. return filter_ensure_valid_filter( $t_filter_array );
  716. }
  717. return $t_filter_array;
  718. }
  719. /**
  720. * Check if the filter cookie exists and is of the correct version.
  721. * @return bool
  722. */
  723. function filter_is_cookie_valid() {
  724. $t_view_all_cookie_id = gpc_get_cookie( config_get( 'view_all_cookie' ), '' );
  725. $t_view_all_cookie = filter_db_get_filter( $t_view_all_cookie_id );
  726. # check to see if the cookie does not exist
  727. if( is_blank( $t_view_all_cookie ) ) {
  728. return false;
  729. }
  730. # check to see if new cookie is needed
  731. $t_setting_arr = explode( '#', $t_view_all_cookie, 2 );
  732. if(( $t_setting_arr[0] == 'v1' ) || ( $t_setting_arr[0] == 'v2' ) || ( $t_setting_arr[0] == 'v3' ) || ( $t_setting_arr[0] == 'v4' ) ) {
  733. return false;
  734. }
  735. # We shouldn't need to do this anymore, as filters from v5 onwards should cope with changing
  736. # filter indices dynamically
  737. $t_filter_cookie_arr = array();
  738. if( isset( $t_setting_arr[1] ) ) {
  739. $t_filter_cookie_arr = unserialize( $t_setting_arr[1] );
  740. } else {
  741. return false;
  742. }
  743. if( $t_filter_cookie_arr['_version'] != config_get( 'cookie_version' ) ) {
  744. return false;
  745. }
  746. return true;
  747. }
  748. /**
  749. * Get the array fields specified by $p_filter_id
  750. * using the cached row if it's available
  751. * @param int $p_filter_id
  752. * @return mixed a filter row
  753. */
  754. function filter_get_row( $p_filter_id ) {
  755. return filter_cache_row( $p_filter_id );
  756. }
  757. /**
  758. * Get the value of the filter field specified by filter id and field name
  759. * @param int $p_filter_id
  760. * @param string $p_field_name
  761. * @return string
  762. */
  763. function filter_get_field( $p_filter_id, $p_field_name ) {
  764. $row = filter_get_row( $p_filter_id );
  765. if( isset( $row[$p_field_name] ) ) {
  766. return $row[$p_field_name];
  767. } else {
  768. error_parameters( $p_field_name );
  769. trigger_error( ERROR_DB_FIELD_NOT_FOUND, WARNING );
  770. return '';
  771. }
  772. }
  773. /**
  774. * Add sort parameters to the query clauses
  775. * @param array $p_filter
  776. * @param bool $p_show_sticky
  777. * @param array $p_query_clauses
  778. * @return array $p_query_clauses
  779. */
  780. function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clauses ) {
  781. $t_bug_table = db_get_table( 'mantis_bug_table' );
  782. $t_custom_field_string_table = db_get_table( 'mantis_custom_field_string_table' );
  783. # if sort is blank then default the sort and direction. This is to fix the
  784. # symptoms of #3953. Note that even if the main problem is fixed, we may
  785. # have to keep this code for a while to handle filters saved with this blank field.
  786. if( is_blank( $p_filter[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
  787. $p_filter[FILTER_PROPERTY_SORT_FIELD_NAME] = 'last_updated';
  788. $p_filter[FILTER_PROPERTY_SORT_DIRECTION] = 'DESC';
  789. }
  790. $p_query_clauses['order'] = array();
  791. $t_sort_fields = explode( ',', $p_filter[FILTER_PROPERTY_SORT_FIELD_NAME] );
  792. $t_dir_fields = explode( ',', $p_filter[FILTER_PROPERTY_SORT_DIRECTION] );
  793. $t_plugin_columns = columns_get_plugin_columns();
  794. if ( gpc_string_to_bool( $p_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) && ( NULL !== $p_show_sticky ) ) {
  795. $p_query_clauses['order'][] = "$t_bug_table.sticky DESC";
  796. }
  797. $t_count = count( $t_sort_fields );
  798. for( $i = 0;$i < $t_count;$i++ ) {
  799. $c_sort = db_prepare_string( $t_sort_fields[$i] );
  800. $c_dir = 'DESC' == $t_dir_fields[$i] ? 'DESC' : 'ASC';
  801. if( !in_array( $t_sort_fields[$i], array_slice( $t_sort_fields, $i + 1 ) ) ) {
  802. # if sorting by a custom field
  803. if( strpos( $c_sort, 'custom_' ) === 0 ) {
  804. $t_custom_field = utf8_substr( $c_sort, utf8_strlen( 'custom_' ) );
  805. $t_custom_field_id = custom_field_get_id_from_name( $t_custom_field );
  806. $c_cf_alias = str_replace( ' ', '_', $t_custom_field );
  807. $t_cf_table_alias = $t_custom_field_string_table . '_' . $t_custom_field_id;
  808. $t_cf_select = "$t_cf_table_alias.value $c_cf_alias";
  809. # check to be sure this field wasn't already added to the query.
  810. if( !in_array( $t_cf_select, $p_query_clauses['select'] ) ) {
  811. $p_query_clauses['select'][] = $t_cf_select;
  812. $p_query_clauses['join'][] = "LEFT JOIN $t_custom_field_string_table $t_cf_table_alias ON $t_bug_table.id = $t_cf_table_alias.bug_id AND $t_cf_table_alias.field_id = $t_custom_field_id";
  813. }
  814. $p_query_clauses['order'][] = "$c_cf_alias $c_dir";
  815. # if sorting by plugin columns
  816. } else if ( isset( $t_plugin_columns[ $t_sort_fields[$i] ] ) ) {
  817. $t_column_object = $t_plugin_columns[ $t_sort_fields[$i] ];
  818. if ( $t_column_object->sortable ) {
  819. $t_clauses = $t_column_object->sortquery( $c_dir );
  820. if ( is_array( $t_clauses ) ) {
  821. if ( isset( $t_clauses['join'] ) ) {
  822. $p_query_clauses['join'][] = $t_clauses['join'];
  823. }
  824. if ( isset( $t_clauses['order'] ) ) {
  825. $p_query_clauses['order'][] = $t_clauses['order'];
  826. }
  827. }
  828. }
  829. # standard column
  830. } else {
  831. if ( 'last_updated' == $c_sort ) {
  832. $c_sort = "last_updated";
  833. }
  834. $p_query_clauses['order'][] = "$t_bug_table.$c_sort $c_dir";
  835. }
  836. }
  837. }
  838. # add basic sorting if necessary
  839. if( !in_array( 'last_updated', $t_sort_fields ) ) {
  840. $p_query_clauses['order'][] = "$t_bug_table.last_updated DESC";
  841. }
  842. if( !in_array( 'date_submitted', $t_sort_fields ) ) {
  843. $p_query_clauses['order'][] = "$t_bug_table.date_submitted DESC";
  844. }
  845. return $p_query_clauses;
  846. }
  847. /**
  848. * Remove any duplicate values in certain elements of query_clauses
  849. * Do not loop over query clauses as some keys may contain valid duplicate values.
  850. * We basically want unique values for just the base query elements select, from, and join
  851. * 'where' and 'where_values' key should not have duplicates as that is handled earlier and applying
  852. * array_unique here could cause problems with the query.
  853. * @param $p_query_clauses
  854. * @return $p_query_clauses
  855. */
  856. function filter_unique_query_clauses( $p_query_clauses ) {
  857. $p_query_clauses['select'] = array_unique( $p_query_clauses['select'] );
  858. $p_query_clauses['from'] = array_unique( $p_query_clauses['from'] );
  859. $p_query_clauses['join'] = array_unique( $p_query_clauses['join'] );
  860. return $p_query_clauses;
  861. }
  862. /**
  863. * Build a query with the query clauses array, query for bug count and return the result
  864. * @param array $p_query_clauses
  865. * @return int
  866. */
  867. function filter_get_bug_count( $p_query_clauses ) {
  868. $t_bug_table = db_get_table( 'mantis_bug_table' );
  869. $p_query_clauses = filter_unique_query_clauses( $p_query_clauses );
  870. $t_select_string = "SELECT Count( DISTINCT $t_bug_table.id ) as idcnt ";
  871. $t_from_string = " FROM " . implode( ', ', $p_query_clauses['from'] );
  872. $t_join_string = (( count( $p_query_clauses['join'] ) > 0 ) ? implode( ' ', $p_query_clauses['join'] ) : '' );
  873. $t_where_string = (( count( $p_query_clauses['where'] ) > 0 ) ? 'WHERE ' . implode( ' AND ', $p_query_clauses['where'] ) : '' );
  874. $t_result = db_query_bound( "$t_select_string $t_from_string $t_join_string $t_where_string", $p_query_clauses['where_values'] );
  875. return db_result( $t_result );
  876. }
  877. /**
  878. * @todo Had to make all these parameters required because we can't use
  879. * call-time pass by reference anymore. I really preferred not having
  880. * to pass all the params in if you didn't want to, but I wanted to get
  881. * rid of the errors for now. If we can think of a better way later
  882. * (maybe return an object) that would be great.
  883. *
  884. * @param int $p_page_number the page you want to see (set to the actual page on return)
  885. * @param int $p_per_page the number of bugs to see per page (set to actual on return)
  886. * -1 indicates you want to see all bugs
  887. * null indicates you want to use the value specified in the filter
  888. * @param int $p_page_count you don't need to give a value here, the number of pages will be stored here on return
  889. * @param int $p_bug_count you don't need to give a value here, the number of bugs will be stored here on return
  890. * @param mixed $p_custom_filter Filter to use.
  891. * @param int $p_project_id project id to use in filtering.
  892. * @param int $p_user_id user id to use as current user when filtering.
  893. * @param bool $p_show_sticky get sticky issues only.
  894. */
  895. function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p_bug_count, $p_custom_filter = null, $p_project_id = null, $p_user_id = null, $p_show_sticky = null ) {
  896. log_event( LOG_FILTERING, 'START NEW FILTER QUERY' );
  897. $t_bug_table = db_get_table( 'mantis_bug_table' );
  898. $t_bug_text_table = db_get_table( 'mantis_bug_text_table' );
  899. $t_bugnote_table = db_get_table( 'mantis_bugnote_table' );
  900. $t_category_table = db_get_table( 'mantis_category_table' );
  901. $t_custom_field_string_table = db_get_table( 'mantis_custom_field_string_table' );
  902. $t_bugnote_text_table = db_get_table( 'mantis_bugnote_text_table' );
  903. $t_project_table = db_get_table( 'mantis_project_table' );
  904. $t_bug_monitor_table = db_get_table( 'mantis_bug_monitor_table' );
  905. $t_limit_reporters = config_get( 'limit_reporters' );
  906. $t_bug_relationship_table = db_get_table( 'mantis_bug_relationship_table' );
  907. $t_report_bug_threshold = config_get( 'report_bug_threshold' );
  908. $t_where_param_count = 0;
  909. $t_current_user_id = auth_get_current_user_id();
  910. if( null === $p_user_id ) {
  911. $t_user_id = $t_current_user_id;
  912. } else {
  913. $t_user_id = $p_user_id;
  914. }
  915. $c_user_id = db_prepare_int( $t_user_id );
  916. if( null === $p_project_id ) {
  917. # @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project.
  918. $t_project_id = helper_get_current_project();
  919. } else {
  920. $t_project_id = $p_project_id;
  921. }
  922. if( $p_custom_filter === null ) {
  923. # Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports
  924. # cookies set by previous version of the code.
  925. if( $t_user_id == $t_current_user_id ) {
  926. $t_filter = current_user_get_bug_filter();
  927. } else {
  928. $t_filter = user_get_bug_filter( $t_user_id, $t_project_id );
  929. }
  930. } else {
  931. $t_filter = $p_custom_filter;
  932. }
  933. $t_filter = filter_ensure_valid_filter( $t_filter );
  934. if( false === $t_filter ) {
  935. return false;
  936. # signify a need to create a cookie
  937. # @@@ error instead?
  938. }
  939. $t_view_type = $t_filter['_view_type'];
  940. $t_where_clauses = array(
  941. "$t_project_table.enabled = " . db_param(),
  942. "$t_project_table.id = $t_bug_table.project_id",
  943. );
  944. $t_where_params = array(
  945. 1,
  946. );
  947. $t_select_clauses = array(
  948. "$t_bug_table.*",
  949. );
  950. $t_join_clauses = array();
  951. $t_from_clauses = array();
  952. // normalize the project filtering into an array $t_project_ids
  953. if( 'simple' == $t_view_type ) {
  954. log_event( LOG_FILTERING, 'Simple Filter' );
  955. $t_project_ids = array(
  956. $t_project_id,
  957. );
  958. $t_include_sub_projects = true;
  959. } else {
  960. log_event( LOG_FILTERING, 'Advanced Filter' );
  961. if( !is_array( $t_filter[FILTER_PROPERTY_PROJECT_ID] ) ) {
  962. $t_project_ids = array(
  963. db_prepare_int( $t_filter[FILTER_PROPERTY_PROJECT_ID] ),
  964. );
  965. } else {
  966. $t_project_ids = array_map( 'db_prepare_int', $t_filter[FILTER_PROPERTY_PROJECT_ID] );
  967. }
  968. $t_include_sub_projects = (( count( $t_project_ids ) == 1 ) && ( ( $t_project_ids[0] == META_FILTER_CURRENT ) || ( $t_project_ids[0] == ALL_PROJECTS ) ) );
  969. }
  970. log_event( LOG_FILTERING, 'project_ids = @P' . implode( ', @P', $t_project_ids ) );
  971. log_event( LOG_FILTERING, 'include sub-projects = ' . ( $t_include_sub_projects ? '1' : '0' ) );
  972. // if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS.
  973. // replace META_FILTER_CURRENT with the actualy current project id.
  974. $t_all_projects_found = false;
  975. $t_new_project_ids = array();
  976. foreach( $t_project_ids as $t_pid ) {
  977. if( $t_pid == META_FILTER_CURRENT ) {
  978. $t_pid = $t_project_id;
  979. }
  980. if( $t_pid == ALL_PROJECTS ) {
  981. $t_all_projects_found = true;
  982. log_event( LOG_FILTERING, 'all projects selected' );
  983. break;
  984. }
  985. // filter out inaccessible projects.
  986. if( !access_has_project_level( VIEWER, $t_pid, $t_user_id ) ) {
  987. continue;
  988. }
  989. $t_new_project_ids[] = $t_pid;
  990. }
  991. $t_projects_query_required = true;
  992. if( $t_all_projects_found ) {
  993. if( user_is_administrator( $t_user_id ) ) {
  994. log_event( LOG_FILTERING, 'all projects + administrator, hence no project filter.' );
  995. $t_projects_query_required = false;
  996. } else {
  997. $t_project_ids = user_get_accessible_projects( $t_user_id );
  998. }
  999. } else {
  1000. $t_project_ids = $t_new_project_ids;
  1001. }
  1002. if( $t_projects_query_required ) {
  1003. // expand project ids to include sub-projects
  1004. if( $t_include_sub_projects ) {
  1005. $t_top_project_ids = $t_project_ids;
  1006. foreach( $t_top_project_ids as $t_pid ) {
  1007. log_event( LOG_FILTERING, 'Getting sub-projects for project id @P' . $t_pid );
  1008. $t_subproject_ids = user_get_all_accessible_subprojects( $t_user_id, $t_pid );
  1009. if (!$t_subproject_ids) continue;
  1010. $t_project_ids = array_merge( $t_project_ids, $t_subproject_ids );
  1011. }
  1012. $t_project_ids = array_unique( $t_project_ids );
  1013. }
  1014. // if no projects are accessible, then return an empty array.
  1015. if( count( $t_project_ids ) == 0 ) {
  1016. log_event( LOG_FILTERING, 'no accessible projects' );
  1017. return array();
  1018. }
  1019. log_event( LOG_FILTERING, 'project_ids after including sub-projects = @P' . implode( ', @P', $t_project_ids ) );
  1020. // this array is to be populated with project ids for which we only want to show public issues. This is due to the limited
  1021. // access of the current user.
  1022. $t_public_only_project_ids = array();
  1023. // this array is populated with project ids that the current user has full access to.
  1024. $t_private_and_public_project_ids = array();
  1025. foreach( $t_project_ids as $t_pid ) {
  1026. $t_access_required_to_view_private_bugs = config_get( 'private_bug_threshold', null, null, $t_pid );
  1027. if( access_has_project_level( $t_access_required_to_view_private_bugs, $t_pid, $t_user_id ) ) {
  1028. $t_private_and_public_project_ids[] = $t_pid;
  1029. } else {
  1030. $t_public_only_project_ids[] = $t_pid;
  1031. }
  1032. }
  1033. log_event( LOG_FILTERING, 'project_ids (with public/private access) = @P' . implode( ', @P', $t_private_and_public_project_ids ) );
  1034. log_event( LOG_FILTERING, 'project_ids (with public access) = @P' . implode( ', @P', $t_public_only_project_ids ) );
  1035. $t_count_private_and_public_project_ids = count( $t_private_and_public_project_ids );
  1036. if( $t_count_private_and_public_project_ids == 1 ) {
  1037. $t_private_and_public_query = "( $t_bug_table.project_id = " . $t_private_and_public_project_ids[0] . " )";
  1038. }
  1039. else if( $t_count_private_and_public_project_ids > 1 ) {
  1040. $t_private_and_public_query = "( $t_bug_table.project_id in (" . implode( ', ', $t_private_and_public_project_ids ) . ") )";
  1041. } else {
  1042. $t_private_and_public_query = null;
  1043. }
  1044. $t_count_public_only_project_ids = count( $t_public_only_project_ids );
  1045. $t_public_view_state_check = "( ( $t_bug_table.view_state = " . VS_PUBLIC . " ) OR ( $t_bug_table.reporter_id = $t_user_id ) )";
  1046. if( $t_count_public_only_project_ids == 1 ) {
  1047. $t_public_only_query = "( ( $t_bug_table.project_id = " . $t_public_only_project_ids[0] . " ) AND $t_public_view_state_check )";
  1048. }
  1049. else if( $t_count_public_only_project_ids > 1 ) {
  1050. $t_public_only_query = "( ( $t_bug_table.project_id in (" . implode( ', ', $t_public_only_project_ids ) . ") ) AND $t_public_view_state_check )";
  1051. } else {
  1052. $t_public_only_query = null;
  1053. }
  1054. // both queries can't be null, so we either have one of them or both.
  1055. if( $t_private_and_public_query === null ) {
  1056. $t_project_query = $t_public_only_query;
  1057. } else if( $t_public_only_query === null ) {
  1058. $t_project_query = $t_private_and_public_query;
  1059. } else {
  1060. $t_project_query = "( $t_public_only_query OR $t_private_and_public_query )";
  1061. }
  1062. log_event( LOG_FILTERING, 'project query = ' . $t_project_query );
  1063. array_push( $t_where_clauses, $t_project_query );
  1064. }
  1065. # view state
  1066. $t_view_state = db_prepare_int( $t_filter[FILTER_PROPERTY_VIEW_STATE_ID] );
  1067. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_VIEW_STATE_ID] ) ) {
  1068. $t_view_state_query = "($t_bug_table.view_state=" . db_param() . ')';
  1069. log_event( LOG_FILTERING, 'view_state query = ' . $t_view_state_query );
  1070. $t_where_params[] = $t_view_state;
  1071. array_push( $t_where_clauses, $t_view_state_query );
  1072. } else {
  1073. log_event( LOG_FILTERING, 'no view_state query' );
  1074. }
  1075. # reporter
  1076. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_REPORTER_ID] ) ) {
  1077. $t_clauses = array();
  1078. foreach( $t_filter[FILTER_PROPERTY_REPORTER_ID] as $t_filter_member ) {
  1079. if( filter_field_is_none( $t_filter_member ) ) {
  1080. array_push( $t_clauses, "0" );
  1081. } else {
  1082. $c_reporter_id = db_prepare_int( $t_filter_member );
  1083. if( filter_field_is_myself( $c_reporter_id ) ) {
  1084. array_push( $t_clauses, $c_user_id );
  1085. } else {
  1086. array_push( $t_clauses, $c_reporter_id );
  1087. }
  1088. }
  1089. }
  1090. if( 1 < count( $t_clauses ) ) {
  1091. $t_reporter_query = "( $t_bug_table.reporter_id in (" . implode( ', ', $t_clauses ) . ") )";
  1092. } else {
  1093. $t_reporter_query = "( $t_bug_table.reporter_id=$t_clauses[0] )";
  1094. }
  1095. log_event( LOG_FILTERING, 'reporter query = ' . $t_reporter_query );
  1096. array_push( $t_where_clauses, $t_reporter_query );
  1097. } else {
  1098. log_event( LOG_FILTERING, 'no reporter query' );
  1099. }
  1100. # limit reporter
  1101. # @@@ thraxisp - access_has_project_level checks greater than or equal to,
  1102. # this assumed that there aren't any holes above REPORTER where the limit would apply
  1103. #
  1104. if(( ON === $t_limit_reporters ) && ( !access_has_project_level( REPORTER + 1, $t_project_id, $t_user_id ) ) ) {
  1105. $c_reporter_id = $c_user_id;
  1106. $t_where_params[] = $c_reporter_id;
  1107. array_push( $t_where_clauses, "($t_bug_table.reporter_id=" . db_param() . ')' );
  1108. }
  1109. # handler
  1110. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_HANDLER_ID] ) ) {
  1111. $t_clauses = array();
  1112. foreach( $t_filter[FILTER_PROPERTY_HANDLER_ID] as $t_filter_member ) {
  1113. if( filter_field_is_none( $t_filter_member ) ) {
  1114. array_push( $t_clauses, 0 );
  1115. } else {
  1116. $c_handler_id = db_prepare_int( $t_filter_member );
  1117. if( filter_field_is_myself( $c_handler_id ) ) {
  1118. array_push( $t_clauses, $c_user_id );
  1119. } else {
  1120. array_push( $t_clauses, $c_handler_id );
  1121. }
  1122. }
  1123. }
  1124. if( 1 < count( $t_clauses ) ) {
  1125. $t_handler_query = "( $t_bug_table.handler_id in (" . implode( ', ', $t_clauses ) . ") )";
  1126. } else {
  1127. $t_handler_query = "( $t_bug_table.handler_id=$t_clauses[0] )";
  1128. }
  1129. log_event( LOG_FILTERING, 'handler query = ' . $t_handler_query );
  1130. array_push( $t_where_clauses, $t_handler_query );
  1131. } else {
  1132. log_event( LOG_FILTERING, 'no handler query' );
  1133. }
  1134. # category
  1135. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_CATEGORY] ) ) {
  1136. $t_clauses = array();
  1137. foreach( $t_filter[FILTER_PROPERTY_CATEGORY] as $t_filter_member ) {
  1138. if( !filter_field_is_none( $t_filter_member ) ) {
  1139. array_push( $t_clauses, $t_filter_member );
  1140. }
  1141. }
  1142. if( 1 < count( $t_clauses ) ) {
  1143. $t_where_tmp = array();
  1144. foreach( $t_clauses as $t_clause ) {
  1145. $t_where_tmp[] = db_param();
  1146. $t_where_params[] = $t_clause;
  1147. }
  1148. array_push( $t_where_clauses, "( $t_bug_table.category_id in ( SELECT id FROM $t_category_table WHERE name in (" . implode( ', ', $t_where_tmp ) . ") ) )" );
  1149. } else {
  1150. $t_where_params[] = $t_clauses[0];
  1151. array_push( $t_where_clauses, "( $t_bug_table.category_id in ( SELECT id FROM $t_category_table WHERE name=" . db_param() . ") )" );
  1152. }
  1153. }
  1154. # severity
  1155. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_SEVERITY_ID] ) ) {
  1156. $t_clauses = array();
  1157. foreach( $t_filter[FILTER_PROPERTY_SEVERITY_ID] as $t_filter_member ) {
  1158. $c_show_severity = db_prepare_int( $t_filter_member );
  1159. array_push( $t_clauses, $c_show_severity );
  1160. }
  1161. if( 1 < count( $t_clauses ) ) {
  1162. $t_where_tmp = array();
  1163. foreach( $t_clauses as $t_clause ) {
  1164. $t_where_tmp[] = db_param();
  1165. $t_where_params[] = $t_clause;
  1166. }
  1167. array_push( $t_where_clauses, "( $t_bug_table.severity in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1168. } else {
  1169. $t_where_params[] = $t_clauses[0];
  1170. array_push( $t_where_clauses, "( $t_bug_table.severity=" . db_param() . " )" );
  1171. }
  1172. }
  1173. # show / hide status
  1174. # take a list of all available statuses then remove the ones that we want hidden, then make sure
  1175. # the ones we want shown are still available
  1176. $t_desired_statuses = array();
  1177. $t_available_statuses = MantisEnum::getValues( config_get( 'status_enum_string' ) );
  1178. if( 'simple' == $t_filter['_view_type'] ) {
  1179. # simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide
  1180. $t_any_found = false;
  1181. $t_this_status = $t_filter[FILTER_PROPERTY_STATUS_ID][0];
  1182. $t_this_hide_status = $t_filter[FILTER_PROPERTY_HIDE_STATUS_ID][0];
  1183. if( filter_field_is_any( $t_this_status ) ) {
  1184. foreach( $t_available_statuses as $t_this_available_status ) {
  1185. if( $t_this_hide_status > $t_this_available_status ) {
  1186. $t_desired_statuses[] = $t_this_available_status;
  1187. }
  1188. }
  1189. } else {
  1190. $t_desired_statuses[] = $t_this_status;
  1191. }
  1192. } else {
  1193. # advanced filtering: ignore the hide
  1194. if( filter_field_is_any( $t_filter[FILTER_PROPERTY_STATUS_ID] ) ) {
  1195. $t_desired_statuses = array();
  1196. } else {
  1197. foreach( $t_filter[FILTER_PROPERTY_STATUS_ID] as $t_this_status ) {
  1198. $t_desired_statuses[] = $t_this_status;
  1199. }
  1200. }
  1201. }
  1202. if( count( $t_desired_statuses ) > 0 ) {
  1203. $t_clauses = array();
  1204. foreach( $t_desired_statuses as $t_filter_member ) {
  1205. $c_show_status = db_prepare_int( $t_filter_member );
  1206. array_push( $t_clauses, $c_show_status );
  1207. }
  1208. if( 1 < count( $t_clauses ) ) {
  1209. $t_where_tmp = array();
  1210. foreach( $t_clauses as $t_clause ) {
  1211. $t_where_tmp[] = db_param();
  1212. $t_where_params[] = $t_clause;
  1213. }
  1214. array_push( $t_where_clauses, "( $t_bug_table.status in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1215. } else {
  1216. $t_where_params[] = $t_clauses[0];
  1217. array_push( $t_where_clauses, "( $t_bug_table.status=" . db_param() . " )" );
  1218. }
  1219. }
  1220. # resolution
  1221. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_RESOLUTION_ID] ) ) {
  1222. $t_clauses = array();
  1223. foreach( $t_filter[FILTER_PROPERTY_RESOLUTION_ID] as $t_filter_member ) {
  1224. $c_show_resolution = db_prepare_int( $t_filter_member );
  1225. array_push( $t_clauses, $c_show_resolution );
  1226. }
  1227. if( 1 < count( $t_clauses ) ) {
  1228. $t_where_tmp = array();
  1229. foreach( $t_clauses as $t_clause ) {
  1230. $t_where_tmp[] = db_param();
  1231. $t_where_params[] = $t_clause;
  1232. }
  1233. array_push( $t_where_clauses, "( $t_bug_table.resolution in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1234. } else {
  1235. $t_where_params[] = $t_clauses[0];
  1236. array_push( $t_where_clauses, "( $t_bug_table.resolution=" . db_param() . " )" );
  1237. }
  1238. }
  1239. # priority
  1240. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_PRIORITY_ID] ) ) {
  1241. $t_clauses = array();
  1242. foreach( $t_filter[FILTER_PROPERTY_PRIORITY_ID] as $t_filter_member ) {
  1243. $c_show_priority = db_prepare_int( $t_filter_member );
  1244. array_push( $t_clauses, $c_show_priority );
  1245. }
  1246. if( 1 < count( $t_clauses ) ) {
  1247. $t_where_tmp = array();
  1248. foreach( $t_clauses as $t_clause ) {
  1249. $t_where_tmp[] = db_param();
  1250. $t_where_params[] = $t_clause;
  1251. }
  1252. array_push( $t_where_clauses, "( $t_bug_table.priority in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1253. } else {
  1254. $t_where_params[] = $t_clauses[0];
  1255. array_push( $t_where_clauses, "( $t_bug_table.priority=" . db_param() . " )" );
  1256. }
  1257. }
  1258. # product build
  1259. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_PRODUCT_BUILD] ) ) {
  1260. $t_clauses = array();
  1261. foreach( $t_filter[FILTER_PROPERTY_PRODUCT_BUILD] as $t_filter_member ) {
  1262. $t_filter_member = stripslashes( $t_filter_member );
  1263. if( filter_field_is_none( $t_filter_member ) ) {
  1264. array_push( $t_clauses, '' );
  1265. } else {
  1266. $c_show_build = db_prepare_string( $t_filter_member );
  1267. array_push( $t_clauses, $c_show_build );
  1268. }
  1269. }
  1270. if( 1 < count( $t_clauses ) ) {
  1271. $t_where_tmp = array();
  1272. foreach( $t_clauses as $t_clause ) {
  1273. $t_where_tmp[] = db_param();
  1274. $t_where_params[] = $t_clause;
  1275. }
  1276. array_push( $t_where_clauses, "( $t_bug_table.build in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1277. } else {
  1278. $t_where_params[] = $t_clauses[0];
  1279. array_push( $t_where_clauses, "( $t_bug_table.build=" . db_param() . " )" );
  1280. }
  1281. }
  1282. # product version
  1283. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION] ) ) {
  1284. $t_clauses = array();
  1285. foreach( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION] as $t_filter_member ) {
  1286. $t_filter_member = stripslashes( $t_filter_member );
  1287. if( filter_field_is_none( $t_filter_member ) ) {
  1288. array_push( $t_clauses, '' );
  1289. } else {
  1290. $c_show_version = db_prepare_string( $t_filter_member );
  1291. array_push( $t_clauses, $c_show_version );
  1292. }
  1293. }
  1294. if( 1 < count( $t_clauses ) ) {
  1295. $t_where_tmp = array();
  1296. foreach( $t_clauses as $t_clause ) {
  1297. $t_where_tmp[] = db_param();
  1298. $t_where_params[] = $t_clause;
  1299. }
  1300. array_push( $t_where_clauses, "( $t_bug_table.version in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1301. } else {
  1302. $t_where_params[] = $t_clauses[0];
  1303. array_push( $t_where_clauses, "( $t_bug_table.version=" . db_param() . " )" );
  1304. }
  1305. }
  1306. # profile
  1307. if( !filter_field_is_any( $t_filter['show_profile'] ) ) {
  1308. $t_clauses = array();
  1309. foreach( $t_filter['show_profile'] as $t_filter_member ) {
  1310. $t_filter_member = stripslashes( $t_filter_member );
  1311. if( filter_field_is_none( $t_filter_member ) ) {
  1312. array_push( $t_clauses, "0" );
  1313. } else {
  1314. $c_show_profile = db_prepare_int( $t_filter_member );
  1315. array_push( $t_clauses, "$c_show_profile" );
  1316. }
  1317. }
  1318. if( 1 < count( $t_clauses ) ) {
  1319. $t_where_tmp = array();
  1320. foreach( $t_clauses as $t_clause ) {
  1321. $t_where_tmp[] = db_param();
  1322. $t_where_params[] = $t_clause;
  1323. }
  1324. array_push( $t_where_clauses, "( $t_bug_table.profile_id in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1325. } else {
  1326. $t_where_params[] = $t_clauses[0];
  1327. array_push( $t_where_clauses, "( $t_bug_table.profile_id=" . db_param() . " )" );
  1328. }
  1329. }
  1330. # platform
  1331. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_PLATFORM] ) ) {
  1332. $t_clauses = array();
  1333. foreach( $t_filter[FILTER_PROPERTY_PLATFORM] as $t_filter_member ) {
  1334. $t_filter_member = stripslashes( $t_filter_member );
  1335. if( filter_field_is_none( $t_filter_member ) ) {
  1336. array_push( $t_clauses, '' );
  1337. } else {
  1338. $c_platform = db_prepare_string( $t_filter_member );
  1339. array_push( $t_clauses, $c_platform );
  1340. }
  1341. }
  1342. if( 1 < count( $t_clauses ) ) {
  1343. $t_where_tmp = array();
  1344. foreach( $t_clauses as $t_clause ) {
  1345. $t_where_tmp[] = db_param();
  1346. $t_where_params[] = $t_clause;
  1347. }
  1348. array_push( $t_where_clauses, "( $t_bug_table.platform in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1349. } else {
  1350. $t_where_params[] = $t_clauses[0];
  1351. array_push( $t_where_clauses, "( $t_bug_table.platform = " . db_param() . " )" );
  1352. }
  1353. }
  1354. # os
  1355. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_OS] ) ) {
  1356. $t_clauses = array();
  1357. foreach( $t_filter[FILTER_PROPERTY_OS] as $t_filter_member ) {
  1358. $t_filter_member = stripslashes( $t_filter_member );
  1359. if( filter_field_is_none( $t_filter_member ) ) {
  1360. array_push( $t_clauses, '' );
  1361. } else {
  1362. $c_os = db_prepare_string( $t_filter_member );
  1363. array_push( $t_clauses, $c_os );
  1364. }
  1365. }
  1366. if( 1 < count( $t_clauses ) ) {
  1367. $t_where_tmp = array();
  1368. foreach( $t_clauses as $t_clause ) {
  1369. $t_where_tmp[] = db_param();
  1370. $t_where_params[] = $t_clause;
  1371. }
  1372. array_push( $t_where_clauses, "( $t_bug_table.os in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1373. } else {
  1374. $t_where_params[] = $t_clauses[0];
  1375. array_push( $t_where_clauses, "( $t_bug_table.os = " . db_param() . " )" );
  1376. }
  1377. }
  1378. # os_build
  1379. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_OS_BUILD] ) ) {
  1380. $t_clauses = array();
  1381. foreach( $t_filter[FILTER_PROPERTY_OS_BUILD] as $t_filter_member ) {
  1382. $t_filter_member = stripslashes( $t_filter_member );
  1383. if( filter_field_is_none( $t_filter_member ) ) {
  1384. array_push( $t_clauses, '' );
  1385. } else {
  1386. $c_os_build = db_prepare_string( $t_filter_member );
  1387. array_push( $t_clauses, $c_os_build );
  1388. }
  1389. }
  1390. if( 1 < count( $t_clauses ) ) {
  1391. $t_where_tmp = array();
  1392. foreach( $t_clauses as $t_clause ) {
  1393. $t_where_tmp[] = db_param();
  1394. $t_where_params[] = $t_clause;
  1395. }
  1396. array_push( $t_where_clauses, "( $t_bug_table.os_build in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1397. } else {
  1398. $t_where_params[] = $t_clauses[0];
  1399. array_push( $t_where_clauses, "( $t_bug_table.os_build = " . db_param() . " )" );
  1400. }
  1401. }
  1402. # date filter
  1403. if(( 'on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) && is_numeric( $t_filter[FILTER_PROPERTY_START_MONTH] ) && is_numeric( $t_filter[FILTER_PROPERTY_START_DAY] ) && is_numeric( $t_filter[FILTER_PROPERTY_START_YEAR] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_MONTH] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_DAY] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_YEAR] ) ) {
  1404. $t_start_string = $t_filter[FILTER_PROPERTY_START_YEAR] . "-" . $t_filter[FILTER_PROPERTY_START_MONTH] . "-" . $t_filter[FILTER_PROPERTY_START_DAY] . " 00:00:00";
  1405. $t_end_string = $t_filter[FILTER_PROPERTY_END_YEAR] . "-" . $t_filter[FILTER_PROPERTY_END_MONTH] . "-" . $t_filter[FILTER_PROPERTY_END_DAY] . " 23:59:59";
  1406. $t_where_params[] = strtotime( $t_start_string );
  1407. $t_where_params[] = strtotime( $t_end_string );
  1408. array_push( $t_where_clauses, "($t_bug_table.date_submitted BETWEEN " . db_param() . " AND " . db_param() . " )" );
  1409. }
  1410. # fixed in version
  1411. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION] ) ) {
  1412. $t_clauses = array();
  1413. foreach( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION] as $t_filter_member ) {
  1414. $t_filter_member = stripslashes( $t_filter_member );
  1415. if( filter_field_is_none( $t_filter_member ) ) {
  1416. array_push( $t_clauses, '' );
  1417. } else {
  1418. $c_fixed_in_version = db_prepare_string( $t_filter_member );
  1419. array_push( $t_clauses, $c_fixed_in_version );
  1420. }
  1421. }
  1422. if( 1 < count( $t_clauses ) ) {
  1423. $t_where_tmp = array();
  1424. foreach( $t_clauses as $t_clause ) {
  1425. $t_where_tmp[] = db_param();
  1426. $t_where_params[] = $t_clause;
  1427. }
  1428. array_push( $t_where_clauses, "( $t_bug_table.fixed_in_version in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1429. } else {
  1430. $t_where_params[] = $t_clauses[0];
  1431. array_push( $t_where_clauses, "( $t_bug_table.fixed_in_version=" . db_param() . " )" );
  1432. }
  1433. }
  1434. # target version
  1435. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_TARGET_VERSION] ) ) {
  1436. $t_clauses = array();
  1437. foreach( $t_filter[FILTER_PROPERTY_TARGET_VERSION] as $t_filter_member ) {
  1438. $t_filter_member = stripslashes( $t_filter_member );
  1439. if( filter_field_is_none( $t_filter_member ) ) {
  1440. array_push( $t_clauses, '' );
  1441. } else {
  1442. $c_target_version = db_prepare_string( $t_filter_member );
  1443. array_push( $t_clauses, $c_target_version );
  1444. }
  1445. }
  1446. # echo var_dump( $t_clauses ); exit;
  1447. if( 1 < count( $t_clauses ) ) {
  1448. $t_where_tmp = array();
  1449. foreach( $t_clauses as $t_clause ) {
  1450. $t_where_tmp[] = db_param();
  1451. $t_where_params[] = $t_clause;
  1452. }
  1453. array_push( $t_where_clauses, "( $t_bug_table.target_version in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1454. } else {
  1455. $t_where_params[] = $t_clauses[0];
  1456. array_push( $t_where_clauses, "( $t_bug_table.target_version=" . db_param() . " )" );
  1457. }
  1458. }
  1459. # users monitoring a bug
  1460. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_MONITOR_USER_ID] ) ) {
  1461. $t_clauses = array();
  1462. $t_table_name = 'user_monitor';
  1463. array_push( $t_join_clauses, "LEFT JOIN $t_bug_monitor_table $t_table_name ON $t_table_name.bug_id = $t_bug_table.id" );
  1464. foreach( $t_filter[FILTER_PROPERTY_MONITOR_USER_ID] as $t_filter_member ) {
  1465. $c_user_monitor = db_prepare_int( $t_filter_member );
  1466. if( filter_field_is_myself( $c_user_monitor ) ) {
  1467. array_push( $t_clauses, $c_user_id );
  1468. } else {
  1469. array_push( $t_clauses, $c_user_monitor );
  1470. }
  1471. }
  1472. if( 1 < count( $t_clauses ) ) {
  1473. $t_where_tmp = array();
  1474. foreach( $t_clauses as $t_clause ) {
  1475. $t_where_tmp[] = db_param();
  1476. $t_where_params[] = $t_clause;
  1477. }
  1478. array_push( $t_where_clauses, "( $t_table_name.user_id in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1479. } else {
  1480. $t_where_params[] = $t_clauses[0];
  1481. array_push( $t_where_clauses, "( $t_table_name.user_id=" . db_param() . " )" );
  1482. }
  1483. }
  1484. # bug relationship
  1485. $t_any_found = false;
  1486. $c_rel_type = $t_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE];
  1487. $c_rel_bug = $t_filter[FILTER_PROPERTY_RELATIONSHIP_BUG];
  1488. if( -1 == $c_rel_type || 0 == $c_rel_bug ) {
  1489. $t_any_found = true;
  1490. }
  1491. if( !$t_any_found ) {
  1492. # use the complementary type
  1493. $t_comp_type = relationship_get_complementary_type( $c_rel_type );
  1494. $t_clauses = array();
  1495. $t_table_name = 'relationship';
  1496. array_push( $t_join_clauses, "LEFT JOIN $t_bug_relationship_table $t_table_name ON $t_table_name.destination_bug_id = $t_bug_table.id" );
  1497. array_push( $t_join_clauses, "LEFT JOIN $t_bug_relationship_table ${t_table_name}2 ON ${t_table_name}2.source_bug_id = $t_bug_table.id" );
  1498. // get reverse relationships
  1499. $t_where_params[] = $t_comp_type;
  1500. $t_where_params[] = $c_rel_bug;
  1501. $t_where_params[] = $c_rel_type;
  1502. $t_where_params[] = $c_rel_bug;
  1503. array_push( $t_clauses, "($t_table_name.relationship_type=" . db_param() . " AND $t_table_name.source_bug_id=" . db_param() . ')' );
  1504. array_push( $t_clauses, "($t_table_name" . "2.relationship_type=" . db_param() . " AND $t_table_name" . "2.destination_bug_id=" . db_param() . ')' );
  1505. array_push( $t_where_clauses, '(' . implode( ' OR ', $t_clauses ) . ')' );
  1506. }
  1507. # tags
  1508. $c_tag_string = trim( $t_filter[FILTER_PROPERTY_TAG_STRING] );
  1509. $c_tag_select = trim( $t_filter[FILTER_PROPERTY_TAG_SELECT] );
  1510. if( is_blank( $c_tag_string ) && !is_blank( $c_tag_select ) && $c_tag_select != 0 ) {
  1511. $t_tag = tag_get( $c_tag_select );
  1512. $c_tag_string = $t_tag['name'];
  1513. }
  1514. if( !is_blank( $c_tag_string ) ) {
  1515. $t_tags = tag_parse_filters( $c_tag_string );
  1516. if( count( $t_tags ) ) {
  1517. $t_tags_all = array();
  1518. $t_tags_any = array();
  1519. $t_tags_none = array();
  1520. foreach( $t_tags as $t_tag_row ) {
  1521. switch( $t_tag_row['filter'] ) {
  1522. case 1:
  1523. $t_tags_all[] = $t_tag_row;
  1524. break;
  1525. case 0:
  1526. $t_tags_any[] = $t_tag_row;
  1527. break;
  1528. case -1:
  1529. $t_tags_none[] = $t_tag_row;
  1530. break;
  1531. }
  1532. }
  1533. if( 0 < $t_filter[FILTER_PROPERTY_TAG_SELECT] && tag_exists( $t_filter[FILTER_PROPERTY_TAG_SELECT] ) ) {
  1534. $t_tags_any[] = tag_get( $t_filter[FILTER_PROPERTY_TAG_SELECT] );
  1535. }
  1536. $t_bug_tag_table = db_get_table( 'mantis_bug_tag_table' );
  1537. if( count( $t_tags_all ) ) {
  1538. $t_clauses = array();
  1539. foreach( $t_tags_all as $t_tag_row ) {
  1540. array_push( $t_clauses, "$t_bug_table.id IN ( SELECT bug_id FROM $t_bug_tag_table WHERE $t_bug_tag_table.tag_id = $t_tag_row[id] )" );
  1541. }
  1542. array_push( $t_where_clauses, '(' . implode( ' AND ', $t_clauses ) . ')' );
  1543. }
  1544. if( count( $t_tags_any ) ) {
  1545. $t_clauses = array();
  1546. foreach( $t_tags_any as $t_tag_row ) {
  1547. array_push( $t_clauses, "$t_bug_tag_table.tag_id = $t_tag_row[id]" );
  1548. }
  1549. array_push( $t_where_clauses, "$t_bug_table.id IN ( SELECT bug_id FROM $t_bug_tag_table WHERE ( " . implode( ' OR ', $t_clauses ) . ') )' );
  1550. }
  1551. if( count( $t_tags_none ) ) {
  1552. $t_clauses = array();
  1553. foreach( $t_tags_none as $t_tag_row ) {
  1554. array_push( $t_clauses, "$t_bug_tag_table.tag_id = $t_tag_row[id]" );
  1555. }
  1556. array_push( $t_where_clauses, "$t_bug_table.id NOT IN ( SELECT bug_id FROM $t_bug_tag_table WHERE ( " . implode( ' OR ', $t_clauses ) . ') )' );
  1557. }
  1558. }
  1559. }
  1560. # note user id
  1561. if( !filter_field_is_any( $t_filter[FILTER_PROPERTY_NOTE_USER_ID] ) ) {
  1562. $t_bugnote_table_alias = 'mbnt';
  1563. $t_clauses = array();
  1564. array_push( $t_from_clauses, "$t_bugnote_table $t_bugnote_table_alias" );
  1565. array_push( $t_where_clauses, "( $t_bug_table.id = $t_bugnote_table_alias.bug_id )" );
  1566. foreach( $t_filter[FILTER_PROPERTY_NOTE_USER_ID] as $t_filter_member ) {
  1567. $c_note_user_id = db_prepare_int( $t_filter_member );
  1568. if( filter_field_is_myself( $c_note_user_id ) ) {
  1569. array_push( $t_clauses, $c_user_id );
  1570. } else {
  1571. array_push( $t_clauses, $c_note_user_id );
  1572. }
  1573. }
  1574. if( 1 < count( $t_clauses ) ) {
  1575. $t_where_tmp = array();
  1576. foreach( $t_clauses as $t_clause ) {
  1577. $t_where_tmp[] = db_param();
  1578. $t_where_params[] = $t_clause;
  1579. }
  1580. array_push( $t_where_clauses, "( $t_bugnote_table_alias.reporter_id in (" . implode( ', ', $t_where_tmp ) . ") )" );
  1581. } else {
  1582. $t_where_params[] = $t_clauses[0];
  1583. array_push( $t_where_clauses, "( $t_bugnote_table_alias.reporter_id=" . db_param() . " )" );
  1584. }
  1585. }
  1586. # plugin filters
  1587. $t_plugin_filters = filter_get_plugin_filters();
  1588. foreach( $t_plugin_filters as $t_field_name => $t_filter_object ) {
  1589. if ( !filter_field_is_any( $t_filter[ $t_field_name ] ) || $t_filter_object->type == FILTER_TYPE_BOOLEAN ) {
  1590. $t_filter_query = $t_filter_object->query( $t_filter[ $t_field_name ] );
  1591. if ( is_array( $t_filter_query ) ) {
  1592. if ( isset( $t_filter_query['join'] ) ) {
  1593. array_push( $t_join_clauses, $t_filter_query['join'] );
  1594. }
  1595. if ( isset( $t_filter_query['where'] ) ) {
  1596. array_push( $t_where_clauses, $t_filter_query['where'] );
  1597. }
  1598. if ( isset( $t_filter_query['params'] ) && is_array( $t_filter_query['params'] ) ) {
  1599. $t_where_params = array_merge( $t_where_params, $t_filter_query['params'] );
  1600. }
  1601. }
  1602. }
  1603. }
  1604. # custom field filters
  1605. if( ON == config_get( 'filter_by_custom_fields' ) ) {
  1606. # custom field filtering
  1607. # @@@ At the moment this gets the linked fields relating to the current project
  1608. # It should get the ones relating to the project in the filter or all projects
  1609. # if multiple projects.
  1610. $t_custom_fields = custom_field_get_linked_ids( $t_project_id );
  1611. foreach( $t_custom_fields as $t_cfid ) {
  1612. $t_field_info = custom_field_cache_row( $t_cfid, true );
  1613. if( !$t_field_info['filter_by'] ) {
  1614. continue;
  1615. # skip this custom field it shouldn't be filterable
  1616. }
  1617. $t_custom_where_clause = '';
  1618. # Ignore all custom filters that are not set, or that are set to '' or "any"
  1619. if( !filter_field_is_any( $t_filter['custom_fields'][$t_cfid] ) ) {
  1620. $t_def = custom_field_get_definition( $t_cfid );
  1621. $t_table_name = $t_custom_field_string_table . '_' . $t_cfid;
  1622. # We need to filter each joined table or the result query will explode in dimensions
  1623. # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields
  1624. # and only after this process ends (if it is able to) the result query will be filtered
  1625. # by the WHERE clause and by the DISTINCT clause
  1626. $t_cf_join_clause = "LEFT JOIN $t_custom_field_string_table $t_table_name ON $t_bug_table.id = $t_table_name.bug_id AND $t_table_name.field_id = $t_cfid";
  1627. if( $t_def['type'] == CUSTOM_FIELD_TYPE_DATE ) {
  1628. switch( $t_filter['custom_fields'][$t_cfid][0] ) {
  1629. case CUSTOM_FIELD_DATE_ANY:
  1630. break;
  1631. case CUSTOM_FIELD_DATE_NONE:
  1632. array_push( $t_join_clauses, $t_cf_join_clause );
  1633. $t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)';
  1634. break;
  1635. case CUSTOM_FIELD_DATE_BEFORE:
  1636. array_push( $t_join_clauses, $t_cf_join_clause );
  1637. $t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . ( $t_filter['custom_fields'][$t_cfid][2] ) . ')';
  1638. break;
  1639. case CUSTOM_FIELD_DATE_AFTER:
  1640. array_push( $t_join_clauses, $t_cf_join_clause );
  1641. $t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ( $t_filter['custom_fields'][$t_cfid][1] + 1 );
  1642. break;
  1643. default:
  1644. array_push( $t_join_clauses, $t_cf_join_clause );
  1645. $t_custom_where_clause = '( (' . $t_table_name . '.value+0) BETWEEN ' . $t_filter['custom_fields'][$t_cfid][1] . ' AND ' . $t_filter['custom_fields'][$t_cfid][2];
  1646. break;
  1647. }
  1648. } else {
  1649. array_push( $t_join_clauses, $t_cf_join_clause );
  1650. $t_filter_array = array();
  1651. foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) {
  1652. $t_filter_member = stripslashes( $t_filter_member );
  1653. if( filter_field_is_none( $t_filter_member ) ) {
  1654. # coerce filter value if selecting META_FILTER_NONE so it will match empty fields
  1655. $t_filter_member = '';
  1656. # but also add those _not_ present in the custom field string table
  1657. array_push( $t_filter_array, "$t_bug_table.id NOT IN (SELECT bug_id FROM $t_custom_field_string_table WHERE field_id=$t_cfid)" );
  1658. }
  1659. switch( $t_def['type'] ) {
  1660. case CUSTOM_FIELD_TYPE_CHECKBOX:
  1661. case CUSTOM_FIELD_TYPE_MULTILIST:
  1662. if( $t_filter_member != '' ) {
  1663. $t_filter_member = '%|' . $t_filter_member . '|%';
  1664. }
  1665. $t_where_params[] = $t_filter_member;
  1666. array_push( $t_filter_array, db_helper_like( "$t_table_name.value" ) );
  1667. break;
  1668. default:
  1669. $t_where_params[] = $t_filter_member;
  1670. array_push( $t_filter_array, "$t_table_name.value = " . db_param() );
  1671. }
  1672. }
  1673. $t_custom_where_clause .= '(' . implode( ' OR ', $t_filter_array );
  1674. }
  1675. if( !is_blank( $t_custom_where_clause ) ) {
  1676. array_push( $t_where_clauses, $t_custom_where_clause . ')' );
  1677. }
  1678. }
  1679. }
  1680. }
  1681. # Text search
  1682. if( !is_blank( $t_filter[FILTER_PROPERTY_FREE_TEXT] ) ) {
  1683. # break up search terms by spacing or quoting
  1684. preg_match_all( "/-?([^'\"\s]+|\"[^\"]+\"|'[^']+')/", $t_filter[FILTER_PROPERTY_FREE_TEXT], $t_matches, PREG_SET_ORDER );
  1685. # organize terms without quoting, paying attention to negation
  1686. $t_search_terms = array();
  1687. foreach( $t_matches as $t_match ) {
  1688. $t_search_terms[ trim( $t_match[1], "\'\"" ) ] = ( $t_match[0][0] == '-' );
  1689. }
  1690. # build a big where-clause and param list for all search terms, including negations
  1691. $t_first = true;
  1692. $t_textsearch_where_clause = "( ";
  1693. foreach( $t_search_terms as $t_search_term => $t_negate ) {
  1694. if ( !$t_first ) {
  1695. $t_textsearch_where_clause .= ' AND ';
  1696. }
  1697. if ( $t_negate ) {
  1698. $t_textsearch_where_clause .= 'NOT ';
  1699. }
  1700. $c_search = '%' . $t_search_term . '%';
  1701. $t_textsearch_where_clause .= '( ' . db_helper_like( 'summary' ) .
  1702. ' OR ' . db_helper_like( "$t_bug_text_table.description" ) .
  1703. ' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce" ) .
  1704. ' OR ' . db_helper_like( "$t_bug_text_table.additional_information" ) .
  1705. ' OR ' . db_helper_like( "$t_bugnote_text_table.note" );
  1706. $t_where_params[] = $c_search;
  1707. $t_where_params[] = $c_search;
  1708. $t_where_params[] = $c_search;
  1709. $t_where_params[] = $c_search;
  1710. $t_where_params[] = $c_search;
  1711. if( is_numeric( $t_search_term ) ) {
  1712. $c_search_int = (int) $t_search_term;
  1713. $t_textsearch_where_clause .= " OR $t_bug_table.id = " . db_param();
  1714. $t_textsearch_where_clause .= " OR $t_bugnote_table.id = " . db_param();
  1715. $t_where_params[] = $c_search_int;
  1716. $t_where_params[] = $c_search_int;
  1717. }
  1718. $t_textsearch_where_clause .= ' )';
  1719. $t_first = false;
  1720. }
  1721. $t_textsearch_where_clause .= ' )';
  1722. # add text query elements to arrays
  1723. if ( !$t_first ) {
  1724. $t_from_clauses[] = "$t_bug_text_table";
  1725. $t_where_clauses[] = "$t_bug_table.bug_text_id = $t_bug_text_table.id";
  1726. $t_where_clauses[] = $t_textsearch_where_clause;
  1727. $t_join_clauses[] = " LEFT JOIN $t_bugnote_table ON $t_bug_table.id = $t_bugnote_table.bug_id";
  1728. $t_join_clauses[] = " LEFT JOIN $t_bugnote_text_table ON $t_bugnote_table.bugnote_text_id = $t_bugnote_text_table.id";
  1729. }
  1730. }
  1731. # End text search
  1732. $t_from_clauses[] = $t_project_table;
  1733. $t_from_clauses[] = $t_bug_table;
  1734. $t_query_clauses['select'] = $t_select_clauses;
  1735. $t_query_clauses['from'] = $t_from_clauses;
  1736. $t_query_clauses['join'] = $t_join_clauses;
  1737. $t_query_clauses['where'] = $t_where_clauses;
  1738. $t_query_clauses['where_values'] = $t_where_params;
  1739. $t_query_clauses = filter_get_query_sort_data( $t_filter, $p_show_sticky, $t_query_clauses );
  1740. # assigning to $p_* for this function writes the values back in case the caller wants to know
  1741. # Get the total number of bugs that meet the criteria.
  1742. $p_bug_count = filter_get_bug_count( $t_query_clauses );
  1743. if( 0 == $p_bug_count ) {
  1744. return array();
  1745. }
  1746. $p_per_page = filter_per_page( $t_filter, $p_bug_count, $p_per_page );
  1747. $p_page_count = filter_page_count( $p_bug_count, $p_per_page );
  1748. $p_page_number = filter_valid_page_number( $p_page_number, $p_page_count );
  1749. $t_offset = filter_offset( $p_page_number, $p_per_page );
  1750. $t_query_clauses = filter_unique_query_clauses( $t_query_clauses );
  1751. $t_select_string = "SELECT DISTINCT " . implode( ', ', $t_query_clauses['select'] );
  1752. $t_from_string = " FROM " . implode( ', ', $t_query_clauses['from'] );
  1753. $t_order_string = " ORDER BY " . implode( ', ', $t_query_clauses['order'] );
  1754. $t_join_string = count( $t_query_clauses['join'] ) > 0 ? implode( ' ', $t_query_clauses['join'] ) : '';
  1755. $t_where_string = count( $t_query_clauses['where'] ) > 0 ? 'WHERE ' . implode( ' AND ', $t_query_clauses['where'] ) : '';
  1756. $t_result = db_query_bound( "$t_select_string $t_from_string $t_join_string $t_where_string $t_order_string", $t_query_clauses['where_values'], $p_per_page, $t_offset );
  1757. $t_row_count = db_num_rows( $t_result );
  1758. $t_id_array_lastmod = array();
  1759. for( $i = 0;$i < $t_row_count;$i++ ) {
  1760. $t_row = db_fetch_array( $t_result );
  1761. $t_id_array_lastmod[] = (int) $t_row['id'];
  1762. $t_rows[] = $t_row;
  1763. }
  1764. return filter_cache_result( $t_rows, $t_id_array_lastmod );
  1765. }
  1766. /**
  1767. * Cache the filter results with bugnote stats for later use
  1768. * @param array $p_rows results of the filter query
  1769. * @param array $p_id_array_lastmod array of bug ids
  1770. * @return array
  1771. */
  1772. function filter_cache_result( $p_rows, $p_id_array_lastmod ) {
  1773. $t_bugnote_table = db_get_table( 'mantis_bugnote_table' );
  1774. $t_id_array_lastmod = array_unique( $p_id_array_lastmod );
  1775. $t_where_string = "WHERE $t_bugnote_table.bug_id in (" . implode( ", ", $t_id_array_lastmod ) . ')';
  1776. $t_query = "SELECT DISTINCT bug_id,MAX(last_modified) as last_modified, COUNT(last_modified) as count FROM $t_bugnote_table $t_where_string GROUP BY bug_id";
  1777. # perform query
  1778. $t_result = db_query_bound( $t_query );
  1779. $t_row_count = db_num_rows( $t_result );
  1780. for( $i = 0;$i < $t_row_count;$i++ ) {
  1781. $t_row = db_fetch_array( $t_result );
  1782. $t_stats[$t_row['bug_id']] = $t_row;
  1783. }
  1784. $t_rows = array();
  1785. foreach( $p_rows as $t_row ) {
  1786. if( !isset( $t_stats[$t_row['id']] ) ) {
  1787. $t_rows[] = bug_row_to_object( bug_cache_database_result( $t_row, false ) );
  1788. } else {
  1789. $t_rows[] = bug_row_to_object( bug_cache_database_result( $t_row, $t_stats[ $t_row['id'] ] ) );
  1790. }
  1791. }
  1792. return $t_rows;
  1793. }
  1794. /**
  1795. * Mainly based on filter_draw_selection_area2() but adds the support for the collapsible
  1796. * filter display.
  1797. * @param int $p_page_number
  1798. * @param bool $p_for_screen
  1799. * @see filter_draw_selection_area2
  1800. */
  1801. function filter_draw_selection_area( $p_page_number, $p_for_screen = true ) {
  1802. collapse_open( 'filter' );
  1803. filter_draw_selection_area2( $p_page_number, $p_for_screen, true );
  1804. collapse_closed( 'filter' );
  1805. filter_draw_selection_area2( $p_page_number, $p_for_screen, false );
  1806. collapse_end( 'filter' );
  1807. }
  1808. /**
  1809. * Prints the filter selection area for both the bug list view screen and
  1810. * the bug list print screen. This function was an attempt to make it easier to
  1811. * add new filters and rearrange them on screen for both pages.
  1812. * @param int $p_page_number
  1813. * @param bool $p_for_screen
  1814. * @param bool $p_expanded
  1815. */
  1816. function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_expanded = true ) {
  1817. $t_form_name_suffix = $p_expanded ? '_open' : '_closed';
  1818. $t_filter = current_user_get_bug_filter();
  1819. $t_filter = filter_ensure_valid_filter( $t_filter );
  1820. $t_project_id = helper_get_current_project();
  1821. $t_page_number = (int) $p_page_number;
  1822. $t_view_type = $t_filter['_view_type'];
  1823. $t_tdclass = 'small-caption';
  1824. $t_trclass = 'row-category2';
  1825. $t_action = 'view_all_set.php?f=3';
  1826. if( $p_for_screen == false ) {
  1827. $t_tdclass = 'print';
  1828. $t_trclass = '';
  1829. $t_action = 'view_all_set.php';
  1830. }
  1831. ?>
  1832. <br />
  1833. <form method="post" name="filters<?php echo $t_form_name_suffix?>" id="filters_form<?php echo $t_form_name_suffix?>" action="<?php echo $t_action;?>">
  1834. <?php # CSRF protection not required here - form does not result in modifications ?>
  1835. <input type="hidden" name="type" value="1" />
  1836. <?php
  1837. if( $p_for_screen == false ) {
  1838. echo '<input type="hidden" name="print" value="1" />';
  1839. echo '<input type="hidden" name="offset" value="0" />';
  1840. }
  1841. ?>
  1842. <input type="hidden" name="page_number" value="<?php echo $t_page_number?>" />
  1843. <input type="hidden" name="view_type" value="<?php echo $t_view_type?>" />
  1844. <table class="width100" cellspacing="1">
  1845. <?php
  1846. $t_filter_cols = config_get( 'filter_custom_fields_per_row' );
  1847. if( $p_expanded ) {
  1848. $t_custom_cols = $t_filter_cols;
  1849. $t_current_user_access_level = current_user_get_access_level();
  1850. $t_accessible_custom_fields_ids = array();
  1851. $t_accessible_custom_fields_names = array();
  1852. $t_accessible_custom_fields_values = array();
  1853. $t_num_custom_rows = 0;
  1854. $t_per_row = 0;
  1855. if( ON == config_get( 'filter_by_custom_fields' ) ) {
  1856. $t_custom_fields = custom_field_get_linked_ids( $t_project_id );
  1857. foreach( $t_custom_fields as $t_cfid ) {
  1858. $t_field_info = custom_field_cache_row( $t_cfid, true );
  1859. if( $t_field_info['access_level_r'] <= $t_current_user_access_level && $t_field_info['filter_by'] ) {
  1860. $t_accessible_custom_fields_ids[] = $t_cfid;
  1861. $t_accessible_custom_fields_names[] = $t_field_info['name'];
  1862. $t_accessible_custom_fields_types[] = $t_field_info['type'];
  1863. $t_accessible_custom_fields_values[] = custom_field_distinct_values( $t_field_info );
  1864. }
  1865. }
  1866. if( count( $t_accessible_custom_fields_ids ) > 0 ) {
  1867. $t_per_row = config_get( 'filter_custom_fields_per_row' );
  1868. $t_num_custom_rows = ceil( count( $t_accessible_custom_fields_ids ) / $t_per_row );
  1869. }
  1870. }
  1871. $t_filters_url = 'view_filters_page.php?for_screen=' . $p_for_screen;
  1872. if( 'advanced' == $t_view_type ) {
  1873. $t_filters_url = $t_filters_url . '&amp;view_type=advanced';
  1874. }
  1875. $t_filters_url = $t_filters_url . '&amp;target_field=';
  1876. $t_show_product_version = version_should_show_product_version( $t_project_id );
  1877. $t_show_build = $t_show_product_version && ( config_get( 'enable_product_build' ) == ON );
  1878. # overload handler_id setting if user isn't supposed to see them (ref #6189)
  1879. if( !access_has_project_level( config_get( 'view_handler_threshold' ), $t_project_id ) ) {
  1880. $t_filter[FILTER_PROPERTY_HANDLER_ID] = array(
  1881. META_FILTER_ANY,
  1882. );
  1883. }
  1884. ?>
  1885. <tr <?php echo "class=\"" . $t_trclass . "\"";?>>
  1886. <td class="small-caption" valign="top">
  1887. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_REPORTER_ID . '[]';?>" id="reporter_id_filter"><?php echo lang_get( 'reporter' )?>:</a>
  1888. </td>
  1889. <td class="small-caption" valign="top">
  1890. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_MONITOR_USER_ID . '[]';?>" id="user_monitor_filter"><?php echo lang_get( 'monitored_by' )?>:</a>
  1891. </td>
  1892. <td class="small-caption" valign="top">
  1893. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_HANDLER_ID . '[]';?>" id="handler_id_filter"><?php echo lang_get( 'assigned_to' )?>:</a>
  1894. </td>
  1895. <td colspan="2" class="small-caption" valign="top">
  1896. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_CATEGORY . '[]';?>" id="show_category_filter"><?php echo lang_get( 'category' )?>:</a>
  1897. </td>
  1898. <td class="small-caption" valign="top">
  1899. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_SEVERITY_ID . '[]';?>" id="show_severity_filter"><?php echo lang_get( 'severity' )?>:</a>
  1900. </td>
  1901. <td class="small-caption" valign="top">
  1902. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_RESOLUTION_ID . '[]';?>" id="show_resolution_filter"><?php echo lang_get( 'resolution' )?>:</a>
  1903. </td>
  1904. <td class="small-caption" valign="top">
  1905. <?php if( ON == config_get( 'enable_profiles' ) ) { ?>
  1906. <a href="<?php echo $t_filters_url . 'show_profile[]';?>" id="show_profile_filter"><?php echo lang_get( 'profile' )?>:</a>
  1907. <?php } ?>
  1908. </td>
  1909. <?php if( $t_filter_cols > 8 ) {
  1910. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&#160;</td>';
  1911. }?>
  1912. </tr>
  1913. <tr class="row-1">
  1914. <td class="small-caption" valign="top" id="reporter_id_filter_target">
  1915. <?php
  1916. $t_output = '';
  1917. $t_any_found = false;
  1918. if( count( $t_filter[FILTER_PROPERTY_REPORTER_ID] ) == 0 ) {
  1919. echo lang_get( 'any' );
  1920. } else {
  1921. $t_first_flag = true;
  1922. foreach( $t_filter[FILTER_PROPERTY_REPORTER_ID] as $t_current ) {
  1923. $t_this_name = '';
  1924. echo '<input type="hidden" name="', FILTER_PROPERTY_REPORTER_ID, '[]" value="', string_attribute( $t_current ), '" />';
  1925. if( filter_field_is_any( $t_current ) ) {
  1926. $t_any_found = true;
  1927. }
  1928. else if( filter_field_is_myself( $t_current ) ) {
  1929. if( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) {
  1930. $t_this_name = '[' . lang_get( 'myself' ) . ']';
  1931. } else {
  1932. $t_any_found = true;
  1933. }
  1934. } else if( filter_field_is_none( $t_current ) ) {
  1935. $t_this_name = lang_get( 'none' );
  1936. } else {
  1937. $t_this_name = user_get_name( $t_current );
  1938. }
  1939. if( $t_first_flag != true ) {
  1940. $t_output = $t_output . '<br />';
  1941. } else {
  1942. $t_first_flag = false;
  1943. }
  1944. $t_output = $t_output . string_display_line( $t_this_name );
  1945. }
  1946. if( true == $t_any_found ) {
  1947. echo lang_get( 'any' );
  1948. } else {
  1949. echo $t_output;
  1950. }
  1951. }
  1952. ?>
  1953. </td>
  1954. <td class="small-caption" valign="top" id="user_monitor_filter_target">
  1955. <?php
  1956. $t_output = '';
  1957. $t_any_found = false;
  1958. if( count( $t_filter[FILTER_PROPERTY_MONITOR_USER_ID] ) == 0 ) {
  1959. echo lang_get( 'any' );
  1960. } else {
  1961. $t_first_flag = true;
  1962. foreach( $t_filter[FILTER_PROPERTY_MONITOR_USER_ID] as $t_current ) {
  1963. echo '<input type="hidden" name="', FILTER_PROPERTY_MONITOR_USER_ID, '[]" value="', string_attribute( $t_current ), '" />';
  1964. $t_this_name = '';
  1965. if( filter_field_is_any( $t_current ) ) {
  1966. $t_any_found = true;
  1967. }
  1968. else if( filter_field_is_myself( $t_current ) ) {
  1969. if( access_has_project_level( config_get( 'monitor_bug_threshold' ) ) ) {
  1970. $t_this_name = '[' . lang_get( 'myself' ) . ']';
  1971. } else {
  1972. $t_any_found = true;
  1973. }
  1974. } else {
  1975. $t_this_name = user_get_name( $t_current );
  1976. }
  1977. if( $t_first_flag != true ) {
  1978. $t_output = $t_output . '<br />';
  1979. } else {
  1980. $t_first_flag = false;
  1981. }
  1982. $t_output = $t_output . string_display_line( $t_this_name );
  1983. }
  1984. if( true == $t_any_found ) {
  1985. echo lang_get( 'any' );
  1986. } else {
  1987. echo string_display( $t_output );
  1988. }
  1989. }
  1990. ?>
  1991. </td>
  1992. <td class="small-caption" valign="top" id="handler_id_filter_target">
  1993. <?php
  1994. $t_output = '';
  1995. $t_any_found = false;
  1996. if( count( $t_filter[FILTER_PROPERTY_HANDLER_ID] ) == 0 ) {
  1997. echo lang_get( 'any' );
  1998. } else {
  1999. $t_first_flag = true;
  2000. foreach( $t_filter[FILTER_PROPERTY_HANDLER_ID] as $t_current ) {
  2001. echo '<input type="hidden" name="', FILTER_PROPERTY_HANDLER_ID, '[]" value="', string_attribute( $t_current ), '" />';
  2002. $t_this_name = '';
  2003. if( filter_field_is_none( $t_current ) ) {
  2004. $t_this_name = lang_get( 'none' );
  2005. } else if( filter_field_is_any( $t_current ) ) {
  2006. $t_any_found = true;
  2007. } else if( filter_field_is_myself( $t_current ) ) {
  2008. if( access_has_project_level( config_get( 'handle_bug_threshold' ) ) ) {
  2009. $t_this_name = '[' . lang_get( 'myself' ) . ']';
  2010. } else {
  2011. $t_any_found = true;
  2012. }
  2013. } else {
  2014. $t_this_name = user_get_name( $t_current );
  2015. }
  2016. if( $t_first_flag != true ) {
  2017. $t_output = $t_output . '<br />';
  2018. } else {
  2019. $t_first_flag = false;
  2020. }
  2021. $t_output = $t_output . string_display_line( $t_this_name );
  2022. }
  2023. if( true == $t_any_found ) {
  2024. echo lang_get( 'any' );
  2025. } else {
  2026. echo string_display( $t_output );
  2027. }
  2028. }
  2029. ?>
  2030. </td>
  2031. <td colspan="2" class="small-caption" valign="top" id="show_category_filter_target">
  2032. <?php
  2033. $t_output = '';
  2034. $t_any_found = false;
  2035. if( count( $t_filter[FILTER_PROPERTY_CATEGORY] ) == 0 ) {
  2036. echo lang_get( 'any' );
  2037. } else {
  2038. $t_first_flag = true;
  2039. foreach( $t_filter[FILTER_PROPERTY_CATEGORY] as $t_current ) {
  2040. echo '<input type="hidden" name="', FILTER_PROPERTY_CATEGORY, '[]" value="', string_attribute( $t_current ), '" />';
  2041. $t_this_string = '';
  2042. if( filter_field_is_any( $t_current ) ) {
  2043. $t_any_found = true;
  2044. } else {
  2045. $t_this_string = $t_current;
  2046. }
  2047. if( $t_first_flag != true ) {
  2048. $t_output = $t_output . '<br />';
  2049. } else {
  2050. $t_first_flag = false;
  2051. }
  2052. $t_output = $t_output . string_display_line( $t_this_string );
  2053. }
  2054. if( true == $t_any_found ) {
  2055. echo lang_get( 'any' );
  2056. } else {
  2057. echo $t_output;
  2058. }
  2059. }
  2060. ?>
  2061. </td>
  2062. <td class="small-caption" valign="top" id="show_severity_filter_target">
  2063. <?php
  2064. $t_output = '';
  2065. $t_any_found = false;
  2066. if( count( $t_filter[FILTER_PROPERTY_SEVERITY_ID] ) == 0 ) {
  2067. echo lang_get( 'any' );
  2068. } else {
  2069. $t_first_flag = true;
  2070. foreach( $t_filter[FILTER_PROPERTY_SEVERITY_ID] as $t_current ) {
  2071. echo '<input type="hidden" name="', FILTER_PROPERTY_SEVERITY_ID, '[]" value="', string_attribute( $t_current ), '" />';
  2072. $t_this_string = '';
  2073. if( filter_field_is_any( $t_current ) ) {
  2074. $t_any_found = true;
  2075. } else {
  2076. $t_this_string = get_enum_element( 'severity', $t_current );
  2077. }
  2078. if( $t_first_flag != true ) {
  2079. $t_output = $t_output . '<br />';
  2080. } else {
  2081. $t_first_flag = false;
  2082. }
  2083. $t_output = $t_output . string_display_line( $t_this_string );
  2084. }
  2085. if( true == $t_any_found ) {
  2086. echo lang_get( 'any' );
  2087. } else {
  2088. echo $t_output;
  2089. }
  2090. }
  2091. ?>
  2092. </td>
  2093. <td class="small-caption" valign="top" id="show_resolution_filter_target">
  2094. <?php
  2095. $t_output = '';
  2096. $t_any_found = false;
  2097. if( count( $t_filter[FILTER_PROPERTY_RESOLUTION_ID] ) == 0 ) {
  2098. echo lang_get( 'any' );
  2099. } else {
  2100. $t_first_flag = true;
  2101. foreach( $t_filter[FILTER_PROPERTY_RESOLUTION_ID] as $t_current ) {
  2102. ?>
  2103. <input type="hidden" name="show_resolution[]" value="<?php echo string_attribute( $t_current );?>" />
  2104. <?php
  2105. $t_this_string = '';
  2106. if( filter_field_is_any( $t_current ) ) {
  2107. $t_any_found = true;
  2108. } else {
  2109. $t_this_string = get_enum_element( 'resolution', $t_current );
  2110. }
  2111. if( $t_first_flag != true ) {
  2112. $t_output = $t_output . '<br />';
  2113. } else {
  2114. $t_first_flag = false;
  2115. }
  2116. $t_output = $t_output . string_display_line( $t_this_string );
  2117. }
  2118. if( true == $t_any_found ) {
  2119. echo lang_get( 'any' );
  2120. } else {
  2121. echo $t_output;
  2122. }
  2123. }
  2124. ?>
  2125. </td>
  2126. <?php if( ON == config_get( 'enable_profiles' ) ) { ?>
  2127. <td class="small-caption" valign="top" id="show_profile_filter_target">
  2128. <?php
  2129. $t_output = '';
  2130. $t_any_found = false;
  2131. if( count( $t_filter['show_profile'] ) == 0 ) {
  2132. echo lang_get( 'any' );
  2133. } else {
  2134. $t_first_flag = true;
  2135. foreach( $t_filter['show_profile'] as $t_current ) {
  2136. ?>
  2137. <input type="hidden" name="show_profile[]" value="<?php echo string_attribute( $t_current );?>" />
  2138. <?php
  2139. $t_this_string = '';
  2140. if( filter_field_is_any( $t_current ) ) {
  2141. $t_any_found = true;
  2142. } else {
  2143. $t_profile = profile_get_row_direct( $t_current );
  2144. $t_this_string = "${t_profile['platform']} ${t_profile['os']} ${t_profile['os_build']}";
  2145. }
  2146. if( $t_first_flag != true ) {
  2147. $t_output = $t_output . '<br />';
  2148. } else {
  2149. $t_first_flag = false;
  2150. }
  2151. $t_output = $t_output . string_display_line( $t_this_string );
  2152. }
  2153. if( true == $t_any_found ) {
  2154. echo lang_get( 'any' );
  2155. } else {
  2156. echo $t_output;
  2157. }
  2158. }
  2159. ?>
  2160. </td>
  2161. <?php } else { ?>
  2162. <td></td>
  2163. <?php }
  2164. if( $t_filter_cols > 8 ) {
  2165. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&#160;</td>';
  2166. }?>
  2167. </tr>
  2168. <tr <?php echo "class=\"" . $t_trclass . "\"";?>>
  2169. <td class="small-caption" valign="top">
  2170. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_STATUS_ID . '[]';?>" id="show_status_filter"><?php echo lang_get( 'status' )?>:</a>
  2171. </td>
  2172. <td class="small-caption" valign="top">
  2173. <?php if( 'simple' == $t_view_type ) {?>
  2174. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_HIDE_STATUS_ID . '[]';?>" id="hide_status_filter"><?php echo lang_get( 'hide_status' )?>:</a>
  2175. <?php
  2176. }?>
  2177. </td>
  2178. <td class="small-caption" valign="top">
  2179. <?php if ( $t_show_build ) { ?>
  2180. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_PRODUCT_BUILD . '[]';?>" id="show_build_filter"><?php echo lang_get( 'product_build' )?>:</a>
  2181. <?php } ?>
  2182. </td>
  2183. <?php if( $t_show_product_version ) {?>
  2184. <td colspan="2" class="small-caption" valign="top">
  2185. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_PRODUCT_VERSION . '[]';?>" id="show_version_filter"><?php echo lang_get( 'product_version' )?>:</a>
  2186. </td>
  2187. <td colspan="1" class="small-caption" valign="top">
  2188. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_FIXED_IN_VERSION . '[]';?>" id="show_fixed_in_version_filter"><?php echo lang_get( 'fixed_in_version' )?>:</a>
  2189. </td>
  2190. <td colspan="1" class="small-caption" valign="top">
  2191. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_TARGET_VERSION . '[]';?>" id="show_target_version_filter"><?php echo lang_get( 'target_version' )?>:</a>
  2192. </td>
  2193. <?php
  2194. } else {?>
  2195. <td colspan="2" class="small-caption" valign="top">
  2196. &#160;
  2197. </td>
  2198. <td colspan="1" class="small-caption" valign="top">
  2199. &#160;
  2200. </td>
  2201. <td colspan="1" class="small-caption" valign="top">
  2202. &nbsp;
  2203. </td>
  2204. <?php
  2205. }?>
  2206. <td colspan="1" class="small-caption" valign="top">
  2207. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_PRIORITY_ID . '[]';?>" id="show_priority_filter"><?php echo lang_get( 'priority' )?>:</a>
  2208. </td>
  2209. <?php if( $t_filter_cols > 8 ) {
  2210. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 7 ) . '">&#160;</td>';
  2211. }?>
  2212. </tr>
  2213. <tr class="row-1">
  2214. <td class="small-caption" valign="top" id="show_status_filter_target">
  2215. <?php
  2216. $t_output = '';
  2217. $t_any_found = false;
  2218. if( count( $t_filter[FILTER_PROPERTY_STATUS_ID] ) == 0 ) {
  2219. echo lang_get( 'any' );
  2220. } else {
  2221. $t_first_flag = true;
  2222. foreach( $t_filter[FILTER_PROPERTY_STATUS_ID] as $t_current ) {
  2223. echo '<input type="hidden" name="', FILTER_PROPERTY_STATUS_ID, '[]" value="', string_attribute( $t_current ), '" />';
  2224. $t_this_string = '';
  2225. if( filter_field_is_any( $t_current ) ) {
  2226. $t_any_found = true;
  2227. } else {
  2228. $t_this_string = get_enum_element( 'status', $t_current );
  2229. }
  2230. if( $t_first_flag != true ) {
  2231. $t_output = $t_output . '<br />';
  2232. } else {
  2233. $t_first_flag = false;
  2234. }
  2235. $t_output = $t_output . string_display_line( $t_this_string );
  2236. }
  2237. if( true == $t_any_found ) {
  2238. echo lang_get( 'any' );
  2239. } else {
  2240. echo $t_output;
  2241. }
  2242. }
  2243. ?>
  2244. </td>
  2245. <td class="small-caption" valign="top" id="hide_status_filter_target">
  2246. <?php
  2247. if( 'simple' == $t_view_type ) {
  2248. $t_output = '';
  2249. $t_none_found = false;
  2250. if( count( $t_filter[FILTER_PROPERTY_HIDE_STATUS_ID] ) == 0 ) {
  2251. echo lang_get( 'none' );
  2252. } else {
  2253. $t_first_flag = true;
  2254. foreach( $t_filter[FILTER_PROPERTY_HIDE_STATUS_ID] as $t_current ) {
  2255. echo '<input type="hidden" name="', FILTER_PROPERTY_HIDE_STATUS_ID, '[]" value="', string_attribute( $t_current ), '" />';
  2256. $t_this_string = '';
  2257. if( filter_field_is_none( $t_current ) ) {
  2258. $t_none_found = true;
  2259. } else {
  2260. $t_this_string = get_enum_element( 'status', $t_current );
  2261. }
  2262. if( $t_first_flag != true ) {
  2263. $t_output = $t_output . '<br />';
  2264. } else {
  2265. $t_first_flag = false;
  2266. }
  2267. $t_output = $t_output . string_display_line( $t_this_string );
  2268. }
  2269. $t_hide_status_post = '';
  2270. if( count( $t_filter[FILTER_PROPERTY_HIDE_STATUS_ID] ) == 1 ) {
  2271. $t_hide_status_post = ' (' . lang_get( 'and_above' ) . ')';
  2272. }
  2273. if( true == $t_none_found ) {
  2274. echo lang_get( 'none' );
  2275. } else {
  2276. echo $t_output . string_display_line( $t_hide_status_post );
  2277. }
  2278. }
  2279. }
  2280. ?>
  2281. </td>
  2282. <?php if ( $t_show_build ) { ?>
  2283. <td class="small-caption" valign="top" id="show_build_filter_target">
  2284. <?php
  2285. $t_output = '';
  2286. $t_any_found = false;
  2287. if( count( $t_filter[FILTER_PROPERTY_PRODUCT_BUILD] ) == 0 ) {
  2288. echo lang_get( 'any' );
  2289. } else {
  2290. $t_first_flag = true;
  2291. foreach( $t_filter[FILTER_PROPERTY_PRODUCT_BUILD] as $t_current ) {
  2292. $t_current = stripslashes( $t_current );
  2293. echo '<input type="hidden" name="', FILTER_PROPERTY_PRODUCT_BUILD, '[]" value="', string_attribute( $t_current ), '" />';
  2294. $t_this_string = '';
  2295. if( filter_field_is_any( $t_current ) ) {
  2296. $t_any_found = true;
  2297. } else if( filter_field_is_none( $t_current ) ) {
  2298. $t_this_string = lang_get( 'none' );
  2299. } else {
  2300. $t_this_string = $t_current;
  2301. }
  2302. if( $t_first_flag != true ) {
  2303. $t_output = $t_output . '<br />';
  2304. } else {
  2305. $t_first_flag = false;
  2306. }
  2307. $t_output = $t_output . string_display_line( $t_this_string );
  2308. }
  2309. if( true == $t_any_found ) {
  2310. echo lang_get( 'any' );
  2311. } else {
  2312. echo $t_output;
  2313. }
  2314. }
  2315. ?>
  2316. </td>
  2317. <?php } else { ?>
  2318. <td class="small-caption" valign="top"></td>
  2319. <?php }
  2320. if( $t_show_product_version ) {
  2321. ?>
  2322. <td colspan="2" class="small-caption" valign="top" id="show_version_filter_target">
  2323. <?php
  2324. $t_output = '';
  2325. $t_any_found = false;
  2326. if( count( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION] ) == 0 ) {
  2327. echo lang_get( 'any' );
  2328. } else {
  2329. $t_first_flag = true;
  2330. foreach( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION] as $t_current ) {
  2331. $t_current = stripslashes( $t_current );
  2332. echo '<input type="hidden" name="', FILTER_PROPERTY_PRODUCT_VERSION, '[]" value="', string_attribute( $t_current ), '" />';
  2333. $t_this_string = '';
  2334. if( filter_field_is_any( $t_current ) ) {
  2335. $t_any_found = true;
  2336. }
  2337. else if( filter_field_is_none( $t_current ) ) {
  2338. $t_this_string = lang_get( 'none' );
  2339. } else {
  2340. $t_this_string = $t_current;
  2341. }
  2342. if( $t_first_flag != true ) {
  2343. $t_output = $t_output . '<br />';
  2344. } else {
  2345. $t_first_flag = false;
  2346. }
  2347. $t_output = $t_output . string_display_line( $t_this_string );
  2348. }
  2349. if( true == $t_any_found ) {
  2350. echo lang_get( 'any' );
  2351. } else {
  2352. echo $t_output;
  2353. }
  2354. }
  2355. ?>
  2356. </td>
  2357. <td colspan="1" class="small-caption" valign="top" id="show_fixed_in_version_filter_target">
  2358. <?php
  2359. $t_output = '';
  2360. $t_any_found = false;
  2361. if( count( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION] ) == 0 ) {
  2362. echo lang_get( 'any' );
  2363. } else {
  2364. $t_first_flag = true;
  2365. foreach( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION] as $t_current ) {
  2366. $t_current = stripslashes( $t_current );
  2367. echo '<input type="hidden" name="', FILTER_PROPERTY_FIXED_IN_VERSION, '[]" value="', string_attribute( $t_current ), '" />';
  2368. $t_this_string = '';
  2369. if( filter_field_is_any( $t_current ) ) {
  2370. $t_any_found = true;
  2371. } else if( filter_field_is_none( $t_current ) ) {
  2372. $t_this_string = lang_get( 'none' );
  2373. } else {
  2374. $t_this_string = $t_current;
  2375. }
  2376. if( $t_first_flag != true ) {
  2377. $t_output = $t_output . '<br />';
  2378. } else {
  2379. $t_first_flag = false;
  2380. }
  2381. $t_output = $t_output . string_display_line( $t_this_string );
  2382. }
  2383. if( true == $t_any_found ) {
  2384. echo lang_get( 'any' );
  2385. } else {
  2386. echo $t_output;
  2387. }
  2388. }
  2389. ?>
  2390. </td>
  2391. <td colspan="1" class="small-caption" valign="top" id="show_target_version_filter_target">
  2392. <?php
  2393. $t_output = '';
  2394. $t_any_found = false;
  2395. if( count( $t_filter[FILTER_PROPERTY_TARGET_VERSION] ) == 0 ) {
  2396. echo lang_get( 'any' );
  2397. } else {
  2398. $t_first_flag = true;
  2399. foreach( $t_filter[FILTER_PROPERTY_TARGET_VERSION] as $t_current ) {
  2400. $t_current = stripslashes( $t_current );
  2401. echo '<input type="hidden" name="', FILTER_PROPERTY_TARGET_VERSION, '[]" value="', string_attribute( $t_current ), '" />';
  2402. $t_this_string = '';
  2403. if( filter_field_is_any( $t_current ) ) {
  2404. $t_any_found = true;
  2405. } else if( filter_field_is_none( $t_current ) ) {
  2406. $t_this_string = lang_get( 'none' );
  2407. } else {
  2408. $t_this_string = $t_current;
  2409. }
  2410. if( $t_first_flag != true ) {
  2411. $t_output = $t_output . '<br />';
  2412. } else {
  2413. $t_first_flag = false;
  2414. }
  2415. $t_output = $t_output . string_display_line( $t_this_string );
  2416. }
  2417. if( true == $t_any_found ) {
  2418. echo lang_get( 'any' );
  2419. } else {
  2420. echo $t_output;
  2421. }
  2422. }
  2423. ?>
  2424. </td>
  2425. <?php
  2426. } else {?>
  2427. <td colspan="2" class="small-caption" valign="top">
  2428. &#160;
  2429. </td>
  2430. <td colspan="1" class="small-caption" valign="top">
  2431. &#160;
  2432. </td>
  2433. <td colspan="1" class="small-caption" valign="top">
  2434. &nbsp;
  2435. </td>
  2436. <?php
  2437. }?>
  2438. <td colspan="1" class="small-caption" valign="top" id="show_priority_filter_target">
  2439. <?php
  2440. $t_output = '';
  2441. $t_any_found = false;
  2442. if( count( $t_filter[FILTER_PROPERTY_PRIORITY_ID] ) == 0 ) {
  2443. echo lang_get( 'any' );
  2444. } else {
  2445. $t_first_flag = true;
  2446. foreach( $t_filter[FILTER_PROPERTY_PRIORITY_ID] as $t_current ) {
  2447. echo '<input type="hidden" name="', FILTER_PROPERTY_PRIORITY_ID, '[]" value="', string_attribute( $t_current ), '" />';
  2448. $t_this_string = '';
  2449. if( filter_field_is_any( $t_current ) ) {
  2450. $t_any_found = true;
  2451. } else {
  2452. $t_this_string = get_enum_element( 'priority', $t_current );
  2453. }
  2454. if( $t_first_flag != true ) {
  2455. $t_output = $t_output . '<br />';
  2456. } else {
  2457. $t_first_flag = false;
  2458. }
  2459. $t_output = $t_output . string_display_line( $t_this_string );
  2460. }
  2461. if( true == $t_any_found ) {
  2462. echo lang_get( 'any' );
  2463. } else {
  2464. echo $t_output;
  2465. }
  2466. }
  2467. ?>
  2468. </td>
  2469. <?php if( $t_filter_cols > 8 ) {
  2470. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 7 ) . '">&#160;</td>';
  2471. }?>
  2472. </tr>
  2473. <tr <?php echo "class=\"" . $t_trclass . "\"";?>>
  2474. <td class="small-caption" valign="top">
  2475. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_ISSUES_PER_PAGE;?>" id="per_page_filter"><?php echo lang_get( 'show' )?>:</a>
  2476. </td>
  2477. <td class="small-caption" valign="top">
  2478. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_VIEW_STATE_ID;?>" id="view_state_filter"><?php echo lang_get( 'view_status' )?>:</a>
  2479. </td>
  2480. <td class="small-caption" valign="top">
  2481. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_SHOW_STICKY_ISSUES;?>" id="sticky_issues_filter"><?php echo lang_get( 'sticky' )?>:</a>
  2482. </td>
  2483. <td class="small-caption" valign="top" colspan="2">
  2484. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_HIGHLIGHT_CHANGED;?>" id="highlight_changed_filter"><?php echo lang_get( 'changed' )?>:</a>
  2485. </td>
  2486. <td class="small-caption" valign="top" >
  2487. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_FILTER_BY_DATE;?>" id="do_filter_by_date_filter"><?php echo lang_get( 'use_date_filters' )?>:</a>
  2488. </td>
  2489. <td class="small-caption" valign="top" colspan="2">
  2490. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_RELATIONSHIP_TYPE;?>" id="relationship_type_filter"><?php echo lang_get( 'bug_relationships' )?>:</a>
  2491. </td>
  2492. <?php if( $t_filter_cols > 8 ) {
  2493. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&#160;</td>';
  2494. }?>
  2495. </tr>
  2496. <tr class="row-1">
  2497. <td class="small-caption" valign="top" id="per_page_filter_target">
  2498. <?php
  2499. echo( $t_filter[FILTER_PROPERTY_ISSUES_PER_PAGE] == 0 ) ? lang_get( 'all' ) : string_display_line( $t_filter[FILTER_PROPERTY_ISSUES_PER_PAGE] );
  2500. echo '<input type="hidden" name="', FILTER_PROPERTY_ISSUES_PER_PAGE, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_ISSUES_PER_PAGE] ), '" />';
  2501. ?>
  2502. </td>
  2503. <td class="small-caption" valign="top" id="view_state_filter_target">
  2504. <?php
  2505. if( VS_PUBLIC === $t_filter[FILTER_PROPERTY_VIEW_STATE_ID] ) {
  2506. echo lang_get( 'public' );
  2507. } else if( VS_PRIVATE === $t_filter[FILTER_PROPERTY_VIEW_STATE_ID] ) {
  2508. echo lang_get( 'private' );
  2509. } else {
  2510. echo lang_get( 'any' );
  2511. $t_filter[FILTER_PROPERTY_VIEW_STATE_ID] = META_FILTER_ANY;
  2512. }
  2513. echo '<input type="hidden" name="', FILTER_PROPERTY_VIEW_STATE_ID, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_VIEW_STATE_ID] ), '" />';
  2514. ?>
  2515. </td>
  2516. <td class="small-caption" valign="top" id="sticky_issues_filter_target">
  2517. <?php
  2518. $t_sticky_filter_state = gpc_string_to_bool( $t_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] );
  2519. print( $t_sticky_filter_state ? lang_get( 'yes' ) : lang_get( 'no' ) );
  2520. ?>
  2521. <input type="hidden" name="sticky_issues" value="<?php echo $t_sticky_filter_state ? 'on' : 'off';?>" />
  2522. </td>
  2523. <td class="small-caption" valign="top" colspan="2" id="highlight_changed_filter_target">
  2524. <?php
  2525. echo $t_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED];
  2526. echo '<input type="hidden" name="', FILTER_PROPERTY_HIGHLIGHT_CHANGED, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] ), '" />';
  2527. ?>
  2528. </td>
  2529. <td class="small-caption" valign="top" id="do_filter_by_date_filter_target">
  2530. <?php
  2531. if(( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ) {
  2532. ?>
  2533. <script type="text/javascript" language="JavaScript">
  2534. <!--
  2535. function SwitchDateFields() {
  2536. // All fields need to be enabled to go back to the script
  2537. document.filters_open.start_month.disabled = ! document.filters_open.do_filter_by_date.checked;
  2538. document.filters_open.start_day.disabled = ! document.filters_open.do_filter_by_date.checked;
  2539. document.filters_open.start_year.disabled = ! document.filters_open.do_filter_by_date.checked;
  2540. document.filters_open.end_month.disabled = ! document.filters_open.do_filter_by_date.checked;
  2541. document.filters_open.end_day.disabled = ! document.filters_open.do_filter_by_date.checked;
  2542. document.filters_open.end_year.disabled = ! document.filters_open.do_filter_by_date.checked;
  2543. return true;
  2544. }
  2545. // -->
  2546. </script>
  2547. <?php
  2548. }
  2549. # end if dhtml_filters
  2550. if( 'on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) {
  2551. echo '<input type="hidden" name="', FILTER_PROPERTY_FILTER_BY_DATE, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ), '" />';
  2552. echo '<input type="hidden" name="', FILTER_PROPERTY_START_MONTH, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_START_MONTH] ), '" />';
  2553. echo '<input type="hidden" name="', FILTER_PROPERTY_START_DAY, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_START_DAY] ), '" />';
  2554. echo '<input type="hidden" name="', FILTER_PROPERTY_START_YEAR, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_START_YEAR] ), '" />';
  2555. echo '<input type="hidden" name="', FILTER_PROPERTY_END_MONTH, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_END_MONTH] ), '" />';
  2556. echo '<input type="hidden" name="', FILTER_PROPERTY_END_DAY, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_END_DAY] ), '" />';
  2557. echo '<input type="hidden" name="', FILTER_PROPERTY_END_YEAR, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_END_YEAR] ), '" />';
  2558. $t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
  2559. $t_time = mktime( 0, 0, 0, $t_filter[FILTER_PROPERTY_START_MONTH], $t_filter[FILTER_PROPERTY_START_DAY], $t_filter[FILTER_PROPERTY_START_YEAR] );
  2560. foreach( $t_chars as $t_char ) {
  2561. if( strcasecmp( $t_char, "M" ) == 0 ) {
  2562. echo ' ';
  2563. echo date( 'F', $t_time );
  2564. }
  2565. if( strcasecmp( $t_char, "D" ) == 0 ) {
  2566. echo ' ';
  2567. echo date( 'd', $t_time );
  2568. }
  2569. if( strcasecmp( $t_char, "Y" ) == 0 ) {
  2570. echo ' ';
  2571. echo date( 'Y', $t_time );
  2572. }
  2573. }
  2574. echo ' - ';
  2575. $t_time = mktime( 0, 0, 0, $t_filter[FILTER_PROPERTY_END_MONTH], $t_filter[FILTER_PROPERTY_END_DAY], $t_filter[FILTER_PROPERTY_END_YEAR] );
  2576. foreach( $t_chars as $t_char ) {
  2577. if( strcasecmp( $t_char, "M" ) == 0 ) {
  2578. echo ' ';
  2579. echo date( 'F', $t_time );
  2580. }
  2581. if( strcasecmp( $t_char, "D" ) == 0 ) {
  2582. echo ' ';
  2583. echo date( 'd', $t_time );
  2584. }
  2585. if( strcasecmp( $t_char, "Y" ) == 0 ) {
  2586. echo ' ';
  2587. echo date( 'Y', $t_time );
  2588. }
  2589. }
  2590. } else {
  2591. echo lang_get( 'no' );
  2592. }
  2593. ?>
  2594. </td>
  2595. <td class="small-caption" valign="top" colspan="2" id="relationship_type_filter_target">
  2596. <?php
  2597. echo '<input type="hidden" name="', FILTER_PROPERTY_RELATIONSHIP_TYPE, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE]), '" />';
  2598. echo '<input type="hidden" name="', FILTER_PROPERTY_RELATIONSHIP_BUG, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] ), '" />';
  2599. $c_rel_type = $t_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE];
  2600. $c_rel_bug = $t_filter[FILTER_PROPERTY_RELATIONSHIP_BUG];
  2601. if( -1 == $c_rel_type || 0 == $c_rel_bug ) {
  2602. echo lang_get( 'any' );
  2603. } else {
  2604. echo relationship_get_description_for_history( $c_rel_type ) . ' ' . $c_rel_bug;
  2605. }
  2606. ?>
  2607. </td>
  2608. <?php if( $t_filter_cols > 8 ) {
  2609. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&#160;</td>';
  2610. }?>
  2611. </tr>
  2612. <tr <?php echo "class=\"" . $t_trclass . "\"";?>>
  2613. <td class="small-caption" valign="top">
  2614. <?php if( ON == config_get( 'enable_profiles' ) ) { ?>
  2615. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_PLATFORM;?>" id="platform_filter"><?php echo lang_get( 'platform' )?>:</a>
  2616. <?php } ?>
  2617. </td>
  2618. <td class="small-caption" valign="top">
  2619. <?php if( ON == config_get( 'enable_profiles' ) ) { ?>
  2620. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_OS;?>" id="os_filter"><?php echo lang_get( 'os' )?>:</a>
  2621. <?php } ?>
  2622. </td>
  2623. <td class="small-caption" valign="top">
  2624. <?php if( ON == config_get( 'enable_profiles' ) ) { ?>
  2625. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_OS_BUILD;?>" id="os_build_filter"><?php echo lang_get( 'os_version' )?>:</a>
  2626. <?php } ?>
  2627. </td>
  2628. <td class="small-caption" valign="top" colspan="5">
  2629. <?php if ( access_has_global_level( config_get( 'tag_view_threshold' ) ) ) { ?>
  2630. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_TAG_STRING;?>" id="tag_string_filter"><?php echo lang_get( 'tags' )?>:</a>
  2631. <?php } ?>
  2632. </td>
  2633. <?php if( $t_filter_cols > 8 ) {
  2634. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 8 ) . '">&#160;</td>';
  2635. }?>
  2636. </tr>
  2637. <tr class="row-1">
  2638. <?php if( ON == config_get( 'enable_profiles' ) ) { ?>
  2639. <td class="small-caption" valign="top" id="platform_filter_target">
  2640. <?php
  2641. print_multivalue_field( FILTER_PROPERTY_PLATFORM, $t_filter[FILTER_PROPERTY_PLATFORM] );
  2642. ?>
  2643. </td>
  2644. <td class="small-caption" valign="top" id="os_filter_target">
  2645. <?php
  2646. print_multivalue_field( FILTER_PROPERTY_OS, $t_filter[FILTER_PROPERTY_OS] );
  2647. ?>
  2648. </td>
  2649. <td class="small-caption" valign="top" id="os_build_filter_target">
  2650. <?php
  2651. print_multivalue_field( FILTER_PROPERTY_OS_BUILD, $t_filter[FILTER_PROPERTY_OS_BUILD] );
  2652. ?>
  2653. </td>
  2654. <?php } else {?>
  2655. <td colspan="3">&#160;</td>
  2656. <?php } ?>
  2657. <td class="small-caption" valign="top" id="tag_string_filter_target" colspan="5">
  2658. <?php
  2659. $t_tag_string = $t_filter[FILTER_PROPERTY_TAG_STRING];
  2660. if( $t_filter[FILTER_PROPERTY_TAG_SELECT] != 0 && tag_exists( $t_filter[FILTER_PROPERTY_TAG_SELECT] ) ) {
  2661. $t_tag_string .= ( is_blank( $t_tag_string ) ? '' : config_get( 'tag_separator' ) );
  2662. $t_tag_string .= tag_get_field( $t_filter[FILTER_PROPERTY_TAG_SELECT], 'name' );
  2663. }
  2664. echo string_html_entities( $t_tag_string );
  2665. echo '<input type="hidden" name="', FILTER_PROPERTY_TAG_STRING, '" value="', string_attribute( $t_tag_string ), '" />';
  2666. ?>
  2667. </td>
  2668. </tr>
  2669. <?php
  2670. # get plugin filters
  2671. $t_plugin_filters = filter_get_plugin_filters();
  2672. $t_column = 0;
  2673. $t_fields = '';
  2674. $t_values = '';
  2675. # output a filter form element for each plugin filter
  2676. foreach( $t_plugin_filters as $t_field_name => $t_filter_object ) {
  2677. $t_fields .= '<td class="small-caption" valign="top"> <a href="' . $t_filters_url . string_attribute( $t_field_name ) .
  2678. '" id="' . string_attribute( $t_field_name ) . '_filter">' . string_display_line( $t_filter_object->title ) . '</a> </td>';
  2679. $t_values .= '<td class="small-caption" valign="top" id="' . string_attribute( $t_field_name ) . '_filter_target"> ';
  2680. if ( !isset( $t_filter[ $t_field_name ] ) ) {
  2681. $t_values .= lang_get( 'any' );
  2682. } else {
  2683. switch( $t_filter_object->type ) {
  2684. case FILTER_TYPE_STRING:
  2685. case FILTER_TYPE_INT:
  2686. if ( filter_field_is_any( $t_filter[ $t_field_name ] ) ) {
  2687. $t_values .= lang_get( 'any' );
  2688. } else {
  2689. $t_values .= string_display_line( $t_filter[ $t_field_name ] );
  2690. }
  2691. $t_values .= '<input type="hidden" name="' . string_attribute( $t_field_name ) . '" value="' . string_attribute( $t_filter[ $t_field_name ] ) . '"/>';
  2692. break;
  2693. case FILTER_TYPE_BOOLEAN:
  2694. $t_values .= string_display_line( $t_filter_object->display( (bool)$t_filter[ $t_field_name ] ) );
  2695. $t_values .= '<input type="hidden" name="' . string_attribute( $t_field_name ) . '" value="' . (bool)$t_filter[ $t_field_name ] . '"/>';
  2696. break;
  2697. case FILTER_TYPE_MULTI_STRING:
  2698. case FILTER_TYPE_MULTI_INT:
  2699. $t_first = true;
  2700. $t_output = '';
  2701. if ( !is_array( $t_filter[ $t_field_name ] ) ) {
  2702. $t_filter[ $t_field_name ] = array( $t_filter[ $t_field_name ] );
  2703. }
  2704. foreach( $t_filter[ $t_field_name ] as $t_current ) {
  2705. if ( filter_field_is_any( $t_current ) ) {
  2706. $t_output .= lang_get( 'any' );
  2707. } else {
  2708. $t_output .= ( $t_first ? '' : '<br />' ) . string_display_line( $t_filter_object->display( $t_current ) );
  2709. $t_first = false;
  2710. }
  2711. $t_values .= '<input type="hidden" name="' . string_attribute( $t_field_name ) . '[]" value="' . string_attribute( $t_current ) . '"/>';
  2712. }
  2713. $t_values .= $t_output;
  2714. break;
  2715. }
  2716. }
  2717. $t_values .= '</td>';
  2718. $t_column++;
  2719. # wrap at the appropriate column
  2720. if ( $t_column >= $t_filter_cols ) {
  2721. echo '<tr class="', $t_trclass, '">', $t_fields, '</tr>';
  2722. echo '<tr class="row-1">', $t_values, '</tr>';
  2723. $t_fields = '';
  2724. $t_values = '';
  2725. $t_column = 0;
  2726. }
  2727. }
  2728. # output any remaining plugin filters
  2729. if ( $t_column > 0 ) {
  2730. if ( $t_column < $t_filter_cols ) {
  2731. $t_fields .= '<td class="small-caption" colspan="' . ( $t_filter_cols - $t_column ) . '">&#160;</td>';
  2732. $t_values .= '<td class="small-caption" colspan="' . ( $t_filter_cols - $t_column ) . '">&#160;</td>';
  2733. }
  2734. echo '<tr class="', $t_trclass, '">', $t_fields, '</tr>';
  2735. echo '<tr class="row-1">', $t_values, '</tr>';
  2736. }
  2737. if( ON == config_get( 'filter_by_custom_fields' ) ) {
  2738. # -- Custom Field Searching --
  2739. if( count( $t_accessible_custom_fields_ids ) > 0 ) {
  2740. $t_per_row = config_get( 'filter_custom_fields_per_row' );
  2741. $t_num_fields = count( $t_accessible_custom_fields_ids );
  2742. $t_row_idx = 0;
  2743. $t_col_idx = 0;
  2744. $t_fields = '';
  2745. $t_values = '';
  2746. for( $i = 0;$i < $t_num_fields;$i++ ) {
  2747. if( $t_col_idx == 0 ) {
  2748. $t_fields = '<tr class="' . $t_trclass . '">';
  2749. $t_values = '<tr class="row-1">';
  2750. }
  2751. if( isset( $t_accessible_custom_fields_names[$i] ) ) {
  2752. $t_fields .= '<td class="small-caption" valign="top"> ';
  2753. $t_fields .= '<a href="' . $t_filters_url . 'custom_field_' . $t_accessible_custom_fields_ids[$i] . '[]" id="custom_field_' . $t_accessible_custom_fields_ids[$i] . '_filter">';
  2754. $t_fields .= string_display_line( lang_get_defaulted( $t_accessible_custom_fields_names[$i] ) );
  2755. $t_fields .= '</a> </td> ';
  2756. }
  2757. $t_output = '';
  2758. $t_any_found = false;
  2759. $t_values .= '<td class="small-caption" valign="top" id="custom_field_' . $t_accessible_custom_fields_ids[$i] . '_filter_target"> ';
  2760. if( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]] ) ) {
  2761. $t_values .= lang_get( 'any' );
  2762. } else {
  2763. if( $t_accessible_custom_fields_types[$i] == CUSTOM_FIELD_TYPE_DATE ) {
  2764. /** @todo moved embedded javascript here from print_filter_custom_field_date
  2765. * it appears not to load properly on Firefox and other browsers if loaded through the httpxmlreq
  2766. */
  2767. $t_field_id = $t_accessible_custom_fields_ids[$i];
  2768. $t_js_toggle_func = "toggle_custom_date_field_" . $t_field_id . "_controls";
  2769. if(( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ) {
  2770. ?>
  2771. <script type="text/javascript" language="JavaScript">
  2772. <!--
  2773. function <?php echo $t_js_toggle_func . "_start";?>(disable) {
  2774. document.filters_open.custom_field_<?php echo $t_field_id;?>_start_year.disabled = disable ;
  2775. document.filters_open.custom_field_<?php echo $t_field_id;?>_start_month.disabled = disable ;
  2776. document.filters_open.custom_field_<?php echo $t_field_id;?>_start_day.disabled = disable ;
  2777. } ;
  2778. function <?php echo $t_js_toggle_func . "_end";?>(disable) {
  2779. document.filters_open.custom_field_<?php echo $t_field_id;?>_end_year.disabled = disable ;
  2780. document.filters_open.custom_field_<?php echo $t_field_id;?>_end_month.disabled = disable ;
  2781. document.filters_open.custom_field_<?php echo $t_field_id;?>_end_day.disabled = disable ;
  2782. } ;
  2783. function <?php echo $t_js_toggle_func;?>() {
  2784. switch (document.filters_open.custom_field_<?php echo $t_field_id;?>_control.selectedIndex) {
  2785. case <?php echo CUSTOM_FIELD_DATE_ANY;?>:
  2786. case <?php echo CUSTOM_FIELD_DATE_NONE;?>:
  2787. <?php echo $t_js_toggle_func . "_start";?>(true) ;
  2788. <?php echo $t_js_toggle_func . "_end";?>(true) ;
  2789. break ;
  2790. case <?php echo CUSTOM_FIELD_DATE_BETWEEN;?>:
  2791. <?php echo $t_js_toggle_func . "_start";?>(false) ;
  2792. <?php echo $t_js_toggle_func . "_end";?>(false) ;
  2793. break ;
  2794. default:
  2795. <?php echo $t_js_toggle_func . "_start";?>(false) ;
  2796. <?php echo $t_js_toggle_func . "_end";?>(true) ;
  2797. break ;
  2798. }
  2799. }
  2800. // -->
  2801. </script>
  2802. <?php
  2803. }
  2804. # end if dhtml_filters
  2805. $t_short_date_format = config_get( 'short_date_format' );
  2806. if( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] ) ) {
  2807. $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] = 0;
  2808. }
  2809. $t_start = date( $t_short_date_format, $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] );
  2810. if( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] ) ) {
  2811. $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] = 0;
  2812. }
  2813. $t_end = date( $t_short_date_format, $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] );
  2814. switch( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][0] ) {
  2815. case CUSTOM_FIELD_DATE_ANY:
  2816. $t_values .= lang_get( 'any' );
  2817. break;
  2818. case CUSTOM_FIELD_DATE_NONE:
  2819. $t_values .= lang_get( 'none' );
  2820. break;
  2821. case CUSTOM_FIELD_DATE_BETWEEN:
  2822. $t_values .= lang_get( 'between_date' ) . '<br />';
  2823. $t_values .= $t_start . '<br />' . $t_end;
  2824. break;
  2825. case CUSTOM_FIELD_DATE_ONORBEFORE:
  2826. $t_values .= lang_get( 'on_or_before_date' ) . '<br />';
  2827. $t_values .= $t_end;
  2828. break;
  2829. case CUSTOM_FIELD_DATE_BEFORE:
  2830. $t_values .= lang_get( 'before_date' ) . '<br />';
  2831. $t_values .= $t_end;
  2832. break;
  2833. case CUSTOM_FIELD_DATE_ON:
  2834. $t_values .= lang_get( 'on_date' ) . '<br />';
  2835. $t_values .= $t_start;
  2836. break;
  2837. case CUSTOM_FIELD_DATE_AFTER:
  2838. $t_values .= lang_get( 'after_date' ) . '<br />';
  2839. $t_values .= $t_start;
  2840. break;
  2841. case CUSTOM_FIELD_DATE_ONORAFTER:
  2842. $t_values .= lang_get( 'on_or_after_date' ) . '<br />';
  2843. $t_values .= $t_start;
  2844. break;
  2845. }
  2846. } else {
  2847. $t_first_flag = true;
  2848. foreach( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]] as $t_current ) {
  2849. $t_current = stripslashes( $t_current );
  2850. $t_this_string = '';
  2851. if( filter_field_is_any( $t_current ) ) {
  2852. $t_any_found = true;
  2853. } else if( filter_field_is_none( $t_current ) ) {
  2854. $t_this_string = lang_get( 'none' );
  2855. } else {
  2856. $t_this_string = $t_current;
  2857. }
  2858. if( $t_first_flag != true ) {
  2859. $t_output = $t_output . '<br />';
  2860. } else {
  2861. $t_first_flag = false;
  2862. }
  2863. $t_output = $t_output . string_display_line( $t_this_string );
  2864. $t_values .= '<input type="hidden" name="custom_field_' . $t_accessible_custom_fields_ids[$i] . '[]" value="' . string_attribute( $t_current ) . '" />';
  2865. }
  2866. }
  2867. if( true == $t_any_found ) {
  2868. $t_values .= lang_get( 'any' );
  2869. } else {
  2870. $t_values .= $t_output;
  2871. }
  2872. }
  2873. $t_values .= ' </td>';
  2874. $t_col_idx++;
  2875. if( $t_col_idx == $t_per_row ) {
  2876. if( $t_filter_cols > $t_per_row ) {
  2877. $t_fields .= '<td colspan="' . ( $t_filter_cols - $t_per_row ) . '">&#160;</td> ';
  2878. $t_values .= '<td colspan="' . ( $t_filter_cols - $t_per_row ) . '">&#160;</td> ';
  2879. }
  2880. $t_fields .= '</tr>' . "\n";
  2881. $t_values .= '</tr>' . "\n";
  2882. echo $t_fields;
  2883. echo $t_values;
  2884. $t_col_idx = 0;
  2885. $t_row_idx++;
  2886. }
  2887. }
  2888. if( $t_col_idx > 0 ) {
  2889. if( $t_col_idx < $t_per_row ) {
  2890. $t_fields .= '<td colspan="' . ( $t_per_row - $t_col_idx ) . '">&#160;</td> ';
  2891. $t_values .= '<td colspan="' . ( $t_per_row - $t_col_idx ) . '">&#160;</td> ';
  2892. }
  2893. if( $t_filter_cols > $t_per_row ) {
  2894. $t_fields .= '<td colspan="' . ( $t_filter_cols - $t_per_row ) . '">&#160;</td> ';
  2895. $t_values .= '<td colspan="' . ( $t_filter_cols - $t_per_row ) . '">&#160;</td> ';
  2896. }
  2897. $t_fields .= '</tr>' . "\n";
  2898. $t_values .= '</tr>' . "\n";
  2899. echo $t_fields;
  2900. echo $t_values;
  2901. }
  2902. }
  2903. }
  2904. ?>
  2905. <tr class="row-1">
  2906. <td class="small-caption category2" valign="top">
  2907. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_NOTE_USER_ID;?>" id="note_user_id_filter"><?php echo lang_get( 'note_user_id' )?>:</a>
  2908. </td>
  2909. <td class="small-caption" valign="top" id="note_user_id_filter_target">
  2910. <?php
  2911. $t_output = '';
  2912. $t_any_found = false;
  2913. if( count( $t_filter[FILTER_PROPERTY_NOTE_USER_ID] ) == 0 ) {
  2914. echo lang_get( 'any' );
  2915. } else {
  2916. $t_first_flag = true;
  2917. foreach( $t_filter[FILTER_PROPERTY_NOTE_USER_ID] as $t_current ) {
  2918. echo '<input type="hidden" name="', FILTER_PROPERTY_NOTE_USER_ID, '[]" value="', string_attribute( $t_current ), '" />';
  2919. $t_this_name = '';
  2920. if( filter_field_is_none( $t_current ) ) {
  2921. $t_this_name = lang_get( 'none' );
  2922. } else if( filter_field_is_any( $t_current ) ) {
  2923. $t_any_found = true;
  2924. } else if( filter_field_is_myself( $t_current ) ) {
  2925. if( access_has_project_level( config_get( 'handle_bug_threshold' ) ) ) {
  2926. $t_this_name = '[' . lang_get( 'myself' ) . ']';
  2927. } else {
  2928. $t_any_found = true;
  2929. }
  2930. } else {
  2931. $t_this_name = user_get_name( $t_current );
  2932. }
  2933. if( $t_first_flag != true ) {
  2934. $t_output = $t_output . '<br />';
  2935. } else {
  2936. $t_first_flag = false;
  2937. }
  2938. $t_output = $t_output . string_display_line( $t_this_name );
  2939. }
  2940. if( true == $t_any_found ) {
  2941. echo lang_get( 'any' );
  2942. } else {
  2943. $t_output;
  2944. }
  2945. }
  2946. ?>
  2947. </td>
  2948. <td class="small-caption" valign="top">
  2949. <a href="<?php echo $t_filters_url . 'show_sort';?>" id="show_sort_filter"><?php echo lang_get( 'sort' )?>:</a>
  2950. </td>
  2951. <td class="small-caption" valign="top" id="show_sort_filter_target">
  2952. <?php
  2953. $t_sort_fields = explode( ',', $t_filter[FILTER_PROPERTY_SORT_FIELD_NAME] );
  2954. $t_dir_fields = explode( ',', $t_filter[FILTER_PROPERTY_SORT_DIRECTION] );
  2955. for( $i = 0;$i < 2;$i++ ) {
  2956. if( isset( $t_sort_fields[$i] ) ) {
  2957. if( 0 < $i ) {
  2958. echo ', ';
  2959. }
  2960. $t_sort = $t_sort_fields[$i];
  2961. if( strpos( $t_sort, 'custom_' ) === 0 ) {
  2962. $t_field_name = string_display( lang_get_defaulted( utf8_substr( $t_sort, utf8_strlen( 'custom_' ) ) ) );
  2963. } else {
  2964. $t_field_name = string_get_field_name( $t_sort );
  2965. }
  2966. echo $t_field_name . ' ' . lang_get( 'bugnote_order_' . utf8_strtolower( $t_dir_fields[$i] ) );
  2967. echo '<input type="hidden" name="', FILTER_PROPERTY_SORT_FIELD_NAME, '_', $i, '" value="', string_attribute( $t_sort_fields[$i] ), '" />';
  2968. echo '<input type="hidden" name="', FILTER_PROPERTY_SORT_DIRECTION, '_', $i, '" value="', string_attribute( $t_dir_fields[$i] ), '" />';
  2969. }
  2970. }
  2971. ?>
  2972. </td>
  2973. <?php
  2974. if( 'advanced' == $t_view_type ) {
  2975. ?>
  2976. <td class="small-caption" valign="top" colspan="2">
  2977. <a href="<?php echo $t_filters_url . FILTER_PROPERTY_PROJECT_ID;?>" id="project_id_filter"><?php echo lang_get( 'email_project' )?>:</a>
  2978. </td>
  2979. <td class="small-caption" valign="top" id="project_id_filter_target">
  2980. <?php
  2981. $t_output = '';
  2982. if( !is_array( $t_filter[FILTER_PROPERTY_PROJECT_ID] ) ) {
  2983. $t_filter[FILTER_PROPERTY_PROJECT_ID] = Array(
  2984. $t_filter[FILTER_PROPERTY_PROJECT_ID],
  2985. );
  2986. }
  2987. if( count( $t_filter[FILTER_PROPERTY_PROJECT_ID] ) == 0 ) {
  2988. echo lang_get( 'current' );
  2989. } else {
  2990. $t_first_flag = true;
  2991. foreach( $t_filter[FILTER_PROPERTY_PROJECT_ID] as $t_current ) {
  2992. echo '<input type="hidden" name="', FILTER_PROPERTY_PROJECT_ID, '[]" value="', string_attribute( $t_current ), '" />';
  2993. $t_this_name = '';
  2994. if( META_FILTER_CURRENT == $t_current ) {
  2995. $t_this_name = lang_get( 'current' );
  2996. } else {
  2997. $t_this_name = project_get_name( $t_current, false );
  2998. }
  2999. if( $t_first_flag != true ) {
  3000. $t_output = $t_output . '<br />';
  3001. } else {
  3002. $t_first_flag = false;
  3003. }
  3004. $t_output = $t_output . string_display_line( $t_this_name );
  3005. }
  3006. echo $t_output;
  3007. }
  3008. ?>
  3009. </td>
  3010. <?php
  3011. if( $t_filter_cols > 6 ) {
  3012. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 5 ) . '">&#160;</td>';
  3013. }
  3014. } else {
  3015. if( $t_filter_cols > 3 ) {
  3016. echo '<td class="small-caption" valign="top" colspan="' . ( $t_filter_cols - 2 ) . '">&#160;</td>';
  3017. }
  3018. }
  3019. ?>
  3020. </tr>
  3021. <?php
  3022. }
  3023. // expanded
  3024. ?>
  3025. <tr>
  3026. <td colspan="2">
  3027. <?php
  3028. collapse_icon( 'filter' );
  3029. echo lang_get( 'search' ) . '&#160;';
  3030. echo '<input type="text" size="16" name="', FILTER_PROPERTY_FREE_TEXT, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_FREE_TEXT] ), '" />';
  3031. ?>
  3032. <input type="submit" name="filter" class="button-small" value="<?php echo lang_get( 'filter_button' )?>" />
  3033. </td>
  3034. </form>
  3035. <td class="center" colspan="<?php echo( $t_filter_cols - 6 )?>"> <!-- use this label for padding -->
  3036. <?php
  3037. if( ON == config_get( 'dhtml_filters' ) ) {
  3038. $f_switch_view_link = 'view_all_set.php?type=6&view_type=';
  3039. } else {
  3040. $f_switch_view_link = 'view_filters_page.php?view_type=';
  3041. }
  3042. $t_view_filters = config_get( 'view_filters' );
  3043. if(( SIMPLE_ONLY != $t_view_filters ) && ( ADVANCED_ONLY != $t_view_filters ) ) {
  3044. if( 'advanced' == $t_view_type ) {
  3045. print_bracket_link( $f_switch_view_link . 'simple', lang_get( 'simple_filters' ) );
  3046. } else {
  3047. print_bracket_link( $f_switch_view_link . 'advanced', lang_get( 'advanced_filters' ) );
  3048. }
  3049. }
  3050. if( access_has_project_level( config_get( 'create_permalink_threshold' ) ) ) {
  3051. print_bracket_link( 'permalink_page.php?url=' . urlencode( filter_get_url( $t_filter ) ), lang_get( 'create_filter_link' ),
  3052. /* new window = */
  3053. true );
  3054. }
  3055. ?>
  3056. </td>
  3057. <td class="right" colspan="4">
  3058. <?php
  3059. $t_stored_queries_arr = array();
  3060. $t_stored_queries_arr = filter_db_get_available_queries();
  3061. if( count( $t_stored_queries_arr ) > 0 ) {
  3062. ?>
  3063. <form method="get" name="list_queries<?php echo $t_form_name_suffix;?>" action="view_all_set.php">
  3064. <?php # CSRF protection not required here - form does not result in modifications ?>
  3065. <input type="hidden" name="type" value="3" />
  3066. <?php
  3067. if( ON == config_get( 'use_javascript' ) ) {
  3068. echo "<select name=\"source_query_id\" onchange=\"document.forms.list_queries$t_form_name_suffix.submit();\">";
  3069. } else {
  3070. echo '<select name="source_query_id">';
  3071. }
  3072. ?>
  3073. <option value="-1"><?php echo '[' . lang_get( 'reset_query' ) . ']'?></option>
  3074. <option value="-1"></option>
  3075. <?php
  3076. foreach( $t_stored_queries_arr as $t_query_id => $t_query_name ) {
  3077. echo '<option value="' . string_attribute( $t_query_id ) . '">' . string_display_line( $t_query_name ) . '</option>';
  3078. }
  3079. ?>
  3080. </select>
  3081. <input type="submit" name="switch_to_query_button" class="button-small" value="<?php echo lang_get( 'use_query' )?>" />
  3082. </form>
  3083. <form method="post" name="open_queries" action="query_view_page.php">
  3084. <?php # CSRF protection not required here - form does not result in modifications ?>
  3085. <input type="submit" name="switch_to_query_button" class="button-small" value="<?php echo lang_get( 'open_queries' )?>" />
  3086. </form>
  3087. <?php
  3088. } else {
  3089. ?>
  3090. <form method="get" name="reset_query" action="view_all_set.php">
  3091. <?php # CSRF protection not required here - form does not result in modifications ?>
  3092. <input type="hidden" name="type" value="3" />
  3093. <input type="hidden" name="source_query_id" value="-1" />
  3094. <input type="submit" name="reset_query_button" class="button-small" value="<?php echo lang_get( 'reset_query' )?>" />
  3095. </form>
  3096. <?php
  3097. }
  3098. if( access_has_project_level( config_get( 'stored_query_create_threshold' ) ) ) {
  3099. ?>
  3100. <form method="post" name="save_query" action="query_store_page.php">
  3101. <?php # CSRF protection not required here - form does not result in modifications ?>
  3102. <input type="submit" name="save_query_button" class="button-small" value="<?php echo lang_get( 'save_query' )?>" />
  3103. </form>
  3104. <?php
  3105. }
  3106. ?>
  3107. </td>
  3108. </tr>
  3109. </table>
  3110. <?php
  3111. }
  3112. /**
  3113. * @internal The following functions each print out filter field inputs.
  3114. * They are derived from view_filters_page.php
  3115. * The functions follow a strict naming convention:
  3116. *
  3117. * print_filter_[filter_name]
  3118. *
  3119. * Where [filter_name] is the same as the "name" of the form element for
  3120. * that filter. This naming convention is depended upon by the controller
  3121. * at the end of the script.
  3122. *
  3123. * @todo print functions should be abstracted. Many of these functions
  3124. * are virtually identical except for the property name.
  3125. * Perhaps this code could be made simpler by refactoring into a
  3126. * class so as to avoid all those calls to global(which are pretty ugly)
  3127. * These functions could also be shared by view_filters_page.php
  3128. */
  3129. /**
  3130. * Print the reporter field
  3131. */
  3132. function print_filter_reporter_id() {
  3133. global $t_select_modifier, $t_filter;
  3134. ?>
  3135. <select <?php echo $t_select_modifier;?> name="reporter_id[]">
  3136. <?php
  3137. # if current user is a reporter, and limited reports set to ON, only display that name
  3138. # @@@ thraxisp - access_has_project_level checks greater than or equal to,
  3139. # this assumed that there aren't any holes above REPORTER where the limit would apply
  3140. #
  3141. if(( ON === config_get( 'limit_reporters' ) ) && ( !access_has_project_level( REPORTER + 1 ) ) ) {
  3142. $t_id = auth_get_current_user_id();
  3143. $t_username = user_get_field( $t_id, 'username' );
  3144. $t_realname = user_get_field( $t_id, 'realname' );
  3145. $t_display_name = string_attribute( $t_username );
  3146. if(( isset( $t_realname ) ) && ( $t_realname > '' ) && ( ON == config_get( 'show_realname' ) ) ) {
  3147. $t_display_name = string_attribute( $t_realname );
  3148. }
  3149. echo '<option value="' . $t_id . '" selected="selected">' . $t_display_name . '</option>';
  3150. } else {
  3151. ?>
  3152. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_REPORTER_ID], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3153. <?php
  3154. if( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) {
  3155. echo '<option value="' . META_FILTER_MYSELF . '" ';
  3156. check_selected( $t_filter[FILTER_PROPERTY_REPORTER_ID], META_FILTER_MYSELF );
  3157. echo '>[' . lang_get( 'myself' ) . ']</option>';
  3158. }
  3159. print_reporter_option_list( $t_filter[FILTER_PROPERTY_REPORTER_ID] );
  3160. }?>
  3161. </select>
  3162. <?php
  3163. }
  3164. /**
  3165. * Print the user monitor field
  3166. */
  3167. function print_filter_user_monitor() {
  3168. global $t_select_modifier, $t_filter;
  3169. ?>
  3170. <!-- Monitored by -->
  3171. <select <?php echo $t_select_modifier;?> name="user_monitor[]">
  3172. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_MONITOR_USER_ID], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3173. <?php
  3174. if( access_has_project_level( config_get( 'monitor_bug_threshold' ) ) ) {
  3175. echo '<option value="' . META_FILTER_MYSELF . '" ';
  3176. check_selected( $t_filter[FILTER_PROPERTY_MONITOR_USER_ID], META_FILTER_MYSELF );
  3177. echo '>[' . lang_get( 'myself' ) . ']</option>';
  3178. }
  3179. $t_threshold = config_get( 'show_monitor_list_threshold' );
  3180. $t_has_project_level = access_has_project_level( $t_threshold );
  3181. if( $t_has_project_level ) {
  3182. print_reporter_option_list( $t_filter[FILTER_PROPERTY_MONITOR_USER_ID] );
  3183. }
  3184. ?>
  3185. </select>
  3186. <?php
  3187. }
  3188. /**
  3189. * print the handler field
  3190. */
  3191. function print_filter_handler_id() {
  3192. global $t_select_modifier, $t_filter, $f_view_type;
  3193. ?>
  3194. <!-- Handler -->
  3195. <select <?php echo $t_select_modifier;?> name="handler_id[]">
  3196. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_HANDLER_ID], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3197. <?php if( access_has_project_level( config_get( 'view_handler_threshold' ) ) ) {?>
  3198. <option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_HANDLER_ID], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
  3199. <?php
  3200. if( access_has_project_level( config_get( 'handle_bug_threshold' ) ) ) {
  3201. echo '<option value="' . META_FILTER_MYSELF . '" ';
  3202. check_selected( $t_filter[FILTER_PROPERTY_HANDLER_ID], META_FILTER_MYSELF );
  3203. echo '>[' . lang_get( 'myself' ) . ']</option>';
  3204. }
  3205. print_assign_to_option_list( $t_filter[FILTER_PROPERTY_HANDLER_ID] );
  3206. }?>
  3207. </select>
  3208. <?php
  3209. }
  3210. /**
  3211. * print the category field
  3212. */
  3213. function print_filter_show_category() {
  3214. global $t_select_modifier, $t_filter;
  3215. ?>
  3216. <!-- Category -->
  3217. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_CATEGORY;?>[]">
  3218. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_CATEGORY], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3219. <?php print_category_filter_option_list( $t_filter[FILTER_PROPERTY_CATEGORY] )?>
  3220. </select>
  3221. <?php
  3222. }
  3223. /**
  3224. * print the platform field
  3225. */
  3226. function print_filter_platform() {
  3227. global $t_select_modifier, $t_filter;
  3228. ?>
  3229. <!-- Platform -->
  3230. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_PLATFORM;?>[]">
  3231. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PLATFORM], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3232. <?php
  3233. log_event( LOG_FILTERING, 'Platform = ' . var_export( $t_filter[FILTER_PROPERTY_PLATFORM], true ) );
  3234. print_platform_option_list( $t_filter[FILTER_PROPERTY_PLATFORM] );
  3235. ?>
  3236. </select>
  3237. <?php
  3238. }
  3239. /**
  3240. * print the os field
  3241. */
  3242. function print_filter_os() {
  3243. global $t_select_modifier, $t_filter;
  3244. ?>
  3245. <!-- OS -->
  3246. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_OS;?>[]">
  3247. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_OS], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3248. <?php print_os_option_list( $t_filter[FILTER_PROPERTY_OS] )?>
  3249. </select>
  3250. <?php
  3251. }
  3252. /**
  3253. * print the os build field
  3254. */
  3255. function print_filter_os_build() {
  3256. global $t_select_modifier, $t_filter;
  3257. ?>
  3258. <!-- OS Build -->
  3259. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_OS_BUILD;?>[]">
  3260. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_OS_BUILD], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3261. <?php print_os_build_option_list( $t_filter[FILTER_PROPERTY_OS_BUILD] )?>
  3262. </select>
  3263. <?php
  3264. }
  3265. /**
  3266. * print the severity field
  3267. */
  3268. function print_filter_show_severity() {
  3269. global $t_select_modifier, $t_filter;
  3270. ?><!-- Severity -->
  3271. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_SEVERITY_ID;?>[]">
  3272. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_SEVERITY_ID], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3273. <?php print_enum_string_option_list( 'severity', $t_filter[FILTER_PROPERTY_SEVERITY_ID] )?>
  3274. </select>
  3275. <?php
  3276. }
  3277. /**
  3278. * print resolution field
  3279. */
  3280. function print_filter_show_resolution() {
  3281. global $t_select_modifier, $t_filter;
  3282. ?><!-- Resolution -->
  3283. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_RESOLUTION_ID;?>[]">
  3284. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_RESOLUTION_ID], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3285. <?php print_enum_string_option_list( 'resolution', $t_filter[FILTER_PROPERTY_RESOLUTION_ID] )?>
  3286. </select>
  3287. <?php
  3288. }
  3289. /**
  3290. * print status field
  3291. */
  3292. function print_filter_show_status() {
  3293. global $t_select_modifier, $t_filter;
  3294. ?> <!-- Status -->
  3295. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_STATUS_ID;?>[]">
  3296. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_STATUS_ID], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3297. <?php print_enum_string_option_list( 'status', $t_filter[FILTER_PROPERTY_STATUS_ID] )?>
  3298. </select>
  3299. <?php
  3300. }
  3301. /**
  3302. * print hide status field
  3303. */
  3304. function print_filter_hide_status() {
  3305. global $t_select_modifier, $t_filter;
  3306. ?><!-- Hide Status -->
  3307. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_HIDE_STATUS_ID;?>[]">
  3308. <option value="<?php echo META_FILTER_NONE?>">[<?php echo lang_get( 'none' )?>]</option>
  3309. <?php print_enum_string_option_list( 'status', $t_filter[FILTER_PROPERTY_HIDE_STATUS_ID] )?>
  3310. </select>
  3311. <?php
  3312. }
  3313. /**
  3314. * print build field
  3315. */
  3316. function print_filter_show_build() {
  3317. global $t_select_modifier, $t_filter;
  3318. ?><!-- Build -->
  3319. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_PRODUCT_BUILD;?>[]">
  3320. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PRODUCT_BUILD], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3321. <option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PRODUCT_BUILD], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
  3322. <?php print_build_option_list( $t_filter[FILTER_PROPERTY_PRODUCT_BUILD] )?>
  3323. </select>
  3324. <?php
  3325. }
  3326. /**
  3327. * print version field
  3328. */
  3329. function print_filter_show_version() {
  3330. global $t_select_modifier, $t_filter;
  3331. ?><!-- Version -->
  3332. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_PRODUCT_VERSION;?>[]">
  3333. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3334. <option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
  3335. <?php print_version_option_list( $t_filter[FILTER_PROPERTY_PRODUCT_VERSION], /* projectId */ null, /* released */ VERSION_ALL, /* leadingBlank */ false, /* withSubs */ true )?>
  3336. </select>
  3337. <?php
  3338. }
  3339. /**
  3340. * print fixed in version field
  3341. */
  3342. function print_filter_show_fixed_in_version() {
  3343. global $t_select_modifier, $t_filter;
  3344. ?><!-- Fixed in Version -->
  3345. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_FIXED_IN_VERSION;?>[]">
  3346. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3347. <option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
  3348. <?php print_version_option_list( $t_filter[FILTER_PROPERTY_FIXED_IN_VERSION], /* projectId */ null, /* released */ VERSION_ALL, /* leadingBlank */ false, /* withSubs */ true )?>
  3349. </select>
  3350. <?php
  3351. }
  3352. /**
  3353. * print target version field
  3354. */
  3355. function print_filter_show_target_version() {
  3356. global $t_select_modifier, $t_filter;
  3357. ?><!-- Fixed in Version -->
  3358. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_TARGET_VERSION;?>[]">
  3359. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_TARGET_VERSION], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3360. <option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_TARGET_VERSION], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
  3361. <?php print_version_option_list( $t_filter[FILTER_PROPERTY_TARGET_VERSION], /* projectId */ null, /* released */ VERSION_ALL, /* leadingBlank */ false, /* withSubs */ true )?>
  3362. </select>
  3363. <?php
  3364. }
  3365. /**
  3366. * print priority field
  3367. */
  3368. function print_filter_show_priority() {
  3369. global $t_select_modifier, $t_filter;
  3370. ?><!-- Priority -->
  3371. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_PRIORITY_ID;?>[]">
  3372. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PRIORITY_ID], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3373. <?php print_enum_string_option_list( 'priority', $t_filter[FILTER_PROPERTY_PRIORITY_ID] )?>
  3374. </select>
  3375. <?php
  3376. }
  3377. /**
  3378. * print profile field
  3379. */
  3380. function print_filter_show_profile() {
  3381. global $t_select_modifier, $t_filter;
  3382. ?><!-- Profile -->
  3383. <select <?php echo $t_select_modifier;?> name="show_profile[]">
  3384. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter['show_profile'], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3385. <?php print_profile_option_list_for_project( helper_get_current_project(), $t_filter['show_profile'] );?>
  3386. </select>
  3387. <?php
  3388. }
  3389. /**
  3390. * print issues per page field
  3391. */
  3392. function print_filter_per_page() {
  3393. global $t_filter;
  3394. ?><!-- Number of bugs per page -->
  3395. <input type="text" name="<?php echo FILTER_PROPERTY_ISSUES_PER_PAGE;?>" size="3" maxlength="7" value="<?php echo $t_filter[FILTER_PROPERTY_ISSUES_PER_PAGE]?>" />
  3396. <?php
  3397. }
  3398. /**
  3399. * print view state field
  3400. */
  3401. function print_filter_view_state() {
  3402. global $t_select_modifier, $t_filter;
  3403. ?><!-- View Status -->
  3404. <select name="<?php echo FILTER_PROPERTY_VIEW_STATE_ID;?>">
  3405. <?php
  3406. echo '<option value="' . META_FILTER_ANY . '" ';
  3407. check_selected( $t_filter[FILTER_PROPERTY_VIEW_STATE_ID], META_FILTER_ANY );
  3408. echo '>[' . lang_get( 'any' ) . ']</option>';
  3409. echo '<option value="' . VS_PUBLIC . '" ';
  3410. check_selected( $t_filter[FILTER_PROPERTY_VIEW_STATE_ID], VS_PUBLIC );
  3411. echo '>' . lang_get( 'public' ) . '</option>';
  3412. echo '<option value="' . VS_PRIVATE . '" ';
  3413. check_selected( $t_filter[FILTER_PROPERTY_VIEW_STATE_ID], VS_PRIVATE );
  3414. echo '>' . lang_get( 'private' ) . '</option>';
  3415. ?>
  3416. </select>
  3417. <?php
  3418. }
  3419. /**
  3420. * print sticky issues field
  3421. */
  3422. function print_filter_sticky_issues() {
  3423. global $t_filter;
  3424. ?><!-- Show or hide sticky bugs -->
  3425. <input type="checkbox" name="<?php echo FILTER_PROPERTY_SHOW_STICKY_ISSUES;?>" <?php check_checked( gpc_string_to_bool( $t_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ), true );?> />
  3426. <?php
  3427. }
  3428. /**
  3429. * print highlight changed field
  3430. */
  3431. function print_filter_highlight_changed() {
  3432. global $t_filter;
  3433. ?><!-- Highlight changed bugs -->
  3434. <input type="text" name="<?php echo FILTER_PROPERTY_HIGHLIGHT_CHANGED;?>" size="3" maxlength="7" value="<?php echo $t_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED]?>" />
  3435. <?php
  3436. }
  3437. /**
  3438. * print filter by date fields with javascript
  3439. * @todo Javascript should be removed and added dynamically
  3440. * via external script
  3441. */
  3442. function print_filter_do_filter_by_date( $p_hide_checkbox = false ) {
  3443. global $t_filter;
  3444. ?>
  3445. <table cellspacing="0" cellpadding="0">
  3446. <?php if( !$p_hide_checkbox ) {
  3447. ?>
  3448. <tr><td colspan="2">
  3449. <input type="checkbox" name="<?php echo FILTER_PROPERTY_FILTER_BY_DATE;?>" <?php
  3450. check_checked( $t_filter[FILTER_PROPERTY_FILTER_BY_DATE], 'on' );
  3451. if( ON == config_get( 'use_javascript' ) ) {
  3452. print "onclick=\"SwitchDateFields();\"";
  3453. }?> />
  3454. <?php echo lang_get( 'use_date_filters' )?>
  3455. </td></tr>
  3456. <?php
  3457. }
  3458. $t_menu_disabled = ( 'on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) ? '' : ' disabled ';
  3459. ?>
  3460. <!-- Start date -->
  3461. <tr>
  3462. <td>
  3463. <?php echo lang_get( 'start_date' )?>:
  3464. </td>
  3465. <td nowrap="nowrap">
  3466. <?php
  3467. $t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
  3468. foreach( $t_chars as $t_char ) {
  3469. if( strcasecmp( $t_char, "M" ) == 0 ) {
  3470. echo '<select name="', FILTER_PROPERTY_START_MONTH, '"', $t_menu_disabled, '>';
  3471. print_month_option_list( $t_filter[FILTER_PROPERTY_START_MONTH] );
  3472. print "</select>\n";
  3473. }
  3474. if( strcasecmp( $t_char, "D" ) == 0 ) {
  3475. echo '<select name="', FILTER_PROPERTY_START_DAY, '"', $t_menu_disabled, '>';
  3476. print_day_option_list( $t_filter[FILTER_PROPERTY_START_DAY] );
  3477. print "</select>\n";
  3478. }
  3479. if( strcasecmp( $t_char, "Y" ) == 0 ) {
  3480. echo '<select name="', FILTER_PROPERTY_START_YEAR, '"', $t_menu_disabled, '>';
  3481. print_year_option_list( $t_filter[FILTER_PROPERTY_START_YEAR] );
  3482. print "</select>\n";
  3483. }
  3484. }
  3485. ?>
  3486. </td>
  3487. </tr>
  3488. <!-- End date -->
  3489. <tr>
  3490. <td>
  3491. <?php echo lang_get( 'end_date' )?>:
  3492. </td>
  3493. <td>
  3494. <?php
  3495. $t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
  3496. foreach( $t_chars as $t_char ) {
  3497. if( strcasecmp( $t_char, "M" ) == 0 ) {
  3498. echo '<select name="', FILTER_PROPERTY_END_MONTH, '"', $t_menu_disabled, '>';
  3499. print_month_option_list( $t_filter[FILTER_PROPERTY_END_MONTH] );
  3500. print "</select>\n";
  3501. }
  3502. if( strcasecmp( $t_char, "D" ) == 0 ) {
  3503. echo '<select name="', FILTER_PROPERTY_END_DAY, '"', $t_menu_disabled, '>';
  3504. print_day_option_list( $t_filter[FILTER_PROPERTY_END_DAY] );
  3505. print "</select>\n";
  3506. }
  3507. if( strcasecmp( $t_char, "Y" ) == 0 ) {
  3508. echo '<select name="', FILTER_PROPERTY_END_YEAR, '"', $t_menu_disabled, '>';
  3509. print_year_option_list( $t_filter[FILTER_PROPERTY_END_YEAR] );
  3510. print "</select>\n";
  3511. }
  3512. }
  3513. ?>
  3514. </td>
  3515. </tr>
  3516. </table>
  3517. <?php
  3518. }
  3519. /**
  3520. * print relationship fields
  3521. */
  3522. function print_filter_relationship_type() {
  3523. global $t_filter;
  3524. $c_reltype_value = $t_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE];
  3525. if( !$c_reltype_value ) {
  3526. $c_reltype_value = -1;
  3527. }
  3528. relationship_list_box( $c_reltype_value, "relationship_type", true );
  3529. echo '<input type="text" name="', FILTER_PROPERTY_RELATIONSHIP_BUG, '" size="5" maxlength="10" value="', $t_filter[FILTER_PROPERTY_RELATIONSHIP_BUG], '" />';
  3530. }
  3531. /**
  3532. * print tag fields
  3533. */
  3534. function print_filter_tag_string() {
  3535. if ( !access_has_global_level( config_get( 'tag_view_threshold' ) ) ) {
  3536. return;
  3537. }
  3538. global $t_filter;
  3539. $t_tag_string = $t_filter[FILTER_PROPERTY_TAG_STRING];
  3540. if( $t_filter[FILTER_PROPERTY_TAG_SELECT] != 0 && tag_exists( $t_filter[FILTER_PROPERTY_TAG_SELECT] ) ) {
  3541. $t_tag_string .= ( is_blank( $t_tag_string ) ? '' : config_get( 'tag_separator' ) );
  3542. $t_tag_string .= tag_get_field( $t_filter[FILTER_PROPERTY_TAG_SELECT], 'name' );
  3543. }
  3544. ?>
  3545. <input type="hidden" id="tag_separator" value="<?php echo config_get( 'tag_separator' )?>" />
  3546. <input type="text" name="<?php echo FILTER_PROPERTY_TAG_STRING;?>" id="<?php echo FILTER_PROPERTY_TAG_STRING;?>" size="40" value="<?php echo string_attribute( $t_tag_string )?>" />
  3547. <select <?php echo helper_get_tab_index()?> name="<?php echo FILTER_PROPERTY_TAG_SELECT;?>" id="<?php echo FILTER_PROPERTY_TAG_SELECT;?>">
  3548. <?php print_tag_option_list();?>
  3549. </select>
  3550. <?php
  3551. }
  3552. /**
  3553. * print note reporter field
  3554. */
  3555. function print_filter_note_user_id() {
  3556. global $t_select_modifier, $t_filter, $f_view_type;
  3557. ?>
  3558. <!-- BUGNOTE REPORTER -->
  3559. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_NOTE_USER_ID;?>[]">
  3560. <option value="<?php echo META_FILTER_ANY?>" <?php check_selected( $t_filter[FILTER_PROPERTY_NOTE_USER_ID], META_FILTER_ANY );?>>[<?php echo lang_get( 'any' )?>]</option>
  3561. <?php if( access_has_project_level( config_get( 'view_handler_threshold' ) ) ) {?>
  3562. <option value="<?php echo META_FILTER_NONE?>" <?php check_selected( $t_filter[FILTER_PROPERTY_NOTE_USER_ID], META_FILTER_NONE );?>>[<?php echo lang_get( 'none' )?>]</option>
  3563. <?php
  3564. if( access_has_project_level( config_get( 'handle_bug_threshold' ) ) ) {
  3565. echo '<option value="' . META_FILTER_MYSELF . '" ';
  3566. check_selected( $t_filter[FILTER_PROPERTY_NOTE_USER_ID], META_FILTER_MYSELF );
  3567. echo '>[' . lang_get( 'myself' ) . ']</option>';
  3568. }
  3569. print_assign_to_option_list( $t_filter[FILTER_PROPERTY_NOTE_USER_ID] );
  3570. }
  3571. ?>
  3572. </select>
  3573. <?php
  3574. }
  3575. /**
  3576. * Print plugin filter fields as defined by MantisFilter objects.
  3577. * @param string Field name
  3578. * @param object Filter object
  3579. */
  3580. function print_filter_plugin_field( $p_field_name, $p_filter_object ) {
  3581. global $t_select_modifier, $t_filter, $f_view_type;
  3582. $t_size = (int)$p_filter_object->size;
  3583. switch( $p_filter_object->type ) {
  3584. case FILTER_TYPE_STRING:
  3585. echo '<input name="', string_attribute( $p_field_name ), '"',
  3586. ( $t_size > 0 ? " size=\"$t_size\"" : '' ), ' value="',
  3587. string_attribute( $t_filter[ $p_field_name ] ), '"/>';
  3588. break;
  3589. case FILTER_TYPE_INT:
  3590. echo '<input name="', string_attribute( $p_field_name ), '"',
  3591. ( $t_size > 0 ? " size=\"$t_size\"" : '' ), ' value="',
  3592. (int) $t_filter[ $p_field_name ], '"/>';
  3593. break;
  3594. case FILTER_TYPE_BOOLEAN:
  3595. echo '<input name="', string_attribute( $p_field_name ), '" type="checkbox"',
  3596. ( $t_size > 0 ? " size=\"$t_size\"" : '' ), check_checked( (bool) $t_filter[ $p_field_name ] ) , '"/>';
  3597. break;
  3598. case FILTER_TYPE_MULTI_STRING:
  3599. echo '<select ', $t_select_modifier, ( $t_size > 0 ? " size=\"$t_size\"" : '' ), ' name="',
  3600. string_attribute( $p_field_name ), '[]">', '<option value="', META_FILTER_ANY, '" ',
  3601. check_selected( $t_filter[ $p_field_name ], META_FILTER_ANY ), '>[', lang_get( 'any' ), ']</option>';
  3602. foreach( $p_filter_object->options() as $t_option_value => $t_option_name ) {
  3603. echo '<option value="', string_attribute( $t_option_value ), '" ',
  3604. check_selected( $t_filter[ $p_field_name ], $t_option_value ), '>',
  3605. string_display_line( $t_option_name ), '</option>';
  3606. }
  3607. echo '</select>';
  3608. break;
  3609. case FILTER_TYPE_MULTI_INT:
  3610. echo '<select ', $t_select_modifier, ( $t_size > 0 ? " size=\"$t_size\"" : '' ), ' name="',
  3611. string_attribute( $p_field_name ), '[]">', '<option value="', META_FILTER_ANY, '" ',
  3612. check_selected( $t_filter[ $p_field_name ], META_FILTER_ANY ), '>[', lang_get( 'any' ), ']</option>';
  3613. foreach( $p_filter_object->options() as $t_option_value => $t_option_name ) {
  3614. echo '<option value="', (int)$t_option_value, '" ',
  3615. check_selected( $t_filter[ $p_field_name ], (int)$t_option_value ), '>',
  3616. string_display_line( $t_option_name ), '</option>';
  3617. }
  3618. echo '</select>';
  3619. break;
  3620. }
  3621. }
  3622. /**
  3623. * print custom fields
  3624. * @param int $p_field_id
  3625. */
  3626. function print_filter_custom_field( $p_field_id ) {
  3627. global $t_filter, $t_accessible_custom_fields_names, $t_accessible_custom_fields_types, $t_accessible_custom_fields_values, $t_accessible_custom_fields_ids, $t_select_modifier;
  3628. $j = array_search( $p_field_id, $t_accessible_custom_fields_ids );
  3629. if( $j === null || $j === false ) {
  3630. # Note: Prior to PHP 4.2.0, array_search() returns NULL on failure instead of FALSE.
  3631. ?>
  3632. <span style="color:red;weight:bold;">
  3633. unknown custom filter (custom <?php $p_field_id;?>)
  3634. </span>
  3635. <?php
  3636. } else if( isset( $t_accessible_custom_fields_names[$j] ) ) {
  3637. if( $t_accessible_custom_fields_types[$j] == CUSTOM_FIELD_TYPE_DATE ) {
  3638. print_filter_custom_field_date( $j, $p_field_id );
  3639. } else {
  3640. echo '<select ' . $t_select_modifier . ' name="custom_field_' . $p_field_id . '[]">';
  3641. echo '<option value="' . META_FILTER_ANY . '" ';
  3642. check_selected( $t_filter['custom_fields'][$p_field_id], META_FILTER_ANY );
  3643. echo '>[' . lang_get( 'any' ) . ']</option>';
  3644. # don't show META_FILTER_NONE for enumerated types as it's not possible for them to be blank
  3645. if( !in_array( $t_accessible_custom_fields_types[$j], array( CUSTOM_FIELD_TYPE_ENUM, CUSTOM_FIELD_TYPE_LIST, CUSTOM_FIELD_TYPE_MULTILIST ) ) ) {
  3646. echo '<option value="' . META_FILTER_NONE . '" ';
  3647. check_selected( $t_filter['custom_fields'][$p_field_id], META_FILTER_NONE );
  3648. echo '>[' . lang_get( 'none' ) . ']</option>';
  3649. }
  3650. if( is_array( $t_accessible_custom_fields_values[$j] ) ) {
  3651. $t_max_length = config_get( 'max_dropdown_length' );
  3652. foreach( $t_accessible_custom_fields_values[$j] as $t_item ) {
  3653. if(( utf8_strtolower( $t_item ) !== META_FILTER_ANY ) && ( utf8_strtolower( $t_item ) !== META_FILTER_NONE ) ) {
  3654. echo '<option value="' . string_attribute( $t_item ) . '" ';
  3655. if( isset( $t_filter['custom_fields'][$p_field_id] ) ) {
  3656. check_selected( $t_filter['custom_fields'][$p_field_id], $t_item );
  3657. }
  3658. echo '>' . string_attribute( string_shorten( $t_item, $t_max_length ) ) . '</option>' . "\n";
  3659. }
  3660. }
  3661. }
  3662. echo '</select>';
  3663. }
  3664. }
  3665. }
  3666. /**
  3667. * print sort fields
  3668. */
  3669. function print_filter_show_sort() {
  3670. global $t_filter;
  3671. # get all of the displayed fields for sort, then drop ones that
  3672. # are not appropriate and translate the rest
  3673. $t_fields = helper_get_columns_to_view();
  3674. $t_n_fields = count( $t_fields );
  3675. $t_shown_fields[''] = '';
  3676. for( $i = 0;$i < $t_n_fields;$i++ ) {
  3677. if( !in_array( $t_fields[$i], array( 'selection', 'edit', 'bugnotes_count', 'attachment' ) ) ) {
  3678. if( strpos( $t_fields[$i], 'custom_' ) === 0 ) {
  3679. $t_field_name = string_display( lang_get_defaulted( utf8_substr( $t_fields[$i], utf8_strlen( 'custom_' ) ) ) );
  3680. } else {
  3681. $t_field_name = string_get_field_name( $t_fields[$i] );
  3682. }
  3683. $t_shown_fields[$t_fields[$i]] = $t_field_name;
  3684. }
  3685. }
  3686. $t_shown_dirs[''] = '';
  3687. $t_shown_dirs['ASC'] = lang_get( 'bugnote_order_asc' );
  3688. $t_shown_dirs['DESC'] = lang_get( 'bugnote_order_desc' );
  3689. # get default values from filter structure
  3690. $t_sort_fields = explode( ',', $t_filter[FILTER_PROPERTY_SORT_FIELD_NAME] );
  3691. $t_dir_fields = explode( ',', $t_filter[FILTER_PROPERTY_SORT_DIRECTION] );
  3692. if( !isset( $t_sort_fields[1] ) ) {
  3693. $t_sort_fields[1] = '';
  3694. $t_dir_fields[1] = '';
  3695. }
  3696. # if there are fields to display, show the dropdowns
  3697. if( count( $t_fields ) > 0 ) {
  3698. # display a primary and secondary sort fields
  3699. echo '<select name="', FILTER_PROPERTY_SORT_FIELD_NAME, '_0">';
  3700. foreach( $t_shown_fields as $key => $val ) {
  3701. echo '<option value="' . $key . '"';
  3702. check_selected( $key, $t_sort_fields[0] );
  3703. echo '>' . $val . '</option>';
  3704. }
  3705. echo '</select>';
  3706. echo '<select name="', FILTER_PROPERTY_SORT_DIRECTION, '_0">';
  3707. foreach( $t_shown_dirs as $key => $val ) {
  3708. echo '<option value="' . $key . '"';
  3709. check_selected( $key, $t_dir_fields[0] );
  3710. echo '>' . $val . '</option>';
  3711. }
  3712. echo '</select>';
  3713. echo ', ';
  3714. # for secondary sort
  3715. echo '<select name="', FILTER_PROPERTY_SORT_FIELD_NAME, '_1">';
  3716. foreach( $t_shown_fields as $key => $val ) {
  3717. echo '<option value="' . $key . '"';
  3718. check_selected( $key, $t_sort_fields[1] );
  3719. echo '>' . $val . '</option>';
  3720. }
  3721. echo '</select>';
  3722. echo '<select name="', FILTER_PROPERTY_SORT_DIRECTION, '_1">';
  3723. foreach( $t_shown_dirs as $key => $val ) {
  3724. echo '<option value="' . $key . '"';
  3725. check_selected( $key, $t_dir_fields[1] );
  3726. echo '>' . $val . '</option>';
  3727. }
  3728. echo '</select>';
  3729. } else {
  3730. echo lang_get_defaulted( 'last_updated' ) . lang_get( 'bugnote_order_desc' );
  3731. echo '<input type="hidden" name="', FILTER_PROPERTY_SORT_FIELD_NAME, '_1" value="last_updated" />';
  3732. echo '<input type="hidden" name="', FILTER_PROPERTY_SORT_DIRECTION, '_1" value="DESC" />';
  3733. }
  3734. }
  3735. /**
  3736. * print custom field date fields
  3737. * @param int $p_field_num
  3738. * @param int $p_field_id
  3739. */
  3740. function print_filter_custom_field_date( $p_field_num, $p_field_id ) {
  3741. global $t_filter, $t_accessible_custom_fields_names, $t_accessible_custom_fields_types, $t_accessible_custom_fields_values, $t_accessible_custom_fields_ids, $t_select_modifier;
  3742. $t_js_toggle_func = 'toggle_custom_date_field_' . $p_field_id . '_controls';
  3743. # Resort the values so there ordered numerically, they are sorted as strings otherwise which
  3744. # may be wrong for dates before early 2001.
  3745. if( is_array( $t_accessible_custom_fields_values[$p_field_num] ) ) {
  3746. array_multisort( $t_accessible_custom_fields_values[$p_field_num], SORT_NUMERIC, SORT_ASC );
  3747. }
  3748. if( isset( $t_accessible_custom_fields_values[$p_field_num][0] ) ) {
  3749. $t_sel_start_year = date( 'Y', $t_accessible_custom_fields_values[$p_field_num][0] );
  3750. }
  3751. $t_count = count( $t_accessible_custom_fields_values[$p_field_num] );
  3752. if( isset( $t_accessible_custom_fields_values[$p_field_num][$t_count - 1] ) ) {
  3753. $t_sel_end_year = date( 'Y', $t_accessible_custom_fields_values[$p_field_num][$t_count - 1] );
  3754. }
  3755. $t_start = date( 'U' );
  3756. # Default to today in filters..
  3757. $t_end = $t_start;
  3758. if( isset( $t_filter['custom_fields'][$p_field_id][1] ) ) {
  3759. $t_start_time = $t_filter['custom_fields'][$p_field_id][1];
  3760. } else {
  3761. $t_start_time = 0;
  3762. }
  3763. if( isset( $t_filter['custom_fields'][$p_field_id][2] ) ) {
  3764. $t_end_time = $t_filter['custom_fields'][$p_field_id][2];
  3765. } else {
  3766. $t_end_time = 0;
  3767. }
  3768. $t_start_disable = true;
  3769. $t_end_disable = true;
  3770. // if $t_filter['custom_fields'][$p_field_id][0] is not set (ie no filter), we will drop through the
  3771. // following switch and use the default values above, so no need to check if stuff is set or not.
  3772. switch( $t_filter['custom_fields'][$p_field_id][0] ) {
  3773. case CUSTOM_FIELD_DATE_ANY:
  3774. case CUSTOM_FIELD_DATE_NONE:
  3775. break;
  3776. case CUSTOM_FIELD_DATE_BETWEEN:
  3777. $t_start_disable = false;
  3778. $t_end_disable = false;
  3779. $t_start = $t_start_time;
  3780. $t_end = $t_end_time;
  3781. break;
  3782. case CUSTOM_FIELD_DATE_ONORBEFORE:
  3783. $t_start_disable = false;
  3784. $t_start = $t_end_time;
  3785. break;
  3786. case CUSTOM_FIELD_DATE_BEFORE:
  3787. $t_start_disable = false;
  3788. $t_start = $t_end_time;
  3789. break;
  3790. case CUSTOM_FIELD_DATE_ON:
  3791. $t_start_disable = false;
  3792. $t_start = $t_start_time;
  3793. break;
  3794. case CUSTOM_FIELD_DATE_AFTER:
  3795. $t_start_disable = false;
  3796. $t_start = $t_start_time;
  3797. break;
  3798. case CUSTOM_FIELD_DATE_ONORAFTER:
  3799. $t_start_disable = false;
  3800. $t_start = $t_start_time;
  3801. break;
  3802. }
  3803. echo "\n<table cellspacing=\"0\" cellpadding=\"0\"><tr><td>\n";
  3804. echo "<select size=\"1\" name=\"custom_field_" . $p_field_id . "_control\" OnChange=\"" . $t_js_toggle_func . "();\">\n";
  3805. echo '<option value="' . CUSTOM_FIELD_DATE_ANY . '"';
  3806. check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ANY );
  3807. echo '>' . lang_get( 'any' ) . '</option>' . "\n";
  3808. echo '<option value="' . CUSTOM_FIELD_DATE_NONE . '"';
  3809. check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_NONE );
  3810. echo '>' . lang_get( 'none' ) . '</option>' . "\n";
  3811. echo '<option value="' . CUSTOM_FIELD_DATE_BETWEEN . '"';
  3812. check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_BETWEEN );
  3813. echo '>' . lang_get( 'between_date' ) . '</option>' . "\n";
  3814. echo '<option value="' . CUSTOM_FIELD_DATE_ONORBEFORE . '"';
  3815. check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ONORBEFORE );
  3816. echo '>' . lang_get( 'on_or_before_date' ) . '</option>' . "\n";
  3817. echo '<option value="' . CUSTOM_FIELD_DATE_BEFORE . '"';
  3818. check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_BEFORE );
  3819. echo '>' . lang_get( 'before_date' ) . '</option>' . "\n";
  3820. echo '<option value="' . CUSTOM_FIELD_DATE_ON . '"';
  3821. check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ON );
  3822. echo '>' . lang_get( 'on_date' ) . '</option>' . "\n";
  3823. echo '<option value="' . CUSTOM_FIELD_DATE_AFTER . '"';
  3824. check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_AFTER );
  3825. echo '>' . lang_get( 'after_date' ) . '</option>' . "\n";
  3826. echo '<option value="' . CUSTOM_FIELD_DATE_ONORAFTER . '"';
  3827. check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ONORAFTER );
  3828. echo '>' . lang_get( 'on_or_after_date' ) . '</option>' . "\n";
  3829. echo '</select>' . "\n";
  3830. echo "</td></tr>\n<tr><td>";
  3831. print_date_selection_set( 'custom_field_' . $p_field_id . '_start', config_get( 'short_date_format' ), $t_start, $t_start_disable, false, $t_sel_start_year, $t_sel_end_year );
  3832. print "</td></tr>\n<tr><td>";
  3833. print_date_selection_set( 'custom_field_' . $p_field_id . '_end', config_get( 'short_date_format' ), $t_end, $t_end_disable, false, $t_sel_start_year, $t_sel_end_year );
  3834. print "</td></tr>\n</table>";
  3835. }
  3836. /**
  3837. * print project field
  3838. */
  3839. function print_filter_project_id() {
  3840. global $t_select_modifier, $t_filter, $f_view_type;
  3841. ?>
  3842. <!-- Project -->
  3843. <select <?php echo $t_select_modifier;?> name="<?php echo FILTER_PROPERTY_PROJECT_ID;?>[]">
  3844. <option value="<?php echo META_FILTER_CURRENT?>" <?php check_selected( $t_filter[FILTER_PROPERTY_PROJECT_ID], META_FILTER_CURRENT );?>>[<?php echo lang_get( 'current' )?>]</option>
  3845. <?php print_project_option_list( $t_filter[FILTER_PROPERTY_PROJECT_ID] )?>
  3846. </select>
  3847. <?php
  3848. }
  3849. /**
  3850. * Prints a multi-value filter field.
  3851. * @param string $p_field_name
  3852. * @param mixed $p_field_value
  3853. */
  3854. function print_multivalue_field( $p_field_name, $p_field_value ) {
  3855. $t_output = '';
  3856. $t_any_found = false;
  3857. if( count( $p_field_value ) == 0 ) {
  3858. echo lang_get( 'any' );
  3859. } else {
  3860. $t_first_flag = true;
  3861. $t_field_value = is_array( $p_field_value ) ? $p_field_value : array( $p_field_value );
  3862. foreach( $t_field_value as $t_current ) {
  3863. $t_current = stripslashes( $t_current );
  3864. ?>
  3865. <input type="hidden" name="<?php echo string_attribute( $p_field_name )?>[]" value="<?php echo string_attribute( $t_current );?>" />
  3866. <?php
  3867. $t_this_string = '';
  3868. if((( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) || ( is_blank( $t_current ) ) ) {
  3869. $t_any_found = true;
  3870. } else {
  3871. $t_this_string = string_display( $t_current );
  3872. }
  3873. if( $t_first_flag != true ) {
  3874. $t_output .= '<br />';
  3875. } else {
  3876. $t_first_flag = false;
  3877. }
  3878. $t_output .= $t_this_string;
  3879. }
  3880. if( true == $t_any_found ) {
  3881. echo lang_get( 'any' );
  3882. } else {
  3883. echo $t_output;
  3884. }
  3885. }
  3886. }
  3887. # ==========================================================================
  3888. # CACHING
  3889. # ==========================================================================
  3890. /**
  3891. * @internal SECURITY NOTE: cache globals are initialized here to prevent them
  3892. * being spoofed if register_globals is turned on.
  3893. * We cache filter requests to reduce the number of SQL queries
  3894. * @global mixed $g_cache_filter
  3895. * @global mixed $g_cache_filter_db_filters
  3896. */
  3897. $g_cache_filter = array();
  3898. $g_cache_filter_db_filters = array();
  3899. /**
  3900. * Cache a filter row if necessary and return the cached copy
  3901. * If the second parameter is true (default), trigger an error
  3902. * if the filter can't be found. If the second parameter is
  3903. * false, return false if the filter can't be found.
  3904. * @param int $p_filter_id
  3905. * @param bool $p_trigger_errors
  3906. * @return mixed
  3907. */
  3908. function filter_cache_row( $p_filter_id, $p_trigger_errors = true ) {
  3909. global $g_cache_filter;
  3910. $c_filter_id = db_prepare_int( $p_filter_id );
  3911. $t_filters_table = db_get_table( 'mantis_filters_table' );
  3912. if( isset( $g_cache_filter[$c_filter_id] ) ) {
  3913. return $g_cache_filter[$c_filter_id];
  3914. }
  3915. $query = 'SELECT *
  3916. FROM ' . $t_filters_table . '
  3917. WHERE id=' . db_param();
  3918. $result = db_query_bound( $query, Array( $c_filter_id ) );
  3919. if( 0 == db_num_rows( $result ) ) {
  3920. if( $p_trigger_errors ) {
  3921. error_parameters( $p_filter_id );
  3922. trigger_error( ERROR_FILTER_NOT_FOUND, ERROR );
  3923. } else {
  3924. return false;
  3925. }
  3926. }
  3927. $row = db_fetch_array( $result );
  3928. $g_cache_filter[$c_filter_id] = $row;
  3929. return $row;
  3930. }
  3931. /**
  3932. * Clear the filter cache (or just the given id if specified)
  3933. * @param int $p_filter_id
  3934. * @return bool
  3935. */
  3936. function filter_clear_cache( $p_filter_id = null ) {
  3937. global $g_cache_filter;
  3938. if( null === $p_filter_id ) {
  3939. $g_cache_filter = array();
  3940. } else {
  3941. $c_filter_id = db_prepare_int( $p_filter_id );
  3942. unset( $g_cache_filter[$c_filter_id] );
  3943. }
  3944. return true;
  3945. }
  3946. # ==========================================================================
  3947. # FILTER DB FUNCTIONS
  3948. # ==========================================================================
  3949. /**
  3950. * Add a filter to the database for the current user
  3951. * @param int $p_project_id
  3952. * @param bool $p_is_public
  3953. * @param string $p_name
  3954. * @param string $p_filter_string
  3955. * @return int
  3956. */
  3957. function filter_db_set_for_current_user( $p_project_id, $p_is_public, $p_name, $p_filter_string ) {
  3958. $t_user_id = auth_get_current_user_id();
  3959. $c_project_id = db_prepare_int( $p_project_id );
  3960. $c_is_public = db_prepare_bool( $p_is_public, false );
  3961. $t_filters_table = db_get_table( 'mantis_filters_table' );
  3962. # check that the user can save non current filters (if required)
  3963. if(( ALL_PROJECTS <= $c_project_id ) && ( !is_blank( $p_name ) ) && ( !access_has_project_level( config_get( 'stored_query_create_threshold' ) ) ) ) {
  3964. return -1;
  3965. }
  3966. # ensure that we're not making this filter public if we're not allowed
  3967. if( !access_has_project_level( config_get( 'stored_query_create_shared_threshold' ) ) ) {
  3968. $c_is_public = db_prepare_bool( false );
  3969. }
  3970. # Do I need to update or insert this value?
  3971. $query = "SELECT id FROM $t_filters_table
  3972. WHERE user_id=" . db_param() . "
  3973. AND project_id=" . db_param() . "
  3974. AND name=" . db_param();
  3975. $result = db_query_bound( $query, Array( $t_user_id, $c_project_id, $p_name ) );
  3976. if( db_num_rows( $result ) > 0 ) {
  3977. $row = db_fetch_array( $result );
  3978. $query = "UPDATE $t_filters_table
  3979. SET is_public=" . db_param() . ",
  3980. filter_string=" . db_param() . "
  3981. WHERE id=" . db_param();
  3982. db_query_bound( $query, Array( $c_is_public, $p_filter_string, $row['id'] ) );
  3983. return $row['id'];
  3984. } else {
  3985. $query = "INSERT INTO $t_filters_table
  3986. ( user_id, project_id, is_public, name, filter_string )
  3987. VALUES
  3988. ( " . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ' )';
  3989. db_query_bound( $query, Array( $t_user_id, $c_project_id, $c_is_public, $p_name, $p_filter_string ) );
  3990. # Recall the query, we want the filter ID
  3991. $query = "SELECT id
  3992. FROM $t_filters_table
  3993. WHERE user_id=" . db_param() . "
  3994. AND project_id=" . db_param() . "
  3995. AND name=" . db_param();
  3996. $result = db_query_bound( $query, Array( $t_user_id, $c_project_id, $p_name ) );
  3997. if( db_num_rows( $result ) > 0 ) {
  3998. $row = db_fetch_array( $result );
  3999. return $row['id'];
  4000. }
  4001. return -1;
  4002. }
  4003. }
  4004. /**
  4005. * This function returns the filter string that is
  4006. * tied to the unique id parameter. If the user doesn't
  4007. * have permission to see this filter, the function
  4008. * returns null
  4009. * @param int $p_filter_id
  4010. * @param int $p_user_id
  4011. * @return mixed
  4012. */
  4013. function filter_db_get_filter( $p_filter_id, $p_user_id = null ) {
  4014. global $g_cache_filter_db_filters;
  4015. $t_filters_table = db_get_table( 'mantis_filters_table' );
  4016. $c_filter_id = db_prepare_int( $p_filter_id );
  4017. if( isset( $g_cache_filter_db_filters[$p_filter_id] ) ) {
  4018. if( $g_cache_filter_db_filters[$p_filter_id] === false ) {
  4019. return null;
  4020. }
  4021. return $g_cache_filter_db_filters[$p_filter_id];
  4022. }
  4023. if( null === $p_user_id ) {
  4024. $t_user_id = auth_get_current_user_id();
  4025. } else {
  4026. $t_user_id = $p_user_id;
  4027. }
  4028. $query = 'SELECT * FROM ' . $t_filters_table . ' WHERE id=' . db_param();
  4029. $result = db_query_bound( $query, Array( $c_filter_id ) );
  4030. if( db_num_rows( $result ) > 0 ) {
  4031. $row = db_fetch_array( $result );
  4032. if( $row['user_id'] != $t_user_id ) {
  4033. if( $row['is_public'] != true ) {
  4034. return null;
  4035. }
  4036. }
  4037. # check that the user has access to non current filters
  4038. if(( ALL_PROJECTS <= $row['project_id'] ) && ( !is_blank( $row['name'] ) ) && ( !access_has_project_level( config_get( 'stored_query_use_threshold', null, $t_user_id, $row['project_id'] ) ) ) ) {
  4039. return null;
  4040. }
  4041. $g_cache_filter_db_filters[$p_filter_id] = $row['filter_string'];
  4042. return $row['filter_string'];
  4043. } else {
  4044. $g_cache_filter_db_filters[$p_filter_id] = false;
  4045. return false;
  4046. }
  4047. }
  4048. /**
  4049. * @param int $p_project_id
  4050. * @param int $p_user_id
  4051. * @return int
  4052. */
  4053. function filter_db_get_project_current( $p_project_id, $p_user_id = null ) {
  4054. $t_filters_table = db_get_table( 'mantis_filters_table' );
  4055. $c_project_id = db_prepare_int( $p_project_id );
  4056. $c_project_id = $c_project_id * -1;
  4057. if( null === $p_user_id ) {
  4058. $c_user_id = auth_get_current_user_id();
  4059. } else {
  4060. $c_user_id = db_prepare_int( $p_user_id );
  4061. }
  4062. # we store current filters for each project with a special project index
  4063. $query = "SELECT *
  4064. FROM $t_filters_table
  4065. WHERE user_id=" . db_param() . "
  4066. AND project_id=" . db_param() . "
  4067. AND name=" . db_param();
  4068. $result = db_query_bound( $query, Array( $c_user_id, $c_project_id, '' ) );
  4069. if( db_num_rows( $result ) > 0 ) {
  4070. $row = db_fetch_array( $result );
  4071. return $row['id'];
  4072. }
  4073. return null;
  4074. }
  4075. /**
  4076. * Query for the filter name using the filter id
  4077. * @param int $p_filter_id
  4078. * @return string
  4079. */
  4080. function filter_db_get_name( $p_filter_id ) {
  4081. $t_filters_table = db_get_table( 'mantis_filters_table' );
  4082. $c_filter_id = db_prepare_int( $p_filter_id );
  4083. $query = 'SELECT * FROM ' . $t_filters_table . ' WHERE id=' . db_param();
  4084. $result = db_query_bound( $query, Array( $c_filter_id ) );
  4085. if( db_num_rows( $result ) > 0 ) {
  4086. $row = db_fetch_array( $result );
  4087. if( $row['user_id'] != auth_get_current_user_id() ) {
  4088. if( $row['is_public'] != true ) {
  4089. return null;
  4090. }
  4091. }
  4092. return $row['name'];
  4093. }
  4094. return null;
  4095. }
  4096. /**
  4097. * Check if the current user has permissions to delete the stored query
  4098. * @param $p_filter_id
  4099. * @return bool
  4100. */
  4101. function filter_db_can_delete_filter( $p_filter_id ) {
  4102. $t_filters_table = db_get_table( 'mantis_filters_table' );
  4103. $c_filter_id = db_prepare_int( $p_filter_id );
  4104. $t_user_id = auth_get_current_user_id();
  4105. # Administrators can delete any filter
  4106. if( user_is_administrator( $t_user_id ) ) {
  4107. return true;
  4108. }
  4109. $query = "SELECT id
  4110. FROM $t_filters_table
  4111. WHERE id=" . db_param() . "
  4112. AND user_id=" . db_param() . "
  4113. AND project_id!=" . db_param();
  4114. $result = db_query_bound( $query, Array( $c_filter_id, $t_user_id, -1 ) );
  4115. if( db_num_rows( $result ) > 0 ) {
  4116. return true;
  4117. }
  4118. return false;
  4119. }
  4120. /**
  4121. * Delete the filter specified by $p_filter_id
  4122. * @param $p_filter_id
  4123. * @return bool
  4124. */
  4125. function filter_db_delete_filter( $p_filter_id ) {
  4126. $t_filters_table = db_get_table( 'mantis_filters_table' );
  4127. $c_filter_id = db_prepare_int( $p_filter_id );
  4128. $t_user_id = auth_get_current_user_id();
  4129. if( !filter_db_can_delete_filter( $c_filter_id ) ) {
  4130. return false;
  4131. }
  4132. $query = 'DELETE FROM ' . $t_filters_table . ' WHERE id=' . db_param();
  4133. $result = db_query_bound( $query, Array( $c_filter_id ) );
  4134. if( db_affected_rows( $result ) > 0 ) {
  4135. return true;
  4136. }
  4137. return false;
  4138. }
  4139. /**
  4140. * Delete all the unnamed filters
  4141. */
  4142. function filter_db_delete_current_filters() {
  4143. $t_filters_table = db_get_table( 'mantis_filters_table' );
  4144. $t_all_id = ALL_PROJECTS;
  4145. $query = "DELETE FROM $t_filters_table
  4146. WHERE project_id<=" . db_param() . "
  4147. AND name=" . db_param();
  4148. $result = db_query_bound( $query, Array( $t_all_id, '' ) );
  4149. }
  4150. /**
  4151. * @param int $p_project_id
  4152. * @param int $p_user_id
  4153. * @return mixed
  4154. */
  4155. function filter_db_get_available_queries( $p_project_id = null, $p_user_id = null ) {
  4156. $t_filters_table = db_get_table( 'mantis_filters_table' );
  4157. $t_overall_query_arr = array();
  4158. if( null === $p_project_id ) {
  4159. $t_project_id = helper_get_current_project();
  4160. } else {
  4161. $t_project_id = db_prepare_int( $p_project_id );
  4162. }
  4163. if( null === $p_user_id ) {
  4164. $t_user_id = auth_get_current_user_id();
  4165. } else {
  4166. $t_user_id = db_prepare_int( $p_user_id );
  4167. }
  4168. # If the user doesn't have access rights to stored queries, just return
  4169. if( !access_has_project_level( config_get( 'stored_query_use_threshold' ) ) ) {
  4170. return $t_overall_query_arr;
  4171. }
  4172. # Get the list of available queries. By sorting such that public queries are
  4173. # first, we can override any query that has the same name as a private query
  4174. # with that private one
  4175. $query = "SELECT * FROM $t_filters_table
  4176. WHERE (project_id=" . db_param() . "
  4177. OR project_id=0)
  4178. AND name!=''
  4179. ORDER BY is_public DESC, name ASC";
  4180. $result = db_query_bound( $query, Array( $t_project_id ) );
  4181. $query_count = db_num_rows( $result );
  4182. for( $i = 0;$i < $query_count;$i++ ) {
  4183. $row = db_fetch_array( $result );
  4184. if(( $row['user_id'] == $t_user_id ) || db_prepare_bool( $row['is_public'] ) ) {
  4185. $t_overall_query_arr[$row['id']] = $row['name'];
  4186. }
  4187. }
  4188. $t_overall_query_arr = array_unique( $t_overall_query_arr );
  4189. asort( $t_overall_query_arr );
  4190. return $t_overall_query_arr;
  4191. }
  4192. /**
  4193. * @param str $p_name
  4194. * @return bool true when under max_length (64) and false when over
  4195. */
  4196. function filter_name_valid_length( $p_name ) {
  4197. if( utf8_strlen( $p_name ) > 64 ) {
  4198. return false;
  4199. } else {
  4200. return true;
  4201. }
  4202. }