From 8f4a3c40756d7d688a0c99aa17681ec8e76a0a22 Mon Sep 17 00:00:00 2001
From: Damien Regad <damien.regad@merckgroup.com>
Date: Wed, 14 Dec 2011 17:20:48 +0100
Subject: [PATCH] Correct display custom status in cross-project relationships

In the bug relationships section in view.php, the target bug's status
was incorrectly displayed as "@X@" (where X is the status_enum id) if
the following conditions were true:
 - the target bug is in a different project
 - it is a custom status

This commit fixes the behavior, and displays the corresponding enum
element's language string.

2 new parameters have been added to function get_enum_element(): user
and project id (defaulted to null to preserve existing behavior). These
parameters are passed on to config_get() call, allowing to specify the
context for retrieving the enum element.

The call to get_enum_element() in function relationship_get_details()
has been altered to specify the target bug's project id.

Fixes #11323
---
 core/helper_api.php       |    9 ++++++---
 core/relationship_api.php |    2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/core/helper_api.php b/core/helper_api.php
index 1354a90..ab0d902 100644
--- a/core/helper_api.php
+++ b/core/helper_api.php
@@ -85,13 +85,16 @@ function get_status_color( $p_status ) {
 }
 
 /**
- * Given a enum string and num, return the appropriate string
+ * Given a enum string and num, return the appropriate string for the
+ * specified user/project
  * @param string $p_enum_name
  * @param int $p_val
+ * @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_enum_element( $p_enum_name, $p_val ) {
-	$config_var = config_get( $p_enum_name . '_enum_string' );
+function get_enum_element( $p_enum_name, $p_val, $p_user = null, $p_project = null ) {
+	$config_var = config_get( $p_enum_name . '_enum_string', null, $p_user, $p_project );
 	$string_var = lang_get( $p_enum_name . '_enum_string' );
 
 	return MantisEnum::getLocalizedLabel( $config_var, $string_var, $p_val );
diff --git a/core/relationship_api.php b/core/relationship_api.php
index bb4d5e0..759ac2d 100644
--- a/core/relationship_api.php
+++ b/core/relationship_api.php
@@ -625,7 +625,7 @@ function relationship_get_details( $p_bug_id, $p_relationship, $p_html = false,
 
 	# get the information from the related bug and prepare the link
 	$t_bug = bug_get( $t_related_bug_id, false );
-	$t_status_string = get_enum_element( 'status', $t_bug->status );
+	$t_status_string = get_enum_element( 'status', $t_bug->status, null, $t_bug->project_id );
 	$t_resolution_string = get_enum_element( 'resolution', $t_bug->resolution );
 
 	$t_relationship_info_html = $t_td . string_no_break( $t_relationship_descr ) . '&#160;</td>';
-- 
1.7.5.4

