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');
42 // Init "action" and "what"
43 $GLOBALS['startTime'] = microtime(true);
44 $GLOBALS['what'] = '';
45 $GLOBALS['action'] = '';
48 $GLOBALS['module'] = 'doubler';
49 $GLOBALS['refid'] = 0;
50 $GLOBALS['output_mode'] = 0;
52 // Load the required file(s)
53 require('inc/config-global.php');
55 // Is the 'doubler' extension active?
56 redirectOnUninstalledExtension('doubler');
58 // Is the script installed?
60 // You have to install first!
61 redirectToUrl('install.php');
64 // Probe for referal ID
65 if (REQUEST_ISSET_GET(('refid'))) $GLOBALS['refid'] = REQUEST_GET(('refid'));
67 // Only check this if refid is provided!
68 if ($GLOBALS['refid'] > 0) {
69 // Probe for nickname extension and if a nickname was supplied by URL
70 $probe_nickname = ((EXT_IS_ACTIVE('nickname')) && ((''.round($GLOBALS['refid']).'') != $GLOBALS['refid']));
72 // Do we have nickname or userid set?
73 if ($probe_nickname === true) {
74 // Nickname in URL, so load the ID
75 $result = SQL_QUERY_ESC("SELECT userid, status FROM `{!_MYSQL_PREFIX!}_user_data` WHERE nickname='%s' LIMIT 1",
76 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
78 // Direct userid entered
79 $result = SQL_QUERY_ESC("SELECT userid, status FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
80 array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
84 list($rid, $status_ref) = SQL_FETCHROW($result);
85 $GLOBALS['refid'] = bigintval($rid);
88 SQL_FREERESULT($result);
94 // If no account was found set default refid and status to CONFIRMED
95 if (empty($GLOBALS['refid'])) {
96 $GLOBALS['refid'] = getConfig('def_refid');
97 $status = 'CONFIRMED';
100 // Begin with doubler script...
102 // Secure points (so only integer/double values are allowed
103 REQUEST_SET_POST('points', bigintval(REQUEST_POST('points')));
105 // Begin with doubling process
106 if ((REQUEST_ISSET_POST(('userid'))) && (REQUEST_ISSET_POST(('pass'))) && (REQUEST_ISSET_POST(('points')))) {
107 // Probe for nickname extension and if a nickname was entered
108 $probe_nickname = ((EXT_IS_ACTIVE('nickname')) && ((''.round(REQUEST_POST('userid')).'') != REQUEST_POST('userid')));
109 if ($probe_nickname) {
110 // Nickname in URL, so load the ID
111 $result = SQL_QUERY_ESC("SELECT userid, status, password FROM `{!_MYSQL_PREFIX!}_user_data` WHERE nickname='%s' LIMIT 1",
112 array(REQUEST_POST('userid')), __FILE__, __LINE__);
114 // Direct userid entered
115 $result = SQL_QUERY_ESC("SELECT userid, status, password FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
116 array(bigintval(REQUEST_POST('userid'))), __FILE__, __LINE__);
120 list($uid, $status, $password) = SQL_FETCHROW($result);
121 $uid = bigintval($uid);
124 SQL_FREERESULT($result);
126 // Remove any dots and unwanted chars from the points
127 REQUEST_SET_POST('points', bigintval(round(convertCommaToDot(REQUEST_POST('points')))));
129 // Probe for enough points
130 $probe_points = ((REQUEST_POST('points') >= getConfig('doubler_min')) && (REQUEST_POST('points') <= getConfig('doubler_max')));
132 // Check all together
133 if ((!empty($uid)) && ($password == generateHash(REQUEST_POST('pass'), substr($password, 0, -40))) && ($status == 'CONFIRMED') && ($probe_points)) {
134 // Nickname resolved to a unique userid or direct userid entered by the member
135 $GLOBALS['doubler_uid'] = $uid;
138 $points = GET_TOTAL_DATA($uid, 'user_points', 'points') - GET_TOTAL_DATA($uid, 'user_data', 'used_points');
140 // So let's continue with probing his points amount
141 if (($points - getConfig('doubler_left') - REQUEST_POST('points') * getConfig('doubler_charge')) >= 0)
142 // Enough points are left so let's continue with the doubling process
143 // Create doubling "account" width *DOUBLED* points
144 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')",
145 array($uid, bigintval($GLOBALS['refid']), bigintval(REQUEST_POST('points') * 2)), __FILE__, __LINE__);
147 // Subtract entered points
148 SUB_POINTS('doubler', $uid, REQUEST_POST('points'));
150 // Add points to "total payed" including charge
151 $points = REQUEST_POST('points') - REQUEST_POST('points') * getConfig('doubler_charge');
152 updateConfiguration('doubler_points', $points, '+');
153 incrementConfigEntry('doubler_points', $points);
155 // Add second line for the referal but only when uid != refid
156 if (($GLOBALS['refid'] > 0) && ($GLOBALS['refid'] != $uid)) {
157 // Okay add a refid line and apply refid percents
158 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')",
160 bigintval($GLOBALS['refid']),
161 bigintval(REQUEST_POST('points') * 2 * getConfig('doubler_ref'))
162 ), __FILE__, __LINE__);
164 // And that's why we don't want to you more than one referal level of doubler-points. ^^^
167 // Update usage counter
168 updateConfiguration('doubler_counter', 1, '+');
171 define('__DOUBLER_MSG', LOAD_TEMPLATE('doubler_reflink', true, REQUEST_POST('userid')));
173 // Not enougth points left
174 define('__ERROR_MSG', getMessage('DOUBLER_FORM_NO_POINTS_LEFT'));
176 } elseif ($status == 'CONFIRMED') {
177 // Account is unconfirmed!
178 define('__ERROR_MSG', getMessage('DOUBLER_FORM_WRONG_PASS'));
179 } elseif ($status == 'UNCONFIRMED') {
180 // Account is unconfirmed!
181 define('__ERROR_MSG', getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED'));
182 } elseif ($status == 'LOCKED') {
183 // Account is locked by admin / holiday!
184 define('__ERROR_MSG', getMessage('DOUBLER_FORM_STATUS_LOCKED'));
185 } elseif (REQUEST_POST('points') < getConfig('doubler_min')) {
186 // Not enougth points entered
187 define('__ERROR_MSG', getMessage('DOUBLER_FORM_POINTS_MIN'));
188 } elseif (REQUEST_POST('points') > getConfig('doubler_max')) {
189 // Too much points entered
190 define('__ERROR_MSG', getMessage('DOUBLER_FORM_POINTS_MAX'));
191 } elseif ($probe_nickname) {
192 // Cannot resolv nickname -> userid
193 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_NICKNAME'));
195 // Wrong password or account not found
196 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_MEMBER'));
198 } elseif (!REQUEST_ISSET_POST(('userid'))) {
200 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_LOGIN'));
201 } elseif (!REQUEST_ISSET_POST(('pass'))) {
202 // Password not entered
203 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_PASSWORD'));
204 } elseif (!REQUEST_ISSET_POST(('points'))) {
205 // points not entered
206 define('__ERROR_MSG', getMessage('DOUBLER_FORM_404_POINTS'));
210 // Set messages to nothing
211 if (!defined('__DOUBLER_MSG')) define('__DOUBLER_MSG', '');
212 if (!defined('__ERROR_MSG')) define('__ERROR_MSG' , '');
214 // Shall I check for points immediately?
215 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/doubler_send.php');
218 loadIncludeOnce('inc/header.php');
221 define('__DOUBLER_BANNER', LOAD_TEMPLATE('doubler_banner', true));
223 // Load header/footer templates
224 define('__DOUBLER_HEADER', LOAD_TEMPLATE('doubler_header', true));
225 define('__DOUBLER_FOOTER', LOAD_TEMPLATE('doubler_footer', true));
228 // Transfer userid/nickname to constant
229 define('__REFID', $uid);
231 // Transfer userid/nickname to constant
232 define('__REFID', $GLOBALS['refid']);
235 // Percent values etc.
236 define('__CHARGE_VALUE', translateComma(getConfig('doubler_charge') * 100));
237 define('__REF_VALUE' , translateComma(getConfig('doubler_ref') * 100));
238 define('__TOTAL_VALUE' , translateComma(getConfig('doubler_points')));
239 define('__MIN_VALUE' , translateComma(getConfig('doubler_min')));
240 define('__MAX_VALUE' , translateComma(getConfig('doubler_max')));
242 // Text "Enter login"
243 if (EXT_IS_ACTIVE('nickname')) {
244 // Choose login/nickname
245 define('DOUBLER_ENTER_LOGIN', getMessage('GUEST_ENTER_LOGIN_NICKNAME'));
248 define('DOUBLER_ENTER_LOGIN', getMessage('GUEST_ENTER_LOGIN'));
251 // Which mail-send-mode did the admin setup?
252 switch (getConfig('doubler_send_mode')) {
254 define('DOUBLER_PAYOUT_TIME', getMessage('DOUBLER_PAYOUT_TIME_DIRECT'));
258 define('DOUBLER_PAYOUT_TIME', getMessage('DOUBLER_PAYOUT_TIME_RESET'));
262 // Generate table with already payed out doubles
263 define('__DOUBLER_PAYOUT_HISTORY', DOUBLER_GENERATE_TABLE('0', 'Y', 'N', 'DESC'));
266 define('__TIMEOUT_MARK', createFancyTime(getConfig('doubler_timeout')));
269 define('__DOUBLER_COUNTER', getConfig('doubler_counter'));
271 // Points left to doubler
272 define('__LEFT_VALUE', translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT()));
274 // Output neccessary form for this
275 // @TODO Rewrite all constants
276 LOAD_TEMPLATE('doubler_index');
279 loadIncludeOnce('inc/footer.php');