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") {
48 // Ok, let's have a look...
49 $since = bigintval(getConfig('ap_inactive_since'));
51 // Init exclusion list
53 if (getConfig('def_refid') > 0) {
54 $EXCLUDE_LIST = " AND d.userid != ".getConfig('def_refid');
57 // Check for more extensions
58 if (EXT_IS_ACTIVE("beg")) $EXCLUDE_LIST .= " AND d.userid != ".getConfig('beg_uid')."";
59 if (EXT_IS_ACTIVE("bonus")) $EXCLUDE_LIST .= " AND d.userid != ".getConfig('bonus_uid')."";
60 if (EXT_IS_ACTIVE("doubler")) $EXCLUDE_LIST .= " AND d.userid != ".getConfig('doubler_uid')."";
62 // Check for new holiday extension
63 if (GET_EXT_VERSION("holiday") >= "0.1.3") {
64 // Include only users with no active holiday
65 $EXCLUDE_LIST .= " AND d.holiday_active='N'";
68 // Check for all accounts
69 $result_inactive = SQL_QUERY_ESC("SELECT DISTINCT d.userid, d.email, d.last_online
70 FROM `{!_MYSQL_PREFIX!}_user_data` AS d
71 WHERE d.`status`='CONFIRMED' AND d.joined < (UNIX_TIMESTAMP() - %s) AND d.last_online < (UNIX_TIMESTAMP() - %s) AND d.ap_notified < (UNIX_TIMESTAMP() - %s)
73 ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
75 if (SQL_NUMROWS($result_inactive) > 0) {
76 // Prepare variables and constants...
78 define('__INACTIVE_SINCE', (getConfig('ap_inactive_since') / 60 / 60));
79 define('__INACTIVE_TIME' , (getConfig('ap_in_time') / 60 / 60));
81 // Mark found accounts as inactive and send an email
82 while (list($uid, $email, $last) = SQL_FETCHROW($result_inactive)) {
83 // Remember userids for the admin
86 // Get date/time from timestamp
87 $last = MAKE_DATETIME($last, "0");
90 $msg = LOAD_EMAIL_TEMPLATE("member_autopurge_inactive", $last, bigintval($uid));
91 SEND_EMAIL($email, AUTOPURGE_MEMBER_INACTIVE_SUBJECT, $msg);
93 // Update this account
94 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ap_notified=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
95 array(bigintval($uid)), __FILE__, __LINE__);
99 $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
101 // Send mail notification to admin
102 SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_INACTIVE_SUBJECT, "admin_autopurge_inactive", $UIDs, "");
106 SQL_FREERESULT($result_inactive);
108 // Now let's have a look for inactive accounts we want to delete we newly use the same exclude list
109 // here for e.g. excluding holiday users
110 $time = bigintval(getConfig('ap_in_time'));
111 $result_inactive = SQL_QUERY_ESC("SELECT d.userid, d.email, d.last_online
112 FROM `{!_MYSQL_PREFIX!}_user_data` AS d
113 WHERE `status`='CONFIRMED' AND joined < (UNIX_TIMESTAMP() - %s) AND last_online < (UNIX_TIMESTAMP() - %s) AND ap_notified < (UNIX_TIMESTAMP() - %s)
116 array($since, $since, $time), __FILE__, __LINE__);
117 if (SQL_NUMROWS($result_inactive) > 0) {
118 // Prepare variable...
121 // Delete inactive accounts
122 while (list($uid, $email, $last) = SQL_FETCHROW($result_inactive)) {
123 // Remember userids for the admin
126 // Get date/time from timestamp
127 $last = MAKE_DATETIME($last, "0");
129 // Finnaly delete this inactive account
130 DELETE_USER_ACCOUNT(bigintval($uid), LOAD_EMAIL_TEMPLATE("member_autopurge_delete", $last, ""));
134 $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
136 // Send mail notification to admin
137 if (getConfig('ap_in_notify') == "Y") {
138 SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_DELETE_SUBJECT, "admin_autopurge_delete", $UIDs, "");
143 SQL_FREERESULT($result_inactive);