2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/24/2009 *
4 * =================== Last change: 06/20/2010 *
6 * -------------------------------------------------------------------- *
7 * File : reset_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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
43 } elseif ((getScriptOutputMode() != 0) || (!isResetModeEnabled())) {
44 // Do not execute when script is in CSS mode
46 } elseif (!isExtensionActive('birthday')) {
47 logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.');
51 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
56 // Shall I include only active members?
57 $add = '%s'; $value = '';
58 if ((getConfig('birthday_active')) && (isExtensionActive('autopurge')) && (getConfig('autopurge_inactive') == 'Y') && (getApInactiveSince() > 0)) {
59 $add = " AND `last_online` >= (UNIX_TIMESTAMP() - {?ap_inactive_since?})";
62 // Only confirmed members shall receive birthday mails...
63 $result_birthday = SQL_QUERY_ESC("SELECT `userid`, `email`, `birth_year`
65 `{?_MYSQL_PREFIX?}_user_data`
67 `status`='CONFIRMED' AND
70 `birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
74 array($day, $month, $value), __FILE__, __LINE__);
76 if (SQL_NUMROWS($result_birthday) > 0) {
77 // Start sending out birthday mails
78 while ($content = SQL_FETCHARRAY($result_birthday)) {
79 // Calculate own timestamp for birthday and today
80 $bd = $content['birth_year'] + 12 * $month + 365 * $day;
81 $now = $year + 12 * $month + 365 * $day;
83 // Simply subtract both values and you got the age... :)
86 if (getConfig('birthday_points') > 0) {
87 // Add more entries to the array
88 $content['age'] = $age;
89 $content['check'] = '';
91 // @TODO 4 is hard-coded here, should we move it out in config?
92 for ($idx = '0'; $idx < 4; $idx++) {
93 $content['check'] .= generateRandomCode('8', mt_rand(0, $month.$day), $content['userid'], ($age * ($idx + 1)));
96 // Insert row into database
97 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_birthday` (`userid`, `points`, `chk_value`) VALUES (%s,{?birthday_points?},'%s' )",
99 bigintval($content['userid']),
101 ), __FILE__, __LINE__);
103 // Load email template with confirmation link
104 $message = loadEmailTemplate('member_birthday_confirm', $content, bigintval($content['userid']));
106 // Load default email template and fill in the age
107 $message = loadEmailTemplate('member_birthday', $age, $content['userid']);
111 sendEmail($content['email'], '{--HAPPY_BIRTHDAY_SUBJECT--}', $message);
113 // Remember him that he has received a birthday mail
114 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `birthday_sent`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
115 array(bigintval($content['userid'])), __FILE__, __LINE__);
119 SQL_FREERESULT($result_birthday);