2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/19/2003 *
4 * =============== Last change: 08/12/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-points.php *
8 * -------------------------------------------------------------------- *
9 * Short description : All your collected points... *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Alle Ihrer gesammelten Punkte *
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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Sets a status message and code
41 function WERNIS_STATUS_MESSAGE ($msg, $status) {
43 $WERNIS['message'] = $msg;
44 $WERNIS['status'] = $status;
47 // Get the status message
48 function GET_WERNIS_ERROR_MESSAGE () {
50 if (isset($WERNIS['message'])) {
52 return $WERNIS['message'];
53 } elseif (isset($WERNIS['status'])) {
54 // Fall-back to status
55 return sprintf(WERNIS_ERROR_STATUS, $WERNIS['status']);
57 // Something bad happend
58 return WERNIS_UNKNOWN_ERROR;
62 // Get the status code
63 function GET_WERNIS_ERROR_CODE () {
65 if (isset($WERNIS['status'])) {
67 return $WERNIS['status'];
68 } elseif (isset($WERNIS['status'])) {
69 // Fall-back to status
70 return sprintf(WERNIS_ERROR_STATUS, $WERNIS['status']);
72 // Something bad happend
73 return WERNIS_UNKNOWN_ERROR;
77 // Sends out a request to the API and returns it's result
78 function WERNIS_SEND_REQUEST ($scriptName, $requestData = array()) {
81 // Is the requestData an array?
82 if (!is_array($requestData)) {
85 'status' => "failed_general",
86 'message' => WERNIS_API_REQUEST_DATA_INVALID
90 // Is the API id and MD5 hash there?
91 if ((empty($_CONFIG['wernis_api_id'])) || (empty($_CONFIG['wernis_api_md5']))) {
94 'status' => "failed_general",
95 'message' => WERNIS_API_REQUEST_DATA_MISSING
99 // Construct the request string
100 $requestString = $_CONFIG['wernis_api_url'] . $scriptName."?api_id=".$_CONFIG['wernis_api_id']."&api_key=".$_CONFIG['wernis_api_md5'];
101 foreach ($requestData as $key=>$value) {
102 $requestString .= "&".$key."=".$value;
105 // Get the raw response from the lower function
106 $response = MXCHANGE_OPEN($requestString);
108 // Check the response header if all is fine
109 if (strpos($response[0], "200") === false) {
110 // Something bad happend... :(
112 'status' => "request_eror",
113 'message' => sprintf(WERNIS_API_REQUEST_ERROR, $response[0])
117 // All (maybe) fine so remove the response header from server
118 $response = $response[(count($response) - 1)];
120 // Prepare the returning result for higher functions
121 if (substr($response, 0, 1) == "&") {
122 // Remove the leading & (which can be used in Flash)
123 $response = substr($response, 1);
126 // Bring back the response
127 $data = explode("=", $response);
129 // Default return array (should not stay empty)
132 // We use only the first two entries (which shall be fine)
133 if ($data[0] == "error") {
134 // The request has failed... :(
136 case "AUTH": // Authorization has failed
138 'status' => "auth_failed",
139 'message' => WERNIS_API_REQUEST_FAILED_AUTH
143 case "USER": // Missing account or invalid password
145 'status' => "user_failed",
146 'message' => WERNIS_API_REQUEST_FAILED_USER
150 case "OWN": // Transfer to own account
152 'status' => "own_failed",
153 'message' => WERNIS_API_REQUEST_FAILED_OWN
157 case "AMOUNT": // Amount is depleted
159 'status' => "amount_failed",
160 'message' => WERNIS_API_REQUEST_FAILED_AMOUNT
164 case "AMOUNT-SEND": // API amount is depleted
166 'status' => "api_amount_failed",
167 'message' => WERNIS_API_REQUEST_FAILED_API_AMOUNT
171 default: // Unknown error (maybe new?)
173 'status' => "request_failed",
174 'message' => sprintf(WERNIS_API_REQUEST_FAILED, $data[1])
182 'response' => $response
190 // Tests the function by calling balance.php on the API
191 function WERNIS_TEST_API () {
196 // Return the result from the lower functions
197 $return = WERNIS_SEND_REQUEST("balance.php");
199 if ($return['status'] == "OK") {
203 // Status failture text
204 WERNIS_STATUS_MESSAGE($return['message'], $return['status']);
211 // Widthdraw this amount
212 function WERNIS_EXECUTE_WITHDRAW($userId, $userMd5, $amount) {
216 // Prepare the purpose
217 $eval = "\$purpose = \"".COMPILE_CODE(WERNIS_API_PURPOSE_WITHDRAW)."\";";
220 // Prepare the request data
221 $requestData = array(
222 'sub_request' => "receive",
223 't_uid' => bigintval($userId),
225 'r_uid' => $_CONFIG['wernis_refid'],
226 'amount' => bigintval($amount),
227 'purpose' => urlencode(base64_encode($purpose))
230 // Return the result from the lower functions
231 $return = WERNIS_SEND_REQUEST("book.php", $requestData);
233 if ($return['status'] == "OK") {
237 // Status failture text
238 WERNIS_STATUS_MESSAGE($return['message'], $return['status']);
246 // Payout this amount
247 function WERNIS_EXECUTE_PAYOUT($userId, $userMd5, $amount) {
251 // Prepare the purpose
252 $eval = "\$purpose = \"".COMPILE_CODE(WERNIS_API_PURPOSE_PAYOUT)."\";";
255 // Prepare the request data
256 $requestData = array(
257 'sub_request' => "send",
258 't_uid' => bigintval($userId),
260 'r_uid' => $_CONFIG['wernis_refid'],
261 'amount' => bigintval($amount),
262 'purpose' => urlencode(base64_encode($purpose))
265 // Return the result from the lower functions
266 $return = WERNIS_SEND_REQUEST("book.php", $requestData);
268 if ($return['status'] == "OK") {
272 // Status failture text
273 WERNIS_STATUS_MESSAGE($return['message'], $return['status']);
280 // Translate the status IN/OUT
281 function WERNIS_TRANSFER_STATUS($status) {
283 $return = sprintf(WERNIS_STATUS_UNKNWOWN, $status);
285 case "IN": // Withdraw
286 $return = WERNIS_STATUS_WITHDRAW;
289 case "OUT": // Payout
290 $return = WERNIS_STATUS_PAYOUT;