Security line in all includes changed
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif ((!EXT_IS_ACTIVE("birthday")) && (!IS_ADMIN())) {
39         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "birthday");
40         return;
41 }
42
43 // Do not execute when script is in CSS mode
44 if ($CSS == 1) return;
45
46 // Get current day (01 to 31), month (01 to 12) and year (4-digits year)
47 $DAY   = date("d", time());
48 $MONTH = date("m", time());
49 $YEAR  = date('Y', time());
50
51 // Shall I include only active members?
52 $ADD = "%s"; $VALUE = "";
53 if (($_CONFIG['birthday_active']) && (EXT_IS_ACTIVE("autopurge")) && ($_CONFIG['ap_in_since'] > 0) && ($_CONFIG['ap_inactive'] == "Y"))
54 {
55         $ADD = " AND last_online >= %d";
56         $VALUE = bigintval(time() - $_CONFIG['ap_in_since']);
57 }
58
59 // Only confirmed members shall receive birthday mails...
60 $result_birthday = SQL_QUERY_ESC("SELECT userid, email, birth_year
61 FROM "._MYSQL_PREFIX."_user_data
62 WHERE status='CONFIRMED' AND birth_day=%s AND birth_month=%s AND birthday_sent < ".(time() - (ONE_DAY*364)).$ADD."
63 ORDER BY userid",
64  array($DAY, $MONTH, $VALUE), __FILE__, __LINE__);
65
66 if (SQL_NUMROWS($result_birthday) > 0)
67 {
68         // Start sending out birthday mails
69         while (list($uid, $email, $byear) = SQL_FETCHROW($result_birthday))
70         {
71                 // Calculate own timestamp for birthday and today
72                 $BD  = $byear + 12*$MONTH + 365*$DAY;
73                 $NOW = $YEAR  + 12*$MONTH + 365*$DAY;
74
75                 // Simply subtract both values and you got the age... :)
76                 $AGE = $NOW - $BD;
77
78                 if ($_CONFIG['birthday_points'] > 0)
79                 {
80                         // Prepare array for loading template
81                         $content = array(
82                                 'age'    => $AGE,
83                                 'points' => $_CONFIG['birthday_points'],
84                                 'check'  => "",
85                         );
86                         for ($idx = 0; $idx < 4; $idx++)
87                         {
88                                 $content['check'] .= GEN_RANDOM_CODE("8", rand(0, "$MONTH$DAY"), $uid, ($AGE*($idx+1)));
89                         }
90
91                         // Insert row into database
92                         $result_insert = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_birthday (userid, points, chk_value) VALUES ('%s', '%s', '%s' )",
93                          array(bigintval($uid), $_CONFIG['birthday_points'], $content['check']), __FILE__, __LINE__);
94
95                         // Load email template with confirmation link
96                         $msg = LOAD_EMAIL_TEMPLATE("member_birthday_confirm", $content, bigintval($uid));
97                 }
98                  else
99                 {
100                         // Load default email template and fill in the age
101                         $msg = LOAD_EMAIL_TEMPLATE("member_birthday", $AGE, $uid);
102                 }
103
104                 // Send email
105                 SEND_EMAIL($email, HAPPY_BIRTHDAY, $msg);
106
107                 // Remember him that he has received a birthday mail
108                 $result_bd = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET birthday_sent=UNIX_TIMESTAMP() WHERE userid=%s LIMIT 1",
109                  array(bigintval($uid)), __FILE__, __LINE__);
110         }
111
112         // Free memory
113         SQL_FREERESULT($result);
114 }
115
116 //
117 ?>