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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
43 } elseif (!IS_MEMBER()) {
44 // User is not logged in
45 LOAD_URL("modules.php?module=index");
46 } elseif ((!EXT_IS_ACTIVE("wernis")) && (!IS_ADMIN())) {
47 addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "wernis");
51 // Add description as navigation point
52 ADD_DESCR("member", __FILE__);
54 // Check if the admin has entered the data
55 if ((getConfig('wernis_api_id') == "") || (getConfig('wernis_api_md5') == "")) {
56 // Something important is missing...
57 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_API_DATA_MISSING'));
61 // Init the content array and points
62 $content = array(); $points = false;
64 // Is the mode set (withdraw or payout)
65 if ((!REQUEST_ISSET_GET(('mode'))) || (REQUEST_GET('mode') == "choose")) {
66 // Let the user choose what he wants to do
67 $content['refid'] = getConfig(('wernis_refid'));
68 $content['wds66_id'] = 0;
71 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
72 array(getUserId()), __FILE__, __LINE__);
74 // Are there some entries?
75 if (SQL_NUMROWS($result) == 1) {
77 list($content['wds66_id']) = SQL_FETCHROW($result);
81 SQL_FREERESULT($result);
84 if ((!empty($content['wds66_id'])) && (!REQUEST_ISSET_GET(('mode')))) {
85 // Then use an other "mode"
86 REQUEST_SET_GET('mode', "list");
89 $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",
90 array(getUserId()), __FILE__, __LINE__);
93 $content['rows'] = ""; $SW = 2;
94 while ($data = SQL_FETCHARRAY($result)) {
95 // Prepare data for output
97 'stamp' => MAKE_DATETIME($data['wernis_timestamp'], "2"),
98 'points' => TRANSLATE_COMMA($data['wernis_amount']),
99 'acc' => bigintval($data['wernis_account']),
100 'status' => WERNIS_TRANSFER_STATUS($data['wernis_type']),
101 'raw_type' => strtolower($data['wernis_type']),
106 $content['rows'] .= LOAD_TEMPLATE("member_wernis_mode_list_row", true, $rowContent);
111 SQL_FREERESULT($result);
113 // Default links are not active!
114 $content['payout_link'] = "<em>{--WERNIS_MEMBER_PAYOUT_DISABLED--}</em>";
115 $content['withdraw_link'] = "<em>{--WERNIS_MEMBER_WITHDRAW_DISABLED--}</em>";
117 // Is the payout mode active?
118 if (getConfig('wernis_payout_active') == "Y") {
120 $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>";
123 // Is the withdraw mode active?
124 if (getConfig('wernis_withdraw_active') == "Y") {
126 $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>";
130 REQUEST_SET_GET('mode', "choose");
132 } elseif ((REQUEST_GET('mode') == "payout") && (getConfig('wernis_payout_active') == "Y")) {
133 // Get total points and check if the user can request a payout
134 $points = GET_TOTAL_DATA(getUserId(), "user_points", "points") - GET_TOTAL_DATA(getUserId(), "user_data", "used_points");
136 // Remove the registration fee
137 $points = $points - getConfig('points_register');
139 // Is there a percentage or fixed fee?
140 $points = WERNIS_TAKE_FEE($points, "payout");
142 // Is this enougth for a payout?
143 if ($points < getConfig('wernis_min_payout')) {
144 // No, then abort here
145 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_MIN_PAYOUT'), TRANSLATE_COMMA(getConfig('wernis_min_payout'))));
150 $points = explode(".", $points);
151 $points = bigintval($points[0]);
153 // Add points to content array
154 $content['points'] = TRANSLATE_COMMA($points);
155 $content['min_points'] = TRANSLATE_COMMA(getConfig('wernis_min_payout'));
158 WERNIS_ADD_FEES_TO_ARRAY($content);
161 $content['wds66_id'] = "";
162 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
163 array(getUserId()), __FILE__, __LINE__);
165 // Are there some entries?
166 if (SQL_NUMROWS($result) == 1) {
168 list($content['wds66_id']) = SQL_FETCHROW($result);
172 SQL_FREERESULT($result);
173 } elseif ((REQUEST_GET('mode') == "withdraw") && (getConfig('wernis_withdraw_active') == "Y")) {
174 // Get total points for just displaying them
175 $points = GET_TOTAL_DATA(getUserId(), "user_points", "points") - GET_TOTAL_DATA(getUserId(), "user_data", "used_points");
177 // Prepare data for the template
178 $content['points'] = TRANSLATE_COMMA($points);
179 $content['min_points'] = TRANSLATE_COMMA(getConfig('wernis_min_withdraw'));
180 $content['wds66_id'] = "";
183 WERNIS_ADD_FEES_TO_ARRAY($content);
186 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
187 array(getUserId()), __FILE__, __LINE__);
189 // Are there some entries?
190 if (SQL_NUMROWS($result) == 1) {
192 list($content['wds66_id']) = SQL_FETCHROW($result);
196 SQL_FREERESULT($result);
199 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_MODE_INVALID'), REQUEST_GET(('mode'))));
203 // Is the formular sent?
204 if ((IS_FORM_SENT()) && (REQUEST_ISSET_GET(('mode')))) {
205 // Is the user ID and password set?
206 if (!REQUEST_ISSET_POST(('wds66_id'))) {
207 // Nothing entered in WDS66 user ID
208 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_EMPTY_USERNAME'));
209 } elseif (!REQUEST_ISSET_POST(('wds66_password'))) {
210 // Nothing entered in WDS66 password
211 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_EMPTY_PASSWORD'));
212 } elseif (!REQUEST_ISSET_POST(('amount'))) {
213 // Nothing entered in amount
214 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_EMPTY_AMOUNT'));
215 } elseif (REQUEST_POST('wds66_id') != bigintval(REQUEST_POST('wds66_id'))) {
216 // Only numbers in account ID!
217 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_INVALID_USERNAME'));
218 } elseif (REQUEST_POST('amount') != bigintval(REQUEST_POST('amount'))) {
219 // Only numbers in amount!
220 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_INVALID_AMOUNT'));
222 // Check input data depending on the mode and execute the requested mode
223 switch (REQUEST_GET('mode')) {
224 case "withdraw": // Widthdraws WDS66 -> This exchange
225 if (REQUEST_POST('amount') < getConfig('wernis_min_withdraw')) {
226 // Not enougth entered!
227 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), getConfig(('wernis_min_withdraw'))));
229 // All is fine here so do the withdraw
230 $success = WERNIS_EXECUTE_WITHDRAW(REQUEST_POST('wds66_id'), md5(REQUEST_POST('wds66_password')), REQUEST_POST('amount'));
232 // Add it to this amount
233 unset($GLOBALS['ref_level']);
234 ADD_POINTS_REFSYSTEM("wernis_withdraw", getUserId(), bigintval(REQUEST_POST('amount')), false, 0, false, "direct");
236 // Update the user data as well..
237 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
238 array(bigintval(REQUEST_POST('wds66_id')), getUserId()), __FILE__, __LINE__);
241 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_WITHDRAW_DONE'));
243 } elseif ((GET_WERNIS_ERROR_CODE() == "user_failed") || (GET_WERNIS_ERROR_CODE() == "own_failed") || (GET_WERNIS_ERROR_CODE() == "amount_failed")) {
245 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
247 // Something went wrong
248 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_WITHDRAW_FAILED'), GET_WERNIS_ERROR_MESSAGE()));
253 case "payout": // Payout this exchange -> WDS66
254 if (REQUEST_POST('amount') < getConfig('wernis_min_payout')) {
255 // Not enougth entered!
256 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), getConfig(('wernis_min_payout'))));
257 } elseif (REQUEST_POST('amount') > $points) {
258 // Not enougth points left!
259 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_PAYOUT_POINTS_DEPLETED'), bigintval(REQUEST_POST('amount')), bigintval($points)));
261 // All is fine here so do the withdraw
262 $success = WERNIS_EXECUTE_PAYOUT(REQUEST_POST('wds66_id'), REQUEST_POST('amount'));
265 SUB_POINTS("wernis_payout", getUserId(), REQUEST_POST('amount'));
268 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
269 array(bigintval(REQUEST_POST('wds66_id')), getUserId()), __FILE__, __LINE__);
272 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_PAYOUT_DONE'));
274 } 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")) {
276 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
278 // Something went wrong
279 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_WITHDRAW_FAILED'), GET_WERNIS_ERROR_MESSAGE()));
284 default: // Invalid mode!
285 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", REQUEST_GET('mode')));
286 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_MODE_INVALID'), REQUEST_GET(('mode'))));
292 // Prepare mode for template name
293 $mode = sprintf("member_wernis_mode_%s", REQUEST_GET(('mode')));
296 LOAD_TEMPLATE($mode, false, $content);