Index: extensions/NBC_UserAdvManager-Trunk/admin/UserAdvManager_admin.php
===================================================================
--- extensions/NBC_UserAdvManager-Trunk/admin/UserAdvManager_admin.php	(revision 3460)
+++ extensions/NBC_UserAdvManager-Trunk/admin/UserAdvManager_admin.php	(revision 3470)
@@ -22,7 +22,7 @@
 // +-----------------------------------------------------------------------+
 if (!isset($_GET['tab']))
-    $page['tab'] = 'global';
+  $page['tab'] = 'global';
 else
-    $page['tab'] = $_GET['tab'];
+  $page['tab'] = $_GET['tab'];
 
 $tabsheet = new tabsheet();
@@ -51,120 +51,117 @@
 // |                           Global Config                               |
 // +-----------------------------------------------------------------------+
-	case 'global':
-	
-	if ( isset($_POST['submit']) and !is_adviser() and isset($_POST['UserAdvManager_Mail_Info']) and isset($_POST['UserAdvManager_No_Casse']) and isset($_POST['UserAdvManager_Username_Char']) and isset($_POST['UserAdvManager_Confirm_Mail']) and isset($_POST['UserAdvManager_No_Comment_Anonymous']) )
+  case 'global':
+	
+  if ( isset($_POST['submit']) and !is_adviser() and isset($_POST['UserAdvManager_Mail_Info']) and isset($_POST['UserAdvManager_No_Casse']) and isset($_POST['UserAdvManager_Username_Char']) and isset($_POST['UserAdvManager_Confirm_Mail']) and isset($_POST['UserAdvManager_No_Comment_Anonymous']) )
+  {
+    $_POST['UserAdvManager_MailInfo_Text'] = str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UserAdvManager_MailInfo_Text']));
+	$_POST['UserAdvManager_ConfirmMail_Text'] = str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UserAdvManager_ConfirmMail_Text']));
+		
+	$newconf_nbc_UserAdvManager = $_POST['UserAdvManager_Mail_Info'].';'.$_POST['UserAdvManager_No_Casse'].';'.$_POST['UserAdvManager_Confirm_Mail'].';'.(isset($_POST['UserAdvManager_No_Confirm_Group'])?$_POST['UserAdvManager_No_Confirm_Group']:'').';'.(isset($_POST['UserAdvManager_Validated_Group'])?$_POST['UserAdvManager_Validated_Group']:'').';'.(isset($_POST['UserAdvManager_Validated_Status'])?$_POST['UserAdvManager_Validated_Status']:'').';'.$_POST['UserAdvManager_No_Comment_Anonymous'].';'.$_POST['UserAdvManager_Username_Char'].';'.$_POST['UserAdvManager_Username_List'].';'.(isset($_POST['UserAdvManager_No_Confirm_Status'])?$_POST['UserAdvManager_No_Confirm_Status']:'').';'.$_POST['UserAdvManager_MailInfo_Text'].';'.$_POST['UserAdvManager_ConfirmMail_Text'].';'.$_POST['UserAdvManager_MailExclusion'].';'.$_POST['UserAdvManager_MailExclusion_List'];
+		
+	$conf['nbc_UserAdvManager'] = $newconf_nbc_UserAdvManager;
+		
+	$query = '
+	  UPDATE '.CONFIG_TABLE.'
+	  SET value="'.$newconf_nbc_UserAdvManager.'"
+	  WHERE param="nbc_UserAdvManager"
+	  LIMIT 1
+	  ;';
+		
+	pwg_query($query);
+		
+	array_push($page['infos'], l10n('UserAdvManager_save_config'));
+  }
+	
+  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
+	
+/* Group setting for unvalidated and validated users */
+  $groups[-1] = '---------';
+  $No_Valid = -1;
+  $Valid = -1;
+	
+/* Check groups list in database  */
+  $query = '
+    SELECT id, name
+	FROM '.GROUPS_TABLE.'
+	ORDER BY name ASC
+	;';
+	
+  $result = pwg_query($query);
+	
+  while ($row = mysql_fetch_array($result))
+  {
+    $groups[$row['id']] = $row['name'];
+/* configuration value for unvalidated users */
+    if (isset($conf_nbc_UserAdvManager[3]) and $conf_nbc_UserAdvManager[3] == $row['id'])
+    {
+	  $No_Valid = $row['id'];
+	}
+/* configuration value for validated users */
+    if (isset($conf_nbc_UserAdvManager[4]) and $conf_nbc_UserAdvManager[4] == $row['id'])
 	{
-		$_POST['UserAdvManager_MailInfo_Text'] = str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UserAdvManager_MailInfo_Text']));
-		$_POST['UserAdvManager_ConfirmMail_Text'] = str_replace("\'", "'", str_replace("\\\\", "\\", $_POST['UserAdvManager_ConfirmMail_Text']));
-		
-		$newconf_nbc_UserAdvManager = $_POST['UserAdvManager_Mail_Info'].';'.$_POST['UserAdvManager_No_Casse'].';'.$_POST['UserAdvManager_Confirm_Mail'].';'.(isset($_POST['UserAdvManager_No_Confirm_Group'])?$_POST['UserAdvManager_No_Confirm_Group']:'').';'.(isset($_POST['UserAdvManager_Validated_Group'])?$_POST['UserAdvManager_Validated_Group']:'').';'.(isset($_POST['UserAdvManager_Validated_Status'])?$_POST['UserAdvManager_Validated_Status']:'').';'.$_POST['UserAdvManager_No_Comment_Anonymous'].';'.$_POST['UserAdvManager_Username_Char'].';'.$_POST['UserAdvManager_Username_List'].';'.(isset($_POST['UserAdvManager_No_Confirm_Status'])?$_POST['UserAdvManager_No_Confirm_Status']:'').';'.$_POST['UserAdvManager_MailInfo_Text'].';'.$_POST['UserAdvManager_ConfirmMail_Text'].';'.$_POST['UserAdvManager_MailExclusion'].';'.$_POST['UserAdvManager_MailExclusion_List'];
-		
-		$conf['nbc_UserAdvManager'] = $newconf_nbc_UserAdvManager;
-		
-		$query = '
-		  UPDATE '.CONFIG_TABLE.'
-		  SET value="'.$newconf_nbc_UserAdvManager.'"
-		  WHERE param="nbc_UserAdvManager"
-		  LIMIT 1
-		  ;';
-		
-		pwg_query($query);
-		
-		array_push($page['infos'], l10n('UserAdvManager_save_config'));
+	  $Valid = $row['id'];
 	}
-	
-	$conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
-	
-	/* Group setting for unvalidated and validated users */
-	$groups[-1] = '---------';
-	$No_Valid = -1;
-	$Valid = -1;
-	
-	/* Check groups list in database  */
-	$query = '
-	  SELECT id, name
-	  FROM '.GROUPS_TABLE.'
-	  ORDER BY name ASC
-	  ;';
-	
-	$result = pwg_query($query);
-	
-	while ($row = mysql_fetch_array($result))
-	{
-		$groups[$row['id']] = $row['name'];
-		/* configuration value for unvalidated users */
-		if (isset($conf_nbc_UserAdvManager[3]) and $conf_nbc_UserAdvManager[3] == $row['id'])
-		{
-			$No_Valid = $row['id'];
+  }
+	
+/* Template initialization for unvalidated users group */
+  $template->assign(
+    'No_Confirm_Group',
+    array(
+	  'group_options'=> $groups,
+	  'group_selected' => $No_Valid
+	)
+  );
+/* Template initialization for validated users group */
+  $template->assign(
+    'Validated_Group',
+	array(
+      'group_options'=> $groups,
+      'group_selected' => $Valid
+	)
+  );
+	
+/* Status setting for unvalidated and validated users */
+  $status_options[-1] = '------------';
+  $No_Valid_Status = -1;
+  $Valid_Status = -1;
+	
+/* Get status values */
+  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
+    {
+	  $status_options[$status] = l10n('user_status_'.$status);
+	  if (isset($conf_nbc_UserAdvManager[9]) and $conf_nbc_UserAdvManager[9] == $status)
+	  {
+	    $No_Valid_Status = $status;
+	  }
+/* Template initialization for unvalidated users group */
+      $template->assign(
+        'No_Confirm_Status',
+        array(
+		  'Status_options' => $status_options,
+		  'Status_selected' => $No_Valid_Status
+		)
+	  );
+    }
+/* Get status values */
+  foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
+    {
+	  $status_options[$status] = l10n('user_status_'.$status);
+	  if (isset($conf_nbc_UserAdvManager[5]) and $conf_nbc_UserAdvManager[5] == $status)
+	    {
+		  $Valid_Status = $status;
 		}
-		/* configuration value for validated users */
-		if (isset($conf_nbc_UserAdvManager[4]) and $conf_nbc_UserAdvManager[4] == $row['id'])
-		{
-			$Valid = $row['id'];
-		}
-	}
-	
-	/* Template initialization for unvalidated users group */
-	$template->assign(
-	'No_Confirm_Group',
-	array(
-		'group_options'=> $groups,
-		'group_selected' => $No_Valid
+/* Template initialization for unvalidated users group */
+      $template->assign(
+	    'Confirm_Status',
+	    array(
+		  'Status_options' => $status_options,
+		  'Status_selected' => $Valid_Status
 		)
-	);
-	/* Template initialization for validated users group */
-	$template->assign(
-	'Validated_Group',
-	array(
-        'group_options'=> $groups,
-        'group_selected' => $Valid
-		)
-	);
-	
-	/* Status setting for unvalidated and validated users */
-	$status_options[-1] = '------------';
-	$No_Valid_Status = -1;
-	$Valid_Status = -1;
-	
-	/* Get status values */
-	foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
-	{
-		$status_options[$status] = l10n('user_status_'.$status);
-		if (isset($conf_nbc_UserAdvManager[9]) and $conf_nbc_UserAdvManager[9] == $status)
-		{
-			$No_Valid_Status = $status;
-		}
-	/* Template initialization for unvalidated users group */
-	$template->assign(
-    'No_Confirm_Status',
-	array(
-		'Status_options' => $status_options,
-		'Status_selected' => $No_Valid_Status
-		)
-	);
-	
-	}
-	/* Get status values */
-	foreach (get_enums(USER_INFOS_TABLE, 'status') as $status)
-	{
-		$status_options[$status] = l10n('user_status_'.$status);
-		if (isset($conf_nbc_UserAdvManager[5]) and $conf_nbc_UserAdvManager[5] == $status)
-		{
-			$Valid_Status = $status;
-		}
-	/* Template initialization for unvalidated users group */
-	$template->assign(
-	'Confirm_Status',
-	array(
-		'Status_options' => $status_options,
-		'Status_selected' => $Valid_Status
-		)
-	);
-	
-	}
-	
-	
-	$template->assign(
-	array(
+	  );
+    }
+	
+  $template->assign(
+    array(
 		'UserAdvManager_MAIL_INFO_TRUE'       => $conf_nbc_UserAdvManager[0]=='true' ?  'checked="checked"' : '' ,
 		'UserAdvManager_MAIL_INFO_FALSE'      => $conf_nbc_UserAdvManager[0]=='false' ?  'checked="checked"' : '' ,
@@ -187,76 +184,74 @@
 		'UserAdvManager_MAILEXCLUSION_FALSE'  => $conf_nbc_UserAdvManager[12]=='false' ?  'checked="checked"' : '' ,
 		'UserAdvManager_MAILEXCLUSION_LIST'   => $conf_nbc_UserAdvManager[13],
-		)
-	);
-	
-
-	if ( isset($_POST['audit']) or isset($_POST['submit']) )
-	{
-		$msg_error1 = '';
-		
-		/* username insensible a la casse */
-		if (isset($conf_nbc_UserAdvManager[3]) and $conf_nbc_UserAdvManager[3] == 'true')
-		{
-			$query = "
-			  SELECT ".$conf['user_fields']['username']."
-			  FROM ".USERS_TABLE." p1
-			  WHERE EXISTS(
-			  SELECT ".$conf['user_fields']['username']."
-			  FROM ".USERS_TABLE." p2
-			  WHERE p1.".$conf['user_fields']['id']." <> p2.".$conf['user_fields']['id']."
-			  AND LOWER(p1.".$conf['user_fields']['username'].") = LOWER(p2.".$conf['user_fields']['username'].")
-			  )
-			  ;";
+    )
+  );
+	
+
+  if ( isset($_POST['audit']) or isset($_POST['submit']) )
+    {
+	  $msg_error1 = '';
+		
+/* username insensible a la casse */
+      if (isset($conf_nbc_UserAdvManager[3]) and $conf_nbc_UserAdvManager[3] == 'true')
+	    {
+		  $query = "
+		    SELECT ".$conf['user_fields']['username']."
+			FROM ".USERS_TABLE." p1
+			WHERE EXISTS(
+			SELECT ".$conf['user_fields']['username']."
+			FROM ".USERS_TABLE." p2
+			WHERE p1.".$conf['user_fields']['id']." <> p2.".$conf['user_fields']['id']."
+			AND LOWER(p1.".$conf['user_fields']['username'].") = LOWER(p2.".$conf['user_fields']['username'].")
+			)
+			;";
 			  
-			$result = pwg_query($query);
+		  $result = pwg_query($query);
 			
-			while($row = mysql_fetch_array($result))
-			{
-				$msg_error1 .= (($msg_error1 <> '') ? '<br/>' : '') . l10n('Err_audit_no_casse').$row['username'];
+		  while($row = mysql_fetch_array($result))
+		    {
+			  $msg_error1 .= (($msg_error1 <> '') ? '<br/>' : '') . l10n('Err_audit_no_casse').$row['username'];
 			}
 		}
 
-
-		$msg_error2 = '';
-		
-		/* Username without forbidden keys */
-		if ( isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' )
-		{
-			$query = "
-			  SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
-			  FROM ".USERS_TABLE."
-			  ;";
+      $msg_error2 = '';
+		
+/* Username without forbidden keys */
+      if ( isset($conf_nbc_UserAdvManager[7]) and $conf_nbc_UserAdvManager[7] == 'true' )
+	    {
+		  $query = "
+		    SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
+			FROM ".USERS_TABLE."
+			;";
 			  
-			$result = pwg_query($query);
+		  $result = pwg_query($query);
 			
-			while($row = mysql_fetch_array($result))
-			{
-				if ( !ValidateUsername($row['username']) )
-				$msg_error2 .= (($msg_error2 <> '') ? '<br/>' : '') . l10n('Err_audit_username_char').$row['username'];
+		  while($row = mysql_fetch_array($result))
+		    {
+			  if ( !ValidateUsername($row['username']) )
+			    $msg_error2 .= (($msg_error2 <> '') ? '<br/>' : '') . l10n('Err_audit_username_char').$row['username'];
 			}
 		}
 
-		
-		$msg_error3 = '';
-		
-		/* Email without forbidden domain */
-		if ( isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' )
-		{
-			$query = "
-			  SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
-			  FROM ".USERS_TABLE."
-			  ;";
+      $msg_error3 = '';
+		
+/* Email without forbidden domain */
+      if ( isset($conf_nbc_UserAdvManager[12]) and $conf_nbc_UserAdvManager[12] == 'true' )
+	    {
+		  $query = "
+		    SELECT ".$conf['user_fields']['username'].", ".$conf['user_fields']['email']."
+			FROM ".USERS_TABLE."
+			;";
 			  
-			$result = pwg_query($query);
+		  $result = pwg_query($query);
 			
-			while($row = mysql_fetch_array($result))
-			{
-				$conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
-				$conf_nbc_MailExclusion = split (",",$conf_nbc_UserAdvManager[13]);
-				for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
-				{
-					if (ereg($conf_nbc_MailExclusion[$i], $row['mail_address']))
-					{
-						$msg_error3 .=  (($msg_error3 <> '') ? '<br/>' : '') . l10n('Err_audit_email_forbidden').$row['username'].' ('.$row['mail_address'].')';
+		  while($row = mysql_fetch_array($result))
+		    {
+			  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
+			  $conf_nbc_MailExclusion = split (",",$conf_nbc_UserAdvManager[13]);
+			  for ($i = 0 ; $i < count($conf_nbc_MailExclusion) ; $i++)
+			    {
+				  if (ereg($conf_nbc_MailExclusion[$i], $row['mail_address']))
+				    {
+					  $msg_error3 .=  (($msg_error3 <> '') ? '<br/>' : '') . l10n('Err_audit_email_forbidden').$row['username'].' ('.$row['mail_address'].')';
 					}
 				}
@@ -264,18 +259,18 @@
 		}
 		
-		if ($msg_error1 <> '')
-		$errors[] = $msg_error1.'<br/><br/>';
-		
-		if ($msg_error2 <> '')
-		$errors[] = $msg_error2.'<br/><br/>';
-		
-		if ($msg_error3 <> '')
-		$errors[] = $msg_error3.'<br/><br/>';
-		
-		if ($msg_error1 <> '' or $msg_error2 <> '' or $msg_error3 <> '')
-			array_push($page['errors'], l10n('Err_audit_advise'));
-		else
-			array_push($page['infos'], l10n('UserAdvManager_audit_ok'));
-	}
+      if ($msg_error1 <> '')
+	    $errors[] = $msg_error1.'<br/><br/>';
+		
+      if ($msg_error2 <> '')
+	    $errors[] = $msg_error2.'<br/><br/>';
+		
+	  if ($msg_error3 <> '')
+	    $errors[] = $msg_error3.'<br/><br/>';
+		
+	  if ($msg_error1 <> '' or $msg_error2 <> '' or $msg_error3 <> '')
+	    array_push($page['errors'], l10n('Err_audit_advise'));
+	  else
+        array_push($page['infos'], l10n('UserAdvManager_audit_ok'));
+    }
 
 
@@ -283,10 +278,10 @@
 // |                             errors display                            |
 // +-----------------------------------------------------------------------+
-	if ( isset ($errors) and count($errors) != 0)
-	{
-		$template->assign('errors',array());
-		foreach ($errors as $error)
-		{
-			array_push($page['errors'], $error);
+  if ( isset ($errors) and count($errors) != 0)
+    {
+	  $template->assign('errors',array());
+	  foreach ($errors as $error)
+	    {
+		  array_push($page['errors'], $error);
 		}
 	}  
@@ -295,375 +290,391 @@
 // |                           templates display                           |
 // +-----------------------------------------------------------------------+
-	$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/global.tpl');
-	$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
-
-	break;
+  $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/global.tpl');
+  $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+  break;
 
 // +-----------------------------------------------------------------------+
 // |                           ConfirmMail Config                          |
 // +-----------------------------------------------------------------------+
-	case 'confirmmail':
-	
-	$conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
-	
-	if (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2]=='true' )
-	{
-		if ( isset($_POST['submit']) and !is_adviser() and isset($_POST['UserAdvManager_ConfirmMail_TimeOut']) )
-		{		
-			$newconf_nbc_UserAdvManager_ConfirmMail = $_POST['UserAdvManager_ConfirmMail_TimeOut'].';'.$_POST['UserAdvManager_ConfirmMail_Delay'];
-			
-			$conf['nbc_UserAdvManager_ConfirmMail'] = $newconf_nbc_UserAdvManager_ConfirmMail;
-		
-			$query = '
-		  	  UPDATE '.CONFIG_TABLE.'
-		  	  SET value="'.$newconf_nbc_UserAdvManager_ConfirmMail.'"
-		  	  WHERE param="nbc_UserAdvManager_ConfirmMail"
-		  	  LIMIT 1
-		  	  ;';
-		
-			pwg_query($query);
-		
-			array_push($page['infos'], l10n('UserAdvManager_save_config'));
+  case 'confirmmail':
+	
+  $conf_nbc_UserAdvManager = isset($conf['nbc_UserAdvManager']) ? explode(";" , $conf['nbc_UserAdvManager']) : array();
+	
+  if (isset($conf_nbc_UserAdvManager[2]) and $conf_nbc_UserAdvManager[2]=='true' )
+    {
+      if ( isset($_POST['submit']) and !is_adviser() and isset($_POST['UserAdvManager_ConfirmMail_TimeOut']) )
+	    {		
+		  $newconf_nbc_UserAdvManager_ConfirmMail = $_POST['UserAdvManager_ConfirmMail_TimeOut'].';'.$_POST['UserAdvManager_ConfirmMail_Delay'];
+	//TODO:Adding new option [Auto deletion : True | False]
+	//TODO:Adding new option [Resend_new_validation_key : True | False]
+		  $conf['nbc_UserAdvManager_ConfirmMail'] = $newconf_nbc_UserAdvManager_ConfirmMail;
+		
+		  $query = '
+		    UPDATE '.CONFIG_TABLE.'
+		  	SET value="'.$newconf_nbc_UserAdvManager_ConfirmMail.'"
+		  	WHERE param="nbc_UserAdvManager_ConfirmMail"
+		  	LIMIT 1
+		  	;';
+		
+		  pwg_query($query);
+		
+		  array_push($page['infos'], l10n('UserAdvManager_save_config'));
 		}
 	
-		$conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
-
-function get_unvalid_user_list()
-{
-  global $conf, $page;
+      $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();
+
+      function get_unvalid_user_list()
+        {
+          global $conf, $page;
   
-  $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();  
+          $conf_nbc_UserAdvManager_ConfirmMail = isset($conf['nbc_UserAdvManager_ConfirmMail']) ? explode(";" , $conf['nbc_UserAdvManager_ConfirmMail']) : array();  
   
-  $users = array();
-
-  // search users depending on filters and order
-  $query = '
-SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
-                u.'.$conf['user_fields']['username'].' AS username,
-                u.'.$conf['user_fields']['email'].' AS email,
-                ui.status,
-                ui.adviser,
-                ui.enabled_high,
-                ui.level,
-                ui.registration_date
-  FROM '.USERS_TABLE.' AS u
-    INNER JOIN '.USER_INFOS_TABLE.' AS ui
-      ON u.'.$conf['user_fields']['id'].' = ui.user_id
-    LEFT JOIN '.USER_GROUP_TABLE.' AS ug
-      ON u.'.$conf['user_fields']['id'].' = ug.user_id
-  WHERE u.'.$conf['user_fields']['id'].' > 0
-  AND TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) <= '.$conf_nbc_UserAdvManager_ConfirmMail[1].'
-  ORDER BY id ASC
-;';
-
-  $result = pwg_query($query);
-  while ($row = mysql_fetch_array($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'];
-  }
-  $user_nums = array_flip($user_ids);
-
-  if (count($user_ids) > 0)
-  {
-    $query = '
-SELECT user_id, group_id
-  FROM '.USER_GROUP_TABLE.'
-  WHERE user_id IN ('.implode(',', $user_ids).')
-;';
-    $result = pwg_query($query);
-    while ($row = mysql_fetch_array($result))
+          $users = array();
+    
+/* search users depending on filters and order */
+//TODO:Adding condition in request [if user in USER_CONFIRM_MAIL_TABLE]
+          $query = '
+            SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
+                            u.'.$conf['user_fields']['username'].' AS username,
+                            u.'.$conf['user_fields']['email'].' AS email,
+                            ui.status,
+                            ui.adviser,
+                            ui.enabled_high,
+                            ui.level,
+                            ui.registration_date
+            FROM '.USERS_TABLE.' AS u
+            INNER JOIN '.USER_INFOS_TABLE.' AS ui
+              ON u.'.$conf['user_fields']['id'].' = ui.user_id
+            LEFT JOIN '.USER_GROUP_TABLE.' AS ug
+              ON u.'.$conf['user_fields']['id'].' = ug.user_id
+            WHERE u.'.$conf['user_fields']['id'].' > 0
+            AND TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= '.$conf_nbc_UserAdvManager_ConfirmMail[1].'
+            ORDER BY id ASC
+          ;';
+
+          $result = pwg_query($query);
+      
+          while ($row = mysql_fetch_array($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'];
+            }
+          $user_nums = array_flip($user_ids);
+
+          if (count($user_ids) > 0)
+            {
+              $query = '
+                SELECT user_id, group_id
+                FROM '.USER_GROUP_TABLE.'
+                WHERE user_id IN ('.implode(',', $user_ids).')
+              ;';
+        
+              $result = pwg_query($query);
+        
+    		  while ($row = mysql_fetch_array($result))
+                {
+                  array_push(
+                    $users[$user_nums[$row['user_id']]]['groups'],
+                    $row['group_id']
+                  );
+                }
+              }
+
+          return $users;
+        }
+
+// +-----------------------------------------------------------------------+
+// |                           initialization                              |
+// +-----------------------------------------------------------------------+
+
+        if (!defined('PHPWG_ROOT_PATH'))
+          {
+            die('Hacking attempt!');
+          }
+          
+        include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+
+// +-----------------------------------------------------------------------+
+// | Check Access and exit when user status is not ok                      |
+// +-----------------------------------------------------------------------+
+        check_status(ACCESS_ADMINISTRATOR);
+
+        $page['order_by_items'] = array(
+          'id' => l10n('registration_date'),
+          'username' => l10n('Username'),
+          'level' => l10n('Privacy level'),
+          'language' => l10n('language'),
+        );
+
+// +-----------------------------------------------------------------------+
+// |                               user list                               |
+// +-----------------------------------------------------------------------+
+
+            $page['filtered_users'] = get_unvalid_user_list();
+
+// +-----------------------------------------------------------------------+
+// |                            selected users                             |
+// +-----------------------------------------------------------------------+
+//TODO:Link deletion to all users selected or single user
+        if (isset($_POST['delete']))
+          {
+            $collection = array();
+  
+            switch ($_POST['target'])
+              {
+                case 'all' :
+                  {
+                    foreach($page['filtered_users'] as $local_user)
+                      {
+                        array_push($collection, $local_user['id']);
+                      }
+                    break;
+                  }
+                case 'selection' :
+                  {
+                    if (isset($_POST['selection']))
+                      {
+                        $collection = $_POST['selection'];
+                      }
+                    break;
+                  }
+              }
+
+            if (count($collection) == 0)
+              {
+                array_push($page['errors'], l10n('Select at least one user'));
+              }
+          }
+
+// +-----------------------------------------------------------------------+
+// |                             delete users                              |
+// +-----------------------------------------------------------------------+
+        if (isset($_POST['delete']) and count($collection) > 0)
+          {
+            if (in_array($conf['guest_id'], $collection))
+              {
+                array_push($page['errors'], l10n('Guest cannot be deleted'));
+              }
+            if (($conf['guest_id'] != $conf['default_user_id']) and
+            in_array($conf['default_user_id'], $collection))
+              {
+                array_push($page['errors'], l10n('Default user cannot be deleted'));
+              }
+            if (in_array($conf['webmaster_id'], $collection))
+              {
+                array_push($page['errors'], l10n('Webmaster cannot be deleted'));
+              }
+            if (in_array($user['id'], $collection))
+              {
+                array_push($page['errors'], l10n('You cannot delete your account'));
+              }
+
+            if (count($page['errors']) == 0)
+              {
+                if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion'])
+                  {
+                    foreach ($collection as $user_id)
+                      {
+                        delete_user($user_id);
+                      }
+                    array_push(
+                    $page['infos'],
+                    l10n_dec(
+                      '%d user deleted', '%d users deleted',
+                      count($collection)
+                      )
+                    );
+
+                    foreach ($page['filtered_users'] as $filter_key => $filter_user)
+                      {
+                        if (in_array($filter_user['id'], $collection))
+                          {
+                            unset($page['filtered_users'][$filter_key]);
+                          }
+                      }
+                  }
+                else
+                  {
+                    array_push($page['errors'], l10n('You need to confirm deletion'));
+                  }
+               }
+          }
+// +-----------------------------------------------------------------------+
+// |                 Resend new validation key to users                    |
+// +-----------------------------------------------------------------------+
+
+//TODO:Function to send a new validation key to all | single | selected users
+
+// +-----------------------------------------------------------------------+
+// |                              groups list                              |
+// +-----------------------------------------------------------------------+
+
+          $groups[-1] = '------------';
+
+          $query = '
+            SELECT id, name
+            FROM '.GROUPS_TABLE.'
+            ORDER BY name ASC
+            ;';
+
+          $result = pwg_query($query);
+          
+          while ($row = mysql_fetch_array($result))
+            {
+              $groups[$row['id']] = $row['name'];
+            }
+
+// +-----------------------------------------------------------------------+
+// |                           Template Init                               |
+// +-----------------------------------------------------------------------+
+        $base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list';
+
+        if (isset($_GET['start']) and is_numeric($_GET['start']))
+          {
+            $start = $_GET['start'];
+          }
+        else
+          {
+            $start = 0;
+          }
+
+        $template->assign(
+          array(
+            'F_ADD_ACTION' => $base_url,
+            'F_USERNAME' => @htmlentities($_GET['username']),
+            'F_FILTER_ACTION' => get_root_url().'admin.php'
+            )
+    	  );
+
+/* Hide radio-button if not allow to assign adviser */
+        if ($conf['allow_adviser'])
+          {
+            $template->assign('adviser', true);
+          }
+	
+// +-----------------------------------------------------------------------+
+// |                               user list                               |
+// +-----------------------------------------------------------------------+
+
+        $profile_url = get_root_url().'admin.php?page=profile&amp;user_id=';
+        $perm_url = get_root_url().'admin.php?page=user_perm&amp;user_id=';
+
+        $visible_user_list = array();
+        foreach ($page['filtered_users'] as $num => $local_user)
+          {
+/* simulate LIMIT $start, $conf['users_page'] */
+            if ($num < $start)
+              {
+                continue;
+              }
+            if ($num >= $start + $conf['users_page'])
+              {
+                break;
+              }
+
+            $visible_user_list[] = $local_user;
+          }
+
+        foreach ($visible_user_list as $local_user)
+          {
+            $groups_string = preg_replace(
+              '/(\d+)/e',
+              "\$groups['$1']",
+              implode(
+                ', ',
+                $local_user['groups']
+              )
+            );
+
+            if (isset($_POST['pref_submit'])
+              and isset($_POST['selection'])
+              and in_array($local_user['id'], $_POST['selection']))
+              {
+                $checked = 'checked="checked"';
+              }
+            else
+              {
+                $checked = '';
+              }
+
+            $properties = array();
+            if ( $local_user['level'] != 0 )
+              {
+                $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
+              }
+            $properties[] =
+            (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
+              ? l10n('is_high_enabled') : l10n('is_high_disabled');
+              
+            if (isset($conf_nbc_UserAdvManager_ConfirmMail[1]) and $conf_nbc_UserAdvManager_ConfirmMail[0]=='true' )
+              {
+                $template->append(
+                  'users',
+                  array(
+                    'ID' => $local_user['id'],
+                    'CHECKED' => $checked,
+                    'U_PROFILE' => $profile_url.$local_user['id'],
+                    'U_PERM' => $perm_url.$local_user['id'],
+                    'USERNAME' => $local_user['username']
+                      .($local_user['id'] == $conf['guest_id']
+                        ? '<BR />['.l10n('is_the_guest').']' : '')
+                      .($local_user['id'] == $conf['default_user_id']
+                        ? '<BR />['.l10n('is_the_default').']' : ''),
+                    'STATUS' => l10n('user_status_'.
+                      $local_user['status']).(($local_user['adviser'] == 'true')
+                      ? '<BR />['.l10n('adviser').']' : ''),
+                    'EMAIL' => get_email_address_as_display_text($local_user['email']),
+                    'GROUPS' => $groups_string,
+                    //TODO:Changing ACTION from $properties to Single_Deletion
+                    //TODO:Addin new ACTION to Resend new validation key
+                    'ACTION' => implode( ', ', $properties),
+                  )
+                );
+              }
+          }		
+
+          $template->assign(
+    	    array(
+    		  'UserAdvManager_CONFIRMMAIL_TIMEOUT_TRUE'		=> $conf_nbc_UserAdvManager_ConfirmMail[0]=='true' ?  'checked="checked"' : '' ,
+    		  'UserAdvManager_CONFIRMMAIL_TIMEOUT_FALSE'	=> $conf_nbc_UserAdvManager_ConfirmMail[0]=='false' ?  'checked="checked"' : '' ,
+    		  'UserAdvManager_CONFIRMMAIL_DELAY'			=> $conf_nbc_UserAdvManager_ConfirmMail[1],
+    		  //TODO:Adding new option [Auto Deletion : True | False]
+    		  //TODO:Adding new option [Resend_new_validation_key : True | False]
+    	    )
+    	  );		
+
+// +-----------------------------------------------------------------------+
+// |                             errors display                            |
+// +-----------------------------------------------------------------------+
+          if ( isset ($errors) and count($errors) != 0)
+    	    {
+              $template->assign('errors',array());
+              foreach ($errors as $error)
+		        {
+		          array_push($page['errors'], $error);
+		        }
+	        }  
+
+// +-----------------------------------------------------------------------+
+// |                           templates display                           |
+// +-----------------------------------------------------------------------+
+      $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/confirmmail.tpl');
+      $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');		
+    }
+  else
     {
-      array_push(
-        $users[$user_nums[$row['user_id']]]['groups'],
-        $row['group_id']
-        );
+	  array_push($page['infos'], l10n('Err_ConfirmMail_Settings'));
     }
-  }
-
-  return $users;
+  break;
 }
-
-// +-----------------------------------------------------------------------+
-// |                           initialization                              |
-// +-----------------------------------------------------------------------+
-
-if (!defined('PHPWG_ROOT_PATH'))
-{
-  die('Hacking attempt!');
-}
-
-include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
-
-// +-----------------------------------------------------------------------+
-// | Check Access and exit when user status is not ok                      |
-// +-----------------------------------------------------------------------+
-check_status(ACCESS_ADMINISTRATOR);
-
-$page['order_by_items'] = array(
-  'id' => l10n('registration_date'),
-  'username' => l10n('Username'),
-  'level' => l10n('Privacy level'),
-  'language' => l10n('language'),
-  );
-
-// +-----------------------------------------------------------------------+
-// |                               user list                               |
-// +-----------------------------------------------------------------------+
-
-$page['filtered_users'] = get_unvalid_user_list();
-
-// +-----------------------------------------------------------------------+
-// |                            selected users                             |
-// +-----------------------------------------------------------------------+
-
-if (isset($_POST['delete']))
-{
-  $collection = array();
-
-  switch ($_POST['target'])
-  {
-    case 'all' :
-    {
-      foreach($page['filtered_users'] as $local_user)
-      {
-        array_push($collection, $local_user['id']);
-      }
-      break;
-    }
-    case 'selection' :
-    {
-      if (isset($_POST['selection']))
-      {
-        $collection = $_POST['selection'];
-      }
-      break;
-    }
-  }
-
-  if (count($collection) == 0)
-  {
-    array_push($page['errors'], l10n('Select at least one user'));
-  }
-}
-
-// +-----------------------------------------------------------------------+
-// |                             delete users                              |
-// +-----------------------------------------------------------------------+
-if (isset($_POST['delete']) and count($collection) > 0)
-{
-  if (in_array($conf['guest_id'], $collection))
-  {
-    array_push($page['errors'], l10n('Guest cannot be deleted'));
-  }
-  if (($conf['guest_id'] != $conf['default_user_id']) and
-      in_array($conf['default_user_id'], $collection))
-  {
-    array_push($page['errors'], l10n('Default user cannot be deleted'));
-  }
-  if (in_array($conf['webmaster_id'], $collection))
-  {
-    array_push($page['errors'], l10n('Webmaster cannot be deleted'));
-  }
-  if (in_array($user['id'], $collection))
-  {
-    array_push($page['errors'], l10n('You cannot delete your account'));
-  }
-
-  if (count($page['errors']) == 0)
-  {
-    if (isset($_POST['confirm_deletion']) and 1 == $_POST['confirm_deletion'])
-    {
-      foreach ($collection as $user_id)
-      {
-        delete_user($user_id);
-      }
-      array_push(
-        $page['infos'],
-        l10n_dec(
-          '%d user deleted', '%d users deleted',
-          count($collection)
-          )
-        );
-      foreach ($page['filtered_users'] as $filter_key => $filter_user)
-      {
-        if (in_array($filter_user['id'], $collection))
-        {
-          unset($page['filtered_users'][$filter_key]);
-        }
-      }
-    }
-    else
-    {
-      array_push($page['errors'], l10n('You need to confirm deletion'));
-    }
-  }
-}
-
-// +-----------------------------------------------------------------------+
-// |                              groups list                              |
-// +-----------------------------------------------------------------------+
-
-$groups[-1] = '------------';
-
-$query = '
-SELECT id, name
-  FROM '.GROUPS_TABLE.'
-  ORDER BY name ASC
-;';
-$result = pwg_query($query);
-
-while ($row = mysql_fetch_array($result))
-{
-  $groups[$row['id']] = $row['name'];
-}
-
-// +-----------------------------------------------------------------------+
-// |                           Template Init                               |
-// +-----------------------------------------------------------------------+
-$base_url = PHPWG_ROOT_PATH.'admin.php?page=user_list';
-
-if (isset($_GET['start']) and is_numeric($_GET['start']))
-{
-  $start = $_GET['start'];
-}
-else
-{
-  $start = 0;
-}
-
-$template->assign(
-  array(
-    'F_ADD_ACTION' => $base_url,
-    'F_USERNAME' => @htmlentities($_GET['username']),
-    'F_FILTER_ACTION' => get_root_url().'admin.php'
-    ));
-
-// Hide radio-button if not allow to assign adviser
-if ($conf['allow_adviser'])
-{
-  $template->assign('adviser', true);
-}
-
-	
-// +-----------------------------------------------------------------------+
-// |                               user list                               |
-// +-----------------------------------------------------------------------+
-
-$profile_url = get_root_url().'admin.php?page=profile&amp;user_id=';
-$perm_url = get_root_url().'admin.php?page=user_perm&amp;user_id=';
-
-$visible_user_list = array();
-foreach ($page['filtered_users'] as $num => $local_user)
-{
-  // simulate LIMIT $start, $conf['users_page']
-  if ($num < $start)
-  {
-    continue;
-  }
-  if ($num >= $start + $conf['users_page'])
-  {
-    break;
-  }
-
-  $visible_user_list[] = $local_user;
-}
-
-foreach ($visible_user_list as $local_user)
-{
-  $groups_string = preg_replace(
-    '/(\d+)/e',
-    "\$groups['$1']",
-    implode(
-      ', ',
-      $local_user['groups']
-      )
-    );
-
-  if (isset($_POST['pref_submit'])
-      and isset($_POST['selection'])
-      and in_array($local_user['id'], $_POST['selection']))
-  {
-    $checked = 'checked="checked"';
-  }
-  else
-  {
-    $checked = '';
-  }
-
-  $properties = array();
-  if ( $local_user['level'] != 0 )
-  {
-    $properties[] = l10n( sprintf('Level %d', $local_user['level']) );
-  }
-  $properties[] =
-    (isset($local_user['enabled_high']) and ($local_user['enabled_high'] == 'true'))
-        ? l10n('is_high_enabled') : l10n('is_high_disabled');
-
-  $template->append(
-    'users',
-    array(
-      'ID' => $local_user['id'],
-      'CHECKED' => $checked,
-      'U_PROFILE' => $profile_url.$local_user['id'],
-      'U_PERM' => $perm_url.$local_user['id'],
-      'USERNAME' => $local_user['username']
-        .($local_user['id'] == $conf['guest_id']
-          ? '<BR />['.l10n('is_the_guest').']' : '')
-        .($local_user['id'] == $conf['default_user_id']
-          ? '<BR />['.l10n('is_the_default').']' : ''),
-      'STATUS' => l10n('user_status_'.
-        $local_user['status']).(($local_user['adviser'] == 'true')
-        ? '<BR />['.l10n('adviser').']' : ''),
-      'EMAIL' => get_email_address_as_display_text($local_user['email']),
-      'GROUPS' => $groups_string,
-      'ACTION' => implode( ', ', $properties),
-      )
-    );
-}		
-
-	$template->assign(
-	array(
-		'UserAdvManager_CONFIRMMAIL_TIMEOUT_TRUE'       => $conf_nbc_UserAdvManager_ConfirmMail[0]=='true' ?  'checked="checked"' : '' ,
-		'UserAdvManager_CONFIRMMAIL_TIMEOUT_FALSE'      => $conf_nbc_UserAdvManager_ConfirmMail[0]=='false' ?  'checked="checked"' : '' ,
-		'UserAdvManager_CONFIRMMAIL_DELAY'   		    => $conf_nbc_UserAdvManager_ConfirmMail[1],
-		)
-	);		
-
-// +-----------------------------------------------------------------------+
-// |                             errors display                            |
-// +-----------------------------------------------------------------------+
-	if ( isset ($errors) and count($errors) != 0)
-	{
-		$template->assign('errors',array());
-		foreach ($errors as $error)
-		{
-			array_push($page['errors'], $error);
-		}
-	}  
-
-// +-----------------------------------------------------------------------+
-// |                           templates display                           |
-// +-----------------------------------------------------------------------+
-	$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/confirmmail.tpl');
-	$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');		
-	}
-	else
-	{
-		array_push($page['infos'], l10n('Err_ConfirmMail_Settings'));
-
-	}
-	break;
-
-}
-
 ?>
