2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/14/2008 *
4 * =============== Last change: 09/14/2008 *
6 * -------------------------------------------------------------------- *
7 * File : purge-inactive.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Purge of inactive users *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auto-Loeschung von inaktiven Mitgliedern *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Abort if autopurge is not active or disabled by admin
41 if ((!EXT_IS_ACTIVE("autopurge")) || (getConfig('auto_purge_active') != "Y")) {
46 // Shall I look for inactive accounts and autopurge inactive accounts?
47 if (getConfig('autopurge_inactive') == "Y") {
51 // Ok, let's have a look...
52 $since = getConfig(('ap_inactive_since'));
54 // Init exclusion list
56 if (getConfig('def_refid') > 0) {
57 $EXCLUDE_LIST = " AND d.userid != ".getConfig('def_refid');
60 // Check for more extensions
61 if (EXT_IS_ACTIVE("beg")) $EXCLUDE_LIST .= " AND d.userid != ".getConfig('beg_uid')."";
62 if (EXT_IS_ACTIVE("bonus")) $EXCLUDE_LIST .= " AND d.userid != ".getConfig('bonus_uid')."";
63 if (EXT_IS_ACTIVE("doubler")) $EXCLUDE_LIST .= " AND d.userid != ".getConfig('doubler_uid')."";
65 // Check for new holiday extension
66 if (GET_EXT_VERSION("holiday") >= "0.1.3") {
67 // Include only users with no active holiday
68 $EXCLUDE_LIST .= " AND d.holiday_active='N'";
71 // Check for all accounts
72 $result_inactive = SQL_QUERY_ESC("SELECT DISTINCT d.userid, d.email, d.last_online
73 FROM `{!_MYSQL_PREFIX!}_user_data` AS d
74 WHERE d.`status`='CONFIRMED' AND d.joined < (UNIX_TIMESTAMP() - %s) AND d.last_online < (UNIX_TIMESTAMP() - %s) AND d.ap_notified < (UNIX_TIMESTAMP() - %s)
76 ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
78 if (SQL_NUMROWS($result_inactive) > 0) {
79 // Prepare variables and constants...
81 define('__INACTIVE_SINCE', (getConfig('ap_inactive_since') / 60 / 60));
82 define('__INACTIVE_TIME' , (getConfig('ap_in_time') / 60 / 60));
84 // Mark found accounts as inactive and send an email
85 while ($content = SQL_FETCHARRAY($result_inactive)) {
86 // Remember userids for the admin
87 $UIDs .= $content['userid'].", ";
89 // Get date/time from timestamp
90 $content['last_online'] = MAKE_DATETIME($content['last_online'], "0");
93 $msg = LOAD_EMAIL_TEMPLATE("member_autopurge_inactive", $content['last_online'], bigintval($content['userid']));
94 SEND_EMAIL($content['email'], getMessage('AUTOPURGE_MEMBER_INACTIVE_SUBJECT'), $msg);
96 // Update this account
97 ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ap_notified=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
98 array(bigintval($content['userid'])), __FILE__, __LINE__, false));
102 $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
104 // Send mail notification to admin
105 SEND_ADMIN_NOTIFICATION(getMessage('AUTOPURGE_ADMIN_INACTIVE_SUBJECT'), "admin_autopurge_inactive", $UIDs, "");
109 SQL_FREERESULT($result_inactive);
111 // Now let's have a look for inactive accounts we want to delete we newly use the same exclude list
112 // here for e.g. excluding holiday users
113 $time = getConfig(('ap_in_time'));
114 $result_inactive = SQL_QUERY_ESC("SELECT d.userid, d.email, d.last_online
115 FROM `{!_MYSQL_PREFIX!}_user_data` AS d
116 WHERE `status`='CONFIRMED' AND joined < (UNIX_TIMESTAMP() - %s) AND last_online < (UNIX_TIMESTAMP() - %s) AND ap_notified < (UNIX_TIMESTAMP() - %s)
119 array($since, $since, $time), __FILE__, __LINE__);
120 if (SQL_NUMROWS($result_inactive) > 0) {
121 // Prepare variable...
124 // Delete inactive accounts
125 while ($content = SQL_FETCHARRAY($result_inactive)) {
126 // Remember userids for the admin
127 $UIDs .= $content['userid'].", ";
129 // Get date/time from timestamp
130 $content['last_online'] = MAKE_DATETIME($content['last_online'], "0");
132 // Finnaly delete this inactive account
133 DELETE_USER_ACCOUNT($content['userid'], LOAD_EMAIL_TEMPLATE("member_autopurge_delete", $content['last_online'], ""));
137 $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
139 // Send mail notification to admin
140 if (getConfig('ap_in_notify') == "Y") {
141 SEND_ADMIN_NOTIFICATION(getMessage('AUTOPURGE_ADMIN_DELETE_SUBJECT'), "admin_autopurge_delete", $UIDs, "");
146 SQL_FREERESULT($result_inactive);
149 runFilterChain('run_sqls');