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 * -------------------------------------------------------------------- *
13 * Copyright (c) 2003 - 2009 by Roland Haeder *
14 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
15 * For more information visit: http://mxchange.org *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
31 ************************************************************************/
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
36 } elseif ((!isHtmlOutputMode()) || (!isDailyResetEnabled())) {
37 // Do not execute when script is in non-HTML mode
39 } elseif (!isExtensionActive('birthday')) {
40 // Extension not active/installed
41 if (isDebugModeEnabled()) logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension ext-birthday disabled.');
46 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset started.');
48 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
57 // Shall I include only active members?
58 // @TODO Move this out to an extension
59 if ((getConfig('birthday_active') == 'Y') && (isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
60 $excludeSql = ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
63 // Only confirmed members shall receive birthday mails...
64 $result_birthday = sqlQueryEscaped("SELECT
69 `{?_MYSQL_PREFIX?}_user_data` AS `d`
71 `d`.`status`='CONFIRMED'
72 " . runFilterChain('user_exclusion_sql', ' ' . $excludeSql) . " AND
73 `d`.`birth_day`=%s AND
74 `d`.`birth_month`=%s AND
75 `d`.`birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
79 array($day, $month), __FILE__, __LINE__);
81 if (!ifSqlHasZeroNums($result_birthday)) {
82 // Start sending out birthday mails
83 while ($content = sqlFetchArray($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 (getBirthdayPoints() > 0) {
92 // Add more entries to the array
93 $content['age'] = $age;
94 $content['check'] = '';
96 // Generate long random code
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 sqlQueryEscaped("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', $content, $content['userid']);
116 sendEmail($content['userid'], '{--MEMBER_HAPPY_BIRTHDAY_SUBJECT--}', $message);
118 // Remember him that he has received a birthday mail
119 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `birthday_sent`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
120 array(bigintval($content['userid'])), __FILE__, __LINE__);
124 sqlFreeResult($result_birthday);
128 //* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'Daily reset ended.');