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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
44 // Don't run on daily reset
45 if (isResetModeEnabled()) {
48 } elseif (!isExtensionActive('bonus')) {
49 // Abort if extension bonus is not active
54 // Only send bonus mail when bonus extension is active and maximum send-mails is not reached
55 if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
56 // Do we need to send out bonus mails?
57 if (isExtensionActive('html_mail')) {
58 // 0 1 2 3 4 5 6 7 8 9 10 11
59 $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__);
61 // 0 1 2 3 4 5 6 7 8 9 10
62 $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__);
65 if (SQL_NUMROWS($result_bonus) > 0) {
66 // Send these mails away...
68 while ($DATA = SQL_FETCHARRAY($result_bonus)) {
69 // Message is active in queue
70 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='QUEUE' WHERE `id`=%s LIMIT 1",
71 array(bigintval($DATA['id'])), __FILE__, __LINE__);
73 // "Explode" all receivers into an array
74 if (ereg(';', $DATA['receivers'])) {
75 // There's more than one receiver in the list...
76 $RECEIVERS = explode(';', $DATA['receivers']);
77 } elseif (!empty($DATA['points'])) {
79 $RECEIVERS = array($DATA['receivers']);
82 $RECEIVERS = array(0);
86 // Now, if we are good little boys and girls Santa left us some user-ids.
87 // We can now send mails to them...
88 foreach ($RECEIVERS as $key => $userid) {
90 if (fetchUserData($userid)) {
91 // The final receiver does exists so we can continue...
92 //* DEBUG: */ print("OK!/L:".__LINE__."<br />");
94 // Mark this user as "spammed" ;-) And place a line for him...
95 if (removeReceiver($dummy, $key, $userid, $DATA['id'], $DATA['id'], true) == 'done') {
96 // Replace text variables
97 foreach ($GLOBALS['replacer'] as $key => $value) {
98 if (isset($DATA[$key])) $DATA['text'] = str_replace($value, $DATA[$key], $DATA['text']);
104 'url' => $DATA['url'],
105 'time' => createFancyTime($DATA['time']),
106 'points' => translateComma($DATA['points']),
107 'category' => getCategory($DATA['cat_id']),
108 'text' => $DATA['text']
112 $mailText = loadEmailTemplate('bonus-mail', $content, $userid);
115 if (isset($DATA['html_msg'])) {
117 sendEmail(getUserData('email'), $DATA['subject'], $mailText, $DATA['html_msg']);
120 sendEmail(getUserData('email'), $DATA['subject'], $mailText);
123 // Count one up and remove entry from dummy array
124 $GLOBALS['pool_cnt']++; unset($dummy[$key]);
126 if (getExtensionVersion('user') >= '0.1.4') {
127 // Update mails received for receiver
128 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET emails_received=emails_received+1 WHERE `userid`=%s LIMIT 1",
129 array(bigintval($userid)), __FILE__, __LINE__);
132 // Do we have send maximum mails?
133 if (($GLOBALS['pool_cnt'] >= getConfig('max_send')) || (countSelection($dummy) == 0)) {
135 //* DEBUG: */ print("*EXIT/L:".__LINE__."<br />");
142 // Update mediadata if version is 0.0.4 or higher
143 if (getExtensionVersion('mediadata') >= '0.0.4') {
144 // Update entry (or add missing
145 $P = $GLOBALS['pool_cnt'];
146 if (!empty($cnt2) && empty($GLOBALS['pool_cnt'])) $P = $cnt2;
147 //* DEBUG: */ print("+MEDIA/L:".__LINE__.'/'.$P."+<br />");
148 updateMediadataEntry(array("total_send", "bonus_send"), 'add', $P);
151 // Close sending system
152 //* DEBUG: */ print("-L:".__LINE__.'/'.countSelection($dummy)."-<br />");
153 if (countSelection($dummy) == 0) {
155 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='SEND', `target_send`=0, `receivers`='' WHERE `id`=%s LIMIT 1",
156 array(bigintval($DATA['id'])), __FILE__, __LINE__);
157 //* DEBUG: */ print("*L:".__LINE__."*<br />");
159 // Update mediadata if version is 0.0.4 or higher
160 if (getExtensionVersion('mediadata') >= '0.0.4') {
161 // Update entry (or add missing)
162 //* DEBUG: */ print("*MEDIA/L:".__LINE__."*<br />");
163 updateMediadataEntry(array("total_orders", "bonus_orders"), 'add', 1);
165 } elseif ($GLOBALS['pool_cnt'] >= getConfig('max_send')) {
167 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='NEW', `target_send`=%s, `receivers`='%s' WHERE `id`=%s LIMIT 1",
168 array(countSelection($dummy), implode(';', $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
169 //* DEBUG: */ print("*L:".__LINE__."<pre>");
170 //* DEBUG: */ print(print_r($dummy, true));
171 //* DEBUG: */ print("</pre>\n!!!<br />");
178 SQL_FREERESULT($result_bonus);