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 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 // Sends out a request to the API and returns it's result
63 function WERNIS_SEND_REQUEST ($scriptName, $requestData = array()) {
66 // Is the requestData an array?
67 if (!is_array($requestData)) {
70 'status' => "failed_general",
71 'message' => WERNIS_API_REQUEST_DATA_INVALID
75 // Is the API id and MD5 hash there?
76 if ((empty($CONFIG['wernis_api_id'])) || (empty($CONFIG['wernis_api_md5']))) {
79 'status' => "failed_general",
80 'message' => WERNIS_API_REQUEST_DATA_MISSING
84 // Construct the request string
85 $requestString = $CONFIG['wernis_api_url'] . $scriptName."?api_id=".$CONFIG['wernis_api_id']."&api_key=".$CONFIG['wernis_api_md5'];
86 foreach ($requestData as $key=>$value) {
87 $requestString .= "&".$key."=".$value;
90 // Get the raw response from the lower function
91 $response = MXCHANGE_OPEN($requestString);
93 // Check the response header if all is fine
94 if (strpos($response[0], "200") === false) {
95 // Something bad happend... :(
97 'status' => "request_eror",
98 'message' => sprintf(WERNIS_API_REQUEST_ERROR, $response[0])
102 // All (maybe) fine so remove the response header from server
103 $response = $response[(count($response) - 1)];
105 // Prepare the returning result for higher functions
106 if (substr($response, 0, 1) == "&") {
107 // Remove the leading & (which can be used in Flash)
108 $response = substr($response, 1);
111 // Bring back the response
112 $data = explode("=", $response);
114 // Default return array (should not stay empty)
117 // We use only the first two entries (which shall be fine)
118 if ($data[0] == "error") {
119 // The request has failed... :(
121 case "AUTH": // Authorization has failed
123 'status' => "auth_failed",
124 'message' => WERNIS_API_REQUEST_FAILED_AUTH
128 default: // Unknown error (maybe new?)
130 'status' => "request_failed",
131 'message' => sprintf(WERNIS_API_REQUEST_FAILED, $data[1])
139 'response' => $response
147 // Tests the function by calling balance.php on the API
148 function WERNIS_TEST_API () {
153 // Return the result from the lower functions
154 $return = WERNIS_SEND_REQUEST("balance.php");
156 if ($return['status'] == "OK") {
160 // Status failture text
161 WERNIS_STATUS_MESSAGE($return['message'], $return['status']);