]> git.mxchange.org Git - mailer.git/blob - inc/modules/member/what-wernis.php
More XHTML-fied and extended header added to templates
[mailer.git] / inc / modules / member / what-wernis.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. March 2009)             $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
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 - 2008 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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 } elseif (!IS_MEMBER()) {
44         // User is not logged in
45         LOAD_URL("modules.php?module=index");
46 } elseif ((!EXT_IS_ACTIVE("wernis")) && (!IS_ADMIN())) {
47         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "wernis");
48         return;
49 }
50
51 // Add description as navigation point
52 ADD_DESCR("member", __FILE__);
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         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_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 ((!REQUEST_ISSET_GET(('mode'))) || (REQUEST_GET('mode') == "choose")) {
66         // Let the user choose what he wants to do
67         $content['refid']    = getConfig(('wernis_refid'));
68         $content['wds66_id'] = 0;
69
70         // Get WDS66 id
71         $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
72                 array(getUserId()), __FILE__, __LINE__);
73
74         // Are there some entries?
75         if (SQL_NUMROWS($result) == 1) {
76                 // Fetch ID
77                 list($content['wds66_id']) = SQL_FETCHROW($result);
78         } // END - if
79
80         // Free result
81         SQL_FREERESULT($result);
82
83         // Is there an ID?
84         if ((!empty($content['wds66_id'])) && (!REQUEST_ISSET_GET(('mode')))) {
85                 // Then use an other "mode"
86                 REQUEST_SET_GET('mode', "list");
87
88                 // And load all rows!
89                 $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",
90                         array(getUserId()), __FILE__, __LINE__);
91
92                 // Load all rows
93                 $content['rows'] = ""; $SW = 2;
94                 while ($data = SQL_FETCHARRAY($result)) {
95                         // Prepare data for output
96                         $rowContent = array(
97                                 'stamp'    => MAKE_DATETIME($data['wernis_timestamp'], "2"),
98                                 'points'   => TRANSLATE_COMMA($data['wernis_amount']),
99                                 'acc'      => bigintval($data['wernis_account']),
100                                 'status'   => WERNIS_TRANSFER_STATUS($data['wernis_type']),
101                                 'raw_type' => strtolower($data['wernis_type']),
102                                 'sw'       => $SW,
103                         );
104
105                         // Load row template
106                         $content['rows'] .= LOAD_TEMPLATE("member_wernis_mode_list_row", true, $rowContent);
107                         $SW = 3 - $SW;
108                 }
109
110                 // Free result
111                 SQL_FREERESULT($result);
112         } else {
113                 // Default links are not active!
114                 $content['payout_link']   = "<em>{--WERNIS_MEMBER_PAYOUT_DISABLED--}</em>";
115                 $content['withdraw_link'] = "<em>{--WERNIS_MEMBER_WITHDRAW_DISABLED--}</em>";
116
117                 // Is the payout mode active?
118                 if (getConfig('wernis_payout_active') == "Y") {
119                         // Add link
120                         $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>";
121                 } // END - if
122
123                 // Is the withdraw mode active?
124                 if (getConfig('wernis_withdraw_active') == "Y") {
125                         // Add link
126                         $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>";
127                 } // END - if
128
129                 // Mode chooser! ;-)
130                 REQUEST_SET_GET('mode', "choose");
131         }
132 } elseif ((REQUEST_GET('mode') == "payout") && (getConfig('wernis_payout_active') == "Y")) {
133         // Get total points and check if the user can request a payout
134         $points = GET_TOTAL_DATA(getUserId(), "user_points", "points") - GET_TOTAL_DATA(getUserId(), "user_data", "used_points");
135
136         // Remove the registration fee
137         $points = $points - getConfig('points_register');
138
139         // Is there a percentage or fixed fee?
140         $points = WERNIS_TAKE_FEE($points, "payout");
141
142         // Is this enougth for a payout?
143         if ($points < getConfig('wernis_min_payout')) {
144                 // No, then abort here
145                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_MIN_PAYOUT'), TRANSLATE_COMMA(getConfig('wernis_min_payout'))));
146                 return;
147         } // END - if
148
149         // No dots here...
150         $points = explode(".", $points);
151         $points = bigintval($points[0]);
152
153         // Add points to content array
154         $content['points']     = TRANSLATE_COMMA($points);
155         $content['min_points'] = TRANSLATE_COMMA(getConfig('wernis_min_payout'));
156
157         // Add fees to array
158         WERNIS_ADD_FEES_TO_ARRAY($content);
159
160         // Get WDS66 id
161         $content['wds66_id'] = "";
162         $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
163                 array(getUserId()), __FILE__, __LINE__);
164
165         // Are there some entries?
166         if (SQL_NUMROWS($result) == 1) {
167                 // Fetch ID
168                 list($content['wds66_id']) = SQL_FETCHROW($result);
169         } // END - if
170
171         // Free result
172         SQL_FREERESULT($result);
173 } elseif ((REQUEST_GET('mode') == "withdraw") && (getConfig('wernis_withdraw_active') == "Y")) {
174         // Get total points for just displaying them
175         $points = GET_TOTAL_DATA(getUserId(), "user_points", "points") - GET_TOTAL_DATA(getUserId(), "user_data", "used_points");
176
177         // Prepare data for the template
178         $content['points']     = TRANSLATE_COMMA($points);
179         $content['min_points'] = TRANSLATE_COMMA(getConfig('wernis_min_withdraw'));
180         $content['wds66_id']   = "";
181
182         // Add fees to array
183         WERNIS_ADD_FEES_TO_ARRAY($content);
184
185         // Get WDS66 id
186         $result = SQL_QUERY_ESC("SELECT wernis_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
187                 array(getUserId()), __FILE__, __LINE__);
188
189         // Are there some entries?
190         if (SQL_NUMROWS($result) == 1) {
191                 // Fetch ID
192                 list($content['wds66_id']) = SQL_FETCHROW($result);
193         } // END - if
194
195         // Free result
196         SQL_FREERESULT($result);
197 } else {
198         // Invalid mode!
199         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_MODE_INVALID'), REQUEST_GET(('mode'))));
200         return;
201 }
202
203 // Is the formular sent?
204 if ((IS_FORM_SENT()) && (REQUEST_ISSET_GET(('mode')))) {
205         // Is the user ID and password set?
206         if (!REQUEST_ISSET_POST(('wds66_id'))) {
207                 // Nothing entered in WDS66 user ID
208                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_EMPTY_USERNAME'));
209         } elseif (!REQUEST_ISSET_POST(('wds66_password'))) {
210                 // Nothing entered in WDS66 password
211                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_EMPTY_PASSWORD'));
212         } elseif (!REQUEST_ISSET_POST(('amount'))) {
213                 // Nothing entered in amount
214                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_EMPTY_AMOUNT'));
215         } elseif (REQUEST_POST('wds66_id') != bigintval(REQUEST_POST('wds66_id'))) {
216                 // Only numbers in account ID!
217                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_INVALID_USERNAME'));
218         } elseif (REQUEST_POST('amount') != bigintval(REQUEST_POST('amount'))) {
219                 // Only numbers in amount!
220                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_INVALID_AMOUNT'));
221         } else {
222                 // Check input data depending on the mode and execute the requested mode
223                 switch (REQUEST_GET('mode')) {
224                         case "withdraw": // Widthdraws WDS66 -> This exchange
225                                 if (REQUEST_POST('amount') < getConfig('wernis_min_withdraw')) {
226                                         // Not enougth entered!
227                                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), getConfig(('wernis_min_withdraw'))));
228                                 } else {
229                                         // All is fine here so do the withdraw
230                                         $success = WERNIS_EXECUTE_WITHDRAW(REQUEST_POST('wds66_id'), md5(REQUEST_POST('wds66_password')), REQUEST_POST('amount'));
231                                         if ($success) {
232                                                 // Add it to this amount
233                                                 unset($GLOBALS['ref_level']);
234                                                 ADD_POINTS_REFSYSTEM("wernis_withdraw", getUserId(), bigintval(REQUEST_POST('amount')), false, 0, false, "direct");
235
236                                                 // Update the user data as well..
237                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
238                                                         array(bigintval(REQUEST_POST('wds66_id')), getUserId()), __FILE__, __LINE__);
239
240                                                 // All done!
241                                                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_WITHDRAW_DONE'));
242                                                 return;
243                                         } elseif ((GET_WERNIS_ERROR_CODE() == "user_failed") || (GET_WERNIS_ERROR_CODE() == "own_failed") || (GET_WERNIS_ERROR_CODE() == "amount_failed")) {
244                                                 // Wrong login data
245                                                 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
246                                         } else {
247                                                 // Something went wrong
248                                                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_WITHDRAW_FAILED'), GET_WERNIS_ERROR_MESSAGE()));
249                                         }
250                                 }
251                                 break;
252
253                         case "payout": // Payout this exchange -> WDS66
254                                 if (REQUEST_POST('amount') < getConfig('wernis_min_payout')) {
255                                         // Not enougth entered!
256                                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_AMOUNT_SMALLER_MIN'), getConfig(('wernis_min_payout'))));
257                                 } elseif (REQUEST_POST('amount') > $points) {
258                                         // Not enougth points left!
259                                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_PAYOUT_POINTS_DEPLETED'), bigintval(REQUEST_POST('amount')), bigintval($points)));
260                                 } else {
261                                         // All is fine here so do the withdraw
262                                         $success = WERNIS_EXECUTE_PAYOUT(REQUEST_POST('wds66_id'), REQUEST_POST('amount'));
263                                         if ($success) {
264                                                 // Sub points
265                                                 SUB_POINTS("wernis_payout", getUserId(), REQUEST_POST('amount'));
266
267                                                 // Update WDS66 id
268                                                 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `wernis_userid`=%s WHERE userid=%s LIMIT 1",
269                                                         array(bigintval(REQUEST_POST('wds66_id')), getUserId()), __FILE__, __LINE__);
270
271                                                 // All done!
272                                                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('WERNIS_MEMBER_PAYOUT_DONE'));
273                                                 return;
274                                         } 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")) {
275                                                 // Wrong login data
276                                                 LOAD_TEMPLATE("admin_settings_saved", false, GET_WERNIS_ERROR_MESSAGE());
277                                         } else {
278                                                 // Something went wrong
279                                                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_WITHDRAW_FAILED'), GET_WERNIS_ERROR_MESSAGE()));
280                                         }
281                                 }
282                                 break;
283
284                         default: // Invalid mode!
285                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", REQUEST_GET('mode')));
286                                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('WERNIS_MEMBER_MODE_INVALID'), REQUEST_GET(('mode'))));
287                                 return;
288                 }
289         }
290 } // END - if
291
292 // Prepare mode for template name
293 $mode = sprintf("member_wernis_mode_%s", REQUEST_GET(('mode')));
294
295 // Load the template
296 LOAD_TEMPLATE($mode, false, $content);
297
298 //
299 ?>