]> git.mxchange.org Git - mailer.git/blobdiff - inc/pool/pool-bonus.php
Now total received mails are reduced if no entry in user_stats_data is found
[mailer.git] / inc / pool / pool-bonus.php
index a93fa52e7d4dc614f90094151fac49b4bc4eabe9..6baa5b7705d1b567bb09f23b13274ebc5eb00802 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 12/12/2008 *
- * ===============                              Last change: 12/12/2008 *
+ * Mailer v0.2.1-FINAL                                Start: 12/12/2008 *
+ * ===================                          Last change: 12/12/2008 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : pool-bonus.php                                   *
@@ -73,29 +73,23 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
                        // "Explode" all receivers into an array
                        if (ereg(';', $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 left us some user-ids.
+                       // 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
-                               //* DEBUG: */ outputHtml("*L:".__LINE__.'/'.$userid."*<br />");
-                               $result_user = SQL_QUERY_ESC("SELECT `surname`, `family`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
-                                       array(bigintval($userid)), __FILE__, __LINE__);
-
-                               // Is his data available?
-                               if (SQL_NUMROWS($result_user) == 1) {
+                               if (fetchUserData($userid)) {
                                        // The final receiver does exists so we can continue...
-                                       list($surname, $family, $email) = SQL_FETCHROW($result_user);
-                                       //* DEBUG: */ outputHtml("OK!/L:".__LINE__."<br />");
+                                       //* DEBUG: */ print("OK!/L:".__LINE__."<br />");
 
                                        // Mark this user as "spammed" ;-) And place a line for him...
                                        if (removeReceiver($dummy, $key, $userid, $DATA['id'], $DATA['id'], true) == 'done') {
@@ -120,10 +114,10 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
                                                // Send mail away
                                                if (isset($DATA['html_msg'])) {
                                                        // Send HTML?
-                                                       sendEmail($email, $DATA['subject'], $mailText, $DATA['html_msg']);
+                                                       sendEmail(getUserData('email'), $DATA['subject'], $mailText, $DATA['html_msg']);
                                                } else {
                                                        // No HTML mail!
-                                                       sendEmail($email, $DATA['subject'], $mailText);
+                                                       sendEmail(getUserData('email'), $DATA['subject'], $mailText);
                                                }
 
                                                // Count one up and remove entry from dummy array
@@ -131,53 +125,50 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
 
                                                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",
+                                                       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)) {
+                                               if (($GLOBALS['pool_cnt'] >= getConfig('max_send')) || (countSelection($dummy) == '0')) {
                                                        // Yes, we have
-                                                       //* DEBUG: */ outputHtml("*EXIT/L:".__LINE__."<br />");
+                                                       //* DEBUG: */ print("*EXIT/L:".__LINE__."<br />");
                                                        break;
                                                } // END - if
                                        } // END - if
                                } // END - if
-
-                               // Free some memory
-                               SQL_FREERESULT($result_user);
-                       }
+                       } // END - foreach
 
                        // Update mediadata if version is 0.0.4 or higher
                        if (getExtensionVersion('mediadata') >= '0.0.4') {
                                // Update entry (or add missing
                                $P = $GLOBALS['pool_cnt'];
                                if (!empty($cnt2) && empty($GLOBALS['pool_cnt'])) $P = $cnt2;
-                               //* DEBUG: */ outputHtml("+MEDIA/L:".__LINE__.'/'.$P."+<br />");
-                               updateMediadataEntry(array("total_send", "bonus_send"), 'add', $P);
+                               //* DEBUG: */ print("+MEDIA/L:".__LINE__.'/'.$P."+<br />");
+                               updateMediadataEntry(array('total_send', 'bonus_send'), 'add', $P);
                        } // END - if
 
                        // Close sending system
-                       //* DEBUG: */ outputHtml("-L:".__LINE__.'/'.countSelection($dummy)."-<br />");
-                       if (countSelection($dummy) == 0) {
+                       //* DEBUG: */ print("-L:".__LINE__.'/'.countSelection($dummy)."-<br />");
+                       if (countSelection($dummy) == '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: */ outputHtml("*L:".__LINE__."*<br />");
+                               //* DEBUG: */ print("*L:".__LINE__."*<br />");
 
                                // Update mediadata if version is 0.0.4 or higher
                                if (getExtensionVersion('mediadata') >= '0.0.4') {
                                        // Update entry (or add missing)
-                                       //* DEBUG: */ outputHtml("*MEDIA/L:".__LINE__."*<br />");
-                                       updateMediadataEntry(array("total_orders", "bonus_orders"), 'add', 1);
+                                       //* DEBUG: */ print("*MEDIA/L:".__LINE__."*<br />");
+                                       updateMediadataEntry(array('total_orders', 'bonus_orders'), 'add', 1);
                                } // END - if
                        } elseif ($GLOBALS['pool_cnt'] >= getConfig('max_send')) {
                                // 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: */ outputHtml("*L:".__LINE__."<pre>");
-                               //* DEBUG: */ outputHtml(print_r($dummy, true));
-                               //* DEBUG: */ outputHtml("</pre>\n!!!<br />");
+                               //* DEBUG: */ print("*L:".__LINE__."<pre>");
+                               //* DEBUG: */ print(print_r($dummy, true));
+                               //* DEBUG: */ print("</pre>\n!!!<br />");
                                break;
                        }
                }