Index: /extensions/NBC_UserAdvManager/trunk/admin/UAM_admin.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/admin/UAM_admin.php	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/admin/UAM_admin.php	(revision 8065)
@@ -74,5 +74,5 @@
 $height = '300px';
 $areas = array();
-array_push( $areas,'UAM_ConfirmMail_Custom_Txt1','UAM_ConfirmMail_Custom_Txt2');
+array_push( $areas,'UAM_ConfirmMail_Custom_Txt1','UAM_ConfirmMail_Custom_Txt2','UAM_GTAutoDelText');
 
 if (function_exists('set_fckeditor_instance'))
@@ -105,5 +105,5 @@
   case 'global':
 
-	if (isset($_POST['submit']) and !is_adviser() and isset($_POST['UAM_Mail_Info']) and isset($_POST['UAM_Username_Char']) and isset($_POST['UAM_Confirm_Mail']) and isset($_POST['UAM_No_Comment_Anonymous']) and isset($_POST['UAM_Password_Enforced']) and isset($_POST['UAM_AdminPassword_Enforced']) and isset($_POST['UAM_GhostUser_Tracker']) and isset($_POST['UAM_Admin_ConfMail']) and isset($_POST['UAM_RedirToProfile']))
+	if (isset($_POST['submit']) and !is_adviser() and isset($_POST['UAM_Mail_Info']) and isset($_POST['UAM_Username_Char']) and isset($_POST['UAM_Confirm_Mail']) and isset($_POST['UAM_No_Comment_Anonymous']) and isset($_POST['UAM_Password_Enforced']) and isset($_POST['UAM_AdminPassword_Enforced']) and isset($_POST['UAM_GhostUser_Tracker']) and isset($_POST['UAM_Admin_ConfMail']) and isset($_POST['UAM_RedirToProfile']) and isset($_POST['UAM_GTAuto']))
   {
 
@@ -114,5 +114,8 @@
 
     $_POST['UAM_GhostTracker_ReminderText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GhostTracker_ReminderText'])));
-
+    
+    $_POST['UAM_GTAutoDelText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoDelText'])));
+
+    $_POST['UAM_GTAutoMailText'] = str_replace('\"', '"', str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UAM_GTAutoMailText'])));
 
     //Check if CR-LF exist at begining and end of mail exclusion list - If yes, removes them
@@ -121,4 +124,14 @@
       array_push($page['errors'], l10n('mail_exclusionlist_error'));
       $UAM_Exclusionlist_Error = true;
+    }
+
+    // Consistency check between ConfirmMail and AutoMail - We cannot use GTAutoMail if ConfirmMail is disabled
+    $conf_UAM = unserialize($conf['UserAdvManager']);
+    
+    if (((isset($conf_UAM['1']) and ($conf_UAM['1'] == 'false' or $conf_UAM['1'] == 'local')) or ($_POST['UAM_Confirm_Mail'] == 'false' or $_POST['UAM_Confirm_Mail'] == 'local')) and $_POST['UAM_GTAutoMail'] == 'true')
+    {
+      $newvalue = 'false';
+      $_POST['UAM_GTAutoMail'] = $newvalue;
+      array_push($page['errors'], l10n('Error_GTAutoMail_cannot_be_set_without_ConfirmMail'));
     }
 
@@ -145,5 +158,12 @@
       $_POST['UAM_Add_LastVisit_Column'],
       $_POST['UAM_Admin_ConfMail'],
-      $_POST['UAM_RedirToProfile']);
+      $_POST['UAM_RedirToProfile'],
+      $_POST['UAM_GTAuto'],
+      $_POST['UAM_GTAutoDel'],
+      $_POST['UAM_GTAutoMail'],
+      $_POST['UAM_GTAutoDelText'],
+      $_POST['UAM_GTAutoMailText'],
+      (isset($_POST['UAM_Downgrade_Group'])?$_POST['UAM_Downgrade_Group']:''),
+      (isset($_POST['UAM_Downgrade_Status'])?$_POST['UAM_Downgrade_Status']:''));
 
     $conf['UserAdvManager'] = serialize($newconf_UAM);
@@ -203,8 +223,9 @@
   $conf_UAM = unserialize($conf['UserAdvManager']);
 
-  //Group setting for unvalidated and validated users
+  //Group setting for unvalidated, validated users and downgrade group
   $groups[-1] = '---------';
   $No_Valid = -1;
   $Valid = -1;
+  $Downgrade = -1;
 	
   //Check groups list in database 
@@ -229,4 +250,9 @@
 		{
 	  	$Valid = $row['id'];
+		}
+    //configuration value for downgrade users
+    if (isset($conf_UAM[27]) and $conf_UAM[27] == $row['id'])
+		{
+	  	$Downgrade = $row['id'];
 		}
   }
@@ -248,11 +274,20 @@
 			)
   	);
+  //Template initialization for downgrade group
+  $template->assign(
+    'Downgrade_Group',
+		array(
+      'group_options'=> $groups,
+      'group_selected' => $Downgrade
+			)
+  	);
 	
-  //Status setting for unvalidated and validated users
+  //Status setting for unvalidated, validated users and downgrade status
   $status_options[-1] = '------------';
   $No_Valid_Status = -1;
   $Valid_Status = -1;
+  $Downgrade_Status = -1;
 	
-  //Get status values
+  //Get unvalidate status values
   foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
   {
@@ -263,5 +298,5 @@
 	  }
 	  
-      //Template initialization for unvalidated users group
+      //Template initialization for unvalidated users status
       $template->assign(
         'No_Confirm_Status',
@@ -273,5 +308,5 @@
   }
   
-  //Get status values
+  //Get validate status values
   foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
   {
@@ -282,5 +317,5 @@
 		}
 		
-      //Template initialization for unvalidated users group
+      //Template initialization for validated users status
       $template->assign(
 	    'Confirm_Status',
@@ -288,4 +323,23 @@
 		    'Status_options' => $status_options,
 		    'Status_selected' => $Valid_Status
+		    )
+	    );
+	}
+
+  //Get downgrade status values
+  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
+  {
+	  $status_options[$status] = l10n('user_status_'.$status);
+	  if (isset($conf_UAM[28]) and $conf_UAM[28] == $status)
+		{
+		  $Downgrade_Status = $status;
+		}
+		
+      //Template initialization for validated users status
+      $template->assign(
+	    'Downgrade_Status',
+	    array(
+		    'Status_options' => $status_options,
+		    'Status_selected' => $Downgrade_Status
 		    )
 	    );
@@ -339,4 +393,14 @@
     'UAM_REDIRTOPROFILE_TRUE'        => $conf_UAM[21]=='true' ?  'checked="checked"' : '' ,
     'UAM_REDIRTOPROFILE_FALSE'       => $conf_UAM[21]=='false' ?  'checked="checked"' : '' ,
+    'UAM_GTAUTO_TRUE'                => $conf_UAM[22]=='true' ?  'checked="checked"' : '' ,
+    'UAM_GTAUTO_FALSE'               => $conf_UAM[22]=='false' ?  'checked="checked"' : '' ,
+    'UAM_GTAUTODEL_TRUE'             => $conf_UAM[23]=='true' ?  'checked="checked"' : '' ,
+    'UAM_GTAUTODEL_FALSE'            => $conf_UAM[23]=='false' ?  'checked="checked"' : '' ,
+    'UAM_GTAUTOMAIL_TRUE'            => $conf_UAM[24]=='true' ?  'checked="checked"' : '' ,
+    'UAM_GTAUTOMAIL_FALSE'           => $conf_UAM[24]=='false' ?  'checked="checked"' : '' ,
+    'UAM_GTAUTODEL_TEXT'             => $conf_UAM[25],
+    'UAM_GTAUTOMAILTEXT'             => $conf_UAM[26],
+		'UAM_Downgrade_Group'            => $conf_UAM[27],
+		'UAM_Downgrade_Status'           => $conf_UAM[28],
 		'UAM_PASSWORD_TEST_SCORE'        => $UAM_Password_Test_Score,
     'UAM_ERROR_REPORTS4'             => $UAM_Exclusionlist_Error,
Index: /extensions/NBC_UserAdvManager/trunk/admin/template/global.tpl
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/admin/template/global.tpl	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/admin/template/global.tpl	(revision 8065)
@@ -202,5 +202,7 @@
             <br><br>
         	</li>
-
+{if $UAM_CONFIRM_MAIL_FALSE}
+<div class="uam_hide">
+{/if}
           <ul>
          	  <li>
@@ -262,122 +264,127 @@
 
           <br><hr><br>
-        
-          <div id="uam_notice">{'UAM_Confirm_grpstat_notice'|@translate}</div>
-            <br>
-            <li>
-              <label class="cluetip" title="{'UAM_confirmgrpTitle'|translate}|{'UAM_confirmgrpTitle_d'|translate}">
-                {'UAM_Confirm_Group'|@translate}
-              </label>
-            <br><br>
-            </li>
-
-            <ul>
+
+          <ul>
+            <div id="uam_notice">{'UAM_Confirm_grpstat_notice'|@translate}</div>
+              <br>
               <li>
-                <label>
-                  {'UAM_No_Confirm_Group'|@translate}
-                </label><br>
-                <div id="uam_leftmargin">
-                  {html_options name="UAM_No_Confirm_Group" options=$No_Confirm_Group.group_options selected=$No_Confirm_Group.group_selected}
-                </div>
-                <br><br>
+                <label class="cluetip" title="{'UAM_confirmgrpTitle'|translate}|{'UAM_confirmgrpTitle_d'|translate}">
+                  {'UAM_Confirm_Group'|@translate}
+                </label>
+              <br><br>
               </li>
-      
+
+              <ul>
+                <li>
+                  <label>
+                    {'UAM_No_Confirm_Group'|@translate}
+                  </label><br>
+                  <div id="uam_leftmargin">
+                    {html_options name="UAM_No_Confirm_Group" options=$No_Confirm_Group.group_options selected=$No_Confirm_Group.group_selected}
+                  </div>
+                  <br><br>
+                </li>
+
+                <li>
+                  <label>
+                    {'UAM_Validated_Group'|@translate}
+                  </label><br>
+                  <div id="uam_leftmargin">
+                    {html_options name="UAM_Validated_Group" options=$Validated_Group.group_options selected=$Validated_Group.group_selected}
+                  </div>
+                  <br><br>
+                </li>
+              </ul>
+
               <li>
-                <label>
-                  {'UAM_Validated_Group'|@translate}
-                </label><br>
-                <div id="uam_leftmargin">
-                  {html_options name="UAM_Validated_Group" options=$Validated_Group.group_options selected=$Validated_Group.group_selected}
-                </div>
-                <br><br>
+                <label class="cluetip" title="{'UAM_confirmstatTitle'|translate}|{'UAM_confirmstatTitle_d'|translate}">
+                  {'UAM_Confirm_Status'|@translate}
+                </label>
+              <br><br>
               </li>
-            </ul>
-
-            <li>
-              <label class="cluetip" title="{'UAM_confirmstatTitle'|translate}|{'UAM_confirmstatTitle_d'|translate}">
-                {'UAM_Confirm_Status'|@translate}
-              </label>
-            <br><br>
-            </li>
-
-            <ul>
+
+              <ul>
+                <li>
+                  <label>
+                    {'UAM_No_Confirm_Status'|@translate}
+                  </label><br>
+                  <div id="uam_leftmargin">
+                    {html_options name="UAM_No_Confirm_Status" options=$No_Confirm_Status.Status_options selected=$No_Confirm_Status.Status_selected}
+                  </div>
+                  <br><br>
+                </li>
+
+                <li>
+                  <label>
+                    {'UAM_Validated_Status'|@translate}
+                  </label><br>
+                  <div id="uam_leftmargin">
+                    {html_options name="UAM_Validated_Status" options=$Confirm_Status.Status_options selected=$Confirm_Status.Status_selected}
+                  </div>
+                  <br><br>
+                </li>
+              </ul>
+
+              <br><hr><br>
+
               <li>
-                <label>
-                  {'UAM_No_Confirm_Status'|@translate}
-                </label><br>
-                <div id="uam_leftmargin">
-                  {html_options name="UAM_No_Confirm_Status" options=$No_Confirm_Status.Status_options selected=$No_Confirm_Status.Status_selected}
-                </div>
-                <br><br>
+                <label class="cluetip" title="{'UAM_validationlimitTitle'|translate}|{'UAM_validationlimitTitle_d'|translate}">
+                  {'UAM_ValidationLimit_Info'|@translate}
+                </label>
+              <br><br>
+                <input type="radio" value="false" {$UAM_CONFIRMMAIL_TIMEOUT_FALSE} name="UAM_ConfirmMail_TimeOut">
+                  {'UAM_ConfirmMail_TimeOut_false'|@translate}<br>
+                <input type="radio" value="true" {$UAM_CONFIRMMAIL_TIMEOUT_TRUE} name="UAM_ConfirmMail_TimeOut">
+                  {'UAM_ConfirmMail_TimeOut_true'|@translate}
+                <input type="text" name="UAM_ConfirmMail_Delay" value="{$UAM_CONFIRMMAIL_DELAY}" size="5" style="text-align: center;"><br><br>
               </li>
 
               <li>
-                <label>
-                  {'UAM_Validated_Status'|@translate}
-                </label><br>
-                <div id="uam_leftmargin">
-                  {html_options name="UAM_Validated_Status" options=$Confirm_Status.Status_options selected=$Confirm_Status.Status_selected}
-                </div>
-                <br><br>
+                <label class="cluetip" title="{'UAM_remailTitle'|translate}|{'UAM_remailTitle_d'|translate}">
+                  {'UAM_ConfirmMail_Remail'|@translate}
+                </label>
+              <br><br>
+                <input type="radio" value="false" {$UAM_CONFIRMMAIL_REMAIL_FALSE} name="UAM_ConfirmMail_Remail">
+                  {'UAM_ConfirmMail_Remail_false'|@translate}<br>
+                <input type="radio" value="true" {$UAM_CONFIRMMAIL_REMAIL_TRUE} name="UAM_ConfirmMail_Remail">
+                  {'UAM_ConfirmMail_Remail_true'|@translate}<br><br>
               </li>
-            </ul>
-
-            <br><hr><br>
-
-            <li>
-              <label class="cluetip" title="{'UAM_validationlimitTitle'|translate}|{'UAM_validationlimitTitle_d'|translate}">
-                {'UAM_ValidationLimit_Info'|@translate}
-              </label>
-            <br><br>
-              <input type="radio" value="false" {$UAM_CONFIRMMAIL_TIMEOUT_FALSE} name="UAM_ConfirmMail_TimeOut">
-                 {'UAM_ConfirmMail_TimeOut_false'|@translate}<br>
-              <input type="radio" value="true" {$UAM_CONFIRMMAIL_TIMEOUT_TRUE} name="UAM_ConfirmMail_TimeOut">
-                 {'UAM_ConfirmMail_TimeOut_true'|@translate}
-              <input type="text" name="UAM_ConfirmMail_Delay" value="{$UAM_CONFIRMMAIL_DELAY}" size="5" style="text-align: center;"><br><br>
-            </li>
-
-            <li>
-              <label class="cluetip" title="{'UAM_remailTitle'|translate}|{'UAM_remailTitle_d'|translate}">
-                {'UAM_ConfirmMail_Remail'|@translate}
-              </label>
-            <br><br>
-              <input type="radio" value="false" {$UAM_CONFIRMMAIL_REMAIL_FALSE} name="UAM_ConfirmMail_Remail">
-                 {'UAM_ConfirmMail_Remail_false'|@translate}<br>
-              <input type="radio" value="true" {$UAM_CONFIRMMAIL_REMAIL_TRUE} name="UAM_ConfirmMail_Remail">
-                 {'UAM_ConfirmMail_Remail_true'|@translate}<br><br>
-            </li>
-
-            <ul>
-              <li>
-                <label class="cluetip" title="{'UAM_remailtxt1Title'|translate}|{'UAM_remailtxt1Title_d'|translate}">
-                  {'UAM_ConfirmMail_ReMail_Txt1'|@translate}
-                </label>
-                <br><br>
-                  <textarea class="uam_textfields" name="UAM_ConfirmMail_ReMail_Txt1" id="UAM_ConfirmMail_ReMail_Txt1" rows="10" {$TAG_INPUT_ENABLED}>{$UAM_CONFIRMMAIL_REMAIL_TXT1}</textarea>
-                <br><br>
-              </li>
+
+              <ul>
+                <li>
+                  <label class="cluetip" title="{'UAM_remailtxt1Title'|translate}|{'UAM_remailtxt1Title_d'|translate}">
+                    {'UAM_ConfirmMail_ReMail_Txt1'|@translate}
+                  </label>
+                  <br><br>
+                    <textarea class="uam_textfields" name="UAM_ConfirmMail_ReMail_Txt1" id="UAM_ConfirmMail_ReMail_Txt1" rows="10" {$TAG_INPUT_ENABLED}>{$UAM_CONFIRMMAIL_REMAIL_TXT1}</textarea>
+                  <br><br>
+                </li>
 <!--
-              {* if 'FCK_PATH'|@defined *}
-                <div style="text-align:right;">
-                  <a href="#" onClick="toogleEditor('UAM_ConfirmMail_ReMail_Txt1'); return false;">FCK Editor On/Off</a>
-                </div>
-              {* /if *}
+                {* if 'FCK_PATH'|@defined *}
+                  <div style="text-align:right;">
+                    <a href="#" onClick="toogleEditor('UAM_ConfirmMail_ReMail_Txt1'); return false;">FCK Editor On/Off</a>
+                  </div>
+                {* /if *}
 -->
 
-              <li>
-                <label class="cluetip" title="{'UAM_remailtxt2Title'|translate}|{'UAM_remailtxt2Title_d'|translate}">
-                  {'UAM_ConfirmMail_ReMail_Txt2'|@translate}
-                </label>
-                <br><br>
-                  <textarea class="uam_textfields" name="UAM_ConfirmMail_ReMail_Txt2" id="UAM_ConfirmMail_ReMail_Txt2" rows="10" {$TAG_INPUT_ENABLED}>{$UAM_CONFIRMMAIL_REMAIL_TXT2}</textarea><br>
-              </li>
+                <li>
+                  <label class="cluetip" title="{'UAM_remailtxt2Title'|translate}|{'UAM_remailtxt2Title_d'|translate}">
+                    {'UAM_ConfirmMail_ReMail_Txt2'|@translate}
+                  </label>
+                  <br><br>
+                    <textarea class="uam_textfields" name="UAM_ConfirmMail_ReMail_Txt2" id="UAM_ConfirmMail_ReMail_Txt2" rows="10" {$TAG_INPUT_ENABLED}>{$UAM_CONFIRMMAIL_REMAIL_TXT2}</textarea><br>
+                </li>
 <!--
-              {* if 'FCK_PATH'|@defined *}
-                <div style="text-align:right;">
-                  <a href="#" onClick="toogleEditor('UAM_ConfirmMail_ReMail_Txt2'); return false;">FCK Editor On/Off</a>
-                </div>
-              {* /if *}
+                {* if 'FCK_PATH'|@defined *}
+                  <div style="text-align:right;">
+                    <a href="#" onClick="toogleEditor('UAM_ConfirmMail_ReMail_Txt2'); return false;">FCK Editor On/Off</a>
+                  </div>
+                {* /if *}
 -->
-            </ul>
+              </ul>
+          </ul>
+{if $UAM_CONFIRM_MAIL_FALSE}
+</div>
+{/if}
         </ul>
       </fieldset>
@@ -401,9 +408,9 @@
         
           <ul>
-            <li><label class="cluetip" title="{'UAM_gttextTitle'|translate}|{'UAM_gttextTitle_d'|translate}">{'UAM_GhostTracker_ReminderText'|@translate}</label><br><br>
-              <textarea class="uam_textfields" name="UAM_GhostTracker_ReminderText" id="UAM_GhostTracker_ReminderText" rows="10" {$TAG_INPUT_ENABLED}>{$UAM_GHOSTRACKER_REMINDERTEXT}</textarea>
-            <br><br>
-            </li>
-
+            <li>
+              <label class="cluetip" title="{'UAM_gttextTitle'|translate}|{'UAM_gttextTitle_d'|translate}">{'UAM_GhostTracker_ReminderText'|@translate}</label>
+            <br><br>
+              <textarea class="uam_textfields" name="UAM_GhostTracker_ReminderText" id="UAM_GhostTracker_ReminderText" rows="10" {$TAG_INPUT_ENABLED}>{$UAM_GHOSTRACKER_REMINDERTEXT}</textarea><br><br>
+            </li>
 <!--
             {* if 'FCK_PATH'|@defined *}
@@ -413,6 +420,76 @@
             {* /if *}
 -->
+
+            <li><label class="cluetip" title="{'UAM_GTAutoTitle'|translate}|{'UAM_GTAutoTitle_d'|translate}">{'UAM_GTAuto'|@translate}</label>
+            <br><br>
+              <input type="radio" value="false" {$UAM_GTAUTO_FALSE} name="UAM_GTAuto">{'UAM_GTAuto_false'|@translate}<br>
+              <input type="radio" value="true" {$UAM_GTAUTO_TRUE} name="UAM_GTAuto">{'UAM_GTAuto_true'|@translate}<br><br>
+            </li>
+            
+            {if $UAM_GTAUTO_FALSE}
+              <div class="uam_hide">
+            {/if}
+                <ul>
+                  <li><label class="cluetip" title="{'UAM_GTAutoDelTitle'|translate}|{'UAM_GTAutoDelTitle_d'|translate}">{'UAM_GTAutoDel'|@translate}</label>
+                  <br><br>
+                    <input type="radio" value="false" {$UAM_GTAUTODEL_FALSE} name="UAM_GTAutoDel">{'UAM_GTAutoDel_false'|@translate}<br>
+                    <input type="radio" value="true" {$UAM_GTAUTODEL_TRUE} name="UAM_GTAutoDel">{'UAM_GTAutoDel_true'|@translate}<br><br>
+                      <textarea class="uam_textfields" name="UAM_GTAutoDelText" id="UAM_GTAutoDelText" rows="10" {$TAG_INPUT_ENABLED}>{$UAM_GTAUTODEL_TEXT}</textarea>
+                      <br><br>
+                      
+                      {if 'FCK_PATH'|@defined}
+                        <div style="text-align:right;">
+                          <a href="#" onClick="toogleEditor('UAM_GTAutoDelText'); return false;">FCK Editor On/Off</a>
+                        </div>
+                      {/if}
+                  </li>
+
+                  {if $UAM_GTAUTODEL_TRUE}
+                    <div class="uam_hide">
+                  {/if}
+                      <li><label class="cluetip" title="{'UAM_GTAutoGpTitle'|translate}|{'UAM_GTAutoGpTitle_d'|translate}">{'UAM_GTAutoGp'|@translate}</label><br><br>
+                        <ul>
+                          <li>
+                            <label>
+                              {'UAM_Expired_Group'|@translate}
+                            </label>
+                          <br>
+                            <div id="uam_leftmargin">
+                              {html_options name="UAM_Downgrade_Group" options=$Downgrade_Group.group_options selected=$Downgrade_Group.group_selected}
+                            </div>
+                          <br><br>
+                          </li>
+
+                          <li>
+                            <label>
+                              {'UAM_Expired_Status'|@translate}
+                            </label>
+                          <br>
+                            <div id="uam_leftmargin">
+                              {html_options name="UAM_Downgrade_Status" options=$Downgrade_Status.Status_options selected=$Downgrade_Status.Status_selected}
+                            </div>
+                          <br><br>
+                          </li>
+                        </ul>
+
+                        <ul>
+                          <li><label class="cluetip" title="{'UAM_GTAutoMailTitle'|translate}|{'UAM_GTAutoMailTitle_d'|translate}">{'UAM_GTAutoMail'|@translate}</label><br><br>
+                            <input type="radio" value="false" {$UAM_GTAUTOMAIL_FALSE} name="UAM_GTAutoMail">{'UAM_GTAutoMail_false'|@translate}<br>
+                            <input type="radio" value="true" {$UAM_GTAUTOMAIL_TRUE} name="UAM_GTAutoMail">{'UAM_GTAutoMail_true'|@translate}<br><br><br>
+                            <textarea class="uam_textfields" name="UAM_GTAutoMailText" id="UAM_GTAutoMailText" rows="10" {$TAG_INPUT_ENABLED}>{$UAM_GTAUTOMAILTEXT}</textarea><br><br>
+                          </li>
+                        </ul>
+                      </li>
+                  {if $UAM_GTAUTODEL_TRUE}
+                    </div>
+                  {/if}
+                </ul>
+            {if $UAM_GTAUTO_FALSE}
+              </div>
+            {/if}
           </ul>
-    
+
+          <br><hr><br>
+
           <li><label class="cluetip" title="{'UAM_lastvisitTitle'|translate}|{'UAM_lastvisitTitle_d'|translate}">{'UAM_LastVisit'|@translate}</label><br><br>
             <input type="radio" value="false" {$UAM_ADDLASTVISIT_FALSE} name="UAM_Add_LastVisit_Column">{'UAM_LastVisit_false'|@translate}<br>
Index: /extensions/NBC_UserAdvManager/trunk/admin/template/uam.css
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/admin/template/uam.css	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/admin/template/uam.css	(revision 8065)
@@ -10,4 +10,9 @@
   text-decoration: underline;
   font-weight:bold;
+}
+
+div.uam_hide
+{
+  display: none;
 }
 
Index: /extensions/NBC_UserAdvManager/trunk/changelog.txt.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/changelog.txt.php	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/changelog.txt.php	(revision 8065)
@@ -204,4 +204,13 @@
 
 -- 2.15.9 : Bug 2010 fixed - No confirmation email when information email is not set
+
+-- 2.15.10 : Bug 2050 fixed - Compatibility with Captcha
+
+
+***************************************
+***** Plugin history (branch 2.16)*****
+***************************************
+-- 2.16.0 : Bug 1430 and 1840 fixed - Automated tasks are available to delete or downgrade ghost users with or without email notification
+
 */
 ?>
Index: /extensions/NBC_UserAdvManager/trunk/del_account.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/del_account.php	(revision 8065)
+++ /extensions/NBC_UserAdvManager/trunk/del_account.php	(revision 8065)
@@ -0,0 +1,52 @@
+<?php
+//----------------------------------------------------------- include
+define('PHPWG_ROOT_PATH','./../../');
+
+include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
+include_once( PHPWG_ROOT_PATH.'include/functions_mail.inc.php' );
+
+include_once (UAM_PATH.'include/constants.php');
+include_once (UAM_PATH.'include/functions.inc.php');
+
+$title= l10n('Deleted_Account_Redirection_Page');
+$page['body_id'] = 'theAboutPage';
+include(PHPWG_ROOT_PATH.'include/page_header.php');
+
+@include(PHPWG_ROOT_PATH.'template/'.$user['template'].
+  '/theme/'.$user['theme'].'/themeconf.inc.php');
+
+
+  global $user, $lang, $conf, $errors;
+  
+
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+
+  if (function_exists('get_user_language_desc'))
+  {
+    $custom_text = get_user_language_desc($conf_UAM[25]);
+  }
+  else $custom_text = l10n($conf_UAM[25]);
+    
+  $template->assign(
+    array(
+      'GALLERY_URL'          => make_index_url(),
+			'CUSTOM_REDIR_MSG'     => $custom_text,
+		)
+  );
+
+if (isset($lang['Theme: '.$user['theme']]))
+{
+  $template->assign(
+  	'THEME_ABOUT',l10n('Theme: '.$user['theme'])
+  );
+}
+
+$template->set_filenames(
+  array(
+  	'UAM_RedirPage'=>dirname(__FILE__).'/template/del_account.tpl',
+	)
+);
+
+$template->pparse('UAM_RedirPage');
+include(PHPWG_ROOT_PATH.'include/page_tail.php');
+?>
Index: /extensions/NBC_UserAdvManager/trunk/include/functions.inc.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/include/functions.inc.php	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/include/functions.inc.php	(revision 8065)
@@ -152,101 +152,13 @@
  * Additional controls on user registration check
  */
-function UAM_RegistrationCheck($err, $user)
-{
-  global $errors, $conf;
+function UAM_RegistrationCheck($errors, $user)
+{
+  global $conf;
 
   // Exclusion of Adult_Content users
   if ($user['username'] != "16" and $user['username'] != "18")
   {
-
-// ***********************************************************
-// We need to reset the standard Piwigo's register controls   
-// because the call of register_user_check trigger resets them
-// ***********************************************************
-
-    // **********************************
-    // Standard Piwigo's username control
-    // **********************************
-    if ($_POST['login'] == '')
-    {
-      return l10n('reg_err_login1');
-    }
-    if (preg_match('/^.* $/', $_POST['login']))
-    {
-      return l10n('reg_err_login2');
-    }
-    if (preg_match('/^ .*$/', $_POST['login']))
-    {
-      return l10n('reg_err_login3');
-    }
-    if (get_userid($_POST['login']))
-    {
-      return l10n('reg_err_login5');
-    }
-
-    if ($conf['insensitive_case_logon'] == true)
-    {
-      $login_error = validate_login_case($_POST['login']);
-      if ($login_error != '')
-      {
-        return l10n($login_error);
-      }
-    }
-
-    if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') // not the same email variable if we are on users registration page or on admin's user registration page
-    {
-      // Email doblons check
-      $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
-      $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
-      $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
-  
-      if (!preg_match($regex, $_POST['email']))
-      {
-        return l10n('reg_err_mail_address');
-      }
-    
-      $query = '
-SELECT count(*)
-FROM '.USERS_TABLE.'
-WHERE upper('.$conf['user_fields']['email'].') = upper(\''.$_POST['email'].'\')
-;';
-      list($count) = pwg_db_fetch_row(pwg_query($query));
-      if ($count != 0)
-      {
-        return l10n('reg_err_mail_address_dbl');
-      }
-    }
-
-    if (script_basename() == 'register') // not the same email variable if we are on users registration page or on admin's user registration page
-    {
-      // Email doblons check
-      $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
-      $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
-      $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
-  
-      if (!preg_match($regex, $_POST['mail_address']))
-      {
-        return l10n('reg_err_mail_address');
-      }
-    
-      $query = '
-SELECT count(*)
-FROM '.USERS_TABLE.'
-WHERE upper('.$conf['user_fields']['email'].') = upper(\''.$_POST['mail_address'].'\')
-;';
-      list($count) = pwg_db_fetch_row(pwg_query($query));
-      if ($count != 0)
-      {
-        return l10n('reg_err_mail_address_dbl');
-      }
-    }
-// ******************************************
-// End of Piwigo's standard register controls
-// ******************************************
-
-
-// ******************************************
-// Here begins the advanced register controls
-// ******************************************
+    load_language('plugin.lang', UAM_PATH);
+
     $PasswordCheck = 0;
 
@@ -263,5 +175,6 @@
         {
           $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
-          return($lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]);
+          $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14];
+          array_push($errors, $lang['reg_err_pass']);
         }
       }
@@ -273,5 +186,6 @@
         {
           $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
-          return($lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]);
+          $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14];
+          array_push($errors, $lang['reg_err_pass']);
         }
       }
@@ -279,16 +193,17 @@
 
     // Username without forbidden keys
-    if (isset($conf_UAM[6]) and $conf_UAM[6] == 'true' and !empty($_POST['login']) and ValidateUsername($_POST['login']) and !is_admin())
-    {
-      $_POST['login'] = '';
-      return($lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_UAM[7]."'");
+    if (isset($conf_UAM[6]) and $conf_UAM[6] == 'true' and !empty($user['username']) and ValidateUsername($user['username']) and !is_admin())
+    {
+      $lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_UAM[7]."'";
+      array_push($errors, $lang['reg_err_login1']);
     }
 
     // Email without forbidden domains
-    if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['mail_address']) and ValidateEmailProvider($_POST['mail_address']) and !is_admin())
-    {
-      $_POST['mail_address'] = '';
-      return($lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_UAM[12]."'");
-    }
+    if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($user['email']) and ValidateEmailProvider($user['email']) and !is_admin())
+    {
+      $lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_UAM[12]."'";
+      array_push($errors, $lang['reg_err_login1']);
+    }
+    return $errors;
   }
 }
@@ -306,5 +221,5 @@
   {
     $user_idsOK = array();
-    if (!check_consult($user['id'], $user_idsOK))
+    if (!UAM_check_profile($user['id'], $user_idsOK))
     {
       $user_idsOK[] = $user['id'];
@@ -397,9 +312,9 @@
  * Triggered on login_success
  * 
- * redirects a visitor (except for admins, webmasters and generic statuses) to his profile.php page
- * 
- * Thx to LucMorizur
- */
-function UAM_RedirectToProfile()
+ * Triggers scheduled tasks at login
+ * Redirects a visitor (except for admins, webmasters and generic statuses) to his profile.php page (Thx to LucMorizur)
+ * 
+ */
+function UAM_LoginTasks()
 {
   global $conf, $user;
@@ -407,4 +322,14 @@
   $conf_UAM = unserialize($conf['UserAdvManager']);
   
+  // Performing scheduled tasks  
+  if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true'))
+  {
+    if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true'))
+    {
+      UAM_ScheduledTasks();
+    }
+  }
+
+  // Performing redirection  
   $query ='
 SELECT user_id, status
@@ -413,38 +338,202 @@
 ;';
   $data = pwg_db_fetch_assoc(pwg_query($query));
-  
+
   if ($data['status'] <> "admin" and $data['status'] <> "webmaster" and $data['status'] <> "generic")
   {
-    if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true'))
-    {
-      $user_idsOK = array();
-      if (!check_consult($user['id'], $user_idsOK))
-        redirect(PHPWG_ROOT_PATH.'profile.php');
-    }
-  }
-}
-
-/**
- * Triggered on login_success
- * 
- * Executes optional post-login tasks like GhostTracker auto tasks
- * 
- */
-function UAM_Tasks()
-{
-  global $conf, $user;
+    $user_idsOK = array();
+    if (!UAM_check_profile($user['id'], $user_idsOK))
+      redirect(PHPWG_ROOT_PATH.'profile.php');
+  }
+}
+
+/**
+ * Triggered on UAM_LoginTasks()
+ * 
+ * Executes optional post-login tasks
+ * 
+ */
+function UAM_ScheduledTasks()
+{
+  global $conf, $user, $page;
   
   $conf_UAM = unserialize($conf['UserAdvManager']);
+  
+  $collection = array();
+  
+  $page['filtered_users'] = get_ghosts_autotasks();
 
   // Ghost accounts auto deletion
   if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true') and (isset($conf_UAM[23]) and $conf_UAM[23] == 'true'))
-  {
-    
+  {       
+		foreach($page['filtered_users'] as $listed_user)
+    {
+      array_push($collection, $listed_user['id']);
+    }
+
+    if (count($collection) > 0)
+  	{
+    	if (in_array($user['id'], $collection))
+    	{
+        invalidate_user_cache();
+        
+        foreach ($collection as $user_id)
+        {
+          //delete_user($user_id);
+        }
+        logout_user();
+        redirect(UAM_PATH.'del_account.php');
+    	}
+      else
+      {
+        foreach ($collection as $user_id)
+        {
+          //delete_user($user_id);
+        }
+      }
+    }
   }
 
   // Ghost accounts auto group or status downgrade with or without information email sending
   if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true') and (isset($conf_UAM[23]) and $conf_UAM[23] == 'false') and ((isset($conf_UAM[27]) and $conf_UAM[27] <> -1) or (isset($conf_UAM[28]) and $conf_UAM[28] <> -1)))
-  {
-    
+  { 
+		foreach($page['filtered_users'] as $listed_user)
+    {
+      array_push($collection, $listed_user['id']);
+    }
+
+    if (count($collection) > 0)
+  	{
+    	if (in_array($user['id'], $collection))
+    	{ 
+        foreach ($collection as $user_id)
+        {
+          // Auto change group and / or status
+          // Delete user from all groups
+          $query = "
+DELETE FROM ".USER_GROUP_TABLE."
+WHERE user_id = '".$user_id."'
+  AND (
+    group_id = '".$conf_UAM[2]."'
+  OR 
+    group_id = '".$conf_UAM[3]."'
+  )
+;";
+
+          pwg_query($query);
+
+          // Change user status
+          if (!is_admin() and $conf_UAM[28] <> -1)
+          {
+            $query = "
+UPDATE ".USER_INFOS_TABLE."
+SET status = '".$conf_UAM[28]."'
+WHERE user_id = '".$user_id."'
+;";
+            pwg_query($query);
+          }
+
+          // Change user group
+          if (!is_admin() and $conf_UAM[27] <> -1)
+          {
+            $query = "
+INSERT INTO ".USER_GROUP_TABLE."
+  (user_id, group_id)
+VALUES
+  ('".$user_id."', '".$conf_UAM[27]."')
+;";
+            pwg_query($query);
+          }
+          
+          // Auto send email notification on group / status downgrade
+          if ((isset($conf_UAM[24]) and $conf_UAM[24] == 'true'))
+          {
+            // Reset confirmed user status to unvalidated
+						$query = '
+UPDATE '.USER_CONFIRM_MAIL_TABLE.'
+SET date_check = NULL
+WHERE user_id = "'.$user_id.'"
+;';
+						pwg_query($query);
+
+            // Get users information for email notification
+						$query = '
+SELECT id, username, mail_address
+FROM '.USERS_TABLE.'
+WHERE id = '.$user_id.'
+;';
+						$data = pwg_db_fetch_assoc(pwg_query($query));
+            
+            demotion_mail($user_id, $data['username'], $data['mail_address']);
+          }
+        }
+        invalidate_user_cache();
+        log_user($user['id'], false);
+        redirect(make_index_url());
+    	}
+      else
+      {
+        foreach ($collection as $user_id)
+        {
+          // Auto change group and / or status
+          // Delete user from all groups
+          $query = "
+DELETE FROM ".USER_GROUP_TABLE."
+WHERE user_id = '".$user_id."'
+  AND (
+    group_id = '".$conf_UAM[2]."'
+  OR 
+    group_id = '".$conf_UAM[3]."'
+  )
+;";
+
+          pwg_query($query);
+
+          // Change user status
+          if (!is_admin() and $conf_UAM[28] <> -1)
+          {
+            $query = "
+UPDATE ".USER_INFOS_TABLE."
+SET status = '".$conf_UAM[28]."'
+WHERE user_id = '".$user_id."'
+;";
+            pwg_query($query);
+          }
+
+          // Change user group
+          if (!is_admin() and $conf_UAM[27] <> -1)
+          {
+            $query = "
+INSERT INTO ".USER_GROUP_TABLE."
+  (user_id, group_id)
+VALUES
+  ('".$user_id."', '".$conf_UAM[27]."')
+;";
+            pwg_query($query);
+          }
+
+          // Auto send email notification on group / status downgrade
+          if ((isset($conf_UAM[24]) and $conf_UAM[24] == 'true'))
+          {
+            // Reset confirmed user status to unvalidated
+						$query = '
+UPDATE '.USER_CONFIRM_MAIL_TABLE.'
+SET date_check = NULL
+WHERE user_id = "'.$user_id.'"
+;';
+						pwg_query($query);
+
+            // Get users information for email notification
+						$query = '
+SELECT id, username, mail_address
+FROM '.USERS_TABLE.'
+WHERE id = '.$user_id.'
+;';
+						$data = pwg_db_fetch_assoc(pwg_query($query));
+            
+            demotion_mail($user_id, $data['username'], $data['mail_address']);
+          }
+        }
+      }
+    }
   }
 }
@@ -513,5 +602,4 @@
 function SendMail2User($typemail, $id, $username, $password, $email, $confirm)
 {
-  // Only available for next Piwigo release (bug in switch_lang function)
   global $conf;
 
@@ -659,5 +747,4 @@
 function ResendMail2User($typemail, $user_id, $username, $email, $confirm)
 {
-  // Only available for next Piwigo release (bug in switch_lang function)
   global $conf;
 
@@ -667,7 +754,4 @@
   
 	include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
-  
-	$infos1_perso = "";
-  $infos2_perso = "";
   
 // We have to get the user's language in database
@@ -765,5 +849,4 @@
 function ghostreminder($user_id, $username, $email)
 {
-  // Only available for next Piwigo release (bug in switch_lang function)
   global $conf;
 
@@ -824,4 +907,87 @@
 
 /**
+ * Function called from functions.inc.php to send notification email when user have been downgraded
+ *
+ * @param : user id, username, email address, confirmation
+ * 
+ */
+function demotion_mail($id, $username, $email)
+{
+  global $conf;
+
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+  
+	include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
+  
+	$custom_txt = "";
+
+// We have to get the user's language in database
+  $query ='
+SELECT user_id, language
+FROM '.USER_INFOS_TABLE.'
+WHERE user_id = '.$id.'
+;';
+  $data = pwg_db_fetch_assoc(pwg_query($query));
+
+// Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language
+  if (empty($data))
+  {
+// And switch gallery to this language before using personalized and multilangual contents
+    $language = pwg_get_session_var( 'lang_switch', $user['language'] );
+    switch_lang_to($language);
+  }
+  else
+  {
+// And switch gallery to this language before using personalized and multilangual contents
+    $language = $data['language']; // Usefull for debugging
+    switch_lang_to($data['language']);
+    load_language('plugin.lang', UAM_PATH);
+  }
+
+  $subject = '['.$conf['gallery_title'].'] '.l10n_args(get_l10n_args('Demotion of %s', stripslashes($username)));
+      
+  if (isset($conf_UAM[26]) and $conf_UAM[26] <> '')
+  {
+    if (function_exists('get_user_language_desc'))
+    {
+      $custom_txt = get_user_language_desc($conf_UAM[26])."\n\n";
+    }
+    else $custom_txt = l10n($conf_UAM[26])."\n\n"; 
+  }
+
+  $infos1 = array(
+    get_l10n_args('User: %s', stripslashes($username)),
+    get_l10n_args('Email: %s', $email),
+    get_l10n_args('', ''),
+  );
+
+  $infos2 = array
+  (
+    get_l10n_args('Link: %s', ResetConfirmMail($id)),
+    get_l10n_args('', ''),
+  ); 
+
+
+// Sending the email with subject and contents
+  pwg_mail($email, array(
+    'subject' => $subject,
+    'content' => ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n").get_absolute_root_url(),
+  ));
+
+// **********************
+// Email sending debugger
+// This is only to trace 
+// the send of emails for
+// debugging             
+// **********************
+//$content = ($infos1."\n\n".$infos2."\n\n").get_absolute_root_url();   
+//MailLog($email,$subject,$content,$language);
+// **********************
+
+// Switching back to default language
+switch_lang_back();
+}
+
+/**
  * Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation
  * 
@@ -880,4 +1046,5 @@
     pwg_query($query);
 
+    // Delete user from all groups
     $query = "
 DELETE FROM ".USER_GROUP_TABLE."
@@ -891,4 +1058,5 @@
     pwg_query($query);
 
+    // Set user unvalidated status
     if (!is_admin() and $conf_UAM[8] <> -1)
     {
@@ -901,5 +1069,6 @@
     }
 
-    if ( $conf_UAM[2] <> -1 )
+    // Set user unvalidated group
+    if (!is_admin() and $conf_UAM[2] <> -1)
     {
       $query = "
@@ -950,5 +1119,5 @@
   }
 
-  if ( $conf_UAM[2] <> -1 )
+  if (!is_admin() and $conf_UAM[2] <> -1)
   {
     $query = "
@@ -1110,5 +1279,6 @@
     $data = pwg_db_fetch_assoc(pwg_query($query));
         
-    if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
+    //if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
+    if (!empty($data) and isset($data['user_id']))
     {
       $query = "
@@ -1387,5 +1557,4 @@
 	if (isset($email) and isset($conf_UAM[12]) and $conf_UAM[12] <> '')
 	{
-		//$ncsemail = strtolower($email);
 		$conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[12]);
 		for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++)
@@ -1547,4 +1716,52 @@
 }
 
+
+/**
+ * Function called from functions.inc.php - Get all ghost users to delete or downgrade automatically on any user login
+ * 
+ * @return : List of users to delete or downgrade automatically
+ * 
+ */
+function get_ghosts_autotasks()
+{
+	global $conf, $page;
+
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+  
+  $users = array();
+  
+	// search users depending expiration date and reminder sent
+  $query = '
+SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
+                lv.lastvisit,
+                lv.reminder
+FROM '.USERS_TABLE.' AS u
+  INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv
+    ON u.'.$conf['user_fields']['id'].' = lv.user_id
+WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[17].'")
+  AND lv.reminder = "true"
+ORDER BY lv.lastvisit ASC;';
+
+	$result = pwg_query($query);
+      
+  while ($row = pwg_db_fetch_assoc($result))
+  {
+  	$user = $row;
+    $user['groups'] = array();
+
+    array_push($users, $user);
+	}
+
+	// add group lists
+  $user_ids = array();
+  foreach ($users as $i => $user)
+  {
+  	$user_ids[$i] = $user['id'];
+	}
+  
+	return $users;
+}
+
+
 /**
  * Function called from UAM_admin.php - Get all users to display the number of days since their last visit
@@ -1823,5 +2040,5 @@
 
 /**
- * check_consult - Thx to LucMorizur
+ * UAM_check_profile - Thx to LucMorizur
  * checks if a user id is registered as having already
  * visited his profile.php page.
@@ -1836,5 +2053,5 @@
  * 
  */
-function check_consult($uid, &$user_idsOK)
+function UAM_check_profile($uid, &$user_idsOK)
 {
   $t = array();
Index: /extensions/NBC_UserAdvManager/trunk/include/upgradedb.inc.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/include/upgradedb.inc.php	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/include/upgradedb.inc.php	(revision 8065)
@@ -2,6 +2,5 @@
 /**
  * @author Eric@piwigo.org
- * @copyright 2010
- * 
+ *  
  * Upgrade processes for old plugin version
  * Called from maintain.inc.php on plugin activation
@@ -96,5 +95,5 @@
 function upgrade_212_213()
 {
-/* Create missing table */
+  // Create missing table
   $query = "
 ALTER TABLE ".USER_CONFIRM_MAIL_TABLE."
@@ -104,5 +103,5 @@
   pwg_query($query);
 
-/* Upgrade plugin configuration */
+  // Upgrade plugin configuration
 	global $conf;
 
@@ -164,5 +163,5 @@
   global $conf;
 
-/* Changing parameter name */
+  // Changing parameter name
   $q = '
 UPDATE '.CONFIG_TABLE.'
@@ -179,5 +178,5 @@
   pwg_query($q);
 
-/* Upgrading ConfirmMail options */
+  // Upgrading ConfirmMail options
   $query = '
 SELECT value
@@ -214,5 +213,5 @@
   global $conf;
 
-/* Upgrading options */
+  // Upgrading options
   $query = '
 SELECT value
@@ -268,11 +267,11 @@
 }
 
-/* upgrade from 2.15.9 to 2.16.0 */
+/* upgrade from 2.15.x to 2.16.0 */
 /* ***************************** */
-function upgrade_2159_2160()
+function upgrade_215_2160()
 {
   global $conf;
 
-/* Upgrading options */
+  // Upgrading options
   $query = '
 SELECT value
@@ -291,4 +290,6 @@
   $Newconf_UAM[25] = 'Sorry, your account has been deleted due to a too long time passed since your last visit.';
   $Newconf_UAM[26] = 'Sorry, your account has been deprecated due to a too long time passed since your last visit. Please, use the following link to revalidate your account.';
+  $Newconf_UAM[27] = '-1';
+  $Newconf_UAM[28] = '-1';
   
   $update_conf = serialize($Newconf_UAM);
@@ -306,5 +307,5 @@
   $query = '
 INSERT INTO '.CONFIG_TABLE.' (param, value, comment)
-VALUES ("UserAdvManager_Version","2.15.8","UAM version check")
+VALUES ("UserAdvManager_Version","2.16.0","UAM version check")
   ;';
   
Index: /extensions/NBC_UserAdvManager/trunk/language/fr_FR/help/plugin.lang.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/language/fr_FR/help/plugin.lang.php	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/language/fr_FR/help/plugin.lang.php	(revision 8065)
@@ -13,10 +13,4 @@
 ';
 $lang['UAM_miscTitle'] = 'Suivi des inscrits et fonctions diverses';
-$lang['UAM_miscTitle_d'] = '
-- Gestion des visiteurs fantômes<br>
-- Suivi des visiteurs inscrits<br>
-- Pseudo obligatoire sur commentaire pour les visiteurs<br>
-...
-';
 $lang['UAM_casenTitle'] = 'Noms d\'utilisateurs : Sensibilité à la casse';
 $lang['UAM_carexcTitle'] = 'Noms d\'utilisateurs : Exclusion de certains caractères';
@@ -56,6 +50,4 @@
 $lang['UAM_remailtxt2Title'] = 'Message de rappel sans regénération de clé';
 $lang['UAM_ghosttrackerTitle'] = 'Gestion des visiteurs fantômes (aussi appelée Ghost Tracker)';
-$lang['UAM_ghosttrackerTitle_d'] = 'L\'activation de cette fonction permet la gestion des visiteurs inscrits en fonction de la fréquence de leurs visites. Une fois atteint le délai entre 2 visites successives, le visiteur apparaît dans le tableau de l\'onglet &quot;Ghost Tracker&quot; d\'où il est possible de le relancer par email.<br><br>
-<b style=&quot;color: red;&quot;>IMPORTANT : A première activation de cette fonction, ou à sa réactivation après une longue période pendant laquelle de nouveaux visiteurs se sont inscrits, il convient d\'initialiser le Ghost Tracker (voir les instructions correspondantes sur l\'onglet &quot;Ghost Tracker&quot;).</b>';
 $lang['UAM_gttextTitle'] = 'Message de rappel Ghost Tracker';
 $lang['UAM_lastvisitTitle'] = 'Suivi des utilisateurs inscrits';
@@ -134,5 +126,5 @@
 <b>Fonction de tri du tableau</b>: Vous pouvez trier les données affichées en cliquant sur les entêtes de colonnes. L\'utilisation de la touche MAJ ou SHIFT permet de trier sur 1 à 4 colonnes simultanées maximum.';
 $lang['UAM_confirmmailTitle'] = 'Confirmation d\'inscription';
-$lang['UAM_confirmmailTitle_d'] = 'Cette option permet soit à un utilisateur de valider son inscription en cliquant sur un lien reçu dans un email envoyé dès son enregistrement sur la galerie soit à l\'administrateur d\'activer manuellement les inscriptions.<br><br>
+$lang['UAM_confirmmailTitle_d'] = 'Cette option permet soit à un utilisateur de valider son inscription en cliquant sur un lien reçu dans un email envoyé dès son enregistrement sur la galerie, soit à l\'administrateur d\'activer manuellement les inscriptions.<br><br>
 Dans le premier cas, le message envoyé comprend une partie fixe, avec le lien d\'activation généré à partir d\'une clef aléatoire (cette clé peut éventuellement être régénérée via l\'onglet &quot;Suivi des validations&quot;), et une partie personnalisable par un texte d\'accueil.
 <br><br>
@@ -154,19 +146,15 @@
 
 
-// --------- Starting below: New or revised $lang ---- from version 2.15.7
-$lang['UAM_GTAutoTitle'] = 'Gestion automatique des utilisateurs fantomes';
-$lang['UAM_GTAutoTitle_d'] = 'Cette option permet d\'appliquer des règles de gestion automatisée des visiteurs fantômes. Lorsque ce mode est actif, on partira du principe qu\'un visiteur ayant atteind la limite maximale entre deux visites et ayant déjà été notifié par mail est considéré comme expiré.';
-$lang['UAM_GTAutoDelTitle'] = 'Suppression automatique des comptes expirés';
-$lang['UAM_GTAutoDelTitle_d'] = 'Supprime automatiquement le compte d\'un utilisateur lorsque celui-ci est expiré. La suppression survient lors de la connexion de l\'utilisateur qui est alors redirigé vers une page annonçant que sont compte a été détruit. Un texte personnalisé peut être saisi dans le champ ci-dessous.<br>
-Ce champ est compatible avec l\'extension FCK Editor et, pour une utilisation multi-langues, vous pouvez utiliser les balises [lang] du plugin Extended Description si celui-ci est actif.<br><br>
-Note : Lorsque cette option est active, les autres règles automatiques ne sont pas accessibles.';
-$lang['UAM_GTAutoGpTitle'] = 'Changement automatique de groupe / statut';
-$lang['UAM_GTAutoGpTitle_d'] = 'Changement automatique de groupe / statut';
-$lang['UAM_GTAutoMailTitle'] = 'Emailing automatique des comptes expirés';
-$lang['UAM_GTAutoMailTitle_d'] = 'Emailing automatique des comptes expirés';
-// --------- End: New or revised $lang ---- from version 2.15.7
-
-
 // --------- Starting below: New or revised $lang ---- from version 2.16.0
+$lang['UAM_ghosttrackerTitle_d'] = 'L\'activation de cette fonction permet la gestion des visiteurs inscrits en fonction de la fréquence de leurs visites. 2 fonctionnements sont possibles:<br><br>
+- Gestion manuelle : Lorsque le délai entre 2 visites successives est atteint, le visiteur apparaît dans le tableau de l\'onglet &quot;Ghost Tracker&quot; d\'où il est possible de le relancer manuellement par email ou le supprimer.<br><br>
+- Gestion automatisée : Lorsque le délai entre 2 visites successives est atteint, le visiteur est automatiquement soit supprimé, soit basculé dans un groupe et/ou statut d\'attente. Dans ce deuxième cas, un email d\'information peut lui être envoyé.<br><br><br>
+<b style=&quot;color: red;&quot;>IMPORTANT : A première activation de cette fonction, ou à sa réactivation après une longue période pendant laquelle de nouveaux visiteurs se sont inscrits, il convient d\'initialiser le Ghost Tracker (voir les instructions correspondantes sur l\'onglet &quot;Ghost Tracker&quot;).</b>';
+$lang['UAM_miscTitle_d'] = '
+- Gestion automatique ou manuelle des visiteurs fantômes<br>
+- Suivi des visiteurs inscrits<br>
+- Pseudo obligatoire sur commentaire pour les visiteurs<br>
+...
+';
 $lang['UAM_mailexcTitle_d'] = 'Par défaut, Piwigo accepte toutes les adresses de messagerie au format xxx@yyy.zz. L\'activation de cette option permet d\'exclure certains domaines selon le format : @[nom_du_domaine].[extension_du_domaine].<br><br>
 Exemples :<br>
@@ -191,4 +179,22 @@
 $lang['UAM_gttextTitle_d'] = 'Saisissez ici le texte qui apparaîtra dans l\'email de rappel pour inciter l\'utilisateur à revenir visiter votre galerie (NB: Le texte pré-renseigné à l\'installation du plugin est donné à titre d\'exemple).<br><br>
 Pour une utilisation multi-langues, vous pouvez utiliser les balises [lang] du plugin Extended Description si celui-ci est actif.';
+$lang['UAM_GTAutoTitle'] = 'Gestion automatique des utilisateurs fantomes';
+$lang['UAM_GTAutoTitle_d'] = 'Cette option permet d\'appliquer des règles de gestion automatisée des visiteurs fantômes.
+<br><br>Principe de base : Un compte d\'utilisateur ayant atteind la limite maximale entre deux visites <b>et</b> ayant déjà été notifié par email est considéré comme expiré. On peut alors appliquer des règles de traitement automatisées telles que la suppression automatique des comptes expirés ou leur rétrogradation en restreignant l\'accès à la galerie (bascule automatique dans un groupe et/ou un statut à accès restreint).
+<br><br>Le déclenchement de ces automatismes se réalise lors de la connexion des utilisateurs (n\'importe quel utilisateur !)à la galerie.';
+$lang['UAM_GTAutoDelTitle'] = 'Suppression automatique des comptes expirés';
+$lang['UAM_GTAutoDelTitle_d'] = 'Supprime automatiquement le compte d\'un utilisateur lorsque celui-ci est expiré.
+<br><br>Fonction à utiliser avec précaution car la suppression des comptes est définitive et sans appel !<br><br>
+La suppression survient lors de la connexion de l\'utilisateur qui est alors redirigé vers une page annonçant que son compte a été détruit. Un texte personnalisé peut être saisi dans le champ ci-dessous.<br>
+Ce champ est compatible avec l\'extension FCK Editor et, pour une utilisation multi-langues, vous pouvez utiliser les balises [lang] du plugin Extended Description si celui-ci est actif.<br><br>
+Note : Lorsque cette option est active, les autres règles automatiques ne sont pas accessibles.';
+$lang['UAM_GTAutoGpTitle'] = 'Changement automatique de groupe / statut';
+$lang['UAM_GTAutoGpTitle_d'] = 'Le changement automatique de groupe ou de statut équivaut à une rétrogradation des comptes concernés et fonctionne sur le même principe que le groupe ou le statut de validation (voir &quot;Paramétrage des confirmations et validations d\'inscriptions&quot;). Il conviendra donc de définir un groupe et/ou un statut rétrogradant l\'accès à la galerie. Si cela a déjà été défini avec l\'utilisation de la fonction Confirmation d\'inscription, on peut utiliser ces mêmes groupe / statut.';
+$lang['UAM_GTAutoMailTitle'] = 'Email automatique sur changement de groupe / statut';
+$lang['UAM_GTAutoMailTitle_d'] = 'Lorsqu\'un compte est expiré (changement de groupe / statut rétrogradant le visiteur), un email d\'information peut être envoyé pour préciser les raisons de ce changement et le moyen de recouvrer l\'accès initial à la galerie.
+<br>Pour ce faire, un lien de revalidation de l\'inscription est joint à l\'email (génération automatique d\'une nouvelle clé de validation).
+<br><br>Saisissez aussi le texte personnalisé qui expliquera les raisons de la rétrogradation et qui accompagnera le lien de validation. Le texte personnalisé n\'est pas obligatoire mais vivement conseillé. En effet, vos visiteurs inscrits n\'apprécieront que moyennement de recevoir un email ne contenant qu\'un simple lien sans plus d\'explications. ;-)
+<br><br>Pour une utilisation multi-langues, vous pouvez utiliser les balises [lang] du plugin Extended Description si celui-ci est actif.
+<br><br><b style=&quot;color: red;&quot;>Attention : L\'emploi de cette fonction est intimement lié à l\'option de confirmation d\'inscription par l\'utilisateur (confirmation par mail) et ne peut pas être activée sans cette option.</b>';
 // --------- End: New or revised $lang ---- from version 2.16.0
 ?>
Index: /extensions/NBC_UserAdvManager/trunk/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/language/fr_FR/plugin.lang.php	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/language/fr_FR/plugin.lang.php	(revision 8065)
@@ -271,4 +271,6 @@
 
 // --------- Starting below: New or revised $lang ---- from version 2.16.0
+$lang['UAM_Expired_Group'] = '<b>Groupe</b> pour les utilisateurs dont l\'inscription aura expirée<br>';
+$lang['UAM_Expired_Status'] = '<b>Statut</b> pour les utilisateurs dont l\'inscription aura expirée<br>';
 $lang['UAM_GTAuto'] = 'Gestion automatique des utilisateurs fantomes';
 $lang['UAM_GTAuto_false'] = ' Désactiver (valeur par défaut)';
@@ -278,7 +280,13 @@
 $lang['UAM_GTAutoDel_false'] = ' Désactiver (valeur par défaut)';
 $lang['UAM_GTAutoDel_true'] = ' Activer';
-$lang['UAM_GTAutoMail'] = 'Emailing de rappel automatique';
+$lang['UAM_GTAutoMail'] = 'Email automatique sur changement de groupe / statut';
 $lang['UAM_GTAutoMail_false'] = ' Désactiver (valeur par défaut)';
 $lang['UAM_GTAutoMail_true'] = ' Activer';
+$lang['Deleted_Account_Redirection_Page'] = 'Accès refusé - Compte détruit !';
+$lang['title_redir_page'] = 'Accès refusé pour cause de compte détruit !';
+$lang['Error_GTAutoMail_cannot_be_set_without_ConfirmMail'] = 'Erreur de cohérence dans la configuration choisie :<br><br>
+"Paramétrage des suivis des inscrits et autres options > Gestion des visiteurs fantômes (Ghost Tracker) > Gestion automatique des utilisateurs fantomes  > Email automatique sur changement de groupe / statut" ne peut pas être activé si "Paramétrage des confirmations et validations d\'inscriptions  > Confirmation d\'inscription - Validation par le visiteur" n\'est pas activé au préalable.<br><br>
+Pour garantir la cohérence, l\'option "Email automatique sur changement de groupe / statut" a été automatiquement repositionnée en "désactivé".<br><br>';
+$lang['Demotion of %s'] = 'Rétrogradation de %s';
 // --------- End: New or revised $lang ---- from version 2.16.0
 ?>
Index: /extensions/NBC_UserAdvManager/trunk/main.inc.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/main.inc.php	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/main.inc.php	(revision 8065)
@@ -2,5 +2,5 @@
 /*
 Plugin Name: UserAdvManager
-Version: 2.16.0-alpha
+Version: 2.16.0b
 Description: Renforcer la gestion des utilisateurs - Enforce users management
 Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=216
@@ -47,5 +47,6 @@
 
 // Redirection to profile page
-add_event_handler('login_success', 'RedirectToProfile');
+add_event_handler('login_success', 'UAM_LoginTasks');
+
 
 // *** Important ! This is necessary to make email exclusion work in admin's users management panel ***
Index: /extensions/NBC_UserAdvManager/trunk/maintain.inc.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/maintain.inc.php	(revision 8064)
+++ /extensions/NBC_UserAdvManager/trunk/maintain.inc.php	(revision 8065)
@@ -26,5 +26,5 @@
 Best regards,
 
-The admin of the gallery.','false','false','false');
+The admin of the gallery.','false','false','false','false','false','false','Sorry, your account has been deleted due to a too long time passed since your last visit.','Sorry, your account has been deprecated due to a too long time passed since your last visit. Please, use the following link to revalidate your account.',-1,-1);
 
   $q = '
@@ -180,5 +180,6 @@
   }
 
-
+/* Check for upgrade from 2.15 to 2.16 */
+/* *********************************** */
 	$query = '
 SELECT param
@@ -190,5 +191,7 @@
   if ($count == 0)
   {
-    upgrade_2159_2160();
+    /* upgrade from branch 2.15 to 2.16 */
+    /* ******************************** */
+    upgrade_215_2160();
   }
 
Index: /extensions/NBC_UserAdvManager/trunk/template/del_account.tpl
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/template/del_account.tpl	(revision 8065)
+++ /extensions/NBC_UserAdvManager/trunk/template/del_account.tpl	(revision 8065)
@@ -0,0 +1,17 @@
+{html_head}<link rel="stylesheet" type="text/css" href="template/confmail.css">{/html_head}
+
+<div id="content" class="content">
+  <div class="titrePage">
+    <ul class="categoryActions">
+      <li>
+        <a href="{$GALLERY_URL}" title="{'return to homepage'|@translate}">
+          <img src="{$ROOT_URL}{$themeconf.icon_dir}/home.png" class="button" alt="{'home'|@translate}">
+        </a>
+      </li>
+    </ul>
+    <h2 class="confmail">{'title_redir_page'|@translate}</h2>
+  </div>
+  <ul>
+    <div class="errors">{$CUSTOM_REDIR_MSG}</div>
+  </ul>
+</div>
