Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / view_filters_page.php
blobee370f03c31f1fb8ced22afdcca668dba932e2f0
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 access_api.php
25 * @uses authentication_api.php
26 * @uses compress_api.php
27 * @uses config_api.php
28 * @uses constant_inc.php
29 * @uses current_user_api.php
30 * @uses custom_field_api.php
31 * @uses filter_api.php
32 * @uses filter_constants_inc.php
33 * @uses gpc_api.php
34 * @uses helper_api.php
35 * @uses html_api.php
36 * @uses lang_api.php
37 * @uses print_api.php
38 * @uses string_api.php
39 * @uses version_api.php
42 require_once( 'core.php' );
43 require_api( 'access_api.php' );
44 require_api( 'authentication_api.php' );
45 require_api( 'compress_api.php' );
46 require_api( 'config_api.php' );
47 require_api( 'constant_inc.php' );
48 require_api( 'current_user_api.php' );
49 require_api( 'custom_field_api.php' );
50 require_api( 'filter_api.php' );
51 require_api( 'filter_constants_inc.php' );
52 require_api( 'gpc_api.php' );
53 require_api( 'helper_api.php' );
54 require_api( 'html_api.php' );
55 require_api( 'lang_api.php' );
56 require_api( 'print_api.php' );
57 require_api( 'string_api.php' );
58 require_api( 'version_api.php' );
60 auth_ensure_user_authenticated();
62 compress_enable();
64 html_page_top();
66 $t_filter = filter_get_default();
67 $t_target_field = rtrim( gpc_get_string( 'target_field', '' ), '[]');
68 if ( !isset( $t_filter[ $t_target_field ] ) ) {
69 $t_target_field = '';
72 if ( ON == config_get( 'use_javascript' ) ) {
74 <body onload="SetInitialFocus();">
76 <script type="text/javascript" language="JavaScript">
77 <!--
78 function SetInitialFocus() {
79 <?php
80 global $t_target_field;
81 if ( $t_target_field ) {
82 $f_view_type = gpc_get_string( 'view_type', '' );
83 if ( ( FILTER_PROPERTY_HIDE_STATUS_ID . '[]' == $t_target_field ) && ( 'advanced' == $f_view_type ) ) {
84 echo 'field_to_focus = "', FILTER_PROPERTY_STATUS_ID, '[]";';
85 } else {
86 echo 'field_to_focus = "', $t_target_field, '";';
88 } else {
89 print "field_to_focus = null;";
92 if ( field_to_focus ) {
93 eval( "document.filters['" + field_to_focus + "'].focus()" );
96 SwitchDateFields();
99 function SwitchDateFields() {
100 // All fields need to be enabled to go back to the script
101 <?php
102 echo 'document.filters.', FILTER_PROPERTY_START_MONTH, '.disabled = ! document.filters.', FILTER_PROPERTY_FILTER_BY_DATE, '.checked;';
103 echo 'document.filters.', FILTER_PROPERTY_START_DAY, '.disabled = ! document.filters.', FILTER_PROPERTY_FILTER_BY_DATE, '.checked;';
104 echo 'document.filters.', FILTER_PROPERTY_START_YEAR, '.disabled = ! document.filters.', FILTER_PROPERTY_FILTER_BY_DATE, '.checked;';
105 echo 'document.filters.', FILTER_PROPERTY_END_MONTH, '.disabled = ! document.filters.', FILTER_PROPERTY_FILTER_BY_DATE, '.checked;';
106 echo 'document.filters.', FILTER_PROPERTY_END_DAY, '.disabled = ! document.filters.', FILTER_PROPERTY_FILTER_BY_DATE, '.checked;';
107 echo 'document.filters.', FILTER_PROPERTY_END_YEAR, '.disabled = ! document.filters.', FILTER_PROPERTY_FILTER_BY_DATE, '.checked;';
110 return true;
112 // -->
113 </script>
115 <?php
118 /** @todo thraxisp - could this be replaced by a call to filter_draw_selection_area2 */
120 $t_filter = current_user_get_bug_filter();
121 $t_filter = filter_ensure_valid_filter( $t_filter );
122 $t_project_id = helper_get_current_project();
124 $t_current_user_access_level = current_user_get_access_level();
125 $t_accessible_custom_fields_ids = array();
126 $t_accessible_custom_fields_names = array();
127 $t_accessible_custom_fields_type = array() ;
128 $t_accessible_custom_fields_values = array();
129 $t_filter_cols = config_get( 'filter_custom_fields_per_row' );
130 $t_custom_cols = 1;
131 $t_custom_rows = 0;
133 #get valid target fields
134 $t_fields = helper_get_columns_to_view();
135 $t_n_fields = count( $t_fields );
136 for ( $i=0; $i < $t_n_fields; $i++ ) {
137 if ( in_array( $t_fields[$i], array( 'selection', 'edit', 'bugnotes_count', 'attachment' ) ) ) {
138 unset( $t_fields[$i] );
142 if ( ON == config_get( 'filter_by_custom_fields' ) ) {
143 $t_custom_cols = $t_filter_cols;
144 $t_custom_fields = custom_field_get_linked_ids( $t_project_id );
146 foreach ( $t_custom_fields as $t_cfid ) {
147 $t_field_info = custom_field_cache_row( $t_cfid, true );
148 if ( $t_field_info['access_level_r'] <= $t_current_user_access_level && $t_field_info['filter_by']) {
149 $t_accessible_custom_fields_ids[] = $t_cfid;
150 $t_accessible_custom_fields_names[] = $t_field_info['name'];
151 $t_accessible_custom_fields_types[] = $t_field_info['type'];
152 $t_accessible_custom_fields_values[] = custom_field_distinct_values( $t_field_info, $t_project_id );
153 $t_fields[] = "custom_" . $t_field_info['name'];
157 if ( count( $t_accessible_custom_fields_ids ) > 0 ) {
158 $t_per_row = config_get( 'filter_custom_fields_per_row' );
159 $t_custom_rows = ceil( count( $t_accessible_custom_fields_ids ) / $t_per_row );
163 if ( !in_array( $t_target_field, $t_fields ) ) {
164 $t_target_field = '';
167 $f_for_screen = gpc_get_bool( 'for_screen', true );
169 $t_action = "view_all_set.php?f=3";
171 if ( $f_for_screen == false ) {
172 $t_action = "view_all_set.php";
175 $f_default_view_type = 'simple';
176 if ( ADVANCED_DEFAULT == config_get( 'view_filters' ) ) {
177 $f_default_view_type = 'advanced';
180 $f_view_type = gpc_get_string( 'view_type', $f_default_view_type );
181 if ( ADVANCED_ONLY == config_get( 'view_filters' ) ) {
182 $f_view_type = 'advanced';
184 if ( SIMPLE_ONLY == config_get( 'view_filters' ) ) {
185 $f_view_type = 'simple';
187 if ( !in_array( $f_view_type, array( 'simple', 'advanced' ) ) ) {
188 $f_view_type = $f_default_view_type;
191 $t_select_modifier = '';
192 if ( 'advanced' == $f_view_type ) {
193 $t_select_modifier = 'multiple="multiple" size="10" ';
196 $t_show_product_version = version_should_show_product_version( $t_project_id );
197 $t_show_build = $t_show_product_version && ( config_get( 'enable_product_build' ) == ON );
199 $t_show_tags = access_has_global_level( config_get( 'tag_view_threshold' ) );
201 <br />
202 <form method="post" name="filters" action="<?php echo $t_action; ?>">
203 <?php # CSRF protection not required here - form does not result in modifications ?>
204 <input type="hidden" name="type" value="1" />
205 <input type="hidden" name="view_type" value="<?php echo $f_view_type; ?>" />
206 <?php
207 if ( $f_for_screen == false ) {
208 print '<input type="hidden" name="print" value="1" />';
209 print '<input type="hidden" name="offset" value="0" />';
212 <table class="width100" cellspacing="1">
213 <tr>
214 <td class="right" colspan="<?php echo ( 8 * $t_custom_cols ); ?>">
215 <?php
216 $f_switch_view_link = 'view_filters_page.php?target_field=' . $t_target_field . '&view_type=';
218 if ( ( SIMPLE_ONLY != config_get( 'view_filters' ) ) && ( ADVANCED_ONLY != config_get( 'view_filters' ) ) ) {
219 if ( 'advanced' == $f_view_type ) {
220 print_bracket_link( $f_switch_view_link . 'simple', lang_get( 'simple_filters' ) );
221 } else {
222 print_bracket_link( $f_switch_view_link . 'advanced', lang_get( 'advanced_filters' ) );
226 </td>
227 </tr>
228 <tr class="row-category2">
229 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'reporter' ) ?></td>
230 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'monitored_by' ) ?></td>
231 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'assigned_to' ) ?></td>
232 <td class="small-caption" colspan="<?php echo ( 2 * $t_custom_cols ); ?>"><?php echo lang_get( 'category' ) ?></td>
233 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'severity' ) ?></td>
234 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'resolution' ) ?></td>
235 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'profile' ) ?></td>
236 <!-- <td colspan="<?php echo ( ( $t_filter_cols - 8 ) * $t_custom_cols ); ?>">&nbsp;</td> -->
237 </tr>
238 <tr class="row-1">
239 <!-- Reporter -->
240 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
241 <?php print_filter_reporter_id(); ?>
242 </td>
243 <!-- Monitored by -->
244 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
245 <?php print_filter_user_monitor(); ?>
246 </td>
247 <!-- Handler -->
248 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
249 <?php print_filter_handler_id(); ?>
250 </td>
251 <!-- Category -->
252 <td valign="top" colspan="<?php echo ( 2 * $t_custom_cols ); ?>">
253 <?php print_filter_show_category(); ?>
254 </td>
255 <!-- Severity -->
256 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
257 <?php print_filter_show_severity(); ?>
258 </td>
259 <!-- Resolution -->
260 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
261 <?php print_filter_show_resolution(); ?>
262 </td>
263 <!-- Profile -->
264 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
265 <?php print_filter_show_profile(); ?>
266 </td>
267 <!-- <td colspan="<?php echo ( ( $t_filter_cols - 8 ) * $t_custom_cols ); ?>">&nbsp;</td> -->
268 </tr>
270 <tr class="row-category2">
271 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'status' ) ?></td>
272 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
273 <?php
274 if ( 'simple' == $f_view_type ) {
275 echo lang_get( 'hide_status' );
276 } else {
277 echo '&nbsp;';
280 </td>
281 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'product_build' ) ?></td>
282 <?php if ( $t_show_product_version ) { ?>
283 <td class="small-caption" colspan="<?php echo ( 2 * $t_custom_cols ); ?>"><?php echo lang_get( 'product_version' ) ?></td>
284 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'fixed_in_version' ) ?></td>
285 <?php } else { ?>
286 <td class="small-caption" colspan="<?php echo ( 2 * $t_custom_cols ); ?>">&nbsp;</td>
287 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">&nbsp;</td>
288 <?php } ?>
289 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'priority' ) ?></td>
290 <?php if ( $t_show_product_version ) { ?>
291 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'target_version' ) ?></td>
292 <?php } else { ?>
293 <td class="small-caption" colspan="<?php echo ( ( $t_filter_cols - 7 ) * $t_custom_cols ); ?>">&nbsp;</td>
294 <?php } ?>
295 </tr>
296 <tr class="row-1">
297 <!-- Status -->
298 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
299 <?php print_filter_show_status(); ?>
300 </td>
301 <!-- Hide Status -->
302 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
303 <?php
304 if ( 'simple' == $f_view_type ) {
305 print_filter_hide_status();
306 } else {
307 echo '&nbsp;';
310 </td>
311 <!-- Build -->
312 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
313 <?php if ( $t_show_build ) {
314 print_filter_show_build();
315 } ?>
316 </td>
317 <!-- Version -->
318 <td valign="top" colspan="<?php echo ( 2 * $t_custom_cols ); ?>">
319 <?php if ( $t_show_product_version ) {
320 print_filter_show_version();
321 } else {
322 echo "&nbsp;";
323 } ?>
324 </td>
325 <!-- Fixed in Version -->
326 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
327 <?php if ( $t_show_product_version ) {
328 print_filter_show_fixed_in_version();
329 } else {
330 echo "&nbsp;";
331 } ?>
332 </td>
333 <!-- Priority -->
334 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
335 <?php print_filter_show_priority(); ?>
336 </td>
337 <!-- Target Version -->
338 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
339 <?php if ( $t_show_product_version ) {
340 print_filter_show_target_version();
341 } else {
342 echo "&nbsp;";
343 } ?>
344 </td>
345 </tr>
347 <tr class="row-category2">
348 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'show' ) ?></td>
349 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'view_status' ) ?></td>
350 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'sticky' ) ?></td>
351 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'changed' ) ?></td>
352 <td class="small-caption" colspan="<?php echo ( 3 * $t_custom_cols ); ?>">
353 <input type="checkbox" name="do_filter_by_date" <?php
354 check_checked( $t_filter['do_filter_by_date'], 'on' );
355 if ( ON == config_get( 'use_javascript' ) ) {
356 print "onclick=\"SwitchDateFields();\""; } ?> />
357 <?php echo lang_get( 'use_date_filters' ) ?>
358 </td>
359 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
360 <?php echo lang_get( 'bug_relationships' ) ?>
361 </td>
362 <!-- <td colspan="<?php echo ( ( $t_filter_cols - 8 ) * $t_custom_cols ); ?>">&nbsp;</td> -->
363 </tr>
364 <tr class="row-2">
365 <!-- Number of bugs per page -->
366 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
367 <?php print_filter_per_page(); ?>
368 </td>
369 <!-- View Status -->
370 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
371 <?php print_filter_view_state(); ?>
372 </td>
373 <!-- Show Sticky bugs -->
374 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
375 <?php print_filter_sticky_issues(); ?>
376 </td>
377 <!-- Highlight changed bugs -->
378 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
379 <?php print_filter_highlight_changed(); ?>
380 </td>
381 <td valign="top" class="left" colspan="<?php echo ( 3 * $t_custom_cols ); ?>">
382 <?php print_filter_do_filter_by_date( true ); # hide checkbox as it's already been shown ?>
383 </td>
384 <td valign="top" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
385 <?php print_filter_relationship_type(); ?>
386 </td>
387 <!-- <td colspan="<?php echo ( ( $t_filter_cols - 8 ) * $t_custom_cols ); ?>">&nbsp;</td> -->
388 </tr>
390 <?php
391 if ( ON == config_get( 'filter_by_custom_fields' ) ) {
393 # -- Custom Field Searching --
394 if ( count( $t_accessible_custom_fields_ids ) > 0 ) {
395 $t_per_row = config_get( 'filter_custom_fields_per_row' );
396 $t_num_rows = ceil( count( $t_accessible_custom_fields_ids ) / $t_per_row );
397 $t_base = 0;
399 for ( $i = 0; $i < $t_num_rows; $i++ ) {
401 <tr class="row-category2">
402 <?php
403 for( $j = 0; $j < $t_per_row; $j++ ) {
404 echo '<td class="small-caption" colspan="' . ( 1 * $t_filter_cols ) . '">';
405 if ( isset( $t_accessible_custom_fields_names[$t_base + $j] ) ) {
406 echo string_display( lang_get_defaulted( $t_accessible_custom_fields_names[$t_base + $j] ) );
407 } else {
408 echo '&nbsp;';
410 echo '</td>';
413 </tr>
414 <tr class="row-2">
415 <?php
416 for ( $j = 0; $j < $t_per_row; $j++ ) {
417 echo '<td colspan="' . ( 1 * $t_filter_cols ) . '">';
418 if ( isset( $t_accessible_custom_fields_ids[$t_base + $j] ) ) {
419 print_filter_custom_field($t_accessible_custom_fields_ids[$t_base + $j]);
420 } else {
421 echo '&nbsp;';
423 echo '</td>';
427 </tr>
428 <?php
429 $t_base += $t_per_row;
434 if ( 'simple' == $f_view_type ) {
435 $t_project_cols = 0;
436 } else {
437 $t_project_cols = 3;
441 <tr class="row-1">
442 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>" valign="top">
443 <?php echo lang_get( 'sort_label' ) ?>
444 </td>
445 <td valign="top" colspan="<?php echo ( ( $t_filter_cols - 1 - $t_project_cols ) * $t_custom_cols ); ?>">
446 <?php
447 print_filter_show_sort();
449 </td>
450 <?php
451 if ( 'advanced' == $f_view_type ) {
453 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>" valign="top">
454 <?php echo lang_get( 'email_project_label' ) ?>
455 </td>
456 <td valign="top" colspan="<?php echo( 2 * $t_custom_cols ); ?>">
457 <?php
458 print_filter_project_id();
460 </td>
461 <?php
464 </tr>
466 <?php
468 # get plugin filters
469 $t_plugin_filters = filter_get_plugin_filters();
470 $t_column = 0;
471 $t_fields = '';
472 $t_row_filters = array();
474 # output a filter form element for each plugin filter
475 foreach( $t_plugin_filters as $t_field_name => $t_filter_object ) {
476 $t_fields .= '<td class="small-caption" valign="top" colspan="' . $t_custom_cols . '"> ' . string_display_line( $t_filter_object->title ) . ' </td>';
477 $t_row_filters[] = $t_field_name;
479 $t_column++;
481 # wrap at the appropriate column
482 if ( $t_column >= $t_filter_cols ) {
483 echo '<tr class="row-category2">', $t_fields, '</tr>';
484 echo '<tr class="row-1">';
485 foreach( $t_row_filters as $t_row_field_name ) {
486 echo '<td class="small-caption" valign="top" colspan="' . $t_custom_cols . '"> ',
487 print_filter_plugin_field( $t_row_field_name, $t_plugin_filters[ $t_row_field_name ] ), '</td>';
489 echo '</tr>';
491 $t_fields = '';
492 $t_row_filters = array();
496 # output any remaining plugin filters
497 if ( $t_column > 0 ) {
498 if ( $t_column < $t_filter_cols ) {
499 $t_fields .= '<td class="small-caption" colspan="' . ( $t_filter_cols - $t_column ) * $t_custom_cols . '">&nbsp;</td>';
502 echo '<tr class="row-category2">', $t_fields, '</tr>';
503 echo '<tr class="row-1">';
504 foreach( $t_row_filters as $t_row_field_name ) {
505 echo '<td class="small-caption" valign="top" colspan="' . $t_custom_cols . '"> ',
506 print_filter_plugin_field( $t_row_field_name, $t_plugin_filters[ $t_row_field_name ] ), '</td>';
509 if ( $t_column < $t_filter_cols ) {
510 echo '<td class="small-caption" colspan="' . ( $t_filter_cols - $t_column ) * $t_custom_cols . '">&nbsp;</td>';
513 echo '</tr>';
518 <tr class="row-category2">
519 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'search' ) ?></td>
520 <td class="small-caption" colspan="<?php echo ( ( $t_filter_cols - 2 ) * $t_custom_cols ); ?>"><?php if ( $t_show_tags ) { echo lang_get( 'tags' ); } ?></td>
521 <td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"></td>
522 </tr>
523 <tr class="row-1">
524 <!-- Search field -->
525 <td colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
526 <input type="text" size="16" name="search" value="<?php echo string_html_specialchars( $t_filter['search'] ); ?>" />
527 </td>
529 <td class="small-caption" colspan="<?php echo ( ( $t_filter_cols - 2 ) * $t_custom_cols ); ?>"><?php if ( $t_show_tags ) { print_filter_tag_string(); } ?></td>
531 <!-- Submit button -->
532 <td class="right" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
533 <input type="submit" name="filter" class="button" value="<?php echo lang_get( 'filter_button' ) ?>" />
534 </td>
535 </tr>
536 </table>
537 </form>
539 <?php
540 html_page_bottom();