]> git.mxchange.org Git - mailer.git/blobdiff - inc/pool/pool-bonus.php
Wrong array element fixed
[mailer.git] / inc / pool / pool-bonus.php
index ef5fb8e6961d953527159ae74dc14922b54d488c..fcbab85a6de60add0b4f9ef7664b2733d26ea96b 100644 (file)
 // 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')) {
@@ -51,7 +51,7 @@ 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
@@ -72,59 +72,63 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
                        // "Explode" all receivers into an array
                        if (isInString(';', $DATA['receivers'])) {
                                // There's more than one receiver in the list...
-                               $receiverS = explode(';', $DATA['receivers']);
+                               $receivers = explode(';', $DATA['receivers']);
                        } elseif (!empty($DATA['points'])) {
                                // Only one user left
-                               $receiverS = array($DATA['receivers']);
+                               $receivers = array($DATA['receivers']);
                        } else {
                                // No users left
-                               $receiverS = array(0);
+                               $receivers = array(0);
                        }
-                       $dummy = $receiverS;
+                       $dummy = $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: */ 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($dummy, $key, $userid, $DATA['id'], $DATA['id'], true);
+
+                                       // Did it work?
+                                       switch ($status) {
+                                               case 'done': // Done!
+                                                       // 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'] >= getMaxSend()) || (countSelection($dummy) == 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=' . $DATA['id'] . ',userid=' . $DATA['userid'] . ',stats_id=' . $stats_id);
                                                        break;
-                                               } // END - if
-                                       } // END - if
+                                       } // END - switch
                                } // END - if
                        } // END - foreach
 
@@ -159,7 +163,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`