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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif (!IS_LOGGED_IN()) {
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", basename(__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']);
66 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d 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'])) && (!isset($_GET['mode']))) {
80 // Then use an other "mode"
81 $_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` = %d 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']),
100 $content['rows'] .= LOAD_TEMPLATE("member_wernis_mode_list_row", true, $rowContent);
105 SQL_FREERESULT($result);
108 $_GET['mode'] = "choose";
110 } elseif ($_GET['mode'] == "pay") {
111 // Get total points and check if the user can request a payout
112 $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
115 $points = explode(".", $points);
116 $points = bigintval($points[0]);
118 // Is this enougth for a payout?
119 if ($points < $_CONFIG['wernis_min_payout']) {
120 // No, then abort here
121 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_MIN_PAYOUT_PAYOUT, TRANSLATE_COMMA($_CONFIG['wernis_min_payout'])));
125 // Add points to content array
126 $content['points'] = $points;
127 $content['min_points'] = TRANSLATE_COMMA($_CONFIG['wernis_min_payout']);
130 $content['wds66_id'] = "";
131 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
132 array($GLOBALS['userid']), __FILE__, __LINE__);
134 // Are there some entries?
135 if (SQL_NUMROWS($result) == 1) {
137 list($content['wds66_id']) = SQL_FETCHROW($result);
141 SQL_FREERESULT($result);
142 } elseif ($_GET['mode'] == "withdraw") {
143 // Get total points for just displaying them
144 $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
146 // Prepare data for the template
147 $content['points'] = TRANSLATE_COMMA($points);
148 $content['min_points'] = TRANSLATE_COMMA($_CONFIG['wernis_min_withdraw']);
149 $content['wds66_id'] = "";
152 $result = SQL_QUERY_ESC("SELECT wernis_userid FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d LIMIT 1",
153 array($GLOBALS['userid']), __FILE__, __LINE__);
155 // Are there some entries?
156 if (SQL_NUMROWS($result) == 1) {
158 list($content['wds66_id']) = SQL_FETCHROW($result);
162 SQL_FREERESULT($result);
165 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_MODE_INVALID, SQL_ESCAPE($_GET['mode'])));
169 // Is the formular sent?
170 if ((isset($_POST['ok'])) && (isset($_GET['mode']))) {
171 // Check input data depending on the mode and execute the requested mode
172 switch ($_GET['mode']) {
173 case "withdraw": // Widthdraws WDS66 -> This exchange
174 // Is the user ID and password set?
175 if (empty($_POST['wds66_id'])) {
176 // Nothing entered in WDS66 user ID
177 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_USERNAME);
178 OUTPUT_HTML("<br />");
179 } elseif (empty($_POST['wds66_password'])) {
180 // Nothing entered in WDS66 password
181 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_PASSWORD);
182 OUTPUT_HTML("<br />");
183 } elseif (empty($_POST['amount'])) {
184 // Nothing entered in amount
185 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_AMOUNT);
186 OUTPUT_HTML("<br />");
187 } elseif ($_POST['wds66_id'] != bigintval($_POST['wds66_id'])) {
188 // Only numbers in account ID!
189 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_USERNAME);
190 OUTPUT_HTML("<br />");
191 } elseif ($_POST['amount'] != bigintval($_POST['amount'])) {
192 // Only numbers in amount!
193 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_AMOUNT);
194 OUTPUT_HTML("<br />");
195 } elseif ($_POST['amount'] < $_CONFIG['wernis_min_withdraw']) {
196 // Not enougth entered!
197 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_AMOUNT_SMALLER_MIN, bigintval($_CONFIG['wernis_min_withdraw'])));
198 OUTPUT_HTML("<br />");
200 // All is fine here so do the withdraw
201 $success = WERNIS_EXECUTE_WITHDRAW($_POST['wds66_id'], md5($_POST['wds66_password']), $_POST['amount']);
203 // Default is locked!
206 // Shall I "pay" the referral points imidiately?
207 if ($_CONFIG['ref_payout'] == "0") {
212 // Add it to this amount
214 ADD_POINTS_REFSYSTEM($GLOBALS['userid'], bigintval($_POST['amount']), false, 0, $locked, "direct");
216 // Register this wernis movement
217 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_wernis (`userid`, `wernis_account`, `wernis_amount`, `wernis_timestamp`, `wernis_type`) VALUES(%d, %d, %d, UNIX_TIMESTAMP(), 'IN')",
218 array($GLOBALS['userid'], bigintval($_POST['wds66_id']), bigintval($_POST['amount'])), __FILE__, __LINE__);
220 // Update the user data as well..
221 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET `wernis_userid`=%d WHERE userid=%d LIMIT 1",
222 array(bigintval($_POST['wds66_id']), $GLOBALS['userid']), __FILE__, __LINE__);
225 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_WITHDRAW_DONE);
227 } elseif ((GET_WERNIS_ERROR_CODE() == "user_failed") || (GET_WERNIS_ERROR_CODE() == "own_failed") || (GET_WERNIS_ERROR_CODE() == "amount_failed")) {
229 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
230 OUTPUT_HTML("<br />");
232 // Something went wrong
233 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_WITHDRAW_FAILED, GET_WERNIS_ERROR_MESSAGE()));
234 OUTPUT_HTML("<br />");
239 case "pay": // Payout this exchange -> WDS66
240 // Is the user ID and password set?
241 if (empty($_POST['wds66_id'])) {
242 // Nothing entered in WDS66 user ID
243 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_USERNAME);
244 OUTPUT_HTML("<br />");
245 } elseif (empty($_POST['wds66_password'])) {
246 // Nothing entered in WDS66 password
247 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_PASSWORD);
248 OUTPUT_HTML("<br />");
249 } elseif (empty($_POST['amount'])) {
250 // Nothing entered in amount
251 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_AMOUNT);
252 OUTPUT_HTML("<br />");
253 } elseif ($_POST['wds66_id'] != bigintval($_POST['wds66_id'])) {
254 // Only numbers in account ID!
255 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_USERNAME);
256 OUTPUT_HTML("<br />");
257 } elseif ($_POST['amount'] != bigintval($_POST['amount'])) {
258 // Only numbers in amount!
259 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_AMOUNT);
260 OUTPUT_HTML("<br />");
261 } elseif ($_POST['amount'] < $_CONFIG['wernis_min_payout']) {
262 // Not enougth entered!
263 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_AMOUNT_SMALLER_MIN, bigintval($_CONFIG['wernis_min_payout'])));
264 OUTPUT_HTML("<br />");
265 } elseif ($_POST['amount'] > $points) {
266 // Not enougth points left!
267 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_PAYOUT_POINTS_DEPLETED, bigintval($_POST['amount']), bigintval($points)));
268 OUTPUT_HTML("<br />");
270 // All is fine here so do the withdraw
271 $success = WERNIS_EXECUTE_PAYOUT($_POST['wds66_id'], md5($_POST['wds66_password']), $_POST['amount']);
273 // Default is locked!
276 // Shall I "pay" the referral points imidiately?
277 if ($_CONFIG['ref_payout'] == "0") {
282 // Remove the points from the account
283 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET `points_used` = `points_used` + %d WHERE userid=%d LIMIT 1",
284 array(bigintval($_POST['amount']), $GLOBALS['userid']), __FILE__, __LINE__);
286 // Register this wernis movement
287 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_user_wernis (`userid`, `wernis_account`, `wernis_amount`, `wernis_timestamp`, `wernis_type`) VALUES(%d, %d, %d, UNIX_TIMESTAMP(), 'OUT')",
288 array($GLOBALS['userid'], bigintval($_POST['wds66_id']), bigintval($_POST['amount'])), __FILE__, __LINE__);
290 // Update the user data as well..
291 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET `wernis_userid`=%d WHERE userid=%d LIMIT 1",
292 array(bigintval($_POST['wds66_id']), $GLOBALS['userid']), __FILE__, __LINE__);
295 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_WITHDRAW_DONE);
297 } 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")) {
299 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
300 OUTPUT_HTML("<br />");
302 // Something went wrong
303 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_WITHDRAW_FAILED, GET_WERNIS_ERROR_MESSAGE()));
304 OUTPUT_HTML("<br />");
309 default: // Invalid mode!
310 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_MODE_INVALID, SQL_ESCAPE($_GET['mode'])));
315 // Prepare mode for template name
316 $mode = sprintf("member_wernis_mode_%s", SQL_ESCAPE($_GET['mode']));
319 LOAD_TEMPLATE($mode, false, $content);