2 /************************************************************************
3 * MXChange v0.2.1 Start: 05/29/2004 *
4 * =============== Last change: 11/26/2004 *
6 * -------------------------------------------------------------------- *
7 * File : autopurge.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Automatical purging of outdated mail links *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auto-Loeschung von veralteten Mail-Links *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Abort if autopurge is not active or disabled by admin
41 if ((!EXT_IS_ACTIVE("autopurge")) || ($_CONFIG['auto_purge_active'] == "N")) {
46 // Search for mails from deleted members?
47 if ($_CONFIG['ap_del_mails'] == "Y") {
48 // Okay, let's check for them...
49 $since = bigintval($_CONFIG['ap_dm_timeout']);
50 $result_mails = SQL_QUERY_ESC("SELECT sender\
51 FROM "._MYSQL_PREFIX."_pool
52 WHERE data_type='DELETED' AND timestamp <= (UNIX_TIMESTAMP() - %s)
54 array($since), __FILE__, __LINE__);
59 // Do we have "purged" mails?
60 if (SQL_NUMROWS($result_mails) > 0) {
61 // Okay, check for their sender's
62 while(list($sender) = SQL_FETCHROW($result_mails)) {
64 $fount = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
65 array(bigintval($sender)), __FILE__, __LINE__));
67 // Okay we found some mails!
68 $result_remove = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_pool WHERE sender=%s",
69 array(bigintval($sender)), __FILE__, __LINE__);
70 $DELETED += SQL_AFFECTEDROWS();
72 // Reset query (to prevent possible errors) ...
73 $since = bigintval($_CONFIG['ap_dm_timeout']);
74 $result_mails = SQL_QUERY_ESC("SELECT sender
75 FROM "._MYSQL_PREFIX."_pool
76 WHERE data_type='DELETED' AND timestamp <= (UNIX_TIMESTAMP() - %s)
78 array($since), __FILE__, __LINE__);
84 SQL_FREERESULT($result_mails);
86 // Now let's check for stats entries as well
87 $since = bigintval($_CONFIG['ap_dm_timeout']);
88 $result_mails = SQL_QUERY_ESC("SELECT sender
89 FROM "._MYSQL_PREFIX."_user_stats
90 WHERE data_type='DELETED' AND timestamp_send <= (UNIX_TIMESTAMP() - %s)
92 array($since), __FILE__, __LINE__);
94 // Do we have "purged" mails?
95 if (SQL_NUMROWS($result_mails) > 0) {
96 // Okay, check for their sender's
97 while(list($sender) = SQL_FETCHROW($result_mails)) {
99 $found = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", array(bigintval($sender)), __FILE__, __LINE__));
101 // Okay we found some mails!
102 $result_remove = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_stats WHERE sender=%s", array(bigintval($sender)), __FILE__, __LINE__);
103 $DELETED += SQL_AFFECTEDROWS();
105 // Reset query (to prevent possible errors) ...
106 $since = bigintval($_CONFIG['ap_dm_timeout']);
107 $result_mails = SQL_QUERY_ESC("SELECT sender
108 FROM "._MYSQL_PREFIX."_user_stats
109 WHERE data_type='DELETED' AND timestamp_send <= (UNIX_TIMESTAMP() - %s)
110 ORDER BY sender ASC",
111 array($since), __FILE__, __LINE__);
117 SQL_FREERESULT($result_mails);
119 // Do we have deleted mails and the admin want's to receive a notification
120 if (($DELETED > 0) && ($_CONFIG['ap_dm_notify'] == "Y")) {
121 // Send out email to admin
122 SEND_ADMIN_NOTIFICATION(AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT, "admin_autopurge_del_mails", $DELETED, "");