Added update_year.sh (still not fully flexible) and updated all years with it.
[mailer.git] / inc / mails / beg_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              : beg_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('beg')) || (isExtensionInstalledAndOlder('beg', '0.2.8'))) {
37         // Do not execute script on missing/out-dated extension ext-beg
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`.`beg_rallye_enable_notify` ";
50 switch (getBegRallye()) {
51         case 'Y': // Begging rallye is activated
52                 if (isBegRallyeEnableNotifyEnabled()) {
53                         // Okay, let's check for member accounts
54                         $sql .= '= 0 OR (`d`.`beg_rallye_enable_notify` > 0 AND `d`.`beg_rallye_enable_notify` < `d`.`beg_rallye_disable_notify`)';
55                         $mode = 'enable';
56                 } else {
57                         // Do not notify!
58                         $sql = '';
59                 }
60                 break;
61
62         case 'N': // Begging rallye is deactivated
63                 if (isBegRallyeDisableNotifyEnabled()) {
64                         // Okay, let's check for member accounts
65                         $sql .= ' > 0 AND `d`.`beg_rallye_disable_notify` < `d`.`beg_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         // No IP locking setuped by default
79         $content['ip_locker'] = '{--BEG_NO_LIMITATION--}';
80
81         if (getBegIpTimeout() > 0) {
82                 // Create timemark
83                 $content['ip_locker'] = '{%config,createFancyTime=beg_ip_timeout%}';
84         } // END - if
85
86         // Check for accounts to be notified
87         $result_main = sqlQuery($sql, __FILE__, __LINE__);
88         if (!ifSqlHasZeroNums($result_main)) {
89                 // Normal notification mails or bonus mails?
90                 $sentBonusMails = ((getBegNotifyBonus() > 0) && ($mode == 'enable') && (isExtensionActive('bonus')));
91
92                 // Load message body for bonus mails
93                 $message = loadEmailTemplate('beg_enable_notify_body', '', '{PER}userid{PER}');
94                 $receiver = ''; $userids = array();
95
96                 // Okay lets notify all users!
97                 while ($row = sqlFetchArray($result_main)) {
98                         // Merge arrays
99                         $content = merge_array($content, $row);
100
101                         // Update account
102                         sqlQueryEscaped("UPDATE
103         `{?_MYSQL_PREFIX?}_user_data`
104 SET
105         `beg_rallye_%s_notify`=UNIX_TIMESTAMP()
106 WHERE
107         `userid`=%s
108 LIMIT 1",
109                                 array(
110                                         $mode,
111                                         $content['userid']
112                                 ), __FILE__, __LINE__);
113
114                         // Load email template and send it to the user!
115                         if ($sentBonusMails === TRUE) {
116                                 // Add userid to queue
117                                 array_push($userids, $content['userid']);
118                         } else {
119                                 // Send normal notification mail to the members
120                                 $message = loadEmailTemplate('beg_' . $mode . '_notify', $content, $content['userid']);
121                                 sendEmail($content['userid'], '{--BEG_RALLYE_' . strtoupper($mode) . '_SUBJECT--}', $message);
122                         }
123                 } // END - while
124
125                 // Shall I send out bonus mails?
126                 if ($sentBonusMails === TRUE) {
127                         // Okay, make array to string
128                         $receiver = implode(';', $userids);
129
130                         // Prepare URL
131                         $url = 'modules.php?module=index&amp;what=login';
132
133                         // Insert mail
134                         addBonusMailToQueue('{--BEG_RALLYE_' . strtoupper($mode) . '_SUBJECT--}', $message, $receiver, getBegNotifyBonus(), getBegNotifyWait(), $url, 0, 'normal', sqlNumRows($result_main));
135                 } // END - if
136         } // END - if
137
138         // Free memory
139         sqlFreeResult($result_main);
140 } // END - if
141
142 // [EOF]
143 ?>