2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 02/16/2005 *
\r
4 * =============== Last change: 01/21/2006 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : doubler_send.php *
\r
8 * -------------------------------------------------------------------- *
\r
9 * Short description : Send's out mails for doubled points *
\r
10 * -------------------------------------------------------------------- *
\r
11 * Kurzbeschreibung : Sendet Mails bei vergueteter Verdoppelung aus *
\r
12 * -------------------------------------------------------------------- *
\r
14 * -------------------------------------------------------------------- *
\r
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
\r
16 * For more information visit: http://www.mxchange.org *
\r
18 * This program is free software; you can redistribute it and/or modify *
\r
19 * it under the terms of the GNU General Public License as published by *
\r
20 * the Free Software Foundation; either version 2 of the License, or *
\r
21 * (at your option) any later version. *
\r
23 * This program is distributed in the hope that it will be useful, *
\r
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
26 * GNU General Public License for more details. *
\r
28 * You should have received a copy of the GNU General Public License *
\r
29 * along with this program; if not, write to the Free Software *
\r
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
\r
31 * MA 02110-1301 USA *
\r
32 ************************************************************************/
\r
34 // Some security stuff...
\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";
\r
41 // Initialize variables
\r
42 $jackpot = "0"; $user = "0";
\r
44 // Get total points of the doubler itself
\r
45 $DOUBLER_POINTS = DOUBLER_GET_TOTAL_POINTS_LEFT();
\r
46 if ($DOUBLER_POINTS == 0)
\r
48 // Exit here to prevent some SQL errors (SQL_QUERY_ESC doen't insert zeros! We need to fix this...)
\r
52 // If not currently doubled set it to zero
\r
53 unset($_GET['DOUBLER_UID']);
\r
54 unset($_POST['DOUBLER_UID']);
\r
55 unset($_COOKIE['DOUBLER_UID']);
\r
56 if (empty($DOUBLER_UID)) $DOUBLER_UID = "0";
\r
58 // Check for doubles which we can pay out
\r
59 $min = bigintval($CONFIG['doubler_min'] * 2);
\r
60 $result_total = SQL_QUERY_ESC("SELECT DISTINCT d.id, d.userid, d.points, d.remote_ip, d.timemark
\r
61 FROM "._MYSQL_PREFIX."_doubler AS d
\r
62 LEFT JOIN "._MYSQL_PREFIX."_user_data AS u
\r
63 ON d.userid=u.userid
\r
64 WHERE u.status='CONFIRMED' AND d.points <= %s AND d.points >= %s AND d.completed='N' AND d.is_ref='N'
\r
65 ORDER BY d.timemark", array($DOUBLER_POINTS, $min), __FILE__, __LINE__);
\r
67 // Check for accounts with limitation
\r
68 $result_main = SQL_QUERY_ESC("SELECT DISTINCT d.id, d.userid, d.points, d.remote_ip, d.timemark
\r
69 FROM "._MYSQL_PREFIX."_doubler AS d
\r
70 LEFT JOIN "._MYSQL_PREFIX."_user_data AS u
\r
71 ON d.userid=u.userid
\r
72 WHERE u.status='CONFIRMED' AND d.points <= %s AND d.points >= %s AND d.completed='N' AND d.is_ref='N'
\r
74 LIMIT %s", array($DOUBLER_POINTS, $min, $CONFIG['doubler_max_sent']), __FILE__, __LINE__);
\r
76 if (((SQL_NUMROWS($result_total) > 0) && ($CONFIG['doubler_sent_all'] == "Y")) || ((SQL_NUMROWS($result_main) == $CONFIG['doubler_group_sent']) && ($CONFIG['doubler_sent_all'] == "N")))
\r
78 // Switch to matching SQL resource
\r
79 $result_load = $result_main;
\r
80 if ((SQL_NUMROWS($result_total) > 0) && ($CONFIG['doubler_sent_all'] == "Y")) $result_load = $result_total;
\r
82 // At least one account was found
\r
83 while(list($id, $uid, $points, $ip, $time) = SQL_FETCHROW($result_load))
\r
85 // Only double when points are enougth!
\r
86 if ($DOUBLER_POINTS >= $points)
\r
88 // Check for his ref points
\r
89 $result_ref = SQL_QUERY_ESC("SELECT SUM(points) FROM "._MYSQL_PREFIX."_doubler WHERE refid=%d AND completed='N' AND is_ref='Y'",
\r
90 array(bigintval($uid)), __FILE__, __LINE__);
\r
91 list($ref) = SQL_FETCHROW($result_ref);
\r
94 SQL_FREERESULT($result_ref);
\r
96 // Zero refid when empty (might be helpful!)
\r
97 if (empty($ref)) $ref = 0;
\r
98 if (($ref > 0) && ($DOUBLER_UID == $uid) && (!empty($ref)))
\r
100 // Referral points found so add them and set line(s) to completed='Y'
\r
102 $result_ref = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_doubler SET completed='Y' WHERE refid=%d AND completed='N' AND is_ref='Y'",
\r
103 array(bigintval($uid)), __FILE__, __LINE__);
\r
107 // No referral points found
\r
111 // Exclude webmaster from doubling...
\r
112 if ($uid != $CONFIG['doubler_uid'])
\r
115 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET points=points+%s WHERE userid=%d AND ref_depth='0' LIMIT 1",
\r
116 array($points, bigintval($uid)), __FILE__, __LINE__);
\r
118 // Update mediadata as well
\r
119 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
\r
122 MEDIA_UPDATE_ENTRY(array("total_points"), "add", $points);
\r
126 // Set entry as "payed"
\r
127 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_doubler SET completed='Y' WHERE id=%d LIMIT 1",
\r
128 array(bigintval($id)), __FILE__, __LINE__);
\r
131 // Check for jackpot inclusion in doubling process
\r
132 if (($jackpot > 0) && ($jackpot >= $points) && ($CONFIG['doubler_jackpot'] == "Y"))
\r
134 // Subtract points from jackpot
\r
135 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_jackpot SET points=points-%s WHERE ok='ok' LIMIT 1",
\r
136 array($points), __FILE__, __LINE__);
\r
137 $jackpot -= $jackpot;
\r
143 // Exclude also webmaster's ID in taking points from webmaster's account
\r
144 if (($user > 0) && ($user >= $points) && (!$OK) && ($CONFIG['doubler_uid'] > 0) && ($uid != $CONFIG['doubler_uid']))
\r
146 // Add points to used points
\r
147 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET used_points=used_points+%s WHERE userid='' LIMIT 1",
\r
148 array($points, $CONFIG['doubler_uid']), __FILE__, __LINE__);
\r
150 // Update mediadata as well
\r
151 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
\r
154 MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $points);
\r
161 // Update doubler's account only when others are not updated
\r
164 // Add points to used doubler points
\r
165 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_config SET doubler_used=doubler_used+%s WHERE config='0' LIMIT 1",
\r
166 array($points), __FILE__, __LINE__);
\r
169 if (GET_EXT_VERSION("cache") >= "0.1.2")
\r
171 if ($CACHE->cache_file("config", true)) $CACHE->cache_destroy();
\r
175 // Update variables to prevent errors
\r
176 $CONFIG['doubler_used'] += $points;
\r
177 $DOUBLER_POINTS -= $points;
\r
181 // Doubler transmission ID
\r
184 'points' => TRANSLATE_COMMA($points),
\r
186 'when' => MAKE_DATETIME($time, "2"),
\r
187 // IP number when the member submitted the doubling form
\r
191 // Load mail template and send mail away...
\r
192 $msg = LOAD_EMAIL_TEMPLATE("member_doubler", $content, $uid);
\r
193 SEND_EMAIL($uid, DOUBLER_MEMBER_SUBJECT, $msg);
\r
199 SQL_FREERESULT($result_total);
\r
200 SQL_FREERESULT($result_main);
\r