<?php
/*
###################################################################################
  Bigware Shop 2.3
  Release Datum: 23.08.2015
  
  Bigware Shop
  http://www.bigware.de

  Copyright (c) 2015 Bigware LTD
  (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
  (c) 2015	Bigware LTD

  Copyrightvermerke duerfen nicht entfernt werden.
  ------------------------------------------------------------------------
  Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
  der GNU General Public License, wie von der Free Software Foundation
  veroeffentlicht, weitergeben und/oder modifizieren, entweder gemaess Version 2 
  der Lizenz oder (nach Ihrer Option) jeder spaeteren Version.
  Die Veroeffentlichung dieses Programms erfolgt in der Hoffnung, dass es Ihnen
  von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die
  implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FUER EINEN
  BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
  
  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
  Programm erhalten haben. Falls nicht, schreiben Sie an die Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

  Infos:
  ------------------------------------------------------------------------
  Der Bigware Shop wurde vor vielen Jahren bereits aus dem bekannten Shopsystem osCommerce
  weiter- und neuentwickelt.
  Der Bigware Shop legt im hohen Masse Wert auf Bedienerfreundlichkeit, beinhaltet eine leichte
  Installation, viele neue professionelle Werkzeuge und zeichnet sich aus durch eine grosse 
  Community, die bei Problemen weiterhelfen kann.
  
  Der Bigware Shop ist auf jedem System lauffaehig, welches eine PHP Umgebung
  (ab PHP 4.1.3) und mySQL zur Verfuegung stellt und auf Linux basiert.
 
  Hilfe erhalten Sie im Forum auf www.bigware.de 
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/
$query = "SELECT attendees_name, attendees_street_address,
          attendees_city, delivery_name, delivery_street_address, delivery_city, date_purchased,
	  orders_id, attendees_email_address, attendees_telephone, attendees_id, 
	  attendees_postcode, attendees_land, delivery_postcode, delivery_land,
	  delivery_company, payment_method
          FROM " . DB_TBL_ORDERS . " WHERE orders_id = $oID";
          
$result = go_db_query($query);
$number = go_db_numrows($result);
$i = 0;
$filename ="Action=new&Partnerid=$PartnerID&PartnerPass=$PartnerPass&UserID=$UserID&Lieferanschrift=1";
$query15 = "SELECT title FROM " . DB_TBL_ORDERS_TOTAL . " WHERE orders_id = $oID AND class = 'ot_shipping'";
$result15 = go_db_query($query15);
$number = go_db_numrows($result15);
$query50 = "SELECT delivery_name
          FROM " . DB_TBL_ORDERS . " WHERE orders_id = $oID";
$result50 = go_db_query($query50); 
                $attendees_street_address = @mysqli_result($result,$i,"attendees_street_address");
                $attendees_city = urlencode (@mysqli_result($result,$i,"attendees_city"));
                $attendees_email_address = urlencode (@mysqli_result($result,$i,"attendees_email_address"));
                $attendees_telephone = urlencode (@mysqli_result($result,$i,"attendees_telephone"));
                $attendees_id = urlencode (@mysqli_result($result,$i,"attendees_id"));
                $attendees_postcode = urlencode (@mysqli_result($result,$i,"attendees_postcode"));
                $attendees_land = urlencode (@mysqli_result($result,$i,"attendees_land"));
                $payment_method = urlencode (@mysqli_result($result,$i,"payment_method"));
                if ($result50 == ""){
                $shipping_method = urlencode (@mysqli_result($result15,$i,"title"));
	        }
	        else{
	        $shipping_method = urlencode (@mysqli_result($result50,$i,"delivery_name"));
	        }
		preg_match("/(.*?)([0-9].*)/", $attendees_street_address, $attendees_street_split);
		$attendees_street_split[1] = urlencode ($attendees_street_split[1]);
		$attendees_street_split[2] = urlencode ($attendees_street_split[2]); 
		
		$query2 = "SELECT attendees_firstname, attendees_lastname
			FROM " . DB_TBL_ATTENDEES . " WHERE attendees_id = $attendees_id";
		$result2 = go_db_query($query2);
		$number2 = go_db_numrows($result2);
		if ($number2 != 0){
                	$attendees_firstname = @mysqli_result($result2,0,"attendees_firstname");
                	$attendees_firstname = urlencode ($attendees_firstname);
                	$VorName = $attendees_firstname;
                	$attendees_lastname = @mysqli_result($result2,0,"attendees_lastname");
                	$NachName = $attendees_lastname;
                	$attendees_lastname = urlencode ($attendees_lastname);
		} 
		
		$query3 = "SELECT entry_company FROM " . DB_TBL_DIRECTORY_TO_ADDRESS . " WHERE attendees_id = $attendees_id";
		$result3 = go_db_query($query3);
		$number3 = go_db_numrows($result3);
		if ($number3 != 0){
                	$attendees_company = urlencode (@mysqli_result($result3,0,"entry_company"));
		}
                $delivery_name = @mysqli_result($result,$i,"delivery_name");
                list($versandvorname1,$versandvorname2,$versandnachname1,$versandnachname2)= split (" ", $delivery_name, 4);
		$versandvorname1 = urlencode ($versandvorname1);
		$versandvorname2 = urlencode ($versandvorname2);
		$versandnachname1 = urlencode ($versandnachname1);
		$versandnachname2 = urlencode ($versandnachname2);
		
		if ($versandnachname1 != ""){
		$versandvorname = $versandvorname1."+".$versandvorname2;
		$versandnachname = $versandnachname1."+".$versandnachname2;
			}
		else{
		$versandvorname = $versandvorname1;
		$versandnachname = $versandvorname2."+".$versandnachname1."+".$versandnachname2;
		}
		$delivery_street_address = @mysqli_result($result,$i,"delivery_street_address");
                $delivery_city = urlencode (@mysqli_result($result,$i,"delivery_city"));
                $delivery_postcode = urlencode (@mysqli_result($result,$i,"delivery_postcode"));
                $delivery_land = urlencode (@mysqli_result($result,$i,"delivery_land"));
                $delivery_company = urlencode (@mysqli_result($result,$i,"delivery_company"));
                 
                $query4 = "SELECT lands_iso_code_2 FROM " . DB_TBL_LANDS . " WHERE lands_name = '$delivery_land'";
		$result4 = go_db_query($query4);
                	$delivery_land = urlencode (@mysqli_result($result4,0,"lands_iso_code_2"));
		$query5 = "SELECT lands_iso_code_2 FROM " . DB_TBL_LANDS . " WHERE lands_name = '$attendees_land'";
		$result5 = go_db_query($query5);
                	$attendees_land = urlencode (@mysqli_result($result5,0,"lands_iso_code_2"));
                	
		preg_match("/(.*?)([0-9].*)/", $delivery_street_address, $delivery_street_split);
		$delivery_street_split[1] = urlencode ($delivery_street_split[1]);
		$delivery_street_split[2] = urlencode ($delivery_street_split[2]);
		
                $date_purchased = urlencode (@mysqli_result($result,$i,"date_purchased"));
                $orders_id = urlencode (@mysqli_result($result,$i,"orders_id"));
##############
		$query6 = "SELECT value FROM " . DB_TBL_ORDERS_TOTAL . "  WHERE class = 'ot_cod_fee' AND orders_id = '$orders_id'";
		$result6 = go_db_query($query6);
		$number6 = go_db_numrows($result6);
		if ($number6 != 0){
                	$price_nachnahme  = @mysqli_result($result6,0,"value");
                }
                else{
                	
                	$price_nachnahme  = "";
                }
                
		$query7 = "SELECT value FROM " . DB_TBL_ORDERS_TOTAL . "  WHERE class = 'ot_shipping' AND orders_id = '$orders_id'";
		$result7 = go_db_query($query7);
		$number7 = go_db_numrows($result7);
		if ($number7 != 0){
                	$price_versand  = @mysqli_result($result7,0,"value");
                }
                else{
                	
                	$price_versand  = "";
                }
                
                $gesamtversand = $price_nachnahme+$price_versand;
                $gesamtversand = number_format($gesamtversand, 2, ',', '.');
##############orders_status_history
                	
                $id = go_db_query("SELECT * FROM " . DB_TBL_ORDERS_STATUS_HISTORY . " WHERE orders_id = '$orders_id'");
		while ($werte = go_db_fetch_array($id)){
                	$comments = $werte["comments"];
                	$date_added = $werte["date_added"];
			
			if ($comments != ""){
				$kommentar .= $date_added." = ".$comments."  ";
				$kommentar = urlencode ($kommentar);
			}
		}
                $filename .= "&Kbenutzername=$attendees_email_address&Kanrede=&KFirma=$attendees_company&KVorname=$attendees_firstname&KNachname=$attendees_lastname&KStrasse=$attendees_street_split[1]+$attendees_street_split[2]&KPLZ=$attendees_postcode&KOrt=$attendees_city&Ktelefon=$attendees_telephone&Kfax=&Kemail=$attendees_email_address&KLFirma=$delivery_company&KLand=$attendees_land&KLVorname=$versandvorname&KLNachname=$versandnachname&KLStrasse=$delivery_street_split[1]+$delivery_street_split[2]&KLLand=$delivery_land&KLOrt=$delivery_city&KLPLZ=$delivery_postcode&Zahlart=$payment_method&Versandart=$shipping_method&kommentar=$kommentar&Versandkosten=$gesamtversand"; 
		$query1 = "SELECT items_name, final_price, items_quantity, orders_items_id, items_id, items_tax, items_model
          	FROM " . DB_TBL_ORDERS_ITEMS . " WHERE orders_id=$orders_id";
		$result1 = go_db_query($query1);
		$number1 = go_db_numrows($result1);
		$j = 0;
		$filename .="&PosAnz=$number1";
		IF ($number1 == 0){ 
		}
		elseif ($number1 > 0) {
			while ($j < $number1){
        $items_name = urlencode (@mysqli_result($result1,$j,"items_name"));
        $items_name = preg_replace('/%26/', 'und', $items_name);
        $items_name = urlencode (@mysqli_result($result1,$j,"items_name"));
        $items_price = @mysqli_result($result1,$j,"final_price");
		    $items_tax = @mysqli_result($result1,$j,"items_tax");
        $items_price = $items_price/100*$items_tax+$items_price;
			  $items_tax= preg_replace("/\./",",",$items_tax);
				$brutto = $items_price;
				$items_quantity = urlencode (@mysqli_result($result1,$j,"items_quantity"));
        $orders_items_id = urlencode (@mysqli_result($result1,$j,"orders_items_id"));
        $items_id = urlencode (@mysqli_result($result1,$j,"items_id"));
				$items_model = urlencode (@mysqli_result($result1,$j,"items_model"));
				$items_price = number_format($items_price, 2, ',', '.');
				$items_price = urlencode ($items_price);
			  $price_gesamt = $brutto*$items_quantity;
			  $price_gesamt = number_format($price_gesamt, 2, ',', '.');
			  $price_gesamt = urlencode ($price_gesamt);
			  $items_model= preg_replace("/[^0-9]/","",$items_model);
				$zahl = $j+1;
				$link = urlencode ($Shop_URL . "/" . $GLOBALS[CONFIG_NAME_FILE][main_bigware_34] . "?bigPfad=" . $orders_items_id . "&items_id=" . $items_id);
				$filename .="&ArtikelStammID_$zahl=$items_model&Artikelnr_$zahl=$items_model&Artikelname_$zahl=$items_name&ArtikelEpreis_$zahl=$items_price&ArtikelMwSt_$zahl=$items_tax&ArtikelMenge_$zahl=$items_quantity&ArtikelLink_$zahl=$link&items_id=$orders_items_id&Kundenerkennung=0&Artikelerkennung=0";		
				
				$price_gesamt = urldecode ($price_gesamt);
				$items_quantity = urldecode($items_quantity);
				$items_name = urldecode($items_name);
				$items_price = urldecode($items_price);
$ArtikelListe .= $items_quantity."x ".$items_model." ".$items_name." - Einzelpreis: ".$items_price." Euro - Gesamt:".$price_gesamt." Euro "."
";
				$gesamt_pre = $gesamt_pre + $brutto*$items_quantity;
		                $summe = $price_nachnahme + $price_versand + $gesamt_pre;
                    
                    
                    $j++;
		
			}
		
		}
if ($c_url_vorhanden == "2"){
$filename = preg_replace('/=/', 'EO%%EO', $filename);
$filename = preg_replace('/&/', '%%EOEO', $filename);
$fp = fopen ($_url."?params=".$filename, "r");
$result = fread($fp, 10000);  
   $result = preg_replace('/\r\n|\r|\n/', ' ', $result);
   $elemente_1 = explode("<KundenNr>",$result);
   $elemente_2 = explode("</KundenNr>",$elemente_1[1]);
   $elemente_3 = explode("<success>",$result);
   $elemente_4 = explode("</success>",$elemente_3[1]);
   $elemente_5 = explode("<errorlist>",$result);
   $elemente_6 = explode("</errorlist>",$elemente_5[1]);
   $elemente_7 = explode("<UID>",$result);
   $elemente_8 = explode("</UID>",$elemente_7[1]);
   $Kundennummer = $elemente_2[0];
   $success = $elemente_4[0];
   $errorlist = $elemente_6[0];
   $uid = $elemente_8[0];
}
elseif ($c_url_vorhanden == "3"){
$filename = preg_replace('/=/', 'EO%%EO', $filename);
$filename = preg_replace('/&/', '%%EOEO', $filename);
$fp = fopen ($_url_2."?params=".$filename, "r");
$result = fread($fp, 10000);  
   $result = preg_replace('/\r\n|\r|\n/', ' ', $result);
   $elemente_1 = explode("<KundenNr>",$result);
   $elemente_2 = explode("</KundenNr>",$elemente_1[1]);
   $elemente_3 = explode("<success>",$result);
   $elemente_4 = explode("</success>",$elemente_3[1]);
   $elemente_5 = explode("<errorlist>",$result);
   $elemente_6 = explode("</errorlist>",$elemente_5[1]);
   $elemente_7 = explode("<UID>",$result);
   $elemente_8 = explode("</UID>",$elemente_7[1]);
   $Kundennummer = $elemente_2[0];
   $success = $elemente_4[0];
   $errorlist = $elemente_6[0];
   $uid = $elemente_8[0];
   }
elseif ($c_url_vorhanden == "1"){
   $defined_vars = get_defined_vars();
   $params = "$filename";
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,$curl_url);   
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);   
	curl_setopt($ch, CURLOPT_POST, 1);   
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
	$result = curl_exec($ch);
	curl_close ($ch);
   $result = preg_replace('/\r\n|\r|\n/', ' ', $result);
   $elemente_1 = explode("<KundenNr>",$result);
   $elemente_2 = explode("</KundenNr>",$elemente_1[1]);
   $elemente_3 = explode("<success>",$result);
   $elemente_4 = explode("</success>",$elemente_3[1]);
   $elemente_5 = explode("<errorlist>",$result);
   $elemente_6 = explode("</errorlist>",$elemente_5[1]);
   $elemente_7 = explode("<UID>",$result);
   $elemente_8 = explode("</UID>",$elemente_7[1]);
   $Kundennummer = $elemente_2[0];
   $success = $elemente_4[0];
   $errorlist = $elemente_6[0];
   $uid = $elemente_8[0];
}
   
?>