Ignore:
Timestamp:
Feb 17, 2011, 6:16:36 PM (13 years ago)
Author:
Eric
Message:

bug 2055 fixed : New automated task for unvalidated registers (auto email reminder sent and auto deletion if already reminded).
Localisation files cleanup : all keys for "enable" and "disable" options have been replaced by one unic key.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/NBC_UserAdvManager/trunk/include/functions.inc.php

    r9253 r9266  
    328328  }
    329329
     330  // Performing User validation scheduled tasks
     331  if ((isset($conf_UAM[31]) and $conf_UAM[31] == 'true'))
     332  {
     333    UAM_USR_ScheduledTasks();
     334  }
     335
    330336  if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true'))
    331337  {
     
    401407        }
    402408
    403         // If never reminded before, set reminder True
    404         if ($reminder) // If user already reminded for ghost account
     409        // If user already reminded for ghost account
     410        if ($reminder)
    405411        {
    406412          // delete account
     
    410416          invalidate_user_cache();
    411417          logout_user();
    412           redirect(UAM_PATH.'del_account.php');
     418          redirect(UAM_PATH.'GT_del_account.php');
    413419        }
    414420        }
     
    523529  }
    524530}
     531
     532/**
     533 * Triggered on UAM_LoginTasks()
     534 *
     535 * Executes optional post-login tasks for unvalidated users
     536 *
     537 */
     538function UAM_USR_ScheduledTasks()
     539{
     540  global $conf, $user, $page;
     541
     542  if (!defined('PHPWG_ROOT_PATH'))
     543  {
     544    die('Hacking attempt!');
     545  }
     546         
     547  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     548
     549  $conf_UAM = unserialize($conf['UserAdvManager']);
     550 
     551  $collection = array();
     552  $reminder = false;
     553 
     554  $page['filtered_users'] = get_unvalid_user_autotasks();
     555
     556  foreach($page['filtered_users'] as $listed_user)
     557  {
     558    array_push($collection, $listed_user['id']);
     559  }
     560
     561  // Unvalidated accounts auto email sending and autodeletion if user already reminded
     562  if ((isset($conf_UAM[31]) and $conf_UAM[31] == 'true'))
     563  {
     564    if (count($collection) > 0)
     565        {
     566      // Process if a non-admin nor webmaster user is logged
     567      if (in_array($user['id'], $collection))
     568        {
     569        // Check ConfirmMail reminder state
     570        $query = '
     571SELECT reminder
     572FROM '.USER_CONFIRM_MAIL_TABLE.'
     573WHERE user_id = '.$user['id'].';';
     574
     575        $result = pwg_db_fetch_assoc(pwg_query($query));
     576
     577        if (isset($result['reminder']) and $result['reminder'] == 'true')
     578        {
     579          $reminder = true;
     580        }
     581        else
     582        {
     583          $reminder = false;
     584        }
     585
     586        // If never reminded before, send reminder and set reminder True
     587        if (!$reminder and isset($conf_UAM[33]) and $conf_UAM[33] == 'true')
     588        {
     589                  $typemail = 1;
     590         
     591          // Get current user informations
     592          $query = "
     593SELECT id, username, mail_address
     594FROM ".USERS_TABLE."
     595WHERE id = '".$user['id']."'
     596;";
     597          $data = pwg_db_fetch_assoc(pwg_query($query));
     598
     599          ResendMail2User($typemail,$user['id'],stripslashes($data['username']),$data['mail_address'],true);
     600        }
     601
     602        // If already reminded before, delete user
     603        if ($reminder)
     604        {
     605          // delete account
     606          delete_user($user['id']);
     607
     608          // Logged-in user cleanup, session destruction and redirected to custom page
     609          invalidate_user_cache();
     610          logout_user();
     611          redirect(UAM_PATH.'USR_del_account.php');
     612        }
     613        }
     614      else // Process if an admin or webmaster user is logged
     615      {
     616        foreach ($collection as $user_id)
     617        {
     618          // Check reminder state
     619          $query = '
     620SELECT reminder
     621FROM '.USER_CONFIRM_MAIL_TABLE.'
     622WHERE user_id = '.$user_id.';';
     623
     624          $result = pwg_db_fetch_assoc(pwg_query($query));
     625
     626          if (isset($result['reminder']) and $result['reminder'] == 'true')
     627          {
     628            $reminder = true;
     629          }
     630          else
     631          {
     632            $reminder = false;
     633          }
     634
     635          // If never reminded before, send reminder and set reminder True
     636          if (!$reminder and isset($conf_UAM[33]) and $conf_UAM[33] == 'true')
     637          {
     638            $typemail = 1;
     639         
     640            // Get current user informations
     641            $query = "
     642SELECT id, username, mail_address
     643FROM ".USERS_TABLE."
     644WHERE id = '".$user_id."'
     645;";
     646            $data = pwg_db_fetch_assoc(pwg_query($query));
     647
     648            ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],true);
     649          }
     650          elseif ($reminder) // If user already reminded for account validation
     651          {
     652            // delete account
     653            delete_user($user_id);
     654          }
     655        }
     656      }
     657    }
     658  }
     659}
     660
    525661
    526662/**
     
    14411577;";
    14421578    $data = pwg_db_fetch_assoc(pwg_query($query));
    1443        
    1444     //if (!empty($data) and isset($data['user_id']) and !isset($data['date_check']))
     1579
    14451580    if (!empty($data) and isset($data['user_id']))
    14461581    {
     
    14781613                                                $query = '
    14791614UPDATE '.USER_CONFIRM_MAIL_TABLE.'
    1480 SET date_check="'.$dbnow.'"
     1615SET date_check="'.$dbnow.'", reminder="false"
    14811616WHERE id = "'.$id.'"
    14821617;';
     
    18501985
    18511986/**
     1987 * Function called from functions.inc.php - Get all users who haven't validate their registration in configured time
     1988 * to delete or remail them automatically
     1989 *
     1990 * @return : List of users
     1991 *
     1992 */
     1993function get_unvalid_user_autotasks()
     1994{
     1995        global $conf, $page;
     1996         
     1997        // Get ConfirmMail configuration
     1998  $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']);
     1999 
     2000  $users = array();
     2001
     2002        // search users depending expiration date
     2003  $query = '
     2004SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
     2005                ui.registration_date
     2006FROM '.USERS_TABLE.' AS u
     2007  INNER JOIN '.USER_INFOS_TABLE.' AS ui
     2008    ON u.'.$conf['user_fields']['id'].' = ui.user_id
     2009WHERE u.'.$conf['user_fields']['id'].' >= 3
     2010  AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'")
     2011ORDER BY ui.registration_date ASC;';
     2012
     2013        $result = pwg_query($query);
     2014     
     2015  while ($row = pwg_db_fetch_assoc($result))
     2016  {
     2017    array_push($users, $row);
     2018        }
     2019
     2020        return $users;
     2021}
     2022
     2023/**
    18522024 * Function called from UAM_admin.php - Get ghost users
    18532025 *
     
    19252097  while ($row = pwg_db_fetch_assoc($result))
    19262098  {
    1927         $user = $row;
    1928     $user['groups'] = array();
    1929 
    1930     array_push($users, $user);
    1931         }
    1932 
    1933         // add group lists
    1934   $user_ids = array();
    1935   foreach ($users as $i => $user)
    1936   {
    1937         $user_ids[$i] = $user['id'];
     2099    array_push($users, $row);
    19382100        }
    19392101 
Note: See TracChangeset for help on using the changeset viewer.