// Recuce the amount of received emails for the receipients for given email
function reduceRecipientReceivedMails ($column, $id, $count) {
// Search for mail in database
- $result = SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s",
+ $result = SQL_QUERY_ESC("SELECT * FROM `{?_MYSQL_PREFIX?}_user_links` WHERE `%s`=%s ORDER BY `userid` ASC LIMIT %s",
array($column, bigintval($id), $count), __FUNCTION__, __LINE__);
// Are there entries?
if (SQL_NUMROWS($result) > 0) {
// Now load all userids for one big query!
- // @TODO This can be somehow rewritten
$userids = array();
- while (list($userid) = SQL_FETCHROW($result)) {
- $userids[$userid] = $userid;
+ while ($data = SQL_FETCHARRAY($result)) {
+ // By default we want to reduce and have no mails found
+ $num = 0;
+
+ // We must now look if he has already confirmed this mail, so might sound double, but it may resolve problems
+ // @TODO Rewrite this to a filter
+ if ((isset($data['stats_id'])) && ($data['stats_id'] > 0)) {
+ // User email
+ $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', true, sprintf(" AND `stats_type`='mailid' AND `stats_data`=%s", bigintval($data['stats_id'])));
+ } elseif ((isset($data['bonus_id'])) && ($data['bonus_id'] > 0)) {
+ // Bonus mail
+ $num = countSumTotalData($data['userid'], 'user_stats_data', 'id', 'userid', true, sprintf(" AND `stats_type`='bonusid' AND `stats_data`=%s", bigintval($data['bonus_id'])));
+ }
+
+ // Reduce this users total received emails?
+ if ($num === 0) $userids[$data['userid']] = $data['userid'];
} // END - while
// Now update all user accounts
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
$P = $GLOBALS['pool_cnt'];
if (!empty($cnt2) && empty($GLOBALS['pool_cnt'])) $P = $cnt2;
//* DEBUG: */ print("+MEDIA/L:".__LINE__.'/'.$P."+<br />");
- updateMediadataEntry(array("total_send", "bonus_send"), 'add', $P);
+ updateMediadataEntry(array('total_send', 'bonus_send'), 'add', $P);
} // END - if
// Close sending system
if (getExtensionVersion('mediadata') >= '0.0.4') {
// Update entry (or add missing)
//* DEBUG: */ print("*MEDIA/L:".__LINE__."*<br />");
- updateMediadataEntry(array("total_orders", "bonus_orders"), 'add', 1);
+ updateMediadataEntry(array('total_orders', 'bonus_orders'), 'add', 1);
} // END - if
} elseif ($GLOBALS['pool_cnt'] >= getConfig('max_send')) {
// Update bonus pool
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