- $UIDs = "";
- while(list($uid, $email, $points) = SQL_FETCHROW($result_main))
- {
- // Add userids in a row
- $UIDs .= ",'".$uid."'";
-
- // Add points to user's account directly
- $result_data = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points
-SET points=points+%s WHERE ref_depth=0 AND userid=%s LIMIT 1",
- array($points, bigintval($uid)), __FILE__, __LINE__);
-
- // Update mediadata as well
- if (GET_EXT_VERSION("mediadata") >= "0.0.4")
- {
- // Update database
- MEDIA_UPDATE_ENTRY(array("total_points"), "add", $points);
- }
-
- // Load email template and email it away
- $msg = LOAD_EMAIL_TEMPLATE("member_bonus", $points, bigintval($uid));
- SEND_EMAIL($email, BONUS_MONTHLY_ONLINE_BONUS, $msg);
- }
- // Remove first commata
- $UIDs = substr($UIDs, 1);
-
- // Get current month
- $curr = date("m", time());
- if (strlen($curr) == 1) $curr = "0".$curr;
- if ($curr == "00") $curr = "12";
-
- // Reset accounts
- $result = SQL_QUERY("UPDATE "._MYSQL_PREFIX."_user_data
-SET turbo_bonus=0, login_bonus=0, bonus_order=0, bonus_stats=0, bonus_ref=0", __FILE__, __LINE__);
-
- }
+ while ($content = SQL_FETCHARRAY($result_main)) {
+ // Make sure zero points are not mailed
+ if ($content['points'] > 0) {
+ // Add points to user's account directly
+ addPointsDirectly('monthly_bonus', $content['userid'], $content['points']);
+
+ // Load email template and email it away
+ $message = loadEmailTemplate('member_bonus', $content, bigintval($content['userid']));
+ sendEmail($content['email'], '{--MEMBER_MONTHLY_BONUS_WON_SUBJECT--}', $message);
+ } // END - if
+ } // END - while
+
+ // Reset all accounts
+ $result = SQL_QUERY('UPDATE `{?_MYSQL_PREFIX?}_user_data`
+SET
+ `turbo_bonus`=0,
+ `login_bonus`=0,
+ `bonus_order`=0,
+ `bonus_stats`=0,
+ `bonus_ref`=0', __FILE__, __LINE__);
+ } // END - if