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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Load security stuff here
41 require('inc/libs/security_functions.php');
44 $GLOBALS['startTime'] = microtime(true);
47 $GLOBALS['module'] = 'doubler';
48 $GLOBALS['output_mode'] = '0';
50 // Load the required file(s)
51 require('inc/config-global.php');
54 setContentType('text/html');
56 // Is the 'doubler' extension active?
57 redirectOnUninstalledExtension('doubler');
64 // Begin with doubler script...
66 // Secure points (so only integer/double values are allowed
67 setPostRequestParameter('points', bigintval(postRequestParameter('points')));
69 // Begin with doubling process
70 if ((isPostRequestParameterSet('userid')) && (isPostRequestParameterSet('pass')) && (isPostRequestParameterSet('points'))) {
71 // Probe for nickname extension and if a nickname was entered
72 if (isNickNameUsed(postRequestParameter('userid'))) {
73 // Nickname in URL, so load the id
74 fetchUserData(postRequestParameter('userid'), 'nickname');
76 // Direct userid entered
77 fetchUserData(postRequestParameter('userid'));
81 if (!isUserDataValid()) {
82 // Output message that the userid is not okay
83 loadTemplate('admin_settings_saved', false, getMessage('DOUBLER_USERID_INVALID'));
86 // Remove any dots and unwanted chars from the points
87 setPostRequestParameter('points', bigintval(round(convertCommaToDot(postRequestParameter('points')))));
89 // Probe for enough points
90 $probe_points = ((postRequestParameter('points') >= getConfig('doubler_min')) && (postRequestParameter('points') <= getConfig('doubler_max')));
93 if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestParameter('pass'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
94 // Nickname resolved to a unique userid or direct userid entered by the member
95 $GLOBALS['doubler_userid'] = getUserData('userid');
98 $points = countSumTotalData(getUserData('userid'), 'user_points', 'points') - countSumTotalData(getUserData('userid'), 'user_data', 'used_points');
100 // So let's continue with probing his points amount
101 if (($points - getConfig('doubler_left') - postRequestParameter('points') * getConfig('doubler_charge')) >= 0) {
102 // Enough points are left so let's continue with the doubling process
103 // Create doubling "account" width *DOUBLED* points
104 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')",
105 array(getUserData('userid'), determineReferalId(), bigintval(postRequestParameter('points') * 2)), __FILE__, __LINE__);
107 // Subtract entered points
108 subtractPoints('doubler', getUserData('userid'), postRequestParameter('points'));
110 // Add points to "total payed" including charge
111 $points = postRequestParameter('points') - postRequestParameter('points') * getConfig('doubler_charge');
112 updateConfiguration('doubler_points', $points, '+');
113 incrementConfigEntry('doubler_points', $points);
115 // Add second line for the referal but only when userid != refid
116 if ((determineReferalId() > 0) && (determineReferalId() != getUserData('userid'))) {
117 // Okay add a refid line and apply refid percents
118 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')",
120 determineReferalId(),
121 bigintval(postRequestParameter('points') * 2 * getConfig('doubler_ref'))
122 ), __FILE__, __LINE__);
124 // And that's why we don't want to you more than one referal level of doubler-points. ^^^
127 // Update usage counter
128 updateConfiguration('doubler_counter', 1, '+');
131 $content['message'] = loadTemplate('doubler_reflink', true, postRequestParameter('userid'));
133 // Not enougth points left
134 $content['message'] = getMessage('DOUBLER_FORM_NO_POINTS_LEFT');
136 } elseif (getUserData('status') == 'CONFIRMED') {
137 // Account is unconfirmed!
138 $content['message'] = getMessage('DOUBLER_FORM_WRONG_PASS');
139 } elseif (getUserData('status') == 'UNCONFIRMED') {
140 // Account is unconfirmed!
141 $content['message'] = getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED');
142 } elseif (getUserData('status') == 'LOCKED') {
143 // Account is locked by admin / holiday!
144 $content['message'] = getMessage('DOUBLER_FORM_STATUS_LOCKED');
145 } elseif (postRequestParameter('points') < getConfig('doubler_min')) {
146 // Not enougth points entered
147 $content['message'] = getMessage('DOUBLER_FORM_POINTS_MIN');
148 } elseif (postRequestParameter('points') > getConfig('doubler_max')) {
149 // Too much points entered
150 $content['message'] = getMessage('DOUBLER_FORM_POINTS_MAX');
151 } elseif (isNickNameUsed(postRequestParameter('userid'))) {
152 // Cannot resolv nickname -> userid
153 $content['message'] = getMessage('DOUBLER_FORM_404_NICKNAME');
155 // Wrong password or account not found
156 $content['message'] = getMessage('DOUBLER_FORM_404_MEMBER');
158 } elseif (!isPostRequestParameterSet('userid')) {
160 $content['message'] = getMessage('DOUBLER_FORM_404_LOGIN');
161 } elseif (!isPostRequestParameterSet('pass')) {
162 // Password not entered
163 $content['message'] = getMessage('DOUBLER_FORM_404_PASSWORD');
164 } elseif (!isPostRequestParameterSet('points')) {
165 // points not entered
166 $content['message'] = getMessage('DOUBLER_FORM_404_POINTS');
168 } // END - if (isFormSet())
170 // Shall I check for points immediately?
171 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/mails/doubler_mails.php');
174 loadIncludeOnce('inc/header.php');
177 $content['banner'] = loadTemplate('doubler_banner', true);
179 // Load header/footer templates
180 $content['header'] = loadTemplate('doubler_header', true);
181 $content['footer'] = loadTemplate('doubler_footer', true);
183 if (isUserDataValid()) {
184 // Transfer userid/nickname to constant
185 $content['refid'] = getUserData('userid');
187 // Transfer userid/nickname to constant
188 $content['refid'] = determineReferalId();
191 // Percent values etc.
192 $content['charge'] = translateComma(getConfig('doubler_charge') * 100);
193 $content['ref'] = translateComma(getConfig('doubler_ref') * 100);
194 $content['total'] = translateComma(getConfig('doubler_points'));
195 $content['min'] = translateComma(getConfig('doubler_min'));
196 $content['max'] = translateComma(getConfig('doubler_max'));
198 // Text "Enter login"
199 if (isExtensionActive('nickname')) {
200 // Choose login/nickname
201 $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN_NICKNAME');
204 $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN');
207 // Which mail-send-mode did the admin setup?
208 $content['payout_time'] = getMessage('DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode'));
210 // Generate table with already payed out doubles
211 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
214 $content['timeout_mark'] = createFancyTime(getConfig('doubler_timeout'));
216 // Points left to doubler
217 $content['left'] = translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT());
219 // Output neccessary form for this
220 loadTemplate('doubler_index', false, $content);
223 loadIncludeOnce('inc/footer.php');