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" with *DOUBLED* points
102 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES (%s,%s,%s,'%s', UNIX_TIMESTAMP(), 'N','N')",
104 getUserData('userid'),
105 makeZeroToNull(determineReferalId()),
106 bigintval(postRequestParameter('points') * 2),
108 ), __FILE__, __LINE__);
110 // Subtract entered points
111 subtractPoints('doubler', getUserData('userid'), postRequestParameter('points'));
113 // Add points to "total payed" including charge
114 $points = postRequestParameter('points') - postRequestParameter('points') * getConfig('doubler_charge') / 100;
115 updateConfiguration('doubler_points', $points, '+');
116 incrementConfigEntry('doubler_points', $points);
118 // Add second line for the referal but only when userid != refid
119 if ((isValidUserId(determineReferalId())) && (determineReferalId() != getUserData('userid'))) {
120 // Okay add a refid line and apply refid percents
121 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES (%s,0,%s,'%s',UNIX_TIMESTAMP(),'N','Y')",
123 makeZeroToNull(determineReferalId()),
124 (postRequestParameter('points') * 2 * getConfig('doubler_ref') / 100),
126 ), __FILE__, __LINE__);
128 // And that's why we don't want to you more than one referal level of doubler-points. ^^^
131 // Update usage counter
132 updateConfiguration('doubler_counter', 1, '+');
135 $content['message'] = loadTemplate('doubler_reflink', true, postRequestParameter('userid'));
137 // Not enougth points left
138 $content['message'] = '{--DOUBLER_FORM_NO_POINTS_LEFT--}';
140 } elseif (getUserData('status') == 'CONFIRMED') {
141 // Account is unconfirmed!
142 $content['message'] = '{--DOUBLER_FORM_WRONG_PASS--}';
143 } elseif (getUserData('status') == 'UNCONFIRMED') {
144 // Account is unconfirmed!
145 $content['message'] = '{--DOUBLER_FORM_STATUS_UNCONFIRMED--}';
146 } elseif (getUserData('status') == 'LOCKED') {
147 // Account is locked by admin / holiday!
148 $content['message'] = '{--DOUBLER_FORM_STATUS_LOCKED--}';
149 } elseif (postRequestParameter('points') < getConfig('doubler_min')) {
150 // Not enougth points entered
151 $content['message'] = '{--DOUBLER_FORM_POINTS_MIN--}';
152 } elseif (postRequestParameter('points') > getConfig('doubler_max')) {
153 // Too much points entered
154 $content['message'] = '{--DOUBLER_FORM_POINTS_MAX--}';
155 } elseif (isNickNameUsed(postRequestParameter('userid'))) {
156 // Cannot resolv nickname -> userid
157 $content['message'] = '{--DOUBLER_FORM_404_NICKNAME--}';
159 // Wrong password or account not found
160 $content['message'] = '{--DOUBLER_FORM_404_MEMBER--}';
162 } elseif (!isPostRequestParameterSet('userid')) {
164 $content['message'] = '{--DOUBLER_FORM_404_LOGIN--}';
165 } elseif (!isPostRequestParameterSet('password')) {
166 // Password not entered
167 $content['message'] = '{--DOUBLER_FORM_404_PASSWORD--}';
168 } elseif (!isPostRequestParameterSet('points')) {
169 // points not entered
170 $content['message'] = '{--DOUBLER_FORM_404_POINTS--}';
172 } // END - if (isFormSet())
174 // Shall I check for points immediately?
175 if (getConfig('doubler_send_mode') == 'DIRECT') {
176 loadInclude('inc/mails/doubler_mails.php');
180 loadIncludeOnce('inc/header.php');
183 $content['banner'] = loadTemplate('doubler_banner', true);
185 // Load header/footer templates
186 $content['header'] = loadTemplate('doubler_header', true);
187 $content['footer'] = loadTemplate('doubler_footer', true);
189 if (isUserDataValid()) {
190 // Transfer userid/nickname to constant
191 $content['refid'] = getUserData('userid');
193 // Transfer userid/nickname to constant
194 $content['refid'] = determineReferalId();
197 // Text "Enter login"
198 if (isExtensionActive('nickname')) {
199 // Choose login/nickname
200 $content['enter_login'] = '{--GUEST_ENTER_LOGIN_NICKNAME--}';
203 $content['enter_login'] = '{--GUEST_ENTER_LOGIN--}';
206 // Which mail-send-mode did the admin setup?
207 $content['payout_time'] = '{--DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode') . '--}';
209 // Generate table with already payed out doubles
210 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
212 // Output neccessary form for this
213 loadTemplate('doubler_index', false, $content);
216 loadIncludeOnce('inc/footer.php');