Mailer project continued:
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } elseif ((!isExtensionActive('bonus')) || (isExtensionInstalledAndOlder('bonus', '0.9.2'))) {
42         // Do not execute script on missing/out-dated extension ext-bonus
43         return;
44 } elseif (!isHtmlOutputMode()) {
45         // Do not execute script if not in HTML mode
46         return;
47 }
48
49 // Create timemark from saved month
50 $mark = mktime(0, 0, 0, getLastMonth(), getDay(), getYear());
51 $sql = ''; $mode = '';
52
53 // Shall I sent activation or deactivation mail?
54 $sql = "SELECT `userid`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE (`bonus_rallye_enable_notify` ";
55 switch (getConfig('bonus_active')) {
56         case 'Y': // Active rallye is activated
57                 if (getConfig('bonus_enable_notify') == 'Y') {
58                         // Okay, let's check for member accounts
59                         $sql .= '= 0 OR (`bonus_rallye_enable_notify` > 0 AND `bonus_rallye_enable_notify` < `bonus_rallye_disable_notify`)';
60                         $mode = 'enable';
61                 } else {
62                         // Do not notify!
63                         $sql = '';
64                 }
65                 break;
66
67         case 'N': // Active rallye is deactivated
68                 if (getConfig('bonus_disable_notify') == 'Y') {
69                         // Okay, let's check for member accounts
70                         $sql .= ' > 0 AND `bonus_rallye_disable_notify` < `bonus_rallye_enable_notify`';
71                         $mode = 'disable';
72                 } else {
73                         // Do not notify!
74                         $sql = '';
75                 }
76                 break;
77 } // END - switch
78
79 if (!empty($sql)) {
80         // The SQL command needs to be finisched here (only confirmed accounts!)
81         $sql .= ')' . runFilterChain('user_exclusion_sql', " AND `status`='CONFIRMED'") . ' ORDER BY `last_online` ASC';
82
83         // Normal notification mails or bonus mails?
84         $sentBonusMails = ((getConfig('bonus_notify_points') > 0) && ($mode == 'enable') && (isExtensionActive('bonus')));
85
86         // Load message body for bonus mails
87         $message = loadEmailTemplate('bonus_enable_notify_body', '', '{PER}userid{PER}');
88         $receiver = ''; $userids = array();
89
90         // Check for accounts to be notified
91         $result_main = SQL_QUERY($sql, __FILE__, __LINE__);
92         if (!SQL_HASZERONUMS($result_main)) {
93                 // Okay lets notify all users!
94                 while ($content = SQL_FETCHARRAY($result_main)) {
95                         // Update account
96                         SQL_QUERY_ESC("UPDATE
97         `{?_MYSQL_PREFIX?}_user_data`
98 SET
99         `bonus_rallye_%s_notify`=UNIX_TIMESTAMP()
100 WHERE
101         `userid`=%s
102 LIMIT 1",
103                                 array(
104                                         $mode,
105                                         $content['userid']
106                                 ), __FILE__, __LINE__);
107
108                         // Load email template and send it to the user!
109                         if ($sentBonusMails === true) {
110                                 // Add userid to queue
111                                 array_push($userids, $content['userid']);
112                         } else {
113                                 // Send normal notification mail to the members
114                                 $message = loadEmailTemplate('bonus_' . $mode . '_notify', $content, $content['userid']);
115                                 sendEmail($content['userid'], '{--MEMBER_BONUS_RALLYE_' . strtoupper($mode) . '_SUBJECT--}', $message);
116                         }
117                 } // END - while
118
119                 // Shall I send out bonus mails?
120                 if ($sentBonusMails === true) {
121                         // Okay, make array to string
122                         $receiver = implode(';', $userids);
123
124                         // Prepare URL
125                         $url = 'modules.php?module=index&amp;what=login';
126
127                         // Insert mail
128                         addBonusMailToQueue('{--MEMBER_BONUS_RALLYE_' . strtoupper($mode) . '_SUBJECT--}', $message, $receiver, getConfig('bonus_notify_points'), getConfig('bonus_notify_wait'), $url, 0, 'normal', SQL_NUMROWS($result_main));
129                 } // END - if
130         } // END - if
131
132         // Free memory
133         SQL_FREERESULT($result_main);
134 } // END - if
135
136 //
137 ?>