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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Load security stuff here
39 require('inc/libs/security_functions.php');
42 $GLOBALS['startTime'] = microtime(true);
45 $GLOBALS['module'] = 'doubler';
46 $GLOBALS['output_mode'] = '0';
48 // Load the required file(s)
49 require('inc/config-global.php');
52 setContentType('text/html');
54 // Is the 'doubler' extension active?
55 redirectOnUninstalledExtension('doubler');
62 // Begin with doubler script...
64 // Secure points (so only integer/double values are allowed
65 setPostRequestParameter('points', bigintval(postRequestParameter('points')));
67 // Begin with doubling process
68 if ((isPostRequestParameterSet('userid')) && (isPostRequestParameterSet('password')) && (isPostRequestParameterSet('points'))) {
69 // Probe for nickname extension and if a nickname was entered
70 if (isNickNameUsed(postRequestParameter('userid'))) {
71 // Nickname in URL, so load the id
72 fetchUserData(postRequestParameter('userid'), 'nickname');
74 // Direct userid entered
75 fetchUserData(postRequestParameter('userid'));
79 if (!isUserDataValid()) {
80 // Output message that the userid is not okay
81 displayMessage('{--DOUBLER_USERID_INVALID--}');
84 // Remove any dots and unwanted chars from the points
85 setPostRequestParameter('points', bigintval(round(convertCommaToDot(postRequestParameter('points')))));
87 // Probe for enough points
88 $probe_points = ((postRequestParameter('points') >= getConfig('doubler_min')) && (postRequestParameter('points') <= getConfig('doubler_max')));
91 if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestParameter('password'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
92 // Nickname resolved to a unique userid or direct userid entered by the member
93 $GLOBALS['local_doubler_userid'] = getUserData('userid');
96 $points = getTotalPoints(getUserData('userid'));
98 // So let's continue with probing his points amount
99 if (($points - getConfig('doubler_left') - postRequestParameter('points') * getConfig('doubler_charge') / 100) >= 0) {
100 // Enough points are left so let's continue with the doubling process
101 // Create doubling "account" width *DOUBLED* points
102 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 getUserData('userid'),
105 makeDatabaseUserId(determineReferalId()),
106 bigintval(postRequestParameter('points') * 2)
107 ), __FILE__, __LINE__);
109 // Subtract entered points
110 subtractPoints('doubler', getUserData('userid'), postRequestParameter('points'));
112 // Add points to "total payed" including charge
113 $points = postRequestParameter('points') - postRequestParameter('points') * getConfig('doubler_charge') / 100;
114 updateConfiguration('doubler_points', $points, '+');
115 incrementConfigEntry('doubler_points', $points);
117 // Add second line for the referal but only when userid != refid
118 if ((isValidUserId(determineReferalId())) && (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 makeDatabaseUserId(determineReferalId()),
123 bigintval(postRequestParameter('points') * 2 * getConfig('doubler_ref') / 100)
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, postRequestParameter('userid'));
135 // Not enougth points left
136 $content['message'] = '{--DOUBLER_FORM_NO_POINTS_LEFT--}';
138 } elseif (getUserData('status') == 'CONFIRMED') {
139 // Account is unconfirmed!
140 $content['message'] = '{--DOUBLER_FORM_WRONG_PASS--}';
141 } elseif (getUserData('status') == 'UNCONFIRMED') {
142 // Account is unconfirmed!
143 $content['message'] = '{--DOUBLER_FORM_STATUS_UNCONFIRMED--}';
144 } elseif (getUserData('status') == 'LOCKED') {
145 // Account is locked by admin / holiday!
146 $content['message'] = '{--DOUBLER_FORM_STATUS_LOCKED--}';
147 } elseif (postRequestParameter('points') < getConfig('doubler_min')) {
148 // Not enougth points entered
149 $content['message'] = '{--DOUBLER_FORM_POINTS_MIN--}';
150 } elseif (postRequestParameter('points') > getConfig('doubler_max')) {
151 // Too much points entered
152 $content['message'] = '{--DOUBLER_FORM_POINTS_MAX--}';
153 } elseif (isNickNameUsed(postRequestParameter('userid'))) {
154 // Cannot resolv nickname -> userid
155 $content['message'] = '{--DOUBLER_FORM_404_NICKNAME--}';
157 // Wrong password or account not found
158 $content['message'] = '{--DOUBLER_FORM_404_MEMBER--}';
160 } elseif (!isPostRequestParameterSet('userid')) {
162 $content['message'] = '{--DOUBLER_FORM_404_LOGIN--}';
163 } elseif (!isPostRequestParameterSet('password')) {
164 // Password not entered
165 $content['message'] = '{--DOUBLER_FORM_404_PASSWORD--}';
166 } elseif (!isPostRequestParameterSet('points')) {
167 // points not entered
168 $content['message'] = '{--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 // Text "Enter login"
194 if (isExtensionActive('nickname')) {
195 // Choose login/nickname
196 $content['enter_login'] = '{--GUEST_ENTER_LOGIN_NICKNAME--}';
199 $content['enter_login'] = '{--GUEST_ENTER_LOGIN--}';
202 // Which mail-send-mode did the admin setup?
203 $content['payout_time'] = '{--DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode') . '--}';
205 // Generate table with already payed out doubles
206 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
208 // Output neccessary form for this
209 loadTemplate('doubler_index', false, $content);
212 loadIncludeOnce('inc/footer.php');