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")) || ($_CONFIG['auto_purge_active'] == "N")) {
47 if (($_CONFIG['auto_purge_active'] == "Y") && ($_CONFIG['auto_purge'] > 0)) {
48 // First calculate the timestamp
49 if (function_exists('CREATE_TIME_SELECTIONS')) {
50 $PURGE = $_CONFIG['auto_purge'];
52 $PURGE = $_CONFIG['auto_purge'] * 24 * 60 * 60;
58 // Then check for outdated mail order. We don't delete them just the confirmation links will be deleted.
59 $result = SQL_QUERY_ESC("SELECT s.id, s.userid, s.pool_id, t.price
60 FROM "._MYSQL_PREFIX."_user_stats AS s
61 LEFT JOIN "._MYSQL_PREFIX."_payments AS t
63 WHERE s.timestamp_ordered <= (UNIX_TIMESTAMP() - %s) ORDER BY s.userid",
64 array(bigintval($PURGE)), __FILE__, __LINE__);
65 if (SQL_NUMROWS($result) > 0) {
66 // Start deleting procedure
67 $uid = 0; $points = 0;
68 while(list($mid, $sender, $pool, $price) = SQL_FETCHROW($result)) {
69 // Check if confirmation links are purged or not
70 $result_links = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s LIMIT 1",
71 array(bigintval($mid)), __FILE__, __LINE__);
72 if (SQL_NUMROWS($result_links) == 1) {
74 SQL_FREERESULT($result_links);
76 // At least one link was found, enougth to pay back the points
77 if (($uid != $sender) && ($uid > 0) && ($points > 0)) {
78 // Directly add points back to senders account
79 AUTOPURGE_ADD_POINTS($uid, $points);
84 $uid = $sender; $points += $price; $admin_points += $price;
86 // Remove confirmation links from queue
87 $result_del = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE stats_id=%s",
88 array(bigintval($mid)), __FILE__, __LINE__);
90 // Update status of order
91 $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='DELETED' WHERE id=%s LIMIT 1",
92 array(bigintval($pool)), __FILE__, __LINE__);
96 // Add last points to last user account
97 if ($points > 0) AUTOPURGE_ADD_POINTS($uid, $points);
101 SQL_FREERESULT($result);
103 // Is the 'bonus' extension installed and activated?
104 if (EXT_IS_ACTIVE("bonus", true)) {
105 // Check for bonus campaigns
106 $result = SQL_QUERY_ESC("SELECT id, points FROM "._MYSQL_PREFIX."_bonus WHERE data_type='SEND' AND timestamp <= %s ORDER BY id",
107 array(bigintval($PURGE)), __FILE__, __LINE__);
108 if (SQL_NUMROWS($result) > 0) {
109 // Start deleting procedure
111 while (list($bid, $price) = SQL_FETCHROW($result)) {
112 // Check if confirmation links are purged or not
113 $result_links = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s",
114 array(bigintval($bid)), __FILE__, __LINE__);
115 if (SQL_NUMROWS($result_links) > 0) {
116 // At least one link was found, enougth to pay back the points
117 $points += $price * SQL_NUMROWS($result_links);
120 SQL_FREERESULT($result_links);
122 // Remove confirmation links from queue
123 $result_del = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_links WHERE bonus_id=%s",
124 array(bigintval($bid)), __FILE__, __LINE__);
126 // Update status of order
127 $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='DELETED' WHERE id=%s LIMIT 1",
128 array(bigintval($bid)), __FILE__, __LINE__);
132 // Add points to jackpot
133 ADD_JACKPOT($points);
135 // Add points for the admin
136 $admin_points += $points;
140 SQL_FREERESULT($result);
143 // Add points from deleted accounts to jackpot, but here just add to notify mail
144 if ($admin_points > 0) {
145 // Send mail to admin
146 SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_SUBJECT, "admin_autopurge_points", TRANSLATE_COMMA($points), "0");