2 /************************************************************************
3 * MXChange v0.2.1 Start: 05/23/2004 *
4 * =============== Last change: 11/22/2005 *
6 * -------------------------------------------------------------------- *
7 * File : birthday_mails.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Sends out birthday mails *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Versendet Geburtstagsmails *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif (!EXT_IS_ACTIVE("birthday")) {
42 // Do not execute when script is in CSS mode
43 if (($GLOBALS['output_mode'] == 1) || (!isResetModeEnabled())) return;
45 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
46 $DAY = date("d", time());
47 $MONTH = date("m", time());
48 $YEAR = date('Y', time());
50 // Shall I include only active members?
51 $ADD = "%s"; $VALUE = "";
52 if ((getConfig('birthday_active')) && (EXT_IS_ACTIVE("autopurge")) && (getConfig('autopurge_inactive') == "Y") && (getConfig('ap_inactive_since') > 0)) {
53 $ADD = " AND last_online >= (UNIX_TIMESTAP() - %s)";
54 $VALUE = getConfig('ap_inactive_since');
57 // Only confirmed members shall receive birthday mails...
58 $result_birthday = SQL_QUERY_ESC("SELECT userid, email, birth_year
59 FROM `{!_MYSQL_PREFIX!}_user_data`
60 WHERE `status`='CONFIRMED' AND birth_day=%s AND birth_month=%s AND birthday_sent < (UNIX_TIMESTAMP() - ".(getConfig('one_day') * 364).")".$ADD."
62 array($DAY, $MONTH, $VALUE), __FILE__, __LINE__);
64 if (SQL_NUMROWS($result_birthday) > 0) {
65 // Start sending out birthday mails
66 while ($content = SQL_FETCHARRAY($result_birthday)) {
67 // Calculate own timestamp for birthday and today
68 $BD = $content['birth_year'] + 12 * $MONTH + 365 * $DAY;
69 $NOW = $YEAR + 12 * $MONTH + 365 * $DAY;
71 // Simply subtract both values and you got the age... :)
74 if (getConfig('birthday_points') > 0) {
75 // Add more entries to the array
76 $content['age'] = $AGE;
77 $content['points'] = TRANSLATE_COMMA(getConfig('birthday_points'));
78 $content['check'] = "";
80 // @TODO 4 is hard-coded here, should we move it out in config?
81 for ($idx = 0; $idx < 4; $idx++) {
82 $content['check'] .= generateRandomCodde("8", mt_rand(0, "$MONTH$DAY"), $content['userid'], ($AGE*($idx+1)));
85 // Insert row into database
86 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_birthday` (userid, points, chk_value) VALUES ('%s','%s','%s' )",
87 array(bigintval($content['userid']), getConfig('birthday_points'), $content['check']), __FILE__, __LINE__);
89 // Load email template with confirmation link
90 $msg = LOAD_EMAIL_TEMPLATE("member_birthday_confirm", $content, bigintval($content['userid']));
92 // Load default email template and fill in the age
93 $msg = LOAD_EMAIL_TEMPLATE("member_birthday", $AGE, $content['userid']);
97 SEND_EMAIL($content['email'], getMessage('HAPPY_BIRTHDAY'), $msg);
99 // Remember him that he has received a birthday mail
100 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET birthday_sent=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
101 array(bigintval($content['userid'])), __FILE__, __LINE__);
105 SQL_FREERESULT($result);