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 // Extension "wernis" is not activated
43 ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "wernis");
47 // Add description as navigation point
48 ADD_DESCR("member", __FILE__);
50 // Check if the admin has entered the data
51 if ((empty($_CONFIG['wernis_api_id'])) || (empty($_CONFIG['wernis_api_md5']))) {
52 // Something important is missing...
53 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_API_DATA_MISSING);
57 // Init the content array and points
58 $content = array(); $points = false;
60 // Is the mode set (withdraw or payout)
61 if ((!isset($_GET['mode'])) || ($_GET['mode'] == "choose")) {
62 // Let the user choose what he wants to do
63 $content['refid'] = bigintval($_CONFIG['wernis_refid']);
64 $content['wds66_id'] = 0;
67 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
68 array($GLOBALS['userid']), __FILE__, __LINE__);
70 // Are there some entries?
71 if (SQL_NUMROWS($result) == 1) {
73 list($content['wds66_id']) = SQL_FETCHROW($result);
77 SQL_FREERESULT($result);
80 if ((!empty($content['wds66_id'])) && (!isset($_GET['mode']))) {
81 // Then use an other "mode"
82 $_GET['mode'] = "list";
85 $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",
86 array($GLOBALS['userid']), __FILE__, __LINE__);
89 $content['rows'] = ""; $SW = 2;
90 while ($data = SQL_FETCHARRAY($result)) {
91 // Prepare data for output
93 'stamp' => MAKE_DATETIME($data['wernis_timestamp'], "2"),
94 'points' => TRANSLATE_COMMA($data['wernis_amount']),
95 'acc' => bigintval($data['wernis_account']),
96 'status' => WERNIS_TRANSFER_STATUS($data['wernis_type']),
97 'raw_type' => strtolower($data['wernis_type']),
102 $content['rows'] .= LOAD_TEMPLATE("member_wernis_mode_list_row", true, $rowContent);
107 SQL_FREERESULT($result);
109 // Default links are not active!
110 $content['payout_link'] = "<em>".WERNIS_MEMBER_PAYOUT_DISABLED."</em>";
111 $content['withdraw_link'] = "<em>".WERNIS_MEMBER_WITHDRAW_DISABLED."</em>";
113 // Is the payout mode active?
114 if ($_CONFIG['wernis_payout_active'] == "Y") {
116 $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>";
119 // Is the withdraw mode active?
120 if ($_CONFIG['wernis_withdraw_active'] == "Y") {
122 $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>";
126 $_GET['mode'] = "choose";
128 } elseif (($_GET['mode'] == "payout") && ($_CONFIG['wernis_payout_active'] == "Y")) {
129 // Get total points and check if the user can request a payout
130 $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
132 // Remove the registration fee
133 $points = $points - $_CONFIG['points_register'];
135 // Is there a percentage or fixed fee?
136 $points = WERNIS_TAKE_FEE($points, "payout");
138 // Is this enougth for a payout?
139 if ($points < $_CONFIG['wernis_min_payout']) {
140 // No, then abort here
141 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_MIN_PAYOUT, TRANSLATE_COMMA($_CONFIG['wernis_min_payout'])));
146 $points = explode(".", $points);
147 $points = bigintval($points[0]);
149 // Add points to content array
150 $content['points'] = TRANSLATE_COMMA($points);
151 $content['min_points'] = TRANSLATE_COMMA($_CONFIG['wernis_min_payout']);
154 WERNIS_ADD_FEES_TO_ARRAY($content);
157 $content['wds66_id'] = "";
158 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
159 array($GLOBALS['userid']), __FILE__, __LINE__);
161 // Are there some entries?
162 if (SQL_NUMROWS($result) == 1) {
164 list($content['wds66_id']) = SQL_FETCHROW($result);
168 SQL_FREERESULT($result);
169 } elseif (($_GET['mode'] == "withdraw") && ($_CONFIG['wernis_withdraw_active'] == "Y")) {
170 // Get total points for just displaying them
171 $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
173 // Prepare data for the template
174 $content['points'] = TRANSLATE_COMMA($points);
175 $content['min_points'] = TRANSLATE_COMMA($_CONFIG['wernis_min_withdraw']);
176 $content['wds66_id'] = "";
179 WERNIS_ADD_FEES_TO_ARRAY($content);
182 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
183 array($GLOBALS['userid']), __FILE__, __LINE__);
185 // Are there some entries?
186 if (SQL_NUMROWS($result) == 1) {
188 list($content['wds66_id']) = SQL_FETCHROW($result);
192 SQL_FREERESULT($result);
195 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_MODE_INVALID, SQL_ESCAPE($_GET['mode'])));
199 // Is the formular sent?
200 if ((isset($_POST['ok'])) && (isset($_GET['mode']))) {
201 // Is the user ID and password set?
202 if (empty($_POST['wds66_id'])) {
203 // Nothing entered in WDS66 user ID
204 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_USERNAME);
205 OUTPUT_HTML("<br />");
206 } elseif (empty($_POST['wds66_password'])) {
207 // Nothing entered in WDS66 password
208 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_PASSWORD);
209 OUTPUT_HTML("<br />");
210 } elseif (empty($_POST['amount'])) {
211 // Nothing entered in amount
212 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_AMOUNT);
213 OUTPUT_HTML("<br />");
214 } elseif ($_POST['wds66_id'] != bigintval($_POST['wds66_id'])) {
215 // Only numbers in account ID!
216 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_USERNAME);
217 OUTPUT_HTML("<br />");
218 } elseif ($_POST['amount'] != bigintval($_POST['amount'])) {
219 // Only numbers in amount!
220 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_AMOUNT);
221 OUTPUT_HTML("<br />");
223 // Check input data depending on the mode and execute the requested mode
224 switch ($_GET['mode']) {
225 case "withdraw": // Widthdraws WDS66 -> This exchange
226 if ($_POST['amount'] < $_CONFIG['wernis_min_withdraw']) {
227 // Not enougth entered!
228 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_AMOUNT_SMALLER_MIN, bigintval($_CONFIG['wernis_min_withdraw'])));
229 OUTPUT_HTML("<br />");
231 // All is fine here so do the withdraw
232 $success = WERNIS_EXECUTE_WITHDRAW($_POST['wds66_id'], md5($_POST['wds66_password']), $_POST['amount']);
234 // Add it to this amount
236 ADD_POINTS_REFSYSTEM($GLOBALS['userid'], bigintval($_POST['amount']), false, 0, false, "direct");
238 // Update the user data as well..
239 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
240 array(bigintval($_POST['wds66_id']), $GLOBALS['userid']), __FILE__, __LINE__);
243 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_WITHDRAW_DONE);
245 } elseif ((GET_WERNIS_ERROR_CODE() == "user_failed") || (GET_WERNIS_ERROR_CODE() == "own_failed") || (GET_WERNIS_ERROR_CODE() == "amount_failed")) {
247 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
248 OUTPUT_HTML("<br />");
250 // Something went wrong
251 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_WITHDRAW_FAILED, GET_WERNIS_ERROR_MESSAGE()));
252 OUTPUT_HTML("<br />");
257 case "payout": // Payout this exchange -> WDS66
258 if ($_POST['amount'] < $_CONFIG['wernis_min_payout']) {
259 // Not enougth entered!
260 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_AMOUNT_SMALLER_MIN, bigintval($_CONFIG['wernis_min_payout'])));
261 OUTPUT_HTML("<br />");
262 } elseif ($_POST['amount'] > $points) {
263 // Not enougth points left!
264 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_PAYOUT_POINTS_DEPLETED, bigintval($_POST['amount']), bigintval($points)));
265 OUTPUT_HTML("<br />");
267 // All is fine here so do the withdraw
268 $success = WERNIS_EXECUTE_PAYOUT($_POST['wds66_id'], md5($_POST['wds66_password']), $_POST['amount']);
271 SUB_POINTS($GLOBALS['userid'], $_POST['amount']);
274 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
275 array(bigintval($_POST['wds66_id']), $GLOBALS['userid']), __FILE__, __LINE__);
278 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_PAYOUT_DONE);
280 } 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")) {
282 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
283 OUTPUT_HTML("<br />");
285 // Something went wrong
286 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_WITHDRAW_FAILED, GET_WERNIS_ERROR_MESSAGE()));
287 OUTPUT_HTML("<br />");
292 default: // Invalid mode!
293 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_MODE_INVALID, SQL_ESCAPE($_GET['mode'])));
299 // Prepare mode for template name
300 $mode = sprintf("member_wernis_mode_%s", SQL_ESCAPE($_GET['mode']));
303 LOAD_TEMPLATE($mode, false, $content);