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