4fdda8ba0d6939334d5e05c4dc05546e176f07ca
[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  * $Revision::                                                        $ *
15  * $Date::                                                            $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author::                                                          $ *
18  * -------------------------------------------------------------------- *
19  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
20  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
21  * For more information visit: http://mxchange.org                      *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } elseif ((!isHtmlOutputMode()) || (!isResetModeEnabled())) {
43         // Do not execute when script is in non-HTML mode or no daily reset
44         return;
45 } elseif (!isExtensionActive('profile')) {
46         logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension ext-profile disabled.');
47         return;
48 }
49
50 // Debug line
51 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset started.');
52
53 if ((isSendProfileUpdateEnabled()) && (getProfileUpdate() > 0) && (getResendProfileUpdate() > 0)) {
54         // Load personal data
55         $result = SQL_QUERY("SELECT
56         `userid`,
57         `email`,
58         `last_update`,
59         `joined`
60 FROM
61         `{?_MYSQL_PREFIX?}_user_data`
62 WHERE
63         `status`='CONFIRMED'
64         " . runFilterChain('user_exclusion_sql', ' ') . " AND (
65                 (
66                         (UNIX_TIMESTAMP() - `last_update`) >= {?profile_update?} AND
67                         `last_update` > 0 AND
68                         (UNIX_TIMESTAMP() - `last_profile_sent`) >= {?resend_profile_update?}
69                 ) OR (
70                         `last_update` = 0 AND
71                         `last_profile_sent` = 0 AND
72                         (UNIX_TIMESTAMP() - `joined`) >= {?profile_update?}
73                 )
74         )
75 ORDER BY
76         `userid` ASC", __FILE__, __LINE__);
77
78         // Are there some notifications to sent?
79         if (!SQL_HASZERONUMS($result)) {
80                 // We need to send-out notifications...
81                 while ($content = SQL_FETCHARRAY($result)) {
82                         // Translate timestamp
83                         $content['joined'] = generateDateTime($content['joined'], '0');
84
85                         if (round($content['last_update']) == '0') {
86                                 // Has never changed his accont
87                                 $content['last_update'] = '{--MEMBER_PROFILE_NEVER_CHANGED--}';
88                         } else {
89                                 // Has changed his account
90                                 $content['last_update'] = generateDateTime($content['last_update'], '0');
91                         }
92
93                         // Load email template and send mail away
94                         $message = loadEmailTemplate('member_profile', $content, bigintval($content['userid']));
95                         sendEmail($content['userid'], '{--MEMBER_PROFILE_OUTDATED_SUBJECT--}', $message);
96
97                         // Update profile data
98                         SQL_QUERY_ESC("UPDATE
99         `{?_MYSQL_PREFIX?}_user_data`
100 SET
101         `last_profile_sent`=UNIX_TIMESTAMP(),
102         `notified`='Y'
103 WHERE
104         `userid`=%s
105 LIMIT 1",
106                                 array(bigintval($content['userid'])), __FILE__, __LINE__);
107                 } // END - while
108         } // END - if
109
110         // Free result
111         SQL_FREERESULT($result);
112 } // END - if
113
114 // Debug line
115 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset ended.');
116
117 // [EOF]
118 ?>