c68794916347a996153811fc6e620ed4a38e4c06
[mailer.git] / inc / daily / daily_profile.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/24/2009 *
4  * ===================                          Last change: 06/20/2010 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : daily_profile.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Sends out notifications to keep profiles updated *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Sendet Erinnerngen aus, damit die Profile        *
12  *                     von den Mitgliedern aktuell gehalten werden      *
13  * -------------------------------------------------------------------- *
14  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
15  * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
16  * For more information visit: http://mxchange.org                      *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         die();
37 } elseif ((!isHtmlOutputMode()) || (!isDailyResetEnabled())) {
38         // Do not execute when script is in non-HTML mode or no daily reset
39         return;
40 } elseif (!isExtensionActive('profile')) {
41         logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension ext-profile disabled.');
42         return;
43 }
44
45 // Debug line
46 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset started.');
47
48 if ((isSendProfileUpdateEnabled()) && (getProfileUpdate() > 0) && (getResendProfileUpdate() > 0)) {
49         // Load personal data
50         $result = sqlQuery("SELECT
51         `userid`,
52         `email`,
53         `last_update`,
54         `joined`
55 FROM
56         `{?_MYSQL_PREFIX?}_user_data`
57 WHERE
58         `status`='CONFIRMED'
59         " . runFilterChain('user_exclusion_sql', ' ') . " AND (
60                 (
61                         (UNIX_TIMESTAMP() - `last_update`) >= {?profile_update?} AND
62                         `last_update` > 0 AND
63                         (UNIX_TIMESTAMP() - `last_profile_sent`) >= {?resend_profile_update?}
64                 ) OR (
65                         `last_update` = 0 AND
66                         `last_profile_sent` = 0 AND
67                         (UNIX_TIMESTAMP() - `joined`) >= {?profile_update?}
68                 )
69         )
70 ORDER BY
71         `userid` ASC", __FILE__, __LINE__);
72
73         // Are there some notifications to sent?
74         if (!ifSqlHasZeroNumRows($result)) {
75                 // We need to send-out notifications...
76                 while ($content = sqlFetchArray($result)) {
77                         // Translate timestamp
78                         $content['joined'] = generateDateTime($content['joined'], '0');
79
80                         if (round($content['last_update']) == '0') {
81                                 // Has never changed his accont
82                                 $content['last_update'] = '{--MEMBER_PROFILE_NEVER_CHANGED--}';
83                         } else {
84                                 // Has changed his account
85                                 $content['last_update'] = generateDateTime($content['last_update'], '0');
86                         }
87
88                         // Load email template and send mail away
89                         $message = loadEmailTemplate('member_profile', $content, bigintval($content['userid']));
90                         sendEmail($content['userid'], '{--MEMBER_PROFILE_OUTDATED_SUBJECT--}', $message);
91
92                         // Update profile data
93                         sqlQueryEscaped("UPDATE
94         `{?_MYSQL_PREFIX?}_user_data`
95 SET
96         `last_profile_sent`=UNIX_TIMESTAMP(),
97         `notified`='Y'
98 WHERE
99         `userid`=%s
100 LIMIT 1",
101                                 array(bigintval($content['userid'])), __FILE__, __LINE__);
102                 } // END - while
103         } // END - if
104
105         // Free result
106         sqlFreeResult($result);
107 } // END - if
108
109 // Debug line
110 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset ended.');
111
112 // [EOF]
113 ?>