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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
42 } elseif (!isExtensionActive('doubler')) {
46 // Do not execute when script is in CSS mode
47 if (getOutputMode() != 0) return;
49 // Initialize variables
50 $jackpot = '0'; $user = '0';
51 if (isExtensionActive('jackpot')) $jackpot = getJackpotPoints();
53 // Get total points of the doubler itself
54 $DOUBLER_POINTS = DOUBLER_GET_TOTAL_POINTS_LEFT();
55 if ($DOUBLER_POINTS == '0') {
56 // Exit here to prevent some SQL errors (SQL_QUERY_ESC doen't insert zeros! We need to fix this...)
60 // If not currently doubled set it to zero
61 unsetGetRequestParameter('DOUBLER_UID');
62 unsetPostRequestParameter('DOUBLER_UID');
63 setSession('DOUBLER_UID', '');
64 if (empty($GLOBALS['doubler_userid'])) $GLOBALS['doubler_userid'] = '0';
66 // Check for doubles which we can pay out
67 $result_total = SQL_QUERY_ESC("SELECT
68 d.id, d.userid, d.points, d.remote_ip, d.timemark
70 `{?_MYSQL_PREFIX?}_doubler` AS d
72 `{?_MYSQL_PREFIX?}_user_data` AS u
76 u.`status`='CONFIRMED' AND
78 d.points >= ({?doubler_min?} * 2) AND
85 ), __FILE__, __LINE__);
87 // Check for accounts with limitation
88 $result_main = SQL_QUERY_ESC("SELECT
89 d.id, d.userid, d.points, d.remote_ip, d.timemark
91 `{?_MYSQL_PREFIX?}_doubler` AS d
93 `{?_MYSQL_PREFIX?}_user_data` AS u
97 u.`status`='CONFIRMED' AND
99 d.points >= ({?doubler_min?} * 2) AND
104 LIMIT {?doubler_max_sent?}",
107 ), __FILE__, __LINE__);
109 // Do we have entries found?
110 if (((SQL_NUMROWS($result_total) > 0) && (getConfig('doubler_sent_all') == 'Y')) || ((SQL_NUMROWS($result_main) == getConfig('doubler_group_sent')) && (getConfig('doubler_sent_all') != 'Y'))) {
111 // Switch to matching SQL resource
112 $result_load = $result_main;
113 if ((SQL_NUMROWS($result_total) > 0) && (getConfig('doubler_sent_all') == 'Y')) $result_load = $result_total;
115 // At least one account was found
116 while ($content = SQL_FETCHARRAY($result_load)) {
117 // Only double when points are enougth!
118 if ($DOUBLER_POINTS >= $content['points']) {
119 // Check for his ref points
120 $ref = countSumTotalData($content['userid'], 'doubler', 'points', 'refid', false, " AND `completed`='N' AND `is_ref`='Y'");
122 // Zero refid when empty (might be helpful!)
123 if (empty($ref)) $ref = '0';
125 if (($ref > 0) && ($GLOBALS['doubler_userid'] == $content['userid']) && (!empty($ref))) {
126 // Referal points found so add them and set line(s) to completed='Y'
127 $content['points'] += $ref;
128 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_doubler` SET `completed`='Y' WHERE `refid`=%s AND `completed`='N' AND `is_ref`='Y'",
129 array(bigintval($content['userid'])), __FILE__, __LINE__);
131 // No referal points found
135 // Exclude webmaster from doubling...
136 if ($content['userid'] != getConfig('doubler_userid')) {
138 addPointsDirectly(sprintf("doubler_%s", strtolower(getConfig('doubler_send_mode'))), $content['userid'], $content['points']);
141 // Set entry as "payed"
142 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_doubler` SET `completed`='Y' WHERE `id`=%s LIMIT 1",
143 array(bigintval($content['id'])), __FILE__, __LINE__);
147 // Check for jackpot inclusion in doubling process
148 if (($jackpot > 0) && ($jackpot >= $content['points']) && (getConfig('doubler_jackpot') == 'Y')) {
149 // Subtract points from jackpot
150 subtractPointsFromJackpot($content['points']);
151 $jackpot -= $content['points'];
157 // Exclude also webmaster's id in taking points from webmaster's account
158 if (($user > 0) && ($user >= $content['points']) && ($okay === false) && (getConfig('doubler_userid') > 0) && ($content['userid'] != getConfig('doubler_userid'))) {
159 // Add points to used points
160 subtractPoints('doubler_payout', getConfig('doubler_userid'), $content['points']);
166 // Update doubler's account only when others are not updated
167 if ($okay === false) {
168 // Add points to used doubler points
169 updateConfiguration('doubler_used', $content['points'], '+');
172 // Update variables to prevent errors
173 incrementConfigEntry('doubler_used', $content['points']);
174 $DOUBLER_POINTS -= $content['points'];
178 // Doubler transmission id
179 'id' => $content['id'],
181 'points' => translateComma($content['points']),
183 'when' => generateDateTime($content['timemark'], 2),
184 // IP number when the member submitted the doubling form
185 'ip' => $content['remote_ip'],
188 // Load mail template and send mail away...
189 $message = loadEmailTemplate('member_doubler', $content, $content['userid']);
190 sendEmail($content['userid'], getMessage('DOUBLER_MEMBER_SUBJECT'), $message);
196 SQL_FREERESULT($result_total);
197 SQL_FREERESULT($result_main);