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 * 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('primera')) && (!isAdmin())) {
51 // Extension 'primera' is not activated
52 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('primera'));
56 // Check if the admin has entered the data
57 if ((getConfig('primera_api_name') == '') || (getConfig('primera_api_md5') == '')) {
58 // Something important is missing...
59 loadTemplate('admin_settings_saved', false, getMessage('PRIMERA_MEMBER_API_DATA_MISSING'));
63 // Init the content array and points
67 // Is the mode set (payout only)
68 if (!isGetRequestElementSet('mode')) {
70 $content['refid'] = getConfig(('primera_refid'));
72 // Are there some entries?
73 if (fetchUserData(getMemberId())) {
75 $content['primera_nickname'] = getUserData('primera_nickname');
79 if ((!empty($content['primera_nickname'])) && (!isGetRequestElementSet('mode'))) {
80 // Then use an other "mode"
81 setRequestGetElement('mode', 'list');
84 $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",
85 array(getMemberId()), __FILE__, __LINE__);
88 $content['rows'] = ''; $SW = 2;
89 while ($data = SQL_FETCHARRAY($result)) {
90 // Prepare data for output
92 'primera_timestamp' => generateDateTime($data['primera_timestamp'], 2),
93 'points' => translateComma($data['primera_amount']),
94 'primera_account' => SQL_ESCAPE($data['primera_account']),
95 'status' => PRIMERA_TRANSFER_STATUS($data['primera_type']),
96 'raw_type' => strtolower($data['primera_type']),
101 $content['rows'] .= loadTemplate('member_primera_mode_list_row', true, $rowContent);
106 SQL_FREERESULT($result);
109 setRequestGetElement('mode', 'pay');
113 if (getRequestElement('mode') == 'pay') {
114 // Get total points and check if the user can request a payout
115 $points = countSumTotalData(getMemberId(), 'user_points', 'points') - countSumTotalData(getMemberId(), 'user_data', 'used_points');
118 $points = explode('.', $points);
119 $points = bigintval($points[0]);
121 // Remove the registration fee
122 $points = $points - getConfig('points_register');
124 // Is this enougth for a payout?
125 if ($points < getConfig('primera_min_payout')) {
126 // No, then abort here
127 loadTemplate('admin_settings_saved', false, sprintf(getMessage('PRIMERA_MEMBER_MIN_PAYOUT_PAYOUT'), translateComma(getConfig('primera_min_payout'))));
131 // Add points to content array
132 $content['points'] = $points;
133 $content['min_points'] = translateComma(getConfig('primera_min_payout'));
136 $content['primera_nickname'] = '';
138 // Do we have a user account? (should be!)
139 if (fetchUserData(getMemberId())) {
141 $content['primera_nickname'] = getUserData('primera_nickname');
145 loadTemplate('admin_settings_saved', false, sprintf(getMessage('PRIMERA_MEMBER_MODE_INVALID'), getRequestElement('mode')));
149 // Is the formular sent?
150 if ((isFormSent()) && (isGetRequestElementSet('mode'))) {
151 // Check input data depending on the mode and execute the requested mode
152 switch (getRequestElement('mode')) {
153 case 'pay': // Payout this exchange -> Primus
154 // Is the user id and password set?
155 if (!isPostRequestElementSet(('primera_nickname'))) {
156 // Nothing entered in Primus nickname
157 loadTemplate('admin_settings_saved', false, getMessage('PRIMERA_MEMBER_EMPTY_USERNAME'));
158 } elseif (!isPostRequestElementSet(('primera_password'))) {
159 // Nothing entered in Primera password
160 loadTemplate('admin_settings_saved', false, getMessage('PRIMERA_MEMBER_EMPTY_PASSWORD'));
161 } elseif (!isPostRequestElementSet(('amount'))) {
162 // Nothing entered in amount
163 loadTemplate('admin_settings_saved', false, getMessage('PRIMERA_MEMBER_EMPTY_AMOUNT'));
164 } elseif (postRequestElement('amount') != bigintval(postRequestElement('amount'))) {
165 // Only numbers in amount!
166 loadTemplate('admin_settings_saved', false, getMessage('PRIMERA_MEMBER_INVALID_AMOUNT'));
167 } elseif (postRequestElement('amount') < getConfig('primera_min_payout')) {
168 // Not enougth entered!
169 loadTemplate('admin_settings_saved', false, sprintf(getMessage('PRIMERA_MEMBER_AMOUNT_SMALLER_MIN'), getConfig(('primera_min_payout'))));
170 } elseif (postRequestElement('amount') > $points) {
171 // Not enougth points left!
172 loadTemplate('admin_settings_saved', false, sprintf(getMessage('PRIMERA_MEMBER_PAYOUT_POINTS_DEPLETED'), bigintval(postRequestElement('amount')), bigintval($points)));
174 // All is fine here so do the payout
175 $success = executePrimeraPayout(postRequestElement('primera_nickname'), md5(postRequestElement('primera_password')), postRequestElement('amount'));
177 // Default is locked!
180 // Shall I 'pay' the referal points imidiately?
181 if (getConfig('ref_payout') == '0') {
186 // Remove points from account
187 subtractPoints('primera_payout', getMemberId(), postRequestElement('amount'));
189 // Update primera nickname
190 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `primera_nickname`=%s WHERE `userid`=%s LIMIT 1",
191 array(postRequestElement('primera_nickname'), getMemberId()), __FILE__, __LINE__);
194 loadTemplate('admin_settings_saved', false, getMessage('PRIMERA_MEMBER_PAYOUT_DONE'));
196 } 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')) {
198 loadTemplate('admin_settings_saved', false, GET_PRIMERA_ERROR_MESSAGE());
200 // Something went wrong
201 loadTemplate('admin_settings_saved', false, sprintf(getMessage('PRIMERA_MEMBER_PAYOUT_FAILED'), GET_PRIMERA_ERROR_MESSAGE()));
206 default: // Invalid mode!
207 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", getRequestElement('mode')));
208 loadTemplate('admin_settings_saved', false, sprintf(getMessage('PRIMERA_MEMBER_MODE_INVALID'), getRequestElement('mode')));
213 // Prepare mode for template name
214 $mode = sprintf("member_primera_mode_%s", getRequestElement('mode'));
217 loadTemplate($mode, false, $content);