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 * -------------------------------------------------------------------- *
19 * Copyright (c) 2003 - 2009 by Roland Haeder *
20 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
21 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
42 } elseif ((!isExtensionActive('autopurge')) || (!isAutoPurgingActive())) {
47 if (getAutoPurge() > 0) {
54 // Then check for outdated mail order. We don't delete them just the confirmation links will be deleted.
55 $result = SQL_QUERY('SELECT
56 s.id, s.userid, s.pool_id, t.price
58 `{?_MYSQL_PREFIX?}_user_stats` AS s
60 `{?_MYSQL_PREFIX?}_payments` AS t
64 (UNIX_TIMESTAMP() - s.`timestamp_ordered`) >= {?auto_purge?}
66 s.userid ASC', __FILE__, __LINE__);
67 if (!SQL_HASZERONUMS($result)) {
68 // Start deleting procedure
71 while ($content = SQL_FETCHARRAY($result)) {
72 // Check if confirmation links are purged or not
73 $result_links = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s LIMIT 1",
74 array(bigintval($content['id'])), __FILE__, __LINE__);
75 if (SQL_NUMROWS($result_links) == 1) {
77 SQL_FREERESULT($result_links);
79 // At least one link was found, enougth to pay back the points
80 if (($userid != $content['userid']) && (isValidUserId($userid)) && ($points > 0)) {
81 // Directly add points back to senders account
82 addPointsAutoPurge($userid, $points);
87 $userid = $content['userid']; $points += $content['price']; $admin_points += $content['price'];
89 // Remove confirmation links from queue
90 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `stats_id`=%s",
91 array(bigintval($content['id'])), __FILE__, __LINE__, false));
93 // Update status of order
94 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='DELETED' WHERE `id`=%s LIMIT 1",
95 array(bigintval($content['pool_id'])), __FILE__, __LINE__, false));
99 // Add last points to last user account
100 if ($points > 0) addPointsAutoPurge($userid, $points);
104 SQL_FREERESULT($result);
106 // Is the 'bonus' extension installed and activated?
107 if (isExtensionActive('bonus', true)) {
108 // Check for bonus campaigns
109 $result = SQL_QUERY("SELECT `id`,`points` FROM `{?_MYSQL_PREFIX?}_bonus` WHERE `data_type`='SEND' AND `timestamp` <= {?auto_purge?} ORDER BY `id` ASC", __FILE__, __LINE__);
110 if (!SQL_HASZERONUMS($result)) {
111 // Start deleting procedure
113 while ($content = SQL_FETCHARRAY($result)) {
114 // Check if confirmation links are purged or not
115 $result_links = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
116 array(bigintval($content['id'])), __FILE__, __LINE__);
117 if (!SQL_HASZERONUMS($result_links)) {
118 // At least one link was found, enougth to pay back the points
119 $points += $content['points'] * SQL_NUMROWS($result_links);
122 SQL_FREERESULT($result_links);
124 // Remove confirmation links from queue
125 addSql(SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `bonus_id`=%s",
126 array(bigintval($content['id'])), __FILE__, __LINE__, false));
128 // Update status of order
129 addSql(SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='DELETED' WHERE `id`=%s LIMIT 1",
130 array(bigintval($content['id'])), __FILE__, __LINE__, false));
134 // Add points to jackpot
135 if (isExtensionActive('jackpot')) addPointsToJackpot($points);
137 // Add points for the admin
138 $admin_points += $points;
142 SQL_FREERESULT($result);
145 // Add points from deleted accounts to jackpot, but here just add to notify mail
146 if ($admin_points > 0) {
147 // Send mail to admin
148 sendAdminNotification('{--ADMIN_AUTOPURGE_SUBJECT--}', 'admin_autopurge_points', $admin_points);
152 runFilterChain('run_sqls');