<?
class connector {
// Connection Variables
private $id_user = "";
private $api_user = "";
private $api_code = "";
private $api_shop_id = "";
private $language = "";
private $root = ""; // The API to connect to
protected $debug = false; // Aktiviert Debug Ausgaben für URL-Check
// Request URL to Nephele XML
private $request_url = "";
// Contructor to set up the api #############################################################
function __construct($id_user,$api_user,$api_code,$api_shop_id,$language="DE") {
$this->root = "https://nephele-s4.de/xml/v14.0/wbo-API.php";
if($id_user!="" && $api_user !="" && $api_code!="" && $api_shop_id!="") {
$this->id_user = trim($id_user);
$this->api_user = trim($api_user);
$this->api_code = trim($api_code);
$this->api_shop_id = trim($api_shop_id);
$this->language = trim($language);
$this->request_url = $this->root."?UID=".$this->id_user."&apiUSER=".$this->api_user."&apiCODE=".$this->api_code."&apiShopID=".$this->api_shop_id."&apiACTION=";
return true;
} else {
return false;
}
}
//Getter####################################################################################
function getShopConfig(){
$url = $this->request_url."getEinstellungen";
$result = $this->perform_xml_request($url);
return $result;
}
function getGutscheine(){
$url = $this->request_url."getGutscheine";
$result = $this->perform_xml_request($url);
return $result;
}
// get wine information data
function getWeinDetail($weinnr) {
$url = $this->request_url."getWineDetail&weinnr=".trim($weinnr);
$result = $this->perform_xml_request($url);
return $result->item;
/* RETURN VALUE
$artikel_nr = $element->artikel_nr;
$artikel_name = $element->artikel_name;
$artikel_beschreibung = $element->artikel_beschreibung;
$artikel_shopnotiz = $element->artikel_shopnotiz;
$artikel_jahrgang = $element->artikel_jahrgang;
$artikel_sorte = $element->artikel_sorte;
$artikel_qualitaet = $element->artikel_qualitaet;
$artikel_geschmack = $element->artikel_geschmack;
$artikel_zucker = $element->artikel_zucker;
$artikel_alkohol = $element->artikel_alkohol;
$artikel_saeure = $element->artikel_saeure;
$artikel_liter = $element->artikel_liter;
$artikel_gewicht = $element->artikel_gewicht;
$artikel_bild = $element->artikel_bild;
$artikel_preis = $element->artikel_preis;
$artikel_literpreis = $element->artikel_literpreis;
*/
}
// Get categories for the shop with displayable content
function getShopMenue() {
$url = $this->request_url."getWineGroups";
return $this->perform_xml_request($url);
// RETURN VALUE: Array with Objects
/*
$element->id_grp; // ID der Kategorie -> Für getWineList
$element->grp_name; // Name der Kategorie
*/
}
// Get AGB from WBO
function getAGB() {
$url = $this->request_url."getAGB";
return $this->perform_xml_request($url);
// RETURN VALUE: String
}
// Get List of Wines -> group_id=0 gets all wines // Suchstring für Einschränkungen
function getWineList($group_id,$suchstring=false) {
$url = $this->request_url."getWines&id_grp=".$group_id."&suchstring=".$suchstring;
$url = $this->decode_url($url);
return $this->perform_xml_request($url);
// RETURN VALUE: Array with elements of type getWeinDetail()
}
// Send data ##################################################################################
// Do a new Order
function sendOrder($firma,$name,$nname,$email,$street,$number,$zip,$city,$country,$phone,$l_city,$l_hnumber,$l_adr,$l_anr,$l_company,$l_vorname,$l_name,$l_street,$l_zip,$l_country,$payment,$note,$positions,$array,$versandkosten,$ktname,$ktblz,$ktnr,$gebuehr,$ktiban,$ktbic,$anrede,$paypal_transaction_id,$gutscheincode,$gutscheinwert) {
// $array needs amount and id informations -> Array([&wein_anzahl1=5&wein_id1=12],[&wein_anzahl2=3...)
$url = $this->request_url."newOrder";
// General adress information
$url .= "&anrede=$anrede";
$url .= "&name=$name";
$url .= "&nname=$nname";
$url .= "&email=$email";
$url .= "&strasse=$street";
$url .= "&hnr=$number";
$url .= "&plz=$zip";
$url .= "&ort=$city";
$url .= "&land=$country";
$url .= "&telefon=$phone";
$url .= "&firma=$firma";
$url .= "&zahlung=$payment";
// alternate adress information for seperate shipping
$url .= "&l_adr =$l_adr";
$url .= "&l_anrede=$l_anr";
$url .= "&l_firma=$l_company";
$url .= "&l_vorname=$l_vorname";
$url .= "&l_name=$l_name";
$url .= "&l_strasse=$l_street";
$url .= "&l_plz=$l_zip";
$url .= "&l_ort=$l_city";
$url .= "&l_land=$l_country";
$url .= "&l_hnummer=$l_hnumber";
$url .= "&kto=".$ktnr;
$url .= "&ktoInh=".$ktname;
$url .= "&blz=".$ktblz;
$url .= "&iban=".$ktiban;
$url .= "&bic=".$ktbic;
$url .= "&gutscheincode=".$gutscheincode;
$url .= "&gutscheinwert=".$gutscheinwert;
// Payment
if($payment == "Vorkasse") $url .= "&zahlung=2";
else if($payment == "Rechnung")$url .= "&zahlung=1";
else if($payment== "Bar")$url .= "&zahlung=2";
else if($payment == "Nachnahme")$url .= "&zahlung=4";
else if($payment == "Bankeinzug")$url .= "&zahlung=3";
else if($payment == "PayPal")$url .= "&zahlung=4";
// Nachnahmegebühr
$url .= "&gebuehr=$gebuehr";
// Note
$note = preg_replace('/\\r/', ' ', $note); // Umbrüche entfernen
$note = preg_replace('/\\n/', ' ', $note);
if($paypal_transaction_id!="") {
$note.="
Paypal transaction ID: ".$paypal_transaction_id;
}
$url .= "&referenz=$note";
// versandkosten
$url.="&versandkosten=$versandkosten";
// Number of positions
$url .= "&positionen=$positions";
$url .=implode("",$array);
// perfom request
$url = $this->decode_url($url);
$xml = $this->perform_xml_request($url);
// Analyze Result
if($xml->status == "ok") {
return true;
} else {
return false;
}
}
// General Function ########################################################################
// Prepare a URL for a XML request
function decode_url ($url) {
$lcSearch = Array(
"#",
"+",
"ä",
"Ä",
"ö",
"Ö",
"ü",
"Ü",
"ß",
" "
);
$lcReplace = Array(
"",
"%2b",
"%E4",
"%C4",
"%F6",
"%D6",
"%FC",
"%DC",
"%DF",
"%20"
);
return str_replace($lcSearch,$lcReplace,$url);
}
// Perform a XML Request
function perform_xml_request($url){
$url = $this->decode_url($url);
########################
if($this->debug) {
?>
<div style="position:relative; height:220px; width:400px; background-color:#f00; color:#fff; float:right; left:800px;;">
<? echo $url; ?>
</div>
<?
}
#######################
// Connect to URL
$auftrag = @fopen($url, "r") or die ("Fehler194");
$antwort = "";
while(!feof($auftrag)){ $antwort .= fgets($auftrag) or die("Fehler 196"); }
fclose($auftrag);
// Convert Information Data
$xml = simplexml_load_string($antwort) or die("Fehler #01: Kein wohlgeformtes XML gefunden. $url -> $antwort");
########################
if($this->debug) {
?>
<div style="position:relative; height:220px; width:400px; background-color:#0f0; color:#fff; float:right; left:800px;;">
<? print_r ($antwort); ?>
</div>
<?
}
#######################
// Return Element
return $xml;
}
}
?>
|