2 /************************************************************************
3 * MXChange v0.2.1 Start: 11/22/2005 *
4 * =============== Last change: 11/22/2005 *
6 * -------------------------------------------------------------------- *
7 * File : bonus_mails.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Sends out reminder mails *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Versendet Erinnerungsmails *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 elseif ((!EXT_IS_ACTIVE("bonus")) && (!IS_ADMIN()))
42 ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "bonus");
46 // Do not execute when script is in CSS mode
47 if ($CSS == 1) return;
49 // Create timemark from saved month
50 $mark = mktime(0, 0, 0, $CONFIG['bonus_month'], date("d", time()), date("Y", time()));
51 $SQL = ""; $MODE = "";
53 // Shall I sent activation or deactivation mail?
54 $SQL = "SELECT userid, email FROM "._MYSQL_PREFIX."_user_data WHERE (bonus_ral_notify ";
55 switch ($CONFIG['bonus_active'])
57 case "Y": // Active rallye is activated
58 if ($CONFIG['bonus_en_notify'] == "Y")
60 // Okay, let's check for member accounts
61 $SQL .= "= 0 OR (bonus_ral_notify > 0 AND bonus_ral_en_notify < bonus_ral_di_notify)";
71 case "N": // Active rallye is deactivated
72 if ($CONFIG['bonus_di_notify'] == "Y")
74 // Okay, let's check for member accounts
75 $SQL .= " > 0 AND bonus_ral_di_notify < bonus_ral_en_notify";
88 // The SQL command needs to be finisched here (only confirmed accounts!)
89 $SQL .= ") AND status='CONFIRMED' ORDER BY last_online ASC";
91 // Normal notification mails or bonus mails?
92 $MAIL_MODE = (($CONFIG['bonus_notify_points'] > 0) && ($MODE == "en") && (EXT_IS_ACTIVE("bonus")));
94 // Generate subject line
95 $eval = "\$SUBJECT = BONUS_RALLYE_".strtoupper($MODE)."_NOTIFY;";
98 // Load message body for bonus mails
99 $MSG = LOAD_EMAIL_TEMPLATE("bonus_en_notify_body", "", "{PER}uid{PER}");
100 $RECEIVER = ""; $UIDs = array();
102 // Check for accounts to be notified
103 $result_main = SQL_QUERY($SQL, __FILE__, __LINE__);
104 if (SQL_NUMROWS($result_main) > 0)
106 // Okay lets notify all users!
107 while(list($uid, $email) = SQL_FETCHROW($result_main))
110 $result_update = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
111 SET bonus_ral_notify='%s', bonus_ral_%s_notify='%s' WHERE userid=%d LIMIT 1",
112 array(time(), $MODE, time(), $uid), __FILE__, __LINE__);
114 // Load email template and send it to the user!
117 // Add userid to queue
122 // Send normal notification mail to the members
123 $MSG = LOAD_EMAIL_TEMPLATE("bonus_".$MODE."_notify", "", $uid);
124 SEND_EMAIL($email, $SUBJECT, $MSG);
128 // Shall I send out bonus mails?
131 // Okay, make array to string
132 $RECEIVER = implode(";", $UIDs);
133 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_bonus
134 (subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, mails_sent, is_notify)
135 VALUES ('%s', '%s', '%s', '%s', '%s', 'NEW', UNIX_TIMESTAMP(), '%s', '%s', '%s', '%s', 'Y')",
140 $CONFIG['bonus_notify_points'],
141 $CONFIG['bonus_notify_wait'],
142 URL."/modules.php?module=index&what=login",
144 SELECTION_COUNT(explode(";", $RECEIVER)),
145 SQL_NUMROWS($result_main),
146 ), __FILE__, __LINE__);
151 SQL_FREERESULT($result_main);