A lot has been rewritten, ext-teams added, ext-forced continued:
[mailer.git] / inc / pool / pool-bonus.php
index 5e9c743b8a7a32cbd421fe00f8c1ee5356e9a5d1..9f04c935bd52d60f9dab5726891a3bd8ee3de855 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * 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 *
@@ -55,32 +55,32 @@ 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_HASZERONUMS($result_bonus)) {
                // Send these mails away...
                $count2 = '';
-               while ($DATA = SQL_FETCHARRAY($result_bonus)) {
+               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 (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']);
+                               $receivers = array($mailData['receivers']);
                        } else {
                                // No users left
                                $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...
@@ -91,25 +91,25 @@ if ($GLOBALS['pool_cnt'] < getMaxSend()) {
                                        //* DEBUG: */ debugOutput('OK!/L:'.__LINE__);
 
                                        // Remove receiver from list
-                                       $status = removeReceiver($dummy, $key, $userid, $DATA['id'], $DATA['id'], true);
+                                       $status = removeReceiver($temporaryReceivers, $key, $userid, $mailData['id'], $mailData['id'], true);
 
                                        // Did it work?
                                        switch ($status) {
                                                case 'done': // Done!
                                                        // Prepare the mail
-                                                       $mailText = loadEmailTemplate('bonus-mail', $DATA, $userid);
+                                                       $mailText = loadEmailTemplate('member_bonus_pool_normal', $mailData, $userid);
 
                                                        // Send mail away
-                                                       if (isset($DATA['html_msg'])) {
+                                                       if (isset($mailData['html_msg'])) {
                                                                // Send HTML?
-                                                               sendEmail(getUserData('email'), $DATA['subject'], $mailText, $DATA['html_msg']);
+                                                               sendEmail(getUserData('userid'), $mailData['subject'], $mailText, $mailData['html_msg']);
                                                        } else {
                                                                // No HTML mail!
-                                                               sendEmail(getUserData('email'), $DATA['subject'], $mailText);
+                                                               sendEmail(getUserData('userid'), $mailData['subject'], $mailText);
                                                        }
 
                                                        // Count one up and remove entry from dummy array
-                                                       $GLOBALS['pool_cnt']++; unset($dummy[$key]);
+                                                       $GLOBALS['pool_cnt']++; unset($temporaryReceivers[$key]);
 
                                                        if (isExtensionInstalledAndNewer('user', '0.1.4')) {
                                                                // Update mails received for receiver
@@ -118,7 +118,7 @@ if ($GLOBALS['pool_cnt'] < getMaxSend()) {
                                                        } // END - if
 
                                                        // Do we have send maximum mails?
-                                                       if (($GLOBALS['pool_cnt'] >= getMaxSend()) || (countSelection($dummy) == 0)) {
+                                                       if (($GLOBALS['pool_cnt'] >= getMaxSend()) || (countSelection($temporaryReceivers) == 0)) {
                                                                // Yes, we have
                                                                //* DEBUG: */ debugOutput('*EXIT/L:'.__LINE__);
                                                                break;
@@ -126,7 +126,7 @@ if ($GLOBALS['pool_cnt'] < getMaxSend()) {
                                                        break;
 
                                                default: // Unknown return type
-                                                       logDebugMessage(__FILE__, __LINE__, 'Unknown status ' . $status . ' detected. pool_id=' . $DATA['id'] . ',sender=' . $DATA['sender'] . ',stats_id=' . $stats_id);
+                                                       logDebugMessage(__FILE__, __LINE__, 'Unknown status ' . $status . ' detected. pool_id=' . $mailData['id'] . ',userid=' . $mailData['userid'] . ',stats_id=' . $stats_id);
                                                        break;
                                        } // END - switch
                                } // END - if
@@ -142,8 +142,8 @@ if ($GLOBALS['pool_cnt'] < getMaxSend()) {
                        } // 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`
@@ -154,7 +154,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
@@ -175,11 +175,11 @@ 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__.'<pre>'.print_r($dummy, true).'</pre>!!!');
+                               //* DEBUG: */ debugOutput('*L:'.__LINE__.'<pre>'.print_r($temporaryReceivers, true).'</pre>!!!');
                                break;
                        }
                } // END - while