From 7dfab37c3c79328d55aa851190a86414f5664cf0 Mon Sep 17 00:00:00 2001
From: Damien Regad <damien.regad@merckgroup.com>
Date: Thu, 15 Dec 2011 16:43:14 +0100
Subject: [PATCH] Fix cross-project display of custom status colors

When a custom status is defined in a different project, its custom
color was not used (displayed white) in the following cases

- view issue details page, relationship
- View Issues
- My View
- Sponsorship
- Bug group action list

Fixes #13682
---
 account_sponsor_page.php      |    4 ++--
 core/bug_group_action_api.php |    5 ++++-
 core/helper_api.php           |   10 ++++++----
 core/relationship_api.php     |    4 +++-
 my_view_inc.php               |    2 +-
 view_all_inc.php              |    2 +-
 6 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/account_sponsor_page.php b/account_sponsor_page.php
index fd7fa55..b8ba78d 100644
--- a/account_sponsor_page.php
+++ b/account_sponsor_page.php
@@ -136,7 +136,7 @@
 				$t_released_label = $t_bug->fixed_in_version;
 			}
 
-			echo '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">';
+			echo '<tr bgcolor="' . get_status_color( $t_bug->status, auth_get_current_user_id(), $t_bug->project_id ) . '">';
 			echo '<td><a href="' . string_get_bug_view_url( $row['bug'] ) . '">' . bug_format_id( $row['bug'] ) . '</a></td>';
 			echo '<td>' . project_get_field( $t_bug->project_id, 'name' ) . '&#160;</td>';
 			echo '<td class="right">' . $t_released_label . '&#160;</td>';
@@ -246,7 +246,7 @@
 				$t_released_label = $t_bug->fixed_in_version;
 			}
 
-			echo '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">';
+			echo '<tr bgcolor="' . get_status_color( $t_bug->status, auth_get_current_user_id(), $t_bug->project_id ) . '">';
 			echo '<td><a href="' . string_get_bug_view_url( $row['bug'] ) . '">' . bug_format_id( $row['bug'] ) . '</a></td>';
 			echo '<td>' . project_get_field( $t_bug->project_id, 'name' ) . '&#160;</td>';
 			echo '<td class="right">' . $t_released_label . '&#160;</td>';
diff --git a/core/bug_group_action_api.php b/core/bug_group_action_api.php
index ef57fd4..ac3cb1e 100644
--- a/core/bug_group_action_api.php
+++ b/core/bug_group_action_api.php
@@ -80,7 +80,10 @@ function bug_group_action_print_bug_list( $p_bug_ids_array ) {
 
 	foreach( $p_bug_ids_array as $t_bug_id ) {
 		$t_class = sprintf( "row-%d", ( $t_i++ % 2 ) + 1 );
-		echo sprintf( "<tr bgcolor=\"%s\"> <td>%s</td> <td>%s</td> </tr>\n", get_status_color( bug_get_field( $t_bug_id, 'status' ) ), string_get_bug_view_link( $t_bug_id ), string_attribute( bug_get_field( $t_bug_id, 'summary' ) ) );
+		echo sprintf( "<tr bgcolor=\"%s\"> <td>%s</td> <td>%s</td> </tr>\n",
+			get_status_color( bug_get_field( $t_bug_id, 'status' ), auth_get_current_user_id(), bug_get_field( $t_bug_id, 'project_id' ) ),
+			string_get_bug_view_link( $t_bug_id ),
+			string_attribute( bug_get_field( $t_bug_id, 'summary' ) ) );
 	}
 
 	echo '</table>';
diff --git a/core/helper_api.php b/core/helper_api.php
index ab0d902..5c80946 100644
--- a/core/helper_api.php
+++ b/core/helper_api.php
@@ -68,13 +68,15 @@ function helper_alternate_class( $p_index = null, $p_odd_class = 'row-1', $p_eve
 }
 
 /**
- * get the color string for the given status
+ * get the color string for the given status, user and project
  * @param int $p_status
+ * @param int|null $p_user user id, defaults to null (all users)
+ * @param int|null $p_project project id, defaults to null (all projects)
  * @return string
  */
-function get_status_color( $p_status ) {
-	$t_status_label = MantisEnum::getLabel( config_get( 'status_enum_string' ), $p_status );
-	$t_status_colors = config_get( 'status_colors' );
+function get_status_color( $p_status, $p_user = null, $p_project = null ) {
+	$t_status_label = MantisEnum::getLabel( config_get( 'status_enum_string', null, $p_user, $p_project ), $p_status );
+	$t_status_colors = config_get( 'status_colors', null, $p_user, $p_project );
 	$t_color = '#ffffff';
 
 	if ( isset( $t_status_colors[$t_status_label] ) ) {
diff --git a/core/relationship_api.php b/core/relationship_api.php
index a895b23..d5b78eb 100644
--- a/core/relationship_api.php
+++ b/core/relationship_api.php
@@ -677,7 +677,9 @@ function relationship_get_details( $p_bug_id, $p_relationship, $p_html = false,
 	$t_relationship_info_text .= "\n";
 
 	if( $p_html_preview == false ) {
-		$t_relationship_info_html = '<tr bgcolor="' . get_status_color( $t_bug->status ) . '">' . $t_relationship_info_html . '</tr>' . "\n";
+		$t_relationship_info_html = '<tr bgcolor="'
+			. get_status_color( $t_bug->status, auth_get_current_user_id(), $t_bug->project_id )
+			. '">' . $t_relationship_info_html . '</tr>' . "\n";
 	} else {
 		$t_relationship_info_html = '<tr>' . $t_relationship_info_html . '</tr>';
 	}
diff --git a/my_view_inc.php b/my_view_inc.php
index 892ce64..cedc67f 100644
--- a/my_view_inc.php
+++ b/my_view_inc.php
@@ -432,7 +432,7 @@ echo "($v_start - $v_end / $t_bug_count)";
 	$t_last_updated = date( config_get( 'normal_date_format' ), $t_bug->last_updated );
 
 	# choose color based on status
-	$status_color = get_status_color( $t_bug->status );
+	$status_color = get_status_color( $t_bug->status, auth_get_current_user_id(), $t_bug->project_id );
 
 	# Check for attachments
 	$t_attachment_count = 0;
diff --git a/view_all_inc.php b/view_all_inc.php
index 0972a83..dfd0d09 100644
--- a/view_all_inc.php
+++ b/view_all_inc.php
@@ -202,7 +202,7 @@
 			}
 
 			# choose color based on status
-			$status_color = get_status_color( $t_row->status );
+			$status_color = get_status_color( $t_row->status, auth_get_current_user_id(), $t_row->project_id );
 
 			echo '<tr bgcolor="', $status_color, '" border="1" valign="top">';
 
-- 
1.7.5.4

