Missing template 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 // 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         setRequestPostElement('points', bigintval(postRequestElement('points')));
67
68         // Begin with doubling process
69         if ((isPostRequestElementSet('userid')) && (isPostRequestElementSet('pass')) && (isPostRequestElementSet('points'))) {
70                 // Probe for nickname extension and if a nickname was entered
71                 if (isNickNameUsed(postRequestElement('userid'))) {
72                         // Nickname in URL, so load the id
73                         fetchUserData(postRequestElement('userid'), 'nickname');
74                 } else {
75                         // Direct userid entered
76                         fetchUserData(postRequestElement('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                 // Free result
86                 SQL_FREERESULT($result);
87
88                 // Remove any dots and unwanted chars from the points
89                 setRequestPostElement('points', bigintval(round(convertCommaToDot(postRequestElement('points')))));
90
91                 // Probe for enough points
92                 $probe_points = ((postRequestElement('points') >= getConfig('doubler_min')) && (postRequestElement('points') <= getConfig('doubler_max')));
93
94                 // Check all together
95                 if ((isUserDataValid()) && (getUserData('password') == generateHash(postRequestElement('pass'), substr(getUserData('password'), 0, -40))) && (getUserData('status') == 'CONFIRMED') && ($probe_points)) {
96                         // Nickname resolved to a unique userid or direct userid entered by the member
97                         $GLOBALS['doubler_userid'] = getUserData('userid');
98
99                         // Calulcate points
100                         $points = countSumTotalData(getUserData('userid'), 'user_points', 'points') - countSumTotalData(getUserData('userid'), 'user_data', 'used_points');
101
102                         // So let's continue with probing his points amount
103                         if (($points - getConfig('doubler_left') - postRequestElement('points') * getConfig('doubler_charge')) >= 0) {
104                                 // Enough points are left so let's continue with the doubling process
105                                 // Create doubling "account" width *DOUBLED* points
106                                 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')",
107                                         array(getUserData('userid'), determineReferalId(), bigintval(postRequestElement('points') * 2)), __FILE__, __LINE__);
108
109                                 // Subtract entered points
110                                 subtractPoints('doubler', getUserData('userid'), postRequestElement('points'));
111
112                                 // Add points to "total payed" including charge
113                                 $points = postRequestElement('points') - postRequestElement('points') * getConfig('doubler_charge');
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 ((determineReferalId() > 0) && (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                                                         determineReferalId(),
123                                                         bigintval(postRequestElement('points') * 2 * getConfig('doubler_ref'))
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, postRequestElement('userid'));
134                         } else {
135                                 // Not enougth points left
136                                 $content['message'] = getMessage('DOUBLER_FORM_NO_POINTS_LEFT');
137                         }
138                 } elseif (getUserData('status') == 'CONFIRMED') {
139                         // Account is unconfirmed!
140                         $content['message'] = getMessage('DOUBLER_FORM_WRONG_PASS');
141                 } elseif (getUserData('status') == 'UNCONFIRMED') {
142                         // Account is unconfirmed!
143                         $content['message'] = getMessage('DOUBLER_FORM_STATUS_UNCONFIRMED');
144                 } elseif (getUserData('status') == 'LOCKED') {
145                         // Account is locked by admin / holiday!
146                         $content['message'] = getMessage('DOUBLER_FORM_STATUS_LOCKED');
147                 } elseif (postRequestElement('points') < getConfig('doubler_min')) {
148                         // Not enougth points entered
149                         $content['message'] = getMessage('DOUBLER_FORM_POINTS_MIN');
150                 } elseif (postRequestElement('points') > getConfig('doubler_max')) {
151                         // Too much points entered
152                         $content['message'] = getMessage('DOUBLER_FORM_POINTS_MAX');
153                 } elseif (isNickNameUsed(postRequestElement('userid'))) {
154                         // Cannot resolv nickname -> userid
155                         $content['message'] = getMessage('DOUBLER_FORM_404_NICKNAME');
156                 } else {
157                         // Wrong password or account not found
158                         $content['message'] = getMessage('DOUBLER_FORM_404_MEMBER');
159                 }
160         } elseif (!isPostRequestElementSet('userid')) {
161                 // Login not entered
162                 $content['message'] = getMessage('DOUBLER_FORM_404_LOGIN');
163         } elseif (!isPostRequestElementSet('pass')) {
164                 // Password not entered
165                 $content['message'] = getMessage('DOUBLER_FORM_404_PASSWORD');
166         } elseif (!isPostRequestElementSet('points')) {
167                 // points not entered
168                 $content['message'] = getMessage('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 // Percent values etc.
194 $content['charge'] = translateComma(getConfig('doubler_charge') * 100);
195 $content['ref']    = translateComma(getConfig('doubler_ref') * 100);
196 $content['total']  = translateComma(getConfig('doubler_points'));
197 $content['min']    = translateComma(getConfig('doubler_min'));
198 $content['max']    = translateComma(getConfig('doubler_max'));
199
200 // Text "Enter login"
201 if (isExtensionActive('nickname')) {
202         // Choose login/nickname
203         $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN_NICKNAME');
204 } else {
205         // Simple login id
206         $content['enter_login'] = getMessage('GUEST_ENTER_LOGIN');
207 }
208
209 // Which mail-send-mode did the admin setup?
210 $content['payout_time'] = getMessage('DOUBLER_PAYOUT_TIME_' . getConfig('doubler_send_mode'));
211
212 // Generate table with already payed out doubles
213 $content['payout_history'] = generateDoublerTable(0, 'Y', 'N', 'DESC');
214
215 // Generate timemark
216 $content['timeout_mark'] = createFancyTime(getConfig('doubler_timeout'));
217
218 // Points left to doubler
219 $content['left'] = translateComma(DOUBLER_GET_TOTAL_POINTS_LEFT());
220
221 // Output neccessary form for this
222 loadTemplate('doubler_index', false, $content);
223
224 // Output footer
225 loadIncludeOnce('inc/footer.php');
226
227 // [EOF]
228 ?>