2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/09/2008 *
4 * =================== Last change: 09/09/2008 *
6 * -------------------------------------------------------------------- *
7 * File : what-primera.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('primera')) && (!isAdmin())) {
50 // Extension 'primera' is not activated
51 displayMessage(generateExtensionInactiveNotInstalledMessage('primera'));
55 // Check if the admin has entered the data
56 if ((getConfig('primera_api_name') == '') || (getConfig('primera_api_md5') == '')) {
57 // Something important is missing...
58 displayMessage('{--MEMBER_PRIMERA_API_DATA_MISSING--}');
62 // Init the content array and points
66 // Is the mode set (payout only)
67 if (!isGetRequestParameterSet('mode')) {
69 if ((!empty($content['primera_nickname'])) && (!isGetRequestParameterSet('mode'))) {
70 // Then use an other "mode"
71 setGetRequestParameter('mode', 'list');
74 $result = SQL_QUERY_ESC("SELECT `id`,`primera_account`,`primera_amount`,`primera_timestamp`,`primera_type` FROM `{?_MYSQL_PREFIX?}_user_primera` WHERE `userid`=%s ORDER BY `primera_timestamp` DESC",
75 array(getMemberId()), __FILE__, __LINE__);
78 $content['rows'] = '';
79 while ($data = SQL_FETCHARRAY($result)) {
80 // Prepare data for output
81 $rowContent['primera_timestamp'] = generateDateTime($data['primera_timestamp'], 2);
84 $content['rows'] .= loadTemplate('member_primera_mode_list_row', true, $rowContent);
88 SQL_FREERESULT($result);
91 setGetRequestParameter('mode', 'pay');
95 if (getRequestParameter('mode') == 'pay') {
96 // Get total points and check if the user can request a payout
97 $points = getTotalPoints(getMemberId());
100 $points = explode('.', $points);
101 $points = bigintval($points[0]);
103 // Remove the registration fee
104 $points = $points - getPointsRegister();
106 // Is this enougth for a payout?
107 if ($points < getConfig('primera_min_payout')) {
108 // No, then abort here
109 displayMessage('{--MEMBER_PRIMERA_MIN_PAYOUT_PAYOUT--}');
113 // Add points to content array
114 $content['points'] = $points;
117 displayMessage(getMaskedMessage('MEMBER_PRIMERA_MODE_INVALID', getRequestParameter('mode')));
121 // Is the formular sent?
122 if ((isFormSent()) && (isGetRequestParameterSet('mode'))) {
123 // Check input data depending on the mode and execute the requested mode
124 switch (getRequestParameter('mode')) {
125 case 'pay': // Payout this exchange -> Primus
126 // Is the user id and password set?
127 if (!isPostRequestParameterSet('primera_nickname')) {
128 // Nothing entered in Primus nickname
129 displayMessage('{--MEMBER_PRIMERA_EMPTY_USERNAME--}');
130 } elseif (!isPostRequestParameterSet('primera_password')) {
131 // Nothing entered in Primera password
132 displayMessage('{--MEMBER_PRIMERA_EMPTY_PASSWORD--}');
133 } elseif (!isPostRequestParameterSet('amount')) {
134 // Nothing entered in amount
135 displayMessage('{--MEMBER_PRIMERA_EMPTY_AMOUNT--}');
136 } elseif (postRequestParameter('amount') != bigintval(postRequestParameter('amount'))) {
137 // Only numbers in amount!
138 displayMessage('{--MEMBER_PRIMERA_INVALID_AMOUNT--}');
139 } elseif (postRequestParameter('amount') < getConfig('primera_min_payout')) {
140 // Not enougth entered!
141 displayMessage('{--MEMBER_PRIMERA_AMOUNT_SMALLER_MIN--}');
142 } elseif (postRequestParameter('amount') > $points) {
143 // Not enougth points left!
144 displayMessage(sprintf(getMessage('MEMBER_PRIMERA_PAYOUT_POINTS_DEPLETED'), bigintval(postRequestParameter('amount')), bigintval($points)));
146 // All is fine here so do the payout
147 $success = executePrimeraPayout(postRequestParameter('primera_nickname'), md5(postRequestParameter('primera_password')), postRequestParameter('amount'));
149 // Default is locked!
152 // Shall I 'pay' the referal points imidiately?
153 if (getConfig('ref_payout') == '0') {
158 // Remove points from account
159 subtractPoints('primera_payout', getMemberId(), postRequestParameter('amount'));
161 // Update primera nickname
162 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `primera_nickname`=%s WHERE `userid`=%s LIMIT 1",
163 array(postRequestParameter('primera_nickname'), getMemberId()), __FILE__, __LINE__);
166 displayMessage('{--MEMBER_PRIMERA_PAYOUT_DONE--}');
168 } elseif ((GET_PRIMERA_ERROR_CODE() == 'user_failed') || (GET_PRIMERA_ERROR_CODE() == 'own_failed') || (GET_PRIMERA_ERROR_CODE() == 'amount_failed') || (GET_PRIMERA_ERROR_CODE() == 'api_amount_failed')) {
170 displayMessage(GET_PRIMERA_ERROR_MESSAGE());
172 // Something went wrong
173 displayMessage(getMaskedMessage('MEMBER_PRIMERA_PAYOUT_FAILED', GET_PRIMERA_ERROR_MESSAGE()));
178 default: // Invalid mode!
179 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", getRequestParameter('mode')));
180 displayMessage(getMaskedMessage('MEMBER_PRIMERA_MODE_INVALID', getRequestParameter('mode')));
185 // Prepare mode for template name
186 $mode = sprintf("member_primera_mode_%s", getRequestParameter('mode'));
189 loadTemplate($mode, false, $content);