View Issue Details

IDProjectCategoryView StatusLast Update
0005744mantisbtcustom fieldspublic2022-04-13 08:58
Reportermalaussena Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Summary0005744: Managing custom fields in the workflow
Description

When creating a custom field, I can say it is necessary reporting, updating, solving or closing an issue.

I would like, in manage_config_workflow_page.php, having a table like workflow.
One row for each custom field, one column by status. A checkbox saying : custom field necessary at this status

Would it be possible ?

Best, having "level access" by cutsom field saying by status the min threshold level allowed for updating the custom field...

Am I crazy ? ;-)

Tagspatch
Attached Files
mantis.patch (26,005 bytes)   
? .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 ) ) {
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
@@ -190,15 +182,15 @@
 	</td>
 </tr>
 <?php
-	} #  custom_field_has_write_access( $t_id, $f_bug_id ) )
-	else if ( custom_field_has_read_access( $t_id, $f_bug_id ) ) {
+    } #  custom_field_has_write_access( $t_id[0], $f_bug_id ) )
+    else if ( custom_field_has_read_access( $t_id[0], $f_bug_id ) ) {
 ?>
 	<tr <?php echo helper_alternate_class() ?>>
 		<td class="category">
 			<?php echo lang_get_defaulted( $t_def['name'] ) ?>
 		</td>
 		<td>
-			<?php print_custom_field_value( $t_def, $t_id, $f_bug_id );			?>
+            <?php print_custom_field_value( $t_def, $t_id[0], $f_bug_id );         ?>
 		</td>
 	</tr>
 <?php
Index: bug_report_advanced_page.php
===================================================================
RCS file: /apps/mantis/bug_report_advanced_page.php,v
retrieving revision 1.2
diff -u -r1.2 bug_report_advanced_page.php
--- bug_report_advanced_page.php	24 Jul 2007 22:28:33 -0000	1.2
+++ bug_report_advanced_page.php	26 Jul 2007 23:55:58 -0000
@@ -366,16 +366,16 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' )  );
 
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_report']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td>
 		<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
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 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' ) );
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( ( $t_def['display_report'] && !$t_def['advanced'] ) || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( ( ( !$t_def['advanced'] ) || $t_id[1]) && custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if( $t_def['require_report'] ) { ?>
+		<?php if( $t_id[1] ) { ?>
 			<span class="required">*</span>
 		<?php } ?>
 		<?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
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 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_update']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: bug_update_page.php
===================================================================
RCS file: /apps/mantis/bug_update_page.php,v
retrieving revision 1.2
diff -u -r1.2 bug_update_page.php
--- bug_update_page.php	24 Jul 2007 22:28:33 -0000	1.2
+++ bug_update_page.php	26 Jul 2007 22:12:57 -0000
@@ -341,15 +341,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if ( $t_def['require_update'] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+        <?php if ( $t_id[1] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: config_defaults_inc.php
===================================================================
RCS file: /apps/mantis/config_defaults_inc.php,v
retrieving revision 1.2
diff -u -r1.2 config_defaults_inc.php
--- config_defaults_inc.php	24 Jul 2007 22:28:34 -0000	1.2
+++ config_defaults_inc.php	26 Jul 2007 21:59:40 -0000
@@ -1239,6 +1239,7 @@
 	$g_mantis_custom_field_project_table	= '%db_table_prefix%_custom_field_project%db_table_suffix%';
 	$g_mantis_custom_field_table      	    = '%db_table_prefix%_custom_field%db_table_suffix%';
 	$g_mantis_custom_field_string_table     = '%db_table_prefix%_custom_field_string%db_table_suffix%';
+    $g_mantis_custom_field_status_table     = '%db_table_prefix%_custom_field_status%db_table_suffix%';
 	$g_mantis_upgrade_table					= '%db_table_prefix%_upgrade%db_table_suffix%';
 	$g_mantis_filters_table					= '%db_table_prefix%_filters%db_table_suffix%';
 	$g_mantis_sponsorship_table				= '%db_table_prefix%_sponsorship%db_table_suffix%';
Index: manage_custom_field_edit_page.php
===================================================================
RCS file: /apps/mantis/manage_custom_field_edit_page.php,v
retrieving revision 1.2
diff -u -r1.2 manage_custom_field_edit_page.php
--- manage_custom_field_edit_page.php	24 Jul 2007 22:28:36 -0000	1.2
+++ manage_custom_field_edit_page.php	26 Jul 2007 22:16:52 -0000
@@ -129,73 +129,56 @@
 				<input type="checkbox" name="advanced" value="1" <?php check_checked( $t_definition['advanced'] ) ?>>
 			</td>
 		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_report" value="1" <?php check_checked( $t_definition['display_report'] ) ?>>
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_update" value="1" <?php check_checked( $t_definition['display_update'] ) ?>>
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_resolved" value="1" <?php check_checked( $t_definition['display_resolved'] ) ?>>
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_closed" value="1" <?php check_checked( $t_definition['display_closed'] ) ?>>
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_report" value="1" <?php check_checked( $t_definition['require_report'] ) ?>>
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_update" value="1" <?php check_checked( $t_definition['require_update'] ) ?>>
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_resolved" value="1" <?php check_checked( $t_definition['require_resolved'] ) ?>>
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_closed" value="1" <?php check_checked( $t_definition['require_closed'] ) ?>>
-			</td>
-		</tr>
-		<tr>
-			<td>&nbsp;</td>
-			<td>
+    </table>
+    <p />    
+    <table class="width50" cellspacing="1">
+        <tr>
+            <td class="form-title" colspan="2">
+                <?php echo lang_get( 'edit_custom_field_status_title' ) ?>
+            </td>
+        </tr>
+        <tr>
+            <td class="small-caption" width="50%">
+                <?php echo lang_get( 'status' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_none' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_display' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_require' ) ?>
+            </td>
+        </tr>
+
+<?php
+    $t_enum_status = config_get( 'status_enum_string' );
+    $t_status_arr  = get_enum_to_array( $t_enum_status );
+    $t_lang_enum_status = lang_get( 'status_enum_string' );
+
+    $t_status_settings = custom_field_get_status_values( $f_field_id ) ;
+    foreach ( $t_status_arr as $t_status => $t_label ) {
+?>
+        <tr <?php echo helper_alternate_class() ?>>
+            <td class="category">
+                <?php echo get_enum_to_string( $t_lang_enum_status, $t_status ) ?>
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="0" <?php check_checked( $t_status_settings[$t_status], 0 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="1" <?php check_checked( $t_status_settings[$t_status], 1 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="2" <?php check_checked( $t_status_settings[$t_status], 2 ) ?> >
+            </td>
+        </tr>
+<?php    
+    }
+?>
+        <tr>
+            <td colspan="4" align="center">
 				<input type="submit" class="button" value="<?php echo lang_get( 'update_custom_field_button' ) ?>" />
 			</td>
 		</tr>
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';
mantis.patch (26,005 bytes)   
mantisbt.patch (41,332 bytes)   
Index: bug_change_status_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_change_status_page.php,v
retrieving revision 1.28
diff -u -r1.28 bug_change_status_page.php
--- bug_change_status_page.php	13 Jul 2007 07:58:26 -0000	1.28
+++ bug_change_status_page.php	27 Jul 2007 04:40:06 -0000
@@ -22,13 +22,13 @@
 <?php
 	$f_bug_id = gpc_get_int( 'bug_id' );
 	$t_bug = bug_get( $f_bug_id );
-	
+
 	if( $t_bug->project_id != helper_get_current_project() ) {
 		# in case the current project is not the same project of the bug we are viewing...
 		# ... override the current project. This to avoid problems with categories and handlers lists etc.
 		$g_project_override = $t_bug->project_id;
 	}
-	
+
 	$f_new_status = gpc_get_int( 'new_status' );
 	$f_reopen_flag = gpc_get_int( 'reopen_flag', OFF );
 
@@ -113,7 +113,7 @@
 	</td>
 	<td>
 		<select name="resolution">
-			<?php 
+			<?php
                 $t_resolution = $t_bug_is_open ? FIXED : $t_current_resolution;
                 print_enum_string_option_list( "resolution", $t_resolution );
             ?>
@@ -154,33 +154,14 @@
 
 <!-- Custom Fields -->
 <?php
-# @@@ thraxisp - I undid part of the change for #5068 for #5527
-#  We really need to say what fields are shown in which statusses. For now,
-#  this page will show required custom fields in update mode, or 
-#  display or required fields on resolve or close
-$t_custom_status_label = "update"; # Don't show custom fields by default
-if ( ( $f_new_status == $t_resolved ) &&
-			( CLOSED > $f_new_status ) ) {
-	$t_custom_status_label = "resolved";
-}
-if ( CLOSED == $f_new_status ) {
-	$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 ) ) {
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
@@ -193,20 +174,20 @@
 	</td>
 </tr>
 <?php
-	} #  custom_field_has_write_access( $t_id, $f_bug_id ) )
-	else if ( custom_field_has_read_access( $t_id, $f_bug_id ) ) {
+	} #  custom_field_has_write_access( $t_id[0], $f_bug_id ) )
+	else if ( custom_field_has_read_access( $t_id[0], $f_bug_id ) ) {
 ?>
 	<tr <?php echo helper_alternate_class() ?>>
 		<td class="category">
 			<?php echo lang_get_defaulted( $t_def['name'] ) ?>
 		</td>
 		<td>
-			<?php print_custom_field_value( $t_def, $t_id, $f_bug_id );			?>
+			<?php print_custom_field_value( $t_def, $t_id[0], $f_bug_id );			?>
 		</td>
 	</tr>
 <?php
-	} # custom_field_has_read_access( $t_id, $f_bug_id ) )
-} # foreach( $t_related_custom_field_ids as $t_id )
+	} # custom_field_has_read_access( $t_id[0], $f_bug_id ) )
+} # foreach( $t_related_custom_field_ids as $t_id[0] )
 ?>
 
 <?php
Index: bug_report_advanced_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_advanced_page.php,v
retrieving revision 1.65
diff -u -r1.65 bug_report_advanced_page.php
--- bug_report_advanced_page.php	13 Jul 2007 07:58:27 -0000	1.65
+++ bug_report_advanced_page.php	27 Jul 2007 04:42:40 -0000
@@ -148,12 +148,12 @@
 			echo "[" . project_get_field( $t_bug->project_id, 'name' ) . "] ";
 		} ?>
 		<select <?php echo helper_get_tab_index() ?> name="category">
-			<?php 
+			<?php
 				if ( is_blank( $f_category ) ) {
 					echo '<option value="" selected="selected">', string_attribute( lang_get( 'select_option' ) ), '</option>';
 				}
 
-				print_category_option_list( $f_category ); 
+				print_category_option_list( $f_category );
 			?>
 		</select>
 	</td>
@@ -415,16 +415,16 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' )  );
 
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_report']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td>
 		<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
Index: bug_report_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_page.php,v
retrieving revision 1.64
diff -u -r1.64 bug_report_page.php
--- bug_report_page.php	13 Jul 2007 07:58:27 -0000	1.64
+++ bug_report_page.php	27 Jul 2007 04:46:25 -0000
@@ -132,12 +132,12 @@
 			echo "[" . project_get_field( $t_bug->project_id, 'name' ) . "] ";
 		} ?>
 		<select <?php echo helper_get_tab_index() ?> name="category">
-			<?php 
+			<?php
 				if ( is_blank( $f_category ) ) {
 					echo '<option value="" selected="selected">', string_attribute( lang_get( 'select_option' ) ), '</option>';
 				}
 
-				print_category_option_list( $f_category ); 
+				print_category_option_list( $f_category );
 			?>
 		</select>
 	</td>
@@ -259,15 +259,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' ) );
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( ( $t_def['display_report'] && !$t_def['advanced'] ) || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( ( ( !$t_def['advanced'] ) || $t_id[1]) && custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if( $t_def['require_report'] ) { ?>
+		<?php if( $t_id[1] ) { ?>
 			<span class="required">*</span>
 		<?php } ?>
 		<?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
Index: bug_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update.php,v
retrieving revision 1.91
diff -u -r1.91 bug_update.php
--- bug_update.php	12 Dec 2006 18:26:28 -0000	1.91
+++ bug_update.php	27 Jul 2007 04:51:54 -0000
@@ -87,44 +87,28 @@
 
 	$t_resolved = config_get( 'bug_resolved_status_threshold' );
 
-	$t_custom_status_label = "update"; # default info to check
-	if ( $t_bug_data->status == $t_resolved ) {
-		$t_custom_status_label = "resolved";
-	}
-	if ( $t_bug_data->status == CLOSED ) {
-		$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 
+		# Only update the field if it is posted
 		#  ( will fail in custom_field_set_value(), if it was required )
 		if ( $t_custom_field_value === null ) {
 			continue;
 		}
 
 		# 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: /cvsroot/mantisbt/mantisbt/bug_update_advanced_page.php,v
retrieving revision 1.102
diff -u -r1.102 bug_update_advanced_page.php
--- bug_update_advanced_page.php	13 Jul 2007 07:58:28 -0000	1.102
+++ bug_update_advanced_page.php	27 Jul 2007 04:53:28 -0000
@@ -512,15 +512,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_update']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: bug_update_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update_page.php,v
retrieving revision 1.100
diff -u -r1.100 bug_update_page.php
--- bug_update_page.php	13 Jul 2007 07:58:28 -0000	1.100
+++ bug_update_page.php	27 Jul 2007 04:55:14 -0000
@@ -348,15 +348,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if ( $t_def['require_update'] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+        <?php if ( $t_id[1] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: config_defaults_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/config_defaults_inc.php,v
retrieving revision 1.347
diff -u -r1.347 config_defaults_inc.php
--- config_defaults_inc.php	25 Jul 2007 08:27:57 -0000	1.347
+++ config_defaults_inc.php	27 Jul 2007 04:56:18 -0000
@@ -194,7 +194,7 @@
 
 	# the sender email, part of 'From: ' header in emails
  	$g_from_email			= 'noreply@example.com';
-	
+
 	# the sender name, part of 'From: ' header in emails
 	$g_from_name			= 'Mantis Bug Tracker';
 
@@ -295,8 +295,8 @@
 	$g_phpMailer_method		= 0;
 
 	# This option allows you to use a remote SMTP host.  Must use the phpMailer script
-	# One or more hosts, separated by a semicolon, can be listed. 
-	# You can also specify a different port for each host by using this 
+	# One or more hosts, separated by a semicolon, can be listed.
+	# You can also specify a different port for each host by using this
 	# format: [hostname:port] (e.g. "smtp1.example.com:25;smtp2.example.com").
 	# Hosts will be tried in order.
 	$g_smtp_host			= 'localhost';
@@ -307,7 +307,7 @@
 	$g_smtp_username = '';
 	$g_smtp_password = '';
 
-	# It is recommended to use a cronjob or a scheduler task to send emails.  
+	# It is recommended to use a cronjob or a scheduler task to send emails.
 	# The cronjob should typically run every 5 minutes.  If no cronjob is used,
 	# then user will have to wait for emails to be sent after performing an action
 	# which triggers notifications.  This slows user performance.
@@ -475,7 +475,7 @@
 	# resolution, fixed_in_version, view_state, os, os_build, platform, version, date_submitted, attachment,
 	# category, sponsorship_total, severity, status, last_updated, summary, bugnotes_count
 	$g_view_issues_page_columns = array ( 'selection', 'edit', 'priority', 'id', 'sponsorship_total', 'bugnotes_count', 'attachment', 'category', 'severity', 'status', 'last_updated', 'summary' );
-	
+
 	# A configuration option that identifies the columns to be show on the print issues page.
 	# In Mantis 1.1, this option can be overriden using the Generic Configuration screen.
 	# This configuration can be overriden dynamically by overriding the custom function "get_columns_to_view".
@@ -625,7 +625,7 @@
 
 	# Default bug priority when reporting a new bug
 	$g_default_bug_priority = NORMAL;
-	
+
 	# Default bug reproducibility when reporting a new bug
 	$g_default_bug_reproducibility = REPRODUCIBILITY_HAVENOTTRIED;
 
@@ -772,7 +772,7 @@
 	# DISK, DATABASE, or FTP.
 	$g_file_upload_method	= DATABASE;
 
-	# When using FTP or DISK for storing uploaded files, this setting control 
+	# When using FTP or DISK for storing uploaded files, this setting control
 	# the access permissions they will have on the web server: with the default
 	# value (0400) files will be read-only, and accessible only by the user
 	# running the apache process (probably "apache" in Linux and "Administrator"
@@ -856,7 +856,7 @@
 	$g_ldap_bind_dn			= '';
 	$g_ldap_bind_passwd		= '';
 	$g_use_ldap_email		= OFF; # Should we send to the LDAP email address or what MySql tells us
-	
+
 	# The LDAP Protocol Version, if 0, then the protocol version is not set.
 	$g_ldap_protocol_version = 0;
 
@@ -1093,7 +1093,7 @@
 
 	# threshold for viewing roadmap
 	$g_roadmap_view_threshold = VIEWER;
-	
+
 	# status change thresholds
 	$g_update_bug_status_threshold = DEVELOPER;
 
@@ -1102,7 +1102,7 @@
 
 	# access level needed to set a bug sticky
 	$g_set_bug_sticky_threshold			= MANAGER;
-	
+
 	# The minimum access level for someone to be a member of the development team
 	# and appear on the project information page.
 	$g_development_team_threshold = DEVELOPER;
@@ -1294,7 +1294,7 @@
 	# Rather than launching a separate page, the filters are updated in-line in the
 	# view_all_bugs_page.
 	$g_dhtml_filters = ON;
-	
+
 	# The service to use to create a short URL.  The %s will be replaced by the long URL.
 	$g_create_short_url = 'http://tinyurl.com/create.php?url=%s';
 
@@ -1328,6 +1328,7 @@
 	$g_mantis_custom_field_project_table	= '%db_table_prefix%_custom_field_project%db_table_suffix%';
 	$g_mantis_custom_field_table      	    = '%db_table_prefix%_custom_field%db_table_suffix%';
 	$g_mantis_custom_field_string_table     = '%db_table_prefix%_custom_field_string%db_table_suffix%';
+	$g_mantis_custom_field_status_table     = '%db_table_prefix%_custom_field_status%db_table_suffix%';
 	$g_mantis_upgrade_table					= '%db_table_prefix%_upgrade%db_table_suffix%';
 	$g_mantis_filters_table					= '%db_table_prefix%_filters%db_table_suffix%';
 	$g_mantis_sponsorship_table				= '%db_table_prefix%_sponsorship%db_table_suffix%';
@@ -1563,7 +1564,7 @@
 	# Note:
 	# - Extensions must be in lower case
 	# - All icons will be displayed as 16x16 pixels.
-	$g_file_type_icons = array(	
+	$g_file_type_icons = array(
 		'7z'	=> 'zip.gif',
 		'ace'	=> 'zip.gif',
 		'arj'	=> 'zip.gif',
@@ -1685,7 +1686,7 @@
 	$g_rss_enabled = ON;
 
 	# This seed is used as part of the inputs for calculating the authentication key for the RSS feeds.
-	# If this seed changes, all the existing keys for the RSS feeds will become invalid.  This is 
+	# If this seed changes, all the existing keys for the RSS feeds will become invalid.  This is
 	# defaulted to the database user name, but it is recommended to overwrite it with a specific value
 	# on installation.
 	$g_rss_key_seed = '%db_username%';
@@ -1764,7 +1765,7 @@
 	# Custom Group Actions
 	#
 	# This extensibility model allows developing new group custom actions.  This
-	# can be implemented with a totally custom form and action pages or with a 
+	# can be implemented with a totally custom form and action pages or with a
 	# pre-implemented form and action page and call-outs to some functions.  These
 	# functions are to be implemented in a predefined file whose name is based on
 	# the action name.  For example, for an action to add a note, the action would
@@ -1792,26 +1793,26 @@
 	#####################
 	# Wiki Integration
 	#####################
- 
+
 	# Wiki Integration Enabled?
 	$g_wiki_enable = OFF;
 
 	# Wiki Engine (supported engines: 'dokuwiki', 'mediawiki')
 	$g_wiki_engine = 'dokuwiki';
- 
+
 	# Wiki namespace to be used as root for all pages relating to this mantis installation.
 	$g_wiki_root_namespace = 'mantis';
- 
+
 	# URL under which the wiki engine is hosted.  Must be on the same server.
 	$g_wiki_engine_url = $t_protocol . '://' . $t_host . '/%wiki_engine%/';
-	
+
 	#####################
 	# Recently Visited
 	#####################
 
 	# Whether to show the most recently visited issues or not.  At the moment we always track them even if this flag is off.
 	$g_recently_visited = ON;
-	
+
 	# The maximum number of issues to keep in the recently visited list.
 	$g_recently_visited_count = 5;
 
@@ -1847,7 +1848,7 @@
 	# Threshold needed to be able to create and modify global profiles
 	$g_manage_global_profile_threshold = MANAGER;
 
-	# Allows the users to enter free text when reporting/updating issues 
+	# Allows the users to enter free text when reporting/updating issues
 	# for the profile related fields (i.e. platform, os, os build)
 	$g_allow_freetext_in_profile_fields = ON;
 
@@ -1861,7 +1862,7 @@
 
 	# The twitter account user name.
 	$g_twitter_username = '';
-	
+
 	# The twitter account password.
 	$g_twitter_password = '';
 ?>
Index: manage_custom_field_edit_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_edit_page.php,v
retrieving revision 1.25
diff -u -r1.25 manage_custom_field_edit_page.php
--- manage_custom_field_edit_page.php	18 May 2007 03:17:59 -0000	1.25
+++ manage_custom_field_edit_page.php	27 Jul 2007 05:00:04 -0000
@@ -129,73 +129,56 @@
 				<input type="checkbox" name="advanced" value="1" <?php check_checked( $t_definition['advanced'] ) ?> />
 			</td>
 		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_report" value="1" <?php check_checked( $t_definition['display_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_update" value="1" <?php check_checked( $t_definition['display_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_resolved" value="1" <?php check_checked( $t_definition['display_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_closed" value="1" <?php check_checked( $t_definition['display_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_report" value="1" <?php check_checked( $t_definition['require_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_update" value="1" <?php check_checked( $t_definition['require_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_resolved" value="1" <?php check_checked( $t_definition['require_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_closed" value="1" <?php check_checked( $t_definition['require_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr>
-			<td>&nbsp;</td>
-			<td>
+    </table>
+    <p />
+    <table class="width50" cellspacing="1">
+        <tr>
+            <td class="form-title" colspan="2">
+                <?php echo lang_get( 'edit_custom_field_status_title' ) ?>
+            </td>
+        </tr>
+        <tr>
+            <td class="small-caption" width="50%">
+                <?php echo lang_get( 'status' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_none' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_display' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_require' ) ?>
+            </td>
+        </tr>
+
+<?php
+    $t_enum_status = config_get( 'status_enum_string' );
+    $t_status_arr  = get_enum_to_array( $t_enum_status );
+    $t_lang_enum_status = lang_get( 'status_enum_string' );
+
+    $t_status_settings = custom_field_get_status_values( $f_field_id ) ;
+    foreach ( $t_status_arr as $t_status => $t_label ) {
+?>
+        <tr <?php echo helper_alternate_class() ?>>
+            <td class="category">
+                <?php echo get_enum_to_string( $t_lang_enum_status, $t_status ) ?>
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="0" <?php check_checked( $t_status_settings[$t_status], 0 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="1" <?php check_checked( $t_status_settings[$t_status], 1 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="2" <?php check_checked( $t_status_settings[$t_status], 2 ) ?> >
+            </td>
+        </tr>
+<?php
+    }
+?>
+        <tr>
+            <td colspan="4" align="center">
 				<input type="submit" class="button" value="<?php echo lang_get( 'update_custom_field_button' ) ?>" />
 			</td>
 		</tr>
Index: manage_custom_field_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_update.php,v
retrieving revision 1.17
diff -u -r1.17 manage_custom_field_update.php
--- manage_custom_field_update.php	3 Aug 2004 23:43:49 -0000	1.17
+++ manage_custom_field_update.php	27 Jul 2007 05:09:52 -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: /cvsroot/mantisbt/mantisbt/admin/db_stats.php,v
retrieving revision 1.3
diff -u -r1.3 db_stats.php
--- admin/db_stats.php	10 Feb 2007 12:19:10 -0000	1.3
+++ admin/db_stats.php	27 Jul 2007 05:11:10 -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: /cvsroot/mantisbt/mantisbt/admin/db_table_names_inc.php,v
retrieving revision 1.8
diff -u -r1.8 db_table_names_inc.php
--- admin/db_table_names_inc.php	14 Jul 2005 21:38:00 -0000	1.8
+++ admin/db_table_names_inc.php	27 Jul 2007 05:11:41 -0000
@@ -31,6 +31,7 @@
 	$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_string_table	= config_get_global( 'mantis_custom_field_string_table' );
+	$t_custom_field_status_table	= config_get_global( 'mantis_custom_field_status_table' );
 	$t_upgrade_table				= config_get_global( 'mantis_upgrade_table' );
 	$t_filters_table				= config_get_global( 'mantis_filters_table' );
 	$t_tokens_table					= config_get_global( 'mantis_tokens_table' );
Index: admin/schema.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/admin/schema.php,v
retrieving revision 1.19
diff -u -r1.19 schema.php
--- admin/schema.php	22 Jul 2007 19:51:18 -0000	1.19
+++ admin/schema.php	27 Jul 2007 05:26:22 -0000
@@ -7,7 +7,7 @@
 	# --------------------------------------------------------
 	# $Id: schema.php,v 1.19 2007/07/22 19:51:18 prichards Exp $
 	# --------------------------------------------------------
-	
+
 	# Each entry below defines the schema. The upgrade array consists of
 	#  two elements
 	# The first is the function to generate SQL statements (see adodb schema doc for more details)
@@ -15,8 +15,8 @@
 	#  DropTableSQL, ChangeTableSQL, RenameTableSQL, RenameColumnSQL, AlterColumnSQL, DropColumnSQL
 	#  A local function "InsertData" has been provided to add data to the db
 	# The second parameter is an array of the parameters to be passed to the function.
-	
-	# An update identifier is inferred from the ordering of this table. ONLY ADD NEW CHANGES TO THE 
+
+	# An update identifier is inferred from the ordering of this table. ONLY ADD NEW CHANGES TO THE
 	#  END OF THE TABLE!!!
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_config_table'),"
 			  config_id C(64) NOTNULL PRIMARY,
@@ -132,6 +132,11 @@
   value 		C(255) NOTNULL DEFAULT \" '' \"
 ",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',
+  required        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 \" '' \",
@@ -309,9 +314,9 @@
 $upgrade[] = Array('CreateIndexSQL',Array('idx_user_username',config_get('mantis_user_table'),'username',Array('UNIQUE')));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_enable',config_get('mantis_user_table'),'enabled'));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_access',config_get('mantis_user_table'),'access_level'));
-$upgrade[] = Array('InsertData', Array( config_get('mantis_user_table'), 
-    "(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES 
-        ('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', " . db_now() . ", " . db_now() . ", 1, 0, 90, 3, 0, 0, '" . 
+$upgrade[] = Array('InsertData', Array( config_get('mantis_user_table'),
+    "(username, realname, email, password, date_created, last_visit, enabled, protected, access_level, login_count, lost_password_request_count, failed_login_count, cookie_string) VALUES
+        ('administrator', '', 'root@localhost', '63a9f0ea7bb98050796b649e85481845', " . db_now() . ", " . db_now() . ", 1, 0, 90, 3, 0, 0, '" .
              md5( mt_rand( 0, mt_getrandmax() ) + mt_rand( 0, mt_getrandmax() ) ) . md5( time() ) . "')" ) );
 $upgrade[] = Array('AlterColumnSQL', Array( config_get( 'mantis_bug_history_table' ), "old_value C(255) NOTNULL" ) );
 $upgrade[] = Array('AlterColumnSQL', Array( config_get( 'mantis_bug_history_table' ), "new_value C(255) NOTNULL" ) );
Index: core/custom_field_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/custom_field_api.php,v
retrieving revision 1.64
diff -u -r1.64 custom_field_api.php
--- core/custom_field_api.php	6 Jul 2007 07:30:16 -0000	1.64
+++ core/custom_field_api.php	27 Jul 2007 05:41:35 -0000
@@ -469,6 +469,41 @@
 		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, required)
+                          VALUES
+                          ( $t_field_id, $t_status_val, 1 )" ;
+
+                db_query( $query ) ;
+            }
+        }
+
+        return true ;
+
+    }
+
 	# --------------------
 	# Add a custom field to a project
 	#  return true on success, false on failure or if already added
@@ -623,9 +658,9 @@
 	# The ids will be sorted based on the sequence number associated with the binding
 	function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS ) {
 	global $g_cache_cf_linked;
-        
+
         if ( ! isset( $g_cache_cf_linked[$p_project_id] ) ) {
-        
+
      		$t_custom_field_table			= config_get( 'mantis_custom_field_table' );
      		$t_custom_field_project_table	= config_get( 'mantis_custom_field_project_table' );
 
@@ -636,7 +671,7 @@
                 $t_user_id = auth_get_current_user_id();
                 $t_pub = VS_PUBLIC;
                 $t_priv = VS_PRIVATE;
-            
+
                 $t_private_access = config_get( 'private_project_threshold' );
                 if ( is_array( $t_private_access ) ) {
                     if ( 1 == count( $t_private_access ) ) {
@@ -646,19 +681,19 @@
                     }
                 } else {
                     $t_access_clause = ">= $t_private_access ";
-                }			
+                }
 
-            
-                # select only the ids that the user has some access to 
+
+                # select only the ids that the user has some access to
                 #  e.g., all fields in public projects, or private projects where the user is listed
                 #    or private projects where the user is implicitly listed
                 $query = "SELECT cft.id as id, cft.name as name
                     FROM $t_custom_field_table as cft, $t_user_table ut, $t_project_table pt, $t_custom_field_project_table cfpt
-                        LEFT JOIN $t_project_user_list_table pult 
+                        LEFT JOIN $t_project_user_list_table pult
                             on cfpt.project_id = pult.project_id and pult.user_id = $t_user_id
-                    WHERE cft.id = cfpt.field_id AND cfpt.project_id = pt.id AND ut.id = $t_user_id AND 
-                        ( pt.view_state = $t_pub OR 
-                        ( pt.view_state = $t_priv and pult.user_id = $t_user_id ) OR 
+                    WHERE cft.id = cfpt.field_id AND cfpt.project_id = pt.id AND ut.id = $t_user_id AND
+                        ( pt.view_state = $t_pub OR
+                        ( pt.view_state = $t_priv and pult.user_id = $t_user_id ) OR
                         ( pult.user_id is null and ut.access_level $t_access_clause ) )
                     GROUP BY cft.id, cft.name
                     ORDER BY cft.name ASC";
@@ -671,7 +706,7 @@
                     }
                 } else {
                     $t_project_clause = "= $p_project_id ";
-                }			
+                }
     			$query = "SELECT cft.id, cft.name, cfpt.sequence
 					  FROM $t_custom_field_table cft, $t_custom_field_project_table cfpt
 					  WHERE cfpt.project_id $t_project_clause AND
@@ -691,15 +726,73 @@
     	} else {
     		$t_ids = $g_cache_cf_linked[$p_project_id];
         }
-        
+
 		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.required
+                  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['required'] ) );
+        }
+
+        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.required
+                  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['required'] ) {
+                $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
 	function custom_field_get_ids( ) {
         global $g_cache_cf_list;
-       
+
         if ( $g_cache_cf_list === NULL ) {
             $t_custom_field_table			= config_get( 'mantis_custom_field_table' );
             $query = "SELECT id, name
Index: lang/strings_english.txt
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/lang/strings_english.txt,v
retrieving revision 1.306
diff -u -r1.306 strings_english.txt
--- lang/strings_english.txt	25 Jul 2007 10:50:49 -0000	1.306
+++ lang/strings_english.txt	27 Jul 2007 05:18:48 -0000
@@ -1163,6 +1163,7 @@
 $s_update_custom_field_button = 'Update Custom Field';
 $s_add_existing_custom_field = 'Add This Existing Custom Field';
 $s_edit_custom_field_title = 'Edit custom field';
+$s_edit_custom_field_status_title = 'Edit custom field display properties';
 $s_custom_field = 'Field';
 $s_custom_fields_setup = 'Custom Fields';
 $s_custom_field_name = 'Name';
@@ -1187,6 +1188,9 @@
 $s_link_custom_field_to_project_title = 'Link custom field to project';
 $s_link_custom_field_to_project_button = 'Link Custom Field';
 $s_linked_projects = 'Linked Projects';
++$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';
mantisbt.patch (41,332 bytes)   
mantisbt_2.patch (27,515 bytes)   
Index: bug_change_status_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_change_status_page.php,v
retrieving revision 1.28
diff -u -r1.28 bug_change_status_page.php
--- bug_change_status_page.php	13 Jul 2007 07:58:26 -0000	1.28
+++ bug_change_status_page.php	27 Jul 2007 15:27:45 -0000
@@ -154,33 +154,14 @@
 
 <!-- Custom Fields -->
 <?php
-# @@@ thraxisp - I undid part of the change for #5068 for #5527
-#  We really need to say what fields are shown in which statusses. For now,
-#  this page will show required custom fields in update mode, or 
-#  display or required fields on resolve or close
-$t_custom_status_label = "update"; # Don't show custom fields by default
-if ( ( $f_new_status == $t_resolved ) &&
-			( CLOSED > $f_new_status ) ) {
-	$t_custom_status_label = "resolved";
-}
-if ( CLOSED == $f_new_status ) {
-	$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 ) ) {
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
@@ -193,20 +174,20 @@
 	</td>
 </tr>
 <?php
-	} #  custom_field_has_write_access( $t_id, $f_bug_id ) )
-	else if ( custom_field_has_read_access( $t_id, $f_bug_id ) ) {
+	} #  custom_field_has_write_access( $t_id[0], $f_bug_id ) )
+	else if ( custom_field_has_read_access( $t_id[0], $f_bug_id ) ) {
 ?>
 	<tr <?php echo helper_alternate_class() ?>>
 		<td class="category">
 			<?php echo lang_get_defaulted( $t_def['name'] ) ?>
 		</td>
 		<td>
-			<?php print_custom_field_value( $t_def, $t_id, $f_bug_id );			?>
+			<?php print_custom_field_value( $t_def, $t_id[0], $f_bug_id );			?>
 		</td>
 	</tr>
 <?php
-	} # custom_field_has_read_access( $t_id, $f_bug_id ) )
-} # foreach( $t_related_custom_field_ids as $t_id )
+	} # custom_field_has_read_access( $t_id[0], $f_bug_id ) )
+} # foreach( $t_related_custom_field_ids as $t_id[0] )
 ?>
 
 <?php
Index: bug_report_advanced_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_advanced_page.php,v
retrieving revision 1.65
diff -u -r1.65 bug_report_advanced_page.php
--- bug_report_advanced_page.php	13 Jul 2007 07:58:27 -0000	1.65
+++ bug_report_advanced_page.php	27 Jul 2007 15:27:45 -0000
@@ -415,16 +415,16 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' )  );
 
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_report']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td>
 		<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
Index: bug_report_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_page.php,v
retrieving revision 1.64
diff -u -r1.64 bug_report_page.php
--- bug_report_page.php	13 Jul 2007 07:58:27 -0000	1.64
+++ bug_report_page.php	27 Jul 2007 15:27:45 -0000
@@ -259,15 +259,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' ) );
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( ( $t_def['display_report'] && !$t_def['advanced'] ) || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( ( ( !$t_def['advanced'] ) || $t_id[1]) && custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if( $t_def['require_report'] ) { ?>
+		<?php if( $t_id[1] ) { ?>
 			<span class="required">*</span>
 		<?php } ?>
 		<?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
Index: bug_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update.php,v
retrieving revision 1.91
diff -u -r1.91 bug_update.php
--- bug_update.php	12 Dec 2006 18:26:28 -0000	1.91
+++ bug_update.php	27 Jul 2007 15:27:45 -0000
@@ -87,44 +87,28 @@
 
 	$t_resolved = config_get( 'bug_resolved_status_threshold' );
 
-	$t_custom_status_label = "update"; # default info to check
-	if ( $t_bug_data->status == $t_resolved ) {
-		$t_custom_status_label = "resolved";
-	}
-	if ( $t_bug_data->status == CLOSED ) {
-		$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 )
 		if ( $t_custom_field_value === null ) {
 			continue;
 		}
 
 		# 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: /cvsroot/mantisbt/mantisbt/bug_update_advanced_page.php,v
retrieving revision 1.102
diff -u -r1.102 bug_update_advanced_page.php
--- bug_update_advanced_page.php	13 Jul 2007 07:58:28 -0000	1.102
+++ bug_update_advanced_page.php	27 Jul 2007 15:27:45 -0000
@@ -512,15 +512,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_update']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: bug_update_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update_page.php,v
retrieving revision 1.100
diff -u -r1.100 bug_update_page.php
--- bug_update_page.php	13 Jul 2007 07:58:28 -0000	1.100
+++ bug_update_page.php	27 Jul 2007 15:27:45 -0000
@@ -348,15 +348,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if ( $t_def['require_update'] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+        <?php if ( $t_id[1] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: config_defaults_inc.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/config_defaults_inc.php,v
retrieving revision 1.347
diff -u -r1.347 config_defaults_inc.php
--- config_defaults_inc.php	25 Jul 2007 08:27:57 -0000	1.347
+++ config_defaults_inc.php	27 Jul 2007 15:27:45 -0000
@@ -1328,6 +1328,7 @@
 	$g_mantis_custom_field_project_table	= '%db_table_prefix%_custom_field_project%db_table_suffix%';
 	$g_mantis_custom_field_table      	    = '%db_table_prefix%_custom_field%db_table_suffix%';
 	$g_mantis_custom_field_string_table     = '%db_table_prefix%_custom_field_string%db_table_suffix%';
+	$g_mantis_custom_field_status_table     = '%db_table_prefix%_custom_field_status%db_table_suffix%';
 	$g_mantis_upgrade_table					= '%db_table_prefix%_upgrade%db_table_suffix%';
 	$g_mantis_filters_table					= '%db_table_prefix%_filters%db_table_suffix%';
 	$g_mantis_sponsorship_table				= '%db_table_prefix%_sponsorship%db_table_suffix%';
Index: manage_custom_field_edit_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_edit_page.php,v
retrieving revision 1.25
diff -u -r1.25 manage_custom_field_edit_page.php
--- manage_custom_field_edit_page.php	18 May 2007 03:17:59 -0000	1.25
+++ manage_custom_field_edit_page.php	27 Jul 2007 15:27:45 -0000
@@ -129,73 +129,56 @@
 				<input type="checkbox" name="advanced" value="1" <?php check_checked( $t_definition['advanced'] ) ?> />
 			</td>
 		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_report" value="1" <?php check_checked( $t_definition['display_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_update" value="1" <?php check_checked( $t_definition['display_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_resolved" value="1" <?php check_checked( $t_definition['display_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_closed" value="1" <?php check_checked( $t_definition['display_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_report" value="1" <?php check_checked( $t_definition['require_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_update" value="1" <?php check_checked( $t_definition['require_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_resolved" value="1" <?php check_checked( $t_definition['require_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_closed" value="1" <?php check_checked( $t_definition['require_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr>
-			<td>&nbsp;</td>
-			<td>
+    </table>
+    <p />
+    <table class="width50" cellspacing="1">
+        <tr>
+            <td class="form-title" colspan="2">
+                <?php echo lang_get( 'edit_custom_field_status_title' ) ?>
+            </td>
+        </tr>
+        <tr>
+            <td class="small-caption" width="50%">
+                <?php echo lang_get( 'status' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_none' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_display' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_require' ) ?>
+            </td>
+        </tr>
+
+<?php
+    $t_enum_status = config_get( 'status_enum_string' );
+    $t_status_arr  = get_enum_to_array( $t_enum_status );
+    $t_lang_enum_status = lang_get( 'status_enum_string' );
+
+    $t_status_settings = custom_field_get_status_values( $f_field_id ) ;
+    foreach ( $t_status_arr as $t_status => $t_label ) {
+?>
+        <tr <?php echo helper_alternate_class() ?>>
+            <td class="category">
+                <?php echo get_enum_to_string( $t_lang_enum_status, $t_status ) ?>
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="0" <?php check_checked( $t_status_settings[$t_status], 0 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="1" <?php check_checked( $t_status_settings[$t_status], 1 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="2" <?php check_checked( $t_status_settings[$t_status], 2 ) ?> >
+            </td>
+        </tr>
+<?php
+    }
+?>
+        <tr>
+            <td colspan="4" align="center">
 				<input type="submit" class="button" value="<?php echo lang_get( 'update_custom_field_button' ) ?>" />
 			</td>
 		</tr>
Index: manage_custom_field_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_update.php,v
retrieving revision 1.17
diff -u -r1.17 manage_custom_field_update.php
--- manage_custom_field_update.php	3 Aug 2004 23:43:49 -0000	1.17
+++ manage_custom_field_update.php	27 Jul 2007 15:27:45 -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: /cvsroot/mantisbt/mantisbt/admin/db_stats.php,v
retrieving revision 1.3
diff -u -r1.3 db_stats.php
--- admin/db_stats.php	10 Feb 2007 12:19:10 -0000	1.3
+++ admin/db_stats.php	27 Jul 2007 15:27:51 -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: /cvsroot/mantisbt/mantisbt/admin/db_table_names_inc.php,v
retrieving revision 1.8
diff -u -r1.8 db_table_names_inc.php
--- admin/db_table_names_inc.php	14 Jul 2005 21:38:00 -0000	1.8
+++ admin/db_table_names_inc.php	27 Jul 2007 15:27:57 -0000
@@ -31,6 +31,7 @@
 	$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_string_table	= config_get_global( 'mantis_custom_field_string_table' );
+	$t_custom_field_status_table	= config_get_global( 'mantis_custom_field_status_table' );
 	$t_upgrade_table				= config_get_global( 'mantis_upgrade_table' );
 	$t_filters_table				= config_get_global( 'mantis_filters_table' );
 	$t_tokens_table					= config_get_global( 'mantis_tokens_table' );
Index: admin/schema.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/admin/schema.php,v
retrieving revision 1.19
diff -u -r1.19 schema.php
--- admin/schema.php	22 Jul 2007 19:51:18 -0000	1.19
+++ admin/schema.php	27 Jul 2007 15:28:00 -0000
@@ -132,6 +132,11 @@
   value 		C(255) NOTNULL DEFAULT \" '' \"
 ",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',
+  required        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: /cvsroot/mantisbt/mantisbt/core/custom_field_api.php,v
retrieving revision 1.64
diff -u -r1.64 custom_field_api.php
--- core/custom_field_api.php	6 Jul 2007 07:30:16 -0000	1.64
+++ core/custom_field_api.php	27 Jul 2007 15:28:06 -0000
@@ -469,6 +469,41 @@
 		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, required)
+                          VALUES
+                          ( $t_field_id, $t_status_val, 1 )" ;
+
+                db_query( $query ) ;
+            }
+        }
+
+        return true ;
+
+    }
+
 	# --------------------
 	# Add a custom field to a project
 	#  return true on success, false on failure or if already added
@@ -691,15 +726,73 @@
     	} else {
     		$t_ids = $g_cache_cf_linked[$p_project_id];
         }
        
 		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.required
+                  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['required'] ) );
+        }
+
+        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.required
+                  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['required'] ) {
+                $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
 	function custom_field_get_ids( ) {
         global $g_cache_cf_list;
       
         if ( $g_cache_cf_list === NULL ) {
             $t_custom_field_table			= config_get( 'mantis_custom_field_table' );
             $query = "SELECT id, name
Index: lang/strings_english.txt
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/lang/strings_english.txt,v
retrieving revision 1.306
diff -u -r1.306 strings_english.txt
--- lang/strings_english.txt	25 Jul 2007 10:50:49 -0000	1.306
+++ lang/strings_english.txt	27 Jul 2007 15:28:11 -0000
@@ -1163,6 +1163,7 @@
 $s_update_custom_field_button = 'Update Custom Field';
 $s_add_existing_custom_field = 'Add This Existing Custom Field';
 $s_edit_custom_field_title = 'Edit custom field';
+$s_edit_custom_field_status_title = 'Edit custom field display properties';
 $s_custom_field = 'Field';
 $s_custom_fields_setup = 'Custom Fields';
 $s_custom_field_name = 'Name';
@@ -1187,6 +1188,9 @@
 $s_link_custom_field_to_project_title = 'Link custom field to project';
 $s_link_custom_field_to_project_button = 'Link Custom Field';
 $s_linked_projects = 'Linked Projects';
++$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';
mantisbt_2.patch (27,515 bytes)   
mantisbt_3.patch (23,541 bytes)   
? custom_contant_inc.php
? mantisbt.patch
Index: bug_change_status_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_change_status_page.php,v
retrieving revision 1.28
diff -u -r1.28 bug_change_status_page.php
--- bug_change_status_page.php	13 Jul 2007 07:58:26 -0000	1.28
+++ bug_change_status_page.php	27 Jul 2007 15:27:45 -0000
@@ -154,33 +154,14 @@
 
 <!-- Custom Fields -->
 <?php
-# @@@ thraxisp - I undid part of the change for #5068 for #5527
-#  We really need to say what fields are shown in which statusses. For now,
-#  this page will show required custom fields in update mode, or 
-#  display or required fields on resolve or close
-$t_custom_status_label = "update"; # Don't show custom fields by default
-if ( ( $f_new_status == $t_resolved ) &&
-			( CLOSED > $f_new_status ) ) {
-	$t_custom_status_label = "resolved";
-}
-if ( CLOSED == $f_new_status ) {
-	$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 ) ) {
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
@@ -193,20 +174,20 @@
 	</td>
 </tr>
 <?php
-	} #  custom_field_has_write_access( $t_id, $f_bug_id ) )
-	else if ( custom_field_has_read_access( $t_id, $f_bug_id ) ) {
+	} #  custom_field_has_write_access( $t_id[0], $f_bug_id ) )
+	else if ( custom_field_has_read_access( $t_id[0], $f_bug_id ) ) {
 ?>
 	<tr <?php echo helper_alternate_class() ?>>
 		<td class="category">
 			<?php echo lang_get_defaulted( $t_def['name'] ) ?>
 		</td>
 		<td>
-			<?php print_custom_field_value( $t_def, $t_id, $f_bug_id );			?>
+			<?php print_custom_field_value( $t_def, $t_id[0], $f_bug_id );			?>
 		</td>
 	</tr>
 <?php
-	} # custom_field_has_read_access( $t_id, $f_bug_id ) )
-} # foreach( $t_related_custom_field_ids as $t_id )
+	} # custom_field_has_read_access( $t_id[0], $f_bug_id ) )
+} # foreach( $t_related_custom_field_ids as $t_id[0] )
 ?>
 
 <?php
Index: bug_report_advanced_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_advanced_page.php,v
retrieving revision 1.65
diff -u -r1.65 bug_report_advanced_page.php
--- bug_report_advanced_page.php	13 Jul 2007 07:58:27 -0000	1.65
+++ bug_report_advanced_page.php	27 Jul 2007 15:27:45 -0000
@@ -415,16 +415,16 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' )  );
 
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_report']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td>
 		<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
Index: bug_report_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_page.php,v
retrieving revision 1.64
diff -u -r1.64 bug_report_page.php
--- bug_report_page.php	13 Jul 2007 07:58:27 -0000	1.64
+++ bug_report_page.php	27 Jul 2007 15:27:45 -0000
@@ -259,15 +259,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' ) );
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( ( $t_def['display_report'] && !$t_def['advanced'] ) || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( ( ( !$t_def['advanced'] ) || $t_id[1]) && custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if( $t_def['require_report'] ) { ?>
+		<?php if( $t_id[1] ) { ?>
 			<span class="required">*</span>
 		<?php } ?>
 		<?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
Index: bug_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update.php,v
retrieving revision 1.91
diff -u -r1.91 bug_update.php
--- bug_update.php	12 Dec 2006 18:26:28 -0000	1.91
+++ bug_update.php	27 Jul 2007 15:27:45 -0000
@@ -87,44 +87,28 @@
 
 	$t_resolved = config_get( 'bug_resolved_status_threshold' );
 
-	$t_custom_status_label = "update"; # default info to check
-	if ( $t_bug_data->status == $t_resolved ) {
-		$t_custom_status_label = "resolved";
-	}
-	if ( $t_bug_data->status == CLOSED ) {
-		$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 
+		# Only update the field if it is posted
 		#  ( will fail in custom_field_set_value(), if it was required )
 		if ( $t_custom_field_value === null ) {
 			continue;
 		}
 
 		# 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: /cvsroot/mantisbt/mantisbt/bug_update_advanced_page.php,v
retrieving revision 1.102
diff -u -r1.102 bug_update_advanced_page.php
--- bug_update_advanced_page.php	13 Jul 2007 07:58:28 -0000	1.102
+++ bug_update_advanced_page.php	27 Jul 2007 15:27:45 -0000
@@ -512,15 +512,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_update']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: bug_update_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update_page.php,v
retrieving revision 1.100
diff -u -r1.100 bug_update_page.php
--- bug_update_page.php	13 Jul 2007 07:58:28 -0000	1.100
+++ bug_update_page.php	27 Jul 2007 15:27:45 -0000
@@ -348,15 +348,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if ( $t_def['require_update'] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+        <?php if ( $t_id[1] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: manage_custom_field_edit_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_edit_page.php,v
retrieving revision 1.25
diff -u -r1.25 manage_custom_field_edit_page.php
--- manage_custom_field_edit_page.php	18 May 2007 03:17:59 -0000	1.25
+++ manage_custom_field_edit_page.php	27 Jul 2007 15:27:45 -0000
@@ -129,73 +129,56 @@
 				<input type="checkbox" name="advanced" value="1" <?php check_checked( $t_definition['advanced'] ) ?> />
 			</td>
 		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_report" value="1" <?php check_checked( $t_definition['display_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_update" value="1" <?php check_checked( $t_definition['display_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_resolved" value="1" <?php check_checked( $t_definition['display_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_closed" value="1" <?php check_checked( $t_definition['display_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_report" value="1" <?php check_checked( $t_definition['require_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_update" value="1" <?php check_checked( $t_definition['require_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_resolved" value="1" <?php check_checked( $t_definition['require_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_closed" value="1" <?php check_checked( $t_definition['require_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr>
-			<td>&nbsp;</td>
-			<td>
+    </table>
+    <p />
+    <table class="width50" cellspacing="1">
+        <tr>
+            <td class="form-title" colspan="2">
+                <?php echo lang_get( 'edit_custom_field_status_title' ) ?>
+            </td>
+        </tr>
+        <tr>
+            <td class="small-caption" width="50%">
+                <?php echo lang_get( 'status' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_none' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_display' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_require' ) ?>
+            </td>
+        </tr>
+
+<?php
+    $t_enum_status = config_get( 'status_enum_string' );
+    $t_status_arr  = get_enum_to_array( $t_enum_status );
+    $t_lang_enum_status = lang_get( 'status_enum_string' );
+
+    $t_status_settings = custom_field_get_status_values( $f_field_id ) ;
+    foreach ( $t_status_arr as $t_status => $t_label ) {
+?>
+        <tr <?php echo helper_alternate_class() ?>>
+            <td class="category">
+                <?php echo get_enum_to_string( $t_lang_enum_status, $t_status ) ?>
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="0" <?php check_checked( $t_status_settings[$t_status], 0 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="1" <?php check_checked( $t_status_settings[$t_status], 1 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="2" <?php check_checked( $t_status_settings[$t_status], 2 ) ?> >
+            </td>
+        </tr>
+<?php
+    }
+?>
+        <tr>
+            <td colspan="4" align="center">
 				<input type="submit" class="button" value="<?php echo lang_get( 'update_custom_field_button' ) ?>" />
 			</td>
 		</tr>
Index: manage_custom_field_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_update.php,v
retrieving revision 1.17
diff -u -r1.17 manage_custom_field_update.php
--- manage_custom_field_update.php	3 Aug 2004 23:43:49 -0000	1.17
+++ manage_custom_field_update.php	27 Jul 2007 18:33:12 -0000
@@ -42,6 +42,19 @@
 
 	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);
+        $t_status_display[$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/schema.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/admin/schema.php,v
retrieving revision 1.19
diff -u -r1.19 schema.php
--- admin/schema.php	22 Jul 2007 19:51:18 -0000	1.19
+++ admin/schema.php	27 Jul 2007 22:18:01 -0000
@@ -152,6 +152,7 @@
   display_resolved 	L NOTNULL DEFAULT '0',
   display_closed 	L NOTNULL DEFAULT '0',
   require_closed 	L NOTNULL DEFAULT '0'
+  display_enum      C(255) NOTNULL DEFAULT \" '' \"
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_custom_field_name',config_get('mantis_custom_field_table'),'name'));
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_filters_table'),"
Index: core/custom_field_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/custom_field_api.php,v
retrieving revision 1.64
diff -u -r1.64 custom_field_api.php
--- core/custom_field_api.php	6 Jul 2007 07:30:16 -0000	1.64
+++ core/custom_field_api.php	27 Jul 2007 22:11:47 -0000
@@ -469,6 +469,27 @@
 		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_table = config_get( 'mantis_custom_field_table' );
+        $t_field_id = db_prepare_int( $p_field_id );
+
+        $c_value = db_prepare_string( serialize( $p_status_display ) );
+        
+        $t_set_query = "UPDATE $t_mantis_custom_field_table
+                        SET display_enum='$c_value'
+                        WHERE id = $t_field_id";
+                        
+        db_query( $t_set_query ) ;
+        
+        custom_field_clear_cache( $p_field_id ) ;
+
+        return true ;
+
+    }
+
 	# --------------------
 	# Add a custom field to a project
 	#  return true on success, false on failure or if already added
@@ -691,15 +712,60 @@
     	} else {
     		$t_ids = $g_cache_cf_linked[$p_project_id];
        }
        
 		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 ) {
+
+        # First get the array of custom fields for this project
+        $t_field_ids = custom_field_get_linked_ids( $p_project_id ) ;
+
+        $t_ids = array();
+
+        # For each custom field ID associated with this project
+        foreach ( $t_field_ids as $t_field )
+        {
+            # Get the serialized array of status display values
+            $row = custom_field_cache_row( $t_field ) ;
+            $t_displays = unserialize( $row['display_enum'] ) ;
+            
+            # If this field is displayed or required
+            if( $t_displays[$p_status_id] > 0 ) {
+            
+                # Add to the array of [field_id][required]
+                # Note that the 2nd value in the array is a boolean indicating if the field is
+                #  required (0=no, 1=yes). Since the value is stored in the database as 
+                #  1=display, 2=require, we must decrement the value here
+                array_push( $t_ids, array( $t_field, $t_displays[$p_status_id]-1 ) ) ;
+            }
+        }
+                
+        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 )
+    {   
+        # Get the row and unserialize the data
+        $row = custom_field_cache_row( $p_custom_field_id ) ;
+        
+        $t_ids = unserialize( $row['display_enum'] ) ;
+
+        return $t_ids ;
+    }
+
 	# --------------------
 	# Return an array all custom field ids sorted by name
 	function custom_field_get_ids( ) {
         global $g_cache_cf_list;

         if ( $g_cache_cf_list === NULL ) {
             $t_custom_field_table			= config_get( 'mantis_custom_field_table' );
             $query = "SELECT id, name
Index: lang/strings_english.txt
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/lang/strings_english.txt,v
retrieving revision 1.306
diff -u -r1.306 strings_english.txt
--- lang/strings_english.txt	25 Jul 2007 10:50:49 -0000	1.306
+++ lang/strings_english.txt	27 Jul 2007 15:28:11 -0000
@@ -1163,6 +1163,7 @@
 $s_update_custom_field_button = 'Update Custom Field';
 $s_add_existing_custom_field = 'Add This Existing Custom Field';
 $s_edit_custom_field_title = 'Edit custom field';
+$s_edit_custom_field_status_title = 'Edit custom field display properties';
 $s_custom_field = 'Field';
 $s_custom_fields_setup = 'Custom Fields';
 $s_custom_field_name = 'Name';
@@ -1187,6 +1188,9 @@
 $s_link_custom_field_to_project_title = 'Link custom field to project';
 $s_link_custom_field_to_project_button = 'Link Custom Field';
 $s_linked_projects = 'Linked Projects';
+$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';
mantisbt_3.patch (23,541 bytes)   
mantisbt_4.patch (25,132 bytes)   
? custom_contant_inc.php
? mantisbt.patch
Index: bug_change_status_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_change_status_page.php,v
retrieving revision 1.28
diff -u -r1.28 bug_change_status_page.php
--- bug_change_status_page.php	13 Jul 2007 07:58:26 -0000	1.28
+++ bug_change_status_page.php	27 Jul 2007 15:27:45 -0000
@@ -154,33 +154,14 @@
 
 <!-- Custom Fields -->
 <?php
-# @@@ thraxisp - I undid part of the change for #5068 for #5527
-#  We really need to say what fields are shown in which statusses. For now,
-#  this page will show required custom fields in update mode, or 
-#  display or required fields on resolve or close
-$t_custom_status_label = "update"; # Don't show custom fields by default
-if ( ( $f_new_status == $t_resolved ) &&
-			( CLOSED > $f_new_status ) ) {
-	$t_custom_status_label = "resolved";
-}
-if ( CLOSED == $f_new_status ) {
-	$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 ) ) {
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
@@ -193,20 +174,20 @@
 	</td>
 </tr>
 <?php
-	} #  custom_field_has_write_access( $t_id, $f_bug_id ) )
-	else if ( custom_field_has_read_access( $t_id, $f_bug_id ) ) {
+	} #  custom_field_has_write_access( $t_id[0], $f_bug_id ) )
+	else if ( custom_field_has_read_access( $t_id[0], $f_bug_id ) ) {
 ?>
 	<tr <?php echo helper_alternate_class() ?>>
 		<td class="category">
 			<?php echo lang_get_defaulted( $t_def['name'] ) ?>
 		</td>
 		<td>
-			<?php print_custom_field_value( $t_def, $t_id, $f_bug_id );			?>
+			<?php print_custom_field_value( $t_def, $t_id[0], $f_bug_id );			?>
 		</td>
 	</tr>
 <?php
-	} # custom_field_has_read_access( $t_id, $f_bug_id ) )
-} # foreach( $t_related_custom_field_ids as $t_id )
+	} # custom_field_has_read_access( $t_id[0], $f_bug_id ) )
+} # foreach( $t_related_custom_field_ids as $t_id[0] )
 ?>
 
 <?php
Index: bug_report_advanced_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_advanced_page.php,v
retrieving revision 1.65
diff -u -r1.65 bug_report_advanced_page.php
--- bug_report_advanced_page.php	13 Jul 2007 07:58:27 -0000	1.65
+++ bug_report_advanced_page.php	27 Jul 2007 15:27:45 -0000
@@ -415,16 +415,16 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' )  );
 
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_report']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td>
 		<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
Index: bug_report_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_page.php,v
retrieving revision 1.64
diff -u -r1.64 bug_report_page.php
--- bug_report_page.php	13 Jul 2007 07:58:27 -0000	1.64
+++ bug_report_page.php	27 Jul 2007 15:27:45 -0000
@@ -259,15 +259,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' ) );
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( ( $t_def['display_report'] && !$t_def['advanced'] ) || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( ( ( !$t_def['advanced'] ) || $t_id[1]) && custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if( $t_def['require_report'] ) { ?>
+		<?php if( $t_id[1] ) { ?>
 			<span class="required">*</span>
 		<?php } ?>
 		<?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
Index: bug_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update.php,v
retrieving revision 1.91
diff -u -r1.91 bug_update.php
--- bug_update.php	12 Dec 2006 18:26:28 -0000	1.91
+++ bug_update.php	27 Jul 2007 15:27:45 -0000
@@ -87,44 +87,28 @@
 
 	$t_resolved = config_get( 'bug_resolved_status_threshold' );
 
-	$t_custom_status_label = "update"; # default info to check
-	if ( $t_bug_data->status == $t_resolved ) {
-		$t_custom_status_label = "resolved";
-	}
-	if ( $t_bug_data->status == CLOSED ) {
-		$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 
+		# Only update the field if it is posted
 		#  ( will fail in custom_field_set_value(), if it was required )
 		if ( $t_custom_field_value === null ) {
 			continue;
 		}
 
 		# 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: /cvsroot/mantisbt/mantisbt/bug_update_advanced_page.php,v
retrieving revision 1.102
diff -u -r1.102 bug_update_advanced_page.php
--- bug_update_advanced_page.php	13 Jul 2007 07:58:28 -0000	1.102
+++ bug_update_advanced_page.php	27 Jul 2007 15:27:45 -0000
@@ -512,15 +512,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_update']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: bug_update_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update_page.php,v
retrieving revision 1.100
diff -u -r1.100 bug_update_page.php
--- bug_update_page.php	13 Jul 2007 07:58:28 -0000	1.100
+++ bug_update_page.php	27 Jul 2007 15:27:45 -0000
@@ -348,15 +348,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if ( $t_def['require_update'] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+        <?php if ( $t_id[1] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: bug_view_advanced_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_view_advanced_page.php,v
retrieving revision 1.85
diff -u -r1.85 bug_view_advanced_page.php
--- bug_view_advanced_page.php  11 Jul 2007 17:03:44 -0000  1.85
+++ bug_view_advanced_page.php  27 Jul 2007 23:50:02 -0000
@@ -474,7 +474,7 @@
 <!-- Custom Fields -->
 <?php
    $t_custom_fields_found = false;
-   $t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->project_id );
+   $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_bug->project_id );
    foreach( $t_related_custom_field_ids as $t_id ) {
        if ( !custom_field_has_read_access( $t_id, $f_bug_id ) ) {
            continue;
Index: bug_view_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_view_page.php,v
retrieving revision 1.87
diff -u -r1.87 bug_view_page.php
--- bug_view_page.php   11 Jul 2007 17:03:47 -0000  1.87
+++ bug_view_page.php   27 Jul 2007 23:45:13 -0000
@@ -351,7 +351,7 @@
 <!-- Custom Fields -->
 <?php
    $t_custom_fields_found = false;
-   $t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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['advanced'] && custom_field_has_read_access( $t_id, $f_bug_id ) ) {
Index: manage_custom_field_edit_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_edit_page.php,v
retrieving revision 1.25
diff -u -r1.25 manage_custom_field_edit_page.php
--- manage_custom_field_edit_page.php	18 May 2007 03:17:59 -0000	1.25
+++ manage_custom_field_edit_page.php	27 Jul 2007 15:27:45 -0000
@@ -129,73 +129,56 @@
 				<input type="checkbox" name="advanced" value="1" <?php check_checked( $t_definition['advanced'] ) ?> />
 			</td>
 		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_report" value="1" <?php check_checked( $t_definition['display_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_update" value="1" <?php check_checked( $t_definition['display_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_resolved" value="1" <?php check_checked( $t_definition['display_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_closed" value="1" <?php check_checked( $t_definition['display_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_report" value="1" <?php check_checked( $t_definition['require_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_update" value="1" <?php check_checked( $t_definition['require_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_resolved" value="1" <?php check_checked( $t_definition['require_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_closed" value="1" <?php check_checked( $t_definition['require_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr>
-			<td>&nbsp;</td>
-			<td>
+    </table>
+    <p />
+    <table class="width50" cellspacing="1">
+        <tr>
+            <td class="form-title" colspan="2">
+                <?php echo lang_get( 'edit_custom_field_status_title' ) ?>
+            </td>
+        </tr>
+        <tr>
+            <td class="small-caption" width="50%">
+                <?php echo lang_get( 'status' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_none' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_display' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_require' ) ?>
+            </td>
+        </tr>
+
+<?php
+    $t_enum_status = config_get( 'status_enum_string' );
+    $t_status_arr  = get_enum_to_array( $t_enum_status );
+    $t_lang_enum_status = lang_get( 'status_enum_string' );
+
+    $t_status_settings = custom_field_get_status_values( $f_field_id ) ;
+    foreach ( $t_status_arr as $t_status => $t_label ) {
+?>
+        <tr <?php echo helper_alternate_class() ?>>
+            <td class="category">
+                <?php echo get_enum_to_string( $t_lang_enum_status, $t_status ) ?>
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="0" <?php check_checked( $t_status_settings[$t_status], 0 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="1" <?php check_checked( $t_status_settings[$t_status], 1 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="2" <?php check_checked( $t_status_settings[$t_status], 2 ) ?> >
+            </td>
+        </tr>
+<?php
+    }
+?>
+        <tr>
+            <td colspan="4" align="center">
 				<input type="submit" class="button" value="<?php echo lang_get( 'update_custom_field_button' ) ?>" />
 			</td>
 		</tr>
Index: manage_custom_field_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_update.php,v
retrieving revision 1.17
diff -u -r1.17 manage_custom_field_update.php
--- manage_custom_field_update.php	3 Aug 2004 23:43:49 -0000	1.17
+++ manage_custom_field_update.php	27 Jul 2007 18:33:12 -0000
@@ -42,6 +42,19 @@
 
 	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);
+        $t_status_display[$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/schema.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/admin/schema.php,v
retrieving revision 1.19
diff -u -r1.19 schema.php
--- admin/schema.php	22 Jul 2007 19:51:18 -0000	1.19
+++ admin/schema.php	27 Jul 2007 22:18:01 -0000
@@ -152,6 +152,7 @@
   display_resolved 	L NOTNULL DEFAULT '0',
   display_closed 	L NOTNULL DEFAULT '0',
   require_closed 	L NOTNULL DEFAULT '0'
+  display_enum      C(255) NOTNULL DEFAULT \" '' \"
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_custom_field_name',config_get('mantis_custom_field_table'),'name'));
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_filters_table'),"
Index: core/custom_field_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/custom_field_api.php,v
retrieving revision 1.64
diff -u -r1.64 custom_field_api.php
--- core/custom_field_api.php	6 Jul 2007 07:30:16 -0000	1.64
+++ core/custom_field_api.php	27 Jul 2007 22:11:47 -0000
@@ -469,6 +469,27 @@
 		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_table = config_get( 'mantis_custom_field_table' );
+        $t_field_id = db_prepare_int( $p_field_id );
+
+        $c_value = db_prepare_string( serialize( $p_status_display ) );
+        
+        $t_set_query = "UPDATE $t_mantis_custom_field_table
+                        SET display_enum='$c_value'
+                        WHERE id = $t_field_id";
+                        
+        db_query( $t_set_query ) ;
+        
+        custom_field_clear_cache( $p_field_id ) ;
+
+        return true ;
+
+    }
+
 	# --------------------
 	# Add a custom field to a project
 	#  return true on success, false on failure or if already added
@@ -691,15 +712,60 @@
     	} else {
     		$t_ids = $g_cache_cf_linked[$p_project_id];
        }
        
 		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 ) {
+
+        # First get the array of custom fields for this project
+        $t_field_ids = custom_field_get_linked_ids( $p_project_id ) ;
+
+        $t_ids = array();
+
+        # For each custom field ID associated with this project
+        foreach ( $t_field_ids as $t_field )
+        {
+            # Get the serialized array of status display values
+            $row = custom_field_cache_row( $t_field ) ;
+            $t_displays = unserialize( $row['display_enum'] ) ;
+            
+            # If this field is displayed or required
+            if( $t_displays[$p_status_id] > 0 ) {
+            
+                # Add to the array of [field_id][required]
+                # Note that the 2nd value in the array is a boolean indicating if the field is
+                #  required (0=no, 1=yes). Since the value is stored in the database as 
+                #  1=display, 2=require, we must decrement the value here
+                array_push( $t_ids, array( $t_field, $t_displays[$p_status_id]-1 ) ) ;
+            }
+        }
+                
+        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 )
+    {   
+        # Get the row and unserialize the data
+        $row = custom_field_cache_row( $p_custom_field_id ) ;
+        
+        $t_ids = unserialize( $row['display_enum'] ) ;
+
+        return $t_ids ;
+    }
+
 	# --------------------
 	# Return an array all custom field ids sorted by name
 	function custom_field_get_ids( ) {
         global $g_cache_cf_list;

         if ( $g_cache_cf_list === NULL ) {
             $t_custom_field_table			= config_get( 'mantis_custom_field_table' );
             $query = "SELECT id, name
Index: lang/strings_english.txt
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/lang/strings_english.txt,v
retrieving revision 1.306
diff -u -r1.306 strings_english.txt
--- lang/strings_english.txt	25 Jul 2007 10:50:49 -0000	1.306
+++ lang/strings_english.txt	27 Jul 2007 15:28:11 -0000
@@ -1163,6 +1163,7 @@
 $s_update_custom_field_button = 'Update Custom Field';
 $s_add_existing_custom_field = 'Add This Existing Custom Field';
 $s_edit_custom_field_title = 'Edit custom field';
+$s_edit_custom_field_status_title = 'Edit custom field display properties';
 $s_custom_field = 'Field';
 $s_custom_fields_setup = 'Custom Fields';
 $s_custom_field_name = 'Name';
@@ -1187,6 +1188,9 @@
 $s_link_custom_field_to_project_title = 'Link custom field to project';
 $s_link_custom_field_to_project_button = 'Link Custom Field';
 $s_linked_projects = 'Linked Projects';
+$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';
mantisbt_4.patch (25,132 bytes)   
mantisbt_5.patch (37,460 bytes)   
? custom_contant_inc.php
? mantisbt.patch
Index: bug_change_status_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_change_status_page.php,v
retrieving revision 1.28
diff -u -r1.28 bug_change_status_page.php
--- bug_change_status_page.php	13 Jul 2007 07:58:26 -0000	1.28
+++ bug_change_status_page.php	27 Jul 2007 15:27:45 -0000
@@ -154,33 +154,14 @@
 
 <!-- Custom Fields -->
 <?php
-# @@@ thraxisp - I undid part of the change for #5068 for #5527
-#  We really need to say what fields are shown in which statusses. For now,
-#  this page will show required custom fields in update mode, or 
-#  display or required fields on resolve or close
-$t_custom_status_label = "update"; # Don't show custom fields by default
-if ( ( $f_new_status == $t_resolved ) &&
-			( CLOSED > $f_new_status ) ) {
-	$t_custom_status_label = "resolved";
-}
-if ( CLOSED == $f_new_status ) {
-	$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 ) ) {
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
@@ -193,20 +174,20 @@
 	</td>
 </tr>
 <?php
-	} #  custom_field_has_write_access( $t_id, $f_bug_id ) )
-	else if ( custom_field_has_read_access( $t_id, $f_bug_id ) ) {
+	} #  custom_field_has_write_access( $t_id[0], $f_bug_id ) )
+	else if ( custom_field_has_read_access( $t_id[0], $f_bug_id ) ) {
 ?>
 	<tr <?php echo helper_alternate_class() ?>>
 		<td class="category">
 			<?php echo lang_get_defaulted( $t_def['name'] ) ?>
 		</td>
 		<td>
-			<?php print_custom_field_value( $t_def, $t_id, $f_bug_id );			?>
+			<?php print_custom_field_value( $t_def, $t_id[0], $f_bug_id );			?>
 		</td>
 	</tr>
 <?php
-	} # custom_field_has_read_access( $t_id, $f_bug_id ) )
-} # foreach( $t_related_custom_field_ids as $t_id )
+	} # custom_field_has_read_access( $t_id[0], $f_bug_id ) )
+} # foreach( $t_related_custom_field_ids as $t_id[0] )
 ?>
 
 <?php
Index: bug_report.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report.php,v
retrieving revision 1.48
diff -u -r1.48 bug_report.php
--- bug_report.php	23 Jun 2007 04:25:40 -0000	1.48
+++ bug_report.php	29 Jul 2007 04:33:49 -0000
@@ -72,15 +72,15 @@
 	helper_call_custom_function( 'issue_create_validate', array( $t_bug_data ) );
 
 	# Validate the custom fields before adding the bug.
-	$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, config_get( 'bug_submit_status' ) );
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if ( $t_def['require_report'] && ( gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ) == '' ) ) {
-			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
+		$t_def = custom_field_get_definition( $t_id[0] );
+		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_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], $t_def['default_value'] ) ) ) {
-			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
+		if ( !custom_field_validate( $t_id[0], gpc_get_custom_field( "custom_field_".$t_id[0], $t_def['type'], $t_def['default_value'] ) ) ) {
+			error_parameters( lang_get_defaulted( custom_field_get_field( $t_id[0], 'name' ) ) );
 			trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
 		}
 	}
Index: bug_report_advanced_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_advanced_page.php,v
retrieving revision 1.65
diff -u -r1.65 bug_report_advanced_page.php
--- bug_report_advanced_page.php	13 Jul 2007 07:58:27 -0000	1.65
+++ bug_report_advanced_page.php	27 Jul 2007 15:27:45 -0000
@@ -415,16 +415,16 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' )  );
 
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_report']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td>
 		<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
Index: bug_report_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_report_page.php,v
retrieving revision 1.64
diff -u -r1.64 bug_report_page.php
--- bug_report_page.php	13 Jul 2007 07:58:27 -0000	1.64
+++ bug_report_page.php	27 Jul 2007 15:27:45 -0000
@@ -259,15 +259,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+    $t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_project_id, config_get( 'bug_submit_status' ) );
 	foreach( $t_related_custom_field_ids as $t_id ) {
-		$t_def = custom_field_get_definition( $t_id );
-		if( ( ( $t_def['display_report'] && !$t_def['advanced'] ) || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+		$t_def = custom_field_get_definition( $t_id[0] );
+		if( ( ( !$t_def['advanced'] ) || $t_id[1]) && custom_field_has_write_access_to_project( $t_id[0], $t_project_id ) ) {
 			$t_custom_fields_found = true;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if( $t_def['require_report'] ) { ?>
+		<?php if( $t_id[1] ) { ?>
 			<span class="required">*</span>
 		<?php } ?>
 		<?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
Index: bug_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update.php,v
retrieving revision 1.91
diff -u -r1.91 bug_update.php
--- bug_update.php	12 Dec 2006 18:26:28 -0000	1.91
+++ bug_update.php	27 Jul 2007 15:27:45 -0000
@@ -87,44 +87,28 @@
 
 	$t_resolved = config_get( 'bug_resolved_status_threshold' );
 
-	$t_custom_status_label = "update"; # default info to check
-	if ( $t_bug_data->status == $t_resolved ) {
-		$t_custom_status_label = "resolved";
-	}
-	if ( $t_bug_data->status == CLOSED ) {
-		$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 
+		# Only update the field if it is posted
 		#  ( will fail in custom_field_set_value(), if it was required )
 		if ( $t_custom_field_value === null ) {
 			continue;
 		}
 
 		# 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: /cvsroot/mantisbt/mantisbt/bug_update_advanced_page.php,v
retrieving revision 1.102
diff -u -r1.102 bug_update_advanced_page.php
--- bug_update_advanced_page.php	13 Jul 2007 07:58:28 -0000	1.102
+++ bug_update_advanced_page.php	27 Jul 2007 15:27:45 -0000
@@ -512,15 +512,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if($t_def['require_update']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		<?php if($t_id[1]) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: bug_update_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_update_page.php,v
retrieving revision 1.100
diff -u -r1.100 bug_update_page.php
--- bug_update_page.php	13 Jul 2007 07:58:28 -0000	1.100
+++ bug_update_page.php	27 Jul 2007 15:27:45 -0000
@@ -348,15 +348,15 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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;
 ?>
 <tr <?php echo helper_alternate_class() ?>>
 	<td class="category">
-		<?php if ( $t_def['require_update'] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+        <?php if ( $t_id[1] ) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
 	</td>
 	<td colspan="5">
 		<?php
Index: bug_view_advanced_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_view_advanced_page.php,v
retrieving revision 1.85
diff -u -r1.85 bug_view_advanced_page.php
--- bug_view_advanced_page.php	11 Jul 2007 17:03:44 -0000	1.85
+++ bug_view_advanced_page.php	27 Jul 2007 23:50:02 -0000
@@ -474,7 +474,7 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->project_id );
+	$t_related_custom_field_ids = custom_field_get_linked_status_ids( $t_bug->project_id );
 	foreach( $t_related_custom_field_ids as $t_id ) {
 		if ( !custom_field_has_read_access( $t_id, $f_bug_id ) ) {
 			continue;
Index: bug_view_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/bug_view_page.php,v
retrieving revision 1.87
diff -u -r1.87 bug_view_page.php
--- bug_view_page.php	11 Jul 2007 17:03:47 -0000	1.87
+++ bug_view_page.php	29 Jul 2007 04:25:02 -0000
@@ -351,7 +351,7 @@
 <!-- Custom Fields -->
 <?php
 	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug->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['advanced'] && custom_field_has_read_access( $t_id, $f_bug_id ) ) {
Index: manage_custom_field_edit_page.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_edit_page.php,v
retrieving revision 1.25
diff -u -r1.25 manage_custom_field_edit_page.php
--- manage_custom_field_edit_page.php	18 May 2007 03:17:59 -0000	1.25
+++ manage_custom_field_edit_page.php	27 Jul 2007 15:27:45 -0000
@@ -129,73 +129,56 @@
 				<input type="checkbox" name="advanced" value="1" <?php check_checked( $t_definition['advanced'] ) ?> />
 			</td>
 		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_report" value="1" <?php check_checked( $t_definition['display_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_update" value="1" <?php check_checked( $t_definition['display_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_resolved" value="1" <?php check_checked( $t_definition['display_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_display_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="display_closed" value="1" <?php check_checked( $t_definition['display_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_report' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_report" value="1" <?php check_checked( $t_definition['require_report'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_update' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_update" value="1" <?php check_checked( $t_definition['require_update'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_resolved' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_resolved" value="1" <?php check_checked( $t_definition['require_resolved'] ) ?> />
-			</td>
-		</tr>
-		<tr <?php echo helper_alternate_class() ?>>
-			<td class="category">
-				<?php echo lang_get( 'custom_field_require_closed' ) ?>
-			</td>
-			<td>
-				<input type="checkbox" name="require_closed" value="1" <?php check_checked( $t_definition['require_closed'] ) ?> />
-			</td>
-		</tr>
-		<tr>
-			<td>&nbsp;</td>
-			<td>
+    </table>
+    <p />
+    <table class="width50" cellspacing="1">
+        <tr>
+            <td class="form-title" colspan="2">
+                <?php echo lang_get( 'edit_custom_field_status_title' ) ?>
+            </td>
+        </tr>
+        <tr>
+            <td class="small-caption" width="50%">
+                <?php echo lang_get( 'status' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_none' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_display' ) ?>
+            </td>
+            <td class="small-caption">
+                <?php echo lang_get( 'custom_field_require' ) ?>
+            </td>
+        </tr>
+
+<?php
+    $t_enum_status = config_get( 'status_enum_string' );
+    $t_status_arr  = get_enum_to_array( $t_enum_status );
+    $t_lang_enum_status = lang_get( 'status_enum_string' );
+
+    $t_status_settings = custom_field_get_status_values( $f_field_id ) ;
+    foreach ( $t_status_arr as $t_status => $t_label ) {
+?>
+        <tr <?php echo helper_alternate_class() ?>>
+            <td class="category">
+                <?php echo get_enum_to_string( $t_lang_enum_status, $t_status ) ?>
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="0" <?php check_checked( $t_status_settings[$t_status], 0 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="1" <?php check_checked( $t_status_settings[$t_status], 1 ) ?> >
+            </td>
+            <td>
+                <input type="radio" name="status_<?php echo $t_status?>" value="2" <?php check_checked( $t_status_settings[$t_status], 2 ) ?> >
+            </td>
+        </tr>
+<?php
+    }
+?>
+        <tr>
+            <td colspan="4" align="center">
 				<input type="submit" class="button" value="<?php echo lang_get( 'update_custom_field_button' ) ?>" />
 			</td>
 		</tr>
Index: manage_custom_field_update.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/manage_custom_field_update.php,v
retrieving revision 1.17
diff -u -r1.17 manage_custom_field_update.php
--- manage_custom_field_update.php	3 Aug 2004 23:43:49 -0000	1.17
+++ manage_custom_field_update.php	29 Jul 2007 04:41:16 -0000
@@ -31,16 +31,20 @@
 	$t_values['length_min']			= gpc_get_int( 'length_min' );
 	$t_values['length_max']			= gpc_get_int( 'length_max' );
 	$t_values['advanced']			= gpc_get_bool( 'advanced' );
-	$t_values['display_report']	= gpc_get_bool( 'display_report' );
-	$t_values['display_update']	= gpc_get_bool( 'display_update' );
-	$t_values['display_resolved']	= gpc_get_bool( 'display_resolved' );
-	$t_values['display_closed']		= gpc_get_bool( 'display_closed' );
-	$t_values['require_report']		= gpc_get_bool( 'require_report' );
-	$t_values['require_update']		= gpc_get_bool( 'require_update' );
-	$t_values['require_resolved']	= gpc_get_bool( 'require_resolved' );
-	$t_values['require_closed']		= gpc_get_bool( 'require_closed' );
 
-	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);
+        $t_status_display[$t_status] = $t_status_display_val ;
+    }
+    
+    $t_values['display_enum']       = serialize( $t_status_display ) ;
+
+    custom_field_update( $f_field_id, $t_values );
 
 	html_page_top1();
 
Index: admin/install.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/admin/install.php,v
retrieving revision 1.33
diff -u -r1.33 install.php
--- admin/install.php	10 Jul 2007 07:04:56 -0000	1.33
+++ admin/install.php	29 Jul 2007 04:58:34 -0000
@@ -61,7 +61,52 @@
 		return Array( $query );
 	}
 
-
+    # This function will migrate custom field display/require settings 
+    #  to the new method of storing them as a list per #5744 '
+    # This function must be called AFTER the new field has been added to the
+    #  custom_field table AND all patches to PHP files have been applied, but 
+    #  BEFORE the old booleans (require_report, etc) are removed from the table
+    function migrateCustomFieldDisplay() {
+        $t_field_ids = custom_field_get_ids() ;
+        $t_enum_status = config_get( 'status_enum_string' ) ;
+        $t_status_arr  = get_enum_to_array( $t_enum_status );
+        $t_report_status = config_get( 'bug_submit_status' ) ;
+        $t_closed_status = CLOSED ;
+        $t_resolved_status = config_get( 'bug_resolved_status_threshold' ) ;
+        
+        foreach( $t_field_ids as $t_field_id )
+        {
+            $t_status_display = array() ;
+            $t_field = custom_field_cache_row( $t_field_id ) ;
+            
+            foreach ( $t_status_arr as $t_status => $t_label ) {
+                if( $t_status == $t_report_status ) {
+                    $t_custom_status_label = "report" ;
+                } elseif ( $t_status == $t_resolved_status ) {
+                    $t_custom_status_label = "resolved" ;
+                } elseif ( $t_status == $t_closed_status ) {
+                    $t_custom_status_label = "closed" ;
+                } else {
+                    $t_custom_status_label = "update" ;
+                }
+                
+                $t_display = $t_field['display_' . $t_custom_status_label];
+                $t_require = $t_field['require_' . $t_custom_status_label];
+                
+                $t_status_display_val = 0;
+                if( $t_display ) $t_status_display_val = 1;
+                if( $t_require ) $t_status_display_val = 2;
+                
+                $t_status_display[$t_status] = $t_status_display_val ;
+            }
+
+            $t_field['display_enum']       = serialize( $t_status_display ) ;
+
+            # Update the custom field status display values
+            custom_field_update( $t_field_id, $t_field );
+            
+        }        
+    }
 
 	# install_state
 	#   0 = no checks done
Index: admin/schema.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/admin/schema.php,v
retrieving revision 1.19
diff -u -r1.19 schema.php
--- admin/schema.php	22 Jul 2007 19:51:18 -0000	1.19
+++ admin/schema.php	27 Jul 2007 23:57:50 -0000
@@ -144,14 +144,7 @@
   length_min 		 I  NOTNULL DEFAULT '0',
   length_max 		 I  NOTNULL DEFAULT '0',
   advanced 		L NOTNULL DEFAULT '0',
-  require_report 	L NOTNULL DEFAULT '0',
-  require_update 	L NOTNULL DEFAULT '0',
-  display_report 	L NOTNULL DEFAULT '1',
-  display_update 	L NOTNULL DEFAULT '1',
-  require_resolved 	L NOTNULL DEFAULT '0',
-  display_resolved 	L NOTNULL DEFAULT '0',
-  display_closed 	L NOTNULL DEFAULT '0',
-  require_closed 	L NOTNULL DEFAULT '0'
+  display_enum      C(255) NOTNULL DEFAULT \" '' \"
 ",Array('mysql' => 'TYPE=MyISAM', 'pgsql' => 'WITHOUT OIDS')));
 $upgrade[] = Array('CreateIndexSQL',Array('idx_custom_field_name',config_get('mantis_custom_field_table'),'name'));
 $upgrade[] = Array('CreateTableSQL',Array(config_get('mantis_filters_table'),"
Index: api/soap/mantisconnect.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/api/soap/mantisconnect.php,v
retrieving revision 1.1
diff -u -r1.1 mantisconnect.php
--- api/soap/mantisconnect.php	18 Jul 2007 06:52:47 -0000	1.1
+++ api/soap/mantisconnect.php	29 Jul 2007 04:18:36 -0000
@@ -479,14 +479,7 @@
 			'length_min'		=>	array( 'name' => 'length_min',		'type' => 'xsd:integer', 	'minOccurs' => '0'),
 			'length_max'		=>	array( 'name' => 'length_max',		'type' => 'xsd:integer', 	'minOccurs' => '0'),
 			'advanced'			=>	array( 'name' => 'advanced',		'type' => 'xsd:boolean', 	'minOccurs' => '0'),
-			'display_report'	=>	array( 'name' => 'display_report',	'type' => 'xsd:boolean', 	'minOccurs' => '0'),
-			'display_update'	=>	array( 'name' => 'display_update',	'type' => 'xsd:boolean', 	'minOccurs' => '0'),
-			'display_resolved'	=>	array( 'name' => 'display_resolved','type' => 'xsd:boolean', 	'minOccurs' => '0'),
-			'display_closed'	=>	array( 'name' => 'display_closed',	'type' => 'xsd:boolean', 	'minOccurs' => '0'),
-			'require_report'	=>	array( 'name' => 'require_report',	'type' => 'xsd:boolean', 	'minOccurs' => '0'),
-			'require_update'	=>	array( 'name' => 'require_update',	'type' => 'xsd:boolean', 	'minOccurs' => '0'),
-			'require_resolved'	=>	array( 'name' => 'require_resolved','type' => 'xsd:boolean', 	'minOccurs' => '0'),
-			'require_closed'	=>	array( 'name' => 'require_closed',	'type' => 'xsd:boolean', 	'minOccurs' => '0')
+			'display_enum'	    =>	array( 'name' => 'display_enum',	'type' => 'xsd:string', 	'minOccurs' => '0')
 		)
 	);
 
Index: api/soap/mc_project_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/api/soap/mc_project_api.php,v
retrieving revision 1.1
diff -u -r1.1 mc_project_api.php
--- api/soap/mc_project_api.php	18 Jul 2007 06:52:56 -0000	1.1
+++ api/soap/mc_project_api.php	29 Jul 2007 04:18:28 -0000
@@ -435,14 +435,7 @@
 					'length_min'		=> $t_def['length_min'],
 					'length_max'		=> $t_def['length_max'],
 					'advanced'			=> $t_def['advanced'],
-					'display_report'	=> $t_def['display_report'],
-					'display_update'	=> $t_def['display_update'],
-					'display_resolved'	=> $t_def['display_resolved'],
-					'display_closed'	=> $t_def['display_closed'],
-					'require_report'	=> $t_def['require_report'],
-					'require_update'	=> $t_def['require_update'],
-					'require_resolved'	=> $t_def['require_resolved'],
-					'require_closed'	=> $t_def['require_closed'],
+					'display_enum'	    => $t_def['display_enum']
 				);
 			}
 		}
Index: core/custom_field_api.php
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/core/custom_field_api.php,v
retrieving revision 1.64
diff -u -r1.64 custom_field_api.php
--- core/custom_field_api.php	6 Jul 2007 07:30:16 -0000	1.64
+++ core/custom_field_api.php	29 Jul 2007 04:59:04 -0000
@@ -280,15 +280,8 @@
 		$c_access_level_rw	= db_prepare_int(    $p_def_array['access_level_rw'] );
 		$c_length_min		= db_prepare_int(    $p_def_array['length_min']      );
 		$c_length_max		= db_prepare_int(    $p_def_array['length_max']      );
-		$c_advanced			= db_prepare_bool(   $p_def_array['advanced']        );
-		$c_display_report	= db_prepare_bool( 	 $p_def_array['display_report'] );
-		$c_display_update	= db_prepare_bool( 	 $p_def_array['display_update'] );
-		$c_display_resolved	= db_prepare_bool( 	 $p_def_array['display_resolved'] );
-		$c_display_closed	= db_prepare_bool( 	 $p_def_array['display_closed']   );
-		$c_require_report	= db_prepare_bool( 	 $p_def_array['require_report']  );
-		$c_require_update	= db_prepare_bool( 	 $p_def_array['require_update']  );
-		$c_require_resolved = db_prepare_bool( 	 $p_def_array['require_resolved'] );
-		$c_require_closed	= db_prepare_bool( 	 $p_def_array['require_closed']   );
+        $c_advanced         = db_prepare_bool(   $p_def_array['advanced']        );
+        $c_display_enum     = db_prepare_string( $p_def_array['display_enum']    );
 
 		if (( is_blank( $c_name ) ) ||
 			( $c_access_level_rw < $c_access_level_r ) ||
@@ -297,11 +290,6 @@
 			trigger_error( ERROR_CUSTOM_FIELD_INVALID_DEFINITION, ERROR );
 		}
 
-		if ( $c_advanced == true && ( $c_require_report == true || $c_require_update ) ) {
-			trigger_error( ERROR_CUSTOM_FIELD_INVALID_DEFINITION, ERROR );
-		}
-
-
 		if ( !custom_field_is_name_unique( $c_name, $c_field_id ) ) {
 			trigger_error( ERROR_CUSTOM_FIELD_NAME_NOT_UNIQUE, ERROR );
 		}
@@ -382,78 +370,22 @@
 			}
 			$query .= "length_max='$c_length_max'";
 		}
-		if( array_key_exists( 'advanced', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "advanced='$c_advanced'";
-		}
-		if( array_key_exists( 'display_report', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "display_report='$c_display_report'";
-		}
-		if( array_key_exists( 'display_update', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "display_update='$c_display_update'";
-		}
-		if( array_key_exists( 'display_resolved', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "display_resolved='$c_display_resolved'";
-		}
-		if( array_key_exists( 'display_closed', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "display_closed='$c_display_closed'";
-		}
-		if( array_key_exists( 'require_report', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "require_report='$c_require_report'";
-		}
-		if( array_key_exists( 'require_update', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "require_update='$c_require_update'";
-		}
-		if( array_key_exists( 'require_resolved', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "require_resolved='$c_require_resolved'";
-		}
-		if( array_key_exists( 'require_closed', $p_def_array ) ) {
-			if ( !$t_update_something ) {
-				$t_update_something = true;
-			} else {
-				$query .= ', ';
-			}
-			$query .= "require_closed='$c_require_closed'";
-		}
+        if( array_key_exists( 'advanced', $p_def_array ) ) {
+            if ( !$t_update_something ) {
+                $t_update_something = true;
+            } else {
+                $query .= ', ';
+            }
+            $query .= "advanced='$c_advanced'";
+        }
+        if( array_key_exists( 'display_enum', $p_def_array ) ) {
+            if ( !$t_update_something ) {
+                $t_update_something = true;
+            } else {
+                $query .= ', ';
+            }
+            $query .= "display_enum='$c_display_enum'";
+        }
 
 
 		$query .= " WHERE id='$c_field_id'";
@@ -691,15 +623,60 @@
     	} else {
     		$t_ids = $g_cache_cf_linked[$p_project_id];
         }
        
 		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 ) {
+
+        # First get the array of custom fields for this project
+        $t_field_ids = custom_field_get_linked_ids( $p_project_id ) ;
+
+        $t_ids = array();
+
+        # For each custom field ID associated with this project
+        foreach ( $t_field_ids as $t_field )
+        {
+            # Get the serialized array of status display values
+            $row = custom_field_cache_row( $t_field ) ;
+            $t_displays = unserialize( $row['display_enum'] ) ;
+            
+            # If this field is displayed or required
+            if( $t_displays[$p_status_id] > 0 ) {
+            
+                # Add to the array of [field_id][required]
+                # Note that the 2nd value in the array is a boolean indicating if the field is
+                #  required (0=no, 1=yes). Since the value is stored in the database as 
+                #  1=display, 2=require, we must decrement the value here
+                array_push( $t_ids, array( $t_field, $t_displays[$p_status_id]-1 ) ) ;
+            }
+        }
+                
+        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 )
+    {   
+        # Get the row and unserialize the data
+        $row = custom_field_cache_row( $p_custom_field_id ) ;
+        
+        $t_ids = unserialize( $row['display_enum'] ) ;
+
+        return $t_ids ;
+    }
+
 	# --------------------
 	# Return an array all custom field ids sorted by name
 	function custom_field_get_ids( ) {
         global $g_cache_cf_list;
       
         if ( $g_cache_cf_list === NULL ) {
             $t_custom_field_table			= config_get( 'mantis_custom_field_table' );
             $query = "SELECT id, name
Index: lang/strings_english.txt
===================================================================
RCS file: /cvsroot/mantisbt/mantisbt/lang/strings_english.txt,v
retrieving revision 1.306
diff -u -r1.306 strings_english.txt
--- lang/strings_english.txt	25 Jul 2007 10:50:49 -0000	1.306
+++ lang/strings_english.txt	29 Jul 2007 04:19:38 -0000
@@ -1163,6 +1163,7 @@
 $s_update_custom_field_button = 'Update Custom Field';
 $s_add_existing_custom_field = 'Add This Existing Custom Field';
 $s_edit_custom_field_title = 'Edit custom field';
+$s_edit_custom_field_status_title = 'Edit custom field display properties';
 $s_custom_field = 'Field';
 $s_custom_fields_setup = 'Custom Fields';
 $s_custom_field_name = 'Name';
@@ -1176,17 +1177,12 @@
 $s_custom_field_length_min = 'Min. Length';
 $s_custom_field_length_max = 'Max. Length';
 $s_custom_field_advanced = 'Display Only On Advanced Page';
-$s_custom_field_display_report = 'Display When Reporting Issues';
-$s_custom_field_display_update = 'Display When Updating Issues';
-$s_custom_field_display_resolved = 'Display When Resolving Issues';
-$s_custom_field_display_closed = 'Display When Closing Issues';
-$s_custom_field_require_report = 'Required On Report';
-$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_link_custom_field_to_project_title = 'Link custom field to project';
 $s_link_custom_field_to_project_button = 'Link Custom Field';
 $s_linked_projects = 'Linked Projects';
+$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';
mantisbt_5.patch (37,460 bytes)   

Relationships

has duplicate 0009195 closedatrol Display when Reporting, Resolving and Closing fields should be merged 
has duplicate 0013494 closedatrol Allow configuration of which custom fields to display/require upon which status changes 
has duplicate 0013610 closedatrol Allow configuration of which custom fields to display/require upon which status changes 
has duplicate 0012886 closedatrol Mandatory Custom Status for Custom Fields 
has duplicate 0014758 closedatrol Display / Require custom fileds when updating to a custom status 

Activities

thraxisp

thraxisp

2005-06-08 11:42

reporter   ~0010424

It was in my plans...

illes

illes

2006-04-25 11:27

reporter   ~0012722

Nice feature, I'm waiting for this one too.

roleary

roleary

2007-07-26 20:08

reporter   ~0015232

Last edited: 2007-07-26 20:22

I'm pretty much finished with a patch to implement this behavior. I need some guidance from the devs on how to handle upgrading from an older version to a version that supports this.

I've attached the current version of the patch. This patch allows you to specify, for each Custom Field, whether you would like that field Not Shown, Displayed, or Required for each Status. PATCH IS FOR 1.0.8

I believe I've covered all the bases here, but there are still some issues that need to be resolved. Mainly, I have not yet stripped the old "require_update", "display_update"... etc. and I have not implemented any sort of upgrade code.

If any of the devs could contact me, I would happy to work through my remaining issues and formally submit this, however that's done. I can update the code to patch to the latest version also.

roleary

roleary

2007-07-27 01:47

reporter   ~0015233

Last edited: 2007-07-27 11:52

Just uploaded new patch that will work on the current CVS repository.

Please use the latest patch above for 1.0.4a (mantisbt_2.patch). If someone can delete the other files, that would be great.

roleary

roleary

2007-07-27 18:32

reporter   ~0015247

mantisbt_3.patch

This patch contains the same functionality as "_2", but with the data stored in a list in a new column on the custom_field table instead of in a whole new table.

roleary

roleary

2007-07-27 20:55

reporter   ~0015249

Last edited: 2007-07-28 02:57

mantisbt_4.patch

Contains additional fixes as discussed in IRC:

<pre>
<roleary> Issue 0000001 - The viewing of the issue. The custom fields always show in that read-only view on top of the bug if they're assigned to the project. A couple ways to change that: either:
<roleary> a) leave as is
<roleary> b) only show when the field is "display" or "require" for the current status
<roleary> c) show when the field is "display" or "require" for any status <= the current status
<roleary> d) other ways?
<thraxisp> roleary: for 0000001, I like b. Display also needs to meet the read/write access levels.
</pre>

grangeway

grangeway

2007-07-28 15:10

reporter   ~0015264

fwiw, assigned to myself as i'm trying to merge this with another patch.

roleary

roleary

2007-07-29 01:23

reporter   ~0015267

mantisbt_5.patch

This patch includes removal of all references to the old "display" and "require" values for custom fields.

Also, this patch includes a new function in admin/install.php that will migrate the existing custom field data. This new function (migrateCustomFieldDisplay()) must be called AFTER the patch has been applied to PHP files and AFTER the new field has been added to the custom_field table, but BEFORE the old fields in the custom_field table have been removed. This function is currently not called anywhere (waiting on help from thraxisp here), but I have tested it to make sure it works.

Additionally, there are some outstanding issues I am waiting for guidance on:
1) I only updated lang/string_english.txt, not any other language. Should I make the change to all files and leave the values blank?
2) I updated the API code accordingly, but currently it will return the serialized array as a string for the new field in custom_field. Not sure if that's the correct way to handle serialized data. Does the serialized array need to be unserialized and returned value-by-value? Or just as a string?
3) Do I need to do anything with admin/upgrades files? I'm not quite sure what their purpose is or how to go about creating an upgrade file for the changed schema.

vboctor

vboctor

2007-07-29 03:18

manager   ~0015270

A quick answer to your localization question. You only need to update strings_english.txt. Any string that is not in the current language will be defaulted to the English string.

It would be great if we can create a requirements wiki page that explains what this feature achieves and possible includes screen captures. This will make it easier to review the feature on high level. This will also be a good starting point for the feature documentation.

Browse through the requirements section in the Wiki to get an idea of what I mean:
http://www.mantisbt.org/wiki/doku.php/mantisbt:requirements

roleary

roleary

2007-07-29 17:17

reporter   ~0015279

Create a requirements page on the wiki per vboctor's request:
http://www.mantisbt.org/wiki/doku.php/mantisbt:custom_field_display_requirements

illes

illes

2007-07-30 03:49

reporter   ~0015285

Nice documentation, thanks, I can only agree with that.

emathieu

emathieu

2007-07-30 09:27

reporter   ~0015296

Could be a good idea to expand it to default fields.

In the requirements page, can you explain what is exactly the meaning of "None" and "Display"

malaussena

malaussena

2007-09-18 12:26

reporter   ~0015659

I have only one thing to say (as the reporter)… very good work !

I hope to see leaving version 1.2.0 very quickly!

cbasset

cbasset

2009-05-28 12:32

reporter   ~0021959

I've upload a new patch for the following reasons:

  • it fixes an issue in the view bug page
  • it adds possible workarounds for update as displaying fields depending on current status might be an issue if the update includes a status change.
  • it is more convenient to apply to current release

See readme.txt file included in the zip for more informations.

cbasset

cbasset

2009-05-29 05:00

reporter   ~0021966

Upload v2 version of patch, lang file was missing in first upload.

Jheredero

Jheredero

2009-06-18 04:46

reporter   ~0022190

Last edited: 2009-06-18 04:50

Hello,

I have installed the pacth, it is very interesting, but I have a grant problem, when I reported a issue (status NEW), the values of the custom fields don´t record (are defined how required), In the other status and when it is recorded and updated work perfectly. do you know which can to be the reason?.
The only thing that no work of steps of the path documentation is the drop the constraints, these dont work but i undertand that isn´t the reason because in the other status work good.

Thank you and sorry for my english.

costinnila

costinnila

2009-10-01 08:27

reporter   ~0023047

There is a problem in bug_update.php at line 129.
No $ sign in front of t_field_value. Because of this the required fields are not checked properly.

serom

serom

2010-07-02 04:15

reporter   ~0026015

I'm having problems with this patch in Mantis 1.2.1. Is there a new patch for the latest version of mantis?

irineus

irineus

2011-02-11 10:28

reporter   ~0028207

It seems this patch doesn't work anymore with newer version (1.2.0 and up). There's any directions to do this in these new versions?

illes

illes

2012-02-07 05:12

reporter   ~0031178

Any update on the status of this issue?

atrol

atrol

2014-01-21 16:03

developer   ~0039117

Unassigned after having been assigned for a long time without progress.

cristobal.manrique

cristobal.manrique

2020-02-15 23:14

reporter   ~0063640

I've just developed a plugin for this.
I guess it is very simple, and of course it can be improved, but for the moment it is a very useful tool, taking into account that it does not require any patch to mantis core files.

Unzip this to your plugins folder, go to manage/manage plugins and check the /doc folder for instructions.

Status_Custom_Fields.zip (137,010 bytes)
martin.fernau

martin.fernau

2022-04-11 03:28

reporter   ~0066416

@cristobal.manrique Thanks for the Plugin! I just tried it and is works very well