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