a7f83cfeb2d256584fe926214ffca49c118a3765
[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" 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')",
103                                         array(
104                                                 getUserData('userid'),
105                                                 makeZeroToNull(determineReferalId()),
106                                                 bigintval(postRequestParameter('points') * 2),
107                                                 detectRemoteAddr()
108                                         ), __FILE__, __LINE__);
109
110                                 // Subtract entered points
111                                 subtractPoints('doubler', getUserData('userid'), postRequestParameter('points'));
112
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);
117
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')",
122                                                 array(
123                                                         makeZeroToNull(determineReferalId()),
124                                                         (postRequestParameter('points') * 2 * getConfig('doubler_ref') / 100),
125                                                         detectRemoteAddr()
126                                                 ), __FILE__, __LINE__);
127
128                                         // And that's why we don't want to you more than one referal 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, postRequestParameter('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 (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--}';
158                 } else {
159                         // Wrong password or account not found
160                         $content['message'] = '{--DOUBLER_FORM_404_MEMBER--}';
161                 }
162         } elseif (!isPostRequestParameterSet('userid')) {
163                 // Login not entered
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--}';
171         }
172 } // END - if (isFormSet())
173
174 // Shall I check for points immediately?
175 if (getConfig('doubler_send_mode') == 'DIRECT') {
176         loadInclude('inc/mails/doubler_mails.php');
177 } // END - if
178
179 // Output header
180 loadIncludeOnce('inc/header.php');
181
182 // Banner in text
183 $content['banner'] = loadTemplate('doubler_banner', true);
184
185 // Load header/footer templates
186 $content['header'] = loadTemplate('doubler_header', true);
187 $content['footer'] = loadTemplate('doubler_footer', true);
188
189 if (isUserDataValid()) {
190         // Transfer userid/nickname to constant
191         $content['refid'] = getUserData('userid');
192 } else {
193         // Transfer userid/nickname to constant
194         $content['refid'] = determineReferalId();
195 }
196
197 // Text "Enter login"
198 if (isExtensionActive('nickname')) {
199         // Choose login/nickname
200         $content['enter_login'] = '{--GUEST_ENTER_LOGIN_NICKNAME--}';
201 } else {
202         // Simple login id
203         $content['enter_login'] = '{--GUEST_ENTER_LOGIN--}';
204 }
205
206 // Which mail-send-mode did the admin setup?
207 $content['payout_time'] = '{--DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode') . '--}';
208
209 // Generate table with already payed out doubles
210 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
211
212 // Output neccessary form for this
213 loadTemplate('doubler_index', false, $content);
214
215 // Output footer
216 loadIncludeOnce('inc/footer.php');
217
218 // [EOF]
219 ?>