Skip to content

Commit

Permalink
Remove use of 'on' and 'off' strings for storing boolean filter states
Browse files Browse the repository at this point in the history
The "sticky issue" and "use date filter" filters are boolean options
that are transmitted via use of 'on' and 'off' strings in the URL.
gpc_get_bool will take these strings and return either true or false (as
a PHP bool type). We were using 'on' and 'off' within filter_api (and
elsewhere) to internally store the state of these two boolean filter
properties.

This has now been replaced with the use of a more sane true/false
representation of the state using a PHP bool type. As a consequence,
checkboxes in the filter UI throughout MantisBT now correctly reflect
the state of the filters as either on/off.
  • Loading branch information
davidhicks committed Feb 25, 2012
1 parent 1652c51 commit 13f67d7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions application/core/filter_api.php
Expand Up @@ -1614,7 +1614,7 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
}

# date filter
if(( 'on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) && is_numeric( $t_filter[FILTER_PROPERTY_START_MONTH] ) && is_numeric( $t_filter[FILTER_PROPERTY_START_DAY] ) && is_numeric( $t_filter[FILTER_PROPERTY_START_YEAR] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_MONTH] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_DAY] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_YEAR] ) ) {
if( $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] && is_numeric( $t_filter[FILTER_PROPERTY_START_MONTH] ) && is_numeric( $t_filter[FILTER_PROPERTY_START_DAY] ) && is_numeric( $t_filter[FILTER_PROPERTY_START_YEAR] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_MONTH] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_DAY] ) && is_numeric( $t_filter[FILTER_PROPERTY_END_YEAR] ) ) {

$t_start_string = $t_filter[FILTER_PROPERTY_START_YEAR] . "-" . $t_filter[FILTER_PROPERTY_START_MONTH] . "-" . $t_filter[FILTER_PROPERTY_START_DAY] . " 00:00:00";
$t_end_string = $t_filter[FILTER_PROPERTY_END_YEAR] . "-" . $t_filter[FILTER_PROPERTY_END_MONTH] . "-" . $t_filter[FILTER_PROPERTY_END_DAY] . " 23:59:59";
Expand Down Expand Up @@ -2822,7 +2822,7 @@ function filter_draw_selection_area2( $p_page_number, $p_for_screen = true, $p_e
</td>
<td class="small-caption" id="do_filter_by_date_filter_target">
<?php
if( 'on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) {
if( $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) {
echo '<input type="hidden" name="', FILTER_PROPERTY_FILTER_BY_DATE, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ), '" />';
echo '<input type="hidden" name="', FILTER_PROPERTY_START_MONTH, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_START_MONTH] ), '" />';
echo '<input type="hidden" name="', FILTER_PROPERTY_START_DAY, '" value="', string_attribute( $t_filter[FILTER_PROPERTY_START_DAY] ), '" />';
Expand Down Expand Up @@ -3745,7 +3745,7 @@ function print_filter_view_state() {
function print_filter_sticky_issues() {
global $t_filter;
?><!-- Show or hide sticky bugs -->
<input type="checkbox" name="<?php echo FILTER_PROPERTY_STICKY;?>"<?php check_checked( gpc_string_to_bool( $t_filter[FILTER_PROPERTY_STICKY] ), true );?> />
<input type="checkbox" name="<?php echo FILTER_PROPERTY_STICKY;?>"<?php check_checked( $t_filter[FILTER_PROPERTY_STICKY] );?> />
<?php
}

Expand All @@ -3771,12 +3771,12 @@ function print_filter_do_filter_by_date( $p_hide_checkbox = false ) {
?>
<tr>
<td colspan="2">
<label><input type="checkbox" id="use_date_filters" name="<?php echo FILTER_PROPERTY_FILTER_BY_DATE ?>"<?php check_checked( $t_filter[FILTER_PROPERTY_FILTER_BY_DATE], 'on' ) ?> /><?php echo lang_get( 'use_date_filters' )?></label>
<label><input type="checkbox" id="use_date_filters" name="<?php echo FILTER_PROPERTY_FILTER_BY_DATE ?>"<?php check_checked( $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) ?> /><?php echo lang_get( 'use_date_filters' )?></label>
</td>
</tr>
<?php
}
$t_menu_disabled = ( !config_get( 'use_javascript' ) || 'on' == $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) ? '' : ' disabled="disabled" ';
$t_menu_disabled = ( !config_get( 'use_javascript' ) || $t_filter[FILTER_PROPERTY_FILTER_BY_DATE] ) ? '' : ' disabled="disabled" ';
?>

<!-- Start date -->
Expand Down
2 changes: 1 addition & 1 deletion public/billing_inc.php
Expand Up @@ -110,7 +110,7 @@
<td class="category" width="25%">
<?php
$t_filter = array();
$t_filter[FILTER_PROPERTY_FILTER_BY_DATE] = 'on';
$t_filter[FILTER_PROPERTY_FILTER_BY_DATE] = true;
$t_filter[FILTER_PROPERTY_START_DAY] = $t_bugnote_stats_from_d;
$t_filter[FILTER_PROPERTY_START_MONTH] = $t_bugnote_stats_from_m;
$t_filter[FILTER_PROPERTY_START_YEAR] = $t_bugnote_stats_from_y;
Expand Down
2 changes: 1 addition & 1 deletion public/bugnote_stats_inc.php
Expand Up @@ -99,7 +99,7 @@
<td class="category" width="25%">
<?php
$t_filter = array();
$t_filter[FILTER_PROPERTY_FILTER_BY_DATE] = 'on';
$t_filter[FILTER_PROPERTY_FILTER_BY_DATE] = true;
$t_filter[FILTER_PROPERTY_START_DAY] = $t_bugnote_stats_from_d;
$t_filter[FILTER_PROPERTY_START_MONTH] = $t_bugnote_stats_from_m;
$t_filter[FILTER_PROPERTY_START_YEAR] = $t_bugnote_stats_from_y;
Expand Down
2 changes: 1 addition & 1 deletion public/view_all_inc.php
Expand Up @@ -173,7 +173,7 @@ function write_bug_rows ( $p_rows )
{
global $t_columns, $t_filter;

$t_in_stickies = ( $t_filter && ( 'on' == $t_filter[FILTER_PROPERTY_STICKY] ) );
$t_in_stickies = ( $t_filter && $t_filter[FILTER_PROPERTY_STICKY] );

# pre-cache custom column data
columns_plugin_cache_issue_data( $p_rows );
Expand Down
6 changes: 3 additions & 3 deletions public/view_all_set.php
Expand Up @@ -360,13 +360,13 @@
}

if ( $f_do_filter_by_date ) {
$f_do_filter_by_date = 'on';
$f_do_filter_by_date = true;
}

if ( $f_sticky_issues ) {
$f_sticky_issues = 'on';
$f_sticky_issues = true;
} else {
$f_sticky_issues = 'off';
$f_sticky_issues = false;
}

if ( $f_type < 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion public/view_filters_page.php
Expand Up @@ -313,7 +313,7 @@
<td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'sticky' ) ?></td>
<td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>"><?php echo lang_get( 'changed' ) ?></td>
<td class="small-caption" colspan="<?php echo ( 3 * $t_custom_cols ); ?>">
<label><input type="checkbox" id="use_date_filters" name="<?php echo FILTER_PROPERTY_FILTER_BY_DATE ?>" <?php check_checked( $t_filter['filter_by_date'], 'on' ) ?> /><?php echo lang_get( 'use_date_filters' )?></label>
<label><input type="checkbox" id="use_date_filters" name="<?php echo FILTER_PROPERTY_FILTER_BY_DATE ?>" <?php check_checked( $t_filter['filter_by_date'] ) ?> /><?php echo lang_get( 'use_date_filters' )?></label>
</td>
<td class="small-caption" colspan="<?php echo ( 1 * $t_custom_cols ); ?>">
<?php echo lang_get( 'bug_relationships' ) ?>
Expand Down

0 comments on commit 13f67d7

Please sign in to comment.