X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fpool%2Fpool-bonus.php;h=9f04c935bd52d60f9dab5726891a3bd8ee3de855;hp=d5084bee6bce167108befe7d69978e16001945ca;hb=0f3a135204757cc8750262871c8e62c42300acb4;hpb=09f5758c42a33a56bdd461c946ffe759a59c54aa diff --git a/inc/pool/pool-bonus.php b/inc/pool/pool-bonus.php index d5084bee6b..9f04c935bd 100644 --- a/inc/pool/pool-bonus.php +++ b/inc/pool/pool-bonus.php @@ -14,11 +14,9 @@ * $Date:: $ * * $Tag:: 0.2.1-FINAL $ * * $Author:: $ * - * Needs to be in all Files and every File needs "svn propset * - * svn:keywords Date Revision" (autoprobset!) at least!!!!!! * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009, 2010 by Mailer Developer Team * + * Copyright (c) 2009 - 2011 by Mailer Developer Team * * For more information visit: http://www.mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -40,10 +38,10 @@ // Some security stuff... if (!defined('__SECURITY')) { die(); -} +} // END - if // Don't run on daily reset -if (isResetModeEnabled()) { +if ((isResetModeEnabled()) || (!isHtmlOutputMode())) { // Skip here return false; } elseif (!isExtensionActive('bonus')) { @@ -53,134 +51,146 @@ if (isResetModeEnabled()) { // 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')) { +if ($GLOBALS['pool_cnt'] < getMaxSend()) { // Do we need to 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__); + $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__); + $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) { + if (!SQL_HASZERONUMS($result_bonus)) { // Send these mails away... - $cnt2 = ''; - while ($DATA = SQL_FETCHARRAY($result_bonus)) { + $count2 = ''; + while ($mailData = SQL_FETCHARRAY($result_bonus)) { // 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__); // "Explode" all receivers into an array - if (ereg(';', $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']); + $receivers = array($mailData['receivers']); } else { // No users left - $receiverS = array(0); + $receivers = array(0); } - $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) { + foreach ($receivers as $key => $userid) { // Load personal data if (fetchUserData($userid)) { // The final receiver does exists so we can continue... - //* DEBUG: */ print("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 content - $content = array( - 'id' => $DATA['id'], - 'url' => $DATA['url'], - 'time' => createFancyTime($DATA['time']), - 'points' => translateComma($DATA['points']), - 'category' => getCategory($DATA['cat_id']), - 'text' => $DATA['text'] - ); - - // Prepare the mail - $mailText = loadEmailTemplate('bonus-mail', $content, $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 (getExtensionVersion('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: */ print("*EXIT/L:".__LINE__."
"); + //* DEBUG: */ debugOutput('OK!/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]); + + 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'] >= getMaxSend()) || (countSelection($temporaryReceivers) == 0)) { + // Yes, we have + //* DEBUG: */ debugOutput('*EXIT/L:'.__LINE__); + break; + } // END - if + break; + + default: // Unknown return type + logDebugMessage(__FILE__, __LINE__, 'Unknown status ' . $status . ' detected. pool_id=' . $mailData['id'] . ',userid=' . $mailData['userid'] . ',stats_id=' . $stats_id); break; - } // END - if - } // END - if + } // END - switch } // END - if } // END - foreach // Update mediadata if version is 0.0.4 or higher - if (getExtensionVersion('mediadata') >= '0.0.4') { + if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) { // Update entry (or add missing $P = $GLOBALS['pool_cnt']; - if (!empty($cnt2) && empty($GLOBALS['pool_cnt'])) $P = $cnt2; - //* DEBUG: */ print("+MEDIA/L:".__LINE__.'/'.$P."+
"); + if (!empty($count2) && empty($GLOBALS['pool_cnt'])) $P = $count2; + //* DEBUG: */ debugOutput('+MEDIA/L:'.__LINE__.'/'.$P.'+'); updateMediadataEntry(array('total_send', 'bonus_send'), 'add', $P); } // END - if // Close sending system - //* DEBUG: */ print("-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` SET `data_type`='SEND', `target_send`=0, `receivers`='' WHERE `id`=%s LIMIT 1", - array(bigintval($DATA['id'])), __FILE__, __LINE__); - //* DEBUG: */ print("*L:".__LINE__."*
"); + SQL_QUERY_ESC("UPDATE + `{?_MYSQL_PREFIX?}_bonus` +SET + `data_type`='SEND', + `target_send`=0, + `receivers`='' +WHERE + `id`=%s +LIMIT 1", + array(bigintval($mailData['id'])), __FILE__, __LINE__); + //* DEBUG: */ debugOutput('*L:'.__LINE__.'*'); // Update mediadata if version is 0.0.4 or higher - if (getExtensionVersion('mediadata') >= '0.0.4') { + if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) { // Update entry (or add missing) - //* DEBUG: */ print("*MEDIA/L:".__LINE__."*
"); + //* 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` SET `data_type`='NEW', `target_send`=%s, `receivers`='%s' WHERE `id`=%s LIMIT 1", - array(countSelection($dummy), implode(';', $dummy), bigintval($DATA['id'])), __FILE__, __LINE__); - //* DEBUG: */ print("*L:".__LINE__."
");
-				//* DEBUG: */ print(print_r($dummy, true));
-				//* DEBUG: */ print("
\n!!!
"); + SQL_QUERY_ESC("UPDATE + `{?_MYSQL_PREFIX?}_bonus` +SET + `data_type`='NEW', + `target_send`=%s, + `receivers`='%s' +WHERE + `id`=%s +LIMIT 1", + array( + countSelection($temporaryReceivers), + implode(';', $temporaryReceivers), + bigintval($mailData['id']) + ), __FILE__, __LINE__); + //* DEBUG: */ debugOutput('*L:'.__LINE__.'
'.print_r($temporaryReceivers, true).'
!!!'); break; } - } - } + } // END - while + } // END - if // Free memory SQL_FREERESULT($result_bonus); // Remove variable unset($mailText); -} +} // END - if -// +// [EOF] ?>