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('password')) && (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, '{--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('password'), 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['local_doubler_userid'] = getUserData('userid');
98 $points = getTotalPoints(getUserData('userid'));
100 // So let's continue with probing his points amount
101 if (($points - getConfig('doubler_left') - postRequestParameter('points') * getConfig('doubler_charge') / 100) >= 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')",
106 getUserData('userid'),
107 makeDatabaseUserId(determineReferalId()),
108 bigintval(postRequestParameter('points') * 2)
109 ), __FILE__, __LINE__);
111 // Subtract entered points
112 subtractPoints('doubler', getUserData('userid'), postRequestParameter('points'));
114 // Add points to "total payed" including charge
115 $points = postRequestParameter('points') - postRequestParameter('points') * getConfig('doubler_charge') / 100;
116 updateConfiguration('doubler_points', $points, '+');
117 incrementConfigEntry('doubler_points', $points);
119 // Add second line for the referal but only when userid != refid
120 if ((isValidUserId(determineReferalId())) && (determineReferalId() != getUserData('userid'))) {
121 // Okay add a refid line and apply refid percents
122 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')",
124 makeDatabaseUserId(determineReferalId()),
125 bigintval(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') loadInclude('inc/mails/doubler_mails.php');
178 loadIncludeOnce('inc/header.php');
181 $content['banner'] = loadTemplate('doubler_banner', true);
183 // Load header/footer templates
184 $content['header'] = loadTemplate('doubler_header', true);
185 $content['footer'] = loadTemplate('doubler_footer', true);
187 if (isUserDataValid()) {
188 // Transfer userid/nickname to constant
189 $content['refid'] = getUserData('userid');
191 // Transfer userid/nickname to constant
192 $content['refid'] = determineReferalId();
195 // Text "Enter login"
196 if (isExtensionActive('nickname')) {
197 // Choose login/nickname
198 $content['enter_login'] = '{--GUEST_ENTER_LOGIN_NICKNAME--}';
201 $content['enter_login'] = '{--GUEST_ENTER_LOGIN--}';
204 // Which mail-send-mode did the admin setup?
205 $content['payout_time'] = '{--DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode') . '--}';
207 // Generate table with already payed out doubles
208 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
210 // Output neccessary form for this
211 loadTemplate('doubler_index', false, $content);
214 loadIncludeOnce('inc/footer.php');