X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fpool-update.php;h=bc5ea6fd70f24a4611bac1df906d3e5e2b634650;hb=d798a412acb8c1263933bd7f7a0fd9aa251495a7;hp=a6ef8e18ebd34d3fdce5458053649154966eae7f;hpb=f01652b7b8efac92d97889e312402c4a845c2f14;p=mailer.git diff --git a/inc/pool-update.php b/inc/pool-update.php index a6ef8e18eb..bc5ea6fd70 100644 --- a/inc/pool-update.php +++ b/inc/pool-update.php @@ -32,23 +32,25 @@ ************************************************************************/ // Some security stuff... -if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) -{ +if (!defined('__SECURITY')) { $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php"; require($INC); } +// Don't run on daily reset +if (defined('__DAILY_RESET')) { + // Skip here + return false; +} // END - if + // Test html extensions once $HTML_EXT = EXT_IS_ACTIVE("html_mail", true); // Check for freed mail orders to send out -if ($HTML_EXT) -{ +if ($HTML_EXT) { // 0 1 2 3 4 5 6 7 8 9 10 $result_main = SQL_QUERY("SELECT id, sender, subject, text, receivers, payment_id, timestamp, url, target_send, cat_id, html_msg FROM "._MYSQL_PREFIX."_pool WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__); -} - else -{ +} else { // 0 1 2 3 4 5 6 7 8 9 10 $result_main = SQL_QUERY("SELECT id, sender, subject, text, receivers, payment_id, timestamp, url, target_send, cat_id, id FROM "._MYSQL_PREFIX."_pool WHERE data_type='NEW' ORDER BY timestamp DESC", __FILE__, __LINE__); } @@ -60,14 +62,14 @@ if (SQL_NUMROWS($result_main) > 0) while ($DATA = SQL_FETCHROW($result_main)) { // Check fetched data for HTML - $HTML = $DATA[10]; if ($HTML == $DATA['id']) $HTML = "N"; + $HTML = $DATA[10]; if ($HTML == $DATA[0]) $HTML = "N"; // Compile URL and subject line $DATA[7] = COMPILE_CODE($DATA[7]); // Set mail order as "active". That means it will be sent out $result_active = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='ACTIVE' WHERE id=%s AND data_type='NEW' LIMIT 1", - array($DATA['id']), __FILE__, __LINE__); + array($DATA[0]), __FILE__, __LINE__); if (SQL_AFFECTEDROWS() == 1) { // "Explode" all receivers into an array @@ -108,19 +110,19 @@ if (SQL_NUMROWS($result_main) > 0) // Do we have a stats entry? $result_stats = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%s AND userid=%s AND timestamp_ordered='%s' LIMIT 1", - array($DATA['id'], $DATA[1], $DATA[6]), __FILE__, __LINE__); + array($DATA[0], $DATA[1], $DATA[6]), __FILE__, __LINE__); // If there's no stats entry add it! //* DEBUG: */ echo "!L:".__LINE__."/".SQL_NUMROWS($result_stats)."!
"; if (SQL_NUMROWS($result_stats) == 0) { // No entry was found, so we add him! - $result_stats = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_stats (pool_id , userid, cat_id, payment_id, subject, url , max_rec , timestamp_ordered, timestamp_sstart) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' , UNIX_TIMESTAMP())", - array(bigintval($DATA['id']), bigintval($DATA[1]), bigintval($DATA[9]), bigintval($DATA[5]), $DATA[2], $DATA[7], $DATA[8], bigintval($DATA[6])), __FILE__, __LINE__); + $result_stats = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_stats (pool_id , userid, cat_id, payment_id, subject, url , max_rec , timestamp_ordered, timestamp_sstart) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s' , UNIX_TIMESTAMP())", + array(bigintval($DATA[0]), bigintval($DATA[1]), bigintval($DATA[9]), bigintval($DATA[5]), $DATA[2], $DATA[7], $DATA[8], bigintval($DATA[6])), __FILE__, __LINE__); // Receive it's ID for the links table $result_stats = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_stats WHERE pool_id=%s AND userid=%s AND timestamp_ordered='%s' LIMIT 1", - array(bigintval($DATA['id']), bigintval($DATA[1]), bigintval($DATA[6])), __FILE__, __LINE__); + array(bigintval($DATA[0]), bigintval($DATA[1]), bigintval($DATA[6])), __FILE__, __LINE__); } //* DEBUG: */ echo "!L:".__LINE__."/".SQL_NUMROWS($result_stats)."!
"; @@ -131,8 +133,8 @@ if (SQL_NUMROWS($result_main) > 0) SQL_FREERESULT($result_stats); // Mark this user as "spammed" ;-) And place a line for him... - //* DEBUG: */ echo "?L:".__LINE__."/".$dummy."/".$key."/".$uid."(".$DATA[1].")/".$DATA['id']."/".$stats_id."?
"; - switch (REMOVE_RECEIVER($dummy, $key, bigintval($uid), bigintval($DATA['id']), bigintval($stats_id))) + //* DEBUG: */ echo "?L:".__LINE__."/".$dummy."/".$key."/".$uid."(".$DATA[1].")/".$DATA[0]."/".$stats_id."?
"; + switch (REMOVE_RECEIVER($dummy, $key, bigintval($uid), bigintval($DATA[0]), bigintval($stats_id))) { case "done": // Prepare the mail @@ -149,7 +151,7 @@ if (SQL_NUMROWS($result_main) > 0) // Prepare content $content = array( 'id' => $DATA[11], - 'url' => $DATA[3], + 'url' => $DATA[7], 'sender_uid' => $DATA[1], 'category' => GET_CATEGORY($DATA[9]), 'time' => CREATE_FANCY_TIME(GET_PAY_POINTS($DATA[5], "time")), @@ -194,12 +196,15 @@ if (SQL_NUMROWS($result_main) > 0) } // Do we have reached the maximum to send mails? || ($_CONFIG['max_send'] >= $cnt) - //* DEBUG: */ echo "*L:".__LINE__."/".$cnt.">=".$DATA[8]."/".$_CONFIG['max_send'].">=".$cnt."/".$LAST_SENT_ID."!=".$DATA['id']."*
"; - if ((($cnt >= $DATA[8])) && ($LAST_SENT_ID != $DATA['id'])) { + //* DEBUG: */ echo "*L:".__LINE__."/".$cnt.">=".$DATA[8]."/".$_CONFIG['max_send'].">=".$cnt."/".$LAST_SENT_ID."!=".$DATA[0]."*
"; + if ((($cnt >= $DATA[8])) && ($LAST_SENT_ID != $DATA[0])) { // Prepare content $content = array( 'sender_uid' => $DATA[1], - 'category' => GET_CATEGORY($DATA[9]) + 'category' => GET_CATEGORY($DATA[9]), + 'text' => $DATA[3], + 'url' => $DATA[7], + 'expiration' => CREATE_FANCY_TIME(GET_PAY_POINTS($DATA[5], "time")) ); // Yes we do, so we notify admin and sender about fully sent mail! @@ -207,7 +212,9 @@ if (SQL_NUMROWS($result_main) > 0) // Get sender's data $result_sender = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", - array(bigintval($DATA[1])), __FILE__, __LINE__); + array(bigintval($DATA[1])), __FILE__, __LINE__); + + // Is the sender found? if (SQL_NUMROWS($result_sender) == 1) { // Load data and prepare mail list($sname, $fname, $email) = SQL_FETCHROW($result_sender); @@ -218,85 +225,75 @@ if (SQL_NUMROWS($result_main) > 0) // Send it also waway SEND_EMAIL($email, MEMBER_SUBJ_SEND_DONE, $msg); - } + } // END - if // Set status to SEND because we completely send it away $result_done = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='SEND', target_send='0', receivers='' WHERE id=%s LIMIT 1", - array(bigintval($DATA['id'])), __FILE__, __LINE__); + array(bigintval($DATA[0])), __FILE__, __LINE__); // Update send-completed-time $result_user = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_stats SET timestamp_send=UNIX_TIMESTAMP() WHERE pool_id=%s LIMIT 1", - array(bigintval($DATA['id'])), __FILE__, __LINE__); + array(bigintval($DATA[0])), __FILE__, __LINE__); - $LAST_SENT_ID = $DATA['id']; $cnt = 0; + $LAST_SENT_ID = $DATA[0]; $cnt = 0; $cnt2 += $cnt; // Update mediadata if version is 0.0.4 or higher - if (GET_EXT_VERSION("mediadata") >= "0.0.4") - { + if (GET_EXT_VERSION("mediadata") >= "0.0.4") { // Update entry (or add missing) //* DEBUG: */ echo "*MEDIA/L:".__LINE__."*
"; MEDIA_UPDATE_ENTRY(array("total_orders", "normal_orders"), "add", 1); - } + } // END - if //* DEBUG: */ echo"*EXIT/L:".__LINE__."/".$P."
"; break; } // Do we have send maximum mails? - elseif (($cnt >= $_CONFIG['max_send']) || ($cnt2 >= $_CONFIG['max_send'])) - { + elseif (($cnt >= $_CONFIG['max_send']) || ($cnt2 >= $_CONFIG['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 ($cnt <= $DATA[8]) $ADD = ", target_send=target_send-".$cnt; $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='NEW', receivers='%s'".$ADD." WHERE id=%s LIMIT 1", - array(implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__); + array(implode(";", $dummy), bigintval($DATA[0])), __FILE__, __LINE__); //* DEBUG: */ echo"*EXIT/L:".__LINE__."*
"; break; } - } - else - { + } else { // User does not exists so we have add the sender's points back to sender's account - if (($RECEIVERS[0] == "0") || (empty($RECEIVERS[0]))) - { + if (($RECEIVERS[0] == "0") || (empty($RECEIVERS[0]))) { // List was empty $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET data_type='SEND' WHERE id=%s LIMIT 1", - array(bigintval($DATA['id'])), __FILE__, __LINE__); - } - else - { - if ($uid > 0) - { + array(bigintval($DATA[0])), __FILE__, __LINE__); + } else { + // Is the userid set? + if ($uid > 0) { // User does not exists, pay points back $points = GET_PAY_POINTS($DATA[5]); - $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET points=points+%s WHERE userid=%s AND ref_depth=0 LIMIT 1", - array($points, bigintval($DATA[1])), __FILE__, __LINE__); - - // Update mediadata as well - if (GET_EXT_VERSION("mediadata") >= "0.0.4") - { - // Update database - //* DEBUG: */ echo "*MEDIA/L:".__LINE__."/".$points."*
"; - MEDIA_UPDATE_ENTRY(array("total_points"), "add", $points); - } + ADD_POINTS_REFSYSTEM("pool_payback", $DATA[1], $points, false, "0", false, "direct"); // Add points together and remove user $points_BACK[$DATA[1]] += $points; - } + } // END - if + + // Count up $cnt_back[$DATA[1]]++; } + // Remove entry from list unset($dummy[$key]); // Update receivers $result_queue = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_pool SET receivers='%s' WHERE id=%s LIMIT 1", - array(implode(";", $dummy), bigintval($DATA['id'])), __FILE__, __LINE__); + array(implode(";", $dummy), bigintval($DATA[0])), __FILE__, __LINE__); } } } } + + // Do we have points to "pay back"? if ((sizeof($points_BACK) > 0) && (!empty($points_BACK[0]))) { + // Walk through all points foreach ($points_BACK as $uid => $PB) { // Add points only when we have points left to add and a valid user ID if (($PB > 0) && ($uid > 0)) { @@ -309,6 +306,8 @@ if (SQL_NUMROWS($result_main) > 0) $result = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1", array(bigintval($uid)), __FILE__, __LINE__); $DATA[10] = $PB; $DATA[11] = $cnt_back[$uid]; + + // User found? if (SQL_NUMROWS($result) == 1) { list($email) = SQL_FETCHROW($result); SQL_FREERESULT($result); @@ -325,9 +324,9 @@ if (SQL_NUMROWS($result_main) > 0) // Send mail out to admin SEND_ADMIN_NOTIFICATION(ADMIN_BACK_JACKPOT." (".$uid.")", "back-admin", $content, "admin"); } - } - } - } + } // END - if + } // END - foreach + } // END - if } // Free memory