2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/14/2008 *
4 * =================== Last change: 09/14/2008 *
6 * -------------------------------------------------------------------- *
7 * File : purge-general.php *
8 * -------------------------------------------------------------------- *
9 * Short description : General autopurging, nothing extension-specific *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Allgemeine, nicht erweiterunsabhaengige Auto- *
13 * -------------------------------------------------------------------- *
16 * $Tag:: 0.2.1-FINAL $ *
18 * Needs to be in all Files and every File needs "svn propset *
19 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
20 * -------------------------------------------------------------------- *
21 * Copyright (c) 2003 - 2009 by Roland Haeder *
22 * Copyright (c) 2009, 2010 by Mailer Developer Team *
23 * For more information visit: http://www.mxchange.org *
25 * This program is free software; you can redistribute it and/or modify *
26 * it under the terms of the GNU General Public License as published by *
27 * the Free Software Foundation; either version 2 of the License, or *
28 * (at your option) any later version. *
30 * This program is distributed in the hope that it will be useful, *
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
33 * GNU General Public License for more details. *
35 * You should have received a copy of the GNU General Public License *
36 * along with this program; if not, write to the Free Software *
37 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
39 ************************************************************************/
41 // Some security stuff...
42 if (!defined('__SECURITY')) {
46 // Abort if autopurge is not active or disabled by admin
47 if ((!isExtensionActive('autopurge')) || (getConfig('auto_purge_active') != 'Y')) {
52 if ((getConfig('auto_purge_active') == 'Y') && (getConfig('auto_purge') > 0)) {
56 // First calculate the timestamp
57 $PURGE = getConfig('auto_purge');
62 // Then check for outdated mail order. We don't delete them just the confirmation links will be deleted.
63 $result = SQL_QUERY_ESC("SELECT
64 s.id, s.userid, s.pool_id, t.price
66 `{?_MYSQL_PREFIX?}_user_stats` AS s
68 `{?_MYSQL_PREFIX?}_payments` AS t
72 s.timestamp_ordered <= (UNIX_TIMESTAMP() - %s)
75 array(bigintval($PURGE)), __FILE__, __LINE__);
76 if (SQL_NUMROWS($result) > 0) {
77 // Start deleting procedure
78 $userid = '0'; $points = '0';
79 while ($content = SQL_FETCHARRAY($result)) {
80 // Check if confirmation links are purged or not
81 $result_links = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s LIMIT 1",
82 array(bigintval($content['id'])), __FILE__, __LINE__);
83 if (SQL_NUMROWS($result_links) == 1) {
85 SQL_FREERESULT($result_links);
87 // At least one link was found, enougth to pay back the points
88 if (($userid != $content['userid']) && ($userid > 0) && ($points > 0)) {
89 // Directly add points back to senders account
90 addPointsAutoPurge($userid, $points);
95 $userid = $content['userid']; $points += $content['price']; $admin_points += $content['price'];
97 // Remove confirmation links from queue
98 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
99 array(bigintval($content['id'])), __FILE__, __LINE__, false));
101 // Update status of order
102 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='DELETED' WHERE `id`=%s LIMIT 1",
103 array(bigintval($content['pool_id'])), __FILE__, __LINE__, false));
107 // Add last points to last user account
108 if ($points > 0) addPointsAutoPurge($userid, $points);
112 SQL_FREERESULT($result);
114 // Is the 'bonus' extension installed and activated?
115 if (isExtensionActive('bonus', true)) {
116 // Check for bonus campaigns
117 $result = SQL_QUERY_ESC("SELECT `id`, `points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `data_type`='SEND' AND `timestamp` <= %s ORDER BY `id` ASC",
118 array(bigintval($PURGE)), __FILE__, __LINE__);
119 if (SQL_NUMROWS($result) > 0) {
120 // Start deleting procedure
122 while ($content = SQL_FETCHARRAY($result)) {
123 // Check if confirmation links are purged or not
124 $result_links = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
125 array(bigintval($content['id'])), __FILE__, __LINE__);
126 if (SQL_NUMROWS($result_links) > 0) {
127 // At least one link was found, enougth to pay back the points
128 $points += $content['points'] * SQL_NUMROWS($result_links);
131 SQL_FREERESULT($result_links);
133 // Remove confirmation links from queue
134 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
135 array(bigintval($content['id'])), __FILE__, __LINE__, false));
137 // Update status of order
138 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='DELETED' WHERE `id`=%s LIMIT 1",
139 array(bigintval($content['id'])), __FILE__, __LINE__, false));
143 // Add points to jackpot
144 if (isExtensionActive('jackpot')) addPointsToJackpot($points);
146 // Add points for the admin
147 $admin_points += $points;
151 SQL_FREERESULT($result);
154 // Add points from deleted accounts to jackpot, but here just add to notify mail
155 if ($admin_points > 0) {
156 // Send mail to admin
157 sendAdminNotification(getMessage('AUTOPURGE_ADMIN_SUBJECT'), 'admin_autopurge_points', translateComma($admin_points));
161 runFilterChain('run_sqls');