2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/24/2009 *
4 * =================== Last change: 06/20/2010 *
6 * -------------------------------------------------------------------- *
7 * File : daily_birthday.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Sends out birthday mails on reset *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Versendet Geburtstagsmails beim Reset *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
41 } elseif ((!isHtmlOutputMode()) || (!isResetModeEnabled())) {
42 // Do not execute when script is in CSS mode
44 } elseif (!isExtensionActive('birthday')) {
45 // Extension not active/installed
46 logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.');
51 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset started.');
53 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
61 // Shall I include only active members?
62 if ((getConfig('birthday_active') == 'Y') && (isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
63 $add = ' AND (UNIX_TIMESTAMP() - `last_online`) < {?ap_inactive_since?}';
66 // Only confirmed members shall receive birthday mails...
67 $result_birthday = SQL_QUERY_ESC("SELECT
68 `userid`,`email`,`birth_year`
70 `{?_MYSQL_PREFIX?}_user_data`
72 `status`='CONFIRMED' AND
75 `birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
79 array($day, $month), __FILE__, __LINE__);
81 if (!SQL_HASZERONUMS($result_birthday)) {
82 // Start sending out birthday mails
83 while ($content = SQL_FETCHARRAY($result_birthday)) {
84 // Calculate own timestamp for birthday and today
85 $bd = $content['birth_year'] + 12 * $month + 365 * $day;
86 $now = $year + 12 * $month + 365 * $day;
88 // Simply subtract both values and you got the age... :)
91 if (getConfig('birthday_points') > 0) {
92 // Add more entries to the array
93 $content['age'] = $age;
94 $content['check'] = '';
96 // @TODO 4 is hard-coded here, should we move it out in config?
97 for ($idx = '0'; $idx < 4; $idx++) {
98 $content['check'] .= generateRandomCode('8', mt_rand(0, $month . $day), $content['userid'], ($age * ($idx + 1)));
101 // Insert row into database
102 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_birthday` (`userid`,`points`,`chk_value`) VALUES (%s,{?birthday_points?},'%s' )",
104 bigintval($content['userid']),
106 ), __FILE__, __LINE__);
108 // Load email template with confirmation link
109 $message = loadEmailTemplate('member_birthday_confirm', $content, bigintval($content['userid']));
111 // Load default email template and fill in the age
112 $message = loadEmailTemplate('member_birthday', $age, $content['userid']);
116 sendEmail($content['userid'], '{--MEMBER_HAPPY_BIRTHDAY_SUBJECT--}', $message);
118 // Remember him that he has received a birthday mail
119 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `birthday_sent`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
120 array(bigintval($content['userid'])), __FILE__, __LINE__);
124 SQL_FREERESULT($result_birthday);
128 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset ended.');