Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / return_dynamic_filters.php
bloba56cb69435c3e38bee865bce6b5c66c0c3d4ee8d
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * @package MantisBT
19 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
20 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
21 * @link http://www.mantisbt.org
23 * @uses core.php
24 * @uses authentication_api.php
25 * @uses compress_api.php
26 * @uses config_api.php
27 * @uses constant_inc.php
28 * @uses current_user_api.php
29 * @uses custom_field_api.php
30 * @uses error_api.php
31 * @uses filter_api.php
32 * @uses filter_constants_inc.php
33 * @uses gpc_api.php
34 * @uses helper_api.php
37 require_once( 'core.php' );
38 require_api( 'authentication_api.php' );
39 require_api( 'compress_api.php' );
40 require_api( 'config_api.php' );
41 require_api( 'constant_inc.php' );
42 require_api( 'current_user_api.php' );
43 require_api( 'custom_field_api.php' );
44 require_api( 'error_api.php' );
45 require_api( 'filter_api.php' );
46 require_api( 'filter_constants_inc.php' );
47 require_api( 'gpc_api.php' );
48 require_api( 'helper_api.php' );
50 auth_ensure_user_authenticated();
52 compress_enable();
54 global $t_filter;
55 global $t_select_modifier;
56 $t_filter = current_user_get_bug_filter();
57 $t_filter = filter_ensure_valid_filter( $t_filter );
58 $t_project_id = helper_get_current_project();
59 $t_current_user_access_level = current_user_get_access_level();
60 $t_accessible_custom_fields_ids = array();
61 $t_accessible_custom_fields_names = array();
62 $t_accessible_custom_fields_types = array();
63 $t_accessible_custom_fields_values = array();
64 $t_filter_cols = 7;
65 $t_custom_cols = 1;
66 $t_custom_rows = 0;
68 if ( ON == config_get( 'filter_by_custom_fields' ) ) {
69 $t_custom_cols = config_get( 'filter_custom_fields_per_row' );
70 $t_custom_fields = custom_field_get_linked_ids( $t_project_id );
72 foreach ( $t_custom_fields as $t_cfid ) {
73 $t_field_info = custom_field_cache_row( $t_cfid, true );
74 if ( $t_field_info['access_level_r'] <= $t_current_user_access_level ) {
75 $t_accessible_custom_fields_ids[] = $t_cfid;
76 $t_accessible_custom_fields_names[] = $t_field_info['name'];
77 $t_accessible_custom_fields_types[] = $t_field_info['type'];
78 $t_accessible_custom_fields_values[] = custom_field_distinct_values( $t_field_info, $t_project_id );
82 if ( count( $t_accessible_custom_fields_ids ) > 0 ) {
83 $t_per_row = config_get( 'filter_custom_fields_per_row' );
84 $t_custom_rows = ceil( count( $t_accessible_custom_fields_ids ) / $t_per_row );
88 $f_for_screen = gpc_get_bool( 'for_screen', true );
90 $t_sort = $t_filter[ FILTER_PROPERTY_SORT_FIELD_NAME ];
91 $t_dir = $t_filter[ FILTER_PROPERTY_SORT_DIRECTION ];
92 $t_action = "view_all_set.php?f=3";
94 if ( $f_for_screen == false ) {
95 $t_action = "view_all_set.php";
98 $f_default_view_type = 'simple';
99 if ( ADVANCED_DEFAULT == config_get( 'view_filters' ) ) {
100 $f_default_view_type = 'advanced';
103 $f_view_type = gpc_get_string( 'view_type', $f_default_view_type );
104 if ( ADVANCED_ONLY == config_get( 'view_filters' ) ) {
105 $f_view_type = 'advanced';
107 if ( SIMPLE_ONLY == config_get( 'view_filters' ) ) {
108 $f_view_type = 'simple';
111 $t_select_modifier = '';
112 if ( 'advanced' == $f_view_type ) {
113 $t_select_modifier = 'multiple="multiple" size="10" ';
117 * Prepend headers to the dynamic filter forms that are sent as the response from this page.
119 function return_dynamic_filters_prepend_headers() {
120 if ( !headers_sent() ) {
121 header( 'Content-Type: text/html; charset=utf-8' );
125 $t_filter_target = gpc_get_string( 'filter_target' );
126 $t_functionName = 'print_filter_' . utf8_substr( $t_filter_target, 0, -7 );
127 if ( function_exists( $t_functionName ) ) {
128 return_dynamic_filters_prepend_headers();
129 call_user_func( $t_functionName );
130 } else if ( 'custom_field' == utf8_substr( $t_filter_target, 0, 12 ) ) {
131 # custom function
132 $t_custom_id = utf8_substr( $t_filter_target, 13, -7 );
133 return_dynamic_filters_prepend_headers();
134 print_filter_custom_field( $t_custom_id );
135 } else {
136 $t_plugin_filters = filter_get_plugin_filters();
137 $t_found = false;
138 foreach ( $t_plugin_filters as $t_field_name => $t_filter_object ) {
139 if ( $filter == $t_field_name . '_filter' ) {
140 return_dynamic_filters_prepend_headers();
141 print_filter_plugin_field( $t_field_name, $t_filter_object );
142 $t_found = true;
143 break;
147 if ( !$t_found ) {
148 # error - no function to populate the target (e.g., print_filter_foo)
149 error_parameters( $t_filter_target );
150 trigger_error( ERROR_FILTER_NOT_FOUND, ERROR );