2 /************************************************************************
3 * MXChange v0.2.1 Start: 12/12/2008 *
4 * =============== Last change: 12/12/2008 *
6 * -------------------------------------------------------------------- *
7 * File : pool-bonus.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Sends queued bonus mails from the pool *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Sendet freigegebene Bonus-Mails aus dem Pool *
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 (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Don't run on daily reset
41 if (defined('__DAILY_RESET')) {
44 } elseif (!EXT_IS_ACTIVE("bonus")) {
45 // Abort if extension bonus is not active
52 // Only send bonus mail when bonus extension is active and maximum send-mails is not reached
53 if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
54 // Do we need to send out bonus mails?
55 if (EXT_IS_ACTIVE("html_mail")) {
56 // 0 1 2 3 4 5 6 7 8 9 10 11
57 $result_bonus = SQL_QUERY("SELECT id, subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send, html_msg FROM "._MYSQL_PREFIX."_bonus WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__);
59 // 0 1 2 3 4 5 6 7 8 9 10
60 $result_bonus = SQL_QUERY("SELECT id, subject, text, receivers, points, time, data_type, timestamp, url, cat_id, target_send FROM "._MYSQL_PREFIX."_bonus WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__);
63 if (SQL_NUMROWS($result_bonus) > 0) {
64 // Send these mails away...
66 while ($DATA = SQL_FETCHARRAY($result_bonus)) {
68 $DATA['url'] = COMPILE_CODE($DATA['url']);
70 // Message is active in queue
71 SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='QUEUE' WHERE id=%s LIMIT 1",
72 array(bigintval($DATA['id'])), __FILE__, __LINE__);
74 // "Explode" all receivers into an array
75 if (ereg(";", $DATA['receivers'])) {
76 // There's more than one receiver in the list...
77 $RECEIVERS = explode(";", $DATA['receivers']);
78 } elseif (!empty($DATA['points'])) {
80 $RECEIVERS = array($DATA['receivers']);
83 $RECEIVERS = array("0");
87 // Now, if we are good little boys and girls Santa left us some user-ids.
88 // We can now send mails to them...
89 foreach ($RECEIVERS as $key => $uid) {
91 //* DEBUG: */ echo "*L:".__LINE__."/".$uid."*<br />";
92 $result_user = SQL_QUERY_ESC("SELECT surname, family, email FROM `"._MYSQL_PREFIX."_user_data` WHERE userid=%s LIMIT 1",
93 array(bigintval($uid)), __FILE__, __LINE__);
95 // Is his data available?
96 if (SQL_NUMROWS($result_user) == 1) {
97 // The final receiver does exists so we can continue...
98 list($sname, $fname, $email) = SQL_FETCHROW($result_user);
99 //* DEBUG: */ echo "OK!/L:".__LINE__."<br />";
101 // Mark this user as "spammed" ;-) And place a line for him...
102 if (REMOVE_RECEIVER($dummy, $key, $uid, $DATA['id'], $DATA['id'], true) == "done") {
103 // Replace text variables
104 foreach ($REPLACER as $key => $value) {
105 if (isset($DATA[$key])) $DATA['text'] = str_replace($value, $DATA[$key], $DATA['text']);
111 'url' => $DATA['url'],
112 'time' => CREATE_FANCY_TIME($DATA['time']),
113 'points' => TRANSLATE_COMMA($DATA['points']),
114 'category' => GET_CATEGORY($DATA['cat_id']),
115 'text' => $DATA['text']
119 $mailText = LOAD_EMAIL_TEMPLATE("bonus-mail", $content, $uid);
122 if (isset($DATA['html_msg'])) {
124 SEND_EMAIL($email, $DATA['subject'], $mailText, $DATA['html_msg']);
127 SEND_EMAIL($email, $DATA['subject'], $mailText);
130 // Count one up and remove entry from dummy array
131 $GLOBALS['pool_cnt']++; unset($dummy[$key]);
133 if (GET_EXT_VERSION("user") >= "0.1.4") {
134 // Update mails received for receiver
135 SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET emails_received=emails_received+1 WHERE userid=%s LIMIT 1",
136 array(bigintval($uid)), __FILE__, __LINE__);
139 // Do we have send maximum mails?
140 if (($GLOBALS['pool_cnt'] >= getConfig('max_send')) || (SELECTION_COUNT($dummy) == 0)) {
142 //* DEBUG: */ echo "*EXIT/L:".__LINE__."<br />";
149 SQL_FREERESULT($result_user);
152 // Update mediadata if version is 0.0.4 or higher
153 if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
154 // Update entry (or add missing
155 $P = $GLOBALS['pool_cnt'];
156 if (!empty($cnt2) && empty($GLOBALS['pool_cnt'])) $P = $cnt2;
157 //* DEBUG: */ echo "+MEDIA/L:".__LINE__."/".$P."+<br />";
158 MEDIA_UPDATE_ENTRY(array("total_send", "bonus_send"), "add", $P);
161 // Close sending system
162 //* DEBUG: */ echo "-L:".__LINE__."/".SELECTION_COUNT($dummy)."-<br />";
163 if (SELECTION_COUNT($dummy) == 0) {
165 SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='SEND', target_send='0', receivers='' WHERE id=%s LIMIT 1",
166 array(bigintval($DATA['id'])), __FILE__, __LINE__);
167 //* DEBUG: */ echo "*L:".__LINE__."*<br />";
169 // Update mediadata if version is 0.0.4 or higher
170 if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
171 // Update entry (or add missing)
172 //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*<br />";
173 MEDIA_UPDATE_ENTRY(array("total_orders", "bonus_orders"), "add", 1);
175 } elseif ($GLOBALS['pool_cnt'] >= getConfig('max_send')) {
177 SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_bonus SET data_type='NEW', target_send=%s, receivers='%s' WHERE id=%s LIMIT 1",
178 array(SELECTION_COUNT($dummy), implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
179 //* DEBUG: */ echo "*L:".__LINE__."<PRE>";
180 //* DEBUG: */ print_r($dummy);
181 //* DEBUG: */ echo "</PRE>\n!!!<br />";
188 SQL_FREERESULT($result_bonus);