2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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'));
85 // Remove any dots and unwanted chars from the points
86 setRequestPostElement('points', bigintval(round(convertCommaToDot(postRequestElement('points')))));
88 // Probe for enough points
89 $probe_points = ((postRequestElement('points') >= getConfig('doubler_min')) && (postRequestElement('points') <= getConfig('doubler_max')));
92 if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestElement('pass'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
93 // Nickname resolved to a unique userid or direct userid entered by the member
94 $GLOBALS['doubler_userid'] = getUserData('userid');
97 $points = countSumTotalData(getUserData('userid'), 'user_points', 'points') - countSumTotalData(getUserData('userid'), 'user_data', 'used_points');
99 // So let's continue with probing his points amount
100 if (($points - getConfig('doubler_left') - postRequestElement('points') * getConfig('doubler_charge')) >= 0) {
101 // Enough points are left so let's continue with the doubling process
102 // Create doubling "account" width *DOUBLED* points
103 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')",
104 array(getUserData('userid'), determineReferalId(), bigintval(postRequestElement('points') * 2)), __FILE__, __LINE__);
106 // Subtract entered points
107 subtractPoints('doubler', getUserData('userid'), postRequestElement('points'));
109 // Add points to "total payed" including charge
110 $points = postRequestElement('points') - postRequestElement('points') * getConfig('doubler_charge');
111 updateConfiguration('doubler_points', $points, '+');
112 incrementConfigEntry('doubler_points', $points);
114 // Add second line for the referal but only when userid != refid
115 if ((determineReferalId() > 0) && (determineReferalId() != getUserData('userid'))) {
116 // Okay add a refid line and apply refid percents
117 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')",
119 determineReferalId(),
120 bigintval(postRequestElement('points') * 2 * getConfig('doubler_ref'))
121 ), __FILE__, __LINE__);
123 // And that's why we don't want to you more than one referal level of doubler-points. ^^^
126 // Update usage counter
127 updateConfiguration('doubler_counter', 1, '+');
130 $content['message'] = loadTemplate('doubler_reflink', true, postRequestElement('userid'));
132 // Not enougth points left
133 $content['message'] = getMessage('DOUBLER_FORM_NO_POINTS_LEFT');
135 } elseif (getUserData('status') == 'CONFIRMED') {
136 // Account is unconfirmed!
137 $content['message'] = getMessage('DOUBLER_FORM_WRONG_PASS');
138 } elseif (getUserData('status') == 'UNCONFIRMED') {
139 // Account is unconfirmed!
140 $content['message'] = getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED');
141 } elseif (getUserData('status') == 'LOCKED') {
142 // Account is locked by admin / holiday!
143 $content['message'] = getMessage('DOUBLER_FORM_STATUS_LOCKED');
144 } elseif (postRequestElement('points') < getConfig('doubler_min')) {
145 // Not enougth points entered
146 $content['message'] = getMessage('DOUBLER_FORM_POINTS_MIN');
147 } elseif (postRequestElement('points') > getConfig('doubler_max')) {
148 // Too much points entered
149 $content['message'] = getMessage('DOUBLER_FORM_POINTS_MAX');
150 } elseif (isNickNameUsed(postRequestElement('userid'))) {
151 // Cannot resolv nickname -> userid
152 $content['message'] = getMessage('DOUBLER_FORM_404_NICKNAME');
154 // Wrong password or account not found
155 $content['message'] = getMessage('DOUBLER_FORM_404_MEMBER');
157 } elseif (!isPostRequestElementSet('userid')) {
159 $content['message'] = getMessage('DOUBLER_FORM_404_LOGIN');
160 } elseif (!isPostRequestElementSet('pass')) {
161 // Password not entered
162 $content['message'] = getMessage('DOUBLER_FORM_404_PASSWORD');
163 } elseif (!isPostRequestElementSet('points')) {
164 // points not entered
165 $content['message'] = getMessage('DOUBLER_FORM_404_POINTS');
167 } // END - if (isFormSet())
169 // Shall I check for points immediately?
170 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/mails/doubler_mails.php');
173 loadIncludeOnce('inc/header.php');
176 $content['banner'] = loadTemplate('doubler_banner', true);
178 // Load header/footer templates
179 $content['header'] = loadTemplate('doubler_header', true);
180 $content['footer'] = loadTemplate('doubler_footer', true);
182 if (isUserDataValid()) {
183 // Transfer userid/nickname to constant
184 $content['refid'] = getUserData('userid');
186 // Transfer userid/nickname to constant
187 $content['refid'] = determineReferalId();
190 // Percent values etc.
191 $content['charge'] = translateComma(getConfig('doubler_charge') * 100);
192 $content['ref'] = translateComma(getConfig('doubler_ref') * 100);
193 $content['total'] = translateComma(getConfig('doubler_points'));
194 $content['min'] = translateComma(getConfig('doubler_min'));
195 $content['max'] = translateComma(getConfig('doubler_max'));
197 // Text "Enter login"
198 if (isExtensionActive('nickname')) {
199 // Choose login/nickname
200 $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN_NICKNAME');
203 $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN');
206 // Which mail-send-mode did the admin setup?
207 $content['payout_time'] = getMessage('DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode'));
209 // Generate table with already payed out doubles
210 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
213 $content['timeout_mark'] = createFancyTime(getConfig('doubler_timeout'));
215 // Points left to doubler
216 $content['left'] = translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT());
218 // Output neccessary form for this
219 loadTemplate('doubler_index', false, $content);
222 loadIncludeOnce('inc/footer.php');