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 // Do we have nickname or userid set?
68 if (isNicknameUsed($GLOBALS['refid'])) {
69 // Nickname in URL, so load the ID
70 $result = SQL_QUERY_ESC("SELECT `userid`, `status` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `nickname`='%s' LIMIT 1",
71 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
73 // Direct userid entered
74 $result = SQL_QUERY_ESC("SELECT userid, status FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
75 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
79 list($rid, $status_ref) = SQL_FETCHROW($result);
80 $GLOBALS['refid'] = bigintval($rid);
83 SQL_FREERESULT($result);
89 // If no account was found set default refid and status to CONFIRMED
90 if (empty($GLOBALS['refid'])) {
91 $GLOBALS['refid'] = getConfig('def_refid');
92 $status = 'CONFIRMED';
95 // Begin with doubler script...
97 // Secure points (so only integer/double values are allowed
98 REQUEST_SET_POST('points', bigintval(REQUEST_POST('points')));
100 // Begin with doubling process
101 if ((REQUEST_ISSET_POST('userid')) && (REQUEST_ISSET_POST('pass')) && (REQUEST_ISSET_POST('points'))) {
102 // Probe for nickname extension and if a nickname was entered
103 if (isNickNameUsed(REQUEST_POST('userid'))) {
104 // Nickname in URL, so load the ID
105 $result = SQL_QUERY_ESC("SELECT `userid`, `status`, `password` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `nickname`='%s' LIMIT 1",
106 array(REQUEST_POST('userid')), __FILE__, __LINE__);
108 // Direct userid entered
109 $result = SQL_QUERY_ESC("SELECT `userid`, `status, `password` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
110 array(bigintval(REQUEST_POST('userid'))), __FILE__, __LINE__);
114 list($uid, $status, $password) = SQL_FETCHROW($result);
115 $uid = bigintval($uid);
118 SQL_FREERESULT($result);
120 // Remove any dots and unwanted chars from the points
121 REQUEST_SET_POST('points', bigintval(round(convertCommaToDot(REQUEST_POST('points')))));
123 // Probe for enough points
124 $probe_points = ((REQUEST_POST('points') >= getConfig('doubler_min')) && (REQUEST_POST('points') <= getConfig('doubler_max')));
126 // Check all together
127 if ((!empty($uid)) && ($password == generateHash(REQUEST_POST('pass'), substr($password, 0, -40))) && ($status == 'CONFIRMED') && ($probe_points)) {
128 // Nickname resolved to a unique userid or direct userid entered by the member
129 $GLOBALS['doubler_uid'] = $uid;
132 $points = GET_TOTAL_DATA($uid, 'user_points', 'points') - GET_TOTAL_DATA($uid, 'user_data', 'used_points');
134 // So let's continue with probing his points amount
135 if (($points - getConfig('doubler_left') - REQUEST_POST('points') * getConfig('doubler_charge')) >= 0) {
136 // Enough points are left so let's continue with the doubling process
137 // Create doubling "account" width *DOUBLED* points
138 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')",
139 array($uid, bigintval($GLOBALS['refid']), bigintval(REQUEST_POST('points') * 2)), __FILE__, __LINE__);
141 // Subtract entered points
142 SUB_POINTS('doubler', $uid, REQUEST_POST('points'));
144 // Add points to "total payed" including charge
145 $points = REQUEST_POST('points') - REQUEST_POST('points') * getConfig('doubler_charge');
146 updateConfiguration('doubler_points', $points, '+');
147 incrementConfigEntry('doubler_points', $points);
149 // Add second line for the referal but only when uid != refid
150 if (($GLOBALS['refid'] > 0) && ($GLOBALS['refid'] != $uid)) {
151 // Okay add a refid line and apply refid percents
152 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')",
154 bigintval($GLOBALS['refid']),
155 bigintval(REQUEST_POST('points') * 2 * getConfig('doubler_ref'))
156 ), __FILE__, __LINE__);
158 // And that's why we don't want to you more than one referal level of doubler-points. ^^^
161 // Update usage counter
162 updateConfiguration('doubler_counter', 1, '+');
165 define('__DOUBLER_MSG', LOAD_TEMPLATE('doubler_reflink', true, REQUEST_POST('userid')));
167 // Not enougth points left
168 define('__ERROR_MSG', getMessage('DOUBLER_FORM_NO_POINTS_LEFT'));
170 } elseif ($status == 'CONFIRMED') {
171 // Account is unconfirmed!
172 define('__ERROR_MSG', getMessage('DOUBLER_FORM_WRONG_PASS'));
173 } elseif ($status == 'UNCONFIRMED') {
174 // Account is unconfirmed!
175 define('__ERROR_MSG', getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED'));
176 } elseif ($status == 'LOCKED') {
177 // Account is locked by admin / holiday!
178 define('__ERROR_MSG', getMessage('DOUBLER_FORM_STATUS_LOCKED'));
179 } elseif (REQUEST_POST('points') < getConfig('doubler_min')) {
180 // Not enougth points entered
181 define('__ERROR_MSG', getMessage('DOUBLER_FORM_POINTS_MIN'));
182 } elseif (REQUEST_POST('points') > getConfig('doubler_max')) {
183 // Too much points entered
184 define('__ERROR_MSG', getMessage('DOUBLER_FORM_POINTS_MAX'));
185 } elseif (isNickNameUsed(REQUEST_POST('userid'))) {
186 // Cannot resolv nickname -> userid
187 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_NICKNAME'));
189 // Wrong password or account not found
190 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_MEMBER'));
192 } elseif (!REQUEST_ISSET_POST('userid')) {
194 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_LOGIN'));
195 } elseif (!REQUEST_ISSET_POST('pass')) {
196 // Password not entered
197 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_PASSWORD'));
198 } elseif (!REQUEST_ISSET_POST('points')) {
199 // points not entered
200 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_POINTS'));
204 // Set messages to nothing
205 if (!defined('__DOUBLER_MSG')) define('__DOUBLER_MSG', '');
206 if (!defined('__ERROR_MSG')) define('__ERROR_MSG' , '');
208 // Shall I check for points immediately?
209 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/doubler_send.php');
212 loadIncludeOnce('inc/header.php');
215 define('__DOUBLER_BANNER', LOAD_TEMPLATE('doubler_banner', true));
217 // Load header/footer templates
218 define('__DOUBLER_HEADER', LOAD_TEMPLATE('doubler_header', true));
219 define('__DOUBLER_FOOTER', LOAD_TEMPLATE('doubler_footer', true));
222 // Transfer userid/nickname to constant
223 define('__REFID', $uid);
225 // Transfer userid/nickname to constant
226 define('__REFID', $GLOBALS['refid']);
229 // Percent values etc.
230 define('__CHARGE_VALUE', translateComma(getConfig('doubler_charge') * 100));
231 define('__REF_VALUE' , translateComma(getConfig('doubler_ref') * 100));
232 define('__TOTAL_VALUE' , translateComma(getConfig('doubler_points')));
233 define('__MIN_VALUE' , translateComma(getConfig('doubler_min')));
234 define('__MAX_VALUE' , translateComma(getConfig('doubler_max')));
236 // Text "Enter login"
237 if (EXT_IS_ACTIVE('nickname')) {
238 // Choose login/nickname
239 define('DOUBLER_ENTER_LOGIN', getMessage('GUEST_ENTER_LOGIN_NICKNAME'));
242 define('DOUBLER_ENTER_LOGIN', getMessage('GUEST_ENTER_LOGIN'));
245 // Which mail-send-mode did the admin setup?
246 switch (getConfig('doubler_send_mode')) {
248 define('DOUBLER_PAYOUT_TIME', getMessage('DOUBLER_PAYOUT_TIME_DIRECT'));
252 define('DOUBLER_PAYOUT_TIME', getMessage('DOUBLER_PAYOUT_TIME_RESET'));
256 // Generate table with already payed out doubles
257 define('__DOUBLER_PAYOUT_HISTORY', DOUBLER_GENERATE_TABLE('0', 'Y', 'N', 'DESC'));
260 define('__TIMEOUT_MARK', createFancyTime(getConfig('doubler_timeout')));
263 define('__DOUBLER_COUNTER', getConfig('doubler_counter'));
265 // Points left to doubler
266 define('__LEFT_VALUE', translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT()));
268 // Output neccessary form for this
269 // @TODO Rewrite all constants
270 LOAD_TEMPLATE('doubler_index');
273 loadIncludeOnce('inc/footer.php');