2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/24/2009 *
4 * =================== Last change: 10/24/2009 *
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 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
42 } elseif (!isExtensionActive('birthday')) {
46 // Do not execute when script is in CSS mode
47 if ((getOutputMode() != 0) || (!isResetModeEnabled())) return;
48 //* DEBUG: */ outputHtml(basename(__FILE__)."<br />");
50 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
51 $day = date('d', time());
52 $month = date('m', time());
53 $year = date('Y', time());
55 // Shall I include only active members?
56 $add = "%s"; $value = '';
57 if ((getConfig('birthday_active')) && (isExtensionActive('autopurge')) && (getConfig('autopurge_inactive') == 'Y') && (getConfig('ap_inactive_since') > 0)) {
58 $add = " AND `last_online` >= (UNIX_TIMESTAMP() - %s)";
59 $value = getConfig('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() - ".(getConfig('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['points'] = translateComma(getConfig('birthday_points'));
90 $content['check'] = '';
92 // @TODO 4 is hard-coded here, should we move it out in config?
93 for ($idx = '0'; $idx < 4; $idx++) {
94 $content['check'] .= generateRandomCode('8', mt_rand(0, $month.$day), $content['userid'], ($age * ($idx + 1)));
97 // Insert row into database
98 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_birthday` (`userid`, `points`, `chk_value`) VALUES (%s,{?birthday_points?},'%s' )",
100 bigintval($content['userid']),
102 ), __FILE__, __LINE__);
104 // Load email template with confirmation link
105 $message = loadEmailTemplate('member_birthday_confirm', $content, bigintval($content['userid']));
107 // Load default email template and fill in the age
108 $message = loadEmailTemplate('member_birthday', $age, $content['userid']);
112 sendEmail($content['email'], getMessage('HAPPY_BIRTHDAY_SUBJECT'), $message);
114 // Remember him that he has received a birthday mail
115 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `birthday_sent`=UNIX_TIMESTAMP() WHERE `userid`=%s LIMIT 1",
116 array(bigintval($content['userid'])), __FILE__, __LINE__);
120 SQL_FREERESULT($result);