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")) || ($_CONFIG['auto_purge_active'] == "N")) {
46 // Shall I look for inactive accounts and autopurge inactive accounts?
47 if ($_CONFIG['autopurge_inactive'] == "Y") {
48 // Ok, let's have a look...
49 $since = bigintval($_CONFIG['ap_inactive_since']);
50 $EXCLUDE_LIST = " AND d.userid != ".$_CONFIG['def_refid'];
52 // Check for more extensions
53 if (EXT_IS_ACTIVE("beg")) $EXCLUDE_LIST .= " AND d.userid != c.beg_uid";
54 if (EXT_IS_ACTIVE("bonus")) $EXCLUDE_LIST .= " AND d.userid != c.bonus_uid";
55 if (EXT_IS_ACTIVE("doubler")) $EXCLUDE_LIST .= " AND d.userid != c.doubler_uid";
57 // Check for new holiday extension
58 if (GET_EXT_VERSION("holiday") >= "0.1.3") {
59 // Include only users with no active holiday
60 $EXCLUDE_LIST .= " AND d.holiday_active='N'";
63 // Check for all accounts
64 $result_inactive = SQL_QUERY_ESC("SELECT DISTINCT d.userid, d.email, d.last_online
65 FROM "._MYSQL_PREFIX."_user_data AS d
66 WHERE d.status='CONFIRMED' AND d.joined < (UNIX_TIMESTAMP() - %s) AND d.last_online < (UNIX_TIMESTAMP() - %s) AND d.ap_notified < (UNIX_TIMESTAMP() - %s)
68 ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
70 if (SQL_NUMROWS($result_inactive) > 0) {
71 // Prepare variables and constants...
73 define('__INACTIVE_SINCE', ($_CONFIG['ap_inactive_since'] / 60 / 60));
74 define('__INACTIVE_TIME' , ($_CONFIG['ap_in_time'] / 60 / 60));
76 // Mark found accounts as inactive and send an email
77 while(list($uid, $email, $last) = SQL_FETCHROW($result_inactive)) {
78 // Remember userids for the admin
81 // Get date/time from timestamp
82 $last = MAKE_DATETIME($last, "0");
85 $msg = LOAD_EMAIL_TEMPLATE("member_autopurge_inactive", $last, bigintval($uid));
86 SEND_EMAIL($email, AUTOPURGE_MEMBER_INACTIVE_SUBJECT, $msg);
88 // Update this account
89 $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET ap_notified=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
90 array(bigintval($uid)), __FILE__, __LINE__);
94 $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
96 // Send mail notification to admin
97 SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_INACTIVE_SUBJECT, "admin_autopurge_inactive", $UIDs, "");
101 SQL_FREERESULT($result_inactive);
103 // Now let's have a look for inactive accounts we want to delete we newly use the same exclude list
104 // here for e.g. excluding holiday users
105 $time = bigintval($_CONFIG['ap_in_time']);
106 $result_inactive = SQL_QUERY_ESC("SELECT d.userid, d.email, d.last_online
107 FROM "._MYSQL_PREFIX."_user_data AS d
108 WHERE status='CONFIRMED' AND joined < (UNIX_TIMESTAMP() - %s) AND last_online < (UNIX_TIMESTAMP() - %s) AND ap_notified < (UNIX_TIMESTAMP() - %s)
111 array($since, $since, $time), __FILE__, __LINE__);
112 if (SQL_NUMROWS($result_inactive) > 0) {
113 // Prepare variable...
116 // Delete inactive accounts
117 while (list($uid, $email, $last) = SQL_FETCHROW($result_inactive)) {
118 // Remember userids for the admin
121 // Get date/time from timestamp
122 $last = MAKE_DATETIME($last, "0");
124 // Finnaly delete this inactive account
125 DELETE_USER_ACCOUNT(bigintval($uid), LOAD_EMAIL_TEMPLATE("member_autopurge_delete", $last, ""));
129 $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
131 // Send mail notification to admin
132 if ($_CONFIG['ap_un_mail'] == "Y") {
133 SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_DELETE_SUBJECT, "admin_autopurge_delete", $UIDs, "");
138 SQL_FREERESULT($result_inactive);