]> git.mxchange.org Git - mailer.git/blob - inc/reset/reset_birthday.php
Added ability to allow empty passwords, if the user does so, a random password will...
[mailer.git] / inc / reset / reset_birthday.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/24/2009 *
4  * ===================                          Last change: 06/20/2010 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : reset_birthday.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Sends out birthday mails on reset                *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Versendet Geburtstagsmails beim Reset            *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } elseif ((!isHtmlOutputMode()) || (!isResetModeEnabled())) {
42         // Do not execute when script is in CSS mode
43         return;
44 } elseif (!isExtensionActive('birthday')) {
45         logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.');
46         return;
47 }
48
49 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
50 $day   = getDay();
51 $month = getMonth();
52 $year  = getYear();
53
54 // Shall I include only active members?
55 $add = '%s'; $value = '';
56 if ((getConfig('birthday_active')) && (isExtensionActive('autopurge')) && (getConfig('autopurge_inactive') == 'Y') && (getApInactiveSince() > 0)) {
57         $add = " AND `last_online` >= (UNIX_TIMESTAMP() - {?ap_inactive_since?})";
58 } // END - if
59
60 // Only confirmed members shall receive birthday mails...
61 $result_birthday = SQL_QUERY_ESC("SELECT `userid`, `email`, `birth_year`
62 FROM
63         `{?_MYSQL_PREFIX?}_user_data`
64 WHERE
65         `status`='CONFIRMED' AND
66         `birth_day`=%s AND
67         `birth_month`=%s AND
68         `birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
69         ".$add."
70 ORDER BY
71         `userid` ASC",
72         array($day, $month, $value), __FILE__, __LINE__);
73
74 if (!SQL_HASZERONUMS($result_birthday)) {
75         // Start sending out birthday mails
76         while ($content = SQL_FETCHARRAY($result_birthday)) {
77                 // Calculate own timestamp for birthday and today
78                 $bd  = $content['birth_year'] + 12 * $month + 365 * $day;
79                 $now = $year  + 12 * $month + 365 * $day;
80
81                 // Simply subtract both values and you got the age... :)
82                 $age = $now - $bd;
83
84                 if (getConfig('birthday_points') > 0) {
85                         // Add more entries to the array
86                         $content['age']    = $age;
87                         $content['check']  = '';
88
89                         // @TODO 4 is hard-coded here, should we move it out in config?
90                         for ($idx = '0'; $idx < 4; $idx++) {
91                                 $content['check'] .= generateRandomCode('8', mt_rand(0, $month.$day), $content['userid'], ($age * ($idx + 1)));
92                         } // END - for
93
94                         // Insert row into database
95                         SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_birthday` (`userid`, `points`, `chk_value`) VALUES (%s,{?birthday_points?},'%s' )",
96                                 array(
97                                         bigintval($content['userid']),
98                                         $content['check']
99                                 ), __FILE__, __LINE__);
100
101                         // Load email template with confirmation link
102                         $message = loadEmailTemplate('member_birthday_confirm', $content, bigintval($content['userid']));
103                 } else {
104                         // Load default email template and fill in the age
105                         $message = loadEmailTemplate('member_birthday', $age, $content['userid']);
106                 }
107
108                 // Send email
109                 sendEmail($content['email'], '{--MEMBER_HAPPY_BIRTHDAY_SUBJECT--}', $message);
110
111                 // Remember him that he has received a birthday mail
112                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `birthday_sent`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
113                         array(bigintval($content['userid'])), __FILE__, __LINE__);
114         } // END - while
115
116         // Free memory
117         SQL_FREERESULT($result_birthday);
118 } // END - if
119
120 // [EOF]
121 ?>