Unneccessary div-s removed
[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  * 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 // Init content array
59 $content = array(
60         'message' => '',
61 );
62
63 // Begin with doubler script...
64 if (isFormSent()) {
65         // Secure points (so only integer/double values are allowed
66         setPostRequestParameter('points', bigintval(postRequestParameter('points')));
67
68         // Begin with doubling process
69         if ((isPostRequestParameterSet('userid')) && (isPostRequestParameterSet('pass')) && (isPostRequestParameterSet('points'))) {
70                 // Probe for nickname extension and if a nickname was entered
71                 if (isNickNameUsed(postRequestParameter('userid'))) {
72                         // Nickname in URL, so load the id
73                         fetchUserData(postRequestParameter('userid'), 'nickname');
74                 } else {
75                         // Direct userid entered
76                         fetchUserData(postRequestParameter('userid'));
77                 }
78
79                 // Is the data valid?
80                 if (!isUserDataValid()) {
81                         // Output message that the userid is not okay
82                         loadTemplate('admin_settings_saved', false, getMessage('DOUBLER_USERID_INVALID'));
83                 } // END - if
84
85                 // Remove any dots and unwanted chars from the points
86                 setPostRequestParameter('points', bigintval(round(convertCommaToDot(postRequestParameter('points')))));
87
88                 // Probe for enough points
89                 $probe_points = ((postRequestParameter('points') >= getConfig('doubler_min')) && (postRequestParameter('points') <= getConfig('doubler_max')));
90
91                 // Check all together
92                 if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestParameter('pass'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
93                         // Nickname resolved to a unique userid or direct userid entered by the member
94                         $GLOBALS['doubler_userid'] = getUserData('userid');
95
96                         // Calulcate points
97                         $points = countSumTotalData(getUserData('userid'), 'user_points', 'points') - countSumTotalData(getUserData('userid'), 'user_data', 'used_points');
98
99                         // So let's continue with probing his points amount
100                         if (($points - getConfig('doubler_left') - postRequestParameter('points') * getConfig('doubler_charge')) >= 0) {
101                                 // Enough points are left so let's continue with the doubling process
102                                 // Create doubling "account" width *DOUBLED* points
103                                 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')",
104                                         array(getUserData('userid'), determineReferalId(), bigintval(postRequestParameter('points') * 2)), __FILE__, __LINE__);
105
106                                 // Subtract entered points
107                                 subtractPoints('doubler', getUserData('userid'), postRequestParameter('points'));
108
109                                 // Add points to "total payed" including charge
110                                 $points = postRequestParameter('points') - postRequestParameter('points') * getConfig('doubler_charge');
111                                 updateConfiguration('doubler_points', $points, '+');
112                                 incrementConfigEntry('doubler_points', $points);
113
114                                 // Add second line for the referal but only when userid != refid
115                                 if ((determineReferalId() > 0) && (determineReferalId() != getUserData('userid'))) {
116                                         // Okay add a refid line and apply refid percents
117                                         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')",
118                                                 array(
119                                                         determineReferalId(),
120                                                         bigintval(postRequestParameter('points') * 2 * getConfig('doubler_ref'))
121                                                 ), __FILE__, __LINE__);
122
123                                         // And that's why we don't want to you more than one referal level of doubler-points. ^^^
124                                 } // END - if
125
126                                 // Update usage counter
127                                 updateConfiguration('doubler_counter', 1, '+');
128
129                                 // Set constant
130                                 $content['message'] = loadTemplate('doubler_reflink', true, postRequestParameter('userid'));
131                         } else {
132                                 // Not enougth points left
133                                 $content['message'] = getMessage('DOUBLER_FORM_NO_POINTS_LEFT');
134                         }
135                 } elseif (getUserData('status') == 'CONFIRMED') {
136                         // Account is unconfirmed!
137                         $content['message'] = getMessage('DOUBLER_FORM_WRONG_PASS');
138                 } elseif (getUserData('status') == 'UNCONFIRMED') {
139                         // Account is unconfirmed!
140                         $content['message'] = getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED');
141                 } elseif (getUserData('status') == 'LOCKED') {
142                         // Account is locked by admin / holiday!
143                         $content['message'] = getMessage('DOUBLER_FORM_STATUS_LOCKED');
144                 } elseif (postRequestParameter('points') < getConfig('doubler_min')) {
145                         // Not enougth points entered
146                         $content['message'] = getMessage('DOUBLER_FORM_POINTS_MIN');
147                 } elseif (postRequestParameter('points') > getConfig('doubler_max')) {
148                         // Too much points entered
149                         $content['message'] = getMessage('DOUBLER_FORM_POINTS_MAX');
150                 } elseif (isNickNameUsed(postRequestParameter('userid'))) {
151                         // Cannot resolv nickname -> userid
152                         $content['message'] = getMessage('DOUBLER_FORM_404_NICKNAME');
153                 } else {
154                         // Wrong password or account not found
155                         $content['message'] = getMessage('DOUBLER_FORM_404_MEMBER');
156                 }
157         } elseif (!isPostRequestParameterSet('userid')) {
158                 // Login not entered
159                 $content['message'] = getMessage('DOUBLER_FORM_404_LOGIN');
160         } elseif (!isPostRequestParameterSet('pass')) {
161                 // Password not entered
162                 $content['message'] = getMessage('DOUBLER_FORM_404_PASSWORD');
163         } elseif (!isPostRequestParameterSet('points')) {
164                 // points not entered
165                 $content['message'] = getMessage('DOUBLER_FORM_404_POINTS');
166         }
167 } // END - if (isFormSet())
168
169 // Shall I check for points immediately?
170 if (getConfig('doubler_send_mode') == 'DIRECT') loadInclude('inc/mails/doubler_mails.php');
171
172 // Output header
173 loadIncludeOnce('inc/header.php');
174
175 // Banner in text
176 $content['banner'] = loadTemplate('doubler_banner', true);
177
178 // Load header/footer templates
179 $content['header'] = loadTemplate('doubler_header', true);
180 $content['footer'] = loadTemplate('doubler_footer', true);
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'] = determineReferalId();
188 }
189
190 // Percent values etc.
191 $content['charge'] = translateComma(getConfig('doubler_charge') * 100);
192 $content['ref']    = translateComma(getConfig('doubler_ref') * 100);
193 $content['total']  = translateComma(getConfig('doubler_points'));
194 $content['min']    = translateComma(getConfig('doubler_min'));
195 $content['max']    = translateComma(getConfig('doubler_max'));
196
197 // Text "Enter login"
198 if (isExtensionActive('nickname')) {
199         // Choose login/nickname
200         $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN_NICKNAME');
201 } else {
202         // Simple login id
203         $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN');
204 }
205
206 // Which mail-send-mode did the admin setup?
207 $content['payout_time'] = getMessage('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 // Generate timemark
213 $content['timeout_mark'] = createFancyTime(getConfig('doubler_timeout'));
214
215 // Points left to doubler
216 $content['left'] = translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT());
217
218 // Output neccessary form for this
219 loadTemplate('doubler_index', false, $content);
220
221 // Output footer
222 loadIncludeOnce('inc/footer.php');
223
224 // [EOF]
225 ?>