2 /************************************************************************
3 * MXChange v0.2.1 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 * -------------------------------------------------------------------- *
15 * -------------------------------------------------------------------- *
16 * Copyright (c) 2003 - 2008 by Roland Haeder *
17 * For more information visit: http://www.mxchange.org *
19 * This program is free software; you can redistribute it and/or modify *
20 * it under the terms of the GNU General Public License as published by *
21 * the Free Software Foundation; either version 2 of the License, or *
22 * (at your option) any later version. *
24 * This program is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU General Public License for more details. *
29 * You should have received a copy of the GNU General Public License *
30 * along with this program; if not, write to the Free Software *
31 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
33 ************************************************************************/
35 // Some security stuff...
36 if (!defined('__SECURITY')) {
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
41 // Abort if autopurge is not active or disabled by admin
42 if ((!EXT_IS_ACTIVE("autopurge")) || (getConfig('auto_purge_active') != "Y")) {
47 if ((getConfig('auto_purge_active') == "Y") && (getConfig('auto_purge') > 0)) {
48 // First calculate the timestamp
49 $PURGE = getConfig('auto_purge');
54 // Then check for outdated mail order. We don't delete them just the confirmation links will be deleted.
55 $result = SQL_QUERY_ESC("SELECT s.id, s.userid, s.pool_id, t.price
56 FROM `{!_MYSQL_PREFIX!}_user_stats` AS s
57 LEFT JOIN `{!_MYSQL_PREFIX!}_payments` AS t
59 WHERE s.timestamp_ordered <= (UNIX_TIMESTAMP() - %s) ORDER BY s.userid",
60 array(bigintval($PURGE)), __FILE__, __LINE__);
61 if (SQL_NUMROWS($result) > 0) {
62 // Start deleting procedure
63 $uid = 0; $points = 0;
64 while (list($mid, $sender, $pool, $price) = SQL_FETCHROW($result)) {
65 // Check if confirmation links are purged or not
66 $result_links = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_links` WHERE stats_id=%s LIMIT 1",
67 array(bigintval($mid)), __FILE__, __LINE__);
68 if (SQL_NUMROWS($result_links) == 1) {
70 SQL_FREERESULT($result_links);
72 // At least one link was found, enougth to pay back the points
73 if (($uid != $sender) && ($uid > 0) && ($points > 0)) {
74 // Directly add points back to senders account
75 AUTOPURGE_ADD_POINTS($uid, $points);
80 $uid = $sender; $points += $price; $admin_points += $price;
82 // Remove confirmation links from queue
83 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE stats_id=%s",
84 array(bigintval($mid)), __FILE__, __LINE__);
86 // Update status of order
87 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_pool` SET data_type='DELETED' WHERE id=%s LIMIT 1",
88 array(bigintval($pool)), __FILE__, __LINE__);
92 // Add last points to last user account
93 if ($points > 0) AUTOPURGE_ADD_POINTS($uid, $points);
97 SQL_FREERESULT($result);
99 // Is the 'bonus' extension installed and activated?
100 if (EXT_IS_ACTIVE("bonus", true)) {
101 // Check for bonus campaigns
102 $result = SQL_QUERY_ESC("SELECT id, points FROM `{!_MYSQL_PREFIX!}_bonus` WHERE data_type='SEND' AND timestamp <= %s ORDER BY `id`",
103 array(bigintval($PURGE)), __FILE__, __LINE__);
104 if (SQL_NUMROWS($result) > 0) {
105 // Start deleting procedure
107 while (list($bid, $price) = SQL_FETCHROW($result)) {
108 // Check if confirmation links are purged or not
109 $result_links = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_links` WHERE bonus_id=%s",
110 array(bigintval($bid)), __FILE__, __LINE__);
111 if (SQL_NUMROWS($result_links) > 0) {
112 // At least one link was found, enougth to pay back the points
113 $points += $price * SQL_NUMROWS($result_links);
116 SQL_FREERESULT($result_links);
118 // Remove confirmation links from queue
119 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_links` WHERE bonus_id=%s",
120 array(bigintval($bid)), __FILE__, __LINE__);
122 // Update status of order
123 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_bonus` SET data_type='DELETED' WHERE id=%s LIMIT 1",
124 array(bigintval($bid)), __FILE__, __LINE__);
128 // Add points to jackpot
129 ADD_JACKPOT($points);
131 // Add points for the admin
132 $admin_points += $points;
136 SQL_FREERESULT($result);
139 // Add points from deleted accounts to jackpot, but here just add to notify mail
140 if ($admin_points > 0) {
141 // Send mail to admin
142 SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_SUBJECT, "admin_autopurge_points", TRANSLATE_COMMA($points), "0");