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