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 - 2009 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['output_mode'] = '0';
49 // Load the required file(s)
50 require('inc/config-global.php');
53 setContentType('text/html');
55 // Is the 'doubler' extension active?
56 redirectOnUninstalledExtension('doubler');
63 // Begin with doubler script...
65 // Secure points (so only integer/double values are allowed
66 setRequestPostElement('points', bigintval(postRequestElement('points')));
68 // Begin with doubling process
69 if ((isPostRequestElementSet('userid')) && (isPostRequestElementSet('pass')) && (isPostRequestElementSet('points'))) {
70 // Probe for nickname extension and if a nickname was entered
71 if (isNickNameUsed(postRequestElement('userid'))) {
72 // Nickname in URL, so load the id
73 fetchUserData(postRequestElement('userid'), 'nickname');
75 // Direct userid entered
76 fetchUserData(postRequestElement('userid'));
80 if (!isUserDataValid()) {
81 // Output message that the userid is not okay
82 loadTemplate('admin_settings_saved', false, getMessage('DOUBLER_USERID_INVALID'));
86 SQL_FREERESULT($result);
88 // Remove any dots and unwanted chars from the points
89 setRequestPostElement('points', bigintval(round(convertCommaToDot(postRequestElement('points')))));
91 // Probe for enough points
92 $probe_points = ((postRequestElement('points') >= getConfig('doubler_min')) && (postRequestElement('points') <= getConfig('doubler_max')));
95 if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestElement('pass'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
96 // Nickname resolved to a unique userid or direct userid entered by the member
97 $GLOBALS['doubler_userid'] = getUserData('userid');
100 $points = countSumTotalData(getUserData('userid'), 'user_points', 'points') - countSumTotalData(getUserData('userid'), 'user_data', 'used_points');
102 // So let's continue with probing his points amount
103 if (($points - getConfig('doubler_left') - postRequestElement('points') * getConfig('doubler_charge')) >= 0) {
104 // Enough points are left so let's continue with the doubling process
105 // Create doubling "account" width *DOUBLED* points
106 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')",
107 array(getUserData('userid'), determineReferalId(), bigintval(postRequestElement('points') * 2)), __FILE__, __LINE__);
109 // Subtract entered points
110 subtractPoints('doubler', getUserData('userid'), postRequestElement('points'));
112 // Add points to "total payed" including charge
113 $points = postRequestElement('points') - postRequestElement('points') * getConfig('doubler_charge');
114 updateConfiguration('doubler_points', $points, '+');
115 incrementConfigEntry('doubler_points', $points);
117 // Add second line for the referal but only when userid != refid
118 if ((determineReferalId() > 0) && (determineReferalId() != getUserData('userid'))) {
119 // Okay add a refid line and apply refid percents
120 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')",
122 determineReferalId(),
123 bigintval(postRequestElement('points') * 2 * getConfig('doubler_ref'))
124 ), __FILE__, __LINE__);
126 // And that's why we don't want to you more than one referal level of doubler-points. ^^^
129 // Update usage counter
130 updateConfiguration('doubler_counter', 1, '+');
133 $content['message'] = loadTemplate('doubler_reflink', true, postRequestElement('userid'));
135 // Not enougth points left
136 $content['message'] = getMessage('DOUBLER_FORM_NO_POINTS_LEFT');
138 } elseif (getUserData('status') == 'CONFIRMED') {
139 // Account is unconfirmed!
140 $content['message'] = getMessage('DOUBLER_FORM_WRONG_PASS');
141 } elseif (getUserData('status') == 'UNCONFIRMED') {
142 // Account is unconfirmed!
143 $content['message'] = getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED');
144 } elseif (getUserData('status') == 'LOCKED') {
145 // Account is locked by admin / holiday!
146 $content['message'] = getMessage('DOUBLER_FORM_STATUS_LOCKED');
147 } elseif (postRequestElement('points') < getConfig('doubler_min')) {
148 // Not enougth points entered
149 $content['message'] = getMessage('DOUBLER_FORM_POINTS_MIN');
150 } elseif (postRequestElement('points') > getConfig('doubler_max')) {
151 // Too much points entered
152 $content['message'] = getMessage('DOUBLER_FORM_POINTS_MAX');
153 } elseif (isNickNameUsed(postRequestElement('userid'))) {
154 // Cannot resolv nickname -> userid
155 $content['message'] = getMessage('DOUBLER_FORM_404_NICKNAME');
157 // Wrong password or account not found
158 $content['message'] = getMessage('DOUBLER_FORM_404_MEMBER');
160 } elseif (!isPostRequestElementSet('userid')) {
162 $content['message'] = getMessage('DOUBLER_FORM_404_LOGIN');
163 } elseif (!isPostRequestElementSet('pass')) {
164 // Password not entered
165 $content['message'] = getMessage('DOUBLER_FORM_404_PASSWORD');
166 } elseif (!isPostRequestElementSet('points')) {
167 // points not entered
168 $content['message'] = getMessage('DOUBLER_FORM_404_POINTS');
170 } // END - if (isFormSet())
172 // Shall I check for points immediately?
173 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/mails/doubler_mails.php');
176 loadIncludeOnce('inc/header.php');
179 $content['banner'] = loadTemplate('doubler_banner', true);
181 // Load header/footer templates
182 $content['header'] = loadTemplate('doubler_header', true);
183 $content['footer'] = loadTemplate('doubler_footer', true);
185 if (isUserDataValid()) {
186 // Transfer userid/nickname to constant
187 $content['refid'] = getUserData('userid');
189 // Transfer userid/nickname to constant
190 $content['refid'] = determineReferalId();
193 // Percent values etc.
194 $content['charge'] = translateComma(getConfig('doubler_charge') * 100);
195 $content['ref'] = translateComma(getConfig('doubler_ref') * 100);
196 $content['total'] = translateComma(getConfig('doubler_points'));
197 $content['min'] = translateComma(getConfig('doubler_min'));
198 $content['max'] = translateComma(getConfig('doubler_max'));
200 // Text "Enter login"
201 if (isExtensionActive('nickname')) {
202 // Choose login/nickname
203 $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN_NICKNAME');
206 $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN');
209 // Which mail-send-mode did the admin setup?
210 $content['payout_time'] = getMessage('DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode'));
212 // Generate table with already payed out doubles
213 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
216 $content['timeout_mark'] = createFancyTime(getConfig('doubler_timeout'));
218 // Points left to doubler
219 $content['left'] = translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT());
221 // Output neccessary form for this
222 loadTemplate('doubler_index', false, $content);
225 loadIncludeOnce('inc/footer.php');