? .cvsignore ? packages ? test.php ? core/.cvsignore Index: bug_change_status_page.php =================================================================== RCS file: /apps/mantis/bug_change_status_page.php,v retrieving revision 1.2 diff -u -r1.2 bug_change_status_page.php --- bug_change_status_page.php 24 Jul 2007 22:28:32 -0000 1.2 +++ bug_change_status_page.php 26 Jul 2007 22:02:11 -0000 @@ -164,20 +164,12 @@ $t_custom_status_label = "closed"; } -$t_related_custom_field_ids = custom_field_get_linked_ids( bug_get_field( $f_bug_id, 'project_id' ) ); +$t_related_custom_field_ids = custom_field_get_linked_status_ids( bug_get_field( $f_bug_id, 'project_id' ), $f_new_status ); foreach( $t_related_custom_field_ids as $t_id ) { - $t_def = custom_field_get_definition( $t_id ); - $t_display = $t_def['display_' . $t_custom_status_label]; - $t_require = $t_def['require_' . $t_custom_status_label]; - - if ( ( "update" == $t_custom_status_label ) && ( ! $t_require ) ) { - continue; - } - if ( in_array( $t_custom_status_label, array( "resolved", "closed" ) ) && ! ( $t_display || $t_require ) ) { - continue; - } - if ( custom_field_has_write_access( $t_id, $f_bug_id ) ) { + $t_def = custom_field_get_definition( $t_id[0] ); + $t_require = $t_id[1]; + if ( custom_field_has_write_access( $t_id[0], $f_bug_id ) ) { ?> > @@ -190,15 +182,15 @@ > - + > - * + * Index: bug_report_page.php =================================================================== RCS file: /apps/mantis/bug_report_page.php,v retrieving revision 1.2 diff -u -r1.2 bug_report_page.php --- bug_report_page.php 24 Jul 2007 22:28:33 -0000 1.2 +++ bug_report_page.php 26 Jul 2007 23:47:25 -0000 @@ -252,15 +252,15 @@ > - + * Index: bug_update.php =================================================================== RCS file: /apps/mantis/bug_update.php,v retrieving revision 1.2 diff -u -r1.2 bug_update.php --- bug_update.php 24 Jul 2007 22:28:33 -0000 1.2 +++ bug_update.php 26 Jul 2007 22:11:01 -0000 @@ -93,18 +93,10 @@ $t_custom_status_label = "closed"; } - $t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug_data->project_id ); + $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_bug_data->project_id, $f_new_status ); foreach( $t_related_custom_field_ids as $t_id ) { - $t_def = custom_field_get_definition( $t_id ); - $t_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], null ); - - # Only update the field if it would have been display for editing - if( !( ( ! $f_update_mode && $t_def['require_' . $t_custom_status_label] ) || - ( ! $f_update_mode && $t_def['display_' . $t_custom_status_label] && in_array( $t_custom_status_label, array( "resolved", "closed" ) ) ) || - ( $f_update_mode && $t_def['display_update'] ) || - ( $f_update_mode && $t_def['require_update'] ) ) ) { - continue; - } + $t_def = custom_field_get_definition( $t_id[0] ); + $t_custom_field_value = gpc_get_custom_field( "custom_field_".$t_id[0], $t_def['type'], null ); # Only update the field if it is posted # ( will fail in custom_field_set_value(), if it was required ) @@ -113,16 +105,16 @@ } # Do not set custom field value if user has no write access. - if( !custom_field_has_write_access( $t_id, $f_bug_id ) ) { + if( !custom_field_has_write_access( $t_id[0], $f_bug_id ) ) { continue; } - if ( $t_def['require_' . $t_custom_status_label] && ( gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ) == '' ) ) { - error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); + if ( $t_id[1] && ( gpc_get_custom_field( "custom_field_".$t_id[0], $t_def['type'], '' ) == '' ) ) { + error_parameters( lang_get_defaulted( custom_field_get_field( $t_id[0], 'name' ) ) ); trigger_error( ERROR_EMPTY_FIELD, ERROR ); } - if ( !custom_field_set_value( $t_id, $f_bug_id, $t_custom_field_value ) ) { - error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); + if ( !custom_field_set_value( $t_id[0], $f_bug_id, $t_custom_field_value ) ) { + error_parameters( lang_get_defaulted( custom_field_get_field( $t_id[0], 'name' ) ) ); trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); } } Index: bug_update_advanced_page.php =================================================================== RCS file: /apps/mantis/bug_update_advanced_page.php,v retrieving revision 1.2 diff -u -r1.2 bug_update_advanced_page.php --- bug_update_advanced_page.php 24 Jul 2007 22:28:33 -0000 1.2 +++ bug_update_advanced_page.php 26 Jul 2007 23:55:36 -0000 @@ -444,15 +444,15 @@ project_id ); + $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_bug->project_id, $t_bug->status ); foreach( $t_related_custom_field_ids as $t_id ) { - $t_def = custom_field_get_definition( $t_id ); - if( ( $t_def['display_update'] || $t_def['require_update']) && custom_field_has_write_access( $t_id, $f_bug_id ) ) { + $t_def = custom_field_get_definition( $t_id[0] ); + if( custom_field_has_write_access( $t_id[0], $f_bug_id ) ) { $t_custom_fields_found = true; ?> > - * + * project_id ); + $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_bug->project_id, $t_bug->status ); foreach( $t_related_custom_field_ids as $t_id ) { - $t_def = custom_field_get_definition( $t_id ); - if( ( ( $t_def['display_update'] && !$t_def['advanced'] ) || $t_def['require_update']) && custom_field_has_write_access( $t_id, $f_bug_id ) ) { + $t_def = custom_field_get_definition( $t_id[0] ); + if( ( ( !$t_def['advanced'] ) || $t_id[1]) && custom_field_has_write_access( $t_id[0], $f_bug_id ) ) { $t_custom_fields_found = true; ?> > - * + * > - > - - - - - > - - - > - - - - - > - - - > - - - - - > - - - > - - - - - > - - - > - - - - - > - - - > - - - - - > - - - > - - - - - > - - - > - - - - - > - - - -   - + +

+ + + + + + + + + + + + $t_label ) { +?> + > + + + + + + + + Index: manage_custom_field_update.php =================================================================== RCS file: /apps/mantis/manage_custom_field_update.php,v retrieving revision 1.2 diff -u -r1.2 manage_custom_field_update.php --- manage_custom_field_update.php 24 Jul 2007 22:28:36 -0000 1.2 +++ manage_custom_field_update.php 26 Jul 2007 22:17:42 -0000 @@ -42,6 +42,21 @@ custom_field_update( $f_field_id, $t_values ); + # For each status value, look for the assigned value from the page and + # store it in an array + $t_status_display = array(); + $t_enum_status = config_get( 'status_enum_string' ); + $t_status_arr = get_enum_to_array( $t_enum_status ); + foreach ( $t_status_arr as $t_status => $t_label ) { + $t_status_display_val = gpc_get_int('status_'.$t_status, 0); + if( $t_status_display_val > 0 ) { + array_push( $t_status_display, array( $t_status, $t_status_display_val ) ) ; + } + } + + # Update the custom field status display values + custom_field_status_update( $f_field_id, $t_status_display ); + html_page_top1(); html_meta_redirect( $f_return ); Index: admin/db_stats.php =================================================================== RCS file: /apps/mantis/admin/db_stats.php,v retrieving revision 1.2 diff -u -r1.2 db_stats.php --- admin/db_stats.php 24 Jul 2007 22:28:41 -0000 1.2 +++ admin/db_stats.php 26 Jul 2007 22:19:05 -0000 @@ -47,6 +47,7 @@ print_table_stats( config_get( 'mantis_config_table' ) ); print_table_stats( config_get( 'mantis_custom_field_project_table' ) ); print_table_stats( config_get( 'mantis_custom_field_string_table' ) ); + print_table_stats( config_get( 'mantis_custom_field_status_table' ) ); print_table_stats( config_get( 'mantis_custom_field_table' ) ); print_table_stats( config_get( 'mantis_filters_table' ) ); print_table_stats( config_get( 'mantis_news_table' ) ); Index: admin/db_table_names_inc.php =================================================================== RCS file: /apps/mantis/admin/db_table_names_inc.php,v retrieving revision 1.2 diff -u -r1.2 db_table_names_inc.php --- admin/db_table_names_inc.php 24 Jul 2007 22:28:41 -0000 1.2 +++ admin/db_table_names_inc.php 26 Jul 2007 22:19:53 -0000 @@ -30,6 +30,7 @@ $t_user_print_pref_table = config_get_global( 'mantis_user_print_pref_table' ); $t_custom_field_project_table = config_get_global( 'mantis_custom_field_project_table' ); $t_custom_field_table = config_get_global( 'mantis_custom_field_table' ); + $t_custom_field_status_table = config_get_global( 'mantis_custom_field_status_table' ); $t_custom_field_string_table = config_get_global( 'mantis_custom_field_string_table' ); $t_upgrade_table = config_get_global( 'mantis_upgrade_table' ); $t_filters_table = config_get_global( 'mantis_filters_table' ); Index: admin/schema.php =================================================================== RCS file: /apps/mantis/admin/schema.php,v retrieving revision 1.2 diff -u -r1.2 schema.php --- admin/schema.php 24 Jul 2007 22:28:42 -0000 1.2 +++ admin/schema.php 26 Jul 2007 22:20:47 -0000 @@ -145,6 +145,12 @@ ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS'))); $upgrade[] = Array('CreateIndexSQL',Array('idx_custom_field_bug',config_get('mantis_custom_field_string_table'),'bug_id')); +$upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_custom_field_status_table')," + field_id I NOTNULL PRIMARY DEFAULT '0', + status_id I NOTNULL PRIMARY DEFAULT '0', + require L NOTNULL DEFAULT '0' +",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS'))); + $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_custom_field_table')," id I NOTNULL PRIMARY AUTOINCREMENT, name C(64) NOTNULL DEFAULT \" '' \", Index: core/custom_field_api.php =================================================================== RCS file: /apps/mantis/core/custom_field_api.php,v retrieving revision 1.2 diff -u -r1.2 custom_field_api.php --- core/custom_field_api.php 24 Jul 2007 22:28:44 -0000 1.2 +++ core/custom_field_api.php 26 Jul 2007 22:22:32 -0000 @@ -466,6 +466,41 @@ # db_query() errors on failure so: return true; } + + # -------------------- + # Update the status-specific display of custom fields + function custom_field_status_update( $p_field_id, $p_status_display ) + { + $t_mantis_custom_field_status_table = config_get( 'mantis_custom_field_status_table' ); + $t_field_id = db_prepare_int( $p_field_id ); + + $query = "DELETE FROM $t_mantis_custom_field_status_table + WHERE field_id = $p_field_id"; + db_query( $query ); + + foreach ( $p_status_display as $t_status ) { + $t_status_val = db_prepare_int( $t_status[0] ); + + if( $t_status[1] == 1 ) { + $query = "INSERT INTO $t_mantis_custom_field_status_table + (field_id, status_id) + VALUES + ( $t_field_id, $t_status_val )" ; + + db_query( $query ) ; + } else if( $t_status[1] == 2 ) { + $query = "INSERT INTO $t_mantis_custom_field_status_table + (field_id, status_id, `require`) + VALUES + ( $t_field_id, $t_status_val, 1 )" ; + + db_query( $query ) ; + } + } + + return true ; + + } # -------------------- # Add a custom field to a project @@ -680,6 +715,64 @@ return $t_ids; } + + # -------------------- + # Return an array of ids of custom fields bound to the specified project and status + # + function custom_field_get_linked_status_ids( $p_project_id = ALL_PROJECTS, $p_status_id ) { + $t_custom_field_status_table = config_get( 'mantis_custom_field_status_table' ); + + # First get the array of custom fields for this project + $t_field_ids = custom_field_get_linked_ids( $p_project_id ) ; + + # Query the database to see if any of the custom field IDs are associated with + # this status. + $query = "SELECT cfs.field_id, cfs.require + FROM $t_custom_field_status_table cfs + WHERE cfs.status_id = $p_status_id AND + cfs.field_id IN (" . implode( ',', $t_field_ids ) . ")" ; + + $result = db_query( $query ); + $t_row_count = db_num_rows( $result ); + $t_ids = array(); + + for ( $i=0 ; $i < $t_row_count ; $i++ ) { + $row = db_fetch_array( $result ); + + array_push( $t_ids, array( $row['field_id'], $row['require'] ) ); + } + + return $t_ids; + } + + # -------------------- + # Return an array with the following format: + # array[status_id]=[display_value] + # where display_value is one of (0:none, 1:display, 2:require) + function custom_field_get_status_values( $p_custom_field_id ) + { + $t_custom_field_status_table = config_get( 'mantis_custom_field_status_table' ); + + $query = "SELECT cfs.status_id, cfs.require + FROM $t_custom_field_status_table cfs + WHERE cfs.field_id = $p_custom_field_id" ; + + $result = db_query( $query ); + $t_row_count = db_num_rows( $result ); + $t_ids = array(); + + for ( $i=0 ; $i < $t_row_count ; $i++ ) { + $row = db_fetch_array( $result ); + + if( $row['require'] ) { + $t_ids[$row['status_id']] = 2 ; + } else { + $t_ids[$row['status_id']] = 1 ; + } + } + + return $t_ids ; + } # -------------------- # Return an array all custom field ids sorted by name Index: lang/strings_english.txt =================================================================== RCS file: /apps/mantis/lang/strings_english.txt,v retrieving revision 1.2 diff -u -r1.2 strings_english.txt --- lang/strings_english.txt 24 Jul 2007 22:28:50 -0000 1.2 +++ lang/strings_english.txt 26 Jul 2007 22:24:43 -0000 @@ -1143,6 +1143,7 @@ $s_edit_custom_field_title = 'Edit custom field'; $s_custom_field = 'Field'; $s_custom_fields_setup = 'Custom Fields'; +$s_edit_custom_field_status_title = 'Edit custom field display properties'; $s_custom_field_name = 'Name'; $s_custom_field_project_count = 'Project Count'; $s_custom_field_type = 'Type'; @@ -1162,6 +1163,9 @@ $s_custom_field_require_update = 'Required On Update'; $s_custom_field_require_resolved = 'Required On Resolve'; $s_custom_field_require_closed = 'Required On Close'; +$s_custom_field_require = 'Require'; +$s_custom_field_display = 'Display'; +$s_custom_field_none = 'None'; $s_custom_field_sequence = 'Sequence'; $s_custom_field_type_enum_string = '0:String,1:Numeric,2:Float,3:Enumeration,4:Email,5:Checkbox,6:List,7:Multiselection list,8:Date';
+ +
+ + + + + + + +
+ + + > + + > + + > +