From afaec9f5f9c26df0d46ef0eaa7481f2e82cf6861 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?St=82phane=20Veyret?= <sveyret@axway.com>
Date: Wed, 1 Jul 2009 09:57:23 +0200
Subject: [PATCH] Fix 0008663: Multiparent projects not prune in project list

---
 core/user_api.php |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/core/user_api.php b/core/user_api.php
index 23dbb45..be17388 100644
--- a/core/user_api.php
+++ b/core/user_api.php
@@ -748,15 +748,22 @@
 			for ( $i=0 ; $i < $row_count ; $i++ ) {
 				$row = db_fetch_array( $result );
 
-				$t_projects[ $row['id'] ] = ( $row['parent_id'] === NULL ) ? 0 : $row['parent_id'];
+				if ( !isset ( $t_projects[ $row['id'] ] ) ) {
+					$t_projects[ $row['id'] ] = array();
+				}
+
+				$t_projects[ $row['id'] ][] = ( $row['parent_id'] === NULL ) ? 0 : $row['parent_id'];
 			}
 
 			# prune out children where the parents are already listed. Make the list
 			#  first, then prune to avoid pruning a parent before the child is found.
 			$t_prune = array();
-			foreach ( $t_projects as $t_id => $t_parent ) {
-				if ( ( $t_parent !== 0 ) && isset( $t_projects[$t_parent] ) ) {
-					$t_prune[] = $t_id;
+			foreach ( $t_projects as $t_id => $t_parent_list ) {
+				foreach ( $t_parent_list as $t_parent ) {
+					if ( ( $t_parent !== 0 ) && isset( $t_projects[$t_parent] ) ) {
+						if ( !in_array ( $t_id, $t_prune ) )
+							$t_prune[] = $t_id;
+					}
 				}
 			}
 			foreach ( $t_prune as $t_id ) {
-- 
1.6.3.2

