]> git.mxchange.org Git - mailer.git/blob - doubler.php
Referal overview finished and rewritten for refback extension
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
35 require_once("inc/libs/security_functions.php");
36
37 // Init "action" and "what"
38 global $what, $action, $startTime;
39 $GLOBALS['startTime'] = microtime(true);
40 $GLOBALS['what'] = "";
41 $GLOBALS['action'] = "";
42
43 // Set module
44 $GLOBALS['module'] = "doubler";
45 $GLOBALS['refid'] = 0;
46 $CSS = 0;
47
48 // Load the required file(s)
49 require ("inc/config.php");
50
51 // Is the "doubler" extension active?
52 if (!EXT_IS_ACTIVE("doubler")) {
53         // Redirect to index
54         LOAD_URL("modules.php?module=index&amp;msg=".CODE_EXTENSION_PROBLEM."&amp;ext=doubler");
55 } // END - if
56
57 // Is the script installed?
58 if (isBooleanConstantAndTrue('mxchange_installed')) {
59         // Probe for referal ID
60         if (!empty($_GET['refid'])) $GLOBALS['refid'] = bigintval($_GET['refid']);
61
62         // Probe for nickname extension and if a nickname was supplied by URL
63         $probe_nickname = ((EXT_IS_ACTIVE("nickname")) && (("".round($GLOBALS['refid'])."") != $GLOBALS['refid']));
64         if ($probe_nickname) {
65                 // Nickname in URL, so load the ID
66                 $result = SQL_QUERY_ESC("SELECT userid, status FROM "._MYSQL_PREFIX."_user_data WHERE nickname='%s' LIMIT 1",
67                  array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
68         } else {
69                 // Direct userid entered
70                 $result = SQL_QUERY_ESC("SELECT userid, status FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
71                  array(bigintval($GLOBALS['refid'])), __FILE__, __LINE__);
72         }
73
74         // Load data
75         list($rid, $status_ref) = SQL_FETCHROW($result);
76         $GLOBALS['refid'] = bigintval($rid);
77
78         // Free memory
79         SQL_FREERESULT($result);
80         $uid = 0;
81
82         // If no account was found set default refid and status to CONFIRMED
83         if (empty($GLOBALS['refid'])) {
84                 $GLOBALS['refid'] = $_CONFIG['def_refid'];
85                 $status = "CONFIRMED";
86         } // END - if
87
88         // Begin with doubler script...
89         if (isset($_POST['ok'])) {
90                 // Secure points (so only integer/double values are allowed
91                 $_POST['points'] = bigintval($_POST['points']);
92
93                 // Begin with doubling process
94                 if ((!empty($_POST['userid'])) && (!empty($_POST['pass'])) && (!empty($_POST['points']))) {
95                         // Probe for nickname extension and if a nickname was entered
96                         $probe_nickname = ((EXT_IS_ACTIVE("nickname")) && (("".round($_POST['userid'])."") != $_POST['userid']));
97                         if ($probe_nickname) {
98                                 // Nickname in URL, so load the ID
99                                 $result = SQL_QUERY_ESC("SELECT userid, status, password FROM "._MYSQL_PREFIX."_user_data WHERE nickname='%s' LIMIT 1",
100                                  array($_POST['userid']), __FILE__, __LINE__);
101                         } else {
102                                 // Direct userid entered
103                                 $result = SQL_QUERY_ESC("SELECT userid, status, password FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
104                                  array(bigintval($_POST['userid'])), __FILE__, __LINE__);
105                         }
106
107                         // Load data
108                         list($uid, $status, $password) = SQL_FETCHROW($result);
109                         $uid = bigintval($uid);
110
111                         // Free result
112                         SQL_FREERESULT($result);
113
114                         // Remove any dots and unwanted chars from the points
115                         $_POST['points'] = bigintval(round(REVERT_COMMA($_POST['points'])));
116
117                         // Probe for enough points
118                         $probe_points = (($_POST['points'] >= $_CONFIG['doubler_min']) && ($_POST['points'] <= $_CONFIG['doubler_max']));
119
120                         // Check all together
121                         if ((!empty($uid)) && ($password == generateHash($_POST['pass'], substr($password, 0, -40))) && ($status == "CONFIRMED") && ($probe_points)) {
122                                 // Nickname resolved to a unique userid or direct userid entered by the member
123                                 $DOUBLER_UID = $uid;
124
125                                 // Calulcate points
126                                 $points = GET_TOTAL_DATA($uid, "user_points", "points") - GET_TOTAL_DATA($uid, "user_data", "used_points");
127
128                                 // So let's continue with probing his points amount
129                                 if (($points - $_CONFIG['doubler_left'] - $_POST['points'] * $_CONFIG['doubler_charge']) >= 0)
130                                 {
131                                         // Enough points are left so let's continue with the doubling process
132                                         // Create doubling "account" width *DOUBLED* points
133                                         $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_doubler (userid, refid, points, remote_ip, timemark, completed, is_ref) VALUES ('%s','%s','%s','".GET_REMOTE_ADDR()."', UNIX_TIMESTAMP(), 'N','N')",
134                                          array($uid, bigintval($GLOBALS['refid']), bigintval($_POST['points'] * 2)), __FILE__, __LINE__);
135
136                                         // Subtract entered points
137                                         SUB_POINTS($uid, $_POST['points']);
138
139                                         // Add points to "total payed" including charge
140                                         $points = $_POST['points'] - $_POST['points'] * $_CONFIG['doubler_charge'];
141                                         UPDATE_CONFIG("doubler_points", $points, "+");
142                                         $_CONFIG['doubler_points'] += $points;
143
144                                         // Add second line for the referal but only when uid != refid
145                                         if (($GLOBALS['refid'] > 0) && ($GLOBALS['refid'] != $uid)) {
146                                                 // Okay add a refid line and apply refid percents
147                                                 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_doubler (userid,refid,points,remote_ip,timemark,completed,is_ref) VALUES ('%s',0,'%s','".GET_REMOTE_ADDR()."',UNIX_TIMESTAMP(),'N','Y')",
148                                                         array(bigintval($GLOBALS['refid']), bigintval($_POST['points'] * 2 * $_CONFIG['doubler_ref'])), __FILE__, __LINE__);
149
150                                                 // And that's why we dont't want to you more than one referal level of doubler-points. ^^^
151                                         } // END - if
152
153                                         // Update usage counter
154                                         UPDATE_CONFIG("doubler_counter", 1, "+");
155                                         $_CONFIG['doubler_counter']++;
156
157                                         // Set constant
158                                         define('__DOUBLER_MSG', LOAD_TEMPLATE("doubler_reflink", true, $_POST['userid']));
159                                 } else {
160                                         // Not enougth points left
161                                         define('__ERROR_MSG', DOUBLER_FORM_NO_POINTS_LEFT);
162                                 }
163                         } elseif ($status == "CONFIRMED") {
164                                 // Account is unconfirmed!
165                                 define('__ERROR_MSG', DOUBLER_FORM_WRONG_PASS);
166                         } elseif ($status == "UNCONFIRMED") {
167                                 // Account is unconfirmed!
168                                 define('__ERROR_MSG', DOUBLER_FORM_STATUS_UNCONFIRMED);
169                         } elseif ($status == "LOCKED") {
170                                 // Account is locked by admin / holiday!
171                                 define('__ERROR_MSG', DOUBLER_FORM_STATUS_LOCKED);
172                         } elseif ($_POST['points'] < $_CONFIG['doubler_min']) {
173                                 // Not enougth points entered
174                                 define('__ERROR_MSG', DOUBLER_FORM_POINTS_MIN);
175                         } elseif ($_POST['points'] > $_CONFIG['doubler_max']) {
176                                 // Too much points entered
177                                 define('__ERROR_MSG', DOUBLER_FORM_POINTS_MAX);
178                         } elseif ($probe_nickname) {
179                                 // Cannot resolv nickname -> userid
180                                 define('__ERROR_MSG', DOUBLER_FORM_404_NICKNAME);
181                         } else {
182                                 // Wrong password or account not found
183                                 define('__ERROR_MSG', DOUBLER_FORM_404_MEMBER);
184                         }
185                 } elseif (empty($_POST['userid'])) {
186                         // Login not entered
187                         define('__ERROR_MSG', DOUBLER_FORM_404_LOGIN);
188                 } elseif (empty($_POST['pass'])) {
189                         // Password not entered
190                         define('__ERROR_MSG', DOUBLER_FORM_404_PASSWORD);
191                 } elseif (empty($_POST['points'])) {
192                         // points not entered
193                         define('__ERROR_MSG', DOUBLER_FORM_404_POINTS);
194                 }
195         }
196
197         // Set messages to nothing
198         if (!defined('__DOUBLER_MSG')) define('__DOUBLER_MSG', "");
199         if (!defined('__ERROR_MSG'))   define('__ERROR_MSG'  , "");
200
201         // Shall I check for points immediately?
202         if ($_CONFIG['doubler_send_mode'] == "DIRECT") require(PATH."inc/doubler_send.php");
203
204         // Output header
205         include(PATH."inc/header.php");
206
207         // Banner in text
208         define('__DOUBLER_BANNER', LOAD_TEMPLATE("doubler_banner", true));
209
210         // Load header/footer templates
211         define('__DOUBLER_HEADER', LOAD_TEMPLATE("doubler_header", true));
212         define('__DOUBLER_FOOTER', LOAD_TEMPLATE("doubler_footer", true));
213
214         if (!empty($uid)) {
215                 // Transfer userid/nickname to constant
216                 define('__REFID', $uid);
217         } elseif (!empty($GLOBALS['refid'])) {
218                 // Transfer userid/nickname to constant
219                 define('__REFID', $GLOBALS['refid']);
220         } else {
221                 // Transfer default refid to constant
222                 define('__REFID', $_CONFIG['def_refid']);
223         }
224
225         // Percent values etc.
226         define('__CHARGE_VALUE', TRANSLATE_COMMA($_CONFIG['doubler_charge'] * 100));
227         define('__REF_VALUE'   , TRANSLATE_COMMA($_CONFIG['doubler_ref'] * 100));
228         define('__TOTAL_VALUE' , TRANSLATE_COMMA($_CONFIG['doubler_points']));
229         define('__MIN_VALUE'   , TRANSLATE_COMMA($_CONFIG['doubler_min']));
230         define('__MAX_VALUE'   , TRANSLATE_COMMA($_CONFIG['doubler_max']));
231
232         // Text "Enter login"
233         if (EXT_IS_ACTIVE("nickname")) {
234                 // Choose login/nickname
235                 define('DOUBLER_ENTER_LOGIN', GUEST_ENTER_LOGIN_NICKNAME);
236         } else {
237                 // Simple login ID
238                 define('DOUBLER_ENTER_LOGIN', GUEST_ENTER_LOGIN);
239         }
240
241         // Which mail-send-mode did the admin setup?
242         switch ($_CONFIG['doubler_send_mode'])
243         {
244         case "DIRECT":
245                 define('DOUBLER_PAYOUT_TIME', DOUBLER_PAYOUT_TIME_DIRECT);
246                 break;
247
248         case "RESET":
249                 define('DOUBLER_PAYOUT_TIME', DOUBLER_PAYOUT_TIME_RESET);
250                 break;
251         }
252
253         // Generate table with already payed out doubles
254         define('__DOUBLER_PAYOUT_HISTORY', DOUBLER_GENERATE_TABLE("0", "Y", "N", "DESC"));
255
256         // Generate timemark
257         define('__TIMEOUT_MARK', CREATE_FANCY_TIME($_CONFIG['doubler_timeout']));
258
259         // Usage counter
260         define('__DOUBLER_COUNTER', $_CONFIG['doubler_counter']);
261
262         // Points left to doubler
263         define('__LEFT_VALUE', TRANSLATE_COMMA(DOUBLER_GET_TOTAL_POINTS_LEFT()));
264
265         // Output neccessary form for this
266         LOAD_TEMPLATE("doubler_index");
267
268         // Output footer
269         include(PATH."inc/footer.php");
270 } else {
271         // You have to configure first!
272         LOAD_URL("install.php");
273 }
274
275 // Really all done here... ;-)
276 ?>