]> git.mxchange.org Git - mailer.git/blob - inc/modules/member/what-wernis.php
Global rewrite of engine:
[mailer.git] / inc / modules / member / what-wernis.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/12/2004 *
4  * ===================                          Last change: 11/16/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-wernis.php                                  *
8  * -------------------------------------------------------------------- *
9  * Short description : Wernis requests                                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Auszahlungsanfragen                              *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } elseif (!isMember()) {
43         // User is not logged in
44         redirectToIndexMemberOnlyModule();
45 }
46
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
49
50 if ((!isExtensionActive('wernis')) && (!isAdmin())) {
51         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('wernis'));
52         return;
53 } // END - if
54
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('WERNIS_MEMBER_API_DATA_MISSING'));
59         return;
60 } // END - if
61
62 // Init the content array and points
63 $content = array(); $points = false;
64
65 // Is the mode set (withdraw or payout)
66 if ((!isGetRequestElementSet('mode')) || (getRequestElement('mode') == 'choose')) {
67         // Let the user choose what he wants to do
68         $content['refid']    = getConfig(('wernis_refid'));
69         $content['wernis_userid'] = '0';
70
71         // Are there some entries?
72         if (fetchUserData(getMemberId())) {
73                 // Fetch id
74                 $content['wernis_userid'] = getUserData('wernis_userid');
75         } // END - if
76
77         // Is there an id?
78         if ((!empty($content['wernis_userid'])) && (!isGetRequestElementSet('mode'))) {
79                 // Then use an other "mode"
80                 setRequestGetElement('mode', 'list');
81
82                 // And load all rows!
83                 $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",
84                         array(getMemberId()), __FILE__, __LINE__);
85
86                 // Load all rows
87                 $content['rows'] = ''; $SW = 2;
88                 while ($data = SQL_FETCHARRAY($result)) {
89                         // Prepare data for output
90                         $rowContent = array(
91                                 'wernis_timestamp' => generateDateTime($data['wernis_timestamp'], 2),
92                                 'points'           => translateComma($data['wernis_amount']),
93                                 'wernis_account'   => bigintval($data['wernis_account']),
94                                 'status'           => WERNIS_TRANSFER_STATUS($data['wernis_type']),
95                                 'raw_type'         => strtolower($data['wernis_type']),
96                                 'sw'               => $SW,
97                         );
98
99                         // Load row template
100                         $content['rows'] .= loadTemplate('member_wernis_mode_list_row', true, $rowContent);
101                         $SW = 3 - $SW;
102                 }
103
104                 // Free result
105                 SQL_FREERESULT($result);
106         } else {
107                 // Default links are not active!
108                 $content['payout_link']   = '<em>{--WERNIS_MEMBER_PAYOUT_DISABLED--}</em>';
109                 $content['withdraw_link'] = '<em>{--WERNIS_MEMBER_WITHDRAW_DISABLED--}</em>';
110
111                 // Is the payout mode active?
112                 if (getConfig('wernis_payout_active') == 'Y') {
113                         // Add link
114                         $content['payout_link'] = "<a class=\"menu_blur\" style=\"height: 40px\" href=\"{%url=modules.php?module=login&amp;what=wernis&amp;mode=payout%}\"><div style=\"padding-top: 10px\">{--MEMBER_WERNIS_MODE_PAYOUT--}</div></a>";
115                 } // END - if
116
117                 // Is the withdraw mode active?
118                 if (getConfig('wernis_withdraw_active') == 'Y') {
119                         // Add link
120                         $content['withdraw_link'] = "<a class=\"menu_blur\" style=\"height: 40px\" href=\"{%url=modules.php?module=login&amp;what=wernis&amp;mode=withdraw%}\"><div style=\"padding-top: 10px\">{--MEMBER_WERNIS_MODE_WITHDRAW--}</div></a>";
121                 } // END - if
122
123                 // Mode chooser! ;-)
124                 setRequestGetElement('mode', 'choose');
125         }
126 } elseif ((getRequestElement('mode') == 'payout') && (getConfig('wernis_payout_active') == 'Y')) {
127         // Get total points and check if the user can request a payout
128         $points = countSumTotalData(getMemberId(), 'user_points', 'points') - countSumTotalData(getMemberId(), 'user_data', 'used_points');
129
130         // Remove the registration fee
131         $points = $points - getConfig('points_register');
132
133         // Is there a percentage or fixed fee?
134         $points = WERNIS_TAKE_FEE($points, 'payout');
135
136         // Is this enougth for a payout?
137         if ($points < getConfig('wernis_min_payout')) {
138                 // No, then abort here
139                 loadTemplate('admin_settings_saved', false, sprintf(
140                         getMessage('WERNIS_MEMBER_MIN_PAYOUT'),
141                         translateComma(getConfig('wernis_min_payout')),
142                         translateComma($points)
143                 ));
144                 return;
145         } // END - if
146
147         // No dots here...
148         $points = explode('.', $points);
149         $points = bigintval($points[0]);
150
151         // Add points to content array
152         $content['points']     = translateComma($points);
153         $content['min_points'] = translateComma(getConfig('wernis_min_payout'));
154
155         // Add fees to array
156         WERNIS_ADD_FEES_TO_ARRAY($content);
157
158         // Init WDS66 userid
159         $content['wernis_userid'] = '';
160
161         // Are there some entries?
162         if (fetchUserData(getMemberId())) {
163                 // Fetch id
164                 $content['wernis_userid'] = getUserData('wernis_userid');
165         } // END - if
166 } elseif ((getRequestElement('mode') == 'withdraw') && (getConfig('wernis_withdraw_active') == 'Y')) {
167         // Get total points for just displaying them
168         $points = countSumTotalData(getMemberId(), 'user_points', 'points') - countSumTotalData(getMemberId(), 'user_data', 'used_points');
169
170         // Prepare data for the template
171         $content['points']        = translateComma($points);
172         $content['min_points']    = translateComma(getConfig('wernis_min_withdraw'));
173         $content['wernis_userid'] = '';
174
175         // Add fees to array
176         WERNIS_ADD_FEES_TO_ARRAY($content);
177
178         // Get WDS66 id
179         if (fetchUserData(getMemberId())) {
180                 // Fetch id
181                 $content['wernis_userid'] = getUserData('wernis_userid');
182         } // END - if
183 } else {
184         // Invalid mode!
185         loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_MODE_INVALID'), getRequestElement('mode')));
186         return;
187 }
188
189 // Is the formular sent?
190 if ((isFormSent()) && (isGetRequestElementSet('mode'))) {
191         // Is the user id and password set?
192         if (!isPostRequestElementSet(('wernis_userid'))) {
193                 // Nothing entered in WDS66 user id
194                 loadTemplate('admin_settings_saved', false, getMessage('WERNIS_MEMBER_EMPTY_USERNAME'));
195         } elseif (!isPostRequestElementSet(('wds66_password'))) {
196                 // Nothing entered in WDS66 password
197                 loadTemplate('admin_settings_saved', false, getMessage('WERNIS_MEMBER_EMPTY_PASSWORD'));
198         } elseif (!isPostRequestElementSet(('amount'))) {
199                 // Nothing entered in amount
200                 loadTemplate('admin_settings_saved', false, getMessage('WERNIS_MEMBER_EMPTY_AMOUNT'));
201         } elseif (postRequestElement('wernis_userid') != bigintval(postRequestElement('wernis_userid'))) {
202                 // Only numbers in account id!
203                 loadTemplate('admin_settings_saved', false, getMessage('WERNIS_MEMBER_INVALID_USERNAME'));
204         } elseif (postRequestElement('amount') != bigintval(postRequestElement('amount'))) {
205                 // Only numbers in amount!
206                 loadTemplate('admin_settings_saved', false, getMessage('WERNIS_MEMBER_INVALID_AMOUNT'));
207         } else {
208                 // Check input data depending on the mode and execute the requested mode
209                 switch (getRequestElement('mode')) {
210                         case 'withdraw': // Widthdraws WDS66 -> This exchange
211                                 if (postRequestElement('amount') < getConfig('wernis_min_withdraw')) {
212                                         // Not enougth entered!
213                                         loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), translateComma(getConfig('wernis_min_withdraw'))));
214                                 } else {
215                                         // All is fine here so do the withdraw
216                                         $success = WERNIS_EXECUTE_WITHDRAW(postRequestElement('wernis_userid'), md5(postRequestElement('wds66_password')), postRequestElement('amount'));
217                                         if ($success === true) {
218                                                 // Add it to this amount
219                                                 addPointsDirectly('wernis_withdraw', getMemberId(), bigintval(postRequestElement('amount')));
220
221                                                 // Update the user data as well..
222                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `wernis_userid`=%s WHERE `userid`=%s LIMIT 1",
223                                                         array(bigintval(postRequestElement('wernis_userid')), getMemberId()), __FILE__, __LINE__);
224
225                                                 // All done!
226                                                 loadTemplate('admin_settings_saved', false, getMessage('WERNIS_MEMBER_WITHDRAW_DONE'));
227                                                 return;
228                                         } elseif ((GET_WERNIS_ERROR_CODE() == 'user_failed') || (GET_WERNIS_ERROR_CODE() == 'own_failed') || (GET_WERNIS_ERROR_CODE() == 'amount_failed')) {
229                                                 // Wrong login data
230                                                 loadTemplate('admin_settings_saved', false, GET_WERNIS_ERROR_MESSAGE());
231                                         } else {
232                                                 // Something went wrong
233                                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_WITHDRAW_FAILED'), GET_WERNIS_ERROR_MESSAGE()));
234                                         }
235                                 }
236                                 break;
237
238                         case 'payout': // Payout this exchange -> WDS66
239                                 if (postRequestElement('amount') < getConfig('wernis_min_payout')) {
240                                         // Not enougth entered!
241                                         loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), translateComma(getConfig('wernis_min_payout'))));
242                                 } elseif (postRequestElement('amount') > $points) {
243                                         // Not enougth points left!
244                                         loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_PAYOUT_POINTS_DEPLETED'), bigintval(postRequestElement('amount')), bigintval($points)));
245                                 } else {
246                                         // All is fine here so do the withdraw
247                                         $success = WERNIS_EXECUTE_PAYOUT(postRequestElement('wernis_userid'), postRequestElement('amount'));
248                                         if ($success === true) {
249                                                 // Sub points
250                                                 subtractPoints('wernis_payout', getMemberId(), postRequestElement('amount'));
251
252                                                 // Update WDS66 id
253                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `wernis_userid`=%s WHERE `userid`=%s LIMIT 1",
254                                                         array(bigintval(postRequestElement('wernis_userid')), getMemberId()), __FILE__, __LINE__);
255
256                                                 // All done!
257                                                 loadTemplate('admin_settings_saved', false, getMessage('WERNIS_MEMBER_PAYOUT_DONE'));
258                                                 return;
259                                         } 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')) {
260                                                 // Wrong login data
261                                                 loadTemplate('admin_settings_saved', false, GET_WERNIS_ERROR_MESSAGE());
262                                         } else {
263                                                 // Something went wrong
264                                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_WITHDRAW_FAILED'), GET_WERNIS_ERROR_MESSAGE()));
265                                         }
266                                 }
267                                 break;
268
269                         default: // Invalid mode!
270                                 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", getRequestElement('mode')));
271                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('WERNIS_MEMBER_MODE_INVALID'), getRequestElement('mode')));
272                                 return;
273                 }
274         }
275 } // END - if
276
277 // Prepare mode for template name
278 $mode = sprintf("member_wernis_mode_%s", getRequestElement('mode'));
279
280 // Load the template
281 loadTemplate($mode, false, $content);
282
283 // [EOF]
284 ?>