Fix for missing CSS variable
[mailer.git] / inc / mails / beg_mails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/22/2005 *
4  * ===============                              Last change: 11/22/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : beg_mails.php                                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Sends out reminder mails                         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Versendet Erinnerungsmails                       *
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("beg")) && (!IS_ADMIN())) {
39         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "beg");
40         return;
41 }
42
43 // Do not execute when script is in CSS mode
44 global $CSS;
45 if ($CSS == 1) return;
46
47 // Create timemark from saved month
48 $mark = mktime(0, 0, 0, $_CONFIG['last_month'], date("d", time()), date('Y', time()));
49 $SQL = ""; $MODE = "";
50
51 // Shall I sent activation or deactivation mail?
52 $SQL = "SELECT userid, email FROM "._MYSQL_PREFIX."_user_data WHERE (beg_ral_notify ";
53 switch ($_CONFIG['beg_rallye'])
54 {
55 case 'Y': // Begging rallye is activated
56         if ($_CONFIG['beg_ral_en_notify'] == "Y")
57         {
58                 // Okay, let's check for member accounts
59                 $SQL .= "= 0 OR (beg_ral_notify > 0 AND beg_ral_en_notify < beg_ral_di_notify)";
60                 $MODE = "en";
61         }
62          else
63         {
64                 // Do not notify!
65                 $SQL = "";
66         }
67         break;
68
69 case 'N': // Begging rallye is deactivated
70         if ($_CONFIG['beg_ral_di_notify'] == "Y")
71         {
72                 // Okay, let's check for member accounts
73                 $SQL .= " > 0 AND beg_ral_di_notify < beg_ral_en_notify";
74                 $MODE = "di";
75         }
76          else
77         {
78                 // Do not notify!
79                 $SQL = "";
80         }
81         break;
82 }
83
84 if (!empty($SQL))
85 {
86         // The SQL command needs to be finisched here (only confirmed accounts!)
87         $SQL .= ") AND status='CONFIRMED' ORDER BY last_online ASC";
88
89         // Prepare data for the template
90         define('__BEG_MIN_POINTS' , TRANSLATE_COMMA($_CONFIG['beg_points']));
91         define('__BEG_MAX_POINTS' , TRANSLATE_COMMA($_CONFIG['beg_points_max']));
92         define('__BEG_MAX_WINNERS', round($_CONFIG['beg_ranks']));
93         if ($_CONFIG['beg_ip_timeout'] == 0)
94         {
95                 // No IP locking setuped!
96                 define('__BEG_IP_LOCKER', BEG_NO_LIMITATION);
97         }
98          else
99         {
100                 // Create timemark
101                 define('__BEG_IP_LOCKER', CREATE_FANCY_TIME($_CONFIG['beg_ip_timeout']));
102         }
103
104         // Check for accounts to be notified
105         $result_main = SQL_QUERY($SQL, __FILE__, __LINE__);
106         if (SQL_NUMROWS($result_main) > 0)
107         {
108                 // Normal notification mails or bonus mails?
109                 $MAIL_MODE = (($_CONFIG['beg_notify_bonus'] > 0) && ($MODE == "en") && (EXT_IS_ACTIVE("bonus")));
110
111                 // Generate subject line
112                 $eval = "\$SUBJECT = BEG_RALLYE_".strtoupper($MODE)."_NOTIFY;";
113                 eval($eval);
114
115                 // Load message body for bonus mails
116                 $MSG = LOAD_EMAIL_TEMPLATE("beg_en_notify_body", "", "{PER}uid{PER}");
117                 $RECEIVER = ""; $UIDs = array();
118
119                 // Okay lets notify all users!
120                 while(list($uid, $email) = SQL_FETCHROW($result_main))
121                 {
122                         // Update account
123                         $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
124 SET beg_ral_notify='%s', beg_ral_%s_notify='%s' WHERE userid=%s LIMIT 1",
125  array(time(), $MODE, time(), $uid), __FILE__, __LINE__);
126
127                         // Load email template and send it to the user!
128                         if ($MAIL_MODE)
129                         {
130                                 // Add userid to queue
131                                 $UIDs[] = $uid;
132                         }
133                          else
134                         {
135                                 // Send normal notification mail to the members
136                                 $MSG = LOAD_EMAIL_TEMPLATE("beg_".$MODE."_notify", array(), $uid);
137                                 SEND_EMAIL($email, $SUBJECT, $MSG);
138                         }
139                 }
140
141                 // Shall I send out bonus mails?
142                 if ($MAIL_MODE)
143                 {
144                         // Okay, make array to string
145                         $RECEIVER = implode(";", $UIDs);
146                         $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus
147 (subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, is_notify)
148 VALUES ('%s','%s','%s','%s','%s','NEW', UNIX_TIMESTAMP(), '%s','%s','%s','%s','Y')",
149  array(
150         $SUBJECT,
151         $MSG,
152         $RECEIVER,
153         $_CONFIG['beg_notify_bonus'],
154         $_CONFIG['beg_notify_wait'],
155         URL."/modules.php?module=index&what=login",
156         0,
157         SELECTION_COUNT(explode(";", $RECEIVER)),
158         SQL_NUMROWS($result_main),
159 ), __FILE__, __LINE__);
160                 }
161         }
162
163         // Free memory
164         SQL_FREERESULT($result_main);
165 }
166
167 //
168 ?>