Index: /extensions/NBC_UserAdvManager/trunk/include/functions.inc.php
===================================================================
--- /extensions/NBC_UserAdvManager/trunk/include/functions.inc.php	(revision 7967)
+++ /extensions/NBC_UserAdvManager/trunk/include/functions.inc.php	(revision 7968)
@@ -3,7 +3,515 @@
 load_language('plugin.lang', UAM_PATH);
 
-/* Function called from main.inc.php to send validation email */
+/**
+ * Triggered on get_admin_plugin_menu_links
+ * 
+ * Plugin's administration menu 
+ */
+function UAM_admin_menu($menu)
+{
+// +-----------------------------------------------------------------------+
+// |                      Getting plugin name                              |
+// +-----------------------------------------------------------------------+
+  $plugin =  PluginInfos(UAM_PATH);
+  $name = $plugin['name'];
+  
+  array_push($menu,
+    array(
+      'NAME' => $name,
+      'URL'  => get_admin_plugin_menu_link(UAM_PATH.'/admin/UAM_admin.php')
+    )
+  );
+
+  return $menu;
+}
+
+/**
+ * Triggered on loc_begin_index
+ * 
+ * Initiating GhostTracker
+ */
+function UAM_GhostTracker()
+{
+  global $conf, $user;
+
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+
+  // Admins, Guests and Adult_Content users are not tracked for Ghost Tracker or Users Tracker
+  if (!is_admin() and !is_a_guest() and $user['username'] != "16" and $user['username'] != "18")
+  {
+    if ((isset($conf_UAM[16]) and $conf_UAM[16] == 'true') or (isset($conf_UAM[19]) and $conf_UAM[19] == 'true'))
+    {
+
+      $userid = get_userid($user['username']);
+     	  
+      // Looking for existing entry in last visit table
+      $query = '
+SELECT *
+FROM '.USER_LASTVISIT_TABLE.'
+WHERE user_id = '.$userid.'
+;';
+        
+      $count = pwg_db_num_rows(pwg_query($query));
+         
+      if ($count == 0)
+      {
+        // If not, data are inserted in table
+        $query = '
+INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder)
+VALUES ('.$userid.', now(), "false")
+;';
+        pwg_query($query);
+      }
+      else if ($count > 0)
+      {
+        // If yes, data are updated in table
+        $query = '
+UPDATE '.USER_LASTVISIT_TABLE.'
+SET lastvisit = now(), reminder = "false"
+WHERE user_id = '.$userid.'
+LIMIT 1
+;';
+        pwg_query($query);
+      }
+    }
+  }
+}
+
+/**
+ * Triggered on register_user
+ * 
+ * Additional controls on user registration
+ */
+function UAM_Adduser($register_user)
+{
+  global $conf;
+
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+
+  // Exclusion of Adult_Content users
+  if ($register_user['username'] != "16" and $register_user['username'] != "18")
+  {
+    if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
+    {
+      // This is to send an information email and set user to "waiting" group or status until admin validation
+      $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
+      SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
+      setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
+    }
+    elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
+    {
+      // This is to set user to "waiting" group or status until admin validation
+      setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
+    }
+    elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'false'))
+    {
+      // This is to send an information email without validation key
+      $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
+      SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
+    }
+    // Sending registration confirmation by email
+    elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true' or $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true'))
+    {
+      if (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'true')
+      {
+        $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
+        SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); 
+      }
+      elseif (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'false')
+      {
+        $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
+        SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
+      }
+      elseif (!is_admin())
+      {
+        $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
+        SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true);
+      }
+    }
+  }
+}
+
+/**
+ * Triggered on delete_user
+ * 
+ * Database cleanup on user deletion
+ */
+function UAM_Deluser($user_id)
+{
+  // Cleanup for ConfirmMail table
+  DeleteConfirmMail($user_id);
+  // Cleanup for LastVisit table
+  DeleteLastVisit($user_id);
+  // Cleanup Redirection settings
+  DeleteRedir($user_id);
+}
+
+/**
+ * Triggered on register_user_check
+ * 
+ * Additional controls on user registration check
+ */
+function UAM_RegistrationCheck($err, $user)
+{
+  global $errors, $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
+// ******************************************
+    $PasswordCheck = 0;
+
+    $conf_UAM = unserialize($conf['UserAdvManager']);
+
+    // Password enforcement control
+    if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14]))
+    {
+      if (!empty($user['password']) and !is_admin())
+      {
+        $PasswordCheck = testpassword($user['password']);
+  
+        if ($PasswordCheck < $conf_UAM[14])
+        {
+          $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
+          return($lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]);
+        }
+      }
+      else if (!empty($user['password']) and is_admin() and isset($conf_UAM[15]) and $conf_UAM[15] == 'true')
+      {
+        $PasswordCheck = testpassword($user['password']);
+  
+        if ($PasswordCheck < $conf_UAM[14])
+        {
+          $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
+          return($lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]);
+        }
+      }
+    }
+
+    // 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]."'");
+    }
+
+    // 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]."'");
+    }
+  }
+}
+
+/**
+ * Triggered on loc_begin_profile
+ */
+function UAM_Profile_Init()
+{
+  global $conf, $user, $template;
+
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+    
+  if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true'))
+  {
+    $user_idsOK = array();
+    if (!check_consult($user['id'], $user_idsOK))
+    {
+      $user_idsOK[] = $user['id'];
+
+      $query = "
+UPDATE ".CONFIG_TABLE."
+SET value = \"".implode(',', $user_idsOK)."\"
+WHERE param = 'UserAdvManager_Redir';";
+          
+      pwg_query($query);
+    }
+  }
+
+  if (isset($_POST['validate']) and !is_admin())
+  {
+    // Email without forbidden domains
+    if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['mail_address']))
+    {
+      if (ValidateEmailProvider($_POST['mail_address']))
+      {
+        $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'");
+        unset($_POST['validate']);
+      }
+    }
+
+    $typemail = 3;
+
+    if (!empty($_POST['use_new_pwd']))
+    {
+      $typemail = 2;
+
+      // Password enforcement control
+      if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14]))
+      {
+        $PasswordCheck = testpassword($_POST['use_new_pwd']);
+
+        if ($PasswordCheck < $conf_UAM[14])
+        {
+          $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
+          $template->append('errors', l10n_args($message).$conf_UAM[14]);
+          unset($_POST['use_new_pwd']);
+          unset($_POST['validate']);
+        }
+      }
+    }
+
+    // Sending registration confirmation by email
+    if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
+    {
+      $confirm_mail_need = false;
+
+      if (!empty($_POST['mail_address']))
+      {
+        $query = '
+SELECT '.$conf['user_fields']['email'].' AS email
+FROM '.USERS_TABLE.'
+WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
+;';
+
+        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[1]) and $conf_UAM[1] == 'true'))
+        
+          $confirm_mail_need = true;
+
+        // This is to set the user to "waiting" group or status until admin validation
+        if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
+        
+          setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
+          $confirm_mail_need = false;
+      }
+        
+      if ((!empty($_POST['use_new_pwd']) and (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or $confirm_mail_need))
+      {
+        $query = '
+SELECT '.$conf['user_fields']['username'].'
+FROM '.USERS_TABLE.'
+WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\'
+;';
+        
+        list($username) = pwg_db_fetch_row(pwg_query($query));
+        SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need);
+      }
+    }
+  }
+}
+
+/**
+ * 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()
+{
+  global $conf, $user;
+  
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+  
+  $query ='
+SELECT user_id, status
+FROM '.USER_INFOS_TABLE.'
+WHERE user_id = '.$user['id'].'
+;';
+  $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;
+  
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+
+  // Ghost accounts auto deletion
+  if ((isset($conf_UAM[22]) and $conf_UAM[22] == 'true') and (isset($conf_UAM[23]) and $conf_UAM[23] == 'true'))
+  {
+    
+  }
+
+  // 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)))
+  {
+    
+  }
+}
+
+/**
+ * Triggered on init
+ * 
+ * Check for forbidden email domains in admin's users management panel
+ */
+function UAM_InitPage()
+{
+  load_language('plugin.lang', UAM_PATH);
+  global $conf, $template, $page, $lang, $errors;
+
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+
+// Admin user management
+  if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list')
+  {
+    if (isset($_POST['submit_add']))
+    {
+      // Email without forbidden domains
+      if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email']))
+      {
+        $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'");
+        unset($_POST['submit_add']);
+      }
+    }
+  }
+}
+
+/**
+ * Triggered on user_comment_check
+ * 
+ * checks if author is mandatory and set on comments post
+ *
+ * @param : comment action, comment
+ * 
+ * @return : comment action
+ * 
+ */
+function UAM_CheckEmptyCommentAuthor($comment_action, $comm)
+{
+  load_language('plugin.lang', UAM_PATH);
+  global $infos, $conf, $template;
+
+  $conf_UAM = unserialize($conf['UserAdvManager']);
+
+// User creation OR update
+  if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest')
+  {
+    $comment_action = 'reject';
+
+    array_push($infos, l10n('UAM_Empty Author'));
+  }
+
+  return $comment_action;
+}
+
+/**
+ * Function called from main.inc.php to send validation email
+ *
+ * @param : Type of email, user id, username, email address, confirmation (optional)
+ * 
+ */
 function SendMail2User($typemail, $id, $username, $password, $email, $confirm)
 {
+  // Only available for next Piwigo release (bug in switch_lang function)
   global $conf;
 
@@ -15,5 +523,5 @@
   $infos2_perso = "";
 
-/* We have to get the user's language in database */
+// We have to get the user's language in database
   $query ='
 SELECT user_id, language
@@ -23,8 +531,8 @@
   $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 */
+// 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 */
+// 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);
@@ -32,6 +540,6 @@
   else
   {
-/* And switch gallery to this language before using personalized and multilangual contents */
-    $language = $data['language']; /* Usefull for debugging */
+// 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);
@@ -98,7 +606,7 @@
   }
 
-/* ******************************************************** */
-/* **** Pending code since to find how to make it work **** */
-/* ******************************************************** */
+// ********************************************************
+// **** Pending code since to find how to make it work ****
+// ********************************************************
 // Testing if FCK Editor is used. Then decoding htmlchars to avoid problems with pwg_mail()
 /*$areas = array();
@@ -123,5 +631,5 @@
 
 
-/* Sending the email with subject and contents */
+// Sending the email with subject and contents
   pwg_mail($email, array(
     'subject' => $subject,
@@ -129,23 +637,27 @@
   ));
 
-/* ********************** */
-/* Email sending debugger */
-/* This is only to trace  */
-/* the send of emails for */
-/* debugging              */
-/* ********************** */
+// **********************
+// Email sending debugger
+// This is only to trace 
+// the send of emails for
+// debugging             
+// **********************
 //$content = (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url();   
 //MailLog($email,$subject,$content,$language);
-/* ********************** */
-
-/* Switching back to default language */
+// **********************
+
+// Switching back to default language
 switch_lang_back();
 }
 
-
-/* Function called from UAM_admin.php to resend validation email with or without new validation key */
+/**
+ * Function called from UAM_admin.php to resend validation email with or without new validation key
+ *
+ * @param : Type of email, user id, username, email address, confirmation (optional)
+ * 
+ */
 function ResendMail2User($typemail, $user_id, $username, $email, $confirm)
 {
-  /* Only available for next Piwigo release (bug in switch_lang function) */
+  // Only available for next Piwigo release (bug in switch_lang function)
   global $conf;
 
@@ -159,5 +671,5 @@
   $infos2_perso = "";
   
-/* We have to get the user's language in database */
+// We have to get the user's language in database
   $query ='
 SELECT user_id, language
@@ -168,5 +680,5 @@
   $language = $data['language'];
   
-/* And switch gallery to this language before using personalized and multilangual contents */
+// And switch gallery to this language before using personalized and multilangual contents
   switch_lang_to($data['language']);
    
@@ -193,5 +705,5 @@
 			}
 
-/* Set reminder true */      
+// Set reminder true      
       $query = "
 UPDATE ".USER_CONFIRM_MAIL_TABLE."
@@ -215,5 +727,5 @@
       }
       
-/* Set reminder true */      
+// Set reminder true      
       $query = "
 UPDATE ".USER_CONFIRM_MAIL_TABLE."
@@ -231,23 +743,27 @@
   ));
 
-/* ********************** */
-/* Email sending debugger */
-/* This is only to trace  */
-/* the send of emails for */
-/* debugging              */
-/* ********************** */
+// **********************
+// Email sending debugger
+// This is only to trace 
+// the send of emails for
+// debugging             
+// **********************
 //$content = ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url();
 //MailLog($email,$subject,$content,$language);
-/* ********************** */
-
-/* Switching back to default language */
+// **********************
+
+// Switching back to default language
 switch_lang_back();
 }
 
-
-/* Function called from UAM_admin.php to send a reminder mail for ghost users */
+/**
+ * Function called from UAM_admin.php to send a reminder mail for ghost users
+ *
+ * @param : User id, username, email address
+ * 
+ */
 function ghostreminder($user_id, $username, $email)
 {
-  /* Only available for next Piwigo release (bug in switch_lang function) */
+  // Only available for next Piwigo release (bug in switch_lang function)
   global $conf;
 
@@ -258,5 +774,5 @@
 	$infos1_perso = "";
 
-/* We have to get the user's language in database */
+// We have to get the user's language in database
   $query ='
 SELECT user_id, language
@@ -267,5 +783,5 @@
   $language = $data['language'];
 
-/* And switch gallery to this language before using personalized and multilangual contents */
+// And switch gallery to this language before using personalized and multilangual contents
   switch_lang_to($data['language']);
    
@@ -293,20 +809,24 @@
   ));
 
-/* ********************** */
-/* Email sending debugger */
-/* This is only to trace  */
-/* the send of emails for */
-/* debugging              */
-/* ********************** */
+// **********************
+// Email sending debugger
+// This is only to trace 
+// the send of emails for
+// debugging             
+// **********************
 //$content = get_user_language_desc($conf_UAM[19])."\n\n";  
 //MailLog($email,$subject,$content,$language);
-/* ********************** */
-
-/* Switching back to default language */
+// **********************
+
+// Switching back to default language
 switch_lang_back();
 }
 
-
-/* Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation */
+/**
+ * Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation
+ * 
+ * @return : validation key
+ * 
+ */
 function FindAvailableConfirmMailID()
 {
@@ -326,6 +846,12 @@
 }
 
-
-/* Function called from functions SendMail2User to process unvalidated users and generate validation key link */
+/**
+ * Function called from functions SendMail2User to process unvalidated users and generate validation key link
+ *
+ * @param : User id, email address
+ * 
+ * @return : Build validation key in URL
+ * 
+ */
 function AddConfirmMail($user_id, $email)
 {
@@ -390,6 +916,11 @@
 }
 
-
-/* Function called from main.inc.php to set group to new users if manual validation is set */
+/**
+ * Function called from main.inc.php to set group to new users if manual validation is set
+ *
+ * @param : User id
+ * 
+ * 
+ */
 function setgroup($user_id)
 {
@@ -431,6 +962,12 @@
 }
 
-
-/* Function called from UAM_admin.php to reset validation key */
+/**
+ * Function called from UAM_admin.php to reset validation key
+ *
+ * @param : User id
+ * 
+ * @return : Build validation key in URL
+ * 
+ */
 function ResetConfirmMail($user_id)
 {
@@ -461,6 +998,10 @@
 }
 
-
-/* Function called from function_UserAdvManager.inc.php to reset last visit date after sending a reminder */
+/**
+ * Function called from functions.inc.php to reset last visit date after sending a reminder
+ *
+ * @param : User id
+ * 
+ */
 function resetlastvisit($user_id)
 {
@@ -478,5 +1019,8 @@
 
 
-/* Function called from main.inc.php - Triggered on user deletion */
+/**
+ * Function called from main.inc.php - Triggered on user deletion
+ * 
+ */
 function DeleteConfirmMail($user_id)
 {
@@ -488,5 +1032,8 @@
 }
 
-/* Function called from main.inc.php - Triggered on user deletion */
+/**
+ * Function called from main.inc.php - Triggered on user deletion
+ * 
+ */
 function DeleteLastVisit($user_id)
 {
@@ -498,6 +1045,10 @@
 }
 
-
-/* Function called from main.inc.php - Triggered on user deletion */
+/**
+ * Function called from main.inc.php - Triggered on user deletion
+ *
+ * @param : User id
+ * 
+ */
 function DeleteRedir($user_id)
 {
@@ -524,7 +1075,13 @@
 }
 
-
-/* Function called from ConfirmMail.php to verify validation key used by user according time limit */
-/* Return true is key validation is OK else return false */
+/**
+ * Function called from ConfirmMail.php to verify validation key used by user according time limit
+ * Return true is key validation is OK else return false
+ *
+ * @param : User id
+ * 
+ * @return : Bool
+ * 
+ */
 function VerifyConfirmMail($id)
 {
@@ -562,6 +1119,6 @@
       list($registration_date) = pwg_db_fetch_row(pwg_query($query));
 
-/*              Time limit process              */
-/* ******************************************** */  
+//              Time limit process             
+// ********************************************  
       if (!empty($registration_date))
       {
@@ -694,5 +1251,12 @@
 }
 
-/* Function called from UAM_admin.php to force users validation by admin */
+/**
+ * Function called from UAM_admin.php to force users validation by admin
+ *
+ * @param : User id
+ * 
+ * @return : Bool
+ * 
+ */
 function ForceValidation($id)
 {
@@ -774,6 +1338,12 @@
 }
 
-
-/* Function called from main.inc.php - Check if username matches forbidden caracters */
+/**
+ * Function called from main.inc.php - Check if username matches forbidden caracters
+ *
+ * @param : User login
+ * 
+ * @return : Bool
+ * 
+ */
 function ValidateUsername($login)
 {
@@ -800,7 +1370,13 @@
 }
 
-
-/* Function called from main.inc.php - Check if user's email is in excluded email providers list */
-/* Doesn't work on call - Must be copied in main.inc.php to work */
+/**
+ * Function called from main.inc.php - Check if user's email is in excluded email providers list
+ * Doesn't work on call - Must be copied in main.inc.php to work
+ *
+ * @param : Email address
+ * 
+ * @return : Bool
+ * 
+ */
 function ValidateEmailProvider($email)
 {
@@ -828,18 +1404,22 @@
 }
 
-
-/* Function called from UserAdvManager.php - Get unvalidated users according time limit */
+/**
+ * Function called from UAM_admin.php - Get unvalidated users according time limit
+ * 
+ * @return : List of users
+ * 
+ */
 function get_unvalid_user_list()
 {
 	global $conf, $page;
           
-	/* Get ConfirmMail configuration */
+	// Get ConfirmMail configuration
   $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
-  /* Get UAM configuration */
+  // Get UAM configuration
   $conf_UAM = unserialize($conf['UserAdvManager']);
   
   $users = array();
 
-	/* search users depending expiration date */
+	// search users depending expiration date
   $query = '
 SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
@@ -889,5 +1469,5 @@
 	}
 
-	/* add group lists */
+	// add group lists
   $user_ids = array();
   foreach ($users as $i => $user)
@@ -920,6 +1500,10 @@
 }
 
-
-/* Function called from UserAdvManager.php - Get ghost users */
+/**
+ * Function called from UAM_admin.php - Get ghost users
+ * 
+ * @return : List of users
+ * 
+ */
 function get_ghost_user_list()
 {
@@ -930,5 +1514,5 @@
   $users = array();
 
-	/* search users depending expiration date */
+	// search users depending expiration date
   $query = '
 SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
@@ -953,5 +1537,5 @@
 	}
 
-	/* add group lists */
+	// add group lists
   $user_ids = array();
   foreach ($users as $i => $user)
@@ -963,6 +1547,10 @@
 }
 
-
-/* Function called from UserAdvManager.php - Get all users to display the number of days since their last visit */
+/**
+ * Function called from UAM_admin.php - Get all users to display the number of days since their last visit
+ * 
+ * @return : List of users
+ * 
+ */
 function get_user_list()
 {
@@ -971,5 +1559,5 @@
   $users = array();
 
-	/* search users depending expiration date */
+	// search users depending expiration date
   $query = '
 SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
@@ -994,5 +1582,5 @@
 	}
 
-	/* add group lists */
+	// add group lists
   $user_ids = array();
   foreach ($users as $i => $user)
@@ -1004,14 +1592,20 @@
 }
 
-
-/* Function called from UserAdvManager.php - to determine who is expired or not and giving a different display color */
+/**
+ * Function called from UAM_admin.php - to determine who is expired or not and giving a different display color
+ *
+ * @param : user id
+ * 
+ * @return : Bool
+ * 
+ */
 function expiration($id)
 {
 	global $conf, $page;
           
-	/* Get ConfirmMail configuration */
+	// Get ConfirmMail configuration
   $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
           
-	/* Get UAM configuration */
+	// Get UAM configuration
   $conf_UAM = unserialize($conf['UserAdvManager']);
 	
@@ -1023,6 +1617,6 @@
 	list($registration_date) = pwg_db_fetch_row(pwg_query($query));
 
-/*              Time limit process              */
-/* ******************************************** */  
+//              Time limit process             
+// ********************************************  
 	if (!empty($registration_date))
   {
@@ -1055,5 +1649,7 @@
  * Returns a password's score for password complexity check
  *
- * @param password filled by user
+ * @param : password filled by user
+ * 
+ * @return : Score calculation
  * 
  * Thanx to MathieuGut from http://m-gut.developpez.com
@@ -1128,5 +1724,12 @@
 }
 
-/* Function called from maintain.inc.php - to check if database upgrade is needed */
+/**
+ * Function called from maintain.inc.php - to check if database upgrade is needed
+ * 
+ * @param : table name
+ * 
+ * @return : boolean
+ * 
+ */
 function table_exist($table)
 {
@@ -1135,5 +1738,5 @@
 }
 
-/* Email sending debugger function */
+// Email sending debugger function
 function MailLog($to, $subject, $content, $language)
 {
@@ -1148,6 +1751,12 @@
 }
 
-
-/* Function called from UAM_admin.php and main.inc.php to get the plugin version and name */
+/**
+ * Function called from UAM_admin.php and main.inc.php to get the plugin version and name
+ *
+ * @param : plugin directory
+ * 
+ * @return : plugin's version and name
+ * 
+ */
 function PluginInfos($dir)
 {
@@ -1213,14 +1822,18 @@
 }
 
-
-// check_consult - Thx to LucMorizur
-// checks if a user id is registered as having already
-// visited his profile.php page.
-// @uid        : the user id
-// @user_idsOK : (returned) array of all users ids having already visited
-//               their profile.php pages
-//
-// @returns    : true or false whether the users has already visited his
-//               profile.php page or not
+/**
+ * check_consult - Thx to LucMorizur
+ * checks if a user id is registered as having already
+ * visited his profile.php page.
+ * 
+ * @uid        : the user id
+ * 
+ * @user_idsOK : (returned) array of all users ids having already visited
+ *               their profile.php pages
+ * 
+ * @returns    : true or false whether the users has already visited his
+ *               profile.php page or not
+ * 
+ */
 function check_consult($uid, &$user_idsOK)
 {
