]> git.mxchange.org Git - mailer.git/blob - inc/autopurge/purge-inact.php
A lot rewrites from double-quote to single-quote, some fixes for extension handling...
[mailer.git] / inc / autopurge / purge-inact.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/14/2008 *
4  * ===============                              Last change: 09/14/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : purge-inactive.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Purge of inactive users                          *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Auto-Loeschung von inaktiven Mitgliedern         *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 } // END - if
44
45 // Abort if autopurge is not active or disabled by admin
46 if ((!EXT_IS_ACTIVE('autopurge')) || (getConfig('auto_purge_active') != "Y")) {
47         // Abort here
48         return false;
49 } // END - if
50
51 // Shall I look for inactive accounts and autopurge inactive accounts?
52 if (getConfig('autopurge_inactive') == 'Y') {
53         // Init SQLs
54         INIT_SQLS();
55
56         // Ok, let's have a look...
57         $since = getConfig(('ap_inactive_since'));
58
59         // Init exclusion list
60         $EXCLUDE_LIST = '';
61         if (getConfig('def_refid') > 0) {
62                 $EXCLUDE_LIST = " AND d.userid != ".getConfig('def_refid');
63         } // END - if
64
65         // Check for more extensions
66         if (EXT_IS_ACTIVE('beg'))     $EXCLUDE_LIST .= " AND d.userid != ".getConfig('beg_uid')."";
67         if (EXT_IS_ACTIVE('bonus'))   $EXCLUDE_LIST .= " AND d.userid != ".getConfig('bonus_uid')."";
68         if (EXT_IS_ACTIVE('doubler')) $EXCLUDE_LIST .= " AND d.userid != ".getConfig('doubler_uid')."";
69
70         // Check for new holiday extension
71         if (GET_EXT_VERSION('holiday') >= '0.1.3') {
72                 // Include only users with no active holiday
73                 $EXCLUDE_LIST .= " AND d.holiday_active='N'";
74         } // END - if
75
76         // Check for all accounts
77         $result_inactive = SQL_QUERY_ESC("SELECT DISTINCT d.userid, d.email, d.last_online
78 FROM `{!_MYSQL_PREFIX!}_user_data` AS d
79 WHERE d.`status`='CONFIRMED' AND d.joined < (UNIX_TIMESTAMP() - %s) AND d.last_online < (UNIX_TIMESTAMP() - %s) AND d.ap_notified < (UNIX_TIMESTAMP() - %s)
80 ".$EXCLUDE_LIST."
81 ORDER BY d.userid", array($since, $since, $since), __FILE__, __LINE__);
82
83         if (SQL_NUMROWS($result_inactive) > 0) {
84                 // Prepare variables and constants...
85                 $UIDs = '';
86                 define('__INACTIVE_SINCE', (getConfig('ap_inactive_since') / 60 / 60));
87                 define('__INACTIVE_TIME' , (getConfig('ap_in_time')  / 60 / 60));
88
89                 // Mark found accounts as inactive and send an email
90                 while ($content = SQL_FETCHARRAY($result_inactive)) {
91                         // Remember userids for the admin
92                         $UIDs .= $content['userid'].", ";
93
94                         // Get date/time from timestamp
95                         $content['last_online'] = MAKE_DATETIME($content['last_online'], "0");
96
97                         // Load mail template
98                         $msg = LOAD_EMAIL_TEMPLATE("member_autopurge_inactive", $content['last_online'], bigintval($content['userid']));
99                         SEND_EMAIL($content['email'], getMessage('AUTOPURGE_MEMBER_INACTIVE_SUBJECT'), $msg);
100
101                         // Update this account
102                         ADD_SQL(SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET ap_notified=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
103                                 array(bigintval($content['userid'])), __FILE__, __LINE__, false));
104                 } // END - while
105
106                 // Remove last comma
107                 $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
108
109                 // Send mail notification to admin
110                 SEND_ADMIN_NOTIFICATION(getMessage('AUTOPURGE_ADMIN_INACTIVE_SUBJECT'), "admin_autopurge_inactive", $UIDs, '');
111         } // END - if
112
113         // Free memory
114         SQL_FREERESULT($result_inactive);
115
116         // Now let's have a look for inactive accounts we want to delete we newly use the same exclude list
117         // here for e.g. excluding holiday users
118         $time = getConfig(('ap_in_time'));
119         $result_inactive = SQL_QUERY_ESC("SELECT d.userid, d.email, d.last_online
120 FROM `{!_MYSQL_PREFIX!}_user_data` AS d
121 WHERE `status`='CONFIRMED' AND joined < (UNIX_TIMESTAMP() - %s) AND last_online < (UNIX_TIMESTAMP() - %s) AND ap_notified < (UNIX_TIMESTAMP() - %s)
122 ".$EXCLUDE_LIST."
123 ORDER BY userid",
124                 array($since, $since, $time), __FILE__, __LINE__);
125         if (SQL_NUMROWS($result_inactive) > 0) {
126                 // Prepare variable...
127                 $UIDs = '';
128
129                 // Delete inactive accounts
130                 while ($content = SQL_FETCHARRAY($result_inactive)) {
131                         // Remember userids for the admin
132                         $UIDs .= $content['userid'].", ";
133
134                         // Get date/time from timestamp
135                         $content['last_online'] = MAKE_DATETIME($content['last_online'], "0");
136
137                         // Finnaly delete this inactive account
138                         DELETE_USER_ACCOUNT($content['userid'], LOAD_EMAIL_TEMPLATE("member_autopurge_delete", $content['last_online'], ''));
139                 } // END - while
140
141                 // Remove last comma
142                 $UIDs = str_replace(", ", "\n", substr($UIDs, 0, -2));
143
144                 // Send mail notification to admin
145                 if (getConfig('ap_in_notify') == 'Y') {
146                         SEND_ADMIN_NOTIFICATION(getMessage('AUTOPURGE_ADMIN_DELETE_SUBJECT'), "admin_autopurge_delete", $UIDs, '');
147                 } // END - if
148         } // END - if
149
150         // Free memory
151         SQL_FREERESULT($result_inactive);
152
153         // Run all SQLs
154         runFilterChain('run_sqls');
155 } // END - if
156
157 //
158 ?>