From 01e68c3398d7d64653fd7fa82f1e3825df870830 Mon Sep 17 00:00:00 2001 From: Glenn Henshaw Date: Tue, 30 Dec 2008 22:38:24 -0500 Subject: [PATCH] fix for #9979: Function gpc_isset always return false for a custom date field - add special check for custom date fields --- bug_report.php | 5 +---- bug_update.php | 5 ++--- core/gpc_api.php | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bug_report.php b/bug_report.php index 84009e23aa..07b4021d70 100644 --- a/bug_report.php +++ b/bug_report.php @@ -98,12 +98,9 @@ $t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug_data->project_id ); foreach( $t_related_custom_field_ids as $t_id ) { $t_def = custom_field_get_definition( $t_id ); - $t_cf_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ); - if ( $t_def['require_report'] && ( !gpc_isset( "custom_field_$t_id" ) || empty( $t_cf_value ) ) ) { + if ( $t_def['require_report'] && !gpc_isset_custom_field( $t_id, $t_def['type'] ) ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_EMPTY_FIELD, ERROR ); - } else if ( empty( $t_cf_value ) ) { - $t_cf_value = $t_def['default_value']; } if ( !custom_field_validate( $t_id, $t_cf_value ) ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); diff --git a/bug_update.php b/bug_update.php index 67505fb7ed..107a2a2fc1 100644 --- a/bug_update.php +++ b/bug_update.php @@ -132,14 +132,13 @@ continue; } - $t_cf_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ); - if ( $t_def['require_' . $t_custom_status_label] && ( !gpc_isset( "custom_field_$t_id" ) || empty( $t_cf_value ) ) ) { + if ( $t_def['require_' . $t_custom_status_label] && !gpc_isset_custom_field( $t_id, $t_def['type'] ) ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_EMPTY_FIELD, ERROR ); } # Only update the field if it is posted - if ( !gpc_isset( "custom_field_$t_id" ) ) { + if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) ) { continue; } diff --git a/core/gpc_api.php b/core/gpc_api.php index 632a8a26a5..34963a77b8 100644 --- a/core/gpc_api.php +++ b/core/gpc_api.php @@ -120,6 +120,23 @@ function gpc_get_bool( $p_var_name, $p_default = false ) { # =================================== # Custom Field Functions # =================================== +# see if a custom field variable is set. Uses gpc_isset(). +function gpc_isset_custom_field( $p_var_name, $p_custom_field_type ) { + switch ($p_custom_field_type ) { + case CUSTOM_FIELD_TYPE_DATE: + // date field is three dropdowns that default to 0 + // Dropdowns are always present, so check if they are set + return gpc_isset( "custom_field_" . $p_var_name . "_day" ) && + gpc_get_int( "custom_field_" . $p_var_name . "_day", 0 ) != 0 && + gpc_isset( "custom_field_" . $p_var_name . "_month" ) && + gpc_get_int( "custom_field_" . $p_var_name . "_month", 0 ) != 0 && + gpc_isset( "custom_field_" . $p_var_name . "_year" ) && + gpc_get_int( "custom_field_" . $p_var_name . "_year", 0 ) != 0 ; + default: + return gpc_isset( "custom_field_" . $p_var_name); + } +} + # Retrieve a custom field variable. Uses gpc_get(). # If you pass in *no* default, an error will be triggered if # the variable does not exist @@ -136,7 +153,6 @@ function gpc_get_custom_field( $p_var_name, $p_custom_field_type, $p_default = n if( is_array( $t_values ) ) { return implode( '|', $t_values ); } else { - echo 'not an array'; return ''; } break;