Compilation time added, some compileCode() calles removed, ADMIN_WHAT_404 added
[mailer.git] / doubler.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  * 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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Load security stuff here
40 require('inc/libs/security_functions.php');
41
42 // Init start time
43 $GLOBALS['startTime'] = microtime(true);
44
45 // Set module
46 $GLOBALS['module'] = 'doubler';
47 $GLOBALS['output_mode'] = 0;
48
49 // Load the required file(s)
50 require('inc/config-global.php');
51
52 // Set content type
53 setContentType('text/html');
54
55 // Is the 'doubler' extension active?
56 redirectOnUninstalledExtension('doubler');
57
58 // Only check this if refid is provided. This will do the rest for us
59 determineReferalId();
60
61 // Init content array
62 $content = array(
63         'message' => '',
64 );
65
66 // Begin with doubler script...
67 if (isFormSent()) {
68         // Secure points (so only integer/double values are allowed
69         setRequestPostElement('points', bigintval(postRequestElement('points')));
70
71         // Begin with doubling process
72         if ((isPostRequestElementSet('userid')) && (isPostRequestElementSet('pass')) && (isPostRequestElementSet('points'))) {
73                 // Probe for nickname extension and if a nickname was entered
74                 if (isNickNameUsed(postRequestElement('userid'))) {
75                         // Nickname in URL, so load the id
76                         fetchUserData(postRequestElement('userid'), 'nickname');
77                 } else {
78                         // Direct userid entered
79                         fetchUserData(postRequestElement('userid'));
80                 }
81
82                 // Is the data valid?
83                 if (!isUserDataValid()) {
84                         // Output message that the userid is not okay
85                         loadTemplate('admin_settings_saved', false, getMessage('DOUBLER_USERID_INVALID'));
86                 } // END - if
87
88                 // Free result
89                 SQL_FREERESULT($result);
90
91                 // Remove any dots and unwanted chars from the points
92                 setRequestPostElement('points', bigintval(round(convertCommaToDot(postRequestElement('points')))));
93
94                 // Probe for enough points
95                 $probe_points = ((postRequestElement('points') >= getConfig('doubler_min')) && (postRequestElement('points') <= getConfig('doubler_max')));
96
97                 // Check all together
98                 if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestElement('pass'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
99                         // Nickname resolved to a unique userid or direct userid entered by the member
100                         $GLOBALS['doubler_userid'] = getUserData('userid');
101
102                         // Calulcate points
103                         $points = countSumTotalData(getUserData('userid'), 'user_points', 'points') - countSumTotalData(getUserData('userid'), 'user_data', 'used_points');
104
105                         // So let's continue with probing his points amount
106                         if (($points - getConfig('doubler_left') - postRequestElement('points') * getConfig('doubler_charge')) >= 0) {
107                                 // Enough points are left so let's continue with the doubling process
108                                 // Create doubling "account" width *DOUBLED* points
109                                 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')",
110                                         array(getUserData('userid'), determineReferalId(), bigintval(postRequestElement('points') * 2)), __FILE__, __LINE__);
111
112                                 // Subtract entered points
113                                 subtractPoints('doubler', getUserData('userid'), postRequestElement('points'));
114
115                                 // Add points to "total payed" including charge
116                                 $points = postRequestElement('points') - postRequestElement('points') * getConfig('doubler_charge');
117                                 updateConfiguration('doubler_points', $points, '+');
118                                 incrementConfigEntry('doubler_points', $points);
119
120                                 // Add second line for the referal but only when userid != refid
121                                 if ((determineReferalId() > 0) && (determineReferalId() != getUserData('userid'))) {
122                                         // Okay add a refid line and apply refid percents
123                                         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                                                 array(
125                                                         determineReferalId(),
126                                                         bigintval(postRequestElement('points') * 2 * getConfig('doubler_ref'))
127                                                 ), __FILE__, __LINE__);
128
129                                         // And that's why we don't want to you more than one referal level of doubler-points. ^^^
130                                 } // END - if
131
132                                 // Update usage counter
133                                 updateConfiguration('doubler_counter', 1, '+');
134
135                                 // Set constant
136                                 $content['message'] = loadTemplate('doubler_reflink', true, postRequestElement('userid'));
137                         } else {
138                                 // Not enougth points left
139                                 $content['message'] = getMessage('DOUBLER_FORM_NO_POINTS_LEFT');
140                         }
141                 } elseif (getUserData('status') == 'CONFIRMED') {
142                         // Account is unconfirmed!
143                         $content['message'] = getMessage('DOUBLER_FORM_WRONG_PASS');
144                 } elseif (getUserData('status') == 'UNCONFIRMED') {
145                         // Account is unconfirmed!
146                         $content['message'] = getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED');
147                 } elseif (getUserData('status') == 'LOCKED') {
148                         // Account is locked by admin / holiday!
149                         $content['message'] = getMessage('DOUBLER_FORM_STATUS_LOCKED');
150                 } elseif (postRequestElement('points') < getConfig('doubler_min')) {
151                         // Not enougth points entered
152                         $content['message'] = getMessage('DOUBLER_FORM_POINTS_MIN');
153                 } elseif (postRequestElement('points') > getConfig('doubler_max')) {
154                         // Too much points entered
155                         $content['message'] = getMessage('DOUBLER_FORM_POINTS_MAX');
156                 } elseif (isNickNameUsed(postRequestElement('userid'))) {
157                         // Cannot resolv nickname -> userid
158                         $content['message'] = getMessage('DOUBLER_FORM_404_NICKNAME');
159                 } else {
160                         // Wrong password or account not found
161                         $content['message'] = getMessage('DOUBLER_FORM_404_MEMBER');
162                 }
163         } elseif (!isPostRequestElementSet('userid')) {
164                 // Login not entered
165                 $content['message'] = getMessage('DOUBLER_FORM_404_LOGIN');
166         } elseif (!isPostRequestElementSet('pass')) {
167                 // Password not entered
168                 $content['message'] = getMessage('DOUBLER_FORM_404_PASSWORD');
169         } elseif (!isPostRequestElementSet('points')) {
170                 // points not entered
171                 $content['message'] = getMessage('DOUBLER_FORM_404_POINTS');
172         }
173 } // END - if (isFormSet())
174
175 // Shall I check for points immediately?
176 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/mails/doubler_mails.php');
177
178 // Output header
179 loadIncludeOnce('inc/header.php');
180
181 // Banner in text
182 $content['banner'] = loadTemplate('doubler_banner', true);
183
184 // Load header/footer templates
185 $content['header'] = loadTemplate('doubler_header', true);
186 $content['footer'] = loadTemplate('doubler_footer', true);
187
188 if (isUserDataValid()) {
189         // Transfer userid/nickname to constant
190         $content['refid'] = getUserData('userid');
191 } else {
192         // Transfer userid/nickname to constant
193         $content['refid'] = determineReferalId();
194 }
195
196 // Percent values etc.
197 $content['charge'] = translateComma(getConfig('doubler_charge') * 100);
198 $content['ref']    = translateComma(getConfig('doubler_ref') * 100);
199 $content['total']  = translateComma(getConfig('doubler_points'));
200 $content['min']    = translateComma(getConfig('doubler_min'));
201 $content['max']    = translateComma(getConfig('doubler_max'));
202
203 // Text "Enter login"
204 if (isExtensionActive('nickname')) {
205         // Choose login/nickname
206         $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN_NICKNAME');
207 } else {
208         // Simple login id
209         $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN');
210 }
211
212 // Which mail-send-mode did the admin setup?
213 $content['payout_time'] = getMessage('DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode'));
214
215 // Generate table with already payed out doubles
216 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
217
218 // Generate timemark
219 $content['timeout_mark'] = createFancyTime(getConfig('doubler_timeout'));
220
221 // Points left to doubler
222 $content['left'] = translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT());
223
224 // Output neccessary form for this
225 loadTemplate('doubler_index', false, $content);
226
227 // Output footer
228 loadIncludeOnce('inc/footer.php');
229
230 // [EOF]
231 ?>