A lot double-quotes rewritten to single-quotes, some redirect URLs fixed
[mailer.git] / inc / mails / birthday_mails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 05/23/2004 *
4  * ===============                              Last change: 11/22/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : birthday_mails.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Sends out birthday mails                         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Versendet Geburtstagsmails                       *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif (!EXT_IS_ACTIVE('birthday')) {
44         return;
45 }
46
47 // Do not execute when script is in CSS mode
48 if (($GLOBALS['output_mode'] == 1) || (!isResetModeEnabled())) return;
49
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());
54
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');
60 }
61
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."
66 ORDER BY userid",
67  array($DAY, $MONTH, $VALUE), __FILE__, __LINE__);
68
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;
75
76                 // Simply subtract both values and you got the age... :)
77                 $AGE = $NOW - $BD;
78
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']  = '';
84
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)));
88                         }
89
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__);
93
94                         // Load email template with confirmation link
95                         $msg = LOAD_EMAIL_TEMPLATE("member_birthday_confirm", $content, bigintval($content['userid']));
96                 } else {
97                         // Load default email template and fill in the age
98                         $msg = LOAD_EMAIL_TEMPLATE("member_birthday", $AGE, $content['userid']);
99                 }
100
101                 // Send email
102                 SEND_EMAIL($content['email'], getMessage('HAPPY_BIRTHDAY'), $msg);
103
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__);
107         } // END - while
108
109         // Free memory
110         SQL_FREERESULT($result);
111 }
112
113 //
114 ?>