2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 02/16/2005 *
4 * =================== Last change: 01/21/2006 *
6 * -------------------------------------------------------------------- *
7 * File : doubler_mails.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Send's out mails for doubled points *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Sendet Mails bei vergueteter Verdoppelung aus *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
41 } elseif (!isExtensionActive('doubler')) {
45 // Do not execute when script is in CSS mode
46 if (!isHtmlOutputMode()) return;
48 // Initialize variables
49 $jackpotPoints = '0'; $userPoints = '0';
50 if (isExtensionActive('jackpot')) $jackpotPoints = getJackpotPoints();
52 // Get total points of the doubler itself
53 $DOUBLER_POINTS = getDoublerTotalPointsLeft();
54 if ($DOUBLER_POINTS == '0') {
55 // Exit here to prevent some SQL errors (SQL_QUERY_ESC doen't insert zeros! We need to fix this...)
59 // If not currently doubled set it to zero
60 unsetGetRequestParameter('DOUBLER_UID');
61 unsetPostRequestParameter('DOUBLER_UID');
62 setSession('DOUBLER_UID', '');
63 if (empty($GLOBALS['local_doubler_userid'])) $GLOBALS['local_doubler_userid'] = '0';
65 // Check for doubles which we can pay out
66 $result_total = SQL_QUERY_ESC("SELECT
67 d.id, d.userid, d.points, d.remote_ip, d.timemark
69 `{?_MYSQL_PREFIX?}_doubler` AS d
71 `{?_MYSQL_PREFIX?}_user_data` AS u
75 u.`status`='CONFIRMED' AND
77 d.points >= ({?doubler_min?} * 2) AND
84 ), __FILE__, __LINE__);
86 // Check for accounts with limitation
87 $result_main = SQL_QUERY_ESC("SELECT
88 d.id, d.userid, d.points, d.remote_ip, d.timemark
90 `{?_MYSQL_PREFIX?}_doubler` AS d
92 `{?_MYSQL_PREFIX?}_user_data` AS u
96 u.`status`='CONFIRMED' AND
98 d.points >= ({?doubler_min?} * 2) AND
103 LIMIT {?doubler_max_sent?}",
106 ), __FILE__, __LINE__);
108 // Do we have entries found?
109 if (((!SQL_HASZERONUMS($result_total)) && (getConfig('doubler_sent_all') == 'Y')) || ((SQL_NUMROWS($result_main) == getConfig('doubler_group_sent')) && (getConfig('doubler_sent_all') != 'Y'))) {
110 // Switch to matching SQL resource
111 $result_load = $result_main;
112 if ((!SQL_HASZERONUMS($result_total)) && (getConfig('doubler_sent_all') == 'Y')) {
113 $result_load = $result_total;
116 // At least one account was found
117 while ($content = SQL_FETCHARRAY($result_load)) {
118 // Only double when points are enougth!
119 if ($DOUBLER_POINTS >= $content['points']) {
120 // Check for his ref points
121 $ref = countSumTotalData($content['userid'], 'doubler', 'points', 'refid', false, " AND `completed`='N' AND `is_ref`='Y'");
123 // Zero refid when empty (might be helpful!)
124 if (empty($ref)) $ref = '0';
126 if (($ref > 0) && ($GLOBALS['local_doubler_userid'] == $content['userid']) && (!empty($ref))) {
127 // Referal points found so add them and set line(s) to completed='Y'
128 $content['points'] += $ref;
129 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_doubler` SET `completed`='Y' WHERE `refid`=%s AND `completed`='N' AND `is_ref`='Y'",
130 array(bigintval($content['userid'])), __FILE__, __LINE__);
132 // No referal points found
136 // Exclude webmaster from doubling...
137 if ($content['userid'] != getConfig('doubler_userid')) {
139 addPointsDirectly(sprintf("doubler_%s", strtolower(getConfig('doubler_send_mode'))), $content['userid'], $content['points']);
142 // Set entry as "payed"
143 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_doubler` SET `completed`='Y' WHERE `id`=%s LIMIT 1",
144 array(bigintval($content['id'])), __FILE__, __LINE__);
148 // Check for jackpot inclusion in doubling process
149 if (($jackpotPoints > 0) && ($jackpotPoints >= $content['points']) && (getConfig('doubler_jackpot') == 'Y')) {
150 // Subtract points from jackpot
151 subtractPointsFromJackpot($content['points']);
152 $jackpotPoints -= $content['points'];
158 // Exclude also webmaster's id in taking points from webmaster's account
159 if (($userPoints > 0) && ($userPoints >= $content['points']) && ($okay === false) && (getConfig('doubler_userid') > 0) && ($content['userid'] != getConfig('doubler_userid'))) {
160 // Add points to used points
161 subtractPoints('doubler_payout', getConfig('doubler_userid'), $content['points']);
167 // Update doubler's account only when others are not updated
168 if ($okay === false) {
169 // Add points to used doubler points
170 updateConfiguration('doubler_used', $content['points'], '+');
173 // Update variables to prevent errors
174 incrementConfigEntry('doubler_used', $content['points']);
175 $DOUBLER_POINTS -= $content['points'];
178 $content['timemark'] = generateDateTime($content['timemark'], 2);
180 // Load mail template and send mail away...
181 $message = loadEmailTemplate('member_doubler', $content, $content['userid']);
182 sendEmail($content['userid'], '{--MEMBER_DOUBLER_SUBJECT--}', $message);
188 SQL_FREERESULT($result_total);
189 SQL_FREERESULT($result_main);