Rewrites from to , fixes
[mailer.git] / inc / mails / bonus_mails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/22/2005 *
4  * ===============                              Last change: 11/22/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : bonus_mails.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Sends out reminder mails                         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Versendet Erinnerungsmails                       *
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 - 2009 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         die();
42 } elseif (!isExtensionActive('bonus')) {
43         return;
44 }
45
46 // Do not execute when script is in CSS mode
47 if (getOutputMode() != 0) return;
48
49 // Create timemark from saved month
50 $mark = mktime(0, 0, 0, getConfig('last_month'), date('d', time()), date('Y', time()));
51 $sql = ''; $mode = '';
52
53 // Shall I sent activation or deactivation mail?
54 $sql = "SELECT `userid`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE (`bonus_ral_notify` ";
55 switch (getConfig('bonus_active'))
56 {
57         case 'Y': // Active rallye is activated
58                 if (getConfig('bonus_en_notify') == 'Y') {
59                         // Okay, let's check for member accounts
60                         $sql .= "= 0 OR (`bonus_ral_notify` > 0 AND `bonus_ral_en_notify` < `bonus_ral_di_notify`)";
61                         $mode = 'en';
62                 } else {
63                         // Do not notify!
64                         $sql = '';
65                 }
66                 break;
67
68         case 'N': // Active rallye is deactivated
69                 if (getConfig('bonus_di_notify') == 'Y') {
70                         // Okay, let's check for member accounts
71                         $sql .= " > 0 AND `bonus_ral_di_notify` < `bonus_ral_en_notify`";
72                         $mode = 'di';
73                 } else {
74                         // Do not notify!
75                         $sql = '';
76                 }
77                 break;
78 }
79
80 if (!empty($sql)) {
81         // The SQL command needs to be finisched here (only confirmed accounts!)
82         $sql .= ") AND `status`='CONFIRMED' ORDER BY `last_online` ASC";
83
84         // Normal notification mails or bonus mails?
85         $sentBonusMails = ((getConfig('bonus_notify_points') > 0) && ($mode == "en") && (isExtensionActive('bonus')));
86
87         // Generate subject line
88         $subject = getMessage('BONUS_RALLYE_' . strtoupper($mode).'_NOTIFY');
89
90         // Load message body for bonus mails
91         $message = loadEmailTemplate('bonus_en_notify_body', '', '{PER}userid{PER}');
92         $RECEIVER = ''; $UIDs = array();
93
94         // Check for accounts to be notified
95         $result_main = SQL_QUERY($sql, __FILE__, __LINE__);
96         if (SQL_NUMROWS($result_main) > 0) {
97                 // Okay lets notify all users!
98                 while ($content = SQL_FETCHARRAY($result_main)) {
99                         // Update account
100                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data`
101 SET
102         `bonus_ral_notify`=UNIX_TIMESTAMP(),
103         `bonus_ral_%s_notify`=UNIX_TIMESTAMP()
104 WHERE
105         `userid`=%s
106 LIMIT 1",
107                                 array(
108                                         $mode,
109                                         $content['userid']
110                                 ), __FILE__, __LINE__);
111
112                         // Load email template and send it to the user!
113                         if ($sentBonusMails === true) {
114                                 // Add userid to queue
115                                 $UIDs[] = $content['userid'];
116                         } else {
117                                 // Send normal notification mail to the members
118                                 $message = loadEmailTemplate('bonus_' . $mode . '_notify', $content, $content['userid']);
119                                 sendEmail($content['email'], $subject, $message);
120                         }
121                 } // END - while
122
123                 // Shall I send out bonus mails?
124                 if ($sentBonusMails === true) {
125                         // Okay, make array to string
126                         $RECEIVER = implode(';', $UIDs);
127
128                         // Prepare URL
129                         $URL = 'modules.php?module=index&amp;what=login';
130
131                         // Insert mail
132                         addBonusMailToQueue($subject, $message, $RECEIVER, getConfig('bonus_notify_points'), getConfig('bonus_notify_wait'), $URL, 0, 'normal', SQL_NUMROWS($result_main));
133                 } // END - if
134         } // END - if
135
136         // Free memory
137         SQL_FREERESULT($result_main);
138 } // END - if
139
140 //
141 ?>