Removed debug die() call
[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 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.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['startTime'] = microtime(true);
43
44 // Set module
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         setPostRequestParameter('points', bigintval(postRequestParameter('points')));
66
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');
73                 } else {
74                         // Direct userid entered
75                         fetchUserData(postRequestParameter('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                 setPostRequestParameter('points', bigintval(round(convertCommaToDot(postRequestParameter('points')))));
86
87                 // Probe for enough points
88                 $probe_points = ((postRequestParameter('points') >= getConfig('doubler_min')) && (postRequestParameter('points') <= getConfig('doubler_max')));
89
90                 // Check all together
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');
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') - 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')",
103                                         array(
104                                                 getUserData('userid'),
105                                                 makeDatabaseUserId(determineReferalId()),
106                                                 bigintval(postRequestParameter('points') * 2)
107                                         ), __FILE__, __LINE__);
108
109                                 // Subtract entered points
110                                 subtractPoints('doubler', getUserData('userid'), postRequestParameter('points'));
111
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);
116
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')",
121                                                 array(
122                                                         makeDatabaseUserId(determineReferalId()),
123                                                         bigintval(postRequestParameter('points') * 2 * getConfig('doubler_ref') / 100)
124                                                 ), __FILE__, __LINE__);
125
126                                         // And that's why we don't want to you more than one referal level of doubler-points. ^^^
127                                 } // END - if
128
129                                 // Update usage counter
130                                 updateConfiguration('doubler_counter', 1, '+');
131
132                                 // Set constant
133                                 $content['message'] = loadTemplate('doubler_reflink', true, postRequestParameter('userid'));
134                         } else {
135                                 // Not enougth points left
136                                 $content['message'] = '{--DOUBLER_FORM_NO_POINTS_LEFT--}';
137                         }
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--}';
156                 } else {
157                         // Wrong password or account not found
158                         $content['message'] = '{--DOUBLER_FORM_404_MEMBER--}';
159                 }
160         } elseif (!isPostRequestParameterSet('userid')) {
161                 // Login not entered
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--}';
169         }
170 } // END - if (isFormSet())
171
172 // Shall I check for points immediately?
173 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/mails/doubler_mails.php');
174
175 // Output header
176 loadIncludeOnce('inc/header.php');
177
178 // Banner in text
179 $content['banner'] = loadTemplate('doubler_banner', true);
180
181 // Load header/footer templates
182 $content['header'] = loadTemplate('doubler_header', true);
183 $content['footer'] = loadTemplate('doubler_footer', true);
184
185 if (isUserDataValid()) {
186         // Transfer userid/nickname to constant
187         $content['refid'] = getUserData('userid');
188 } else {
189         // Transfer userid/nickname to constant
190         $content['refid'] = determineReferalId();
191 }
192
193 // Text "Enter login"
194 if (isExtensionActive('nickname')) {
195         // Choose login/nickname
196         $content['enter_login'] = '{--GUEST_ENTER_LOGIN_NICKNAME--}';
197 } else {
198         // Simple login id
199         $content['enter_login'] = '{--GUEST_ENTER_LOGIN--}';
200 }
201
202 // Which mail-send-mode did the admin setup?
203 $content['payout_time'] = '{--DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode') . '--}';
204
205 // Generate table with already payed out doubles
206 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
207
208 // Output neccessary form for this
209 loadTemplate('doubler_index', false, $content);
210
211 // Output footer
212 loadIncludeOnce('inc/footer.php');
213
214 // [EOF]
215 ?>