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 ADD_FATAL(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, 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 ((!isset($_GET['mode'])) || ($_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'])) && (!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` = %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 $_GET['mode'] = "choose";
127 } elseif (($_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(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 (($_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, SQL_ESCAPE($_GET['mode'])));
198 // Is the formular sent?
199 if ((isset($_POST['ok'])) && (isset($_GET['mode']))) {
200 // Is the user ID and password set?
201 if (empty($_POST['wds66_id'])) {
202 // Nothing entered in WDS66 user ID
203 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_USERNAME);
204 OUTPUT_HTML("<br />");
205 } elseif (empty($_POST['wds66_password'])) {
206 // Nothing entered in WDS66 password
207 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_PASSWORD);
208 OUTPUT_HTML("<br />");
209 } elseif (empty($_POST['amount'])) {
210 // Nothing entered in amount
211 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_EMPTY_AMOUNT);
212 OUTPUT_HTML("<br />");
213 } elseif ($_POST['wds66_id'] != bigintval($_POST['wds66_id'])) {
214 // Only numbers in account ID!
215 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_USERNAME);
216 OUTPUT_HTML("<br />");
217 } elseif ($_POST['amount'] != bigintval($_POST['amount'])) {
218 // Only numbers in amount!
219 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_INVALID_AMOUNT);
220 OUTPUT_HTML("<br />");
222 // Check input data depending on the mode and execute the requested mode
223 switch ($_GET['mode']) {
224 case "withdraw": // Widthdraws WDS66 -> This exchange
225 if ($_POST['amount'] < getConfig('wernis_min_withdraw')) {
226 // Not enougth entered!
227 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_AMOUNT_SMALLER_MIN, bigintval(getConfig('wernis_min_withdraw'))));
228 OUTPUT_HTML("<br />");
230 // All is fine here so do the withdraw
231 $success = WERNIS_EXECUTE_WITHDRAW($_POST['wds66_id'], md5($_POST['wds66_password']), $_POST['amount']);
233 // Add it to this amount
235 ADD_POINTS_REFSYSTEM("wernis_withdraw", $GLOBALS['userid'], bigintval($_POST['amount']), false, 0, false, "direct");
237 // Update the user data as well..
238 $result = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
239 array(bigintval($_POST['wds66_id']), $GLOBALS['userid']), __FILE__, __LINE__);
242 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_WITHDRAW_DONE);
244 } elseif ((GET_WERNIS_ERROR_CODE() == "user_failed") || (GET_WERNIS_ERROR_CODE() == "own_failed") || (GET_WERNIS_ERROR_CODE() == "amount_failed")) {
246 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
247 OUTPUT_HTML("<br />");
249 // Something went wrong
250 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_WITHDRAW_FAILED, GET_WERNIS_ERROR_MESSAGE()));
251 OUTPUT_HTML("<br />");
256 case "payout": // Payout this exchange -> WDS66
257 if ($_POST['amount'] < getConfig('wernis_min_payout')) {
258 // Not enougth entered!
259 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_AMOUNT_SMALLER_MIN, bigintval(getConfig('wernis_min_payout'))));
260 OUTPUT_HTML("<br />");
261 } elseif ($_POST['amount'] > $points) {
262 // Not enougth points left!
263 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_PAYOUT_POINTS_DEPLETED, bigintval($_POST['amount']), bigintval($points)));
264 OUTPUT_HTML("<br />");
266 // All is fine here so do the withdraw
267 $success = WERNIS_EXECUTE_PAYOUT($_POST['wds66_id'], $_POST['amount']);
270 SUB_POINTS("wernis_payout", $GLOBALS['userid'], $_POST['amount']);
273 $result = SQL_QUERY_ESC("UPDATE `"._MYSQL_PREFIX."_user_data` SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
274 array(bigintval($_POST['wds66_id']), $GLOBALS['userid']), __FILE__, __LINE__);
277 LOAD_TEMPLATE("admin_settings_saved", false, WERNIS_MEMBER_PAYOUT_DONE);
279 } 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")) {
281 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
282 OUTPUT_HTML("<br />");
284 // Something went wrong
285 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(WERNIS_MEMBER_WITHDRAW_FAILED, GET_WERNIS_ERROR_MESSAGE()));
286 OUTPUT_HTML("<br />");
291 default: // Invalid mode!
292 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", $_GET['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);