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 * -------------------------------------------------------------------- *
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 - 2008 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')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
43 } elseif (!EXT_IS_ACTIVE("birthday")) {
47 // Do not execute when script is in CSS mode
48 if (($GLOBALS['output_mode'] == 1) || (!isResetModeEnabled())) return;
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')) && (EXT_IS_ACTIVE("autopurge")) && (getConfig('autopurge_inactive') == "Y") && (getConfig('ap_inactive_since') > 0)) {
58 $ADD = " AND last_online >= (UNIX_TIMESTAP() - %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
64 FROM `{!_MYSQL_PREFIX!}_user_data`
65 WHERE `status`='CONFIRMED' AND birth_day=%s AND birth_month=%s AND birthday_sent < (UNIX_TIMESTAMP() - ".(getConfig('one_day') * 364).")".$ADD."
67 array($DAY, $MONTH, $VALUE), __FILE__, __LINE__);
69 if (SQL_NUMROWS($result_birthday) > 0) {
70 // Start sending out birthday mails
71 while ($content = SQL_FETCHARRAY($result_birthday)) {
72 // Calculate own timestamp for birthday and today
73 $BD = $content['birth_year'] + 12 * $MONTH + 365 * $DAY;
74 $NOW = $YEAR + 12 * $MONTH + 365 * $DAY;
76 // Simply subtract both values and you got the age... :)
79 if (getConfig('birthday_points') > 0) {
80 // Add more entries to the array
81 $content['age'] = $AGE;
82 $content['points'] = TRANSLATE_COMMA(getConfig('birthday_points'));
83 $content['check'] = "";
85 // @TODO 4 is hard-coded here, should we move it out in config?
86 for ($idx = 0; $idx < 4; $idx++) {
87 $content['check'] .= generateRandomCodde("8", mt_rand(0, "$MONTH$DAY"), $content['userid'], ($AGE*($idx+1)));
90 // Insert row into database
91 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_birthday` (userid, points, chk_value) VALUES ('%s','%s','%s' )",
92 array(bigintval($content['userid']), getConfig('birthday_points'), $content['check']), __FILE__, __LINE__);
94 // Load email template with confirmation link
95 $msg = LOAD_EMAIL_TEMPLATE("member_birthday_confirm", $content, bigintval($content['userid']));
97 // Load default email template and fill in the age
98 $msg = LOAD_EMAIL_TEMPLATE("member_birthday", $AGE, $content['userid']);
102 SEND_EMAIL($content['email'], getMessage('HAPPY_BIRTHDAY'), $msg);
104 // Remember him that he has received a birthday mail
105 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET birthday_sent=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
106 array(bigintval($content['userid'])), __FILE__, __LINE__);
110 SQL_FREERESULT($result);