]> git.mxchange.org Git - mailer.git/blobdiff - inc/pool/pool-user.php
Rewrote script to use more EL, introduced wrappers for sending pool:
[mailer.git] / inc / pool / pool-user.php
index 9d8b295dd67c06ba164926f23c3c233dae2a347b..1d074ef580d3fba3cb87981c7be51920251ff484 100644 (file)
@@ -70,7 +70,7 @@ $result_main = SQL_QUERY("SELECT
        `url`,
        `target_send`,
        `cat_id`
-       ".$HTML."
+       " . $HTML . "
 FROM
        `{?_MYSQL_PREFIX?}_pool`
 WHERE
@@ -88,12 +88,13 @@ if (!SQL_HASZERONUMS($result_main)) {
        // Parse all mails
        while ($mailData = SQL_FETCHARRAY($result_main)) {
                // Set mail order as 'active'. That means it will be sent out
-               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='ACTIVE' WHERE `id`=%s AND `data_type`='NEW' LIMIT 1",
-                       array($mailData['id']), __FILE__, __LINE__);
+               updatePoolDataById($mailData['id'], 'data_type', 'ACTIVE', NULL, " AND `data_type`='NEW'");
 
                // Check fetched data for HTML
                $isHtml = 'N';
-               if (isset($mailData['html_msg'])) $isHtml = $mailData['html_msg'];
+               if (isset($mailData['html_msg'])) {
+                       $isHtml = $mailData['html_msg'];
+               } // END - if
 
                // Entry updated?
                if (!SQL_HASZEROAFFECTED()) {
@@ -177,10 +178,6 @@ if (!SQL_HASZERONUMS($result_main)) {
                                                                // Prepare the mail
                                                                $mailData['stats_id'] = bigintval($stats_id);
 
-                                                               // Prepare content
-                                                               $mailData['time']   = getPaymentData($mailData['payment_id'], 'time');
-                                                               $mailData['points'] = getPaymentData($mailData['payment_id'], 'payment');
-
                                                                // Load message template
                                                                $mailText = loadEmailTemplate('member_user_pool_normal', $mailData, bigintval($userid));
 
@@ -230,7 +227,7 @@ if (!SQL_HASZERONUMS($result_main)) {
                                                        'cat_id'        => $mailData['cat_id'],
                                                        'text'          => $mailData['text'],
                                                        'url'           => $mailData['url'],
-                                                       'expiration'    => '{%pipe,createFancyTime=' . getPaymentData($mailData['payment_id'], 'time') . '%}'
+                                                       'expiration'    => '{%pipe,getPaymentTime,createFancyTime=' . $mailData['payment_id'] . '%}'
                                                );
 
                                                // Yes we do, so we notify admin and sender about fully sent mail!
@@ -246,8 +243,7 @@ if (!SQL_HASZERONUMS($result_main)) {
                                                } // END - if
 
                                                // Set status to SEND because we completely send it away
-                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='SEND',`target_send`=0,`receivers`='' WHERE `id`=%s LIMIT 1",
-                                                       array(bigintval($mailData['id'])), __FILE__, __LINE__);
+                                               updatePoolDataById($mailData['id'], NULL, array('data_type' => 'SEND', 'target_send' => '0', 'receivers' => '');
 
                                                // Update send-completed-time
                                                SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_stats` SET `timestamp_send`=UNIX_TIMESTAMP() WHERE `pool_id`=%s LIMIT 1",
@@ -270,12 +266,8 @@ if (!SQL_HASZERONUMS($result_main)) {
                                        elseif (($GLOBALS['pool_cnt'] >= getConfig('max_send')) || ($count2 >= getConfig('max_send'))) {
                                                // There are some mails left to send for next round, so we reset the status back to NEW (=still not fully delivered)
                                                $add = '';
-                                               if ($GLOBALS['pool_cnt'] <= $mailData['target_send']) $add = ", target_send=target_send-".$GLOBALS['pool_cnt'];
-                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='NEW', receivers='%s'" . $add . " WHERE `id`=%s LIMIT 1",
-                                                       array(
-                                                               implode(';', $temporaryReceivers),
-                                                               bigintval($mailData['id'])
-                                                       ), __FILE__, __LINE__);
+                                               if ($GLOBALS['pool_cnt'] <= $mailData['target_send']) $add = ',`target_send`=`target_send`-' . $GLOBALS['pool_cnt'];
+                                               updatePoolDataById($mailData['id'], NULL, array('data_type' => 'NEW', 'receivers' => implode(';', $temporaryReceivers)), NULL, '', $add);
 
                                                //* DEBUG: */ debugOutput('*EXIT/L:'.__LINE__.'*');
                                                break;
@@ -287,18 +279,16 @@ if (!SQL_HASZERONUMS($result_main)) {
                                        // User does not exists so we have add the sender's points back to sender's account
                                        if (($receivers['id'] == '0') || (empty($receivers['id']))) {
                                                // List was empty
-                                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `data_type`='SEND' WHERE `id`=%s LIMIT 1",
-                                                       array(bigintval($mailData['id'])), __FILE__, __LINE__);
+                                               updatePoolDataById($mailData['id'], 'data_type', 'SEND');
                                        } else {
                                                // Is the userid set?
                                                if (isValidId($userid)) {
                                                        // User does not exists, pay points back
-                                                       $points = getPaymentPrice($mailData['payment_id']);
                                                        initReferralSystem();
-                                                       addPointsThroughReferralSystem('pool_payback', $mailData['sender_userid'], $points);
+                                                       addPointsThroughReferralSystem('pool_payback', $mailData['sender_userid'], getPaymentPrice($mailData['payment_id']));
 
                                                        // Add points together and remove user
-                                                       $pointsBack[$mailData['sender_userid']] += $points;
+                                                       $pointsBack[$mailData['sender_userid']] += getPaymentPrice($mailData['payment_id']);
                                                } // END - if
 
                                                // Count up
@@ -309,8 +299,7 @@ if (!SQL_HASZERONUMS($result_main)) {
                                        unset($temporaryReceivers[$key]);
 
                                        // Update receivers
-                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_pool` SET `receivers`='%s' WHERE `id`=%s LIMIT 1",
-                                               array(implode(';', $temporaryReceivers), bigintval($mailData['id'])), __FILE__, __LINE__);
+                                       updatePoolData($mailData['id'], 'receivers', implode(';', $temporaryReceivers));
                                }
                        } // END - foreach
                } // END - if