2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
41 } elseif (!isMember()) {
42 // User is not logged in
43 redirectToIndexMemberOnlyModule();
46 // Add description as navigation point
47 addYouAreHereLink('member', __FILE__);
49 if ((!isExtensionActive('wernis')) && (!isAdmin())) {
50 displayMessage(generateExtensionInactiveNotInstalledMessage('wernis'));
54 // Check if the admin has entered the data
55 if ((getWernisApiId() == '') || (getWernisApiMd5() == '')) {
56 // Something important is missing...
57 displayMessage('{--MEMBER_WERNIS_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 ((!isGetRequestParameterSet('mode')) || (getRequestParameter('mode') == 'choose')) {
66 // Let the user choose what he wants to do
67 $content['wernis_userid'] = '0';
70 if ((!empty($content['wernis_userid'])) && (!isGetRequestParameterSet('mode'))) {
71 // Then use an other "mode"
72 setGetRequestParameter('mode', 'list');
75 $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",
76 array(getMemberId()), __FILE__, __LINE__);
79 $content['rows'] = '';
80 while ($data = SQL_FETCHARRAY($result)) {
81 // Prepare data for output
83 'wernis_timestamp' => generateDateTime($data['wernis_timestamp'], 2),
84 'wernis_amount' => $data['wernis_amount'],
85 'wernis_account' => $data['wernis_account'],
86 'wernis_type' => $data['wernis_type'],
90 $content['rows'] .= loadTemplate('member_wernis_mode_list_row', true, $rowContent);
94 SQL_FREERESULT($result);
96 // Default links are not active!
97 $content['payout_link'] = '<em>{--MEMBER_WERNIS_PAYOUT_DISABLED--}</em>';
98 $content['withdraw_link'] = '<em>{--MEMBER_WERNIS_WITHDRAW_DISABLED--}</em>';
100 // Is the payout mode active?
101 if (getConfig('wernis_payout_active') == 'Y') {
103 $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>';
106 // Is the withdraw mode active?
107 if (isWernisWithdrawActive()) {
109 $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>';
113 setGetRequestParameter('mode', 'choose');
115 } elseif ((getRequestParameter('mode') == 'payout') && (getConfig('wernis_payout_active') == 'Y')) {
116 // Get user's total points and remove the registration fee
117 $points = getTotalPoints(getMemberId()) - getPointsRegister();
119 // Is there a percentage or fixed fee?
120 $points = WERNIS_TAKE_FEE($points, 'payout');
122 // Is this enougth for a payout?
123 if ($points < getConfig('wernis_min_payout')) {
124 // No, then abort here
125 displayMessage('{%message,MEMBER_WERNIS_MIN_PAYOUT=' . $points . '%}');
130 $points = explode('.', $points);
131 $points = bigintval($points[0]);
133 // Add points to content array
134 $content['points'] = $points;
135 } elseif ((getRequestParameter('mode') == 'withdraw') && (isWernisWithdrawActive())) {
136 // Prepare data for the template
137 $content['points'] = getTotalPoints(getMemberId());
138 $content['wernis_userid'] = '';
141 $content['wernis_userid'] = getUserData('wernis_userid');
144 displayMessage(getMaskedMessage('MEMBER_WERNIS_MODE_INVALID', getRequestParameter('mode')));
148 // Is the formular sent?
149 if ((isFormSent()) && (isGetRequestParameterSet('mode'))) {
150 // Is the user id and password set?
151 if (!isPostRequestParameterSet('wernis_userid')) {
152 // Nothing entered in WDS66 user id
153 displayMessage('{--MEMBER_WERNIS_EMPTY_USERNAME--}');
154 } elseif (!isPostRequestParameterSet('wds66_password')) {
155 // Nothing entered in WDS66 password
156 displayMessage('{--MEMBER_WERNIS_EMPTY_PASSWORD--}');
157 } elseif (!isPostRequestParameterSet('amount')) {
158 // Nothing entered in amount
159 displayMessage('{--MEMBER_WERNIS_EMPTY_AMOUNT--}');
160 } elseif (postRequestParameter('wernis_userid') != bigintval(postRequestParameter('wernis_userid'))) {
161 // Only numbers in account id!
162 displayMessage('{--MEMBER_WERNIS_INVALID_USERNAME');
163 } elseif (postRequestParameter('amount') != bigintval(postRequestParameter('amount'))) {
164 // Only numbers in amount!
165 displayMessage('{--MEMBER_WERNIS_INVALID_AMOUNT--}');
167 // Check input data depending on the mode and execute the requested mode
168 switch (getRequestParameter('mode')) {
169 case 'withdraw': // Widthdraws WDS66 -> This exchange
170 if (postRequestParameter('amount') < getConfig('wernis_min_withdraw')) {
171 // Not enougth entered!
172 displayMessage('{--MEMBER_WERNIS_WITHDRAW_AMOUNT_SMALLER_MIN--}');
174 // All is fine here so do the withdraw
175 $success = WERNIS_EXECUTE_WITHDRAW(postRequestParameter('wernis_userid'), md5(postRequestParameter('wds66_password')), postRequestParameter('amount'));
176 if ($success === true) {
177 // Add it to this amount
178 addPointsDirectly('wernis_withdraw', getMemberId(), bigintval(postRequestParameter('amount')));
180 // Update the user data as well..
181 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `wernis_userid`=%s WHERE `userid`=%s LIMIT 1",
182 array(bigintval(postRequestParameter('wernis_userid')), getMemberId()), __FILE__, __LINE__);
185 displayMessage('{--MEMBER_WERNIS_WITHDRAW_DONE--}');
187 } elseif ((GET_WERNIS_ERROR_CODE() == 'user_failed') || (GET_WERNIS_ERROR_CODE() == 'own_failed') || (GET_WERNIS_ERROR_CODE() == 'amount_failed')) {
189 displayMessage(GET_WERNIS_ERROR_MESSAGE());
191 // Something went wrong
192 displayMessage(getMaskedMessage('MEMBER_WERNIS_WITHDRAW_FAILED', GET_WERNIS_ERROR_MESSAGE()));
197 case 'payout': // Payout this exchange -> WDS66
198 if (postRequestParameter('amount') < getConfig('wernis_min_payout')) {
199 // Not enougth entered!
200 displayMessage('{--MEMBER_WERNIS_PAYOUT_AMOUNT_SMALLER_MIN--}');
201 } elseif (postRequestParameter('amount') > $points) {
202 // Not enougth points left!
203 displayMessage(sprintf(getMessage('MEMBER_WERNIS_PAYOUT_POINTS_DEPLETED'), bigintval(postRequestParameter('amount')), bigintval($points)));
205 // All is fine here so do the withdraw
206 $success = WERNIS_EXECUTE_PAYOUT(postRequestParameter('wernis_userid'), postRequestParameter('amount'));
207 if ($success === true) {
209 subtractPoints('wernis_payout', getMemberId(), postRequestParameter('amount'));
212 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `wernis_userid`=%s WHERE `userid`=%s LIMIT 1",
213 array(bigintval(postRequestParameter('wernis_userid')), getMemberId()), __FILE__, __LINE__);
216 displayMessage('{--MEMBER_WERNIS_PAYOUT_DONE--}');
218 } 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')) {
220 displayMessage(GET_WERNIS_ERROR_MESSAGE());
222 // Something went wrong
223 displayMessage(getMaskedMessage('MEMBER_WERNIS_WITHDRAW_FAILED', GET_WERNIS_ERROR_MESSAGE()));
228 default: // Invalid mode!
229 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", getRequestParameter('mode')));
230 displayMessage(getMaskedMessage('MEMBER_WERNIS_MODE_INVALID', getRequestParameter('mode')));
236 // Prepare mode for template name
237 $mode = sprintf("member_wernis_mode_%s", getRequestParameter('mode'));
240 loadTemplate($mode, false, $content);