99f47d66a7125e04b1fda182fb1c005d9320a617
[mailer.git] / inc / mails / bonus_mails.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } elseif ((!isExtensionActive('bonus')) || (isExtensionInstalledAndOlder('bonus', '0.9.2'))) {
44         return;
45 }
46
47 // Do not execute when script is in CSS mode
48 if (getOutputMode() != 0) 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 (`bonus_rallye_notify` ";
56 switch (getConfig('bonus_active')) {
57         case 'Y': // Active rallye is activated
58                 if (getConfig('bonus_enable_notify') == 'Y') {
59                         // Okay, let's check for member accounts
60                         $sql .= '= 0 OR (`bonus_rallye_notify` > 0 AND `bonus_rallye_enable_notify` < `bonus_rallye_disable_notify`)';
61                         $mode = 'enable';
62                 } else {
63                         // Do not notify!
64                         $sql = '';
65                 }
66                 break;
67
68         case 'N': // Active rallye is deactivated
69                 if (getConfig('bonus_disable_notify') == 'Y') {
70                         // Okay, let's check for member accounts
71                         $sql .= ' > 0 AND `bonus_rallye_disable_notify` < `bonus_rallye_enable_notify`';
72                         $mode = 'disable';
73                 } else {
74                         // Do not notify!
75                         $sql = '';
76                 }
77                 break;
78 } // END - switch
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 == 'enable') && (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_enable_notify_body', '', '{PER}userid{PER}');
92         $receiver = ''; $userids = 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
101         `{?_MYSQL_PREFIX?}_user_data`
102 SET
103         `bonus_rallye_notify`=UNIX_TIMESTAMP(),
104         `bonus_rallye_%s_notify`=UNIX_TIMESTAMP()
105 WHERE
106         `userid`=%s
107 LIMIT 1",
108                                 array(
109                                         $mode,
110                                         $content['userid']
111                                 ), __FILE__, __LINE__);
112
113                         // Load email template and send it to the user!
114                         if ($sentBonusMails === true) {
115                                 // Add userid to queue
116                                 $userids[] = $content['userid'];
117                         } else {
118                                 // Send normal notification mail to the members
119                                 $message = loadEmailTemplate('bonus_' . $mode . '_notify', $content, $content['userid']);
120                                 sendEmail($content['email'], $subject, $message);
121                         }
122                 } // END - while
123
124                 // Shall I send out bonus mails?
125                 if ($sentBonusMails === true) {
126                         // Okay, make array to string
127                         $receiver = implode(';', $userids);
128
129                         // Prepare URL
130                         $url = 'modules.php?module=index&amp;what=login';
131
132                         // Insert mail
133                         addBonusMailToQueue($subject, $message, $receiver, getConfig('bonus_notify_points'), getConfig('bonus_notify_wait'), $url, 0, 'normal', SQL_NUMROWS($result_main));
134                 } // END - if
135         } // END - if
136
137         // Free memory
138         SQL_FREERESULT($result_main);
139 } // END - if
140
141 //
142 ?>