Blame Extras/Mantis/1.1.2-1.fc9/core/filter_api.php

4c79b5
4c79b5
# Mantis - a php based bugtracking system
4c79b5
4c79b5
# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
4c79b5
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
4c79b5
4c79b5
# Mantis is free software: you can redistribute it and/or modify
4c79b5
# it under the terms of the GNU General Public License as published by
4c79b5
# the Free Software Foundation, either version 2 of the License, or
4c79b5
# (at your option) any later version.
4c79b5
#
4c79b5
# Mantis is distributed in the hope that it will be useful,
4c79b5
# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c79b5
# GNU General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
4c79b5
4c79b5
	#------------------------------
4c79b5
	#   $Revision: 2643 $
4c79b5
	#     $Author: al $    
4c79b5
	#       $Date: 2009-06-18 19:06:27 -0400 (Thu, 18 Jun 2009) $  
4c79b5
	#------------------------------
4c79b5
4c79b5
	$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
4c79b5
4c79b5
	require_once( $t_core_dir . 'current_user_api.php' );
4c79b5
	require_once( $t_core_dir . 'user_api.php' );
4c79b5
	require_once( $t_core_dir . 'bug_api.php' );
4c79b5
	require_once( $t_core_dir . 'collapse_api.php' );
4c79b5
	require_once( $t_core_dir . 'relationship_api.php' );
4c79b5
	require_once( $t_core_dir . 'tag_api.php' );
4c79b5
4c79b5
	###########################################################################
4c79b5
	# Filter Property Names
4c79b5
	###########################################################################
4c79b5
4c79b5
	define( 'FILTER_PROPERTY_FREE_TEXT', 'search' );
4c79b5
	define( 'FILTER_PROPERTY_CATEGORY', 'show_category' );
4c79b5
	define( 'FILTER_PROPERTY_SEVERITY_ID', 'show_severity' );
4c79b5
	define( 'FILTER_PROPERTY_STATUS_ID', 'show_status' );
4c79b5
	define( 'FILTER_PROPERTY_PRIORITY_ID', 'show_priority' );
4c79b5
	define( 'FILTER_PROPERTY_HIGHLIGHT_CHANGED', 'highlight_changed' );
4c79b5
	define( 'FILTER_PROPERTY_REPORTER_ID', 'reporter_id' );
4c79b5
	define( 'FILTER_PROPERTY_HANDLER_ID', 'handler_id' );
4c79b5
	define( 'FILTER_PROPERTY_PROJECT_ID', 'project_id' );
4c79b5
	define( 'FILTER_PROPERTY_RESOLUTION_ID', 'show_resolution' );
4c79b5
	define( 'FILTER_PROPERTY_PRODUCT_BUILD', 'show_build' );
4c79b5
	define( 'FILTER_PROPERTY_PRODUCT_VERSION', 'show_version' );
4c79b5
	define( 'FILTER_PROPERTY_MONITOR_USER_ID', 'user_monitor' );
4c79b5
	define( 'FILTER_PROPERTY_HIDE_STATUS_ID', 'hide_status' );
4c79b5
	define( 'FILTER_PROPERTY_SORT_FIELD_NAME', 'sort' );
4c79b5
	define( 'FILTER_PROPERTY_SORT_DIRECTION', 'dir' );
4c79b5
	define( 'FILTER_PROPERTY_SHOW_STICKY_ISSUES', 'sticky_issues' );
4c79b5
	define( 'FILTER_PROPERTY_VIEW_STATE_ID', 'view_state' );
4c79b5
	define( 'FILTER_PROPERTY_FIXED_IN_VERSION', 'fixed_in_version' );
4c79b5
	define( 'FILTER_PROPERTY_TARGET_VERSION', 'target_version' );
4c79b5
	define( 'FILTER_PROPERTY_ISSUES_PER_PAGE', 'per_page' );
4c79b5
	define( 'FILTER_PROPERTY_PROFILE', 'profile_id' );
4c79b5
	define( 'FILTER_PROPERTY_PLATFORM', 'platform' );
4c79b5
	define( 'FILTER_PROPERTY_OS', 'os' );
4c79b5
	define( 'FILTER_PROPERTY_OS_BUILD', 'os_build' );
4c79b5
	define( 'FILTER_PROPERTY_START_DAY', 'start_day' );
4c79b5
	define( 'FILTER_PROPERTY_START_MONTH', 'start_month' );
4c79b5
	define( 'FILTER_PROPERTY_START_YEAR', 'start_year' );
4c79b5
	define( 'FILTER_PROPERTY_END_DAY', 'end_day' );
4c79b5
	define( 'FILTER_PROPERTY_END_MONTH', 'end_month' );
4c79b5
	define( 'FILTER_PROPERTY_END_YEAR', 'end_year' );
4c79b5
	define( 'FILTER_PROPERTY_NOT_ASSIGNED', 'and_not_assigned' );
4c79b5
	define( 'FILTER_PROPERTY_FILTER_BY_DATE', 'do_filter_by_date' );
4c79b5
	define( 'FILTER_PROPERTY_RELATIONSHIP_TYPE', 'relationship_type' );
4c79b5
	define( 'FILTER_PROPERTY_RELATIONSHIP_BUG', 'relationship_bug' );
4c79b5
	define( 'FILTER_PROPERTY_TAG_STRING', 'tag_string' );
4c79b5
	define( 'FILTER_PROPERTY_TAG_SELECT', 'tag_select' );
4c79b5
4c79b5
	###########################################################################
4c79b5
	# Filter Query Parameter Names
4c79b5
	###########################################################################
4c79b5
4c79b5
	define( 'FILTER_SEARCH_FREE_TEXT', 'search' );
4c79b5
	define( 'FILTER_SEARCH_CATEGORY', 'category' );
4c79b5
	define( 'FILTER_SEARCH_SEVERITY_ID', 'severity_id');
4c79b5
	define( 'FILTER_SEARCH_STATUS_ID', 'status_id' );
4c79b5
	define( 'FILTER_SEARCH_REPORTER_ID', 'reporter_id' );
4c79b5
	define( 'FILTER_SEARCH_HANDLER_ID', 'handler_id' );
4c79b5
	define( 'FILTER_SEARCH_PROJECT_ID', 'project_id' );
4c79b5
	define( 'FILTER_SEARCH_RESOLUTION_ID', 'resolution_id' );
4c79b5
	define( 'FILTER_SEARCH_FIXED_IN_VERSION', 'fixed_in_version' );
4c79b5
	define( 'FILTER_SEARCH_TARGET_VERSION', 'target_version' );
4c79b5
	define( 'FILTER_SEARCH_START_DAY', 'start_day' );
4c79b5
	define( 'FILTER_SEARCH_START_MONTH', 'start_month' );
4c79b5
	define( 'FILTER_SEARCH_START_YEAR', 'start_year' );
4c79b5
	define( 'FILTER_SEARCH_END_DAY', 'end_day' );
4c79b5
	define( 'FILTER_SEARCH_END_MONTH', 'end_month' );
4c79b5
	define( 'FILTER_SEARCH_END_YEAR', 'end_year' );
4c79b5
	define( 'FILTER_SEARCH_PRIORITY_ID', 'priority_id' );
4c79b5
	define( 'FILTER_SEARCH_PROFILE', 'profile_id' );
4c79b5
	define( 'FILTER_SEARCH_PLATFORM', 'platform' );
4c79b5
	define( 'FILTER_SEARCH_OS', 'os' );
4c79b5
	define( 'FILTER_SEARCH_OS_BUILD', 'os_build' );
4c79b5
	define( 'FILTER_SEARCH_MONITOR_USER_ID', 'monitor_user_id' );
4c79b5
	define( 'FILTER_SEARCH_PRODUCT_BUILD', 'product_build' );
4c79b5
	define( 'FILTER_SEARCH_PRODUCT_VERSION', 'product_version' );
4c79b5
	define( 'FILTER_SEARCH_VIEW_STATE_ID', 'view_state_id' );
4c79b5
	define( 'FILTER_SEARCH_SHOW_STICKY_ISSUES', 'sticky_issues' );
4c79b5
	define( 'FILTER_SEARCH_SORT_FIELD_NAME', 'sortby' );
4c79b5
	define( 'FILTER_SEARCH_SORT_DIRECTION', 'dir' );
4c79b5
	define( 'FILTER_SEARCH_ISSUES_PER_PAGE', 'per_page' );
4c79b5
	define( 'FILTER_SEARCH_HIGHLIGHT_CHANGED', 'highlight_changed' );
4c79b5
	define( 'FILTER_SEARCH_HIDE_STATUS_ID', 'hide_status_id' );
4c79b5
	define( 'FILTER_SEARCH_NOT_ASSIGNED', 'not_assigned' );
4c79b5
	define( 'FILTER_SEARCH_FILTER_BY_DATE', 'filter_by_date' );
4c79b5
	define( 'FILTER_SEARCH_RELATIONSHIP_TYPE', 'relationship_type' );
4c79b5
	define( 'FILTER_SEARCH_RELATIONSHIP_BUG', 'relationship_bug' );
4c79b5
	define( 'FILTER_SEARCH_TAG_STRING', 'tag_string' );
4c79b5
	define( 'FILTER_SEARCH_TAG_SELECT', 'tag_select' );
4c79b5
4c79b5
	# Checks the supplied value to see if it is an ANY value.
4c79b5
	# $p_field_value - The value to check.
4c79b5
	# Returns true for "ANY" values and false for others.  "ANY" means filter criteria not active.
4c79b5
	function filter_str_field_is_any( $p_field_value ) {
4c79b5
		if ( is_array( $p_field_value ) ) {
4c79b5
			if ( count( $p_field_value ) == 0 ) {
4c79b5
				return true;
4c79b5
			}
4c79b5
4c79b5
			foreach( $p_field_value as $t_value ) {
4c79b5
				if ( ( META_FILTER_ANY == $t_value ) && ( is_numeric( $t_value ) ) ) {
4c79b5
					return true;
4c79b5
				}
4c79b5
			}
4c79b5
		} else {
4c79b5
			if ( is_string( $p_field_value ) && is_blank( $p_field_value ) ) {
4c79b5
				return true;
4c79b5
			}
4c79b5
			
4c79b5
			if ( is_bool( $p_field_value ) && !$p_field_value ) {
4c79b5
				return true;
4c79b5
			}
4c79b5
4c79b5
			if ( ( META_FILTER_ANY == $p_field_value ) && ( is_numeric( $p_field_value ) ) ) {
4c79b5
				return true;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		return false;
4c79b5
	}
4c79b5
4c79b5
	# Encodes a field and it's value for the filter URL.  This handles the URL encoding
4c79b5
	# and arrays.
4c79b5
	# $p_field_name - The field name.
4c79b5
	# $p_field_value - The field value (can be an array)
4c79b5
	function filter_encode_field_and_value( $p_field_name, $p_field_value ) {
4c79b5
		$t_query_array = array();		
4c79b5
		if ( is_array( $p_field_value ) ) {
4c79b5
			$t_count = count( $p_field_value );
4c79b5
			if ( $t_count > 1 ) {
4c79b5
				foreach ( $p_field_value as $t_value ) {
4c79b5
					$t_query_array[] = urlencode( $p_field_name . '[]' ) . '=' . urlencode( $t_value );
4c79b5
				}
4c79b5
			} else if ( $t_count == 1 ) {
4c79b5
				$t_query_array[] = urlencode( $p_field_name ) . '=' . urlencode( $p_field_value[0] );
4c79b5
			}
4c79b5
		} else {
4c79b5
			$t_query_array[] = urlencode( $p_field_name ) . '=' . urlencode( $p_field_value );
4c79b5
		}
4c79b5
4c79b5
		return implode( $t_query_array, '&' );
4c79b5
	}
4c79b5
4c79b5
	# Get a permalink for the current active filter.  The results of using these fields by other users
4c79b5
	# can be inconsistent with the original results due to fields like "Myself", "Current Project",
4c79b5
	# and due to access level.
4c79b5
	# Returns the search.php?xxxx or an empty string if no criteria applied. 
4c79b5
	function filter_get_url( $p_custom_filter ) {
4c79b5
		$t_query = array();
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PROJECT_ID] ) ) {
4c79b5
			$t_project_id = $p_custom_filter[FILTER_PROPERTY_PROJECT_ID];
4c79b5
4c79b5
			if ( count( $t_project_id ) == 1 && $t_project_id[0] == META_FILTER_CURRENT ) {
4c79b5
				$t_project_id = array( helper_get_current_project() );
4c79b5
			}
4c79b5
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PROJECT_ID, $t_project_id );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_FREE_TEXT] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FREE_TEXT, $p_custom_filter[FILTER_PROPERTY_FREE_TEXT] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_CATEGORY] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_CATEGORY, $p_custom_filter[FILTER_PROPERTY_CATEGORY] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_REPORTER_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_REPORTER_ID, $p_custom_filter[FILTER_PROPERTY_REPORTER_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_STATUS_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_STATUS_ID, $p_custom_filter[FILTER_PROPERTY_STATUS_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_MONITOR_USER_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_MONITOR_USER_ID, $p_custom_filter[FILTER_PROPERTY_MONITOR_USER_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_HANDLER_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HANDLER_ID, $p_custom_filter[FILTER_PROPERTY_HANDLER_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_SEVERITY_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SEVERITY_ID, $p_custom_filter[FILTER_PROPERTY_SEVERITY_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_RESOLUTION_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RESOLUTION_ID, $p_custom_filter[FILTER_PROPERTY_RESOLUTION_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRIORITY_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRIORITY_ID, $p_custom_filter[FILTER_PROPERTY_PRIORITY_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_VIEW_STATE_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_VIEW_STATE_ID, $p_custom_filter[FILTER_PROPERTY_VIEW_STATE_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SHOW_STICKY_ISSUES, $p_custom_filter[FILTER_PROPERTY_SHOW_STICKY_ISSUES] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRODUCT_VERSION] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRODUCT_VERSION, $p_custom_filter[FILTER_PROPERTY_PRODUCT_VERSION] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PRODUCT_BUILD] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PRODUCT_BUILD, $p_custom_filter[FILTER_PROPERTY_PRODUCT_BUILD] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_FIXED_IN_VERSION] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FIXED_IN_VERSION, $p_custom_filter[FILTER_PROPERTY_FIXED_IN_VERSION] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_TARGET_VERSION] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TARGET_VERSION, $p_custom_filter[FILTER_PROPERTY_TARGET_VERSION] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_SORT_FIELD_NAME] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SORT_FIELD_NAME, $p_custom_filter[FILTER_PROPERTY_SORT_FIELD_NAME] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_SORT_DIRECTION] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_SORT_DIRECTION, $p_custom_filter[FILTER_PROPERTY_SORT_DIRECTION] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] ) ) {
4c79b5
			if ( $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] != config_get( 'default_limit_view' ) ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_PROPERTY_ISSUES_PER_PAGE, $p_custom_filter[FILTER_SEARCH_ISSUES_PER_PAGE] );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] ) ) {
4c79b5
			if ( $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] != config_get( 'default_show_changed' ) ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HIGHLIGHT_CHANGED, $p_custom_filter[FILTER_PROPERTY_HIGHLIGHT_CHANGED] );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_HIDE_STATUS_ID] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_HIDE_STATUS_ID, $p_custom_filter[FILTER_PROPERTY_HIDE_STATUS_ID] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_NOT_ASSIGNED] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_NOT_ASSIGNED, $p_custom_filter[FILTER_PROPERTY_NOT_ASSIGNED] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_FILTER_BY_DATE, $p_custom_filter[FILTER_PROPERTY_FILTER_BY_DATE] );
4c79b5
4c79b5
			# The start and end dates are only applicable if filter by date is set.
4c79b5
			if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_DAY] ) ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_DAY, $p_custom_filter[FILTER_PROPERTY_START_DAY] );
4c79b5
			}
4c79b5
	
4c79b5
			if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_DAY] ) ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_DAY, $p_custom_filter[FILTER_PROPERTY_END_DAY] );
4c79b5
			}
4c79b5
	
4c79b5
			if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_MONTH] ) ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_MONTH, $p_custom_filter[FILTER_PROPERTY_START_MONTH] );
4c79b5
			}
4c79b5
	
4c79b5
			if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_MONTH] ) ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_MONTH, $p_custom_filter[FILTER_PROPERTY_END_MONTH] );
4c79b5
			}
4c79b5
	
4c79b5
			if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_START_YEAR] ) ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_START_YEAR, $p_custom_filter[FILTER_PROPERTY_START_YEAR] );
4c79b5
			}
4c79b5
	
4c79b5
			if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_END_YEAR] ) ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_END_YEAR, $p_custom_filter[FILTER_PROPERTY_END_YEAR] );
4c79b5
			}	
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] ) ) {
4c79b5
			if ( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] != -1 ) {
4c79b5
				$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RELATIONSHIP_TYPE, $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_TYPE] );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_RELATIONSHIP_BUG, $p_custom_filter[FILTER_PROPERTY_RELATIONSHIP_BUG] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_PLATFORM] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_PLATFORM, $p_custom_filter[FILTER_PROPERTY_PLATFORM] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_OS] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_OS, $p_custom_filter[FILTER_PROPERTY_OS] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_OS_BUILD] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_OS_BUILD, $p_custom_filter[FILTER_PROPERTY_OS_BUILD] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_TAG_STRING] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TAG_STRING, $p_custom_filter[FILTER_PROPERTY_TAG_STRING] );
4c79b5
		}
4c79b5
4c79b5
		if ( !filter_str_field_is_any( $p_custom_filter[FILTER_PROPERTY_TAG_SELECT] ) ) {
4c79b5
			$t_query[] = filter_encode_field_and_value( FILTER_SEARCH_TAG_SELECT, $p_custom_filter[FILTER_PROPERTY_TAG_SELECT] );
4c79b5
		}
4c79b5
4c79b5
		if ( isset( $p_custom_filter['custom_fields'] ) ) {
4c79b5
			foreach( $p_custom_filter['custom_fields'] as $t_custom_field_id => $t_custom_field_values ) {
4c79b5
				if ( !filter_str_field_is_any( $t_custom_field_values ) ) {
4c79b5
					$t_query[] = filter_encode_field_and_value( 'custom_field_' . $t_custom_field_id, $t_custom_field_values );
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ( count( $t_query ) > 0 ) {
4c79b5
			$t_query_str = implode( $t_query, '&' );
4c79b5
			$t_url = config_get( 'path' ) . 'search.php?' . $t_query_str;
4c79b5
		} else {
4c79b5
			$t_url = '';
4c79b5
		}
4c79b5
4c79b5
		return $t_url;
4c79b5
	}
4c79b5
4c79b5
	###########################################################################
4c79b5
	# Filter API
4c79b5
	###########################################################################
4c79b5
4c79b5
	# Get the standard filter that is to be used when no filter was previously saved.
4c79b5
	# When creating specific filters, this can be used as a basis for the filter, where
4c79b5
	# specific entries can be overridden.
4c79b5
	function filter_get_default() {
4c79b5
		$t_hide_status_default  = config_get( 'hide_status_default' );
4c79b5
		$t_default_show_changed = config_get( 'default_show_changed' );
4c79b5
4c79b5
		$t_filter = array(
4c79b5
			'show_category'		=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'show_severity'		=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'show_status'		=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'highlight_changed'	=> $t_default_show_changed,
4c79b5
			'reporter_id'		=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'handler_id'		=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'project_id'		=> Array ( '0' => META_FILTER_CURRENT ),
4c79b5
			'show_resolution'	=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'show_build'		=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'show_version'		=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'hide_status'		=> Array ( '0' => $t_hide_status_default ),
4c79b5
			'user_monitor'		=> Array ( '0' => META_FILTER_ANY ),
4c79b5
			'sort'              => 'last_updated',
4c79b5
			'dir'               => 'DESC'
4c79b5
		);
4c79b5
4c79b5
		return filter_ensure_valid_filter( $t_filter );
4c79b5
	}
4c79b5
4c79b5
	# @@@ Had to make all these parameters required because we can't use
4c79b5
	#  call-time pass by reference anymore.  I really preferred not having
4c79b5
	#  to pass all the params in if you didn't want to, but I wanted to get
4c79b5
	#  rid of the errors for now.  If we can think of a better way later
4c79b5
	#  (maybe return an object) that would be great.
4c79b5
	#
4c79b5
	# $p_page_numer
4c79b5
	#   - the page you want to see (set to the actual page on return)
4c79b5
	# $p_per_page
4c79b5
	#   - the number of bugs to see per page (set to actual on return)
4c79b5
	#     -1   indicates you want to see all bugs
4c79b5
	#     null indicates you want to use the value specified in the filter
4c79b5
	# $p_page_count
4c79b5
	#   - you don't need to give a value here, the number of pages will be
4c79b5
	#     stored here on return
4c79b5
	# $p_bug_count
4c79b5
	#   - you don't need to give a value here, the number of bugs will be
4c79b5
	#     stored here on return
4c79b5
	# $p_custom_filter
4c79b5
	#   - Filter to use.
4c79b5
	# $p_project_id
4c79b5
	#   - project id to use in filtering.
4c79b5
	# $p_user_id
4c79b5
	#   - user id to use as current user when filtering.
4c79b5
	# $p_show_sticky
4c79b5
	#	- get sticky issues only.
4c79b5
	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 ) {
4c79b5
		log_event( LOG_FILTERING, 'FILTERING: START NEW FILTER QUERY' );
4c79b5
4c79b5
		$t_bug_table			= config_get( 'mantis_bug_table' );
4c79b5
		$t_bug_text_table		= config_get( 'mantis_bug_text_table' );
4c79b5
		$t_bugnote_table		= config_get( 'mantis_bugnote_table' );
4c79b5
		$t_custom_field_string_table	= config_get( 'mantis_custom_field_string_table' );
4c79b5
		$t_bugnote_text_table	= config_get( 'mantis_bugnote_text_table' );
4c79b5
		$t_project_table		= config_get( 'mantis_project_table' );
4c79b5
		$t_bug_monitor_table	= config_get( 'mantis_bug_monitor_table' );
4c79b5
		$t_limit_reporters		= config_get( 'limit_reporters' );
4c79b5
		$t_bug_relationship_table	= config_get( 'mantis_bug_relationship_table' );
4c79b5
		$t_report_bug_threshold		= config_get( 'report_bug_threshold' );
4c79b5
4c79b5
		$t_current_user_id = auth_get_current_user_id();
4c79b5
4c79b5
		if ( null === $p_user_id ) {
4c79b5
			$t_user_id = $t_current_user_id;
4c79b5
		} else {
4c79b5
			$t_user_id = $p_user_id;
4c79b5
		}
4c79b5
4c79b5
		$c_user_id = db_prepare_int( $t_user_id );
4c79b5
4c79b5
		if ( null === $p_project_id ) {
4c79b5
			# @@@ If project_id is not specified, then use the project id(s) in the filter if set, otherwise, use current project.
4c79b5
			$t_project_id	= helper_get_current_project();
4c79b5
		} else {
4c79b5
			$t_project_id	= $p_project_id;
4c79b5
		}
4c79b5
4c79b5
		if ( $p_custom_filter === null ) {
4c79b5
			# Prefer current_user_get_bug_filter() over user_get_filter() when applicable since it supports
4c79b5
			# cookies set by previous version of the code.
4c79b5
			if ( $t_user_id == $t_current_user_id ) {
4c79b5
				$t_filter = current_user_get_bug_filter();
4c79b5
			} else {
4c79b5
				$t_filter = user_get_bug_filter( $t_user_id, $t_project_id );
4c79b5
			}
4c79b5
		} else {
4c79b5
			$t_filter = $p_custom_filter;
4c79b5
		}
4c79b5
4c79b5
		$t_filter = filter_ensure_valid_filter( $t_filter );
4c79b5
4c79b5
		if ( false === $t_filter ) {
4c79b5
			return false; # signify a need to create a cookie
4c79b5
			#@@@ error instead?
4c79b5
		}
4c79b5
4c79b5
		$t_view_type = $t_filter['_view_type'];
4c79b5
4c79b5
		$t_where_clauses = array( "$t_project_table.enabled = 1", "$t_project_table.id = $t_bug_table.project_id" );
4c79b5
		$t_select_clauses = array( "$t_bug_table.*" );
4c79b5
		$t_join_clauses = array();
4c79b5
		$t_from_clauses = array();
4c79b5
4c79b5
		// normalize the project filtering into an array $t_project_ids
4c79b5
		if ( 'simple' == $t_view_type ) {
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: Simple Filter' );
4c79b5
			$t_project_ids = array( $t_project_id );
4c79b5
			$t_include_sub_projects = true;
4c79b5
		} else {
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: Advanced Filter' );
4c79b5
			if ( !is_array( $t_filter['project_id'] ) ) {
4c79b5
				$t_project_ids = array( db_prepare_int( $t_filter['project_id'] ) );
4c79b5
			} else {
4c79b5
				$t_project_ids = array_map( 'db_prepare_int', $t_filter['project_id'] );
4c79b5
			}
4c79b5
4c79b5
			$t_include_sub_projects = ( ( count( $t_project_ids ) == 1 ) && ( $t_project_ids[0] == META_FILTER_CURRENT ) );
4c79b5
		}
4c79b5
4c79b5
		log_event( LOG_FILTERING, 'FILTERING: project_ids = ' . implode( ',', $t_project_ids ) );
4c79b5
		log_event( LOG_FILTERING, 'FILTERING: include sub-projects = ' . ( $t_include_sub_projects ? '1' : '0' ) );
4c79b5
4c79b5
		// if the array has ALL_PROJECTS, then reset the array to only contain ALL_PROJECTS.
4c79b5
		// replace META_FILTER_CURRENT with the actualy current project id.
4c79b5
		$t_all_projects_found = false;
4c79b5
		$t_new_project_ids = array();
4c79b5
		foreach ( $t_project_ids as $t_pid ) {
4c79b5
			if ( $t_pid == META_FILTER_CURRENT ) { 
4c79b5
				$t_pid = $t_project_id;
4c79b5
			}
4c79b5
4c79b5
			if ( $t_pid == ALL_PROJECTS ) {
4c79b5
				$t_all_projects_found = true;
4c79b5
				log_event( LOG_FILTERING, 'FILTERING: all projects selected' );
4c79b5
				break;
4c79b5
			}
4c79b5
4c79b5
			// filter out inaccessible projects.
4c79b5
			if ( !access_has_project_level( VIEWER, $t_pid, $t_user_id ) ) {
4c79b5
				continue;
4c79b5
			}
4c79b5
4c79b5
			$t_new_project_ids[] = $t_pid;
4c79b5
		}
4c79b5
4c79b5
		$t_projects_query_required = true;
4c79b5
		if ( $t_all_projects_found ) {
4c79b5
			if ( user_is_administrator( $t_user_id ) ) {
4c79b5
				log_event( LOG_FILTERING, 'FILTERING: all projects + administrator, hence no project filter.' );
4c79b5
				$t_projects_query_required = false;
4c79b5
			} else {
4c79b5
				$t_project_ids = user_get_accessible_projects( $t_user_id );
4c79b5
			}
4c79b5
		} else {
4c79b5
			$t_project_ids = $t_new_project_ids;
4c79b5
		}
4c79b5
	
4c79b5
		if ( $t_projects_query_required ) {
4c79b5
			// expand project ids to include sub-projects
4c79b5
			if ( $t_include_sub_projects ) {
4c79b5
				$t_top_project_ids = $t_project_ids;
4c79b5
4c79b5
				foreach ( $t_top_project_ids as $t_pid ) {
4c79b5
					log_event( LOG_FILTERING, 'FILTERING: Getting sub-projects for project id ' . $t_pid );
4c79b5
					$t_project_ids = array_merge( $t_project_ids, user_get_all_accessible_subprojects( $t_user_id, $t_pid ) );
4c79b5
				}
4c79b5
4c79b5
				$t_project_ids = array_unique( $t_project_ids );
4c79b5
			}
4c79b5
4c79b5
			// if no projects are accessible, then return an empty array.
4c79b5
			if ( count( $t_project_ids ) == 0 ) {
4c79b5
				log_event( LOG_FILTERING, 'FILTERING: no accessible projects' );
4c79b5
				return array();
4c79b5
			}
4c79b5
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: project_ids after including sub-projects = ' . implode( ',', $t_project_ids ) );
4c79b5
4c79b5
			// this array is to be populated with project ids for which we only want to show public issues.  This is due to the limited
4c79b5
			// access of the current user.
4c79b5
			$t_public_only_project_ids = array();
4c79b5
4c79b5
			// this array is populated with project ids that the current user has full access to.
4c79b5
			$t_private_and_public_project_ids = array();
4c79b5
4c79b5
			$t_access_required_to_view_private_bugs = config_get( 'private_bug_threshold' );
4c79b5
			foreach ( $t_project_ids as $t_pid ) {
4c79b5
				if ( access_has_project_level( $t_access_required_to_view_private_bugs, $t_pid, $t_user_id ) ) {
4c79b5
					$t_private_and_public_project_ids[] = $t_pid;
4c79b5
				} else {
4c79b5
					$t_public_only_project_ids[] = $t_pid;
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: project_ids (with public/private access) = ' . implode( ',', $t_private_and_public_project_ids ) );
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: project_ids (with public access) = ' . implode( ',', $t_public_only_project_ids ) );
4c79b5
4c79b5
			$t_count_private_and_public_project_ids = count( $t_private_and_public_project_ids );
4c79b5
			if ( $t_count_private_and_public_project_ids == 1 ) {
4c79b5
				$t_private_and_public_query = "( $t_bug_table.project_id = " . $t_private_and_public_project_ids[0] . " )";
4c79b5
			} else if ( $t_count_private_and_public_project_ids > 1 ) {
4c79b5
				$t_private_and_public_query = "( $t_bug_table.project_id in (". implode( ', ', $t_private_and_public_project_ids ) . ") )";
4c79b5
			} else {
4c79b5
				$t_private_and_public_query = null;
4c79b5
			}
4c79b5
4c79b5
			$t_count_public_only_project_ids = count( $t_public_only_project_ids );
4c79b5
			$t_public_view_state_check = "( ( $t_bug_table.view_state = " . VS_PUBLIC . " ) OR ( $t_bug_table.reporter_id = $t_user_id ) )";
4c79b5
			if ( $t_count_public_only_project_ids == 1 ) {
4c79b5
				$t_public_only_query = "( ( $t_bug_table.project_id = " . $t_public_only_project_ids[0] . " ) AND $t_public_view_state_check )";
4c79b5
			} else if ( $t_count_public_only_project_ids > 1 ) {
4c79b5
				$t_public_only_query = "( ( $t_bug_table.project_id in (". implode( ', ', $t_public_only_project_ids ) . ") ) AND $t_public_view_state_check )";
4c79b5
			} else {
4c79b5
				$t_public_only_query = null;
4c79b5
			}
4c79b5
4c79b5
			// both queries can't be null, so we either have one of them or both.
4c79b5
			
4c79b5
			if ( $t_private_and_public_query === null ) {
4c79b5
				$t_project_query = $t_public_only_query;
4c79b5
			} else if ( $t_public_only_query === null ) {
4c79b5
				$t_project_query = $t_private_and_public_query;
4c79b5
			} else {
4c79b5
				$t_project_query = "( $t_public_only_query OR $t_private_and_public_query )";
4c79b5
			}
4c79b5
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: project query = ' . $t_project_query );
4c79b5
			array_push( $t_where_clauses, $t_project_query );
4c79b5
		}
4c79b5
4c79b5
		# view state
4c79b5
		$t_view_state = db_prepare_int( $t_filter['view_state'] );
4c79b5
		if ( ( $t_filter['view_state'] !== META_FILTER_ANY ) && ( !is_blank( $t_filter['view_state'] ) ) ) {
4c79b5
			$t_view_state_query = "($t_bug_table.view_state='$t_view_state')";
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: view_state query = ' . $t_view_state_query );
4c79b5
			array_push( $t_where_clauses, $t_view_state_query );
4c79b5
		} else {
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: no view_state query' );
4c79b5
		}
4c79b5
4c79b5
		# reporter
4c79b5
		$t_any_found = false;
4c79b5
4c79b5
		foreach( $t_filter['reporter_id'] as $t_filter_member ) {
4c79b5
			if ( ( META_FILTER_ANY === $t_filter_member ) || ( 0 === $t_filter_member ) ) {
4c79b5
				$t_any_found = true;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ( count( $t_filter['reporter_id'] ) == 0 ) {
4c79b5
			$t_any_found = true;
4c79b5
		}
4c79b5
4c79b5
		if ( !$t_any_found ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['reporter_id'] as $t_filter_member ) {
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, "0" );
4c79b5
				} else {
4c79b5
					$c_reporter_id = db_prepare_int( $t_filter_member );
4c79b5
					if ( META_FILTER_MYSELF == $c_reporter_id ) {
4c79b5
						array_push( $t_clauses, $c_user_id );
4c79b5
					} else {
4c79b5
						array_push( $t_clauses, $c_reporter_id );
4c79b5
					}
4c79b5
				}
4c79b5
			}
4c79b5
			
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				$t_reporter_query = "( $t_bug_table.reporter_id in (". implode( ', ', $t_clauses ) .") )";
4c79b5
			} else {
4c79b5
				$t_reporter_query = "( $t_bug_table.reporter_id=$t_clauses[0] )";
4c79b5
			}
4c79b5
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: reporter query = ' . $t_reporter_query );
4c79b5
			array_push( $t_where_clauses, $t_reporter_query );
4c79b5
		} else {
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: no reporter query' );
4c79b5
		}
4c79b5
4c79b5
		# limit reporter
4c79b5
		# @@@ thraxisp - access_has_project_level checks greater than or equal to,
4c79b5
		#   this assumed that there aren't any holes above REPORTER where the limit would apply
4c79b5
		#
4c79b5
		if ( ( ON === $t_limit_reporters ) && ( ! access_has_project_level( REPORTER + 1, $t_project_id, $t_user_id ) ) ) {
4c79b5
			$c_reporter_id = $c_user_id;
4c79b5
			array_push( $t_where_clauses, "($t_bug_table.reporter_id='$c_reporter_id')" );
4c79b5
		}
4c79b5
4c79b5
		# handler
4c79b5
		$t_any_found = false;
4c79b5
4c79b5
		foreach( $t_filter['handler_id'] as $t_filter_member ) {
4c79b5
			if ( ( META_FILTER_ANY === $t_filter_member ) || ( 0 === $t_filter_member ) ) {
4c79b5
				$t_any_found = true;
4c79b5
			}
4c79b5
		}
4c79b5
		if ( count( $t_filter['handler_id'] ) == 0 ) {
4c79b5
			$t_any_found = true;
4c79b5
		}
4c79b5
4c79b5
		if ( !$t_any_found ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['handler_id'] as $t_filter_member ) {
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, 0 );
4c79b5
				} else {
4c79b5
					$c_handler_id = db_prepare_int( $t_filter_member );
4c79b5
					if ( META_FILTER_MYSELF == $c_handler_id ) {
4c79b5
						array_push( $t_clauses, $c_user_id );
4c79b5
					} else {
4c79b5
						array_push( $t_clauses, $c_handler_id );
4c79b5
					}
4c79b5
				}
4c79b5
			}
4c79b5
			
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				$t_handler_query = "( $t_bug_table.handler_id in (". implode( ', ', $t_clauses ) .") )";
4c79b5
			} else {
4c79b5
				$t_handler_query = "( $t_bug_table.handler_id=$t_clauses[0] )";
4c79b5
			}
4c79b5
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: handler query = ' . $t_handler_query );
4c79b5
			array_push( $t_where_clauses, $t_handler_query );
4c79b5
		} else {
4c79b5
			log_event( LOG_FILTERING, 'FILTERING: no handler query' );
4c79b5
		}
4c79b5
4c79b5
		# category
4c79b5
		if ( !_filter_is_any( $t_filter['show_category'] ) ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['show_category'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, "''" );
4c79b5
				} else {
4c79b5
					$c_show_category = db_prepare_string( $t_filter_member );
4c79b5
					array_push( $t_clauses, "'$c_show_category'" );
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.category in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.category=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# severity
4c79b5
		$t_any_found = false;
4c79b5
		foreach( $t_filter['show_severity'] as $t_filter_member ) {
4c79b5
			if ( ( META_FILTER_ANY == $t_filter_member ) || ( 0 === $t_filter_member ) ) {
4c79b5
				$t_any_found = true;
4c79b5
			}
4c79b5
		}
4c79b5
		if ( count( $t_filter['show_severity'] ) == 0 ) {
4c79b5
			$t_any_found = true;
4c79b5
		}
4c79b5
		if ( !$t_any_found ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['show_severity'] as $t_filter_member ) {
4c79b5
				$c_show_severity = db_prepare_int( $t_filter_member );
4c79b5
				array_push( $t_clauses, $c_show_severity );
4c79b5
			}
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.severity in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.severity=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# show / hide status
4c79b5
		# take a list of all available statuses then remove the ones that we want hidden, then make sure
4c79b5
		# the ones we want shown are still available
4c79b5
		$t_status_arr = explode_enum_string( config_get( 'status_enum_string' ) );
4c79b5
		$t_available_statuses = array();
4c79b5
		$t_desired_statuses = array();
4c79b5
		foreach( $t_status_arr as $t_this_status ) {
4c79b5
			$t_this_status_arr = explode_enum_arr( $t_this_status );
4c79b5
			$t_available_statuses[] = $t_this_status_arr[0];
4c79b5
		}
4c79b5
4c79b5
		if ( 'simple' == $t_filter['_view_type'] ) {
4c79b5
			# simple filtering: if showing any, restrict by the hide status value, otherwise ignore the hide
4c79b5
			$t_any_found = false;
4c79b5
			$t_this_status = $t_filter['show_status'][0];
4c79b5
			$t_this_hide_status = $t_filter['hide_status'][0];
4c79b5
4c79b5
			if ( ( META_FILTER_ANY == $t_this_status ) || ( is_blank( $t_this_status ) ) || ( 0 === $t_this_status ) ) {
4c79b5
				$t_any_found = true;
4c79b5
			}
4c79b5
			if ( $t_any_found ) {
4c79b5
				foreach( $t_available_statuses as $t_this_available_status ) {
4c79b5
					if ( $t_this_hide_status > $t_this_available_status ) {
4c79b5
						$t_desired_statuses[] = $t_this_available_status;
4c79b5
					}
4c79b5
				}
4c79b5
			} else {
4c79b5
				$t_desired_statuses[] = $t_this_status;
4c79b5
			}
4c79b5
		} else {
4c79b5
			# advanced filtering: ignore the hide
4c79b5
			$t_any_found = false;
4c79b5
			foreach( $t_filter['show_status'] as $t_this_status ) {
4c79b5
				$t_desired_statuses[] = $t_this_status;
4c79b5
				if ( ( META_FILTER_ANY == $t_this_status ) || ( is_blank( $t_this_status ) ) || ( 0 === $t_this_status ) ) {
4c79b5
					$t_any_found = true;
4c79b5
				}
4c79b5
			}
4c79b5
			if ( $t_any_found ) {
4c79b5
				$t_desired_statuses = array();
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ( count( $t_desired_statuses ) > 0 ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_desired_statuses as $t_filter_member ) {
4c79b5
				$c_show_status = db_prepare_int( $t_filter_member );
4c79b5
				array_push( $t_clauses, $c_show_status );
4c79b5
			}
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.status in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.status=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# resolution
4c79b5
		$t_any_found = false;
4c79b5
		foreach( $t_filter['show_resolution'] as $t_filter_member ) {
4c79b5
			if ( META_FILTER_ANY == $t_filter_member ) {
4c79b5
				$t_any_found = true;
4c79b5
			}
4c79b5
		}
4c79b5
		if ( count( $t_filter['show_resolution'] ) == 0 ) {
4c79b5
			$t_any_found = true;
4c79b5
		}
4c79b5
		if ( !$t_any_found ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['show_resolution'] as $t_filter_member ) {
4c79b5
				$c_show_resolution = db_prepare_int( $t_filter_member );
4c79b5
				array_push( $t_clauses, $c_show_resolution );
4c79b5
			}
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.resolution in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.resolution=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# priority
4c79b5
		$t_any_found = false;
4c79b5
		foreach( $t_filter['show_priority'] as $t_filter_member ) {
4c79b5
				if ( ( META_FILTER_ANY == $t_filter_member ) || ( 0 === $t_filter_member ) ) {
4c79b5
					$t_any_found = true;
4c79b5
				}
4c79b5
		}
4c79b5
		if ( count( $t_filter['show_priority'] ) == 0 ) {
4c79b5
				$t_any_found = true;
4c79b5
		}
4c79b5
		if ( !$t_any_found ) {
4c79b5
				$t_clauses = array();
4c79b5
4c79b5
				foreach( $t_filter['show_priority'] as $t_filter_member ) {
4c79b5
						$c_show_priority = db_prepare_int( $t_filter_member );
4c79b5
						array_push( $t_clauses, $c_show_priority );
4c79b5
				}
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.priority in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.priority=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# product build
4c79b5
		$t_any_found = false;
4c79b5
		foreach( $t_filter['show_build'] as $t_filter_member ) {
4c79b5
			if ( ( META_FILTER_ANY == $t_filter_member ) && ( is_numeric( $t_filter_member ) ) ) {
4c79b5
				$t_any_found = true;
4c79b5
			}
4c79b5
		}
4c79b5
		if ( count( $t_filter['show_build'] ) == 0 ) {
4c79b5
			$t_any_found = true;
4c79b5
		}
4c79b5
		if ( !$t_any_found ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['show_build'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, "''" );
4c79b5
				} else {
4c79b5
					$c_show_build = db_prepare_string( $t_filter_member );
4c79b5
					array_push( $t_clauses, "'$c_show_build'" );
4c79b5
				}
4c79b5
			}
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.build in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.build=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# product version
4c79b5
		if ( !_filter_is_any( $t_filter['show_version'] ) ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['show_version'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, "''" );
4c79b5
				} else {
4c79b5
					$c_show_version = db_prepare_string( $t_filter_member );
4c79b5
					array_push( $t_clauses, "'$c_show_version'" );
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.version in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.version=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# profile
4c79b5
		if ( !_filter_is_any( $t_filter['show_profile'] ) ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['show_profile'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, "0" );
4c79b5
				} else {
4c79b5
					$c_show_profile = db_prepare_int( $t_filter_member );
4c79b5
					array_push( $t_clauses, "$c_show_profile" );
4c79b5
				}
4c79b5
			}
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.profile_id in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.profile_id=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# platform
4c79b5
		if ( !_filter_is_any( $t_filter['platform'] ) ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['platform'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, '' );
4c79b5
				} else {
4c79b5
					$c_platform = db_prepare_string( $t_filter_member );
4c79b5
					array_push( $t_clauses, "'$c_platform'" );
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.platform in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.platform = $t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# os
4c79b5
		if ( !_filter_is_any( $t_filter['os'] ) ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['os'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, '' );
4c79b5
				} else {
4c79b5
					$c_os = db_prepare_string( $t_filter_member );
4c79b5
					array_push( $t_clauses, "'$c_os'" );
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.os in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.os = $t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# os_build
4c79b5
		if ( !_filter_is_any( $t_filter['os_build'] ) ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['os_build'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, '' );
4c79b5
				} else {
4c79b5
					$c_os_build = db_prepare_string( $t_filter_member );
4c79b5
					array_push( $t_clauses, "'$c_os_build'" );
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.os_build in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.os_build = $t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# date filter
4c79b5
		if ( ( 'on' == $t_filter['do_filter_by_date'] ) &&
4c79b5
				is_numeric( $t_filter['start_month'] ) &&
4c79b5
				is_numeric( $t_filter['start_day'] ) &&
4c79b5
				is_numeric( $t_filter['start_year'] ) &&
4c79b5
				is_numeric( $t_filter['end_month'] ) &&
4c79b5
				is_numeric( $t_filter['end_day'] ) &&
4c79b5
				is_numeric( $t_filter['end_year'] )
4c79b5
			) {
4c79b5
4c79b5
			$t_start_string = db_prepare_string( $t_filter['start_year']  . "-". $t_filter['start_month']  . "-" . $t_filter['start_day'] ." 00:00:00" );
4c79b5
			$t_end_string   = db_prepare_string( $t_filter['end_year']  . "-". $t_filter['end_month']  . "-" . $t_filter['end_day'] ." 23:59:59" );
4c79b5
4c79b5
			array_push( $t_where_clauses, "($t_bug_table.date_submitted BETWEEN '$t_start_string' AND '$t_end_string' )" );
4c79b5
		}
4c79b5
4c79b5
		# fixed in version
4c79b5
		if ( !_filter_is_any( $t_filter['fixed_in_version'] ) ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['fixed_in_version'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, "''" );
4c79b5
				} else {
4c79b5
					$c_fixed_in_version = db_prepare_string( $t_filter_member );
4c79b5
					array_push( $t_clauses, "'$c_fixed_in_version'" );
4c79b5
				}
4c79b5
			}
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.fixed_in_version in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.fixed_in_version=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# target version
4c79b5
		if ( !_filter_is_any( $t_filter['target_version'] ) ) {
4c79b5
			$t_clauses = array();
4c79b5
4c79b5
			foreach( $t_filter['target_version'] as $t_filter_member ) {
4c79b5
				$t_filter_member = stripslashes( $t_filter_member );
4c79b5
				if ( META_FILTER_NONE == $t_filter_member ) {
4c79b5
					array_push( $t_clauses, "''" );
4c79b5
				} else {
4c79b5
					$c_target_version = db_prepare_string( $t_filter_member );
4c79b5
					array_push( $t_clauses, "'$c_target_version'" );
4c79b5
				}
4c79b5
			}
4c79b5
			
4c79b5
			#echo var_dump( $t_clauses ); exit;
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.target_version in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_bug_table.target_version=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# users monitoring a bug
4c79b5
		$t_any_found = false;
4c79b5
		foreach( $t_filter['user_monitor'] as $t_filter_member ) {
4c79b5
			if ( ( META_FILTER_ANY == $t_filter_member ) || ( 0 === $t_filter_member ) ) {
4c79b5
				$t_any_found = true;
4c79b5
			}
4c79b5
		}
4c79b5
		if ( count( $t_filter['user_monitor'] ) == 0 ) {
4c79b5
			$t_any_found = true;
4c79b5
		}
4c79b5
		if ( !$t_any_found ) {
4c79b5
			$t_clauses = array();
4c79b5
			$t_table_name = 'user_monitor';
4c79b5
			array_push( $t_from_clauses, $t_bug_monitor_table );
4c79b5
			array_push( $t_join_clauses, "LEFT JOIN $t_bug_monitor_table $t_table_name ON $t_table_name.bug_id = $t_bug_table.id" );
4c79b5
4c79b5
			foreach( $t_filter['user_monitor'] as $t_filter_member ) {
4c79b5
				$c_user_monitor = db_prepare_int( $t_filter_member );
4c79b5
				if ( META_FILTER_MYSELF == $c_user_monitor ) {
4c79b5
					array_push( $t_clauses, $c_user_id );
4c79b5
				} else {
4c79b5
					array_push( $t_clauses, $c_user_monitor );
4c79b5
				}
4c79b5
			}
4c79b5
			if ( 1 < count( $t_clauses ) ) {
4c79b5
				array_push( $t_where_clauses, "( $t_table_name.user_id in (". implode( ', ', $t_clauses ) .") )" );
4c79b5
			} else {
4c79b5
				array_push( $t_where_clauses, "( $t_table_name.user_id=$t_clauses[0] )" );
4c79b5
			}
4c79b5
		}
4c79b5
		# bug relationship
4c79b5
		$t_any_found = false;
4c79b5
		$c_rel_type = $t_filter['relationship_type'];
4c79b5
		$c_rel_bug = $t_filter['relationship_bug'];
4c79b5
		if ( -1 == $c_rel_type || 0 == $c_rel_bug) {
4c79b5
			$t_any_found = true;
4c79b5
		}
4c79b5
		if ( !$t_any_found ) {
4c79b5
			# use the complementary type
4c79b5
			$t_comp_type = relationship_get_complementary_type( $c_rel_type );
4c79b5
			$t_clauses = array();
4c79b5
			$t_table_name = 'relationship';
4c79b5
			array_push( $t_from_clauses, $t_bug_relationship_table );
4c79b5
			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" );
4c79b5
			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" );
4c79b5
			// get reverse relationships
4c79b5
 			array_push( $t_clauses, "($t_table_name.relationship_type='$t_comp_type' AND $t_table_name.source_bug_id='$c_rel_bug')" );
4c79b5
			array_push( $t_clauses, "($t_table_name"."2.relationship_type='$c_rel_type' AND $t_table_name"."2.destination_bug_id='$c_rel_bug')" );
4c79b5
			array_push( $t_where_clauses, '('. implode( ' OR ', $t_clauses ) .')' );
4c79b5
		}
4c79b5
4c79b5
		# tags
4c79b5
		$c_tag_string = trim( $t_filter['tag_string'] );
4c79b5
		if ( !is_blank( $c_tag_string ) ) {
4c79b5
			$t_tags = tag_parse_filters( $c_tag_string );
4c79b5
4c79b5
			if ( count( $t_tags ) ) {
4c79b5
4c79b5
				$t_tags_all = array();
4c79b5
				$t_tags_any = array();
4c79b5
				$t_tags_none = array();
4c79b5
	
4c79b5
				foreach( $t_tags as $t_tag_row ) {
4c79b5
					switch ( $t_tag_row['filter'] ) {
4c79b5
						case 1:
4c79b5
							$t_tags_all[] = $t_tag_row;
4c79b5
							break;
4c79b5
						case 0:
4c79b5
							$t_tags_any[] = $t_tag_row;
4c79b5
							break;
4c79b5
						case -1:
4c79b5
							$t_tags_none[] = $t_tag_row;
4c79b5
							break;
4c79b5
					}
4c79b5
				}
4c79b5
	
4c79b5
				if ( 0 < $t_filter['tag_select'] && tag_exists( $t_filter['tag_select'] ) ) {
4c79b5
					$t_tags_any[] = tag_get( $t_filter['tag_select'] );
4c79b5
				}
4c79b5
	
4c79b5
				$t_bug_tag_table = config_get( 'mantis_bug_tag_table' );
4c79b5
				
4c79b5
				if ( count( $t_tags_all ) ) {
4c79b5
					$t_clauses = array();
4c79b5
					foreach ( $t_tags_all as $t_tag_row ) {
4c79b5
						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] )" );
4c79b5
					}
4c79b5
					array_push( $t_where_clauses, '('. implode( ' AND ', $t_clauses ) .')' );
4c79b5
				}
4c79b5
				
4c79b5
				if ( count( $t_tags_any ) ) {
4c79b5
					$t_clauses = array();
4c79b5
					foreach ( $t_tags_any as $t_tag_row ) {
4c79b5
						array_push( $t_clauses, "$t_bug_tag_table.tag_id = $t_tag_row[id]" );
4c79b5
					}
4c79b5
					array_push( $t_where_clauses, "$t_bug_table.id IN ( SELECT bug_id FROM $t_bug_tag_table WHERE ( ". implode( ' OR ', $t_clauses ) .') )' );
4c79b5
				}
4c79b5
			
4c79b5
				if ( count( $t_tags_none ) ) {
4c79b5
					$t_clauses = array();
4c79b5
					foreach ( $t_tags_none as $t_tag_row ) {
4c79b5
						array_push( $t_clauses, "$t_bug_tag_table.tag_id = $t_tag_row[id]" );
4c79b5
					}
4c79b5
					array_push( $t_where_clauses, "$t_bug_table.id NOT IN ( SELECT bug_id FROM $t_bug_tag_table WHERE ( ". implode( ' OR ', $t_clauses ) .') )' );
4c79b5
				} 
4c79b5
4c79b5
			}	
4c79b5
		}
4c79b5
4c79b5
		# custom field filters
4c79b5
		if( ON == config_get( 'filter_by_custom_fields' ) ) {
4c79b5
			# custom field filtering
4c79b5
			# @@@ At the moment this gets the linked fields relating to the current project
4c79b5
			#     It should get the ones relating to the project in the filter or all projects
4c79b5
			#     if multiple projects.
4c79b5
			$t_custom_fields = custom_field_get_linked_ids( $t_project_id );
4c79b5
4c79b5
			foreach( $t_custom_fields as $t_cfid ) {
4c79b5
				$t_custom_where_clause = '';
4c79b5
				# Ignore all custom filters that are not set, or that are set to '' or "any"
4c79b5
				$t_any_found = false;
4c79b5
				foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) {
4c79b5
				if ( ( META_FILTER_ANY == $t_filter_member ) && ( is_numeric( $t_filter_member ) ) ) {
4c79b5
						$t_any_found = true;
4c79b5
					}
4c79b5
				}
4c79b5
				if ( !isset( $t_filter['custom_fields'][$t_cfid] ) ) {
4c79b5
					$t_any_found = true;
4c79b5
				}
4c79b5
				if ( !$t_any_found ) {
4c79b5
					$t_def = custom_field_get_definition( $t_cfid );
4c79b5
					$t_table_name = $t_custom_field_string_table . '_' . $t_cfid;
4c79b5
                    # We need to filter each joined table or the result query will explode in dimensions
4c79b5
                    # Each custom field will result in a exponential growth like Number_of_Issues^Number_of_Custom_Fields
4c79b5
                    # and only after this process ends (if it is able to) the result query will be filtered
4c79b5
                    # by the WHERE clause and by the DISTINCT clause
4c79b5
					$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 ";
4c79b5
4c79b5
					if ($t_def['type'] == CUSTOM_FIELD_TYPE_DATE) {
4c79b5
						switch ($t_filter['custom_fields'][$t_cfid][0]) {
4c79b5
						case CUSTOM_FIELD_DATE_ANY:
4c79b5
							break ;
4c79b5
						case CUSTOM_FIELD_DATE_NONE:
4c79b5
							array_push( $t_join_clauses, $t_cf_join_clause );
4c79b5
							$t_custom_where_clause = '(( ' . $t_table_name . '.bug_id is null) OR ( ' . $t_table_name . '.value = 0)' ;
4c79b5
							break ;
4c79b5
						case CUSTOM_FIELD_DATE_BEFORE:
4c79b5
							array_push( $t_join_clauses, $t_cf_join_clause );
4c79b5
							$t_custom_where_clause = '(( ' . $t_table_name . '.value != 0 AND (' . $t_table_name . '.value+0) < ' . ($t_filter['custom_fields'][$t_cfid][2]) . ')' ;
4c79b5
							break ;
4c79b5
						case CUSTOM_FIELD_DATE_AFTER:
4c79b5
							array_push( $t_join_clauses, $t_cf_join_clause );
4c79b5
							$t_custom_where_clause = '( (' . $t_table_name . '.value+0) > ' . ($t_filter['custom_fields'][$t_cfid][1]+1) ;
4c79b5
							break ;
4c79b5
						default:
4c79b5
							array_push( $t_join_clauses, $t_cf_join_clause );
4c79b5
							$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];
4c79b5
							break ;
4c79b5
						}
4c79b5
					} else {
4c79b5
4c79b5
						array_push( $t_join_clauses, $t_cf_join_clause );
4c79b5
4c79b5
						$t_filter_array = array();
4c79b5
						foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) {
4c79b5
							$t_filter_member = stripslashes( $t_filter_member );
4c79b5
							if ( META_FILTER_NONE == $t_filter_member ) { 
4c79b5
								# coerce filter value if selecting META_FILTER_NONE so it will match empty fields
4c79b5
								$t_filter_member = '';
4c79b5
								# but also add those _not_ present in the custom field string table
4c79b5
								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)" );
4c79b5
							}
4c79b5
4c79b5
							switch( $t_def['type'] ) {
4c79b5
								case CUSTOM_FIELD_TYPE_MULTILIST:
4c79b5
								case CUSTOM_FIELD_TYPE_CHECKBOX:
4c79b5
									array_push( $t_filter_array , db_helper_like( "$t_table_name.value", '%|' . db_prepare_string( $t_filter_member ) . '|%' ) );
4c79b5
									break;
4c79b5
								default:
4c79b5
									array_push( $t_filter_array, "$t_table_name.value = '" . db_prepare_string( $t_filter_member ) . "'" );
4c79b5
							}
4c79b5
						}
4c79b5
						$t_custom_where_clause .= '(' . implode( ' OR ', $t_filter_array );
4c79b5
					}
4c79b5
					if ( !is_blank( $t_custom_where_clause ) ) {
4c79b5
						array_push( $t_where_clauses, $t_custom_where_clause . ')' );
4c79b5
					}
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$t_textsearch_where_clause = '';
4c79b5
		$t_textsearch_wherejoin_clause = '';
4c79b5
		# Simple Text Search - Thanks to Alan Knowles
4c79b5
		if ( !is_blank( $t_filter['search'] ) ) {
4c79b5
			$c_search = db_prepare_string( $t_filter['search'] );
4c79b5
			$c_search_int = db_prepare_int( $t_filter['search'] );
4c79b5
			$t_textsearch_where_clause = '(' . db_helper_like( 'summary', "%$c_search%" ) .
4c79b5
							 ' OR ' . db_helper_like( "$t_bug_text_table.description", "%$c_search%" ) . 
4c79b5
							 ' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce", "%$c_search%" ) .
4c79b5
							 ' OR ' . db_helper_like( "$t_bug_text_table.additional_information", "%$c_search%" ) .
4c79b5
							 " OR ( $t_bug_table.id = '$c_search_int' ) )";
4c79b5
4c79b5
			$t_textsearch_wherejoin_clause = '(' . db_helper_like( 'summary', "%$c_search%" ) .
4c79b5
							 ' OR ' . db_helper_like( "$t_bug_text_table.description", "%$c_search%" ) .
4c79b5
							 ' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce", "%$c_search%" ) .
4c79b5
							 ' OR ' . db_helper_like( "$t_bug_text_table.additional_information", "%$c_search%" ) .
4c79b5
							 ' OR ' . db_helper_like( "$t_bug_table.id", "%$c_search%" ) .
4c79b5
							 ' OR ' . db_helper_like( "$t_bugnote_text_table.note", "%$c_search%" ) . ' )';
4c79b5
4c79b5
			array_push( $t_where_clauses, "($t_bug_text_table.id = $t_bug_table.bug_text_id)" );
4c79b5
4c79b5
			$t_from_clauses = array( $t_bug_text_table, $t_project_table, $t_bug_table );
4c79b5
		} else {
4c79b5
			$t_from_clauses = array( $t_project_table, $t_bug_table );
4c79b5
		}
4c79b5
4c79b5
		$t_select	= implode( ', ', array_unique( $t_select_clauses ) );
4c79b5
		$t_from		= 'FROM ' . implode( ', ', array_unique( $t_from_clauses ) );
4c79b5
		$t_join		= implode( ' ', $t_join_clauses );
4c79b5
		if ( count( $t_where_clauses ) > 0 ) {
4c79b5
			$t_where	= 'WHERE ' . implode( ' AND ', $t_where_clauses );
4c79b5
		} else {
4c79b5
			$t_where	= '';
4c79b5
		}
4c79b5
4c79b5
		# Possibly do two passes. First time, grab the IDs of issues that match the filters. Second time, grab the IDs of issues that
4c79b5
		# have bugnotes that match the text search if necessary.
4c79b5
		$t_id_array = array();
4c79b5
		for ( $i = 0; $i < 2; $i++ ) {
4c79b5
			$t_id_where = $t_where;
4c79b5
			$t_id_join = $t_join;
4c79b5
			if ( $i == 0 ) {
4c79b5
				if ( !is_blank( $t_id_where ) && !is_blank( $t_textsearch_where_clause ) ) {
4c79b5
					$t_id_where = $t_id_where . ' AND ' . $t_textsearch_where_clause;
4c79b5
				}
4c79b5
			} else if ( !is_blank( $t_textsearch_wherejoin_clause ) ) {
4c79b5
				$t_id_where = $t_id_where . ' AND ' . $t_textsearch_wherejoin_clause;
4c79b5
				$t_id_join = $t_id_join . " INNER JOIN $t_bugnote_table ON $t_bugnote_table.bug_id = $t_bug_table.id";
4c79b5
				$t_id_join = $t_id_join . " INNER JOIN $t_bugnote_text_table ON $t_bugnote_text_table.id = $t_bugnote_table.bugnote_text_id";
4c79b5
			}
4c79b5
			$query  = "SELECT DISTINCT $t_bug_table.id AS id
4c79b5
						$t_from
4c79b5
						$t_id_join
4c79b5
						$t_id_where";
4c79b5
			if ( ( $i == 0 ) || ( !is_blank( $t_textsearch_wherejoin_clause ) ) ) {
4c79b5
				$result = db_query( $query );
4c79b5
				$row_count = db_num_rows( $result );
4c79b5
4c79b5
				for ( $j=0; $j < $row_count; $j++ ) {
4c79b5
					$row = db_fetch_array( $result );
4c79b5
					$t_id_array[] = db_prepare_int ( $row['id'] );
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$t_id_array = array_unique( $t_id_array );
4c79b5
4c79b5
		# Get the total number of bugs that meet the criteria.
4c79b5
		$bug_count = count( $t_id_array );
4c79b5
4c79b5
		$rows = array();
4c79b5
4c79b5
		if ( $bug_count > 0 ) {
4c79b5
			$t_where = "WHERE $t_bug_table.id in (" . implode( ", ", $t_id_array ) . ")";
4c79b5
		} else {
4c79b5
			return $rows;
4c79b5
		}
4c79b5
4c79b5
		$t_from = 'FROM ' . $t_bug_table;
4c79b5
4c79b5
		# write the value back in case the caller wants to know
4c79b5
		$p_bug_count = $bug_count;
4c79b5
4c79b5
		if ( null === $p_per_page ) {
4c79b5
			$p_per_page = (int)$t_filter['per_page'];
4c79b5
		} else if ( -1 == $p_per_page ) {
4c79b5
			$p_per_page = $bug_count;
4c79b5
		}
4c79b5
4c79b5
		# Guard against silly values of $f_per_page.
4c79b5
		if ( 0 == $p_per_page ) {
4c79b5
			$p_per_page = $bug_count;	// 0 - means show all
4c79b5
		}
4c79b5
4c79b5
		$p_per_page = (int)abs( $p_per_page );
4c79b5
4c79b5
		# Use $bug_count and $p_per_page to determine how many pages
4c79b5
		# to split this list up into.
4c79b5
		# For the sake of consistency have at least one page, even if it
4c79b5
		# is empty.
4c79b5
		$t_page_count = ceil($bug_count / $p_per_page);
4c79b5
		if ( $t_page_count < 1 ) {
4c79b5
			$t_page_count = 1;
4c79b5
		}
4c79b5
4c79b5
		# write the value back in case the caller wants to know
4c79b5
		$p_page_count = $t_page_count;
4c79b5
4c79b5
		# Make sure $p_page_number isn't past the last page.
4c79b5
		if ( $p_page_number > $t_page_count ) {
4c79b5
			$p_page_number = $t_page_count;
4c79b5
		}
4c79b5
4c79b5
		# Make sure $p_page_number isn't before the first page
4c79b5
		if ( $p_page_number < 1 ) {
4c79b5
			$p_page_number = 1;
4c79b5
		}
4c79b5
4c79b5
		# Now add the rest of the criteria i.e. sorting, limit.
4c79b5
4c79b5
		# if sort is blank then default the sort and direction.  This is to fix the
4c79b5
		# symptoms of #3953.  Note that even if the main problem is fixed, we may
4c79b5
		# have to keep this code for a while to handle filters saved with this blank field.
4c79b5
		if ( is_blank( $t_filter['sort'] ) ) {
4c79b5
			$t_filter['sort'] = 'last_updated';
4c79b5
			$t_filter['dir'] = 'DESC';
4c79b5
		}
4c79b5
4c79b5
		$t_order_array = array();
4c79b5
		$t_sort_fields = split( ',', $t_filter['sort'] );
4c79b5
		$t_dir_fields = split( ',', $t_filter['dir'] );
4c79b5
4c79b5
		if ( ( 'on' == $t_filter['sticky_issues'] ) && ( NULL !== $p_show_sticky ) ) {
4c79b5
			$t_order_array[] = "sticky DESC";
4c79b5
		}
4c79b5
		
4c79b5
		$t_join = '';
4c79b5
		for ( $i=0; $i < count( $t_sort_fields ); $i++ ) {
4c79b5
			$c_sort = db_prepare_string( $t_sort_fields[$i] );
4c79b5
4c79b5
			if ( ! in_array( $t_sort_fields[$i], array_slice( $t_sort_fields, $i + 1) ) ) {
4c79b5
4c79b5
        		# if sorting by a custom field
4c79b5
        		if ( strpos( $c_sort, 'custom_' ) === 0 ) {
4c79b5
	        		$t_custom_field = substr( $c_sort, strlen( 'custom_' ) );
4c79b5
        			$t_custom_field_id = custom_field_get_id_from_name( $t_custom_field );
4c79b5
    	    		$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 ) )";
4c79b5
        			$c_sort = "$t_custom_field_string_table.value";
4c79b5
        			$t_select_clauses[] = "$t_custom_field_string_table.value";
4c79b5
     		   	}
4c79b5
4c79b5
				if ( 'DESC' == $t_dir_fields[$i] ) {
4c79b5
					$c_dir = 'DESC';
4c79b5
				} else {
4c79b5
					$c_dir = 'ASC';
4c79b5
				}
4c79b5
4c79b5
				$t_order_array[] = "$c_sort $c_dir";
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		# add basic sorting if necessary
4c79b5
		if ( ! in_array( 'last_updated', $t_sort_fields ) ) {
4c79b5
			$t_order_array[] = 'last_updated DESC';
4c79b5
        }
4c79b5
		if ( ! in_array( 'date_submitted', $t_sort_fields ) ) {
4c79b5
			$t_order_array[] = 'date_submitted DESC';
4c79b5
        }
4c79b5
4c79b5
		$t_order = " ORDER BY " . implode( ', ', $t_order_array );
4c79b5
		$t_select	= implode( ', ', array_unique( $t_select_clauses ) );
4c79b5
4c79b5
		$query2  = "SELECT DISTINCT $t_select
4c79b5
					$t_from
4c79b5
					$t_join
4c79b5
					$t_where
4c79b5
					$t_order";
4c79b5
4c79b5
		# Figure out the offset into the db query
4c79b5
		#
4c79b5
		# for example page number 1, per page 5:
4c79b5
		#     t_offset = 0
4c79b5
		# for example page number 2, per page 5:
4c79b5
		#     t_offset = 5
4c79b5
		$c_per_page = db_prepare_int( $p_per_page );
4c79b5
		$c_page_number = db_prepare_int( $p_page_number );
4c79b5
		$t_offset = ( ( $c_page_number - 1 ) * $c_per_page );
4c79b5
4c79b5
		# perform query
4c79b5
		$result2 = db_query( $query2, $c_per_page, $t_offset );
4c79b5
4c79b5
		$row_count = db_num_rows( $result2 );
4c79b5
4c79b5
		$t_id_array_lastmod = array();
4c79b5
		
4c79b5
		for ( $i=0 ; $i < $row_count ; $i++ ) {
4c79b5
			$row = db_fetch_array( $result2 );
4c79b5
			$t_id_array_lastmod[] = db_prepare_int ( $row['id'] );
4c79b5
			
4c79b5
			$row['date_submitted'] = db_unixtimestamp ( $row['date_submitted'] );
4c79b5
			$row['last_updated'] = db_unixtimestamp ( $row['last_updated'] );
4c79b5
					
4c79b5
			array_push( $rows, $row );
4c79b5
		}
4c79b5
4c79b5
		$t_id_array_lastmod = array_unique( $t_id_array_lastmod );
4c79b5
		
4c79b5
		// paulr: it should be impossible for t_id_array_lastmod to be array():
4c79b5
		// that would imply that $t_id_array is null which aborts this function early
4c79b5
		//if ( count( $t_id_array_lastmod ) > 0 ) {
4c79b5
		$t_where = "WHERE $t_bugnote_table.bug_id in (" . implode( ", ", $t_id_array_lastmod ) . ")";
4c79b5
		
4c79b5
		$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";
4c79b5
4c79b5
		# perform query
4c79b5
		$result3 = db_query( $query3 );
4c79b5
4c79b5
		$row_count = db_num_rows( $result3 );
4c79b5
4c79b5
		for ( $i=0 ; $i < $row_count ; $i++ ) {
4c79b5
			$row = db_fetch_array( $result3 );
4c79b5
			
4c79b5
			$t_stats[ $row['bug_id'] ] = $row;
4c79b5
		}
4c79b5
4c79b5
		foreach($rows as $row) {
4c79b5
			if( !isset( $t_stats[ $row['id'] ] ) ) {
4c79b5
				bug_cache_database_result( $row, false );
4c79b5
			} else {
4c79b5
				bug_cache_database_result( $row, $t_stats[ $row['id'] ] );
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		return $rows;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# return true if the filter cookie exists and is of the correct version,
4c79b5
	#  false otherwise
4c79b5
	function filter_is_cookie_valid() {
4c79b5
		$t_view_all_cookie_id = gpc_get_cookie( config_get( 'view_all_cookie' ), '' );
4c79b5
		$t_view_all_cookie = filter_db_get_filter( $t_view_all_cookie_id );
4c79b5
4c79b5
		# check to see if the cookie does not exist
4c79b5
		if ( is_blank( $t_view_all_cookie ) ) {
4c79b5
			return false;
4c79b5
		}
4c79b5
4c79b5
		# check to see if new cookie is needed
4c79b5
		$t_setting_arr = explode( '#', $t_view_all_cookie, 2 );
4c79b5
		if ( ( $t_setting_arr[0] == 'v1' ) ||
4c79b5
			 ( $t_setting_arr[0] == 'v2' ) ||
4c79b5
			 ( $t_setting_arr[0] == 'v3' ) ||
4c79b5
			 ( $t_setting_arr[0] == 'v4' ) ) {
4c79b5
			return false;
4c79b5
		}
4c79b5
4c79b5
		# We shouldn't need to do this anymore, as filters from v5 onwards should cope with changing
4c79b5
		# filter indices dynamically
4c79b5
		$t_filter_cookie_arr = array();
4c79b5
		if ( isset( $t_setting_arr[1] ) ) {
4c79b5
			$t_filter_cookie_arr = unserialize( $t_setting_arr[1] );
4c79b5
		} else {
4c79b5
			return false;
4c79b5
		}
4c79b5
		if ( $t_filter_cookie_arr['_version'] != config_get( 'cookie_version' ) ) {
4c79b5
			return false;
4c79b5
		}
4c79b5
4c79b5
		return true;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# return filter array if supplied serialized filter is valid, otherwise false.otherwise
4c79b5
	function filter_deserialize( $p_serialized_filter ) {
4c79b5
		if ( is_blank( $p_serialized_filter ) ) {
4c79b5
			return false;
4c79b5
		}
4c79b5
4c79b5
		# check to see if new cookie is needed
4c79b5
		$t_setting_arr = explode( '#', $p_serialized_filter, 2 );
4c79b5
		if ( ( $t_setting_arr[0] == 'v1' ) ||
4c79b5
			 ( $t_setting_arr[0] == 'v2' ) ||
4c79b5
			 ( $t_setting_arr[0] == 'v3' ) ||
4c79b5
			 ( $t_setting_arr[0] == 'v4' ) ) {
4c79b5
			# these versions can't be salvaged, they are too old to update
4c79b5
			return false;
4c79b5
		}
4c79b5
4c79b5
		# We shouldn't need to do this anymore, as filters from v5 onwards should cope with changing
4c79b5
		# filter indices dynamically
4c79b5
		$t_filter_array = array();
4c79b5
		if ( isset( $t_setting_arr[1] ) ) {
4c79b5
			$t_filter_array = unserialize( $t_setting_arr[1] );
4c79b5
		} else {
4c79b5
			return false;
4c79b5
		}
4c79b5
		if ( $t_filter_array['_version'] != config_get( 'cookie_version' ) ) {
4c79b5
			# if the version is not new enough, update it using defaults
4c79b5
			return filter_ensure_valid_filter( $t_filter_array );
4c79b5
		}
4c79b5
4c79b5
		return $t_filter_array;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Mainly based on filter_draw_selection_area2() but adds the support for the collapsible
4c79b5
	# filter display.
4c79b5
	function filter_draw_selection_area( $p_page_number, $p_for_screen = true )
4c79b5
	{
4c79b5
		collapse_open( 'filter' );
4c79b5
		filter_draw_selection_area2( $p_page_number, $p_for_screen, true );
4c79b5
		collapse_closed( 'filter' );
4c79b5
		filter_draw_selection_area2( $p_page_number, $p_for_screen, false );
4c79b5
		collapse_end( 'filter' );
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Will print the filter selection area for both the bug list view screen, as well
4c79b5
	# as the bug list print screen. This function was an attempt to make it easier to
4c79b5
	# add new filters and rearrange them on screen for both pages.
4c79b5
	function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_expanded = true )
4c79b5
	{
4c79b5
		$t_form_name_suffix = $p_expanded ? '_open' : '_closed';
4c79b5
4c79b5
		$t_filter = current_user_get_bug_filter();
4c79b5
		$t_filter = filter_ensure_valid_filter( $t_filter );
4c79b5
		$t_project_id = helper_get_current_project();
4c79b5
		$t_page_number = (int) $p_page_number;
4c79b5
4c79b5
		$t_view_type = $t_filter['_view_type'];
4c79b5
4c79b5
		$t_tdclass = 'small-caption';
4c79b5
		$t_trclass = 'row-category2';
4c79b5
		$t_action  = 'view_all_set.php?f=3';
4c79b5
4c79b5
		if ( $p_for_screen == false ) {
4c79b5
			$t_tdclass = 'print';
4c79b5
			$t_trclass = '';
4c79b5
			$t_action  = 'view_all_set.php';
4c79b5
		}
4c79b5
?>
4c79b5
4c79b5
		
4c79b5
		<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; ?>">
4c79b5
		<input type="hidden" name="type" value="1" />
4c79b5
		
4c79b5
			if ( $p_for_screen == false ) {
4c79b5
				PRINT '<input type="hidden" name="print" value="1" />';
4c79b5
				PRINT '<input type="hidden" name="offset" value="0" />';
4c79b5
			}
4c79b5
		?>
4c79b5
		<input type="hidden" name="page_number" value="<?php PRINT $t_page_number ?>" />
4c79b5
		<input type="hidden" name="view_type" value="<?php PRINT $t_view_type ?>" />
4c79b5
		
4c79b5
4c79b5
		
4c79b5
		$t_filter_cols = config_get( 'filter_custom_fields_per_row' );
4c79b5
		if ( $p_expanded ) {
4c79b5
			$t_custom_cols = $t_filter_cols;
4c79b5
4c79b5
			$t_current_user_access_level = current_user_get_access_level();
4c79b5
			$t_accessible_custom_fields_ids = array();
4c79b5
			$t_accessible_custom_fields_names = array();
4c79b5
			$t_accessible_custom_fields_values = array();
4c79b5
			$t_num_custom_rows = 0;
4c79b5
			$t_per_row = 0;
4c79b5
4c79b5
			if ( ON == config_get( 'filter_by_custom_fields' ) ) {
4c79b5
				$t_custom_fields = custom_field_get_linked_ids( $t_project_id );
4c79b5
4c79b5
				foreach ( $t_custom_fields as $t_cfid ) {
4c79b5
					$t_field_info = custom_field_cache_row( $t_cfid, true );
4c79b5
					if ( $t_field_info['access_level_r'] <= $t_current_user_access_level ) {
4c79b5
						$t_accessible_custom_fields_ids[] = $t_cfid;
4c79b5
						$t_accessible_custom_fields_names[] = $t_field_info['name'];
4c79b5
						$t_accessible_custom_fields_types[] = $t_field_info['type'];
4c79b5
						$t_accessible_custom_fields_values[] = custom_field_distinct_values( $t_cfid );
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
				if ( count( $t_accessible_custom_fields_ids ) > 0 ) {
4c79b5
					$t_per_row = config_get( 'filter_custom_fields_per_row' );
4c79b5
					$t_num_custom_rows = ceil( count( $t_accessible_custom_fields_ids ) / $t_per_row );
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			$t_filters_url = 'view_filters_page.php?for_screen=' . $p_for_screen;
4c79b5
			if ( 'advanced' == $t_view_type ) {
4c79b5
				$t_filters_url = $t_filters_url . '&view_type=advanced';
4c79b5
			}
4c79b5
			$t_filters_url = $t_filters_url . '&target_field=';
4c79b5
4c79b5
			$t_show_version = ( ON == config_get( 'show_product_version' ) )
4c79b5
					|| ( ( AUTO == config_get( 'show_product_version' ) )
4c79b5
								&& ( count( version_get_all_rows_with_subs( $t_project_id ) ) > 0 ) );
4c79b5
			# overload handler_id setting if user isn't supposed to see them (ref #6189)
4c79b5
			if ( ! access_has_project_level( config_get( 'view_handler_threshold' ), $t_project_id ) ) { 
4c79b5
				$t_filter['handler_id'] = array( META_FILTER_ANY ); 
4c79b5
			} 
4c79b5
		?>
4c79b5
4c79b5
		>
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			 8 ) {
4c79b5
				echo ' ';
4c79b5
			} ?>
4c79b5
		
4c79b5
4c79b5
		
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['reporter_id'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['reporter_id'] as $t_current ) {
4c79b5
										$t_this_name = '';
4c79b5
										?>
4c79b5
										<input type="hidden" name="reporter_id[]" value="<?php echo $t_current;?>" />
4c79b5
										
4c79b5
										if ( ( $t_current === 0 ) || ( is_blank( $t_current ) ) || ( META_FILTER_ANY == $t_current ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else if ( META_FILTER_MYSELF == $t_current ) {
4c79b5
											if ( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) {
4c79b5
												$t_this_name = '[' . lang_get( 'myself' ) . ']';
4c79b5
											} else {
4c79b5
												$t_any_found = true;
4c79b5
											}
4c79b5
										} else if ( META_FILTER_NONE == $t_current ) {
4c79b5
											$t_this_name = lang_get( 'none' );
4c79b5
										} else {
4c79b5
											$t_this_name = user_get_name( $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_name;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['user_monitor'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['user_monitor'] as $t_current ) {
4c79b5
										?>
4c79b5
										<input type="hidden" name="user_monitor[]" value="<?php echo $t_current;?>" />
4c79b5
										
4c79b5
										$t_this_name = '';
4c79b5
										if ( ( $t_current === 0 ) || ( is_blank( $t_current ) ) || ( META_FILTER_ANY == $t_current ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else if ( META_FILTER_MYSELF == $t_current ) {
4c79b5
											if ( access_has_project_level( config_get( 'monitor_bug_threshold' ) ) ) {
4c79b5
												$t_this_name = '[' . lang_get( 'myself' ) . ']';
4c79b5
											} else {
4c79b5
												$t_any_found = true;
4c79b5
											}
4c79b5
										} else {
4c79b5
											$t_this_name = user_get_name( $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_name;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['handler_id'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['handler_id'] as $t_current ) {
4c79b5
										?>
4c79b5
										<input type="hidden" name="handler_id[]" value="<?php echo $t_current;?>" />
4c79b5
										
4c79b5
										$t_this_name = '';
4c79b5
										if ( META_FILTER_NONE == $t_current ) {
4c79b5
											$t_this_name = lang_get( 'none' );
4c79b5
										} else if ( ( $t_current === 0 ) || ( is_blank( $t_current ) ) || ( META_FILTER_ANY == $t_current ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else if ( META_FILTER_MYSELF == $t_current ) {
4c79b5
											if ( access_has_project_level( config_get( 'handle_bug_threshold' ) ) ) {
4c79b5
												$t_this_name = '[' . lang_get( 'myself' ) . ']';
4c79b5
											} else {
4c79b5
												$t_any_found = true;
4c79b5
											}
4c79b5
										} else {
4c79b5
											$t_this_name = user_get_name( $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_name;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['show_category'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['show_category'] as $t_current ) {
4c79b5
										$t_current = stripslashes( $t_current );
4c79b5
										?>
4c79b5
										<input type="hidden" name="show_category[]" value="<?php echo string_display( $t_current );?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
4c79b5
												|| ( is_blank( $t_current ) ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else {
4c79b5
											$t_this_string = string_display( $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['show_severity'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['show_severity'] as $t_current ) {
4c79b5
										?>
4c79b5
										<input type="hidden" name="show_severity[]" value="<?php echo $t_current;?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current == 0 ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else {
4c79b5
											$t_this_string = get_enum_element( 'severity', $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['show_resolution'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['show_resolution'] as $t_current ) {
4c79b5
										?>
4c79b5
										<input type="hidden" name="show_resolution[]" value="<?php echo $t_current;?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else {
4c79b5
											$t_this_string = get_enum_element( 'resolution', $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['show_profile'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['show_profile'] as $t_current ) {
4c79b5
										?>
4c79b5
										<input type="hidden" name="show_profile[]" value="<?php echo $t_current;?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else {
4c79b5
											$t_profile = profile_get_row_direct( $t_current );
4c79b5
4c79b5
											$t_this_string = "${t_profile['platform']} ${t_profile['os']} ${t_profile['os_build']}";
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			 8 ) {
4c79b5
				echo ' ';
4c79b5
			} ?>
4c79b5
			
4c79b5
4c79b5
		>
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				
4c79b5
					:
4c79b5
				
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
				 
4c79b5
			
4c79b5
			
4c79b5
				 
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			 8 ) {
4c79b5
				echo ' ';
4c79b5
			} ?>
4c79b5
		
4c79b5
4c79b5
		
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['show_status'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['show_status'] as $t_current ) {
4c79b5
										?>
4c79b5
										<input type="hidden" name="show_status[]" value="<?php echo $t_current;?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else {
4c79b5
											$t_this_string = get_enum_element( 'status', $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								if ( 'simple' == $t_view_type ) {
4c79b5
									$t_output = '';
4c79b5
									$t_none_found = false;
4c79b5
									if ( count( $t_filter['hide_status'] ) == 0 ) {
4c79b5
										PRINT lang_get( 'none' );
4c79b5
									} else {
4c79b5
										$t_first_flag = true;
4c79b5
										foreach( $t_filter['hide_status'] as $t_current ) {
4c79b5
											?>
4c79b5
											<input type="hidden" name="hide_status[]" value="<?php echo $t_current;?>" />
4c79b5
											
4c79b5
											$t_this_string = '';
4c79b5
											if ( ( $t_current == META_FILTER_NONE ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
4c79b5
												$t_none_found = true;
4c79b5
											} else {
4c79b5
												$t_this_string = get_enum_element( 'status', $t_current );
4c79b5
											}
4c79b5
											if ( $t_first_flag != true ) {
4c79b5
												$t_output = $t_output . '
';
4c79b5
											} else {
4c79b5
												$t_first_flag = false;
4c79b5
											}
4c79b5
											$t_output = $t_output . $t_this_string;
4c79b5
										}
4c79b5
										$t_hide_status_post = '';
4c79b5
										if ( count( $t_filter['hide_status'] ) == 1 ) {
4c79b5
											$t_hide_status_post = ' (' . lang_get( 'and_above' ) . ')';
4c79b5
										}
4c79b5
										if ( true == $t_none_found ) {
4c79b5
											PRINT lang_get( 'none' );
4c79b5
										} else {
4c79b5
											PRINT $t_output . $t_hide_status_post;
4c79b5
										}
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['show_build'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['show_build'] as $t_current ) {
4c79b5
										$t_current = stripslashes( $t_current );
4c79b5
										?>
4c79b5
										<input type="hidden" name="show_build[]" value="<?php echo string_display( $t_current );?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
4c79b5
												|| ( is_blank( $t_current ) ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else if ( META_FILTER_NONE == $t_current ) {
4c79b5
											$t_this_string = lang_get( 'none' );
4c79b5
										} else {
4c79b5
											$t_this_string = string_display( $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['show_version'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['show_version'] as $t_current ) {
4c79b5
										$t_current = stripslashes( $t_current );
4c79b5
										?>
4c79b5
										<input type="hidden" name="show_version[]" value="<?php echo string_display( $t_current );?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( ( $t_current == META_FILTER_ANY ) && (is_numeric( $t_current ) ) ) 
4c79b5
												|| ( is_blank( $t_current ) ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else if ( META_FILTER_NONE == $t_current ) {
4c79b5
											$t_this_string = lang_get( 'none' );
4c79b5
										} else {
4c79b5
											$t_this_string = string_display( $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['fixed_in_version'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['fixed_in_version'] as $t_current ) {
4c79b5
										$t_current = stripslashes( $t_current );
4c79b5
										?>
4c79b5
										<input type="hidden" name="fixed_in_version[]" value="<?php echo string_display( $t_current );?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
4c79b5
												|| ( is_blank( $t_current ) ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else if ( META_FILTER_NONE == $t_current ) {
4c79b5
											$t_this_string = lang_get( 'none' );
4c79b5
										} else {
4c79b5
											$t_this_string = string_display( $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
				 
4c79b5
			
4c79b5
			
4c79b5
				 
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
              
4c79b5
							  $t_output = '';
4c79b5
                $t_any_found = false;
4c79b5
                if ( count( $t_filter['show_priority'] ) == 0 ) {
4c79b5
                	PRINT lang_get( 'any' );
4c79b5
                } else {
4c79b5
                  $t_first_flag = true;
4c79b5
                  foreach( $t_filter['show_priority'] as $t_current ) {
4c79b5
										?>
4c79b5
										<input type="hidden" name="show_priority[]" value="<?php echo $t_current;?>" />
4c79b5
										
4c79b5
                  	$t_this_string = '';
4c79b5
										if ( ( $t_current === META_FILTER_ANY ) || ( is_blank( $t_current ) ) || ( $t_current === 0 ) ) {
4c79b5
                  		$t_any_found = true;
4c79b5
	                  } else {
4c79b5
	                  	$t_this_string = get_enum_element( 'priority', $t_current );
4c79b5
	                  }
4c79b5
	                  if ( $t_first_flag != true ) {
4c79b5
	                  	$t_output = $t_output . '
';
4c79b5
	                  } else {
4c79b5
	                  	$t_first_flag = false;
4c79b5
	                  }
4c79b5
	                  $t_output = $t_output . $t_this_string;
4c79b5
	                }
4c79b5
	                if ( true == $t_any_found ) {
4c79b5
	                 	PRINT lang_get( 'any' );
4c79b5
	                } else {
4c79b5
	                	PRINT $t_output;
4c79b5
	                }
4c79b5
	               }
4c79b5
	              ?>
4c79b5
	    	
4c79b5
			
4c79b5
							
4c79b5
								$t_output = '';
4c79b5
								$t_any_found = false;
4c79b5
								if ( count( $t_filter['target_version'] ) == 0 ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
									$t_first_flag = true;
4c79b5
									foreach( $t_filter['target_version'] as $t_current ) {
4c79b5
										$t_current = stripslashes( $t_current );
4c79b5
										?>
4c79b5
										<input type="hidden" name="target_version[]" value="<?php echo string_display( $t_current );?>" />
4c79b5
										
4c79b5
										$t_this_string = '';
4c79b5
										if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
4c79b5
												|| ( is_blank( $t_current ) ) ) {
4c79b5
											$t_any_found = true;
4c79b5
										} else if ( META_FILTER_NONE == $t_current ) {
4c79b5
											$t_this_string = lang_get( 'none' );
4c79b5
										} else {
4c79b5
											$t_this_string = string_display( $t_current );
4c79b5
										}
4c79b5
										if ( $t_first_flag != true ) {
4c79b5
											$t_output = $t_output . '
';
4c79b5
										} else {
4c79b5
											$t_first_flag = false;
4c79b5
										}
4c79b5
										$t_output = $t_output . $t_this_string;
4c79b5
									}
4c79b5
									if ( true == $t_any_found ) {
4c79b5
										PRINT lang_get( 'any' );
4c79b5
									} else {
4c79b5
										PRINT $t_output;
4c79b5
									}
4c79b5
								}
4c79b5
							?>
4c79b5
			
4c79b5
			 8 ) {
4c79b5
				echo ' ';
4c79b5
			} ?>
4c79b5
4c79b5
		
4c79b5
4c79b5
		>
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			 8 ) {
4c79b5
				echo ' ';
4c79b5
			} ?>
4c79b5
		
4c79b5
		
4c79b5
			
4c79b5
				
4c79b5
				<input type="hidden" name="per_page" value="<?php echo $t_filter['per_page'];?>" />
4c79b5
			
4c79b5
			
4c79b5
				
4c79b5
				if ( VS_PUBLIC === $t_filter['view_state'] ) {
4c79b5
					PRINT lang_get( 'public' );
4c79b5
				} else if ( VS_PRIVATE === $t_filter['view_state'] ) {
4c79b5
					PRINT lang_get( 'private' );
4c79b5
				} else {
4c79b5
					PRINT lang_get( 'any' );
4c79b5
					$t_filter['view_state'] = META_FILTER_ANY;
4c79b5
				}
4c79b5
				?>
4c79b5
				<input type="hidden" name="view_state" value="<?php echo $t_filter['view_state'];?>" />
4c79b5
			
4c79b5
			
4c79b5
				
4c79b5
					$t_sticky_filter_state = gpc_string_to_bool( $t_filter['sticky_issues'] )  ;
4c79b5
					PRINT ( $t_sticky_filter_state ? lang_get( 'yes' ) : lang_get( 'no' ) );
4c79b5
				?>
4c79b5
				<input type="hidden" name="sticky_issues" value="<?php echo $t_sticky_filter_state ? 'on' : 'off';?>" />
4c79b5
			
4c79b5
			
4c79b5
				
4c79b5
				<input type="hidden" name="highlight_changed" value="<?php echo $t_filter['highlight_changed'];?>" />
4c79b5
			
4c79b5
			
4c79b5
							
4c79b5
							if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ){
4c79b5
								?>
4c79b5
		<script type="text/javascript" language="JavaScript">
4c79b5
		
4c79b5
			function SwitchDateFields() {
4c79b5
		    	// All fields need to be enabled to go back to the script
4c79b5
				document.filters_open.start_month.disabled = ! document.filters_open.do_filter_by_date.checked;
4c79b5
				document.filters_open.start_day.disabled = ! document.filters_open.do_filter_by_date.checked;
4c79b5
				document.filters_open.start_year.disabled = ! document.filters_open.do_filter_by_date.checked;
4c79b5
				document.filters_open.end_month.disabled = ! document.filters_open.do_filter_by_date.checked;
4c79b5
				document.filters_open.end_day.disabled = ! document.filters_open.do_filter_by_date.checked;
4c79b5
				document.filters_open.end_year.disabled = ! document.filters_open.do_filter_by_date.checked;
4c79b5
4c79b5
		   		return true;
4c79b5
			}
4c79b5
		// -->
4c79b5
		</script>
4c79b5
							
4c79b5
							} # end if dhtml_filters
4c79b5
							if ( 'on' == $t_filter['do_filter_by_date'] ) {
4c79b5
								?>
4c79b5
								<input type="hidden" name="do_filter_by_date" value="<?php echo $t_filter['do_filter_by_date'];?>" />
4c79b5
								<input type="hidden" name="start_month" value="<?php echo $t_filter['start_month'];?>" />
4c79b5
								<input type="hidden" name="start_day" value="<?php echo $t_filter['start_day'];?>" />
4c79b5
								<input type="hidden" name="start_year" value="<?php echo $t_filter['start_year'];?>" />
4c79b5
								<input type="hidden" name="end_month" value="<?php echo $t_filter['end_month'];?>" />
4c79b5
								<input type="hidden" name="end_day" value="<?php echo $t_filter['end_day'];?>" />
4c79b5
								<input type="hidden" name="end_year" value="<?php echo $t_filter['end_year'];?>" />
4c79b5
								
4c79b5
								$t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
4c79b5
								$t_time = mktime( 0, 0, 0, $t_filter['start_month'], $t_filter['start_day'], $t_filter['start_year'] );
4c79b5
								foreach( $t_chars as $t_char ) {
4c79b5
									if ( strcasecmp( $t_char, "M" ) == 0 ) {
4c79b5
										PRINT ' ';
4c79b5
										PRINT date( 'F', $t_time );
4c79b5
									}
4c79b5
									if ( strcasecmp( $t_char, "D" ) == 0 ) {
4c79b5
										PRINT ' ';
4c79b5
										PRINT date( 'd', $t_time );
4c79b5
									}
4c79b5
									if ( strcasecmp( $t_char, "Y" ) == 0 ) {
4c79b5
										PRINT ' ';
4c79b5
										PRINT date( 'Y', $t_time );
4c79b5
									}
4c79b5
								}
4c79b5
4c79b5
								PRINT ' - ';
4c79b5
4c79b5
								$t_time = mktime( 0, 0, 0, $t_filter['end_month'], $t_filter['end_day'], $t_filter['end_year'] );
4c79b5
								foreach( $t_chars as $t_char ) {
4c79b5
									if ( strcasecmp( $t_char, "M" ) == 0 ) {
4c79b5
										PRINT ' ';
4c79b5
										PRINT date( 'F', $t_time );
4c79b5
									}
4c79b5
									if ( strcasecmp( $t_char, "D" ) == 0 ) {
4c79b5
										PRINT ' ';
4c79b5
										PRINT date( 'd', $t_time );
4c79b5
									}
4c79b5
									if ( strcasecmp( $t_char, "Y" ) == 0 ) {
4c79b5
										PRINT ' ';
4c79b5
										PRINT date( 'Y', $t_time );
4c79b5
									}
4c79b5
								}
4c79b5
							} else {
4c79b5
								PRINT lang_get( 'no' );
4c79b5
							}
4c79b5
							?>
4c79b5
			
4c79b5
4c79b5
			
4c79b5
							<input type="hidden" name="relationship_type" value="<?php echo $t_filter['relationship_type'];?>" />
4c79b5
							<input type="hidden" name="relationship_bug" value="<?php echo $t_filter['relationship_bug'];?>" />
4c79b5
							
4c79b5
								$c_rel_type = $t_filter['relationship_type'];
4c79b5
								$c_rel_bug = $t_filter['relationship_bug'];
4c79b5
								if ( -1 == $c_rel_type || 0 == $c_rel_bug ) {
4c79b5
									PRINT lang_get( 'any' );
4c79b5
								} else {
4c79b5
								    PRINT relationship_get_description_for_history ($c_rel_type) . ' ' . $c_rel_bug;
4c79b5
								}
4c79b5
4c79b5
							?>
4c79b5
			
4c79b5
			 8 ) {
4c79b5
				echo ' ';
4c79b5
			} ?>
4c79b5
		
4c79b5
		>
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			 8 ) {
4c79b5
				echo ' ';
4c79b5
			} ?>
4c79b5
		
4c79b5
		
4c79b5
			
4c79b5
				
4c79b5
					print_multivalue_field( FILTER_PROPERTY_PLATFORM, $t_filter[FILTER_PROPERTY_PLATFORM] );
4c79b5
				?>
4c79b5
			
4c79b5
			
4c79b5
				
4c79b5
					print_multivalue_field( FILTER_PROPERTY_OS, $t_filter[FILTER_PROPERTY_OS] );
4c79b5
				?>
4c79b5
			
4c79b5
			
4c79b5
				
4c79b5
					print_multivalue_field( FILTER_PROPERTY_OS_BUILD, $t_filter[FILTER_PROPERTY_OS_BUILD] );
4c79b5
				?>
4c79b5
			
4c79b5
			
4c79b5
				
4c79b5
					$t_tag_string = $t_filter['tag_string'];
4c79b5
					if ( $t_filter['tag_select'] != 0 ) {
4c79b5
						$t_tag_string .= ( is_blank( $t_tag_string ) ? '' : config_get( 'tag_separator' ) );
4c79b5
						$t_tag_string .= tag_get_field( $t_filter['tag_select'], 'name' );
4c79b5
					}
4c79b5
					PRINT $t_tag_string 
4c79b5
				?>
4c79b5
				<input type="hidden" name="tag_string" value="<?php echo $t_tag_string ?>"/>
4c79b5
			
4c79b5
		
4c79b5
		
4c79b5
4c79b5
		if ( ON == config_get( 'filter_by_custom_fields' ) ) {
4c79b5
4c79b5
			# -- Custom Field Searching --
4c79b5
4c79b5
			if ( count( $t_accessible_custom_fields_ids ) > 0 ) {
4c79b5
				$t_per_row = config_get( 'filter_custom_fields_per_row' );
4c79b5
				$t_num_fields = count( $t_accessible_custom_fields_ids ) ;
4c79b5
				$t_row_idx = 0;
4c79b5
				$t_col_idx = 0;
4c79b5
4c79b5
				$t_fields = "";
4c79b5
				$t_values = "";
4c79b5
4c79b5
				for ( $i = 0; $i < $t_num_fields; $i++ ) {
4c79b5
					if ( $t_col_idx == 0 ) {
4c79b5
						$t_fields = '';
4c79b5
						$t_values = '';
4c79b5
					}
4c79b5
4c79b5
					if ( isset( $t_accessible_custom_fields_names[ $i ] ) ) {
4c79b5
						$t_fields .= ' ';
4c79b5
						$t_fields .= '';
4c79b5
						$t_fields .= string_display( lang_get_defaulted( $t_accessible_custom_fields_names[$i] ) );
4c79b5
						$t_fields .= '  ';
4c79b5
					}
4c79b5
					$t_output = '';
4c79b5
					$t_any_found = false;
4c79b5
4c79b5
					$t_values .= ' ' ;
4c79b5
					if ( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]] ) ) {
4c79b5
						$t_values .= lang_get( 'any' );
4c79b5
					} else {
4c79b5
						if ( $t_accessible_custom_fields_types[$i] == CUSTOM_FIELD_TYPE_DATE ) {
4c79b5
							# @@@ moved embedded javascript here from print_filter_custom_field_date
4c79b5
							#  it appears not to load properly on Firefox and other browsers if loaded through the httpxmlreq
4c79b5
							$t_field_id = $t_accessible_custom_fields_ids[$i];
4c79b5
							$t_js_toggle_func = "toggle_custom_date_field_" . $t_field_id . "_controls" ;
4c79b5
							if ( ( ON == config_get( 'dhtml_filters' ) ) && ( ON == config_get( 'use_javascript' ) ) ) {
4c79b5
								?>
4c79b5
	<script type="text/javascript" language="JavaScript">
4c79b5
	
4c79b5
	function (disable) {
4c79b5
			document.filters_open.custom_field__start_year.disabled = disable ;
4c79b5
			document.filters_open.custom_field__start_month.disabled = disable ;
4c79b5
			document.filters_open.custom_field__start_day.disabled = disable ;
4c79b5
	} ;
4c79b5
4c79b5
	function (disable) {
4c79b5
			document.filters_open.custom_field__end_year.disabled = disable ;
4c79b5
			document.filters_open.custom_field__end_month.disabled = disable ;
4c79b5
			document.filters_open.custom_field__end_day.disabled = disable ;
4c79b5
	} ;
4c79b5
4c79b5
	function () {
4c79b5
		switch (document.filters_open.custom_field__control.selectedIndex) {
4c79b5
		case :
4c79b5
		case :
4c79b5
			(true) ;
4c79b5
			(true) ;
4c79b5
			break ;
4c79b5
		case :
4c79b5
			(false) ;
4c79b5
			(false) ;
4c79b5
			break ;
4c79b5
		default:
4c79b5
			(false) ;
4c79b5
			(true) ;
4c79b5
			break ;
4c79b5
		}
4c79b5
	}
4c79b5
	// -->
4c79b5
	</script>
4c79b5
4c79b5
							} # end if dhtml_filters
4c79b5
							$t_short_date_format = config_get( 'short_date_format' );
4c79b5
							if ( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] ) ) {
4c79b5
								$t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] = 0;
4c79b5
							}
4c79b5
							$t_start = date( $t_short_date_format, $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][1] );
4c79b5
4c79b5
							if ( !isset( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] ) ) {
4c79b5
								$t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] = 0;
4c79b5
							}
4c79b5
							$t_end = date( $t_short_date_format, $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][2] );
4c79b5
							switch ($t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]][0]) {
4c79b5
							case CUSTOM_FIELD_DATE_ANY:
4c79b5
								$t_values .= lang_get( 'any' ) ;
4c79b5
								break;
4c79b5
							case CUSTOM_FIELD_DATE_NONE:
4c79b5
								$t_values .= lang_get( 'none' ) ;
4c79b5
								break;
4c79b5
							case CUSTOM_FIELD_DATE_BETWEEN:
4c79b5
								$t_values .= lang_get( 'between' ) . '
';
4c79b5
								$t_values .= $t_start . '
' . $t_end;
4c79b5
								break;
4c79b5
							case CUSTOM_FIELD_DATE_ONORBEFORE:
4c79b5
								$t_values .= lang_get( 'on_or_before' ) . '
';
4c79b5
								$t_values .= $t_end;
4c79b5
								break;
4c79b5
							case CUSTOM_FIELD_DATE_BEFORE:
4c79b5
								$t_values .= lang_get( 'before' ) . '
';
4c79b5
								$t_values .= $t_end;
4c79b5
								break;
4c79b5
							case CUSTOM_FIELD_DATE_ON:
4c79b5
								$t_values .= lang_get( 'on' ) . '
';
4c79b5
								$t_values .= $t_start;
4c79b5
								break;
4c79b5
							case CUSTOM_FIELD_DATE_AFTER:
4c79b5
								$t_values .= lang_get( 'after' ) . '
';
4c79b5
								$t_values .= $t_start;
4c79b5
								break ;
4c79b5
							case CUSTOM_FIELD_DATE_ONORAFTER:
4c79b5
								$t_values .= lang_get( 'on_or_after' ) . '
';
4c79b5
								$t_values .= $t_start;
4c79b5
								break ;
4c79b5
							}
4c79b5
						} else {
4c79b5
							$t_first_flag = true;
4c79b5
							foreach( $t_filter['custom_fields'][$t_accessible_custom_fields_ids[$i]] as $t_current ) {
4c79b5
								$t_current = stripslashes( $t_current );
4c79b5
								$t_this_string = '';
4c79b5
								if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
4c79b5
										|| ( is_blank( $t_current ) ) ) {
4c79b5
									$t_any_found = true;
4c79b5
								} else if ( ( META_FILTER_NONE == $t_current ) && ( is_numeric( $t_current ) ) ) {
4c79b5
									$t_this_string = lang_get( 'none' );
4c79b5
								} else {
4c79b5
									$t_this_string = string_display( $t_current );
4c79b5
								}
4c79b5
4c79b5
								if ( $t_first_flag != true ) {
4c79b5
									$t_output = $t_output . '
';
4c79b5
								} else {
4c79b5
									$t_first_flag = false;
4c79b5
								}
4c79b5
4c79b5
								$t_output = $t_output . $t_this_string;
4c79b5
								$t_values .= '<input type="hidden" name="custom_field_'.$t_accessible_custom_fields_ids[$i].'[]" value="'.string_display( $t_current ).'" />';
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						if ( true == $t_any_found ) {
4c79b5
							$t_values .= lang_get( 'any' );
4c79b5
						} else {
4c79b5
							$t_values .= $t_output;
4c79b5
						}
4c79b5
					}
4c79b5
					$t_values .= ' ';
4c79b5
4c79b5
					$t_col_idx++;
4c79b5
4c79b5
					if ( $t_col_idx == $t_per_row ) {
4c79b5
						if ( $t_filter_cols > $t_per_row ) {
4c79b5
							$t_fields .= '  ';
4c79b5
							$t_values .= '  ';
4c79b5
						}
4c79b5
4c79b5
						$t_fields .= '' . "\n";
4c79b5
						$t_values .= '' . "\n";
4c79b5
4c79b5
						echo $t_fields;
4c79b5
						echo $t_values;
4c79b5
4c79b5
						$t_col_idx = 0;
4c79b5
						$t_row_idx++;
4c79b5
					}
4c79b5
				}
4c79b5
4c79b5
4c79b5
				if ( $t_col_idx > 0 ) {
4c79b5
					if ( $t_col_idx < $t_per_row ) {
4c79b5
						$t_fields .= '  ';
4c79b5
						$t_values .= '  ';
4c79b5
					}
4c79b5
4c79b5
					if ( $t_filter_cols > $t_per_row ) {
4c79b5
						$t_fields .= '  ';
4c79b5
						$t_values .= '  ';
4c79b5
					}
4c79b5
4c79b5
					$t_fields .= '' . "\n";
4c79b5
					$t_values .= '' . "\n";
4c79b5
4c79b5
					echo $t_fields;
4c79b5
					echo $t_values;
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
		?>
4c79b5
		
4c79b5
			
4c79b5
				:
4c79b5
			
4c79b5
			
4c79b5
				
4c79b5
					$t_sort_fields = split( ',', $t_filter['sort'] );
4c79b5
					$t_dir_fields = split( ',', $t_filter['dir'] );
4c79b5
4c79b5
					for ( $i=0; $i<2; $i++ ) {
4c79b5
						if ( isset( $t_sort_fields[$i] ) ) {
4c79b5
							if ( 0 < $i ) {
4c79b5
								echo ", ";
4c79b5
							}
4c79b5
							$t_sort = $t_sort_fields[$i];
4c79b5
        					if ( strpos( $t_sort, 'custom_' ) === 0 ) {
4c79b5
        						$t_field_name = string_display( lang_get_defaulted( substr( $t_sort, strlen( 'custom_' ) ) ) );
4c79b5
        					} else {
4c79b5
        						$t_field_name = string_get_field_name( $t_sort );
4c79b5
        					}
4c79b5
4c79b5
							echo $t_field_name . " " . lang_get( 'bugnote_order_' . strtolower( $t_dir_fields[$i] ) );
4c79b5
							echo "<input type=\"hidden\" name=\"sort_$i\" value=\"$t_sort_fields[$i]\" />";
4c79b5
							echo "<input type=\"hidden\" name=\"dir_$i\" value=\"$t_dir_fields[$i]\" />";
4c79b5
						}
4c79b5
					}
4c79b5
				?>
4c79b5
			
4c79b5
			
4c79b5
				if ( 'advanced' == $t_view_type ) {
4c79b5
				?>
4c79b5
					
4c79b5
						:
4c79b5
					
4c79b5
					
4c79b5
						
4c79b5
							$t_output = '';
4c79b5
							if ( !is_array( $t_filter['project_id'] ) ) {
4c79b5
								$t_filter['project_id'] = Array( $t_filter['project_id'] );
4c79b5
							}
4c79b5
							if ( count( $t_filter['project_id'] ) == 0 ) {
4c79b5
								PRINT lang_get( 'current' );
4c79b5
							} else {
4c79b5
								$t_first_flag = true;
4c79b5
								foreach( $t_filter['project_id'] as $t_current ) {
4c79b5
									?>
4c79b5
									<input type="hidden" name="project_id[]" value="<?php echo $t_current;?>" />
4c79b5
									
4c79b5
									$t_this_name = '';
4c79b5
									if ( META_FILTER_CURRENT == $t_current ) {
4c79b5
										$t_this_name = lang_get( 'current' );
4c79b5
									} else {
4c79b5
										$t_this_name = project_get_name( $t_current );
4c79b5
									}
4c79b5
									if ( $t_first_flag != true ) {
4c79b5
										$t_output = $t_output . '
';
4c79b5
									} else {
4c79b5
										$t_first_flag = false;
4c79b5
									}
4c79b5
									$t_output = $t_output . $t_this_name;
4c79b5
								}
4c79b5
								PRINT $t_output;
4c79b5
							}
4c79b5
						?>
4c79b5
					
4c79b5
					
4c79b5
					if ( $t_filter_cols > 6 ) {
4c79b5
						echo ' ';
4c79b5
					}
4c79b5
				} else {
4c79b5
					if ( $t_filter_cols > 3 ) {
4c79b5
						echo ' ';
4c79b5
					}
4c79b5
				} 
4c79b5
			?>
4c79b5
		
4c79b5
		
4c79b5
		} // expanded
4c79b5
		?>
4c79b5
		
4c79b5
			
4c79b5
				
4c79b5
					collapse_icon( 'filter' );
4c79b5
					echo lang_get( 'search' );
4c79b5
				?>:
4c79b5
				<input type="text" size="16" name="search" value="<?php PRINT string_html_specialchars( $t_filter['search'] ); ?>" />
4c79b5
4c79b5
				<input type="submit" name="filter" class="button-small" value="<?php PRINT lang_get( 'filter_button' ) ?>" />
4c79b5
			
4c79b5
			</form>
4c79b5
			 
4c79b5
				
4c79b5
					if ( ON == config_get( 'dhtml_filters' ) ) {
4c79b5
						$f_switch_view_link = 'view_all_set.php?type=6&view_type=';
4c79b5
					} else {
4c79b5
						$f_switch_view_link = 'view_filters_page.php?view_type=';
4c79b5
					}
4c79b5
4c79b5
					if ( ( SIMPLE_ONLY != config_get( 'view_filters' ) ) && ( ADVANCED_ONLY != config_get( 'view_filters' ) ) ) {
4c79b5
						if ( 'advanced' == $t_view_type ) {
4c79b5
							print_bracket_link( $f_switch_view_link . 'simple', lang_get( 'simple_filters' ) );
4c79b5
						} else {
4c79b5
							print_bracket_link( $f_switch_view_link . 'advanced', lang_get( 'advanced_filters' ) );
4c79b5
						}
4c79b5
4c79b5
						print_bracket_link( 
4c79b5
							'permalink_page.php?url=' . urlencode( filter_get_url( $t_filter ) ), 
4c79b5
							lang_get( 'create_filter_link' ), 
4c79b5
							/* new window = */ true );
4c79b5
					}
4c79b5
				?>
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
			$t_stored_queries_arr = array();
4c79b5
			$t_stored_queries_arr = filter_db_get_available_queries();
4c79b5
4c79b5
			if ( count( $t_stored_queries_arr ) > 0 ) {
4c79b5
				?>
4c79b5
					<form method="get" name="list_queries<?php echo $t_form_name_suffix; ?>" action="view_all_set.php">
4c79b5
					<input type="hidden" name="type" value="3" />
4c79b5
					
4c79b5
					if ( ON == config_get( 'use_javascript' ) ) {
4c79b5
						echo "<select name=\"source_query_id\" onchange=\"document.forms.list_queries$t_form_name_suffix.submit();\">";
4c79b5
					} else {
4c79b5
						PRINT '<select name="source_query_id">';
4c79b5
					}
4c79b5
					?>
4c79b5
					<option value="-1"></option>
4c79b5
					<option value="-1"></option>
4c79b5
					
4c79b5
					foreach( $t_stored_queries_arr as $t_query_id => $t_query_name ) {
4c79b5
						PRINT '<option value="' . $t_query_id . '">' . $t_query_name . '</option>';
4c79b5
					}
4c79b5
					?>
4c79b5
					</select>
4c79b5
					<input type="submit" name="switch_to_query_button" class="button-small" value="<?php PRINT lang_get( 'use_query' ) ?>" />
4c79b5
					</form>
4c79b5
					<form method="post" name="open_queries" action="query_view_page.php">
4c79b5
					<input type="submit" name="switch_to_query_button" class="button-small" value="<?php PRINT lang_get( 'open_queries' ) ?>" />
4c79b5
					</form>
4c79b5
				
4c79b5
			} else {
4c79b5
				?>
4c79b5
					<form method="get" name="reset_query" action="view_all_set.php">
4c79b5
					<input type="hidden" name="type" value="3" />
4c79b5
					<input type="hidden" name="source_query_id" value="-1" />
4c79b5
					<input type="submit" name="reset_query_button" class="button-small" value="<?php PRINT lang_get( 'reset_query' ) ?>" />
4c79b5
					</form>
4c79b5
				
4c79b5
			}
4c79b5
4c79b5
			if ( access_has_project_level( config_get( 'stored_query_create_threshold' ) ) ) {
4c79b5
			?>
4c79b5
					<form method="post" name="save_query" action="query_store_page.php">
4c79b5
					<input type="submit" name="save_query_button" class="button-small" value="<?php PRINT lang_get( 'save_query' ) ?>" />
4c79b5
					</form>
4c79b5
			
4c79b5
			} else {
4c79b5
			?>
4c79b5
			
4c79b5
			}
4c79b5
			?>
4c79b5
			
4c79b5
		
4c79b5
		
4c79b5
4c79b5
	}
4c79b5
4c79b5
	# Add a filter to the database for the current user
4c79b5
	function filter_db_set_for_current_user( $p_project_id, $p_is_public,
4c79b5
										$p_name, $p_filter_string ) {
4c79b5
		$t_user_id = auth_get_current_user_id();
4c79b5
		$c_project_id = db_prepare_int( $p_project_id );
4c79b5
		$c_is_public = db_prepare_bool( $p_is_public, false );
4c79b5
		$c_name = db_prepare_string( $p_name );
4c79b5
		$c_filter_string = db_prepare_string( $p_filter_string );
4c79b5
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
4c79b5
		# check that the user can save non current filters (if required)
4c79b5
		if ( ( ALL_PROJECTS <= $c_project_id ) && ( !is_blank( $p_name ) ) &&
4c79b5
		     ( !access_has_project_level( config_get( 'stored_query_create_threshold' ) ) ) ) {
4c79b5
			return -1;
4c79b5
		}
4c79b5
4c79b5
		# ensure that we're not making this filter public if we're not allowed
4c79b5
		if ( !access_has_project_level( config_get( 'stored_query_create_shared_threshold' ) ) ) {
4c79b5
			$c_is_public = db_prepare_bool( false );
4c79b5
		}
4c79b5
4c79b5
		# Do I need to update or insert this value?
4c79b5
		$query = "SELECT id FROM $t_filters_table
4c79b5
					WHERE user_id='$t_user_id'
4c79b5
					AND project_id='$c_project_id'
4c79b5
					AND name='$c_name'";
4c79b5
		$result = db_query( $query );
4c79b5
4c79b5
		if ( db_num_rows( $result ) > 0 ) {
4c79b5
			$row = db_fetch_array( $result );
4c79b5
4c79b5
			$query = "UPDATE $t_filters_table
4c79b5
					  SET is_public='$c_is_public',
4c79b5
					  	filter_string='$c_filter_string'
4c79b5
					  WHERE id='" . $row['id'] . "'";
4c79b5
			db_query( $query );
4c79b5
4c79b5
			return $row['id'];
4c79b5
		} else {
4c79b5
			$query = "INSERT INTO $t_filters_table
4c79b5
						( user_id, project_id, is_public, name, filter_string )
4c79b5
					  VALUES
4c79b5
						( '$t_user_id', '$c_project_id', '$c_is_public', '$c_name', '$c_filter_string' )";
4c79b5
			db_query( $query );
4c79b5
4c79b5
			# Recall the query, we want the filter ID
4c79b5
			$query = "SELECT id
4c79b5
						FROM $t_filters_table
4c79b5
						WHERE user_id='$t_user_id'
4c79b5
						AND project_id='$c_project_id'
4c79b5
						AND name='$c_name'";
4c79b5
			$result = db_query( $query );
4c79b5
4c79b5
			if ( db_num_rows( $result ) > 0 ) {
4c79b5
				$row = db_fetch_array( $result );
4c79b5
				return $row['id'];
4c79b5
			}
4c79b5
4c79b5
			return -1;
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	# We cache filter requests to reduce the number of SQL queries
4c79b5
	$g_cache_filter_db_filters = array();
4c79b5
4c79b5
	# This function will return the filter string that is
4c79b5
	# tied to the unique id parameter. If the user doesn't
4c79b5
	# have permission to see this filter, the function will
4c79b5
	# return null
4c79b5
	function filter_db_get_filter( $p_filter_id, $p_user_id = null ) {
4c79b5
		global $g_cache_filter_db_filters;
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
		$c_filter_id = db_prepare_int( $p_filter_id );
4c79b5
4c79b5
		if ( isset( $g_cache_filter_db_filters[$p_filter_id] ) ) {
4c79b5
			return $g_cache_filter_db_filters[$p_filter_id];
4c79b5
		}
4c79b5
4c79b5
		if ( null === $p_user_id ) {
4c79b5
			$t_user_id = auth_get_current_user_id();
4c79b5
		} else {
4c79b5
			$t_user_id = $p_user_id;
4c79b5
		}
4c79b5
4c79b5
		$query = "SELECT *
4c79b5
				  FROM $t_filters_table
4c79b5
				  WHERE id='$c_filter_id'";
4c79b5
		$result = db_query( $query );
4c79b5
4c79b5
		if ( db_num_rows( $result ) > 0 ) {
4c79b5
			$row = db_fetch_array( $result );
4c79b5
4c79b5
			if ( $row['user_id'] != $t_user_id ) {
4c79b5
				if ( $row['is_public'] != true ) {
4c79b5
					return null;
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			# check that the user has access to non current filters
4c79b5
			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 ) ) ) ) {
4c79b5
				return null;
4c79b5
			}
4c79b5
4c79b5
			$g_cache_filter_db_filters[$p_filter_id] = $row['filter_string'];
4c79b5
			return $row['filter_string'];
4c79b5
		}
4c79b5
4c79b5
		return null;
4c79b5
	}
4c79b5
4c79b5
	function filter_db_get_project_current( $p_project_id, $p_user_id = null ) {
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
		$c_project_id 	= db_prepare_int( $p_project_id );
4c79b5
		$c_project_id 	= $c_project_id * -1;
4c79b5
4c79b5
		if ( null === $p_user_id ) {
4c79b5
			$c_user_id 		= auth_get_current_user_id();
4c79b5
		} else {
4c79b5
			$c_user_id		= db_prepare_int( $p_user_id );
4c79b5
		}
4c79b5
4c79b5
		# we store current filters for each project with a special project index
4c79b5
		$query = "SELECT *
4c79b5
				  FROM $t_filters_table
4c79b5
				  WHERE user_id='$c_user_id'
4c79b5
				  	AND project_id='$c_project_id'
4c79b5
				  	AND name=''";
4c79b5
		$result = db_query( $query );
4c79b5
4c79b5
		if ( db_num_rows( $result ) > 0 ) {
4c79b5
			$row = db_fetch_array( $result );
4c79b5
			return $row['id'];
4c79b5
		}
4c79b5
4c79b5
		return null;
4c79b5
	}
4c79b5
4c79b5
	function filter_db_get_name( $p_filter_id ) {
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
		$c_filter_id = db_prepare_int( $p_filter_id );
4c79b5
4c79b5
		$query = "SELECT *
4c79b5
				  FROM $t_filters_table
4c79b5
				  WHERE id='$c_filter_id'";
4c79b5
		$result = db_query( $query );
4c79b5
4c79b5
		if ( db_num_rows( $result ) > 0 ) {
4c79b5
			$row = db_fetch_array( $result );
4c79b5
4c79b5
			if ( $row['user_id'] != auth_get_current_user_id() ) {
4c79b5
				if ( $row['is_public'] != true ) {
4c79b5
					return null;
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			return $row['name'];
4c79b5
		}
4c79b5
4c79b5
		return null;
4c79b5
	}
4c79b5
4c79b5
	# Will return true if the user can delete this query
4c79b5
	function filter_db_can_delete_filter( $p_filter_id ) {
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
		$c_filter_id = db_prepare_int( $p_filter_id );
4c79b5
		$t_user_id = auth_get_current_user_id();
4c79b5
4c79b5
		# Administrators can delete any filter
4c79b5
		if ( access_has_global_level( ADMINISTRATOR ) ) {
4c79b5
			return true;
4c79b5
		}
4c79b5
4c79b5
		$query = "SELECT id
4c79b5
				  FROM $t_filters_table
4c79b5
				  WHERE id='$c_filter_id'
4c79b5
				  AND user_id='$t_user_id'
4c79b5
				  AND project_id!='-1'";
4c79b5
4c79b5
		$result = db_query( $query );
4c79b5
4c79b5
		if ( db_num_rows( $result ) > 0 ) {
4c79b5
			return true;
4c79b5
		}
4c79b5
4c79b5
		return false;
4c79b5
	}
4c79b5
4c79b5
	function filter_db_delete_filter( $p_filter_id ) {
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
		$c_filter_id = db_prepare_int( $p_filter_id );
4c79b5
		$t_user_id = auth_get_current_user_id();
4c79b5
4c79b5
		if ( !filter_db_can_delete_filter( $c_filter_id ) ) {
4c79b5
			return false;
4c79b5
		}
4c79b5
4c79b5
		$query = "DELETE FROM $t_filters_table
4c79b5
				  WHERE id='$c_filter_id'";
4c79b5
		$result = db_query( $query );
4c79b5
4c79b5
		if ( db_affected_rows( $result ) > 0 ) {
4c79b5
			return true;
4c79b5
		}
4c79b5
4c79b5
		return false;
4c79b5
	}
4c79b5
4c79b5
	function filter_db_delete_current_filters( ) {
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
		$t_all_id = ALL_PROJECTS;
4c79b5
4c79b5
		$query = "DELETE FROM $t_filters_table
4c79b5
					WHERE project_id<='$t_all_id'
4c79b5
					AND name=''";
4c79b5
		$result = db_query( $query );
4c79b5
	}
4c79b5
4c79b5
	function filter_db_get_available_queries( $p_project_id = null, $p_user_id = null ) {
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
		$t_overall_query_arr = array();
4c79b5
4c79b5
		if ( null === $p_project_id ) {
4c79b5
			$t_project_id = helper_get_current_project();
4c79b5
		} else {
4c79b5
			$t_project_id = db_prepare_int( $p_project_id );
4c79b5
		}
4c79b5
4c79b5
		if ( null === $p_user_id ) {
4c79b5
			$t_user_id = auth_get_current_user_id();
4c79b5
		} else {
4c79b5
			$t_user_id = db_prepare_int( $p_user_id );
4c79b5
		}
4c79b5
4c79b5
		# If the user doesn't have access rights to stored queries, just return
4c79b5
		if ( !access_has_project_level( config_get( 'stored_query_use_threshold' ) ) ) {
4c79b5
			return $t_overall_query_arr;
4c79b5
		}
4c79b5
4c79b5
		# Get the list of available queries. By sorting such that public queries are
4c79b5
		# first, we can override any query that has the same name as a private query
4c79b5
		# with that private one
4c79b5
		$query = "SELECT * FROM $t_filters_table
4c79b5
					WHERE (project_id='$t_project_id'
4c79b5
					OR project_id='0')
4c79b5
					AND name!=''
4c79b5
					ORDER BY is_public DESC, name ASC";
4c79b5
		$result = db_query( $query );
4c79b5
		$query_count = db_num_rows( $result );
4c79b5
4c79b5
		for ( $i = 0; $i < $query_count; $i++ ) {
4c79b5
			$row = db_fetch_array( $result );
4c79b5
			if ( ( $row['user_id'] == $t_user_id ) || db_prepare_bool( $row['is_public'] ) ) {
4c79b5
				$t_overall_query_arr[$row['id']] = $row['name'];
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$t_overall_query_arr = array_unique( $t_overall_query_arr );
4c79b5
		asort( $t_overall_query_arr );
4c79b5
4c79b5
		return $t_overall_query_arr;
4c79b5
	}
4c79b5
4c79b5
	# Make sure that our filters are entirely correct and complete (it is possible that they are not).
4c79b5
	# We need to do this to cover cases where we don't have complete control over the filters given.
4c79b5
	function filter_ensure_valid_filter( $p_filter_arr ) {
4c79b5
		# extend current filter to add information passed via POST
4c79b5
		if ( !isset( $p_filter_arr['_version'] ) ) {
4c79b5
			$p_filter_arr['_version'] = config_get( 'cookie_version' );
4c79b5
		}
4c79b5
		$t_cookie_vers = (int) substr( $p_filter_arr['_version'], 1 );
4c79b5
		if ( substr( config_get( 'cookie_version' ), 1 ) > $t_cookie_vers ) { # if the version is old, update it
4c79b5
			$p_filter_arr['_version'] = config_get( 'cookie_version' );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['_view_type'] ) ) {
4c79b5
			$p_filter_arr['_view_type'] = gpc_get_string( 'view_type', 'simple' );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['per_page'] ) ) {
4c79b5
			$p_filter_arr['per_page'] = gpc_get_int( 'per_page', config_get( 'default_limit_view' ) );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['highlight_changed'] ) ) {
4c79b5
			$p_filter_arr['highlight_changed'] = config_get( 'default_show_changed' );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['sticky_issues'] ) ) {
4c79b5
			$p_filter_arr['sticky_issues'] = config_get( 'show_sticky_issues' );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['sort'] ) ) {
4c79b5
			$p_filter_arr['sort'] = "last_updated";
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['dir'] ) ) {
4c79b5
			$p_filter_arr['dir'] = "DESC";
4c79b5
		}
4c79b5
		
4c79b5
		if ( !isset( $p_filter_arr['platform'] ) ) {
4c79b5
			$p_filter_arr['platform'] = array( 0 => META_FILTER_ANY );
4c79b5
		}
4c79b5
4c79b5
		if ( !isset( $p_filter_arr['os'] ) ) {
4c79b5
			$p_filter_arr['os'] = array( 0 => META_FILTER_ANY );
4c79b5
		}
4c79b5
4c79b5
		if ( !isset( $p_filter_arr['os_build'] ) ) {
4c79b5
			$p_filter_arr['os_build'] = array( 0 => META_FILTER_ANY );
4c79b5
		}
4c79b5
4c79b5
		if ( !isset( $p_filter_arr['project_id'] ) ) {
4c79b5
			$p_filter_arr['project_id'] = array( 0 => META_FILTER_CURRENT );
4c79b5
		}
4c79b5
4c79b5
		if ( !isset( $p_filter_arr['start_month'] ) ) {
4c79b5
			$p_filter_arr['start_month'] = gpc_get_string( 'start_month', date( 'm' ) );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['start_day'] ) ) {
4c79b5
			$p_filter_arr['start_day'] = gpc_get_string( 'start_day', 1 );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['start_year'] ) ) {
4c79b5
			$p_filter_arr['start_year'] = gpc_get_string( 'start_year', date( 'Y' ) );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['end_month'] ) ) {
4c79b5
			$p_filter_arr['end_month'] = gpc_get_string( 'end_month', date( 'm' ) );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['end_day'] ) ) {
4c79b5
			$p_filter_arr['end_day'] = gpc_get_string( 'end_day', date( 'd' ) );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['end_year'] ) ) {
4c79b5
			$p_filter_arr['end_year'] = gpc_get_string( 'end_year', date( 'Y' ) );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['search'] ) ) {
4c79b5
			$p_filter_arr['search'] = '';
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['and_not_assigned'] ) ) {
4c79b5
			$p_filter_arr['and_not_assigned'] = gpc_get_bool( 'and_not_assigned', false );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['do_filter_by_date'] ) ) {
4c79b5
			$p_filter_arr['do_filter_by_date'] = gpc_get_bool( 'do_filter_by_date', false );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['view_state'] ) ) {
4c79b5
			$p_filter_arr['view_state'] = gpc_get( 'view_state', '' );
4c79b5
		} else if ( ( $p_filter_arr['view_state'] == 'any' ) || ( $p_filter_arr['view_state'] == 0 ) ) {
4c79b5
			$p_filter_arr['view_state'] = META_FILTER_ANY;
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['relationship_type'] ) ) {
4c79b5
			$p_filter_arr['relationship_type'] = gpc_get_int( 'relationship_type', -1 );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['relationship_bug'] ) ) {
4c79b5
			$p_filter_arr['relationship_bug'] = gpc_get_int( 'relationship_bug', 0 );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['target_version'] ) ) {
4c79b5
			$p_filter_arr['target_version'] = META_FILTER_ANY;
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['tag_string'] ) ) {
4c79b5
			$p_filter_arr['tag_string'] = gpc_get_string( 'tag_string', '' );
4c79b5
		}
4c79b5
		if ( !isset( $p_filter_arr['tag_select'] ) ) {
4c79b5
			$p_filter_arr['tag_select'] = gpc_get_string( 'tag_select', '' );
4c79b5
		}
4c79b5
4c79b5
		$t_custom_fields 		= custom_field_get_ids(); # @@@ (thraxisp) This should really be the linked ids, but we don't know the project
4c79b5
		$f_custom_fields_data 	= array();
4c79b5
		if ( is_array( $t_custom_fields ) && ( sizeof( $t_custom_fields ) > 0 ) ) {
4c79b5
			foreach( $t_custom_fields as $t_cfid ) {
4c79b5
				if ( is_array( gpc_get( 'custom_field_' . $t_cfid, null ) ) ) {
4c79b5
					$f_custom_fields_data[$t_cfid] = gpc_get_string_array( 'custom_field_' . $t_cfid, META_FILTER_ANY );
4c79b5
				} else {
4c79b5
					$f_custom_fields_data[$t_cfid] = gpc_get_string( 'custom_field_' . $t_cfid, META_FILTER_ANY );
4c79b5
					$f_custom_fields_data[$t_cfid] = array( $f_custom_fields_data[$t_cfid] );
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		#validate sorting
4c79b5
		$t_fields = helper_get_columns_to_view();
4c79b5
		$t_n_fields = count( $t_fields );
4c79b5
		for ( $i=0; $i < $t_n_fields; $i++ ) {
4c79b5
			if ( isset( $t_fields[$i] ) && in_array( $t_fields[$i], array( 'selection', 'edit', 'bugnotes_count', 'attachment' ) ) ) {
4c79b5
				unset( $t_fields[$i] );
4c79b5
			}
4c79b5
		}
4c79b5
		$t_sort_fields = split( ',', $p_filter_arr['sort'] );
4c79b5
		$t_dir_fields = split( ',', $p_filter_arr['dir'] );
4c79b5
		for ( $i=0; $i<2; $i++ ) {
4c79b5
			if ( isset( $t_sort_fields[$i] ) ) {
4c79b5
				$t_drop = false;
4c79b5
				$t_sort = $t_sort_fields[$i];
4c79b5
        		if ( strpos( $t_sort, 'custom_' ) === 0 ) {
4c79b5
        			if ( false === custom_field_get_id_from_name( substr( $t_sort, strlen( 'custom_' ) ) ) ) {
4c79b5
        				$t_drop = true;
4c79b5
        			}
4c79b5
        		} else {
4c79b5
        			if ( ! in_array( $t_sort, $t_fields ) ) {
4c79b5
        				$t_drop = true;
4c79b5
        			}
4c79b5
        		}
4c79b5
				if ( ! in_array( $t_dir_fields[$i], array( "ASC", "DESC" ) ) ) {
4c79b5
					$t_drop = true;
4c79b5
				}
4c79b5
				if ( $t_drop ) {
4c79b5
					unset( $t_sort_fields[$i] );
4c79b5
					unset( $t_dir_fields[$i] );
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
		if ( count( $t_sort_fields ) > 0 ) {
4c79b5
			$p_filter_arr['sort'] = implode( ',', $t_sort_fields );
4c79b5
			$p_filter_arr['dir'] = implode( ',', $t_dir_fields );
4c79b5
		} else {
4c79b5
			$p_filter_arr['sort'] = "last_updated";
4c79b5
			$p_filter_arr['dir'] = "DESC";
4c79b5
		}
4c79b5
4c79b5
		# validate or filter junk from other fields
4c79b5
		$t_multi_select_list = array( 'show_category' => 'string',
4c79b5
									  'show_severity' => 'int',
4c79b5
									  'show_status' => 'int',
4c79b5
									  'reporter_id' => 'int',
4c79b5
									  'handler_id' => 'int',
4c79b5
									  'show_resolution' => 'int',
4c79b5
									  'show_priority' => 'int',
4c79b5
									  'show_build' => 'string',
4c79b5
									  'show_version' => 'string',
4c79b5
									  'hide_status' => 'int',
4c79b5
									  'fixed_in_version' => 'string',
4c79b5
									  'target_version' => 'string',
4c79b5
									  'user_monitor' => 'int',
4c79b5
									  'show_profile' => 'int'
4c79b5
									 );
4c79b5
		foreach( $t_multi_select_list as $t_multi_field_name => $t_multi_field_type ) {
4c79b5
			if ( !isset( $p_filter_arr[$t_multi_field_name] ) ) {
4c79b5
				if ( 'hide_status' == $t_multi_field_name ) {
4c79b5
					$p_filter_arr[$t_multi_field_name] = array( config_get( 'hide_status_default' ) );
4c79b5
				} else if ( 'custom_fields' == $t_multi_field_name ) {
4c79b5
					$p_filter_arr[$t_multi_field_name] = array( $f_custom_fields_data );
4c79b5
				} else {
4c79b5
					$p_filter_arr[$t_multi_field_name] = array( META_FILTER_ANY );
4c79b5
				}
4c79b5
			} else {
4c79b5
				if ( !is_array( $p_filter_arr[$t_multi_field_name] ) ) {
4c79b5
					$p_filter_arr[$t_multi_field_name] = array( $p_filter_arr[$t_multi_field_name] );
4c79b5
				}
4c79b5
				$t_checked_array = array();
4c79b5
				foreach ( $p_filter_arr[$t_multi_field_name] as $t_filter_value ) {
4c79b5
					$t_filter_value = stripslashes( $t_filter_value );
4c79b5
					if ( ( $t_filter_value === 'any' ) || ( $t_filter_value === '[any]' ) ) {
4c79b5
						$t_filter_value = META_FILTER_ANY;
4c79b5
					}
4c79b5
					if ( ( $t_filter_value === 'none' ) || ( $t_filter_value === '[none]' ) ) {
4c79b5
						$t_filter_value = META_FILTER_NONE;
4c79b5
					}
4c79b5
					if ( 'string' == $t_multi_field_type ) {
4c79b5
						$t_checked_array[] = db_prepare_string( $t_filter_value );
4c79b5
					} else if ( 'int' == $t_multi_field_type ) {
4c79b5
						$t_checked_array[] = db_prepare_int( $t_filter_value );
4c79b5
					} else if ( 'array' == $t_multi_field_type ) {
4c79b5
						$t_checked_array[] = $t_filter_value;
4c79b5
					}
4c79b5
				}
4c79b5
				$p_filter_arr[$t_multi_field_name] = $t_checked_array;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		if ( is_array( $t_custom_fields ) && ( sizeof( $t_custom_fields ) > 0 ) ) {
4c79b5
			foreach( $t_custom_fields as $t_cfid ) {
4c79b5
				if ( !isset( $p_filter_arr['custom_fields'][$t_cfid] ) ) {
4c79b5
					$p_filter_arr['custom_fields'][$t_cfid] = array( META_FILTER_ANY );
4c79b5
				} else {
4c79b5
					if ( !is_array( $p_filter_arr['custom_fields'][$t_cfid] ) ) {
4c79b5
						$p_filter_arr['custom_fields'][$t_cfid] = array( $p_filter_arr['custom_fields'][$t_cfid] );
4c79b5
					}
4c79b5
					$t_checked_array = array();
4c79b5
					foreach ( $p_filter_arr['custom_fields'][$t_cfid] as $t_filter_value ) {
4c79b5
						$t_filter_value = stripslashes( $t_filter_value );
4c79b5
						if ( ( $t_filter_value === 'any' ) || ( $t_filter_value === '[any]' ) ) {
4c79b5
							$t_filter_value = META_FILTER_ANY;
4c79b5
						}
4c79b5
						$t_checked_array[] = db_prepare_string( $t_filter_value );
4c79b5
					}
4c79b5
					$p_filter_arr['custom_fields'][$t_cfid] = $t_checked_array;
4c79b5
				}
4c79b5
			}
4c79b5
		}
4c79b5
		# all of our filter values are now guaranteed to be there, and correct.
4c79b5
		return $p_filter_arr;
4c79b5
	}
4c79b5
4c79b5
4c79b5
	/**
4c79b5
	 * The following functions each print out an individual filter field.
4c79b5
	 * They are derived from view_filters_page.php
4c79b5
	 *
4c79b5
	 * The functions follow a strict naming convention:
4c79b5
	 *
4c79b5
	 *   print_filter_[filter_name]
4c79b5
	 *
4c79b5
	 * Where [filter_name] is the same as the "name" of the form element for
4c79b5
	 * that filter. This naming convention is depended upon by the controller
4c79b5
	 * at the end of the script.
4c79b5
	 */
4c79b5
	/**
4c79b5
	 * I expect that this code could be made simpler by refactoring into a
4c79b5
	 * class so as to avoid all those calls to global(which are pretty ugly)
4c79b5
	 *
4c79b5
	 * These functions could also be shared by view_filters_page.php
4c79b5
	 *
4c79b5
	 */
4c79b5
	function print_filter_reporter_id(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="reporter_id[]">
4c79b5
		
4c79b5
			# if current user is a reporter, and limited reports set to ON, only display that name
4c79b5
		# @@@ thraxisp - access_has_project_level checks greater than or equal to,
4c79b5
		#   this assumed that there aren't any holes above REPORTER where the limit would apply
4c79b5
		#
4c79b5
			if ( ( ON === config_get( 'limit_reporters' ) ) && ( ! access_has_project_level( REPORTER + 1 ) ) ) {
4c79b5
				$t_id = auth_get_current_user_id();
4c79b5
				$t_username = user_get_field( $t_id, 'username' );
4c79b5
				$t_realname = user_get_field( $t_id, 'realname' );
4c79b5
				$t_display_name = string_attribute( $t_username );
4c79b5
				if ( ( isset( $t_realname ) ) && ( $t_realname > "" ) && ( ON == config_get( 'show_realname' ) ) ){
4c79b5
					$t_display_name = string_attribute( $t_realname );
4c79b5
				}
4c79b5
				PRINT '<option value="' . $t_id . '" selected="selected">' . $t_display_name . '</option>';
4c79b5
			} else {
4c79b5
		?>
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['reporter_id'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
				if ( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) {
4c79b5
					PRINT '
4c79b5
					check_selected( $t_filter['reporter_id'], META_FILTER_MYSELF );
4c79b5
					PRINT '>[' . lang_get( 'myself' ) . ']</option>';
4c79b5
				}
4c79b5
			?>
4c79b5
			
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
4c79b5
	function print_filter_user_monitor(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
	
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="user_monitor[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['user_monitor'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
				if ( access_has_project_level( config_get( 'monitor_bug_threshold' ) ) ) {
4c79b5
					PRINT '
4c79b5
					check_selected( $t_filter['user_monitor'], META_FILTER_MYSELF );
4c79b5
					PRINT '>[' . lang_get( 'myself' ) . ']</option>';
4c79b5
				}
4c79b5
				$t_threshold = config_get( 'show_monitor_list_threshold' );
4c79b5
				$t_has_project_level = access_has_project_level( $t_threshold );
4c79b5
4c79b5
				if ( $t_has_project_level ) {
4c79b5
					print_reporter_option_list( $t_filter['user_monitor'] );
4c79b5
				}
4c79b5
			?>
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_handler_id(){
4c79b5
		global $t_select_modifier, $t_filter, $f_view_type;
4c79b5
		?>
4c79b5
		
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="handler_id[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['handler_id'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
			<option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['handler_id'], META_FILTER_NONE ); ?>>[]</option>
4c79b5
			
4c79b5
				if ( access_has_project_level( config_get( 'handle_bug_threshold' ) ) ) {
4c79b5
					PRINT '
4c79b5
					check_selected( $t_filter['handler_id'], META_FILTER_MYSELF );
4c79b5
					PRINT '>[' . lang_get( 'myself' ) . ']</option>';
4c79b5
				}
4c79b5
			?>
4c79b5
			
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_category(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
		
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="show_category[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_category'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
	
4c79b5
	function print_filter_platform() {
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
4c79b5
		?>
4c79b5
		
4c79b5
		<select <?php echo $t_select_modifier;?> name="platform[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['platform'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
				log_event( LOG_FILTERING, 'Platform = ' . var_export( $t_filter['platform'], true ) );
4c79b5
				print_platform_option_list( $t_filter['platform'] );
4c79b5
			?>
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_os() {
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
4c79b5
		?>
4c79b5
		
4c79b5
		<select <?php echo $t_select_modifier;?> name="os[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['os'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_os_build() {
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
4c79b5
		?>
4c79b5
		
4c79b5
		<select <?php echo $t_select_modifier;?> name="os_build[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['os_build'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_severity(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
			<select <?php PRINT $t_select_modifier;?> name="show_severity[]">
4c79b5
				<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_severity'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
				
4c79b5
			</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_resolution(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
			<select <?php PRINT $t_select_modifier;?> name="show_resolution[]">
4c79b5
				<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_resolution'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
				
4c79b5
			</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_status(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>	
4c79b5
			<select <?php PRINT $t_select_modifier;?> name="show_status[]">
4c79b5
				<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_status'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
				
4c79b5
			</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_hide_status(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
			<select <?php PRINT $t_select_modifier;?> name="hide_status[]">
4c79b5
				<option value="<?php echo META_FILTER_NONE ?>">[]</option>
4c79b5
				
4c79b5
			</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_build(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="show_build[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_build'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			<option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['show_build'], META_FILTER_NONE ); ?>>[]</option>
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_version(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="show_version[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_version'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			<option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['show_version'], META_FILTER_NONE ); ?>>[]</option>
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_fixed_in_version(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="fixed_in_version[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['fixed_in_version'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			<option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['fixed_in_version'], META_FILTER_NONE ); ?>>[]</option>
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_target_version(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="target_version[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['target_version'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			<option value="<?php echo META_FILTER_NONE ?>" <?php check_selected( $t_filter['target_version'], META_FILTER_NONE ); ?>>[]</option>
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_priority(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
    <select <?php PRINT $t_select_modifier;?> name="show_priority[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_priority'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
    </select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_profile() {
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="show_profile[]">
4c79b5
			<option value="<?php echo META_FILTER_ANY ?>" <?php check_selected( $t_filter['show_profile'], META_FILTER_ANY ); ?>>[]</option>
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_per_page(){
4c79b5
		global $t_filter;
4c79b5
		?>
4c79b5
		<input type="text" name="per_page" size="3" maxlength="7" value="<?php echo $t_filter['per_page'] ?>" />
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_view_state(){
4c79b5
		global $t_select_modifier, $t_filter;
4c79b5
		?>
4c79b5
		<select name="view_state">
4c79b5
			
4c79b5
			PRINT '
4c79b5
			check_selected( $t_filter['view_state'], META_FILTER_ANY );
4c79b5
			PRINT '>[' . lang_get( 'any' ) . ']</option>';
4c79b5
			PRINT '
4c79b5
			check_selected( $t_filter['view_state'], VS_PUBLIC );
4c79b5
			PRINT '>' . lang_get( 'public' ) . '</option>';
4c79b5
			PRINT '
4c79b5
			check_selected( $t_filter['view_state'], VS_PRIVATE );
4c79b5
			PRINT '>' . lang_get( 'private' ) . '</option>';
4c79b5
			?>
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_sticky_issues(){
4c79b5
		global $t_filter;
4c79b5
		?>
4c79b5
			<input type="checkbox" name="sticky_issues" <?php check_checked( gpc_string_to_bool( $t_filter['sticky_issues'] ), 'on' ); ?> />
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_highlight_changed(){
4c79b5
		global $t_filter;
4c79b5
		?>
4c79b5
			<input type="text" name="highlight_changed" size="3" maxlength="7" value="<?php echo $t_filter['highlight_changed'] ?>" />
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_do_filter_by_date( $p_hide_checkbox=false ){
4c79b5
		global $t_filter;
4c79b5
		?>
4c79b5
		
4c79b5
		
4c79b5
		?>
4c79b5
		
4c79b5
			<label title="<?php echo lang_get( 'use_date_filters' ); ?>">
4c79b5
			
4c79b5
				check_checked( $t_filter['do_filter_by_date'], 'on' );
4c79b5
				if ( ON == config_get( 'use_javascript' ) ) {
4c79b5
					print "onclick=\"SwitchDateFields();\""; } ?> />
4c79b5
			
4c79b5
			'; ?>
4c79b5
		
4c79b5
		
4c79b5
		$t_menu_disabled = ( 'on' == $t_filter['do_filter_by_date'] ) ? '' : ' disabled ';
4c79b5
		?>
4c79b5
4c79b5
		
4c79b5
		
4c79b5
			
4c79b5
			:
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
			$t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
4c79b5
			foreach( $t_chars as $t_char ) {
4c79b5
				if ( strcasecmp( $t_char, "M" ) == 0 ) {
4c79b5
					print "<select name=\"start_month\" $t_menu_disabled>";
4c79b5
					print_month_option_list( $t_filter['start_month'] );
4c79b5
					print "</select>\n";
4c79b5
				}
4c79b5
				if ( strcasecmp( $t_char, "D" ) == 0 ) {
4c79b5
					print "<select name=\"start_day\" $t_menu_disabled>";
4c79b5
					print_day_option_list( $t_filter['start_day'] );
4c79b5
					print "</select>\n";
4c79b5
				}
4c79b5
				if ( strcasecmp( $t_char, "Y" ) == 0 ) {
4c79b5
					print "<select name=\"start_year\" $t_menu_disabled>";
4c79b5
					print_year_option_list( $t_filter['start_year'] );
4c79b5
					print "</select>\n";
4c79b5
				}
4c79b5
			}
4c79b5
			?>
4c79b5
			
4c79b5
		
4c79b5
		
4c79b5
		
4c79b5
			
4c79b5
			:
4c79b5
			
4c79b5
			
4c79b5
			
4c79b5
			$t_chars = preg_split( '//', config_get( 'short_date_format' ), -1, PREG_SPLIT_NO_EMPTY );
4c79b5
			foreach( $t_chars as $t_char ) {
4c79b5
				if ( strcasecmp( $t_char, "M" ) == 0 ) {
4c79b5
					print "<select name=\"end_month\" $t_menu_disabled>";
4c79b5
					print_month_option_list( $t_filter['end_month'] );
4c79b5
					print "</select>\n";
4c79b5
				}
4c79b5
				if ( strcasecmp( $t_char, "D" ) == 0 ) {
4c79b5
					print "<select name=\"end_day\" $t_menu_disabled>";
4c79b5
					print_day_option_list( $t_filter['end_day'] );
4c79b5
					print "</select>\n";
4c79b5
				}
4c79b5
				if ( strcasecmp( $t_char, "Y" ) == 0 ) {
4c79b5
					print "<select name=\"end_year\" $t_menu_disabled>";
4c79b5
					print_year_option_list( $t_filter['end_year'] );
4c79b5
					print "</select>\n";
4c79b5
				}
4c79b5
			}
4c79b5
			?>
4c79b5
			
4c79b5
		
4c79b5
		
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_relationship_type(){
4c79b5
		global $t_filter;
4c79b5
		$c_reltype_value = $t_filter['relationship_type'];
4c79b5
		if (!$c_reltype_value) {
4c79b5
			$c_reltype_value = -1;
4c79b5
		}
4c79b5
		relationship_list_box ($c_reltype_value, "relationship_type", true); ?>
4c79b5
		<input type="text" name="relationship_bug" size="5" maxlength="10" value="<?php echo $t_filter['relationship_bug']?>" />
4c79b5
		
4c79b5
4c79b5
	}
4c79b5
4c79b5
	function print_filter_tag_string() {
4c79b5
		global $t_filter;
4c79b5
		$t_tag_string = $t_filter['tag_string'];
4c79b5
		if ( $t_filter['tag_select'] != 0 ) {
4c79b5
			$t_tag_string .= ( is_blank( $t_tag_string ) ? '' : config_get( 'tag_separator' ) );
4c79b5
			$t_tag_string .= tag_get_field( $t_filter['tag_select'], 'name' );
4c79b5
		}
4c79b5
		?>
4c79b5
		<input type="hidden" id="tag_separator" value="<?php echo config_get( 'tag_separator' ) ?>" />
4c79b5
		<input type="text" name="tag_string" id="tag_string" size="40" value="<?php echo $t_tag_string ?>" />
4c79b5
		<select <?php echo helper_get_tab_index() ?> name="tag_select" id="tag_select">
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
4c79b5
	function print_filter_custom_field($p_field_id){
4c79b5
		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;
4c79b5
4c79b5
		$j = array_search($p_field_id, $t_accessible_custom_fields_ids);
4c79b5
		if($j === null || $j === false){
4c79b5
			# Note: Prior to PHP 4.2.0, array_search() returns NULL on failure instead of FALSE.
4c79b5
			?>
4c79b5
			
4c79b5
				unknown custom filter (custom )
4c79b5
			
4c79b5
			
4c79b5
		} elseif ( isset( $t_accessible_custom_fields_names[$j] ) ) {
4c79b5
			if ($t_accessible_custom_fields_types[$j] == CUSTOM_FIELD_TYPE_DATE) {
4c79b5
				print_filter_custom_field_date($j, $p_field_id) ;
4c79b5
			} else {
4c79b5
				echo '<select ' . $t_select_modifier . ' name="custom_field_' . $p_field_id .'[]">';
4c79b5
				echo '
4c79b5
				check_selected( $t_filter['custom_fields'][ $p_field_id ], META_FILTER_ANY );
4c79b5
				echo '>[' . lang_get( 'any' ) .']</option>';
4c79b5
				# don't show META_FILTER_NONE for enumerated types as it's not possible for them to be blank
4c79b5
				if ( ! in_array( $t_accessible_custom_fields_types[$j], array( CUSTOM_FIELD_TYPE_ENUM, CUSTOM_FIELD_TYPE_LIST, CUSTOM_FIELD_TYPE_MULTILIST ) ) ) {
4c79b5
					echo '
4c79b5
					check_selected( $t_filter['custom_fields'][ $p_field_id ], META_FILTER_NONE );
4c79b5
					echo '>[' . lang_get( 'none' ) .']</option>';
4c79b5
				}
4c79b5
				foreach( $t_accessible_custom_fields_values[$j] as $t_item ) {
4c79b5
					if ( ( strtolower( $t_item ) !== META_FILTER_ANY ) && ( strtolower( $t_item ) !== META_FILTER_NONE ) ) {
4c79b5
						echo '
4c79b5
						if ( isset( $t_filter['custom_fields'][ $p_field_id ] ) ) {
4c79b5
							check_selected( $t_filter['custom_fields'][ $p_field_id ], $t_item );
4c79b5
						}
4c79b5
						echo '>' . string_shorten( $t_item )  . '</option>' . "\n";
4c79b5
					}
4c79b5
				}
4c79b5
				echo '</select>';
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
	}
4c79b5
4c79b5
	function print_filter_show_sort() {
4c79b5
		global $t_filter;
4c79b5
4c79b5
		# get all of the displayed fields for sort, then drop ones that
4c79b5
		#  are not appropriate and translate the rest
4c79b5
		$t_fields = helper_get_columns_to_view();
4c79b5
		$t_n_fields = count( $t_fields );
4c79b5
		$t_shown_fields[""] = "";
4c79b5
		for ( $i=0; $i < $t_n_fields; $i++ ) {
4c79b5
			if ( !in_array( $t_fields[$i], array( 'selection', 'edit', 'bugnotes_count', 'attachment' ) ) ) {
4c79b5
        		if ( strpos( $t_fields[$i], 'custom_' ) === 0 ) {
4c79b5
        			$t_field_name = string_display( lang_get_defaulted( substr( $t_fields[$i], strlen( 'custom_' ) ) ) );
4c79b5
        		} else {
4c79b5
        			$t_field_name = string_get_field_name( $t_fields[$i] );
4c79b5
        		}
4c79b5
				$t_shown_fields[$t_fields[$i]] = $t_field_name;
4c79b5
			}
4c79b5
		}
4c79b5
		$t_shown_dirs[""] = "";
4c79b5
		$t_shown_dirs["ASC"] = lang_get( 'bugnote_order_asc' );
4c79b5
		$t_shown_dirs["DESC"] = lang_get( 'bugnote_order_desc' );
4c79b5
4c79b5
		# get default values from filter structure
4c79b5
		$t_sort_fields = split( ',', $t_filter['sort'] );
4c79b5
		$t_dir_fields = split( ',', $t_filter['dir'] );
4c79b5
		if ( !isset( $t_sort_fields[1] ) ) {
4c79b5
			$t_sort_fields[1] = '';
4c79b5
			$t_dir_fields[1] = '';
4c79b5
		}
4c79b5
4c79b5
		# if there are fields to display, show the dropdowns
4c79b5
		if ( count( $t_fields ) > 0 ) {
4c79b5
			# display a primary and secondary sort fields
4c79b5
			echo '<select name="sort_0">';
4c79b5
			foreach ( $t_shown_fields as $key => $val ) {
4c79b5
				echo "
4c79b5
				check_selected( $key, $t_sort_fields[0] );
4c79b5
				echo ">$val</option>";
4c79b5
			}
4c79b5
			echo '</select>';
4c79b5
4c79b5
			echo '<select name="dir_0">';
4c79b5
			foreach ( $t_shown_dirs as $key => $val ) {
4c79b5
				echo "
4c79b5
				check_selected( $key, $t_dir_fields[0] );
4c79b5
				echo ">$val</option>";
4c79b5
			}
4c79b5
			echo '</select>';
4c79b5
4c79b5
			echo ', ';
4c79b5
4c79b5
			# for secondary sort
4c79b5
			echo '<select name="sort_1">';
4c79b5
			foreach ( $t_shown_fields as $key => $val ) {
4c79b5
				echo "
4c79b5
				check_selected( $key, $t_sort_fields[1] );
4c79b5
				echo ">$val</option>";
4c79b5
			}
4c79b5
			echo '</select>';
4c79b5
			echo '<select name="dir_1">';
4c79b5
			foreach ($t_shown_dirs as $key => $val ) {
4c79b5
				echo "
4c79b5
				check_selected( $key, $t_dir_fields[1] );
4c79b5
				echo ">$val</option>";
4c79b5
			}
4c79b5
			echo '</select>';
4c79b5
		} else {
4c79b5
			echo lang_get_defaulted( 'last_updated' ) . lang_get( 'bugnote_order_desc' );
4c79b5
			echo "<input type=\"hidden\" name=\"sort_1\" value=\"last_updated\" />";
4c79b5
			echo "<input type=\"hidden\" name=\"dir_1\" value=\"DESC\" />";
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
4c79b5
4c79b5
	function print_filter_custom_field_date($p_field_num, $p_field_id) {
4c79b5
		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;
4c79b5
4c79b5
		$t_js_toggle_func = "toggle_custom_date_field_" . $p_field_id . "_controls" ;
4c79b5
4c79b5
		# Resort the values so there ordered numerically, they are sorted as strings otherwise which
4c79b5
		# may be wrong for dates before early 2001.
4c79b5
		if (is_array($t_accessible_custom_fields_values[$p_field_num]))
4c79b5
		{
4c79b5
			array_multisort($t_accessible_custom_fields_values[$p_field_num], SORT_NUMERIC, SORT_ASC);
4c79b5
		}
4c79b5
4c79b5
		if (isset($t_accessible_custom_fields_values[$p_field_num][0])) {
4c79b5
			$t_sel_start_year = date( 'Y', $t_accessible_custom_fields_values[$p_field_num][0]) ;
4c79b5
		}
4c79b5
		$t_count = count($t_accessible_custom_fields_values[$p_field_num]) ;
4c79b5
		if (isset($t_accessible_custom_fields_values[$p_field_num][$t_count-1])) {
4c79b5
			$t_sel_end_year = date( 'Y', $t_accessible_custom_fields_values[$p_field_num][$t_count-1]) ;
4c79b5
		}
4c79b5
4c79b5
		$t_start = date( 'U' ); # Default to today in filters..
4c79b5
		$t_end = $t_start;
4c79b5
4c79b5
		if ( isset( $t_filter['custom_fields'][$p_field_id][1] ) ) {
4c79b5
			$t_start_time = $t_filter['custom_fields'][$p_field_id][1];
4c79b5
		} else {
4c79b5
			$t_start_time = 0;
4c79b5
		}
4c79b5
4c79b5
		if ( isset( $t_filter['custom_fields'][$p_field_id][2] ) ) {
4c79b5
			$t_end_time = $t_filter['custom_fields'][$p_field_id][2];
4c79b5
		} else {
4c79b5
			$t_end_time = 0;
4c79b5
		}
4c79b5
4c79b5
		$t_start_disable = true;
4c79b5
		$t_end_disable = true;
4c79b5
4c79b5
		// if $t_filter['custom_fields'][$p_field_id][0] is not set (ie no filter), we will drop through the
4c79b5
		// following switch and use the default values above, so no need to check if stuff is set or not.
4c79b5
		switch ($t_filter['custom_fields'][$p_field_id][0]) {
4c79b5
		case CUSTOM_FIELD_DATE_ANY:
4c79b5
		case CUSTOM_FIELD_DATE_NONE:
4c79b5
			break;
4c79b5
		case CUSTOM_FIELD_DATE_BETWEEN:
4c79b5
			$t_start_disable = false;
4c79b5
			$t_end_disable = false;
4c79b5
			$t_start = $t_start_time;
4c79b5
			$t_end = $t_end_time;
4c79b5
			break;
4c79b5
		case CUSTOM_FIELD_DATE_ONORBEFORE:
4c79b5
			$t_start_disable = false;
4c79b5
			$t_start = $t_end_time;
4c79b5
			break;
4c79b5
		case CUSTOM_FIELD_DATE_BEFORE:
4c79b5
			$t_start_disable = false;
4c79b5
			$t_start = $t_end_time;
4c79b5
			break;
4c79b5
		case CUSTOM_FIELD_DATE_ON:
4c79b5
			$t_start_disable = false;
4c79b5
			$t_start = $t_start_time;
4c79b5
			break;
4c79b5
		case CUSTOM_FIELD_DATE_AFTER:
4c79b5
			$t_start_disable = false;
4c79b5
			$t_start = $t_start_time;
4c79b5
			break;
4c79b5
		case CUSTOM_FIELD_DATE_ONORAFTER:
4c79b5
			$t_start_disable = false;
4c79b5
			$t_start = $t_start_time;
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		echo "\n
\n" ;
4c79b5
		echo "<select size=\"1\" name=\"custom_field_" . $p_field_id . "_control\" OnChange=\"" . $t_js_toggle_func . "();\">\n";
4c79b5
		echo '
4c79b5
			check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ANY );
4c79b5
			echo '>' . lang_get( 'any' ) . '</option>' . "\n";
4c79b5
		echo '
4c79b5
			check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_NONE );
4c79b5
			echo '>' . lang_get( 'none' ) . '</option>' . "\n";
4c79b5
		echo '
4c79b5
			check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_BETWEEN );
4c79b5
			echo '>' . lang_get( 'between' ) . '</option>' . "\n";
4c79b5
		echo '
4c79b5
			check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ONORBEFORE );
4c79b5
			echo '>' . lang_get( 'on_or_before' ) . '</option>' . "\n";
4c79b5
		echo '
4c79b5
			check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_BEFORE );
4c79b5
			echo '>' . lang_get( 'before' ) . '</option>' . "\n";
4c79b5
		echo '
4c79b5
			check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ON );
4c79b5
			echo '>' . lang_get( 'on' ) . '</option>' . "\n";
4c79b5
		echo '
4c79b5
			check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_AFTER );
4c79b5
			echo '>' . lang_get( 'after' ) . '</option>' . "\n";
4c79b5
		echo '
4c79b5
			check_selected( $t_filter['custom_fields'][$p_field_id][0], CUSTOM_FIELD_DATE_ONORAFTER	);
4c79b5
			echo '>' . lang_get( 'on_or_after' ) . '</option>' . "\n";
4c79b5
		echo '</select>' . "\n";
4c79b5
4c79b5
		echo "\n";
4c79b5
4c79b5
		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);
4c79b5
		print "\n";
4c79b5
		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);
4c79b5
		print "\n";
4c79b5
	}
4c79b5
4c79b5
	function print_filter_project_id(){
4c79b5
		global $t_select_modifier, $t_filter, $f_view_type;
4c79b5
		?>
4c79b5
		
4c79b5
		<select <?php PRINT $t_select_modifier;?> name="project_id[]">
4c79b5
			<option value="<?php echo META_FILTER_CURRENT ?>" <?php check_selected( $t_filter['project_id'], META_FILTER_CURRENT ); ?>>[]</option>
4c79b5
			
4c79b5
		</select>
4c79b5
		
4c79b5
	}
4c79b5
	
4c79b5
	# Prints a multi-value filter field.  For example, platform, etc.
4c79b5
	# $p_field_name - The name of the field, e.g. "platform"
4c79b5
	# $p_field_value - an array of values.
4c79b5
	function print_multivalue_field( $p_field_name, $p_field_value ) {
4c79b5
		$t_output = '';
4c79b5
		$t_any_found = false;
4c79b5
4c79b5
		if ( count( $p_field_value ) == 0 ) {
4c79b5
			echo lang_get( 'any' );
4c79b5
		} else {
4c79b5
			$t_first_flag = true;
4c79b5
			
4c79b5
			$t_field_value = is_array( $p_field_value ) ? $p_field_value : array( $p_field_value );
4c79b5
4c79b5
			foreach( $t_field_value as $t_current ) {
4c79b5
				$t_current = stripslashes( $t_current );
4c79b5
				?>
4c79b5
				<input type="hidden" name="<?php echo $p_field_name ?>[]" value="<?php echo string_display( $t_current );?>" />
4c79b5
				
4c79b5
				$t_this_string = '';
4c79b5
4c79b5
				if ( ( ( $t_current == META_FILTER_ANY ) && ( is_numeric( $t_current ) ) ) 
4c79b5
						|| ( is_blank( $t_current ) ) ) {
4c79b5
					$t_any_found = true;
4c79b5
				} else {
4c79b5
					$t_this_string = string_display( $t_current );
4c79b5
				}
4c79b5
4c79b5
				if ( $t_first_flag != true ) {
4c79b5
					$t_output .= '
';
4c79b5
				} else {
4c79b5
					$t_first_flag = false;
4c79b5
				}
4c79b5
4c79b5
				$t_output .= $t_this_string;
4c79b5
			}
4c79b5
4c79b5
			if ( true == $t_any_found ) {
4c79b5
				echo lang_get( 'any' );
4c79b5
			} else {
4c79b5
				echo $t_output;
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
4c79b5
	#===================================
4c79b5
	# Caching
4c79b5
	#===================================
4c79b5
4c79b5
	#########################################
4c79b5
	# SECURITY NOTE: cache globals are initialized here to prevent them
4c79b5
	#   being spoofed if register_globals is turned on
4c79b5
4c79b5
	$g_cache_filter = array();
4c79b5
4c79b5
	# --------------------
4c79b5
	# Cache a filter row if necessary and return the cached copy
4c79b5
	# If the second parameter is true (default), trigger an error
4c79b5
	# if the filter can't be found.  If the second parameter is
4c79b5
	# false, return false if the filter can't be found.
4c79b5
	function filter_cache_row( $p_filter_id, $p_trigger_errors=true) {
4c79b5
		global $g_cache_filter;
4c79b5
4c79b5
		$c_filter_id = db_prepare_int( $p_filter_id );
4c79b5
4c79b5
		$t_filters_table = config_get( 'mantis_filters_table' );
4c79b5
4c79b5
		if ( isset ( $g_cache_filter[$c_filter_id] ) ) {
4c79b5
			return $g_cache_filter[$c_filter_id];
4c79b5
		}
4c79b5
4c79b5
		$query = "SELECT *
4c79b5
				  FROM $t_filters_table
4c79b5
				  WHERE id='$c_filter_id'";
4c79b5
		$result = db_query( $query );
4c79b5
4c79b5
		if ( 0 == db_num_rows( $result ) ) {
4c79b5
			if ( $p_trigger_errors ) {
4c79b5
				error_parameters( $p_filter_id );
4c79b5
				trigger_error( ERROR_FILTER_NOT_FOUND, ERROR );
4c79b5
			} else {
4c79b5
				return false;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		$row = db_fetch_array( $result );
4c79b5
4c79b5
		$g_cache_filter[$c_filter_id] = $row;
4c79b5
4c79b5
		return $row;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# Clear the filter cache (or just the given id if specified)
4c79b5
	function filter_clear_cache( $p_filter_id = null ) {
4c79b5
		global $g_cache_filter;
4c79b5
4c79b5
		if ( null === $p_filter_id ) {
4c79b5
			$g_cache_filter = array();
4c79b5
		} else {
4c79b5
			$c_filter_id = db_prepare_int( $p_filter_id );
4c79b5
			unset( $g_cache_filter[$c_filter_id] );
4c79b5
		}
4c79b5
4c79b5
		return true;
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	# return a filter row
4c79b5
	function filter_get_row( $p_filter_id ) {
4c79b5
		return filter_cache_row( $p_filter_id );
4c79b5
	}
4c79b5
4c79b5
	# --------------------
4c79b5
	function filter_get_field( $p_filter_id, $p_field_name ) {
4c79b5
		$row = filter_get_row( $p_filter_id );
4c79b5
4c79b5
		if ( isset( $row[$p_field_name] ) ) {
4c79b5
			return $row[$p_field_name];
4c79b5
		} else {
4c79b5
			error_parameters( $p_field_name );
4c79b5
			trigger_error( ERROR_DB_FIELD_NOT_FOUND, WARNING );
4c79b5
			return '';
4c79b5
		}
4c79b5
	}
4c79b5
	
4c79b5
	# --------------------
4c79b5
	# Checks if a filter value is "any".  Supports both single value as well as multiple value
4c79b5
	# fields (array).
4c79b5
	# $p_filter_value - The value which can be a simple value or an array.
4c79b5
	function _filter_is_any( $p_filter_value ) {
4c79b5
		if ( ( META_FILTER_ANY == $p_filter_value ) && is_numeric( $p_filter_value ) ) {
4c79b5
			return true;
4c79b5
		}
4c79b5
4c79b5
		if ( count( $p_filter_value ) == 0 ) {
4c79b5
			return true;
4c79b5
		}
4c79b5
4c79b5
		foreach( $p_filter_value as $t_value ) {
4c79b5
			if ( ( META_FILTER_ANY == $t_value ) && ( is_numeric( $t_value ) ) ) {
4c79b5
				return true;
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		return false;
4c79b5
	}
4c79b5
?>