5d4c3ce0924416621b04c9b03805f5e65a03ffa2
[mailer.git] / doubler.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 02/13/2005 *
4  * ===================                          Last change: 02/13/2005 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : doubler.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : Points doubler                                   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Punkteverdoppler                                 *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Load security stuff here
39 require('inc/libs/security_functions.php');
40
41 // Init start time
42 $GLOBALS['__start_time'] = microtime(TRUE);
43
44 // Set module and output mode
45 $GLOBALS['__module']      = 'doubler';
46 $GLOBALS['__output_mode'] = '0';
47
48 // Load the required file(s)
49 require('inc/config-global.php');
50
51 // Set content type
52 setContentType('text/html');
53
54 // Is the 'doubler' extension active?
55 redirectOnUninstalledExtension('doubler');
56
57 // Init content array
58 $content = array(
59         'message' => '',
60 );
61
62 // Begin with doubler script...
63 if (isFormSent()) {
64         // Secure points (so only integer/double values are allowed
65         setPostRequestElement('points', bigintval(postRequestElement('points')));
66
67         // Begin with doubling process
68         if ((isPostRequestElementSet('userid')) && (isPostRequestElementSet('password')) && (isPostRequestElementSet('points'))) {
69                 // Probe for nickname extension and if a nickname was entered
70                 if (isNicknameUsed(postRequestElement('userid'))) {
71                         // Nickname in URL, so load the id
72                         fetchUserData(postRequestElement('userid'), 'nickname');
73                 } else {
74                         // Direct userid entered
75                         fetchUserData(postRequestElement('userid'));
76                 }
77
78                 // Is the data valid?
79                 if (!isUserDataValid()) {
80                         // Output message that the userid is not okay
81                         displayMessage('{--DOUBLER_USERID_INVALID--}');
82                 } // END - if
83
84                 // Remove any dots and unwanted chars from the points
85                 setPostRequestElement('points', bigintval(round(convertCommaToDot(postRequestElement('points')))));
86
87                 // Probe for enough points
88                 $probe_points = ((postRequestElement('points') >= getDoublerMin()) && (postRequestElement('points') <= getDoublerMax()));
89
90                 // Check all together
91                 if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestElement('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');
94
95                         // Calulcate points
96                         $points = getTotalPoints(getUserData('userid'));
97
98                         // So let's continue with probing his points amount
99                         if (($points - getConfig('doubler_left') - postRequestElement('points') * getDoublerCharge() / 100) >= 0) {
100                                 // Enough points are left so let's continue with the doubling process
101                                 // Create doubling "account" with *DOUBLED* points
102                                 sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES (%s,%s,%s,'%s', UNIX_TIMESTAMP(), 'N','N')",
103                                         array(
104                                                 getUserData('userid'),
105                                                 convertZeroToNull(determineReferralId()),
106                                                 bigintval(postRequestElement('points') * 2),
107                                                 determineRealRemoteAddress()
108                                         ), __FILE__, __LINE__);
109
110                                 // Subtract entered points and ignore return status
111                                 subtractPoints('doubler', getUserData('userid'), postRequestElement('points'));
112
113                                 // Add points to "total payed" including charge
114                                 $points = postRequestElement('points') - postRequestElement('points') * getDoublerCharge() / 100;
115                                 updateConfiguration('doubler_points', $points, '+');
116                                 incrementConfigEntry('doubler_points', $points);
117
118                                 // Add second line for the referral but only when userid != refid
119                                 if ((isValidId(determineReferralId())) && (determineReferralId() != getUserData('userid'))) {
120                                         // Okay add a refid line and apply refid percents
121                                         sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_doubler` (`userid`, `refid`, `points`, `remote_ip`, `timemark`, `completed`, `is_ref`) VALUES (%s,0,%s,'%s',UNIX_TIMESTAMP(),'N','Y')",
122                                                 array(
123                                                         convertZeroToNull(determineReferralId()),
124                                                         (postRequestElement('points') * 2 * getDoublerRef() / 100),
125                                                         determineRealRemoteAddress()
126                                                 ), __FILE__, __LINE__);
127
128                                         // And that's why we don't want to you more than one referral level of doubler-points. ^^^
129                                 } // END - if
130
131                                 // Update usage counter
132                                 updateConfiguration('doubler_counter', 1, '+');
133
134                                 // Set constant
135                                 $content['message'] = loadTemplate('doubler_reflink', TRUE, postRequestElement('userid'));
136                         } else {
137                                 // Not enougth points left
138                                 $content['message'] = '{--DOUBLER_FORM_NO_POINTS_LEFT--}';
139                         }
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 (postRequestElement('points') < getDoublerMin()) {
150                         // Not enougth points entered
151                         $content['message'] = '{--DOUBLER_FORM_POINTS_MIN--}';
152                 } elseif (postRequestElement('points') > getDoublerMax()) {
153                         // Too much points entered
154                         $content['message'] = '{--DOUBLER_FORM_POINTS_MAX--}';
155                 } elseif (isNicknameUsed(postRequestElement('userid'))) {
156                         // Cannot resolv nickname -> userid
157                         $content['message'] = '{--DOUBLER_FORM_404_NICKNAME--}';
158                 } else {
159                         // Wrong password or account not found
160                         $content['message'] = '{--DOUBLER_FORM_404_MEMBER--}';
161                 }
162         } elseif (!isPostRequestElementSet('userid')) {
163                 // Login not entered
164                 $content['message'] = '{--DOUBLER_FORM_404_LOGIN--}';
165         } elseif (!isPostRequestElementSet('password')) {
166                 // Password not entered
167                 $content['message'] = '{--DOUBLER_FORM_404_PASSWORD--}';
168         } elseif (!isPostRequestElementSet('points')) {
169                 // points not entered
170                 $content['message'] = '{--DOUBLER_FORM_404_POINTS--}';
171         }
172 } // END - if (isFormSet())
173
174 // Shall I check for points immediately?
175 if (getDoublerSendMode() == 'DIRECT') {
176         loadInclude('inc/mails/doubler_mails.php');
177 } // END - if
178
179 // Output header
180 loadIncludeOnce('inc/header.php');
181
182 if (isUserDataValid()) {
183         // Transfer userid/nickname to constant
184         $content['refid'] = getUserData('userid');
185 } else {
186         // Transfer userid/nickname to constant
187         $content['refid'] = determineReferralId();
188 }
189
190 // Text "Enter login"
191 if (isExtensionActive('nickname')) {
192         // Choose login/nickname
193         $content['enter_login'] = '{--GUEST_ENTER_LOGIN_NICKNAME--}';
194 } else {
195         // Simple login id
196         $content['enter_login'] = '{--GUEST_ENTER_LOGIN--}';
197 }
198
199 // Which mail-send-mode did the admin setup?
200 $content['payout_time'] = '{--DOUBLER_PAYOUT_TIME_' . getDoublerSendMode() . '--}';
201
202 // Generate table with already payed out doubles
203 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
204
205 // Output neccessary form for this
206 loadTemplate('doubler_index', FALSE, $content);
207
208 // Output footer
209 loadIncludeOnce('inc/footer.php');
210
211 // [EOF]
212 ?>