2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Don't run on daily reset
44 if (isResetModeEnabled()) {
47 } elseif (!isExtensionActive('bonus')) {
48 // Abort if extension bonus is not active
53 // Only send bonus mail when bonus extension is active and maximum send-mails is not reached
54 if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
55 // Do we need to send out bonus mails?
56 if (isExtensionActive('html_mail')) {
57 // 0 1 2 3 4 5 6 7 8 9 10 11
58 $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__);
60 // 0 1 2 3 4 5 6 7 8 9 10
61 $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__);
64 if (!SQL_HASZERONUMS($result_bonus)) {
65 // Send these mails away...
67 while ($DATA = SQL_FETCHARRAY($result_bonus)) {
68 // Message is active in queue
69 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='QUEUE' WHERE `id`=%s LIMIT 1",
70 array(bigintval($DATA['id'])), __FILE__, __LINE__);
72 // "Explode" all receivers into an array
73 if (isInString(';', $DATA['receivers'])) {
74 // There's more than one receiver in the list...
75 $receiverS = explode(';', $DATA['receivers']);
76 } elseif (!empty($DATA['points'])) {
78 $receiverS = array($DATA['receivers']);
81 $receiverS = array(0);
85 // Now, if we are good little boys and girls Santa Claus left us some user-ids.
86 // We can now send mails to them...
87 foreach ($receiverS as $key => $userid) {
89 if (fetchUserData($userid)) {
90 // The final receiver does exists so we can continue...
91 //* DEBUG: */ debugOutput('OK!/L:'.__LINE__);
93 // Mark this user as "spammed" ;-) And place a line for him...
94 if (removeReceiver($dummy, $key, $userid, $DATA['id'], $DATA['id'], true) == 'done') {
95 // Replace text variables
96 foreach ($GLOBALS['replacer'] as $key => $value) {
97 if (isset($DATA[$key])) $DATA['text'] = str_replace($value, $DATA[$key], $DATA['text']);
101 $mailText = loadEmailTemplate('bonus-mail', $DATA, $userid);
104 if (isset($DATA['html_msg'])) {
106 sendEmail(getUserData('email'), $DATA['subject'], $mailText, $DATA['html_msg']);
109 sendEmail(getUserData('email'), $DATA['subject'], $mailText);
112 // Count one up and remove entry from dummy array
113 $GLOBALS['pool_cnt']++; unset($dummy[$key]);
115 if (isExtensionInstalledAndNewer('user', '0.1.4')) {
116 // Update mails received for receiver
117 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`+1 WHERE `userid`=%s LIMIT 1",
118 array(bigintval($userid)), __FILE__, __LINE__);
121 // Do we have send maximum mails?
122 if (($GLOBALS['pool_cnt'] >= getConfig('max_send')) || (countSelection($dummy) == 0)) {
124 //* DEBUG: */ debugOutput('*EXIT/L:'.__LINE__);
131 // Update mediadata if version is 0.0.4 or higher
132 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
133 // Update entry (or add missing
134 $P = $GLOBALS['pool_cnt'];
135 if (!empty($count2) && empty($GLOBALS['pool_cnt'])) $P = $count2;
136 //* DEBUG: */ debugOutput('+MEDIA/L:'.__LINE__.'/'.$P.'+');
137 updateMediadataEntry(array('total_send', 'bonus_send'), 'add', $P);
140 // Close sending system
141 //* DEBUG: */ debugOutput('-L:'.__LINE__.'/'.countSelection($dummy).'-');
142 if (countSelection($dummy) == 0) {
144 SQL_QUERY_ESC("UPDATE
145 `{?_MYSQL_PREFIX?}_bonus`
153 array(bigintval($DATA['id'])), __FILE__, __LINE__);
154 //* DEBUG: */ debugOutput('*L:'.__LINE__.'*');
156 // Update mediadata if version is 0.0.4 or higher
157 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
158 // Update entry (or add missing)
159 //* DEBUG: */ debugOutput('*MEDIA/L:'.__LINE__.'*');
160 updateMediadataEntry(array('total_orders', 'bonus_orders'), 'add', 1);
162 } elseif ($GLOBALS['pool_cnt'] >= getConfig('max_send')) {
164 SQL_QUERY_ESC("UPDATE
165 `{?_MYSQL_PREFIX?}_bonus`
174 countSelection($dummy),
175 implode(';', $dummy),
176 bigintval($DATA['id'])
177 ), __FILE__, __LINE__);
178 //* DEBUG: */ debugOutput('*L:'.__LINE__.'<pre>'.print_r($dummy, true).'</pre>!!!');
185 SQL_FREERESULT($result_bonus);