2 /************************************************************************
3 * MXChange v0.2.1 Start: 04/12/2004 *
4 * ================ Last change: 11/16/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-wernis.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Wernis requests *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auszahlungsanfragen *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif (!IS_MEMBER()) {
39 // User is not logged in
40 LOAD_URL("modules.php?module=index");
41 } elseif ((!EXT_IS_ACTIVE("wernis")) && (!IS_ADMIN())) {
42 addFatalMessage(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "wernis");
46 // Add description as navigation point
47 ADD_DESCR("member", __FILE__);
49 // Check if the admin has entered the data
50 if ((getConfig('wernis_api_id') == "") || (getConfig('wernis_api_md5') == "")) {
51 // Something important is missing...
52 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_API_DATA_MISSING'));
56 // Init the content array and points
57 $content = array(); $points = false;
59 // Is the mode set (withdraw or payout)
60 if ((!REQUEST_ISSET_GET(('mode'))) || (REQUEST_GET('mode') == "choose")) {
61 // Let the user choose what he wants to do
62 $content['refid'] = bigintval(getConfig('wernis_refid'));
63 $content['wds66_id'] = 0;
66 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
67 array($GLOBALS['userid']), __FILE__, __LINE__);
69 // Are there some entries?
70 if (SQL_NUMROWS($result) == 1) {
72 list($content['wds66_id']) = SQL_FETCHROW($result);
76 SQL_FREERESULT($result);
79 if ((!empty($content['wds66_id'])) && (!REQUEST_ISSET_GET(('mode')))) {
80 // Then use an other "mode"
81 REQUEST_SET_GET('mode', "list");
84 $result = SQL_QUERY_ESC("SELECT `id`, `wernis_account`, `wernis_amount`, `wernis_timestamp`, `wernis_type` FROM `{!_MYSQL_PREFIX!}_user_wernis` WHERE `userid` = %s ORDER BY `wernis_timestamp` DESC",
85 array($GLOBALS['userid']), __FILE__, __LINE__);
88 $content['rows'] = ""; $SW = 2;
89 while ($data = SQL_FETCHARRAY($result)) {
90 // Prepare data for output
92 'stamp' => MAKE_DATETIME($data['wernis_timestamp'], "2"),
93 'points' => TRANSLATE_COMMA($data['wernis_amount']),
94 'acc' => bigintval($data['wernis_account']),
95 'status' => WERNIS_TRANSFER_STATUS($data['wernis_type']),
96 'raw_type' => strtolower($data['wernis_type']),
101 $content['rows'] .= LOAD_TEMPLATE("member_wernis_mode_list_row", true, $rowContent);
106 SQL_FREERESULT($result);
108 // Default links are not active!
109 $content['payout_link'] = "<em>{--WERNIS_MEMBER_PAYOUT_DISABLED--}</em>";
110 $content['withdraw_link'] = "<em>{--WERNIS_MEMBER_WITHDRAW_DISABLED--}</em>";
112 // Is the payout mode active?
113 if (getConfig('wernis_payout_active') == "Y") {
115 $content['payout_link'] = "<a class=\"menu_blur\" style=\"height: 40px\" href=\"{!URL!}/modules.php?module=login&what=wernis&mode=payout\"><div style=\"padding-top: 10px\">{--MEMBER_WERNIS_MODE_PAYOUT--}</div></a>";
118 // Is the withdraw mode active?
119 if (getConfig('wernis_withdraw_active') == "Y") {
121 $content['withdraw_link'] = "<a class=\"menu_blur\" style=\"height: 40px\" href=\"{!URL!}/modules.php?module=login&what=wernis&mode=withdraw\"><div style=\"padding-top: 10px\">{--MEMBER_WERNIS_MODE_WITHDRAW--}</div></a>";
125 REQUEST_SET_GET('mode', "choose");
127 } elseif ((REQUEST_GET('mode') == "payout") && (getConfig('wernis_payout_active') == "Y")) {
128 // Get total points and check if the user can request a payout
129 $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
131 // Remove the registration fee
132 $points = $points - getConfig('points_register');
134 // Is there a percentage or fixed fee?
135 $points = WERNIS_TAKE_FEE($points, "payout");
137 // Is this enougth for a payout?
138 if ($points < getConfig('wernis_min_payout')) {
139 // No, then abort here
140 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_MIN_PAYOUT'), TRANSLATE_COMMA(getConfig('wernis_min_payout'))));
145 $points = explode(".", $points);
146 $points = bigintval($points[0]);
148 // Add points to content array
149 $content['points'] = TRANSLATE_COMMA($points);
150 $content['min_points'] = TRANSLATE_COMMA(getConfig('wernis_min_payout'));
153 WERNIS_ADD_FEES_TO_ARRAY($content);
156 $content['wds66_id'] = "";
157 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
158 array($GLOBALS['userid']), __FILE__, __LINE__);
160 // Are there some entries?
161 if (SQL_NUMROWS($result) == 1) {
163 list($content['wds66_id']) = SQL_FETCHROW($result);
167 SQL_FREERESULT($result);
168 } elseif ((REQUEST_GET('mode') == "withdraw") && (getConfig('wernis_withdraw_active') == "Y")) {
169 // Get total points for just displaying them
170 $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
172 // Prepare data for the template
173 $content['points'] = TRANSLATE_COMMA($points);
174 $content['min_points'] = TRANSLATE_COMMA(getConfig('wernis_min_withdraw'));
175 $content['wds66_id'] = "";
178 WERNIS_ADD_FEES_TO_ARRAY($content);
181 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
182 array($GLOBALS['userid']), __FILE__, __LINE__);
184 // Are there some entries?
185 if (SQL_NUMROWS($result) == 1) {
187 list($content['wds66_id']) = SQL_FETCHROW($result);
191 SQL_FREERESULT($result);
194 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_MODE_INVALID, REQUEST_GET(('mode'))));
198 // Is the formular sent?
199 if ((IS_FORM_SENT()) && (REQUEST_ISSET_GET(('mode')))) {
200 // Is the user ID and password set?
201 if (!REQUEST_ISSET_POST(('wds66_id'))) {
202 // Nothing entered in WDS66 user ID
203 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_USERNAME);
204 } elseif (!REQUEST_ISSET_POST(('wds66_password'))) {
205 // Nothing entered in WDS66 password
206 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_PASSWORD);
207 } elseif (!REQUEST_ISSET_POST(('amount'))) {
208 // Nothing entered in amount
209 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_AMOUNT);
210 } elseif (REQUEST_POST('wds66_id') != bigintval(REQUEST_POST('wds66_id'))) {
211 // Only numbers in account ID!
212 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_USERNAME);
213 } elseif (REQUEST_POST('amount') != bigintval(REQUEST_POST('amount'))) {
214 // Only numbers in amount!
215 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_AMOUNT);
217 // Check input data depending on the mode and execute the requested mode
218 switch (REQUEST_GET('mode')) {
219 case "withdraw": // Widthdraws WDS66 -> This exchange
220 if (REQUEST_POST('amount') < getConfig('wernis_min_withdraw')) {
221 // Not enougth entered!
222 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_AMOUNT_SMALLER_MIN, bigintval(getConfig('wernis_min_withdraw'))));
224 // All is fine here so do the withdraw
225 $success = WERNIS_EXECUTE_WITHDRAW(REQUEST_POST('wds66_id'), md5(REQUEST_POST('wds66_password')), REQUEST_POST('amount'));
227 // Add it to this amount
228 unset($GLOBALS['ref_level']);
229 ADD_POINTS_REFSYSTEM("wernis_withdraw", $GLOBALS['userid'], bigintval(REQUEST_POST('amount')), false, 0, false, "direct");
231 // Update the user data as well..
232 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
233 array(bigintval(REQUEST_POST('wds66_id')), $GLOBALS['userid']), __FILE__, __LINE__);
236 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_WITHDRAW_DONE);
238 } elseif ((GET_WERNIS_ERROR_CODE() == "user_failed") || (GET_WERNIS_ERROR_CODE() == "own_failed") || (GET_WERNIS_ERROR_CODE() == "amount_failed")) {
240 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
242 // Something went wrong
243 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_WITHDRAW_FAILED, GET_WERNIS_ERROR_MESSAGE()));
248 case "payout": // Payout this exchange -> WDS66
249 if (REQUEST_POST('amount') < getConfig('wernis_min_payout')) {
250 // Not enougth entered!
251 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_AMOUNT_SMALLER_MIN, bigintval(getConfig('wernis_min_payout'))));
252 } elseif (REQUEST_POST('amount') > $points) {
253 // Not enougth points left!
254 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_PAYOUT_POINTS_DEPLETED, bigintval(REQUEST_POST('amount')), bigintval($points)));
256 // All is fine here so do the withdraw
257 $success = WERNIS_EXECUTE_PAYOUT(REQUEST_POST('wds66_id'), REQUEST_POST('amount'));
260 SUB_POINTS("wernis_payout", $GLOBALS['userid'], REQUEST_POST('amount'));
263 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
264 array(bigintval(REQUEST_POST('wds66_id')), $GLOBALS['userid']), __FILE__, __LINE__);
267 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_PAYOUT_DONE);
269 } elseif ((GET_WERNIS_ERROR_CODE() == "user_failed") || (GET_WERNIS_ERROR_CODE() == "own_failed") || (GET_WERNIS_ERROR_CODE() == "amount_failed") || (GET_WERNIS_ERROR_CODE() == "api_amount_failed")) {
271 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
273 // Something went wrong
274 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_WITHDRAW_FAILED, GET_WERNIS_ERROR_MESSAGE()));
279 default: // Invalid mode!
280 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", REQUEST_GET('mode')));
281 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_MODE_INVALID, REQUEST_GET(('mode'))));
287 // Prepare mode for template name
288 $mode = sprintf("member_wernis_mode_%s", REQUEST_GET(('mode')));
291 LOAD_TEMPLATE($mode, false, $content);