]> git.mxchange.org Git - mailer.git/blob - inc/modules/member/what-wernis.php
Removed comment introduced by Profi-Concept, this comment should fine (in a much...
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } elseif (!isMember()) {
42         // User is not logged in
43         redirectToIndexMemberOnlyModule();
44 }
45
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
48
49 if ((!isExtensionActive('wernis')) && (!isAdmin())) {
50         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('wernis'));
51         return;
52 } // END - if
53
54 // Check if the admin has entered the data
55 if ((getConfig('wernis_api_id') == '') || (getConfig('wernis_api_md5') == '')) {
56         // Something important is missing...
57         loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_API_DATA_MISSING--}');
58         return;
59 } // END - if
60
61 // Init the content array and points
62 $content = array(); $points = false;
63
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';
68
69         // Is there an id?
70         if ((!empty($content['wernis_userid'])) && (!isGetRequestParameterSet('mode'))) {
71                 // Then use an other "mode"
72                 setGetRequestParameter('mode', 'list');
73
74                 // And load all rows!
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__);
77
78                 // Load all rows
79                 $content['rows'] = '';
80                 while ($data = SQL_FETCHARRAY($result)) {
81                         // Prepare data for output
82                         $rowContent = array(
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'],
87                         );
88
89                         // Load row template
90                         $content['rows'] .= loadTemplate('member_wernis_mode_list_row', true, $rowContent);
91                 } // END - while
92
93                 // Free result
94                 SQL_FREERESULT($result);
95         } else {
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>';
99
100                 // Is the payout mode active?
101                 if (getConfig('wernis_payout_active') == 'Y') {
102                         // Add link
103                         $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>';
104                 } // END - if
105
106                 // Is the withdraw mode active?
107                 if (getConfig('wernis_withdraw_active') == 'Y') {
108                         // Add link
109                         $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>';
110                 } // END - if
111
112                 // Mode chooser! ;-)
113                 setGetRequestParameter('mode', 'choose');
114         }
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();
118
119         // Is there a percentage or fixed fee?
120         $points = WERNIS_TAKE_FEE($points, 'payout');
121
122         // Is this enougth for a payout?
123         if ($points < getConfig('wernis_min_payout')) {
124                 // No, then abort here
125                 loadTemplate('admin_settings_saved', false, sprintf(
126                         getMessage('MEMBER_WERNIS_MIN_PAYOUT'),
127                         translateComma(getConfig('wernis_min_payout')),
128                         translateComma($points)
129                 ));
130                 return;
131         } // END - if
132
133         // No dots here...
134         $points = explode('.', $points);
135         $points = bigintval($points[0]);
136
137         // Add points to content array
138         $content['points']     = $points;
139
140         // Get WDS66 username
141         $content['wernis_userid'] = getUserData('wernis_userid');
142 } elseif ((getRequestParameter('mode') == 'withdraw') && (getConfig('wernis_withdraw_active') == 'Y')) {
143         // Prepare data for the template
144         $content['points']        = getTotalPoints(getMemberId());
145         $content['wernis_userid'] = '';
146
147         // Fetch id
148         $content['wernis_userid'] = getUserData('wernis_userid');
149 } else {
150         // Invalid mode!
151         loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_WERNIS_MODE_INVALID', getRequestParameter('mode')));
152         return;
153 }
154
155 // Is the formular sent?
156 if ((isFormSent()) && (isGetRequestParameterSet('mode'))) {
157         // Is the user id and password set?
158         if (!isPostRequestParameterSet('wernis_userid')) {
159                 // Nothing entered in WDS66 user id
160                 loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_EMPTY_USERNAME--}');
161         } elseif (!isPostRequestParameterSet('wds66_password')) {
162                 // Nothing entered in WDS66 password
163                 loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_EMPTY_PASSWORD--}');
164         } elseif (!isPostRequestParameterSet('amount')) {
165                 // Nothing entered in amount
166                 loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_EMPTY_AMOUNT--}');
167         } elseif (postRequestParameter('wernis_userid') != bigintval(postRequestParameter('wernis_userid'))) {
168                 // Only numbers in account id!
169                 loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_INVALID_USERNAME');
170         } elseif (postRequestParameter('amount') != bigintval(postRequestParameter('amount'))) {
171                 // Only numbers in amount!
172                 loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_INVALID_AMOUNT--}');
173         } else {
174                 // Check input data depending on the mode and execute the requested mode
175                 switch (getRequestParameter('mode')) {
176                         case 'withdraw': // Widthdraws WDS66 -> This exchange
177                                 if (postRequestParameter('amount') < getConfig('wernis_min_withdraw')) {
178                                         // Not enougth entered!
179                                         loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_WITHDRAW_AMOUNT_SMALLER_MIN--}');
180                                 } else {
181                                         // All is fine here so do the withdraw
182                                         $success = WERNIS_EXECUTE_WITHDRAW(postRequestParameter('wernis_userid'), md5(postRequestParameter('wds66_password')), postRequestParameter('amount'));
183                                         if ($success === true) {
184                                                 // Add it to this amount
185                                                 addPointsDirectly('wernis_withdraw', getMemberId(), bigintval(postRequestParameter('amount')));
186
187                                                 // Update the user data as well..
188                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `wernis_userid`=%s WHERE `userid`=%s LIMIT 1",
189                                                         array(bigintval(postRequestParameter('wernis_userid')), getMemberId()), __FILE__, __LINE__);
190
191                                                 // All done!
192                                                 loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_WITHDRAW_DONE--}');
193                                                 return;
194                                         } elseif ((GET_WERNIS_ERROR_CODE() == 'user_failed') || (GET_WERNIS_ERROR_CODE() == 'own_failed') || (GET_WERNIS_ERROR_CODE() == 'amount_failed')) {
195                                                 // Wrong login data
196                                                 loadTemplate('admin_settings_saved', false, GET_WERNIS_ERROR_MESSAGE());
197                                         } else {
198                                                 // Something went wrong
199                                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_WERNIS_WITHDRAW_FAILED', GET_WERNIS_ERROR_MESSAGE()));
200                                         }
201                                 }
202                                 break;
203
204                         case 'payout': // Payout this exchange -> WDS66
205                                 if (postRequestParameter('amount') < getConfig('wernis_min_payout')) {
206                                         // Not enougth entered!
207                                         loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_PAYOUT_AMOUNT_SMALLER_MIN--}');
208                                 } elseif (postRequestParameter('amount') > $points) {
209                                         // Not enougth points left!
210                                         loadTemplate('admin_settings_saved', false, sprintf(getMessage('MEMBER_WERNIS_PAYOUT_POINTS_DEPLETED'), bigintval(postRequestParameter('amount')), bigintval($points)));
211                                 } else {
212                                         // All is fine here so do the withdraw
213                                         $success = WERNIS_EXECUTE_PAYOUT(postRequestParameter('wernis_userid'), postRequestParameter('amount'));
214                                         if ($success === true) {
215                                                 // Sub points
216                                                 subtractPoints('wernis_payout', getMemberId(), postRequestParameter('amount'));
217
218                                                 // Update WDS66 id
219                                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `wernis_userid`=%s WHERE `userid`=%s LIMIT 1",
220                                                         array(bigintval(postRequestParameter('wernis_userid')), getMemberId()), __FILE__, __LINE__);
221
222                                                 // All done!
223                                                 loadTemplate('admin_settings_saved', false, '{--MEMBER_WERNIS_PAYOUT_DONE--}');
224                                                 return;
225                                         } 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')) {
226                                                 // Wrong login data
227                                                 loadTemplate('admin_settings_saved', false, GET_WERNIS_ERROR_MESSAGE());
228                                         } else {
229                                                 // Something went wrong
230                                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_WERNIS_WITHDRAW_FAILED', GET_WERNIS_ERROR_MESSAGE()));
231                                         }
232                                 }
233                                 break;
234
235                         default: // Invalid mode!
236                                 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", getRequestParameter('mode')));
237                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_WERNIS_MODE_INVALID', getRequestParameter('mode')));
238                                 return;
239                 } // END - switch
240         }
241 } // END - if
242
243 // Prepare mode for template name
244 $mode = sprintf("member_wernis_mode_%s", getRequestParameter('mode'));
245
246 // Load the template
247 loadTemplate($mode, false, $content);
248
249 // [EOF]
250 ?>