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 - 2012 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()) || (!isDailyResetEnabled())) {
42 // Do not execute when script is in non-HTML mode
44 } elseif (!isExtensionActive('birthday')) {
45 // Extension not active/installed
46 if (isDebugModeEnabled()) logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension ext-birthday 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)
62 // Shall I include only active members?
63 if ((getConfig('birthday_active') == 'Y') && (isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
64 $excludeSql = ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
67 // Is ext-holiday installed?
68 // @TODO Rewrite these if() blocks to a filter
69 if (isExtensionActive('holiday')) {
70 // Exclude those as well
71 $excludeSql .= " AND `d`.`holiday_active`='N'";
74 // Only confirmed members shall receive birthday mails...
75 $result_birthday = SQL_QUERY_ESC("SELECT
80 `{?_MYSQL_PREFIX?}_user_data` AS `d`
82 `d`.`status`='CONFIRMED'
83 " . runFilterChain('user_exclusion_sql', $excludeSql) . " AND
84 `d`.`birth_day`=%s AND
85 `d`.`birth_month`=%s AND
86 `d`.`birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
90 array($day, $month), __FILE__, __LINE__);
92 if (!SQL_HASZERONUMS($result_birthday)) {
93 // Start sending out birthday mails
94 while ($content = SQL_FETCHARRAY($result_birthday)) {
95 // Calculate own timestamp for birthday and today
96 $bd = $content['birth_year'] + 12 * $month + 365 * $day;
97 $now = $year + 12 * $month + 365 * $day;
99 // Simply subtract both values and you got the age... :)
102 if (getBirthdayPoints() > 0) {
103 // Add more entries to the array
104 $content['age'] = $age;
105 $content['check'] = '';
107 // @TODO 4 is hard-coded here, should we move it out in config?
108 for ($idx = 0; $idx < 4; $idx++) {
109 $content['check'] .= generateRandomCode('8', mt_rand(0, $month . $day), $content['userid'], ($age * ($idx + 1)));
112 // Insert row into database
113 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_birthday` (`userid`, `points`, `chk_value`) VALUES (%s,{?birthday_points?},'%s' )",
115 bigintval($content['userid']),
117 ), __FILE__, __LINE__);
119 // Load email template with confirmation link
120 $message = loadEmailTemplate('member_birthday_confirm', $content, bigintval($content['userid']));
122 // Load default email template and fill in the age
123 $message = loadEmailTemplate('member_birthday', $content, $content['userid']);
127 sendEmail($content['userid'], '{--MEMBER_HAPPY_BIRTHDAY_SUBJECT--}', $message);
129 // Remember him that he has received a birthday mail
130 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `birthday_sent`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
131 array(bigintval($content['userid'])), __FILE__, __LINE__);
135 SQL_FREERESULT($result_birthday);
139 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset ended.');