From ff0dc92f1810612680db88aa2156a3b5922e2958 Mon Sep 17 00:00:00 2001
From: Damien Regad <damien.regad@merckserono.net>
Date: Wed, 20 Oct 2010 18:07:45 +0200
Subject: [PATCH] Fix #11351: Do not delete email or realname when editing user with LDAP

When connecting to Mantis with LDAP and either use_ldap_email or
use_ldap_realname = ON, that field is set to blank when the user edits
their profile (account_page.php). The same happens when either or both
of the above options are ON and the administrator updates a user from
manage_user_edit_page.php.
---
 account_page.php          |   53 +++++++++++++++++++++++---------------------
 manage_user_edit_page.php |   26 ++++++++++++++++------
 2 files changed, 47 insertions(+), 32 deletions(-)

diff --git a/account_page.php b/account_page.php
index 2c9790e..bc9058b 100644
--- a/account_page.php
+++ b/account_page.php
@@ -176,20 +176,6 @@
 <?php
 } // End LDAP conditional
 
-if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { ?> <!-- With LDAP Email-->
-
-	<!-- Email -->
-	<tr <?php echo helper_alternate_class() ?>>
-		<td class="category">
-			<?php echo lang_get( 'email' ) ?>
-		</td>
-		<td>
-			<?php echo $u_email ?>
-		</td>
-	</tr>
-
-<?php } else { ?> <!-- Without LDAP Email -->
-
 	<!-- Email -->
 	<tr <?php echo helper_alternate_class() ?>>
 		<td class="category">
@@ -197,13 +183,22 @@ if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { ?> <!-- With LDAP Email
 		</td>
 		<td>
 			<?php
-				$t_show_update_button = true;
-				print_email_input( 'email', $u_email );
+				// With LDAP
+				if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { 
+					echo $u_email
+			?>	
+					<input type="hidden" name="email" value="<?php echo string_attribute( $u_email ) ?>" />
+			<?php 
+				} 
+				// Without LDAP
+				else { 
+					$t_show_update_button = true;
+					print_email_input( 'email', $u_email );
+				}	
 			?>
 		</td>
 	</tr>
 
-<?php } ?> <!-- End LDAP Email conditional -->
 
 	<!-- Realname -->
 	<tr <?php echo helper_alternate_class() ?> valign="top">
@@ -211,14 +206,22 @@ if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { ?> <!-- With LDAP Email
 			<?php echo lang_get( 'realname' ) ?>
 		</td>
 		<td>
-<?php
-if ( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) {
-	echo string_display( ldap_realname_from_username( $u_username ) );
-} else {
-	$t_show_update_button = true;
-?>
-			<input type="text" size="32" maxlength="<?php echo REALLEN;?>" name="realname" value="<?php echo string_attribute( $u_realname ) ?>" />
-<?php } ?>
+			<?php
+				// With LDAP
+				if ( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) {
+					echo string_display( ldap_realname_from_username( $u_username ) );
+			?>
+					<input type="hidden" name="realname" value="<?php echo string_attribute( ldap_realname_from_username( $u_username ) ) ?>" />
+			<?php
+				} 
+				// Without LDAP
+				else {
+					$t_show_update_button = true;
+			?>
+					<input type="text" size="32" maxlength="<?php echo REALLEN;?>" name="realname" value="<?php echo string_attribute( $u_realname ) ?>" />
+			<?php 
+				}
+			?>
 		</td>
 	</tr>
 
diff --git a/manage_user_edit_page.php b/manage_user_edit_page.php
index 4ac18d4..2c66b72 100644
--- a/manage_user_edit_page.php
+++ b/manage_user_edit_page.php
@@ -88,12 +88,18 @@
 	</td>
 	<td width="70%">
 		<?php
-			if ( !$t_ldap || config_get( 'use_ldap_realname' ) == OFF ) {
+			// With LDAP
+			if ( $t_ldap && ON == config_get( 'use_ldap_realname' ) ) {
+				echo string_display( user_get_realname( $f_user_id ) );
+		?>
+				<input type="hidden" name="realname" value="<?php echo string_attribute( user_get_realname( $f_user_id ) ) ?>" />
+		<?php
+			} 
+			// Without LDAP
+			else {
 		?>
 				<input type="text" size="16" maxlength="<?php echo REALLEN;?>" name="realname" value="<?php echo string_attribute( $t_user['realname'] ) ?>" />
 		<?php
-			} else {
-				echo string_display( user_get_realname( $f_user_id ) );
 			}
 		?>
 	</td>
@@ -106,11 +112,17 @@
 	</td>
 	<td>
 		<?php
-			if ( !$t_ldap || config_get( 'use_ldap_email' ) == OFF ) {
-				print_email_input( 'email', $t_user['email'] );
-			} else {
+			// With LDAP
+			if ( $t_ldap && ON == config_get( 'use_ldap_email' ) ) { 
 				echo string_display( user_get_email( $f_user_id ) );
-			}
+		?>
+				<input type="hidden" name="email" value="<?php echo user_get_email( $f_user_id ) ?>" />
+		<?php 
+			} 
+			// Without LDAP
+			else { 
+				print_email_input( 'email', $t_user['email'] );
+			}	
 		?>
 	</td>
 </tr>
-- 
1.7.1

