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