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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 elseif ((!EXT_IS_ACTIVE("birthday")) && (!IS_ADMIN()))
42 ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "birthday");
46 // Do not execute when script is in CSS mode
47 if ($CSS == 1) return;
49 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
50 $DAY = date("d", time());
51 $MONTH = date("m", time());
52 $YEAR = date("Y", time());
54 // Shall I include only active members?
55 $ADD = "%s"; $VALUE = "";
56 if (($CONFIG['birthday_active']) && (EXT_IS_ACTIVE("autopurge")) && ($CONFIG['ap_in_since'] > 0) && ($CONFIG['ap_inactive'] == "Y"))
58 $ADD = " AND last_online >= %d";
59 $VALUE = bigintval(time() - $CONFIG['ap_in_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=%d AND birth_month=%d AND birthday_sent < ".(time() - (ONE_DAY*364)).$ADD."
67 array($DAY, $MONTH, $VALUE), __FILE__, __LINE__);
69 if (SQL_NUMROWS($result_birthday) > 0)
71 // Start sending out birthday mails
72 while (list($uid, $email, $byear) = SQL_FETCHROW($result_birthday))
74 // Calculate own timestamp for birthday and today
75 $BD = $byear + 12*$MONTH + 365*$DAY;
76 $NOW = $YEAR + 12*$MONTH + 365*$DAY;
78 // Simply subtract both values and you got the age... :)
81 if ($CONFIG['birthday_points'] > 0)
83 // Prepare array for loading template
86 'points' => $CONFIG['birthday_points'],
89 for ($idx = 0; $idx < 4; $idx++)
91 $content['check'] .= GEN_RANDOM_CODE("8", rand(0, "$MONTH$DAY"), $uid, ($AGE*($idx+1)));
94 // Insert row into database
95 $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_birthday (userid, points, chk_value) VALUES ('%s', '%s', '%s' )",
96 array(bigintval($uid), $CONFIG['birthday_points'], $content['check']), __FILE__, __LINE__);
98 // Load email template with confirmation link
99 $msg = LOAD_EMAIL_TEMPLATE("member_birthday_confirm", $content, bigintval($uid));
103 // Load default email template and fill in the age
104 $msg = LOAD_EMAIL_TEMPLATE("member_birthday", $AGE, $uid);
108 SEND_EMAIL($email, HAPPY_BIRTHDAY, $msg);
110 // Remember him that he has received a birthday mail
111 $result_bd = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET birthday_sent=UNIX_TIMESTAMP() WHERE userid=%d LIMIT 1",
112 array(bigintval($uid)), __FILE__, __LINE__);
116 SQL_FREERESULT($result);