2 /************************************************************************
3 * MXChange v0.2.1 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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif (!IS_MEMBER()) {
39 // User is not logged in
40 LOAD_URL("modules.php?module=index");
41 } elseif ((!EXT_IS_ACTIVE("primera")) && (!IS_ADMIN())) {
42 // Extension "primera" is not activated
43 addFatalMessage(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "primera");
47 // Add description as navigation point
48 ADD_DESCR("member", __FILE__);
50 // Check if the admin has entered the data
51 if ((getConfig('primera_api_name') == "") || (getConfig('primera_api_md5') == "")) {
52 // Something important is missing...
53 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('PRIMERA_MEMBER_API_DATA_MISSING'));
57 // Init the content array and points
58 $content = array(); $points = false;
60 // Is the mode set (payout only)
61 if (!REQUEST_ISSET_GET(('mode'))) {
63 $content['refid'] = bigintval(getConfig('primera_refid'));
66 $result = SQL_QUERY_ESC("SELECT primera_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
67 array($GLOBALS['userid']), __FILE__, __LINE__);
69 // Are there some entries?
70 if (SQL_NUMROWS($result) == 1) {
72 list($content['primera_nickname']) = SQL_FETCHROW($result);
76 SQL_FREERESULT($result);
79 if ((!empty($content['primera_nickname'])) && (!REQUEST_ISSET_GET(('mode')))) {
80 // Then use an other "mode"
81 REQUEST_SET_GET('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($GLOBALS['userid']), __FILE__, __LINE__);
88 $content['rows'] = ""; $SW = 2;
89 while ($data = SQL_FETCHARRAY($result)) {
90 // Prepare data for output
92 'stamp' => MAKE_DATETIME($data['primera_timestamp'], "2"),
93 'points' => TRANSLATE_COMMA($data['primera_amount']),
94 'acc' => SQL_ESCAPE($data['primera_account']),
95 'status' => PRIMERA_TRANSFER_STATUS($data['primera_type']),
96 'raw_type' => strtolower($data['primera_type']),
101 $content['rows'] .= LOAD_TEMPLATE("member_primera_mode_list_row", true, $rowContent);
106 SQL_FREERESULT($result);
109 REQUEST_SET_GET('mode', "pay");
112 if (REQUEST_GET('mode') == "pay") {
113 // Get total points and check if the user can request a payout
114 $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
117 $points = explode(".", $points);
118 $points = bigintval($points[0]);
120 // Remove the registration fee
121 $points = $points - getConfig('points_register');
123 // Is this enougth for a payout?
124 if ($points < getConfig('primera_min_payout')) {
125 // No, then abort here
126 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(PRIMERA_MEMBER_MIN_PAYOUT_PAYOUT, TRANSLATE_COMMA(getConfig('primera_min_payout'))));
130 // Add points to content array
131 $content['points'] = $points;
132 $content['min_points'] = TRANSLATE_COMMA(getConfig('primera_min_payout'));
135 $content['primera_nickname'] = "";
136 $result = SQL_QUERY_ESC("SELECT primera_userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
137 array($GLOBALS['userid']), __FILE__, __LINE__);
139 // Are there some entries?
140 if (SQL_NUMROWS($result) == 1) {
142 list($content['primera_nickname']) = SQL_FETCHROW($result);
146 SQL_FREERESULT($result);
149 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(PRIMERA_MEMBER_MODE_INVALID, REQUEST_GET(('mode'))));
153 // Is the formular sent?
154 if ((IS_FORM_SENT()) && (REQUEST_ISSET_GET(('mode')))) {
155 // Check input data depending on the mode and execute the requested mode
156 switch (REQUEST_GET('mode')) {
157 case "pay": // Payout this exchange -> Primus
158 // Is the user ID and password set?
159 if (!REQUEST_ISSET_POST(('primera_nickname'))) {
160 // Nothing entered in Primus nickname
161 LOAD_TEMPLATE("admin_settings_saved", false, PRIMERA_MEMBER_EMPTY_USERNAME);
162 } elseif (!REQUEST_ISSET_POST(('primera_password'))) {
163 // Nothing entered in Primera password
164 LOAD_TEMPLATE("admin_settings_saved", false, PRIMERA_MEMBER_EMPTY_PASSWORD);
165 } elseif (!REQUEST_ISSET_POST(('amount'))) {
166 // Nothing entered in amount
167 LOAD_TEMPLATE("admin_settings_saved", false, PRIMERA_MEMBER_EMPTY_AMOUNT);
168 } elseif (REQUEST_POST('amount') != bigintval(REQUEST_POST('amount'))) {
169 // Only numbers in amount!
170 LOAD_TEMPLATE("admin_settings_saved", false, PRIMERA_MEMBER_INVALID_AMOUNT);
171 } elseif (REQUEST_POST('amount') < getConfig('primera_min_payout')) {
172 // Not enougth entered!
173 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(PRIMERA_MEMBER_AMOUNT_SMALLER_MIN, bigintval(getConfig('primera_min_payout'))));
174 } elseif (REQUEST_POST('amount') > $points) {
175 // Not enougth points left!
176 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(PRIMERA_MEMBER_PAYOUT_POINTS_DEPLETED, bigintval(REQUEST_POST('amount')), bigintval($points)));
178 // All is fine here so do the payout
179 $success = PRIMERA_EXECUTE_PAYOUT(REQUEST_POST('primera_nickname'), md5(REQUEST_POST('primera_password')), REQUEST_POST('amount'));
181 // Default is locked!
184 // Shall I "pay" the referal points imidiately?
185 if (getConfig('ref_payout') == "0") {
190 // Remove points from account
191 SUB_POINTS("primera_payout", $GLOBALS['userid'], REQUEST_POST('amount'));
193 // Update primera nickname
194 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET `primera_userid`=%s WHERE userid=%s LIMIT 1",
195 array(REQUEST_POST('primera_nickname'), $GLOBALS['userid']), __FILE__, __LINE__);
198 LOAD_TEMPLATE("admin_settings_saved", false, PRIMERA_MEMBER_PAYOUT_DONE);
200 } 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")) {
202 LOAD_TEMPLATE("admin_settings_saved", false, GET_PRIMERA_ERROR_MESSAGE());
204 // Something went wrong
205 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(PRIMERA_MEMBER_PAYOUT_FAILED, GET_PRIMERA_ERROR_MESSAGE()));
210 default: // Invalid mode!
211 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid mode %s detected.", REQUEST_GET('mode')));
212 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(PRIMERA_MEMBER_MODE_INVALID, REQUEST_GET(('mode'))));
217 // Prepare mode for template name
218 $mode = sprintf("member_primera_mode_%s", REQUEST_GET(('mode')));
221 LOAD_TEMPLATE($mode, false, $content);