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 - 2013 by Mailer Developer Team *
20 * For more information visit: http://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()) || (!isHtmlOutputMode())) {
47 } elseif ((!isExtensionActive('bonus')) || (!isExtensionActive('other'))) {
48 // Abort if extension bonus/other are not active
52 // Only send bonus mail when bonus extension is active and maximum send-mails is not reached
53 if ($GLOBALS['pool_cnt'] < getMaxSend()) {
54 // Default is ext-html_mail is gone
57 // Send out bonus mails?
58 if (isExtensionActive('html_mail')) {
60 $add = ', `html_msg`';
64 $result_main = sqlQuery("SELECT
78 `{?_MYSQL_PREFIX?}_bonus`
82 `timestamp` DESC", __FILE__, __LINE__);
85 if (!ifSqlHasZeroNums($result_main)) {
89 // Send these mails away...
91 while ($mailData = sqlFetchArray($result_main)) {
92 // Message is active in queue
93 sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='QUEUE' WHERE `id`=%s LIMIT 1",
94 array(bigintval($mailData['id'])), __FILE__, __LINE__);
96 // Default is no users left
99 // "Explode" all receivers into an array
100 if (isInString(';', $mailData['receivers'])) {
101 // There's more than one receiver in the list...
102 $receivers = explode(';', $mailData['receivers']);
103 } elseif (!empty($mailData['points'])) {
104 // Only one user left
105 $receivers = array($mailData['receivers']);
107 $temporaryReceivers = $receivers;
110 * Now, if we are good little boys and girls Santa Claus left us
111 * some user-ids and send out mails to them.
113 foreach ($receivers as $key => $userid) {
114 // Load personal data
115 if (fetchUserData($userid)) {
116 // The final receiver does exists so we can continue...
117 //* DEBUG: */ debugOutput('OK!/L:'.__LINE__);
119 // Remove receiver from list
120 $status = removeReceiver($temporaryReceivers, $key, $userid, $mailData['id'], $mailData['id'], TRUE);
124 case 'done': // Done!
126 $mailText = loadEmailTemplate('member_bonus_pool_normal', $mailData, $userid);
129 if (isset($mailData['html_msg'])) {
131 sendEmail(getUserData('userid'), $mailData['subject'], $mailText, $mailData['html_msg']);
134 sendEmail(getUserData('userid'), $mailData['subject'], $mailText);
137 // Count one up and remove entry from dummy array
138 $GLOBALS['pool_cnt']++; unset($temporaryReceivers[$key]);
140 // Is ext-user installed?
141 if (isExtensionInstalledAndNewer('user', '0.1.4')) {
143 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',mailData[id]=' . $mailData['id']);
144 // Update mails received for receiver
145 addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`+1 WHERE `userid`=%s LIMIT 1", bigintval($userid)));
148 // Is the size of pool reached or nothing to sent left?
149 if (($GLOBALS['pool_cnt'] >= getMaxSend()) || (countSelection($temporaryReceivers) == 0)) {
150 // Yes, it is. So abort here
155 default: // Unknown return type
156 logDebugMessage(__FILE__, __LINE__, 'Unknown status ' . $status . ' detected. pool_id=' . $mailData['id'] . ',userid=' . $mailData['userid'] . ',stats_id=' . $stats_id);
163 runFilterChain('run_sqls');
165 // Update mediadata if version is 0.0.4 or higher
166 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
167 // Update entry (or add missing
168 $P = $GLOBALS['pool_cnt'];
169 if (!empty($count2) && empty($GLOBALS['pool_cnt'])) $P = $count2;
170 //* DEBUG: */ debugOutput('+MEDIA/L:'.__LINE__.'/'.$P.'+');
171 updateMediadataEntry(array('total_send', 'bonus_send'), 'add', $P);
174 // Close sending system
175 //* DEBUG: */ debugOutput('-L:'.__LINE__.'/'.countSelection($temporaryReceivers).'-');
176 if (countSelection($temporaryReceivers) == 0) {
178 sqlQueryEscaped("UPDATE
179 `{?_MYSQL_PREFIX?}_bonus`
187 array(bigintval($mailData['id'])), __FILE__, __LINE__);
188 //* DEBUG: */ debugOutput('*L:'.__LINE__.'*');
190 // Update mediadata if version is 0.0.4 or higher
191 if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
192 // Update entry (or add missing)
193 //* DEBUG: */ debugOutput('*MEDIA/L:'.__LINE__.'*');
194 updateMediadataEntry(array('total_orders', 'bonus_orders'), 'add', 1);
196 } elseif ($GLOBALS['pool_cnt'] >= getMaxSend()) {
198 sqlQueryEscaped("UPDATE
199 `{?_MYSQL_PREFIX?}_bonus`
208 countSelection($temporaryReceivers),
209 implode(';', $temporaryReceivers),
210 bigintval($mailData['id'])
211 ), __FILE__, __LINE__);
212 //* DEBUG: */ debugOutput('*L:'.__LINE__.'<pre>'.print_r($temporaryReceivers, TRUE).'</pre>!!!');
215 runFilterChain('run_sqls');
222 sqlFreeResult($result_main);