Renamed all SQL-related functions to camel-case notation
[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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 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('beg')) || (isExtensionInstalledAndOlder('beg', '0.2.8'))) {
42         // Do not execute script on missing/out-dated extension ext-beg
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, getLastMonthly(), getDay(), getYear());
51 $sql = ''; $mode = '';
52
53 // Shall I sent activation or deactivation mail?
54 $sql = "SELECT `d`.`userid`, `d`.`email` FROM `{?_MYSQL_PREFIX?}_user_data` AS `d` WHERE (`d`.`beg_rallye_enable_notify` ";
55 switch (getBegRallye()) {
56         case 'Y': // Begging rallye is activated
57                 if (isBegRallyeEnableNotifyEnabled()) {
58                         // Okay, let's check for member accounts
59                         $sql .= '= 0 OR (`d`.`beg_rallye_enable_notify` > 0 AND `d`.`beg_rallye_enable_notify` < `d`.`beg_rallye_disable_notify`)';
60                         $mode = 'enable';
61                 } else {
62                         // Do not notify!
63                         $sql = '';
64                 }
65                 break;
66
67         case 'N': // Begging rallye is deactivated
68                 if (isBegRallyeDisableNotifyEnabled()) {
69                         // Okay, let's check for member accounts
70                         $sql .= ' > 0 AND `d`.`beg_rallye_disable_notify` < `d`.`beg_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         // Init additional WHERE statement
81         $whereStatement = '';
82
83         // Is ext-holiday installed?
84         // @TODO Rewrite these if() blocks to a filter
85         if (isExtensionActive('holiday')) {
86                 // Exclude those as well
87                 $whereStatement .= " AND `d`.`holiday_active`='N'";
88         } // END - if
89
90         // The SQL command needs to be finisched here (only confirmed accounts!)
91         $sql .= ')' . $whereStatement . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC';
92
93         // No IP locking setuped by default
94         $content['ip_locker'] = '{--BEG_NO_LIMITATION--}';
95
96         if (getBegIpTimeout() > 0) {
97                 // Create timemark
98                 $content['ip_locker'] = '{%config,createFancyTime=beg_ip_timeout%}';
99         } // END - if
100
101         // Check for accounts to be notified
102         $result_main = sqlQuery($sql, __FILE__, __LINE__);
103         if (!ifSqlHasZeroNums($result_main)) {
104                 // Normal notification mails or bonus mails?
105                 $sentBonusMails = ((getBegNotifyBonus() > 0) && ($mode == 'enable') && (isExtensionActive('bonus')));
106
107                 // Load message body for bonus mails
108                 $message = loadEmailTemplate('beg_enable_notify_body', '', '{PER}userid{PER}');
109                 $receiver = ''; $userids = array();
110
111                 // Okay lets notify all users!
112                 while ($row = sqlFetchArray($result_main)) {
113                         // Merge arrays
114                         $content = merge_array($content, $row);
115
116                         // Update account
117                         sqlQueryEscaped("UPDATE
118         `{?_MYSQL_PREFIX?}_user_data`
119 SET
120         `beg_rallye_%s_notify`=UNIX_TIMESTAMP()
121 WHERE
122         `userid`=%s
123 LIMIT 1",
124                                 array(
125                                         $mode,
126                                         $content['userid']
127                                 ), __FILE__, __LINE__);
128
129                         // Load email template and send it to the user!
130                         if ($sentBonusMails === TRUE) {
131                                 // Add userid to queue
132                                 array_push($userids, $content['userid']);
133                         } else {
134                                 // Send normal notification mail to the members
135                                 $message = loadEmailTemplate('beg_' . $mode . '_notify', $content, $content['userid']);
136                                 sendEmail($content['userid'], '{--BEG_RALLYE_' . strtoupper($mode) . '_SUBJECT--}', $message);
137                         }
138                 } // END - while
139
140                 // Shall I send out bonus mails?
141                 if ($sentBonusMails === TRUE) {
142                         // Okay, make array to string
143                         $receiver = implode(';', $userids);
144
145                         // Prepare URL
146                         $url = 'modules.php?module=index&amp;what=login';
147
148                         // Insert mail
149                         addBonusMailToQueue('{--BEG_RALLYE_' . strtoupper($mode) . '_SUBJECT--}', $message, $receiver, getBegNotifyBonus(), getBegNotifyWait(), $url, 0, 'normal', sqlNumRows($result_main));
150                 } // END - if
151         } // END - if
152
153         // Free memory
154         sqlFreeResult($result_main);
155 } // END - if
156
157 // [EOF]
158 ?>