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 * -------------------------------------------------------------------- *
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 - 2008 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 // Load security stuff here
40 require('inc/libs/security_functions.php');
43 $GLOBALS['startTime'] = microtime(true);
46 $GLOBALS['module'] = 'doubler';
47 $GLOBALS['refid'] = 0;
48 $GLOBALS['output_mode'] = 0;
50 // Load the required file(s)
51 require('inc/config-global.php');
53 // Is the 'doubler' extension active?
54 redirectOnUninstalledExtension('doubler');
56 // Is the script installed?
58 // You have to install first!
59 redirectToUrl('install.php');
62 // Probe for referal ID
63 if (REQUEST_ISSET_GET(('refid'))) $GLOBALS['refid'] = REQUEST_GET(('refid'));
65 // Only check this if refid is provided!
66 if ($GLOBALS['refid'] > 0) {
67 // Probe for nickname extension and if a nickname was supplied by URL
68 $probe_nickname = ((EXT_IS_ACTIVE('nickname')) && ((''.round($GLOBALS['refid']).'') != $GLOBALS['refid']));
70 // Do we have nickname or userid set?
71 if ($probe_nickname === true) {
72 // Nickname in URL, so load the ID
73 $result = SQL_QUERY_ESC("SELECT userid, status FROM `{!_MYSQL_PREFIX!}_user_data` WHERE nickname='%s' LIMIT 1",
74 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
76 // Direct userid entered
77 $result = SQL_QUERY_ESC("SELECT userid, status FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
78 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
82 list($rid, $status_ref) = SQL_FETCHROW($result);
83 $GLOBALS['refid'] = bigintval($rid);
86 SQL_FREERESULT($result);
92 // If no account was found set default refid and status to CONFIRMED
93 if (empty($GLOBALS['refid'])) {
94 $GLOBALS['refid'] = getConfig('def_refid');
95 $status = 'CONFIRMED';
98 // Begin with doubler script...
100 // Secure points (so only integer/double values are allowed
101 REQUEST_SET_POST('points', bigintval(REQUEST_POST('points')));
103 // Begin with doubling process
104 if ((REQUEST_ISSET_POST(('userid'))) && (REQUEST_ISSET_POST(('pass'))) && (REQUEST_ISSET_POST(('points')))) {
105 // Probe for nickname extension and if a nickname was entered
106 $probe_nickname = ((EXT_IS_ACTIVE('nickname')) && ((''.round(REQUEST_POST('userid')).'') != REQUEST_POST('userid')));
107 if ($probe_nickname) {
108 // Nickname in URL, so load the ID
109 $result = SQL_QUERY_ESC("SELECT userid, status, password FROM `{!_MYSQL_PREFIX!}_user_data` WHERE nickname='%s' LIMIT 1",
110 array(REQUEST_POST('userid')), __FILE__, __LINE__);
112 // Direct userid entered
113 $result = SQL_QUERY_ESC("SELECT userid, status, password FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
114 array(bigintval(REQUEST_POST('userid'))), __FILE__, __LINE__);
118 list($uid, $status, $password) = SQL_FETCHROW($result);
119 $uid = bigintval($uid);
122 SQL_FREERESULT($result);
124 // Remove any dots and unwanted chars from the points
125 REQUEST_SET_POST('points', bigintval(round(convertCommaToDot(REQUEST_POST('points')))));
127 // Probe for enough points
128 $probe_points = ((REQUEST_POST('points') >= getConfig('doubler_min')) && (REQUEST_POST('points') <= getConfig('doubler_max')));
130 // Check all together
131 if ((!empty($uid)) && ($password == generateHash(REQUEST_POST('pass'), substr($password, 0, -40))) && ($status == 'CONFIRMED') && ($probe_points)) {
132 // Nickname resolved to a unique userid or direct userid entered by the member
133 $GLOBALS['doubler_uid'] = $uid;
136 $points = GET_TOTAL_DATA($uid, 'user_points', 'points') - GET_TOTAL_DATA($uid, 'user_data', 'used_points');
138 // So let's continue with probing his points amount
139 if (($points - getConfig('doubler_left') - REQUEST_POST('points') * getConfig('doubler_charge')) >= 0)
140 // Enough points are left so let's continue with the doubling process
141 // Create doubling "account" width *DOUBLED* points
142 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_doubler` (userid, refid, points, remote_ip, timemark, completed, is_ref) VALUES ('%s','%s','%s','".detectRemoteAddr()."', UNIX_TIMESTAMP(), 'N','N')",
143 array($uid, bigintval($GLOBALS['refid']), bigintval(REQUEST_POST('points') * 2)), __FILE__, __LINE__);
145 // Subtract entered points
146 SUB_POINTS('doubler', $uid, REQUEST_POST('points'));
148 // Add points to "total payed" including charge
149 $points = REQUEST_POST('points') - REQUEST_POST('points') * getConfig('doubler_charge');
150 updateConfiguration('doubler_points', $points, '+');
151 incrementConfigEntry('doubler_points', $points);
153 // Add second line for the referal but only when uid != refid
154 if (($GLOBALS['refid'] > 0) && ($GLOBALS['refid'] != $uid)) {
155 // Okay add a refid line and apply refid percents
156 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_doubler` (userid, refid, points, remote_ip, timemark, completed, is_ref) VALUES ('%s',0,'%s','".detectRemoteAddr()."',UNIX_TIMESTAMP(),'N','Y')",
158 bigintval($GLOBALS['refid']),
159 bigintval(REQUEST_POST('points') * 2 * getConfig('doubler_ref'))
160 ), __FILE__, __LINE__);
162 // And that's why we don't want to you more than one referal level of doubler-points. ^^^
165 // Update usage counter
166 updateConfiguration('doubler_counter', 1, '+');
169 define('__DOUBLER_MSG', LOAD_TEMPLATE('doubler_reflink', true, REQUEST_POST('userid')));
171 // Not enougth points left
172 define('__ERROR_MSG', getMessage('DOUBLER_FORM_NO_POINTS_LEFT'));
174 } elseif ($status == 'CONFIRMED') {
175 // Account is unconfirmed!
176 define('__ERROR_MSG', getMessage('DOUBLER_FORM_WRONG_PASS'));
177 } elseif ($status == 'UNCONFIRMED') {
178 // Account is unconfirmed!
179 define('__ERROR_MSG', getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED'));
180 } elseif ($status == 'LOCKED') {
181 // Account is locked by admin / holiday!
182 define('__ERROR_MSG', getMessage('DOUBLER_FORM_STATUS_LOCKED'));
183 } elseif (REQUEST_POST('points') < getConfig('doubler_min')) {
184 // Not enougth points entered
185 define('__ERROR_MSG', getMessage('DOUBLER_FORM_POINTS_MIN'));
186 } elseif (REQUEST_POST('points') > getConfig('doubler_max')) {
187 // Too much points entered
188 define('__ERROR_MSG', getMessage('DOUBLER_FORM_POINTS_MAX'));
189 } elseif ($probe_nickname) {
190 // Cannot resolv nickname -> userid
191 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_NICKNAME'));
193 // Wrong password or account not found
194 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_MEMBER'));
196 } elseif (!REQUEST_ISSET_POST(('userid'))) {
198 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_LOGIN'));
199 } elseif (!REQUEST_ISSET_POST(('pass'))) {
200 // Password not entered
201 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_PASSWORD'));
202 } elseif (!REQUEST_ISSET_POST(('points'))) {
203 // points not entered
204 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_POINTS'));
208 // Set messages to nothing
209 if (!defined('__DOUBLER_MSG')) define('__DOUBLER_MSG', '');
210 if (!defined('__ERROR_MSG')) define('__ERROR_MSG' , '');
212 // Shall I check for points immediately?
213 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/doubler_send.php');
216 loadIncludeOnce('inc/header.php');
219 define('__DOUBLER_BANNER', LOAD_TEMPLATE('doubler_banner', true));
221 // Load header/footer templates
222 define('__DOUBLER_HEADER', LOAD_TEMPLATE('doubler_header', true));
223 define('__DOUBLER_FOOTER', LOAD_TEMPLATE('doubler_footer', true));
226 // Transfer userid/nickname to constant
227 define('__REFID', $uid);
229 // Transfer userid/nickname to constant
230 define('__REFID', $GLOBALS['refid']);
233 // Percent values etc.
234 define('__CHARGE_VALUE', translateComma(getConfig('doubler_charge') * 100));
235 define('__REF_VALUE' , translateComma(getConfig('doubler_ref') * 100));
236 define('__TOTAL_VALUE' , translateComma(getConfig('doubler_points')));
237 define('__MIN_VALUE' , translateComma(getConfig('doubler_min')));
238 define('__MAX_VALUE' , translateComma(getConfig('doubler_max')));
240 // Text "Enter login"
241 if (EXT_IS_ACTIVE('nickname')) {
242 // Choose login/nickname
243 define('DOUBLER_ENTER_LOGIN', getMessage('GUEST_ENTER_LOGIN_NICKNAME'));
246 define('DOUBLER_ENTER_LOGIN', getMessage('GUEST_ENTER_LOGIN'));
249 // Which mail-send-mode did the admin setup?
250 switch (getConfig('doubler_send_mode')) {
252 define('DOUBLER_PAYOUT_TIME', getMessage('DOUBLER_PAYOUT_TIME_DIRECT'));
256 define('DOUBLER_PAYOUT_TIME', getMessage('DOUBLER_PAYOUT_TIME_RESET'));
260 // Generate table with already payed out doubles
261 define('__DOUBLER_PAYOUT_HISTORY', DOUBLER_GENERATE_TABLE('0', 'Y', 'N', 'DESC'));
264 define('__TIMEOUT_MARK', createFancyTime(getConfig('doubler_timeout')));
267 define('__DOUBLER_COUNTER', getConfig('doubler_counter'));
269 // Points left to doubler
270 define('__LEFT_VALUE', translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT()));
272 // Output neccessary form for this
273 // @TODO Rewrite all constants
274 LOAD_TEMPLATE('doubler_index');
277 loadIncludeOnce('inc/footer.php');