Mantis

LongCF/Date doesn't validate

Posted by bartik 
LongCF/Date doesn't validate
March 10, 2009 07:27PM
Hello,

I don't know if it was already mentioned here but there is a problem with the date field. If you define a custom variable with the type date it seems to never get changed/updated (at least for me). The problem is that mantis is checking the existence of the POST variable with isset in gpc_api.php with isset( $_POST[$p_var_name] ) the problem is that the date custom variable POSTs the day,month and year separately therefore using the $p_var_name."_day" etc. variable names. So to get it working you should change the check to something like if ( isset( $_POST[$p_var_name] ) || isset( $_POST[$p_var_name."_day"] )) { The other thing which is a bit bothersome is that when the date custom field is not filled in in the report the gpc_get_custom_field returns for the case CUSTOM_FIELD_TYPE_DATE: an empty string return '' which the application doesn't seem to like and gives a warrning about incorrect value (this is in case when the $p_default is not specified). The solution at least for me was not to return empty string but the time return time(); so the changed functions are:

	function gpc_get_custom_field( $p_var_name, $p_custom_field_type, $p_default = null ) {
		switch ($p_custom_field_type ) {
			case CUSTOM_FIELD_TYPE_MULTILIST:
			case CUSTOM_FIELD_TYPE_CHECKBOX:
			    // ensure that the default is an array, if it is set
			    if ( ($p_default !== NULL) && (!is_array($p_default)) ) {
			        $p_default = array( $p_default );
			    }
				$t_values = gpc_get_string_array( $p_var_name, $p_default );
				if( is_array( $t_values ) ) {
					return implode( '|', $t_values );
				} else {
					return '';
				}
				break ;
			case CUSTOM_FIELD_TYPE_DATE:
				$t_day = gpc_get_int( $p_var_name . "_day", 0) ;
				$t_month = gpc_get_int( $p_var_name . "_month", 0) ;
				$t_year = gpc_get_int( $p_var_name . "_year", 0) ;
				if (($t_year == 0) || ($t_month == 0) || ($t_day == 0)) {
					if ($p_default == null) {
						return time() ;
					} else {
						return $p_default ;
					}
				} else {
					return strtotime($t_year . "-" . $t_month . "-" . $t_day) ;
				}
				break ;
			default:
				return gpc_get_string( $p_var_name, $p_default);
		}
	}


	function gpc_isset( $p_var_name ) {
		if ( isset( $_POST[$p_var_name] ) || isset( $_POST[$p_var_name."_day"] )) {
			return true;
		} else if ( isset( $_GET[$p_var_name] ) ) {
			return true;
		}
		file_put_contents ('/tmp/bartalp_mantis.log',
			date('YmdHis&#039winking smiley.":".__FILE__.":".__FUNCTION__.":".__LINE__.":p_var_name = $p_var_name\n", FILE_APPEND );
		return false;
	}

bartik

PS: just ignore me if it was already solved.

Mantis 1.1.6
Pluginmanager 0.4.0
LongCF 0.4.0
Sorry, only registered users may post in this forum.

Click here to login



Online Users

Guests: 7
Record Number of Users: 1 on April 02, 2023
Record Number of Guests: 115 on November 09, 2023
Top Users
Hébergeur : Morinie.Fr