2 /************************************************************************
3 * MXChange v0.2.1 Start: 02/13/2005 *
4 * =============== Last change: 02/13/2005 *
6 * -------------------------------------------------------------------- *
8 * -------------------------------------------------------------------- *
9 * Short description : Points doubler *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Punkteverdoppler *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
35 require_once("inc/libs/security_functions.php");
37 // Init "action" and "what"
38 global $what, $action;
39 $GLOBALS['what'] = ""; $GLOBALS['action'] = "";
42 $GLOBALS['module'] = "doubler";
43 $GLOBALS['refid'] = 0;
46 // Load the required file(s)
47 require ("inc/config.php");
49 // Is the script installed?
50 if (defined('mxchange_installed') && (mxchange_installed))
52 // Probe for referral ID
53 if (!empty($_GET['refid'])) $GLOBALS['refid'] = bigintval($_GET['refid']);
55 // Probe for nickname extension and if a nickname was supplied by URL
56 $probe_nickname = ((EXT_IS_ACTIVE("nickname")) && (("".round($GLOBALS['refid'])."") != $GLOBALS['refid']));
59 // Nickname in URL, so load the ID
60 $result = SQL_QUERY_ESC("SELECT userid, status FROM "._MYSQL_PREFIX."_user_data WHERE nickname='%s' LIMIT 1",
61 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
65 // Direct userid entered
66 $result = SQL_QUERY_ESC("SELECT userid, status FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
67 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
71 list($rid, $status_ref) = SQL_FETCHROW($result);
72 $GLOBALS['refid'] = bigintval($rid);
75 SQL_FREERESULT($result);
78 // If no account was found set default refid and status to CONFIRMED
79 if (empty($GLOBALS['refid'])) { $GLOBALS['refid'] = $CONFIG['def_refid']; $status = "CONFIRMED"; }
81 // Begin with doubler script...
82 if (isset($_POST['ok']))
84 // Secure points (so only integer/double values are allowed
85 $_POST['points'] = bigintval($_POST['points']);
87 // Begin with doubling process
88 if ((!empty($_POST['userid'])) && (!empty($_POST['pass'])) && (!empty($_POST['points'])))
90 // Probe for nickname extension and if a nickname was entered
91 $probe_nickname = ((EXT_IS_ACTIVE("nickname")) && (("".round($_POST['userid'])."") != $_POST['userid']));
94 // Nickname in URL, so load the ID
95 $result = SQL_QUERY_ESC("SELECT userid, status, password FROM "._MYSQL_PREFIX."_user_data WHERE nickname='%s' LIMIT 1",
96 array($_POST['userid']), __FILE__, __LINE__);
100 // Direct userid entered
101 $result = SQL_QUERY_ESC("SELECT userid, status, password FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
102 array(bigintval($_POST['userid'])), __FILE__, __LINE__);
106 list($uid, $status, $password) = SQL_FETCHROW($result);
107 $uid = bigintval($uid);
110 SQL_FREERESULT($result);
112 // Remove any dots and unwanted chars from the points
113 $_POST['points'] = bigintval(round(str_replace(",", ".", $_POST['points'])));
115 // Probe for enough points
116 $probe_points = (($_POST['points'] >= $CONFIG['doubler_min']) && ($_POST['points'] <= $CONFIG['doubler_max']));
118 // Check all together
119 if ((!empty($uid)) && ($password == generateHash($_POST['pass'], substr($password, 0, -40))) && ($status == "CONFIRMED") && ($probe_points))
121 // Nickname resolved to a unique userid or direct userid entered by the member
125 $POINTS = GET_TOTAL_DATA($uid, "user_points", "points") - GET_TOTAL_DATA($uid, "user_data", "used_points");
127 // So let's continue with probing his points amount
128 if (($POINTS - $CONFIG['doubler_left'] - $_POST['points'] * $CONFIG['doubler_charge']) >= 0)
130 // Enough points are left so let's continue with the doubling process
131 // Create doubling "account" width *DOUBLED* points
132 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_doubler (userid, refid, points, remote_ip, timemark, completed, is_ref) VALUES ('%s', '%s', '%s', '".$_SERVER['REMOTE_ADDR']."', UNIX_TIMESTAMP(), 'N', 'N')",
133 array($uid, bigintval($GLOBALS['refid']), bigintval($_POST['points'] * 2)), __FILE__, __LINE__);
135 // Subtract entered points
136 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET used_points=used_points+%s WHERE userid=%d LIMIT 1",
137 array($_POST['points'], $uid), __FILE__, __LINE__);
139 // Update mediadata as well
140 if (GET_EXT_VERSION("mediadata") >= "0.0.4")
143 MEDIA_UPDATE_ENTRY(array("total_points"), "sub", $_POST['points']);
146 // Add points to "total payed" including charge
147 $points = $_POST['points'] - $_POST['points'] * $CONFIG['doubler_charge'];
148 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_config SET doubler_points=doubler_points+%s WHERE config='0' LIMIT 1",
149 array($points), __FILE__, __LINE__);
150 $CONFIG['doubler_points'] += $points;
153 if (GET_EXT_VERSION("cache") >= "0.1.2")
155 if ($CACHE->cache_file("config", true)) $CACHE->cache_destroy();
158 // Add second line for the referral but only when uid != refid
159 if (($GLOBALS['refid'] > 0) && ($GLOBALS['refid'] != $uid))
161 // Okay add a refid line and apply refid percents
162 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_doubler (userid, refid, points, remote_ip, timemark, completed, is_ref) VALUES ('%s', '0', '%s', '".$_SERVER['REMOTE_ADDR']."', UNIX_TIMESTAMP(), 'N', 'Y')",
163 array(bigintval($GLOBALS['refid']), bigintval($_POST['points'] * 2 * $CONFIG['doubler_ref'])), __FILE__, __LINE__);
165 // And that's why we dont't want to you more than one referral level of doubler-points. ^^^
168 // Update usage counter
169 $result = SQL_QUERY("UPDATE "._MYSQL_PREFIX."_config SET doubler_counter=doubler_counter+1 WHERE config='0' LIMIT 1", __FILE__, __LINE__);
170 $CONFIG['doubler_counter']++;
173 define('__DOUBLER_MSG', LOAD_TEMPLATE("doubler_reflink", true, $_POST['userid']));
177 // Not enougth points left
178 define('__ERROR_MSG', DOUBLER_FORM_NO_POINTS_LEFT);
182 elseif ($status == "CONFIRMED")
184 // Account is unconfirmed!
185 define('__ERROR_MSG', DOUBLER_FORM_WRONG_PASS);
187 elseif ($status == "UNCONFIRMED")
189 // Account is unconfirmed!
190 define('__ERROR_MSG', DOUBLER_FORM_STATUS_UNCONFIRMED);
192 elseif ($status == "LOCKED")
194 // Account is locked by admin / holiday!
195 define('__ERROR_MSG', DOUBLER_FORM_STATUS_LOCKED);
197 elseif ($_POST['points'] < $CONFIG['doubler_min'])
199 // Not enougth points entered
200 define('__ERROR_MSG', DOUBLER_FORM_POINTS_MIN);
202 elseif ($_POST['points'] > $CONFIG['doubler_max'])
204 // Too much points entered
205 define('__ERROR_MSG', DOUBLER_FORM_POINTS_MAX);
207 elseif ($probe_nickname)
209 // Cannot resolv nickname -> userid
210 define('__ERROR_MSG', DOUBLER_FORM_404_NICKNAME);
214 // Wrong password or account not found
215 define('__ERROR_MSG', DOUBLER_FORM_404_MEMBER);
218 elseif (empty($_POST['userid']))
221 define('__ERROR_MSG', DOUBLER_FORM_404_LOGIN);
223 elseif (empty($_POST['pass']))
225 // Password not entered
226 define('__ERROR_MSG', DOUBLER_FORM_404_PASSWORD);
228 elseif (empty($_POST['points']))
230 // points not entered
231 define('__ERROR_MSG', DOUBLER_FORM_404_POINTS);
235 // Set messages to nothing
236 if (!defined('__DOUBLER_MSG')) define('__DOUBLER_MSG', "");
237 if (!defined('__ERROR_MSG')) define('__ERROR_MSG' , "");
239 // Shall I check for points immediately?
240 if ($CONFIG['doubler_send_mode'] == "DIRECT") require(PATH."inc/doubler_send.php");
243 include(PATH."inc/header.php");
246 define('__DOUBLER_BANNER', LOAD_TEMPLATE("doubler_banner", true));
248 // Load header/footer templates
249 define('__DOUBLER_HEADER', LOAD_TEMPLATE("doubler_header", true));
250 define('__DOUBLER_FOOTER', LOAD_TEMPLATE("doubler_footer", true));
254 // Transfer userid/nickname to constant
255 define('__REFID', $uid);
257 elseif (!empty($GLOBALS['refid']))
259 // Transfer userid/nickname to constant
260 define('__REFID', $GLOBALS['refid']);
264 // Transfer default refid to constant
265 define('__REFID', $CONFIG['def_refid']);
268 // Percent values etc.
269 define('__CHARGE_VALUE', TRANSLATE_COMMA($CONFIG['doubler_charge'] * 100));
270 define('__REF_VALUE' , TRANSLATE_COMMA($CONFIG['doubler_ref'] * 100));
271 define('__TOTAL_VALUE' , TRANSLATE_COMMA($CONFIG['doubler_points']));
272 define('__MIN_VALUE' , TRANSLATE_COMMA($CONFIG['doubler_min']));
273 define('__MAX_VALUE' , TRANSLATE_COMMA($CONFIG['doubler_max']));
275 // Text "Enter login"
276 if (EXT_IS_ACTIVE("nickname"))
278 // Choose login/nickname
279 define('DOUBLER_ENTER_LOGIN', GUEST_ENTER_LOGIN_NICKNAME);
284 define('DOUBLER_ENTER_LOGIN', GUEST_ENTER_LOGIN);
287 // Which mail-send-mode did the admin setup?
288 switch ($CONFIG['doubler_send_mode'])
291 define('DOUBLER_PAYOUT_TIME', DOUBLER_PAYOUT_TIME_DIRECT);
295 define('DOUBLER_PAYOUT_TIME', DOUBLER_PAYOUT_TIME_RESET);
299 // Generate table with already payed out doubles
300 define('__DOUBLER_PAYOUT_HISTORY', DOUBLER_GENERATE_TABLE("0", 'Y', 'N', "DESC"));
303 define('__TIMEOUT_MARK', CREATE_FANCY_TIME($CONFIG['doubler_timeout']));
306 define('__DOUBLER_COUNTER', $CONFIG['doubler_counter']);
308 // Points left to doubler
309 define('__LEFT_VALUE', TRANSLATE_COMMA(DOUBLER_GET_TOTAL_POINTS_LEFT()));
311 // Output neccessary form for this
312 LOAD_TEMPLATE("doubler_index");
315 include(PATH."inc/footer.php");
319 // You have to configure first!
320 LOAD_URL(URL."/install.php");
323 // Really all done here... ;-)