X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=inc%2Fpool%2Fpool-bonus.php;h=58ea34151ca1904b52faf657acef63f454805ba8;hb=3bfec15f1d037e1dd4885786103c70d0c1cfe1a8;hp=139f1f5e7cfb21658dc6fcc888ea60cb4ea5e482;hpb=0575b28ca79d2dc5d1d33aa7f9997053a5fc52c4;p=mailer.git diff --git a/inc/pool/pool-bonus.php b/inc/pool/pool-bonus.php index 139f1f5e7c..58ea34151c 100644 --- a/inc/pool/pool-bonus.php +++ b/inc/pool/pool-bonus.php @@ -16,8 +16,8 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009, 2010 by Mailer Developer Team * - * For more information visit: http://www.mxchange.org * + * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -38,96 +38,130 @@ // Some security stuff... if (!defined('__SECURITY')) { die(); -} +} // END - if // Don't run on daily reset -if (isResetModeEnabled()) { +if ((isResetModeEnabled()) || (!isHtmlOutputMode())) { // Skip here - return false; + return FALSE; } elseif (!isExtensionActive('bonus')) { // Abort if extension bonus is not active - return false; + return FALSE; } -// Need this here // Only send bonus mail when bonus extension is active and maximum send-mails is not reached -if ($GLOBALS['pool_cnt'] < getConfig('max_send')) { - // Do we need to send out bonus mails? +if ($GLOBALS['pool_cnt'] < getMaxSend()) { + // Default is ext-html_mail is gone + $add = ''; + + // Send out bonus mails? if (isExtensionActive('html_mail')) { - // 0 1 2 3 4 5 6 7 8 9 10 11 - $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__); - } else { - // 0 1 2 3 4 5 6 7 8 9 10 - $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__); - } - - if (SQL_NUMROWS($result_bonus) > 0) { + // With HTML support + $add = ', `html_msg`'; + } // END - if + + // Run query + $result_main = SQL_QUERY("SELECT + `id`, + `subject`, + `text`, + `receivers`, + `points`, + `time`, + `data_type`, + `timestamp`, + `url`, + `cat_id`, + `target_send` + " . $add . " +FROM + `{?_MYSQL_PREFIX?}_bonus` +WHERE + `data_type`='NEW' +ORDER BY + `timestamp` DESC", __FILE__, __LINE__); + + // Some mails left? + if (!SQL_HASZERONUMS($result_main)) { + // Init SQLs here + initSqls(); + // Send these mails away... $count2 = ''; - while ($DATA = SQL_FETCHARRAY($result_bonus)) { + while ($mailData = SQL_FETCHARRAY($result_main)) { // Message is active in queue SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='QUEUE' WHERE `id`=%s LIMIT 1", - array(bigintval($DATA['id'])), __FILE__, __LINE__); + array(bigintval($mailData['id'])), __FILE__, __LINE__); + + // Default is no users left + $receivers = array(); // "Explode" all receivers into an array - if (isInString(';', $DATA['receivers'])) { + if (isInString(';', $mailData['receivers'])) { // There's more than one receiver in the list... - $receiverS = explode(';', $DATA['receivers']); - } elseif (!empty($DATA['points'])) { + $receivers = explode(';', $mailData['receivers']); + } elseif (!empty($mailData['points'])) { // Only one user left - $receiverS = array($DATA['receivers']); - } else { - // No users left - $receiverS = array(0); + $receivers = array($mailData['receivers']); } - $dummy = $receiverS; + $temporaryReceivers = $receivers; - // Now, if we are good little boys and girls Santa Claus left us some user-ids. - // We can now send mails to them... - foreach ($receiverS as $key => $userid) { + /* + * Now, if we are good little boys and girls Santa Claus left us + * some user-ids and send out mails to them. + */ + foreach ($receivers as $key => $userid) { // Load personal data if (fetchUserData($userid)) { // The final receiver does exists so we can continue... //* DEBUG: */ debugOutput('OK!/L:'.__LINE__); - // Mark this user as "spammed" ;-) And place a line for him... - if (removeReceiver($dummy, $key, $userid, $DATA['id'], $DATA['id'], true) == 'done') { - // Replace text variables - foreach ($GLOBALS['replacer'] as $key => $value) { - if (isset($DATA[$key])) $DATA['text'] = str_replace($value, $DATA[$key], $DATA['text']); - } // END - foreach - - // Prepare the mail - $mailText = loadEmailTemplate('bonus-mail', $DATA, $userid); - - // Send mail away - if (isset($DATA['html_msg'])) { - // Send HTML? - sendEmail(getUserData('email'), $DATA['subject'], $mailText, $DATA['html_msg']); - } else { - // No HTML mail! - sendEmail(getUserData('email'), $DATA['subject'], $mailText); - } - - // Count one up and remove entry from dummy array - $GLOBALS['pool_cnt']++; unset($dummy[$key]); - - if (isExtensionInstalledAndNewer('user', '0.1.4')) { - // Update mails received for receiver - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`+1 WHERE `userid`=%s LIMIT 1", - array(bigintval($userid)), __FILE__, __LINE__); - } // END - if - - // Do we have send maximum mails? - if (($GLOBALS['pool_cnt'] >= getConfig('max_send')) || (countSelection($dummy) == 0)) { - // Yes, we have - //* DEBUG: */ debugOutput('*EXIT/L:'.__LINE__); + // Remove receiver from list + $status = removeReceiver($temporaryReceivers, $key, $userid, $mailData['id'], $mailData['id'], TRUE); + + // Did it work? + switch ($status) { + case 'done': // Done! + // Prepare the mail + $mailText = loadEmailTemplate('member_bonus_pool_normal', $mailData, $userid); + + // Send mail away + if (isset($mailData['html_msg'])) { + // Send HTML? + sendEmail(getUserData('userid'), $mailData['subject'], $mailText, $mailData['html_msg']); + } else { + // No HTML mail! + sendEmail(getUserData('userid'), $mailData['subject'], $mailText); + } + + // Count one up and remove entry from dummy array + $GLOBALS['pool_cnt']++; unset($temporaryReceivers[$key]); + + // Is ext-user installed? + if (isExtensionInstalledAndNewer('user', '0.1.4')) { + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $userid . ',mailData[id]=' . $mailData['id']); + // Update mails received for receiver + addSql(sprintf("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`+1 WHERE `userid`=%s LIMIT 1", bigintval($userid))); + } // END - if + + // Is the size of pool reached or nothing to sent left? + if (($GLOBALS['pool_cnt'] >= getMaxSend()) || (countSelection($temporaryReceivers) == 0)) { + // Yes, it is. So abort here + break; + } // END - if break; - } // END - if - } // END - if + + default: // Unknown return type + logDebugMessage(__FILE__, __LINE__, 'Unknown status ' . $status . ' detected. pool_id=' . $mailData['id'] . ',userid=' . $mailData['userid'] . ',stats_id=' . $stats_id); + break; + } // END - switch } // END - if } // END - foreach + // Run all SQLs + runFilterChain('run_sqls'); + // Update mediadata if version is 0.0.4 or higher if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) { // Update entry (or add missing @@ -138,8 +172,8 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) { } // END - if // Close sending system - //* DEBUG: */ debugOutput('-L:'.__LINE__.'/'.countSelection($dummy).'-'); - if (countSelection($dummy) == 0) { + //* DEBUG: */ debugOutput('-L:'.__LINE__.'/'.countSelection($temporaryReceivers).'-'); + if (countSelection($temporaryReceivers) == 0) { // Queue reached! SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` @@ -150,7 +184,7 @@ SET WHERE `id`=%s LIMIT 1", - array(bigintval($DATA['id'])), __FILE__, __LINE__); + array(bigintval($mailData['id'])), __FILE__, __LINE__); //* DEBUG: */ debugOutput('*L:'.__LINE__.'*'); // Update mediadata if version is 0.0.4 or higher @@ -159,7 +193,7 @@ LIMIT 1", //* DEBUG: */ debugOutput('*MEDIA/L:'.__LINE__.'*'); updateMediadataEntry(array('total_orders', 'bonus_orders'), 'add', 1); } // END - if - } elseif ($GLOBALS['pool_cnt'] >= getConfig('max_send')) { + } elseif ($GLOBALS['pool_cnt'] >= getMaxSend()) { // Update bonus pool SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` @@ -171,18 +205,21 @@ WHERE `id`=%s LIMIT 1", array( - countSelection($dummy), - implode(';', $dummy), - bigintval($DATA['id']) + countSelection($temporaryReceivers), + implode(';', $temporaryReceivers), + bigintval($mailData['id']) ), __FILE__, __LINE__); - //* DEBUG: */ debugOutput('*L:'.__LINE__.'
'.print_r($dummy, true).'!!!'); + //* DEBUG: */ debugOutput('*L:'.__LINE__.'
'.print_r($temporaryReceivers, TRUE).'!!!'); + + // Run any SQLs + runFilterChain('run_sqls'); break; } } // END - while } // END - if // Free memory - SQL_FREERESULT($result_bonus); + SQL_FREERESULT($result_main); // Remove variable unset($mailText);