]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/primera_functions.php
Rewrote 'we' word a little, rewrote mail order to use SQL_INSERTID() instead of anoth...
[mailer.git] / inc / libs / primera_functions.php
index 1d19c960a73467df51e8830c879fd9120f4c96ec..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,282 +1,3 @@
 <?php
-/**
- * PrimeraApi
- * -------------------------------------------
- * Mit dieser Klasse ist ein einfacher Primeratransfer von Ihrem Account
- * zu dem Account eines bei Primusportal.de registrierten Mitglieds möglich.
- *
- *------------------ Aenderungen durch Roland Haeder 09.08.2008 ----------------
- * Klasse umbenannt nach PrimeraApi, damit sie in das Framework besser passt.
- * Zudem sind alle oeffentlichen Attribute nun privat, der Konstruktor hat den
- * neuen "magischen" Namen __construct() und "normale" Konstanten sind nach
- * Klassenkonstanten umbenannt. Unsinnige else-Bloecke sind noch umgewandelt.
- * Methodennamen fangen nun immer mit einem kleinen Buchstaben an. Zudem sind
- * die Methoden Pay,Query und Parse umbenannt.
- *------------------ Aenderungen durch Roland Haeder 09.08.2008 ----------------
- *
- * Die Einbindung des Interfaces geschieht folgendermaßen:
- *  1. Einbindung der Klasse in Ihr PHP-Auszahlungsskript:
- *     CODE:
- *       require_once( "PFAD/ZU/DER/KLASSE/PrimeraApi.class.php" );
- *       $PPUsername = "username"; // Ihr Username bei Primusportal
- *       $PPPassword = "passwort"; // Ihr Passwort bei Primusportal
- *
- *       $Interface = new PrimeraApi($PPUsername, $PPPassword);
- *  2. Durchführen einer Auszahlung:
- *     CODE:
- *       $Status = $Interface->payPrimera($PayReceiver, $PayAmount, $PayDescription);
- *
- *     Wobei $PayReicer der Username des Empfängers bei
- *     Primusportal.de ist. $PayAmount ist der gerundete( !! ) Betrag an Primera,
- *     die der Empfänger erhalten soll. $PayDescription ist eine von Ihnen 
- *     festgelegte kurze Beschreibung. Die Länge dieses Textes darf 100 Zeichen
- *     nicht überschreiten. Beispiel:
- *       $status = $Interface->payPrimera("garbage", 10000, "Auszahlung IhreSeite.de - ID: 12345");
- *  3. Überprüfung des Status (Rückgabecode):
- *     CODE:
- *       if (!$status) {
- *         // Ein Fehler ist aufgetreten
- *     // Fehlerbehandlung hier einfügen...
- *       }else {
- *         // Auszahlung erfolgreich durchgeführt
- *         // Führen Sie hier Ihre Datenbankabfragen durch, um die Auszahlung zu
- *         // bestätigen...
- *       }
- *
- *     Die komplette Rückgabe des Interfaces wird als assoziatives Array in der Klassen-
- *     variable __data gespeichert:
- *     __data => array("status" => Rückgabecode (PI_DONE, PI_SENDER_ERROR, ...),
- *                     "statustext" => Status in Worten (z.B.: "Transaktion erfolgreich durchgeführt"),
- *                     ")
- *
- *
- * @author             Andreas Schmidt <xxgarbagexx@web.de>
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            1.0 - beta
- * @copyright  (c) 2007 by Primusportal.de
- * @copyright  (c) 2008 by Roland Haeder
- */
-class PrimeraApi {
-       /**
-        * Fehler - Interfacebenutzer
-        */
-       const PI_ERROR = -1;
-
-       /**
-        * Statuscode für erfolgreich ausgeführte Transaktion
-        */
-       const PI_DONE = 200;
-
-       /**
-        * Fehler - User existiert nicht oder ist gesperrt
-        */
-       const PI_RECEIVER_ERROR = 301;
-
-       /**
-        * Sender-Account Fehler (User nicht existent, gesperrt, ...)
-        */
-       const PI_SENDER_ERROR = 401;
-
-       /**
-        * Betrag fehler
-        */
-       const PI_AMOUNT_ERROR = 501;
-
-       /**
-        * Zu wenig Primera
-        */
-       const PI_TOO_LESS_PRIMERA = 502;
-
-       /**
-        * User nicht aktiv oder existiert nicht
-        */
-       const PI_USER_CHECK_ERROR = 601;
-
-       /**
-        * User aktiv
-        */
-       const PI_USER_CHECK_OK = 602;
-
-       /**
-        * Primerastand erfolgreich geholt
-        */
-       const PI_GET_PRIMERA_DONE = 701;
-
-       /**
-        * URL für das Interface auf dem Primusserver:
-        */
-       var $host = "http://www.primusportal.de";
-       var $path = "/transfer.interface.2.0.php";
-
-       var $errno = 0;
-       var $err = "";
-
-       var $seperator = ":";
-
-       var $username = "";
-       var $password = "";
-
-       var $data = array();
-
-       var $headers = "";
-
-       /**
-        * Konstruktor
-        */
-       function PrimeraApi ($PPUsername, $PPPassword) {
-               // Set data
-               $this->username = $PPUsername;
-               $this->password = $PPPassword;
-       }
-
-       /**
-        * Anfrage senden und Rückgabecode in Variable speichern
-        */
-       function queryApi ( $data = array() ) {
-               // Base64-encode username and password hash
-               $data["PrimusInterface_Username"] = base64_encode($this->username);
-               $data["PrimusInterface_Password"] = base64_encode($this->password);
-
-               // Send POST request
-               $return = POST_URL($this->host.$this->path, $data);
-
-               // Convert the array into a full string
-               $returnStr = implode("\n", $return);
-
-               // Extract the real content, strip header away
-               $content = explode("<!-- return-start -->", $returnStr);
-
-               // Store headers away for debugging
-               $this->headers = $content[0];
-
-               // Return the content
-               return $content[1];
-       }
-
-       /**
-        * Funktion parst die Rückgabe vom Transferskript:
-        */
-       function parseContent ( $content ) {
-               $x = explode("\n", $content);
-               $return = array();
-               foreach($x as $currentLine) {
-                       $line_exploded = explode(":", $currentLine,2);
-                       if (count($line_exploded) > 1) {
-                               $return[$line_exploded[0]] = $line_exploded[1];
-                       }
-               }
-               return $return;
-       }
-
-       /**
-        * @param int/string $Receiver UserID / Username des Empfängers
-        * @param int $Amount Betrag in ganzzahligen Primera
-        * @param string $Description Beschreibung (Sichtbar in Einzelauflistung)
-        */
-       function payPrimera ($Receiver, $Amount, $Description = "") {
-               $valid = false;
-               $postData = array("PrimusInterface_Action" => "Pay",
-                       "PrimusInterface_Receiver" => base64_encode($Receiver),
-                       "PrimusInterface_Amount" => base64_encode($Amount),
-                       "PrimusInterface_Description" => base64_encode($Description) );
-
-               $postReturn = $this->parseContent( $this->queryApi($postData) );
-
-               $this->data = $postReturn;
-               if ($postReturn["status"] == "200") {
-                       $valid = true;
-               }
-               return $valid;
-       }
-
-       /**
-        * Überprüft den Status eines Primus-Users
-        * - existiert der User
-        * - ist er aktiv
-        * @param string/int $User Userid / Username
-        */
-       function CheckPrimusUser($User) {
-               $valid = false;
-               $postData = array("PrimusInterface_Action"=> "CheckPrimusUser",
-                       "PrimusInterface_CheckPrimusUser" => $User);
-
-               $postReturn = $this->parseContent( $this->queryApi($postData) );
-
-               $this->data = $postReturn;
-
-               if ($postReturn["status"] == self::PI_USER_CHECK_OK) {
-                       $valid = true;
-               }
-               return $valid;
-       }
-
-       /**
-        * Die Funktion liefer den aktuellen Primerastand
-        */
-       function getPrimera() {
-               $primera = false;
-               $postData = array( "PrimusInterface_Action" => "GetPrimera" );
-               $postReturn = $this->parseContent( $this->queryApi($postData) );
-
-               $this->data = $postReturn;
-               if ($postReturn["status"] == self::PI_GET_PRIMERA_DONE) {
-                       $primera = $postReturn["primera"];
-               }
-               return $primera;
-       }
-       /**
-        * Getter fuer data
-        */
-       function getData () {
-               return $this->data;
-       }
-}
-
-// Function to test the Primera API by getting the amount. If the returned value
-// is not false the API data is valid, else invalid
-function PRIMERA_TEST_API () {
-       // Get new instance
-       $api = new PrimeraApi($_POST['primera_api_name'], $_POST['primera_api_md5']);
-
-       // Was that fine?
-       return ($api->getPrimera() !== false);
-}
-// Execute the withdraw of a sponsor only!
-function PRIMERA_EXECUTE_WITHDRAW ($primusNick, $userMd5, $amount) {
-       global $_CONFIG;
-
-       // Is the sponsor extension installed?
-       if (!EXT_IS_ACTIVE("sponsor")) {
-               // No, abort here
-               return false;
-       } elseif (!IS_SPONSOR()) {
-               // No sponsor, not allowed to withdraw!
-               return false;
-       }
-
-       // Get new instance
-       $api = new PrimeraApi($primusNick, $userMd5);
-
-       // Prepare purpose
-       $eval = "\$purpose = \"".COMPILE_CODE(sprintf(PRIMERA_API_PURPOSE_WITHDRAW, $_COOKIE['sponsorid']))."\";";
-       eval($eval);
-
-       // Pay the Primera
-       return $api->payPrimera($primusNick, $amount, $purpose);
-}
-// Execute the payout
-function PRIMERA_EXECUTE_PAYOUT ($primusNick, $userMd5, $amount) {
-       global $_CONFIG;
-
-       // Get new instance
-       $api = new PrimeraApi($_CONFIG['primera_api_name'], $_CONFIG['primera_api_md5']);
-
-       // Prepare purpose
-       $eval = "\$purpose = \"".COMPILE_CODE(sprintf(PRIMERA_API_PURPOSE_PAYOUT, $GLOBALS['userid']))."\";";
-       eval($eval);
-
-       // Pay the Primera
-       return $api->payPrimera($primusNick, $amount, $purpose);
-}
-// [EOF]
+// @DEPRECATED
 ?>