Re-added, now the right ones
[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  * $Revision:: 856                                                    $ *
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("beg")) {
44         return;
45 }
46
47 // Do not execute when script is in CSS mode
48 if ($GLOBALS['output_mode'] == 1) return;
49
50 // Create timemark from saved month
51 $mark = mktime(0, 0, 0, getConfig('last_month'), date("d", time()), date('Y', time()));
52 $sql = ""; $MODE = "";
53
54 // Shall I sent activation or deactivation mail?
55 $sql = "SELECT userid, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE (beg_ral_notify ";
56 switch (getConfig('beg_rallye'))
57 {
58 case "Y": // Begging rallye is activated
59         if (getConfig('beg_ral_en_notify') == "Y")
60         {
61                 // Okay, let's check for member accounts
62                 $sql .= "= 0 OR (beg_ral_notify > 0 AND beg_ral_en_notify < beg_ral_di_notify)";
63                 $MODE = "en";
64         }
65          else
66         {
67                 // Do not notify!
68                 $sql = "";
69         }
70         break;
71
72 case "N": // Begging rallye is deactivated
73         if (getConfig('beg_ral_di_notify') == "Y")
74         {
75                 // Okay, let's check for member accounts
76                 $sql .= " > 0 AND beg_ral_di_notify < beg_ral_en_notify";
77                 $MODE = "di";
78         }
79          else
80         {
81                 // Do not notify!
82                 $sql = "";
83         }
84         break;
85 }
86
87 if (!empty($sql)) {
88         // The SQL command needs to be finisched here (only confirmed accounts!)
89         $sql .= ") AND `status`='CONFIRMED' ORDER BY last_online ASC";
90
91         // Prepare data for the template
92         define('__BEG_MIN_POINTS' , TRANSLATE_COMMA(getConfig('beg_points')));
93         define('__BEG_MAX_POINTS' , TRANSLATE_COMMA(getConfig('beg_points_max')));
94         define('__BEG_MAX_WINNERS', round(getConfig('beg_ranks')));
95         if (getConfig('beg_ip_timeout') == 0)
96         {
97                 // No IP locking setuped!
98                 define('__BEG_IP_LOCKER', BEG_NO_LIMITATION);
99         }
100          else
101         {
102                 // Create timemark
103                 define('__BEG_IP_LOCKER', CREATE_FANCY_TIME(getConfig('beg_ip_timeout')));
104         }
105
106         // Check for accounts to be notified
107         $result_main = SQL_QUERY($sql, __FILE__, __LINE__);
108         if (SQL_NUMROWS($result_main) > 0) {
109                 // Normal notification mails or bonus mails?
110                 $sentBonusMails = ((getConfig('beg_notify_bonus') > 0) && ($MODE == "en") && (EXT_IS_ACTIVE("bonus")));
111
112                 // Generate subject line
113                 $SUBJECT = constant('BEG_RALLYE_'.strtoupper($MODE).'_NOTIFY');
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 ($content = SQL_FETCHARRAY($result_main)) {
121                         // Update account
122                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
123 SET beg_ral_notify='%s', beg_ral_%s_notify='%s'
124 WHERE userid=%s
125 LIMIT 1",
126                                 array(time(), $MODE, time(), $content['userid']), __FILE__, __LINE__);
127
128                         // Load email template and send it to the user!
129                         if ($sentBonusMails === true) {
130                                 // Add userid to queue
131                                 $UIDs[] = $content['userid'];
132                         } else {
133                                 // Send normal notification mail to the members
134                                 $MSG = LOAD_EMAIL_TEMPLATE("beg_".$MODE."_notify", array(), $content['userid']);
135                                 SEND_EMAIL($content['email'], $SUBJECT, $MSG);
136                         }
137                 } // END - while
138
139                 // Shall I send out bonus mails?
140                 if ($sentBonusMails === true) {
141                         // Okay, make array to string
142                         $RECEIVER = implode(";", $UIDs);
143
144                         // Prepare URL
145                         $URL = "modules.php?module=index&amp;what=login";
146
147                         // Insert mail
148                         ADD_BONUS_MAIL_TO_QUEUE($SUBJECT, $MSG, $RECEIVER, getConfig('beg_notify_bonus'), getConfig('beg_notify_wait'), $URL, 0, "normal", SQL_NUMROWS($result_main));
149                 } // END - if
150         } // END - if
151
152         // Free memory
153         SQL_FREERESULT($result_main);
154 } // END - if
155
156 //
157 ?>