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 * 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 - 2009 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')) {
42 } elseif (!isMember()) {
43 // User is not logged in
44 redirectToIndexMemberOnlyModule();
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
50 if ((!isExtensionActive('wernis')) && (!isAdmin())) {
51 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('wernis'));
55 // Check if the admin has entered the data
56 if ((getConfig('wernis_api_id') == '') || (getConfig('wernis_api_md5') == '')) {
57 // Something important is missing...
58 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_API_DATA_MISSING'));
62 // Init the content array and points
63 $content = array(); $points = false;
65 // Is the mode set (withdraw or payout)
66 if ((!isGetRequestParameterSet('mode')) || (getRequestParameter('mode') == 'choose')) {
67 // Let the user choose what he wants to do
68 $content['refid'] = getConfig(('wernis_refid'));
69 $content['wernis_userid'] = '0';
72 if ((!empty($content['wernis_userid'])) && (!isGetRequestParameterSet('mode'))) {
73 // Then use an other "mode"
74 setGetRequestParameter('mode', 'list');
77 $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",
78 array(getMemberId()), __FILE__, __LINE__);
81 $content['rows'] = ''; $SW = 2;
82 while ($data = SQL_FETCHARRAY($result)) {
83 // Prepare data for output
85 'wernis_timestamp' => generateDateTime($data['wernis_timestamp'], 2),
86 'points' => translateComma($data['wernis_amount']),
87 'wernis_account' => bigintval($data['wernis_account']),
88 'status' => WERNIS_TRANSFER_STATUS($data['wernis_type']),
89 'raw_type' => strtolower($data['wernis_type']),
94 $content['rows'] .= loadTemplate('member_wernis_mode_list_row', true, $rowContent);
99 SQL_FREERESULT($result);
101 // Default links are not active!
102 $content['payout_link'] = '<em>{--MEMBER_WERNIS_PAYOUT_DISABLED--}</em>';
103 $content['withdraw_link'] = '<em>{--MEMBER_WERNIS_WITHDRAW_DISABLED--}</em>';
105 // Is the payout mode active?
106 if (getConfig('wernis_payout_active') == 'Y') {
108 $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>";
111 // Is the withdraw mode active?
112 if (getConfig('wernis_withdraw_active') == 'Y') {
114 $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>";
118 setGetRequestParameter('mode', 'choose');
120 } elseif ((getRequestParameter('mode') == 'payout') && (getConfig('wernis_payout_active') == 'Y')) {
121 // Get total points and check if the user can request a payout
122 $points = countSumTotalData(getMemberId(), 'user_points', 'points') - countSumTotalData(getMemberId(), 'user_data', 'used_points');
124 // Remove the registration fee
125 $points = $points - getConfig('points_register');
127 // Is there a percentage or fixed fee?
128 $points = WERNIS_TAKE_FEE($points, 'payout');
130 // Is this enougth for a payout?
131 if ($points < getConfig('wernis_min_payout')) {
132 // No, then abort here
133 loadTemplate('admin_settings_saved', false, sprintf(
134 getMessage('MEMBER_WERNIS_MIN_PAYOUT'),
135 translateComma(getConfig('wernis_min_payout')),
136 translateComma($points)
142 $points = explode('.', $points);
143 $points = bigintval($points[0]);
145 // Add points to content array
146 $content['points'] = translateComma($points);
148 // Get WDS66 username
149 $content['wernis_userid'] = getUserData('wernis_userid');
150 } elseif ((getRequestParameter('mode') == 'withdraw') && (getConfig('wernis_withdraw_active') == 'Y')) {
151 // Get total points for just displaying them
152 $points = countSumTotalData(getMemberId(), 'user_points', 'points') - countSumTotalData(getMemberId(), 'user_data', 'used_points');
154 // Prepare data for the template
155 $content['points'] = translateComma($points);
156 $content['wernis_userid'] = '';
159 WERNIS_ADD_FEES_TO_ARRAY($content);
162 $content['wernis_userid'] = getUserData('wernis_userid');
165 loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_WERNIS_MODE_INVALID', getRequestParameter('mode')));
169 // Is the formular sent?
170 if ((isFormSent()) && (isGetRequestParameterSet('mode'))) {
171 // Is the user id and password set?
172 if (!isPostRequestParameterSet(('wernis_userid'))) {
173 // Nothing entered in WDS66 user id
174 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_EMPTY_USERNAME'));
175 } elseif (!isPostRequestParameterSet(('wds66_password'))) {
176 // Nothing entered in WDS66 password
177 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_EMPTY_PASSWORD'));
178 } elseif (!isPostRequestParameterSet(('amount'))) {
179 // Nothing entered in amount
180 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_EMPTY_AMOUNT'));
181 } elseif (postRequestParameter('wernis_userid') != bigintval(postRequestParameter('wernis_userid'))) {
182 // Only numbers in account id!
183 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_INVALID_USERNAME'));
184 } elseif (postRequestParameter('amount') != bigintval(postRequestParameter('amount'))) {
185 // Only numbers in amount!
186 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_INVALID_AMOUNT'));
188 // Check input data depending on the mode and execute the requested mode
189 switch (getRequestParameter('mode')) {
190 case 'withdraw': // Widthdraws WDS66 -> This exchange
191 if (postRequestParameter('amount') < getConfig('wernis_min_withdraw')) {
192 // Not enougth entered!
193 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_WITHDRAW_AMOUNT_SMALLER_MIN'));
195 // All is fine here so do the withdraw
196 $success = WERNIS_EXECUTE_WITHDRAW(postRequestParameter('wernis_userid'), md5(postRequestParameter('wds66_password')), postRequestParameter('amount'));
197 if ($success === true) {
198 // Add it to this amount
199 addPointsDirectly('wernis_withdraw', getMemberId(), bigintval(postRequestParameter('amount')));
201 // Update the user data as well..
202 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `wernis_userid`=%s WHERE `userid`=%s LIMIT 1",
203 array(bigintval(postRequestParameter('wernis_userid')), getMemberId()), __FILE__, __LINE__);
206 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_WITHDRAW_DONE'));
208 } elseif ((GET_WERNIS_ERROR_CODE() == 'user_failed') || (GET_WERNIS_ERROR_CODE() == 'own_failed') || (GET_WERNIS_ERROR_CODE() == 'amount_failed')) {
210 loadTemplate('admin_settings_saved', false, GET_WERNIS_ERROR_MESSAGE());
212 // Something went wrong
213 loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_WERNIS_WITHDRAW_FAILED', GET_WERNIS_ERROR_MESSAGE()));
218 case 'payout': // Payout this exchange -> WDS66
219 if (postRequestParameter('amount') < getConfig('wernis_min_payout')) {
220 // Not enougth entered!
221 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_PAYOUT_AMOUNT_SMALLER_MIN'));
222 } elseif (postRequestParameter('amount') > $points) {
223 // Not enougth points left!
224 loadTemplate('admin_settings_saved', false, sprintf(getMessage('MEMBER_WERNIS_PAYOUT_POINTS_DEPLETED'), bigintval(postRequestParameter('amount')), bigintval($points)));
226 // All is fine here so do the withdraw
227 $success = WERNIS_EXECUTE_PAYOUT(postRequestParameter('wernis_userid'), postRequestParameter('amount'));
228 if ($success === true) {
230 subtractPoints('wernis_payout', getMemberId(), postRequestParameter('amount'));
233 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `wernis_userid`=%s WHERE `userid`=%s LIMIT 1",
234 array(bigintval(postRequestParameter('wernis_userid')), getMemberId()), __FILE__, __LINE__);
237 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_WERNIS_PAYOUT_DONE'));
239 } 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')) {
241 loadTemplate('admin_settings_saved', false, GET_WERNIS_ERROR_MESSAGE());
243 // Something went wrong
244 loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_WERNIS_WITHDRAW_FAILED', GET_WERNIS_ERROR_MESSAGE()));
249 default: // Invalid mode!
250 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", getRequestParameter('mode')));
251 loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_WERNIS_MODE_INVALID', getRequestParameter('mode')));
257 // Prepare mode for template name
258 $mode = sprintf("member_wernis_mode_%s", getRequestParameter('mode'));
261 loadTemplate($mode, false, $content);