diff -Naurb mantisbt_before_custom_field_checkbox/admin/upgrades/0_18_inc.php mantisbt/admin/upgrades/0_18_inc.php --- mantisbt_before_custom_field_checkbox/admin/upgrades/0_18_inc.php 2004-08-14 21:53:20.000000000 +0200 +++ mantisbt/admin/upgrades/0_18_inc.php 2004-08-18 22:57:17.000000000 +0200 @@ -616,5 +616,34 @@ "Add bugnote_order to user preference table", "ALTER TABLE $t_user_pref_table ADD bugnote_order VARCHAR( 4 ) NOT NULL DEFAULT '" . config_get( 'default_bugnote_order' ) . "' AFTER redirect_delay" ); + $upgrades[] = new FunctionUpgrade( + 'cb_ml_upgrade', + 'Upgrade custom field types (checkbox, list, multilist) to support advanced filtering', + 'upgrade_0_19_checkbox_list_multilist_upgrade' ); + function upgrade_0_19_checkbox_list_multilist_upgrade() { + global $t_custom_field_string_table, $t_custom_field_table; + $t_checkbox = CUSTOM_FIELD_TYPE_CHECKBOX; + $t_multilist = CUSTOM_FIELD_TYPE_MULTILIST; + $query = "SELECT f.field_id, f.bug_id, f.value FROM $t_custom_field_string_table AS f + LEFT JOIN $t_custom_field_table as s ON f.field_id = s.id + WHERE (s.type = $t_checkbox) OR (s.type = $t_multilist)"; + $result = db_query( $query ); + $t_count = db_num_rows( $result ); + for ( $i = 0; $i < $t_count; $i++ ) { + $t_row = db_fetch_array( $result ); + $t_value = $t_row['value']; + if ( '' != $t_value ) { + $t_field_id = $t_row['field_id']; + $t_bug_id = $t_row['bug_id']; + $query = "UPDATE $t_custom_field_string_table + SET value = '|$t_value|' + WHERE (field_id = $t_field_id) AND (bug_id = $t_bug_id)"; + db_query( $query ); + } + } + + return true; + } + return $upgrades; ?> diff -Naurb mantisbt_before_custom_field_checkbox/core/custom_field_api.php mantisbt/core/custom_field_api.php --- mantisbt_before_custom_field_checkbox/core/custom_field_api.php 2004-08-04 19:38:04.000000000 +0200 +++ mantisbt/core/custom_field_api.php 2004-08-18 22:43:52.000000000 +0200 @@ -686,7 +686,7 @@ custom_field_ensure_exists( $p_field_id ); $t_custom_field_table = config_get( 'mantis_custom_field_table' ); - $query = "SELECT access_level_r, default_value + $query = "SELECT access_level_r, default_value, type FROM $t_custom_field_table WHERE id='$c_field_id'"; $result = db_query( $query ); @@ -704,10 +704,10 @@ FROM $t_custom_field_string_table WHERE bug_id='$c_bug_id' AND field_id='$c_field_id'"; - $result = db_query( $query ); + $t_result = db_query( $query ); - if( db_num_rows( $result ) > 0 ) { - return db_result( $result ); + if( db_num_rows( $t_result ) > 0 ) { + return custom_field_database_to_value( db_result( $t_result ) , $row['type'] ); } else { return $t_default_value; } @@ -750,7 +750,7 @@ $t_custom_field_table = config_get( 'mantis_custom_field_table' ); $t_custom_field_string_table = config_get( 'mantis_custom_field_string_table' ); - $query = "SELECT f.name, f.type, f.access_level_r, f.default_value, s.value + $query = "SELECT f.name, f.type, f.access_level_r, f.default_value, f.type, s.value FROM $t_custom_field_project_table AS p, $t_custom_field_table AS f LEFT JOIN $t_custom_field_string_table AS s ON p.field_id=s.field_id AND s.bug_id='$c_bug_id' @@ -769,7 +769,7 @@ if( is_null( $row['value'] ) ) { $t_value = $row['default_value']; } else { - $t_value = $row['value']; + $t_value = custom_field_database_to_value( $row['value'], $row['type'] ); } $t_custom_fields[$row['name']] = array( 'type' => $row['type'], @@ -914,12 +914,45 @@ #=================================== # -------------------- + # Convert the value to save it into the database, depending of the type + # return value for database + function custom_field_value_to_database( $p_value, $p_type ) { + switch ($p_type) { + case CUSTOM_FIELD_TYPE_MULTILIST: + case CUSTOM_FIELD_TYPE_CHECKBOX: + if ( '' == $p_value ) { + $result = ''; + } else { + $result = '|' . $p_value . '|'; + } + break; + default: + $result = $p_value; + } + return $result; + } + + # -------------------- + # Convert the database-value to value, depending of the type + # return value for further operation + function custom_field_database_to_value( $p_value, $p_type ) { + switch ($p_type) { + case CUSTOM_FIELD_TYPE_MULTILIST: + case CUSTOM_FIELD_TYPE_CHECKBOX: + $result = str_replace( '||', '', '|' . $p_value . '|' ); + break; + default: + $result = $p_value; + } + return $result; + } + + # -------------------- # Set the value of a custom field for a given bug # return true on success, false on failure function custom_field_set_value( $p_field_id, $p_bug_id, $p_value ) { $c_field_id = db_prepare_int( $p_field_id ); $c_bug_id = db_prepare_int( $p_bug_id ); - $c_value = db_prepare_string( $p_value ); custom_field_ensure_exists( $p_field_id ); @@ -940,6 +973,8 @@ $t_length_max = $row['length_max']; $t_default_value = $row['default_value']; + $c_value = db_prepare_string( custom_field_value_to_database( $p_value, $t_type ) ); + # check for valid value if ( !is_blank( $t_valid_regexp ) ) { if ( !ereg( $t_valid_regexp, $p_value ) ) { diff -Naurb mantisbt_before_custom_field_checkbox/core/filter_api.php mantisbt/core/filter_api.php --- mantisbt_before_custom_field_checkbox/core/filter_api.php 2004-08-14 21:53:20.000000000 +0200 +++ mantisbt/core/filter_api.php 2004-08-18 23:00:34.000000000 +0200 @@ -418,6 +418,7 @@ $t_any_found = true; } if ( !$t_any_found ) { + $t_def = custom_field_get_definition( $t_cfid ); $t_table_name = $t_custom_field_string_table . '_' . $t_cfid; array_push( $t_join_clauses, "LEFT JOIN $t_custom_field_string_table as $t_table_name ON $t_table_name.bug_id = $t_bug_table.id" ); foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) { @@ -432,8 +433,19 @@ $t_custom_where_clause .= ' OR '; } - $t_custom_where_clause .= "( $t_table_name.field_id = $t_cfid AND $t_table_name.value = '"; - $t_custom_where_clause .= db_prepare_string( trim( $t_filter_member ) ) . "' )"; + $t_custom_where_clause .= "( $t_table_name.field_id = $t_cfid AND $t_table_name.value "; + switch( $t_def['type'] ) { + case CUSTOM_FIELD_TYPE_MULTILIST: + case CUSTOM_FIELD_TYPE_CHECKBOX: + $t_custom_where_clause .= "LIKE '%"; + $t_custom_where_clause_closing = "%' )"; + break; + default: + $t_custom_where_clause .= "= '"; + $t_custom_where_clause_closing = "' )"; + } + $t_custom_where_clause .= db_prepare_string( trim( $t_filter_member ) ); + $t_custom_where_clause .= $t_custom_where_clause_closing; } } if ( !is_blank( $t_custom_where_clause ) ) {