0e4e19224b722e24422418f9b275fa55a9b3fbad
[mailer.git] / inc / mails / bonus_mails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!EXT_IS_ACTIVE("bonus")) {
39         return;
40 }
41
42 // Do not execute when script is in CSS mode
43 global $CSS;
44 if ($CSS == 1) return;
45
46 // Create timemark from saved month
47 $mark = mktime(0, 0, 0, $_CONFIG['last_month'], date("d", time()), date('Y', time()));
48 $SQL = ""; $MODE = "";
49
50 // Shall I sent activation or deactivation mail?
51 $SQL = "SELECT userid, email FROM "._MYSQL_PREFIX."_user_data WHERE (bonus_ral_notify ";
52 switch ($_CONFIG['bonus_active'])
53 {
54 case 'Y': // Active rallye is activated
55         if ($_CONFIG['bonus_en_notify'] == "Y") {
56                 // Okay, let's check for member accounts
57                 $SQL .= "= 0 OR (bonus_ral_notify > 0 AND bonus_ral_en_notify < bonus_ral_di_notify)";
58                 $MODE = "en";
59         } else {
60                 // Do not notify!
61                 $SQL = "";
62         }
63         break;
64
65 case 'N': // Active rallye is deactivated
66         if ($_CONFIG['bonus_di_notify'] == "Y") {
67                 // Okay, let's check for member accounts
68                 $SQL .= " > 0 AND bonus_ral_di_notify < bonus_ral_en_notify";
69                 $MODE = "di";
70         } else {
71                 // Do not notify!
72                 $SQL = "";
73         }
74         break;
75 }
76
77 if (!empty($SQL)) {
78         // The SQL command needs to be finisched here (only confirmed accounts!)
79         $SQL .= ") AND status='CONFIRMED' ORDER BY last_online ASC";
80
81         // Normal notification mails or bonus mails?
82         $MAIL_MODE = (($_CONFIG['bonus_notify_points'] > 0) && ($MODE == "en") && (EXT_IS_ACTIVE("bonus")));
83
84         // Generate subject line
85         $SUBJECT = constant('BONUS_RALLYE_'.strtoupper($MODE).'_NOTIFY');
86
87         // Load message body for bonus mails
88         $MSG = LOAD_EMAIL_TEMPLATE("bonus_en_notify_body", "", "{PER}uid{PER}");
89         $RECEIVER = ""; $UIDs = array();
90
91         // Check for accounts to be notified
92         $result_main = SQL_QUERY($SQL, __FILE__, __LINE__);
93         if (SQL_NUMROWS($result_main) > 0) {
94                 // Okay lets notify all users!
95                 while(list($uid, $email) = SQL_FETCHROW($result_main)) {
96                         // Update account
97                         $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
98 SET bonus_ral_notify='%s', bonus_ral_%s_notify='%s' WHERE userid=%s LIMIT 1",
99  array(time(), $MODE, time(), $uid), __FILE__, __LINE__);
100
101                         // Load email template and send it to the user!
102                         if ($MAIL_MODE) {
103                                 // Add userid to queue
104                                 $UIDs[] = $uid;
105                         } else {
106                                 // Send normal notification mail to the members
107                                 $MSG = LOAD_EMAIL_TEMPLATE("bonus_".$MODE."_notify", array(), $uid);
108                                 SEND_EMAIL($uid, $SUBJECT, $MSG);
109                         }
110                 } // END - if
111
112                 // Shall I send out bonus mails?
113                 if ($MAIL_MODE) {
114                         // Okay, make array to string
115                         $RECEIVER = implode(";", $UIDs);
116                         $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus
117 (subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, is_notify)
118 VALUES ('%s','%s','%s','%s','%s','NEW', UNIX_TIMESTAMP(), '%s','%s','%s','%s','Y')",
119  array(
120         $SUBJECT,
121         $MSG,
122         $RECEIVER,
123         $_CONFIG['bonus_notify_points'],
124         $_CONFIG['bonus_notify_wait'],
125         URL."/modules.php?module=index&what=login",
126         0,
127         SELECTION_COUNT(explode(";", $RECEIVER)),
128         SQL_NUMROWS($result_main),
129 ), __FILE__, __LINE__);
130                 }
131         }
132
133         // Free memory
134         SQL_FREERESULT($result_main);
135 }
136
137 //
138 ?>