2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 05/23/2004 *
\r
4 * =============== Last change: 11/22/2005 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : birthday_mails.php *
\r
8 * -------------------------------------------------------------------- *
\r
9 * Short description : Sends out birthday mails *
\r
10 * -------------------------------------------------------------------- *
\r
11 * Kurzbeschreibung : Versendet Geburtstagsmails *
\r
12 * -------------------------------------------------------------------- *
\r
14 * -------------------------------------------------------------------- *
\r
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
\r
16 * For more information visit: http://www.mxchange.org *
\r
18 * This program is free software; you can redistribute it and/or modify *
\r
19 * it under the terms of the GNU General Public License as published by *
\r
20 * the Free Software Foundation; either version 2 of the License, or *
\r
21 * (at your option) any later version. *
\r
23 * This program is distributed in the hope that it will be useful, *
\r
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
26 * GNU General Public License for more details. *
\r
28 * You should have received a copy of the GNU General Public License *
\r
29 * along with this program; if not, write to the Free Software *
\r
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
\r
31 * MA 02110-1301 USA *
\r
32 ************************************************************************/
\r
34 // Some security stuff...
\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
\r
40 elseif ((!EXT_IS_ACTIVE("birthday")) && (!IS_ADMIN()))
\r
42 ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "birthday");
\r
46 // Do not execute when script is in CSS mode
\r
47 if ($CSS == 1) return;
\r
49 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
\r
50 $DAY = date("d", time());
\r
51 $MONTH = date("m", time());
\r
52 $YEAR = date("Y", time());
\r
54 // Shall I include only active members?
\r
55 $ADD = "%s"; $VALUE = "";
\r
56 if (($CONFIG['birthday_active']) && (EXT_IS_ACTIVE("autopurge")) && ($CONFIG['ap_in_since'] > 0) && ($CONFIG['ap_inactive'] == "Y"))
\r
58 $ADD = " AND last_online >= %d";
\r
59 $VALUE = bigintval(time() - $CONFIG['ap_in_since']);
\r
62 // Only confirmed members shall receive birthday mails...
\r
63 $result_birthday = SQL_QUERY_ESC("SELECT userid, email, birth_year
\r
64 FROM "._MYSQL_PREFIX."_user_data
\r
65 WHERE status='CONFIRMED' AND birth_day=%d AND birth_month=%d AND birthday_sent < ".(time() - (ONE_DAY*364)).$ADD."
\r
67 array($DAY, $MONTH, $VALUE), __FILE__, __LINE__);
\r
69 if (SQL_NUMROWS($result_birthday) > 0)
\r
71 // Start sending out birthday mails
\r
72 while (list($uid, $email, $byear) = SQL_FETCHROW($result_birthday))
\r
74 // Calculate own timestamp for birthday and today
\r
75 $BD = $byear + 12*$MONTH + 365*$DAY;
\r
76 $NOW = $YEAR + 12*$MONTH + 365*$DAY;
\r
78 // Simply subtract both values and you got the age... :)
\r
81 if ($CONFIG['birthday_points'] > 0)
\r
83 // Prepare array for loading template
\r
86 'points' => $CONFIG['birthday_points'],
\r
89 for ($idx = 0; $idx < 4; $idx++)
\r
91 $content['check'] .= GEN_RANDOM_CODE("8", rand(0, "$MONTH$DAY"), $uid, ($AGE*($idx+1)));
\r
94 // Insert row into database
\r
95 $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_birthday (userid, points, chk_value) VALUES ('%s', '%s', '%s' )",
\r
96 array(bigintval($uid), $CONFIG['birthday_points'], $content['check']), __FILE__, __LINE__);
\r
98 // Load email template with confirmation link
\r
99 $msg = LOAD_EMAIL_TEMPLATE("member_birthday_confirm", $content, bigintval($uid));
\r
103 // Load default email template and fill in the age
\r
104 $msg = LOAD_EMAIL_TEMPLATE("member_birthday", $AGE, $uid);
\r
108 SEND_EMAIL($email, HAPPY_BIRTHDAY, $msg);
\r
110 // Remember him that he has received a birthday mail
\r
111 $result_bd = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET birthday_sent=UNIX_TIMESTAMP() WHERE userid=%d LIMIT 1",
\r
112 array(bigintval($uid)), __FILE__, __LINE__);
\r
116 SQL_FREERESULT($result);
\r