Index: extensions/UserAdvManager/trunk/include/functions.inc.php
===================================================================
--- extensions/UserAdvManager/trunk/include/functions.inc.php	(revision 26077)
+++ extensions/UserAdvManager/trunk/include/functions.inc.php	(revision 26914)
@@ -287,11 +287,4 @@
     }
 
-    $typemail = 3; // Only information email send to user on user profile update if checked
-
-    if (!empty($_POST['use_new_pwd']))
-    {
-      $typemail = 2; // Confirmation email on user profile update - With information email
-    }
-
     // Sending registration confirmation by email
     // ------------------------------------------
@@ -310,7 +303,7 @@
         list($current_email) = pwg_db_fetch_row(pwg_query($query));
 
-        // This is to send a new validation key
-        // ------------------------------------
-        if ($_POST['mail_address'] != $current_email and (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true'))
+        // This is to set the user to "waiting" group or status until validation
+        // ---------------------------------------------------------------------
+        if ($_POST['mail_address'] != $current_email and (isset($conf_UAM['CONFIRM_MAIL']) and ($conf_UAM['CONFIRM_MAIL'] == 'true' or $conf_UAM['CONFIRM_MAIL'] == 'local')))
         {
           SetPermission($user['id']);// Set to "waiting" group or status until user validation
@@ -318,16 +311,14 @@
           $confirm_mail_need = true;
         }
-
-        // This is to set the user to "waiting" group or status until admin validation
-        // ---------------------------------------------------------------------------
-        elseif ($_POST['mail_address'] != $current_email and (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'local'))
+        else
         {
-          SetPermission($user['id']);// Set to "waiting" group or status until admin validation
-          SetUnvalidated($user['id']); // Set UAM_validated field to false in #_users table
           $confirm_mail_need = false;
-        }       
-      }
-
-      if (((!empty($_POST['use_new_pwd']) and (isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true')) or $confirm_mail_need))
+        }
+      }
+
+      $typemail = 2;
+
+      // Send email
+      if ((isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true') or $confirm_mail_need)
       {
         $query = '
@@ -338,4 +329,5 @@
 
         list($username) = pwg_db_fetch_row(pwg_query($query));
+
         SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need);
       }
@@ -1109,6 +1101,6 @@
       break;
 
-    case 2: // Confirmation email on user profile update - With information email if modification done in user profile
-      if (isset($conf_UAM['CONFIRMMAIL_SUBJECT']) and !empty($conf_UAM['CONFIRMMAIL_SUBJECT']))
+    case 2: // Confirmation email on user profile update - Information email if modification done in user profile
+      if (isset($conf_UAM['INFOMAIL_SUBJECT']) and !empty($conf_UAM['INFOMAIL_SUBJECT']))
       {
         // Management of Extension flags ([username], [mygallery])
@@ -1121,10 +1113,10 @@
         if (function_exists('get_user_language_desc'))
         {
-          $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_SUBJECT']))."\n\n";
+          $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['INFOMAIL_SUBJECT']))."\n\n";
         }
-        else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['CONFIRMMAIL_SUBJECT']))."\n\n"; 
-      }
-
-      $password = !empty($password) ? $password : l10n('UAM_empty_pwd');
+        else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['INFOMAIL_SUBJECT']))."\n\n"; 
+      }
+
+      $password = !empty($password) ? $password : l10n('UAM_no_update_pwd');
 
       if (isset($conf_UAM['MAILINFO_TEXT']) and !empty($conf_UAM['MAILINFO_TEXT']))
@@ -1170,66 +1162,4 @@
 
       break;
-
-    case 3: // Only information email send to user if checked
-      if (isset($conf_UAM['INFOMAIL_SUBJECT']) and !empty($conf_UAM['INFOMAIL_SUBJECT']))
-      {
-        // Management of Extension flags ([username], [mygallery])
-        // -------------------------------------------------------
-        $patterns[] = '#\[username\]#i';
-        $replacements[] = $username;
-        $patterns[] = '#\[mygallery\]#i';
-        $replacements[] = $conf['gallery_title'];
-
-        if (function_exists('get_user_language_desc'))
-        {
-          $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['INFOMAIL_SUBJECT']))."\n\n";
-        }
-        else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM['INFOMAIL_SUBJECT']))."\n\n"; 
-      }
-
-      $password = !empty($password) ? $password : l10n('UAM_no_update_pwd');
-
-      if (isset($conf_UAM['MAILINFO_TEXT']) and !empty($conf_UAM['MAILINFO_TEXT']))
-      {
-        // Management of Extension flags ([username], [mygallery], [myurl])
-        // ----------------------------------------------------------------
-        $patterns[] = '#\[username\]#i';
-        $replacements[] = $username;
-        $patterns[] = '#\[mygallery\]#i';
-        $replacements[] = $conf['gallery_title'];
-        $patterns[] = '#\[myurl\]#i';
-        $replacements[] = get_gallery_home_url();
-
-        if (function_exists('get_user_language_desc'))
-        {
-          $infos1_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM['MAILINFO_TEXT']))."\n\n";
-        }
-        else $infos1_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM['MAILINFO_TEXT']))."\n\n"; 
-      }
-
-      if (isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true')
-      {
-        if (isset($conf_UAM['HIDEPASSW']) and $conf_UAM['HIDEPASSW'] == 'true') // Allow display of clear password in email
-        {
-          $infos1 = array(
-            get_l10n_args('UAM_infos_mail %s', stripslashes($username)),
-            get_l10n_args('UAM_User: %s', stripslashes($username)),
-            get_l10n_args('UAM_Password: %s', $password),
-            get_l10n_args('Email: %s', $email),
-            get_l10n_args('', ''),
-          );
-        }
-        else // Do not allow display of clear password in email
-        {
-          $infos1 = array(
-            get_l10n_args('UAM_infos_mail %s', stripslashes($username)),
-            get_l10n_args('UAM_User: %s', stripslashes($username)),
-            get_l10n_args('Email: %s', $email),
-            get_l10n_args('', ''),
-          );
-        }
-      }
-
-      break;
   }
 
@@ -1266,28 +1196,31 @@
   }
 
+
 // Sending the email with subject and contents
 // -------------------------------------------
-  if ((isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'local') and $confirm)
-	{
+
+  if ((isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'local') and $confirm) // Confirmation email send to admins
+  {
     switch_lang_to(get_default_language());
 
-  	load_language('plugin.lang', UAM_PATH);
-  	$subject = get_l10n_args('UAM_Subject admin validation for %s',$username);
-
-		$content = array(
-  	 get_l10n_args('UAM_Manual_validation_needed_for %s', stripslashes($username)),
-     get_l10n_args('', ''),
-     get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)),
+    load_language('plugin.lang', UAM_PATH);
+    $subject_admin = get_l10n_args('UAM_Subject admin validation for %s',$username);
+
+    $content_admin = array(
+      get_l10n_args('UAM_Manual_validation_needed_for %s', stripslashes($username)),
+      get_l10n_args('', ''),
+      get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)),
     );
 
-    //UAM_mail_notification_admins($subject, $content);
-    pwg_mail_notification_admins($subject, $content, true);
-  }
-	elseif ((isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true') and $confirm)
+    pwg_mail_notification_admins($subject_admin, $content_admin, true);
+  }
+
+
+	if (isset($conf_UAM['CONFIRM_MAIL']) and $conf_UAM['CONFIRM_MAIL'] == 'true' and $confirm) // Confirmation email send to users
 	{
 	  // Adding gallery URL at the end of the email
     if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true')
     {
-      $content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url();
+      $content_confirmation = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url();
 
       pwg_mail(
@@ -1297,5 +1230,5 @@
           ),
         array(
-          'content' => $content,
+          'content' => $content_confirmation,
           'content_format' => 'text/plain',
           'subject' => $subject,
@@ -1306,5 +1239,5 @@
     elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false')
     {
-      $content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "");
+      $content_confirmation = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "");
 
       pwg_mail(
@@ -1314,5 +1247,5 @@
           ),
         array(
-          'content' => $content,
+          'content' => $content_confirmation,
           'content_format' => 'text/plain',
           'subject' => $subject,
@@ -1323,5 +1256,5 @@
     else
     {
-      $content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "");
+      $content_confirmation = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "");
 
       pwg_mail(
@@ -1331,5 +1264,61 @@
           ),
         array(
-          'content' => $content,
+          'content' => $content_confirmation,
+          'content_format' => 'text/plain',
+          'subject' => $subject,
+          )
+        );
+    }
+	}
+
+
+	if (isset($conf_UAM['MAIL_INFO']) and $conf_UAM['MAIL_INFO'] == 'true') // Information email send to users
+	{
+	  // Adding gallery URL at the end of the email
+    if (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'true')
+    {
+      $content_info = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url();
+
+      pwg_mail(
+        array(
+          'name' => stripslashes($username),
+          'email' => $email,
+          ),
+        array(
+          'content' => $content_info,
+          'content_format' => 'text/plain',
+          'subject' => $subject,
+          )
+        );
+    }
+    // Do not add gallery URL at the end of the email
+    elseif (isset($conf_UAM['ADD_GALLERY_URL_TO_EMAILS']) and $conf_UAM['ADD_GALLERY_URL_TO_EMAILS'] == 'false')
+    {
+      $content_info = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "");
+
+      pwg_mail(
+        array(
+          'name' => stripslashes($username),
+          'email' => $email,
+          ),
+        array(
+          'content' => $content_info,
+          'content_format' => 'text/plain',
+          'subject' => $subject,
+          )
+        );
+    }
+    // By default do not add gallery URL at the end of the email
+    else
+    {
+      $content_info = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "");
+
+      pwg_mail(
+        array(
+          'name' => stripslashes($username),
+          'email' => $email,
+          ),
+        array(
+          'content' => $content_info,
           'content_format' => 'text/plain',
           'subject' => $subject,
