9bf3915639ae0d6a45a616696a322b437419766d
[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  * 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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } elseif (!isExtensionActive('beg')) {
43         return;
44 }
45
46 // Do not execute when script is in CSS mode
47 if (getOutputMode() != 0) return;
48
49 // Create timemark from saved month
50 $mark = mktime(0, 0, 0, getConfig('last_month'), date('d', time()), date('Y', time()));
51 $sql = ''; $mode = '';
52
53 // Shall I sent activation or deactivation mail?
54 $sql = "SELECT `userid`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE (`beg_ral_notify` ";
55 switch (getConfig('beg_rallye')) {
56         case 'Y': // Begging rallye is activated
57                 if (getConfig('beg_ral_en_notify') == 'Y') {
58                         // Okay, let's check for member accounts
59                         $sql .= '= 0 OR (`beg_ral_notify` > 0 AND `beg_ral_en_notify` < `beg_ral_di_notify`)';
60                         $mode = 'en';
61                 } else {
62                         // Do not notify!
63                         $sql = '';
64                 }
65                 break;
66
67         case 'N': // Begging rallye is deactivated
68                 if (getConfig('beg_ral_di_notify') == 'Y') {
69                         // Okay, let's check for member accounts
70                         $sql .= ' > 0 AND `beg_ral_di_notify` < `beg_ral_en_notify`';
71                         $mode = 'di';
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 .= ") AND `status`='CONFIRMED' ORDER BY `last_online` ASC";
82
83         // Prepare data for the template
84         $content['min_points'] = translateComma(getConfig('beg_points'));
85         $content['max_points'] = translateComma(getConfig('beg_points_max'));
86         $content['max_winner'] = round(getConfig('beg_ranks'));
87
88         // No IP locking setuped by default
89         $content['ip_locker'] = getMessage('BEG_NO_LIMITATION');
90
91         if (getConfig('beg_ip_timeout') > 0) {
92                 // Create timemark
93                 $content['ip_locker'] = createFancyTime(getConfig('beg_ip_timeout'));
94         } // END - if
95
96         // Check for accounts to be notified
97         $result_main = SQL_QUERY($sql, __FILE__, __LINE__);
98         if (SQL_NUMROWS($result_main) > 0) {
99                 // Normal notification mails or bonus mails?
100                 $sentBonusMails = ((getConfig('beg_notify_bonus') > 0) && ($mode == "en") && (isExtensionActive('bonus')));
101
102                 // Generate subject line
103                 $subject = getMessage('BEG_RALLYE_'.strtoupper($mode).'_NOTIFY');
104
105                 // Load message body for bonus mails
106                 $message = loadEmailTemplate('beg_en_notify_body', '', '{PER}userid{PER}');
107                 $receiver = ''; $userids = array();
108
109                 // Okay lets notify all users!
110                 while ($content = merge_array($content, SQL_FETCHARRAY($result_main))) {
111                         // Update account
112                         SQL_QUERY_ESC("UPDATE
113         `{?_MYSQL_PREFIX?}_user_data`
114 SET
115         `beg_ral_notify`=UNIX_TIMESTAMP(),
116         `beg_ral_%s_notify`=UNIX_TIMESTAMP()
117 WHERE
118         `userid`=%s
119 LIMIT 1",
120                                 array(
121                                         $mode,
122                                         $content['userid']
123                                 ), __FILE__, __LINE__);
124
125                         // Load email template and send it to the user!
126                         if ($sentBonusMails === true) {
127                                 // Add userid to queue
128                                 $userids[] = $content['userid'];
129                         } else {
130                                 // Send normal notification mail to the members
131                                 $message = loadEmailTemplate('beg_' . $mode . '_notify', $content, $content['userid']);
132                                 sendEmail($content['email'], $subject, $message);
133                         }
134                 } // END - while
135
136                 // Shall I send out bonus mails?
137                 if ($sentBonusMails === true) {
138                         // Okay, make array to string
139                         $receiver = implode(';', $userids);
140
141                         // Prepare URL
142                         $URL = 'modules.php?module=index&amp;what=login';
143
144                         // Insert mail
145                         addBonusMailToQueue($subject, $message, $receiver, getConfig('beg_notify_bonus'), getConfig('beg_notify_wait'), $URL, 0, 'normal', SQL_NUMROWS($result_main));
146                 } // END - if
147         } // END - if
148
149         // Free memory
150         SQL_FREERESULT($result_main);
151 } // END - if
152
153 // [EOF]
154 ?>