Projekt

Allgemein

Profil

GX-Bug #40306 » afterbuy.php

/includes/classes/afterbuy.php - Till Tepelmann, 09.09.2014 13:04

 
1
<?php
2
/* -----------------------------------------------------------------------------------------
3
 $Id: afterbuy.php 1287 2005-10-07 10:41:03Z mz $
4

    
5
 modified by F.T.Store (FTS) 2007-08-156 20:07 FTS
6
 Version 1.8 (August 2007)
7

    
8
 mickser
9
 Modifikation:
10
 2008 	Bei vorhandener Attribut-Artikelnummer diese f?r die ?bertragung verwenden
11
 2009 	urlencode statt ereg_replace
12
 		Zahlungsstatus iPayment
13
		Auswertung Afterbuy-Daten (UID,AID etc.) und eintragen in DB
14
 2010   getCurrency und getCustomerstatustax ausgelagert (unn?tige mehrfach-DB-Anfragen)
15
 XT-Commerce - community made shopping
16
 http://www.xt-commerce.com
17

    
18
 Copyright (c) 2003 XT-Commerce
19
 -----------------------------------------------------------------------------------------
20
 based on:
21
 (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
22
 (c) 2002-2003 osCommerce(Coding Standards); www.oscommerce.com
23

    
24
 Released under the GNU General Public License
25
 ---------------------------------------------------------------------------------------*/
26

    
27
class xtc_afterbuy_functions_ORIGIN {
28
	var $order_id;
29
	var $payment_id;
30
	var $payment_name;
31
	var $paid;
32
	// constructor
33
	function xtc_afterbuy_functions_ORIGIN($order_id) {
34
		$this->order_id = $order_id;
35
	}
36

    
37
	function process_order() {
38

    
39
		require_once (DIR_FS_INC.'xtc_get_attributes_model.inc.php');
40
		require_once("xmlparserv4.php");
41
		$this->paid = 0;
42

    
43
		// ############ SETTINGS ################
44
		//Daten im XT Admin (werden von Afterbuy mitgeteilt)
45
		$PartnerID = AFTERBUY_PARTNERID;
46
		$PartnerPass = AFTERBUY_PARTNERPASS;
47
		$UserID = AFTERBUY_USERID;
48
		$order_status = AFTERBUY_ORDERSTATUS;
49

    
50
		// ############ THUNK ################
51

    
52
		$oID = $this->order_id;
53
		$customer = array ();
54
		$afterbuy_URL = 'https://api.afterbuy.de/afterbuy/ShopInterface.aspx';
55

    
56
		//***************************************************************************************************************************************//
57
		//settings:
58
		$verwende_shop_artikelnummer = 0;
59
		// 0 = Artikelnummer
60
		// 1 = interne products_id (DB-ID)
61
		// 2 = Afterbuy Produkt-ID (wenn vorhanden, in ?lteren AfterbuyImportSchnittstellenversionen nicht verwenden)
62
		
63
		$paypalexpress = 0;
64
		$moneybookers = 0;
65

    
66
		$feedbackdatum = '0';
67
		//0= Feedbackdatum setzen und KEINE automatische Erstkontaktmail versenden
68
		//1= KEIN Feedbackdatum setzen, aber automatische Erstkontaktmail versenden (Achtung: Kunde m?sste Feedback durchlaufen wenn die Erstkontakt nicht angepasst wird!)
69
		//2= Feedbackdatum setzen und automatische Erstkontaktmail versenden (Achtung: Erstkontaktmail muss mit Variablen angepasst werden!)
70

    
71
		$versandermittlung_ab = 1;
72
		// 1 = Versand aus XT
73
		// 0 = Versandermittlung durch Afterbuy (nur wennStammartikel erkannt wird!)
74
		
75
		$kundenerkennung = '1';
76
		// 0=Standard EbayName (= gesamte Zeile "Benutzername" in dieser Datei)
77
		// 1=Email
78
		// 2=EKNummer (wenn im XT vorhanden!)
79

    
80
		// ############# ARTIKELERKENNUNG SETZEN #############
81
		// modified FT
82
		$Artikelerkennung = '1';
83
		// 0 = Product ID (p_Model XT muss gleich Product ID Afterbuy sein)
84
		// 1 = Artikelnummer (p_Model XT muss gleich Arrikelnummer Afterbuy sein)
85
		// 2 = EAN (p_Model XT muss gleich EAN Afterbuy sein)
86
		// sollen keine Stammartikel erkannt werden, muss die Zeile: $DATAstring .= "Artikelerkennung=" . $Artikelerkennung ."&";  gel?scht werden
87
		// sollen keine Stammartikel erkannt werden, muss die Zeile: $Artikelerkennung = '1';  gel?scht werden
88

    
89
		//***************************************************************************************************************************************//
90
		
91
		// connect
92
		$ch = curl_init();
93

    
94
		// This is the URL that you want PHP to fetch. You can also set this option when initializing a session with the curl_init()  function.
95
		curl_setopt($ch, CURLOPT_URL, "$afterbuy_URL");
96

    
97
		// curl_setopt($ch, CURLOPT_CAFILE, 'D:/curl-ca.crt');
98
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
99
		//bei einer leeren Transmission Error Mail + cURL Problemen die n?chste Zeile auskommentieren
100
		//curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
101

    
102
		// Set this option to a non-zero value if you want PHP to do a regular HTTP POST. This POST is a normal application/x-www-form-urlencoded  kind, most commonly used by HTML forms.
103
		curl_setopt($ch, CURLOPT_POST, 1);
104

    
105
		// get order data
106
		$o_query = xtc_db_query("SELECT * FROM ".TABLE_ORDERS." WHERE orders_id='".$oID."'");
107
		$oData = xtc_db_fetch_array($o_query);
108

    
109
		// ############CUSTOMERS ADRESS################
110
		// modified FT (Neuer Parameter ?bergabe der 2.Adresszeile)
111

    
112
		$customer['id'] = $oData['customers_id'];
113
		$customer['firma'] = urlencode($oData['billing_company']);
114
		$customer['vorname'] = urlencode($oData['billing_firstname']);
115
		$customer['nachname'] = urlencode($oData['billing_lastname']);
116
		$customer['strasse'] = urlencode($oData['billing_street_address']);
117
		$customer['strasse2'] = urlencode($oData['billing_suburb']);
118
		$customer['plz'] = $oData['billing_postcode'];
119
		$customer['ort'] = urlencode($oData['billing_city']);
120
		$customer['tel'] = $oData['customers_telephone'];
121
		$customer['fax'] = "";
122
		$customer['mail'] = $oData['customers_email_address'];
123
		// get ISO code
124
		$ctr_query=xtc_db_query("SELECT countries_iso_code_2 FROM ".TABLE_COUNTRIES." WHERE  countries_name='".$oData['customers_country']."'");
125
		$crt_data=xtc_db_fetch_array($ctr_query);
126
		$customer['land']=$crt_data['countries_iso_code_2'];
127

    
128
		// ############ VAT_ID ################
129

    
130
		$ustid_querystrg="SELECT customers_vat_id, customers_status FROM ".TABLE_CUSTOMERS." WHERE customers_id ='".$customer['id']."'";
131
		$ustid_query=xtc_db_query($ustid_querystrg);
132
		$ustid_data=xtc_db_fetch_array($ustid_query);
133
		$customer['ustid']=$ustid_data['customers_vat_id'];
134

    
135
		// ############ CUSTOMERS ANREDE ################
136

    
137
		$c_query = xtc_db_query("SELECT customers_gender FROM ".TABLE_CUSTOMERS." WHERE customers_id='".$customer['id']."'");
138
		$c_data = xtc_db_fetch_array($c_query);
139
		switch ($c_data['customers_gender']) {
140
			case 'm' :
141
				$customer['gender'] = 'Herr';
142
				break;
143
			case 'f' :
144
				$customer['gender'] = 'Frau';
145
				break;
146
			default :
147
				$customer['gender'] = '';
148
				break;
149
		}
150

    
151
		// ############ DELIVERY ADRESS ################
152
		// modified FT (Neuer Parameter ?bergabe der 2.Adresszeile)
153

    
154
		$customer['d_firma'] = urlencode(preg_replace("/&/","%26",$oData['delivery_company']));
155
		$customer['d_vorname'] = urlencode($oData['delivery_firstname']);
156
		$customer['d_nachname'] = urlencode($oData['delivery_lastname']);
157
		$customer['d_strasse'] = urlencode($oData['delivery_street_address']);
158
		$customer['d_strasse2'] = urlencode($oData['delivery_suburb']);
159
		$customer['d_plz'] = $oData['delivery_postcode'];
160
		$customer['d_ort'] = urlencode($oData['delivery_city']);
161
		// get ISO code
162
		$ctr_query=xtc_db_query("SELECT countries_iso_code_2 FROM ".TABLE_COUNTRIES." WHERE  countries_name='".$oData['delivery_country']."'");
163
		$crt_data=xtc_db_fetch_array($ctr_query);
164
		$customer['d_land']=$crt_data['countries_iso_code_2'];
165

    
166
		// ############# KUNDENERKENNUNG SETZEN #############
167
		// Modifiziert FT
168

    
169
		$DATAstring .= "Kundenerkennung=" . $kundenerkennung . "&";
170

    
171
		// ############ GET PRODUCT RELATED TO ORDER / INIT GET STRING ################
172
		// modified FT (Leerzeichen)
173

    
174
		$p_query = xtc_db_query("SELECT * FROM ".TABLE_ORDERS_PRODUCTS." WHERE orders_id='".$oID."'");
175
		$p_count = xtc_db_num_rows($p_query);
176
		$DATAstring .= "Action=new&";
177
		$DATAstring .= "PartnerID=".$PartnerID."&";
178
		$DATAstring .= "PartnerPass=".$PartnerPass."&";
179
		$DATAstring .= "UserID=".$UserID."&";
180
		$DATAstring .= "Kbenutzername=".$customer['id']."_XTC_".$oID."&";
181
		#oder
182
		#$DATAstring .= "Kbenutzername=".$customer['mail']."_XTC_".$oID."&";
183
		$DATAstring .= "Kanrede=".$customer['gender']."&";
184
		$DATAstring .= "KFirma=".$customer['firma']."&";
185
		$DATAstring .= "KVorname=".$customer['vorname']."&";
186
		$DATAstring .= "KNachname=".$customer['nachname']."&";
187
		$DATAstring .= "KStrasse=".$customer['strasse']."&";
188
		$DATAstring .= "KStrasse2=" . $customer['strasse2'] . "&";
189
		$DATAstring .= "KPLZ=".$customer['plz']."&";
190
		$DATAstring .= "KOrt=".$customer['ort']."&";
191
		$DATAstring .= "KTelefon=".$customer['tel']."&";
192
		$DATAstring .= "Kfax=&";
193
		$DATAstring .= "Kemail=".$customer['mail']."&";
194
		$DATAstring .= "KLand=".$customer['land']."&";
195
		
196
		
197
		// ############# LIEFERANSCHRIFT SETZEN #############
198
		// Modifiziert FT (Neuer Parameter ?bergabe der 2.Adresszeile)
199
		// hier wird die Rechnungs-und Lieferanschrift verglichen, wenn die Adressen gleich sind, wird kein "L" in der ?bersicht gesetzt
200
		// soll generell ein "L" in der ?bersicht gesetzt werden, m?ssen die $DATAStrings "Lieferanschrift=1&" sein
201
			
202
		if( ($customer['firma']    == $customer['d_firma']) &&
203
		($customer['vorname']  == $customer['d_vorname']) &&
204
		($customer['nachname'] == $customer['d_nachname']) &&
205
		($customer['strasse']  == $customer['d_strasse']) &&
206
		($customer['strasse2'] == $customer['d_strasse2']) &&
207
		($customer['plz']      == $customer['d_plz']) &&
208
		($customer['ort']      == $customer['d_ort']))
209
		{
210
			$DATAstring .= "Lieferanschrift=0&";
211
		}
212
		else
213
		{
214
			$DATAstring .= "Lieferanschrift=1&";
215
			$DATAstring .= "KLFirma=".$customer['d_firma']."&";
216
			$DATAstring .= "KLVorname=".$customer['d_vorname']."&";
217
			$DATAstring .= "KLNachname=".$customer['d_nachname']."&";
218
			$DATAstring .= "KLStrasse=".$customer['d_strasse']."&";
219
			$DATAstring .= "KLStrasse2=".$customer['d_strasse2']."&";
220
			$DATAstring .= "KLPLZ=".$customer['d_plz']."&";
221
			$DATAstring .= "KLOrt=".$customer['d_ort']."&";
222
			$DATAstring .= "KLLand=".$customer['d_land']."&";
223
		}
224
		
225
		$DATAstring .= "UsStID=".$customer['ustid']."&";
226
		$DATAstring .= "VID=".$oID."&";
227

    
228
		// ############# H?NDLERMARKIERUNG AFTERBUY KUNDENDATENSATZ #############
229
		// Modifiziert FT
230
		// "H" Kennzeichnung im Kundendatensatz in Afterbuy
231
		// "Haendler=0&" bedeutet Checkbox deaktiviert
232
		// "Haendler=1&" bedeutet Checkbox aktiviert
233
		// "case 'X'" steht f?r die jeweilige Kundengruppen_ID im XT (-->siehe Admin)
234

    
235
		$customer_status = $ustid_data['customers_status'];
236
		switch ($customer_status) 
237
		{
238
			case '0': //Admin
239
				$DATAstring .= "Haendler=0&";
240
				break;
241
			case '1': //Gast
242
				$DATAstring .= "Haendler=0&";
243
				break;
244
			case '2': //Kunde
245
				$DATAstring .= "Haendler=0&";
246
				break;
247
			case '3': //im Standard B2B
248
				$DATAstring .= "Haendler=1&";
249
				break;
250
			case '4': //eigene Kundengruppe
251
				$DATAstring .= "Haendler=0&";
252
				break;
253
			case '5': //eigene Kundengruppe
254
				$DATAstring .= "Haendler=0&";
255
				break;
256
			case '6': //eigene Kundengruppe
257
				$DATAstring .= "Haendler=0&";
258
				break;
259
			case '7': //eigene Kundengruppe
260
				$DATAstring .= "Haendler=0&";
261
				break;
262
			default: //wenn alles nicht zutrifft
263
				$DATAstring .= "Haendler=0&";
264
		}
265

    
266
		$xt_currency = $this->getCurrency($oData['currency']);
267

    
268
		// ############# PRODUCTS_DATA TEIL1 #############
269
		// modified FT
270
		$DATAstring .= "Artikelerkennung=" . $Artikelerkennung ."&";
271
		$nr = 0;
272
		$anzahl = 0;
273
		while ($pDATA = xtc_db_fetch_array($p_query)) {
274
			$nr ++;
275

    
276
			if ($verwende_shop_artikelnummer == 1)
277
			{
278
				$artnr = $pDATA['products_id'];
279
				if ($artnr == '')
280
					$artnr = "99999";
281
			}
282
			elseif ($verwende_shop_artikelnummer == 2)
283
			{
284
				$select_ab_products_id = xtc_db_query("SELECT ab_productsid FROM products WHERE products_id = '".$pDATA['products_id']."'");
285
				$ab_products_id = xtc_db_fetch_array($select_ab_products_id);
286
				$artnr = $ab_products_id['ab_productsid'];
287
				
288
			}	
289
			else
290
			{
291
			$artnr = $pDATA['products_model'];
292
			}
293

    
294
			
295
			$a_query = xtc_db_query("SELECT * FROM ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES." WHERE orders_id='".$oID."' AND orders_products_id='".$pDATA['orders_products_id']."'");
296
			while ($aDATA = xtc_db_fetch_array($a_query))
297
			{
298
				if( $verwende_shop_artikelnummer == 1)
299
				{
300
					$attribute_model = $this->xtc_get_attributes_products_attributes_id($pDATA['products_id'], $aDATA['products_options_values'], $aDATA['products_options']);
301
					if ((int)$attribute_model >0)
302
						$artnr = $attribute_model;
303
				}
304
				elseif ($verwende_shop_artikelnummer == 2)
305
				{
306
					$attribute_model = $this->xtc_get_attributes_ab_productsid($pDATA['products_id'], $aDATA['products_options_values'], $aDATA['products_options']);
307
					if ((int)$attribute_model >0)
308
						$artnr = $attribute_model;
309
				}
310
				else
311
				{
312
				$attribute_model = xtc_get_attributes_model($pDATA['products_id'], $aDATA['products_options_values'], $aDATA['products_options']);
313
				if ((int)$attribute_model >0)
314
				$artnr = $attribute_model;
315
				}
316
			}
317

    
318
			$artnr = preg_replace('/[A-Za-z_\..-]*/','',$artnr);
319
			if ($artnr == '')
320
					$artnr = $pDATA['products_id'];
321
					
322
			//$pean_query = xtc_db_query("SELECT * FROM ".TABLE_PRODUCTS." WHERE products_id='".$pDATA['orders_products_id']."' LIMIT 1");
323
			/*while ($pean = xtc_db_fetch_array($pean_query))
324
			{
325
				$attribute_model = xtc_get_attributes_model($pDATA['products_id'], $aDATA['products_options_values'], $aDATA['products_options']);
326
				if ((int)$attribute_model >0)
327
				$artnr = $attribute_model;
328

    
329
			}*/
330
			$DATAstring .= "Artikelnr_".$nr."=".$artnr."&";
331
			$DATAstring .= "ArtikelStammID_" . $nr . "=" . $artnr . "&";
332
			$DATAstring .= "Artikelname_".$nr."=".urlencode($pDATA['products_name'])."&";
333

    
334
			// ############# PREIS?BERGABE BRUTTO/NETTO NACH KUNDENGRUPPE #############
335
			// Kundengruppen m?ssen jeweilige Zuordnung inkl/excl. Anzeige im Admin XT haben
336

    
337
			$price = $pDATA['products_price'];
338
			$tax_rate = $pDATA['products_tax'];
339
			if ($pDATA['allow_tax']==0) {
340
				$cQuery=xtc_db_query("SELECT customers_status_add_tax_ot FROM ".TABLE_CUSTOMERS_STATUS." WHERE customers_status_id='".$oData['customers_status']."' LIMIT 0,1");
341
				$cData=xtc_db_fetch_array($cQuery);
342
				if ($cData['customers_status_add_tax_ot']==0) {
343
					$tax_rate=0;
344
				} else {
345
					$price+=$price/100*$tax_rate;
346
				}
347
			}
348
			//W?hrungspr?fung
349
			
350
			$price = $price * $xt_currency;
351
			//W?hrungspr?fung END
352
			$price = $this->change_dec_separator($price);
353
			$tax = $this->change_dec_separator($tax_rate);
354

    
355
			// ############# PRODUCTS_DATA TEIL2 #############
356

    
357
			$DATAstring .= "ArtikelEPreis_".$nr."=".$price."&";
358
			$DATAstring .= "ArtikelMwst_".$nr."=".$tax."&";
359
			//$DATAstring .= "ArtikelMenge_".$nr."=". ereg_replace("\.", ",", $pDATA['products_quantity'])."&";
360
			$DATAstring .= "ArtikelMenge_".$nr."=".gm_prepare_number($pDATA['products_quantity'])."&";
361
			$url = HTTP_SERVER.DIR_WS_CATALOG.'product_info.php?products_id='.$pDATA['products_id'];
362
			$DATAstring .= "ArtikelLink_".$nr."=".$url."&";
363
			//Attribut?bergabe
364
			$a_query = xtc_db_query("SELECT * FROM ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES." WHERE orders_id='".$oID."' AND orders_products_id='".$pDATA['orders_products_id']."'");
365
			$options = '';
366
			while ($aDATA = xtc_db_fetch_array($a_query)) {
367
				if ($options == '') {
368
					$options = $aDATA['products_options'].":".$aDATA['products_options_values'];
369
				} else {
370
					$options .= "|".$aDATA['products_options'].":".$aDATA['products_options_values'];
371
				}
372
			}
373
			if ($options != "") {
374
				$DATAstring .= "Attribute_".$nr."=".$options."&";
375
			}
376
			$anzahl += (int)$pDATA['products_quantity'];
377

    
378
		}
379
		// ############# ORDER_TOTAL #############
380

    
381
		$order_total_query = xtc_db_query("SELECT
382
						                      class,
383
						                      value,
384
						                      sort_order
385
						                      FROM ".TABLE_ORDERS_TOTAL."
386
						                      WHERE orders_id='".$oID."'
387
						                      ORDER BY sort_order ASC");
388

    
389
		$order_total = array ();
390
		$zk = '';
391
		$cod_fee = '';
392
		$cod_flag = false;
393
		$discount_flag = false;
394
		$gv_flag = false;
395
		$coupon_flag = false;
396
		$gv = '';
397
		
398
		$customers_status_show_price_tax = $this->getCustomertaxstatus($oData['customers_status']);
399
		
400
		while ($order_total_values = xtc_db_fetch_array($order_total_query)) {
401

    
402
			$order_total[] = array ('CLASS' => $order_total_values['class'], 'VALUE' => $order_total_values['value']);
403

    
404
			// ############# NACHNAHME/GUTSCHEINE/KUPONS/RABATTE #############
405
			if ($order_total_values['class'] == 'ot_shipping')
406
			$shipping = $order_total_values['value'];
407

    
408
			// Nachnamegebuehr
409
			if ($order_total_values['class'] == 'ot_cod_fee') {
410
				$cod_flag = true;
411
				$cod_fee = $order_total_values['value'];
412
			}
413
			// Rabatt
414
			if ($order_total_values['class'] == 'ot_discount') {
415
				$discount_flag = true;
416
				$discount = $order_total_values['value'];
417
			}
418
			// Gutschein
419
			if ($order_total_values['class'] == 'ot_gv') {
420
				$gv_flag = true;
421
				$gv = $order_total_values['value'];
422
			}
423
			// Kupon
424
			if ($order_total_values['class'] == 'ot_coupon') {
425
				$coupon_flag = true;
426
				$coupon = $order_total_values['value'];
427
			}
428
			// ot_payment
429
			if ($order_total_values['class']=='ot_payment') {
430
				$ot_payment_flag=true;
431
				$ot_payment=$order_total_values['value'];
432
			}
433
			// Bonuspunkte
434
			if ($order_total_values['class'] == 'ot_bonus_fee') {
435
				$bonus_flag = true;
436
				$bonus_fee = $order_total_values['value'];
437
			}
438
		}
439

    
440
		// ############# ?BERGABE NACHNAHME/GUTSCHEINE/KUPONS/RABATTE #############
441

    
442
		$xt_currency = $this->getCurrency($oData['currency']);
443
		$customers_status_show_price_tax = $this->getCustomertaxstatus($oData['customers_status']);
444
		
445
// Bonuspunkte ?bergabe als Produkt
446
		if ($bonus_flag) 
447
		{
448
			$nr ++;
449
			$DATAstring .= "Artikelnr_".$nr."=99999991&";
450
			$DATAstring .= "Artikelname_".$nr."=Bonuspunkte&";
451
			$bonus_fee = $this->get_ot_total_fee($customers_status_show_price_tax, $tax_rate, $xt_currency, (-1)*$bonus_fee);
452
	
453
			$DATAstring .= "ArtikelEPreis_".$nr."=".$bonus_fee."&";
454
			$DATAstring .= "ArtikelMwst_".$nr."=".$tax."&";
455
			$DATAstring .= "ArtikelMenge_".$nr."=1&";
456
			$p_count ++;
457
			}
458
		// Nachnamegebuehr ?bergabe als Produkt
459
		if ($cod_flag) {
460
			$nr ++;
461
			$DATAstring .= "Artikelnr_".$nr."=99999999&";
462
			$DATAstring .= "Artikelname_".$nr."=Nachnahme&";
463
				
464
			$cod_fee = $this->get_ot_total_fee($customers_status_show_price_tax, $tax_rate, $xt_currency, $cod_fee);
465
		
466
			$DATAstring .= "ArtikelEPreis_".$nr."=".$cod_fee."&";
467
			$DATAstring .= "ArtikelMwst_".$nr."=".$tax."&";
468
			$DATAstring .= "ArtikelMenge_".$nr."=1&";
469
			$p_count ++;
470
		}
471
		// Rabatt ?bergabe als Produkt
472
		if ($discount_flag) {
473
			$nr ++;
474
			$DATAstring .= "Artikelnr_".$nr."=99999998&";
475
			$DATAstring .= "Artikelname_".$nr."=Rabatt&";
476
				
477
			$value_ot_total = $this->get_ot_total_fee($customers_status_show_price_tax, $tax_rate, $xt_currency, $discount);
478
			
479
			$DATAstring .= "ArtikelEPreis_".$nr."=".$value_ot_total."&";
480
			$DATAstring .= "ArtikelMwst_".$nr."=".$tax."&";
481
			$DATAstring .= "ArtikelMenge_".$nr."=1&";
482
			$p_count ++;
483
		}
484
		// Gutschein ?bergabe als Produkt
485
		if ($gv_flag) {
486
			$nr ++;
487
			$DATAstring .= "Artikelnr_".$nr."=99999997&";
488
			$DATAstring .= "Artikelname_".$nr."=Gutschein&";
489
			$value_ot_total = $this->get_ot_total_fee($customers_status_show_price_tax, $tax_rate, $xt_currency, (-1)*$gv);
490
				
491
			$DATAstring .= "ArtikelEPreis_".$nr."=".$value_ot_total."&";
492
			$DATAstring .= "ArtikelMwst_".$nr."=".$tax."&";
493
			$DATAstring .= "ArtikelMenge_".$nr."=1&";
494
			$p_count ++;
495
		}
496
		// Kupon ?bergabe als Produkt
497
		if ($coupon_flag) {
498
			$nr ++;
499
			$DATAstring .= "Artikelnr_".$nr."=99999996&";
500
			$DATAstring .= "Artikelname_".$nr."=Kupon&";
501
				
502
			$value_ot_total = $this->get_ot_total_fee($customers_status_show_price_tax, $tax_rate, $xt_currency, (-1)*$coupon);
503
			
504
			$DATAstring .= "ArtikelEPreis_".$nr."=".$value_ot_total."&";
505
			$DATAstring .= "ArtikelMwst_".$nr."=".$tax."&";
506
			$DATAstring .= "ArtikelMenge_".$nr."=1&";
507
			$p_count ++;
508
		}
509
		//ot_payment ?bergabe als Produkt
510
		if ($ot_payment_flag) {
511
			$nr++;
512
			$DATAstring .= "Artikelnr_" . $nr . "=99999995&";
513
			$DATAstring .= "Artikelname_" . $nr . "=Zahlartenrabatt&";
514
			$value_ot_total = $this->get_ot_total_fee($customers_status_show_price_tax, $tax_rate, $xt_currency, $ot_payment);
515
				
516
			$DATAstring .= "ArtikelEPreis_".$nr."=".$ot_payment."&";
517
			$DATAstring .= "ArtikelMwst_" . $nr . "=" . $tax . "&";
518
			$DATAstring .= "ArtikelMenge_" . $nr . "=1&";
519
			$p_count++;
520
		}
521

    
522
		$DATAstring .= "PosAnz=".$p_count."&";
523

    
524
		// ############# ?BERGABE BRUTTO/NETTO VERSAND #############
525
		// mofified FT Kundengruppen m?ssen jeweilige Zuordnung inkl/excl. Anzeige im Admin XT haben
526
		if ($order_total_values['class'] == 'ot_shipping')
527
		$shipping = $order_total_values['value'];
528
		if ($pDATA['allow_tax']==0) {
529
				if ($customers_status_show_price_tax == 1)
530
					$tax_rate=0;
531
				else				
532
					$shipping=((($shipping/100)*$tax_rate)+$shipping);
533
			
534
		}
535
		if ((int)$xt_currency > 0)
536
			$shipping = $shipping * $xt_currency;
537
		//W?hrungspr?fung END
538
		
539
		$DATAstring .= "Versandkosten=" . $this->change_dec_separator($shipping) . "&";
540

    
541
		$s_method = explode('(', $oData['shipping_method']);
542
		$s_method = str_replace(' ', '%20', $s_method[0]);
543
		$DATAstring .= "kommentar=".urlencode($oData['comments'])."&";
544
		$DATAstring .= "Versandart=".$s_method."&";
545
		$DATAstring .= "NoVersandCalc=".$versandermittlung_ab."&";
546
        $DATAstring .= "VID=".$oID."&";
547

    
548
		
549
		//$DATAstring .= "ZahlartenAufschlag=". ereg_replace("\.", ",", $zahlartenaufschlag). "&";
550
		
551
		$this->getPayment($oData['payment_method']);
552
		$DATAstring .= "Zahlart=".$this->payment_name. "&";
553
		$DATAstring .= "ZFunktionsID=".$this->payment_id. "&";
554
		
555
		/*if ($oData['payment_method'] == 'paypal_gambio' OR $oData['payment_method'] == 'paypa_ipn') {
556
			$feedbackdatum = '2';
557
		}*/
558

    
559
		//?bergabe Bankdaten
560
		if ($oData['payment_method'] == 'banktransfer') 
561
		{
562

    
563
			if ($_GET['oID']) {
564
				$b_query = xtc_db_query("SELECT * FROM banktransfer WHERE orders_id='".(int)$_GET['oID']."'");
565
				$b_data=xtc_db_fetch_array($b_query);
566
				$DATAstring .= "Bankname=".urlencode($b_data['banktransfer_bankname'])."&";
567
				$DATAstring .= "BLZ=".$b_data['banktransfer_blz']."&";
568
				$DATAstring .= "Kontonummer=".$b_data['banktransfer_number']."&";
569
				$DATAstring .= "Kontoinhaber=".urlencode($b_data['banktransfer_owner'])."&";
570
			} else {
571
				$DATAstring .= "Bankname=".urlencode($_POST['banktransfer_bankname'])."&";
572
				$DATAstring .= "BLZ=".$_POST['banktransfer_blz']."&";
573
				$DATAstring .= "Kontonummer=".$_POST['banktransfer_number']."&";
574
				$DATAstring .= "Kontoinhaber=".urlencode($_POST['banktransfer_owner'])."&";
575
			}	
576
		}
577
		
578
		if ($moneybookers == 1)
579
		{
580
			$sql = "SELECT * FROM `payment_moneybookers` WHERE mb_ORDERID = '".$oID."' ORDER BY mb_DATE DESC";
581
		$mb_query = xtc_db_query($sql);
582
		if (count($mb_query)) 
583
		{
584
			$mb_data = xtc_db_fetch_array($mb_query);
585
			if ($mb_data['mb_STATUS'] == '2')
586
		{
587
				$DATAstring .= "SetPay=1&";
588
			}
589
			}
590
		}
591
		//
592
		//$DATAstring .= "MarkierungID=9852&";
593
		//$DATAstring .= "Bestandart=auktion&"; //shop oder auktion
594
		$DATAstring .= "Bestandart=shop&";	
595
			
596
		if($paypalexpress == 1)
597
		{
598
			$paypal_sql = "SELECT * FROM ".TABLE_PAYPAL." WHERE xtc_order_id ='".$oID."' ORDER BY payment_date DESC";
599
		$paypal_query = xtc_db_query($paypal_sql);
600
		if (count($paypal_query)) 
601
		{
602
			$paypal_data = xtc_db_fetch_array($paypal_query);
603
			if ($paypal_data['payment_status'] == 'Completed')
604
			{
605
				$DATAstring .= "SetPay=1&";
606
			}
607
			}
608
		}
609

    
610
		if ($this->paid == 1)
611
			$DATAstring .= "SetPay=1&";
612
		
613
		$DATAstring .= "NoFeedback=" . $feedbackdatum . "&";
614
		// #############  CHECK  #############
615
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
616
		curl_setopt($ch, CURLOPT_POSTFIELDS, $DATAstring);
617
		$result = curl_exec($ch);
618
		if (strpos($result, "<success>1</success>") !== false) {
619
			// result ok, mark order
620
			// extract ID from result
621
			$cdr = explode('<KundenNr>', $result);
622
			$cdr = explode('</KundenNr>', $cdr[1]);
623
			$cdr = $cdr[0];
624
			xtc_db_query("update ".TABLE_ORDERS." set afterbuy_success='1',afterbuy_id='".$cdr."' where orders_id='".$oID."'");
625
			$p = new XMLParser($result);
626
			$array_complete_parse = $p->getOutput();
627

    
628
			$array_results_parse = $array_complete_parse["result"];
629
			$ab_aid = $array_results_parse["data"]["AID"];
630
			$ab_uid = $array_results_parse["data"]["UID"];
631
			$ab_kundennr = $array_results_parse["data"]["KundenNr"];
632
			$ab_ekundennr = $array_results_parse["data"]["EKundenNr"];
633
			//wenn Kundenkommentar
634
			if ($oData['comments'] != '') {
635
				$mail_content .= "Name: " .$oData['billing_firstname']." ".$oData['billing_lastname']. "\nEmailadresse: " .$oData['customers_email_address']. "\nKundenkommentar: " .$oData['comments']. "\nBestellnummer: " .$oID.chr(13).chr(10). "\n";
636
				mail(EMAIL_BILLING_ADDRESS, "Kundenkommentar bei Bestellung", $mail_content);
637
				//mail(EMAIL_BILLING_ADDRESS, "Kundenkommentar bei Bestellung", $mail_content);
638
			}
639
			//set new order status
640
			if ($order_status != '') {
641
				xtc_db_query("update ".TABLE_ORDERS." set orders_status='".$order_status."' where orders_id='".$oID."'");
642
			}
643
		} else {
644

    
645
			// mail to shopowner
646
			$mail_content = 'Fehler bei ?&Uuml;bertragung der Bestellung: '.$oID.chr(13).chr(10).'Folgende Fehlermeldung wurde vom afterbuy.de zur&uuml;ckgegeben:'.chr(13).chr(10).$result;
647
			mail(EMAIL_BILLING_ADDRESS, "Afterbuy-Fehl&uuml;bertragung", $mail_content);
648
			//mail("info@pimpmyxtc.de", "Afterbuy-Fehl&uuml;bertragung", $mail_content);
649
		}
650
		// close session
651
		curl_close($ch);
652
	}
653

    
654
	// Funktion zum ueberpruefen ob Bestellung bereits an Afterbuy gesendet.
655
	function order_send() {
656
		$check_query = xtc_db_query("SELECT afterbuy_success FROM ".TABLE_ORDERS." WHERE orders_id='".$this->order_id."'");
657
		$data = xtc_db_fetch_array($check_query);
658

    
659
		if ($data['afterbuy_success'] == 1)
660
			return false;
661
		return true;
662
	}
663
	
664
	function getCurrency($o_currency)
665
	{
666
		//W?hrungspr?fung
667
		$curreny_query = xtc_db_query("SELECT * FROM " . TABLE_CURRENCIES ." WHERE code = '".$o_currency."' LIMIT 1");
668
		while ($currency_array = xtc_db_fetch_array($curreny_query)) 
669
		{
670
			$xt_currency = $currency_array['value'];
671
		}
672
		return $xt_currency;
673
	}
674
		
675
	function getCustomertaxstatus($customers_status)
676
	{
677
		//Steuerpr?fung
678
		$cQuery=xtc_db_query("SELECT customers_status_show_price_tax FROM ".TABLE_CUSTOMERS_STATUS." WHERE customers_status_id='".$customers_status."' LIMIT 1");
679
		$cData=xtc_db_fetch_array($cQuery);
680
		if ($cData['customers_status_show_price_tax']==1) 
681
		{
682
			$customers_status_show_price_tax = 1;
683
		} 
684
		else 
685
		{
686
			$customers_status_show_price_tax = 2;		
687
		}
688
		return $customers_status_show_price_tax;
689
		
690
	}
691
	
692
	function getPayment($payment)
693
	{
694
		switch($payment) {
695
			case 'banktransfer':
696
				$this->payment_id = '7';
697
				$this->payment_name = "Bankeinzug";	
698
			break;
699
			case 'cash':
700
				$this->payment_id = '2';
701
				$this->payment_name = "Barzahlung";
702
			break;
703
			case 'cod':
704
				$this->payment_id = '4';
705
				$this->payment_name = "Nachnahme";
706
			break;
707
			case 'invoice':
708
				$this->payment_id = '6';
709
				$this->payment_name = "Rechnung";
710
			break;
711
			case 'moneyorder':
712
			case 'eustandardtransfer':
713
				$this->payment_id = '1';
714
				$this->payment_name = "?berweisung/Vorkasse";
715
			break;
716
			case 'moneybookers':
717
				$payment_name = "Moneybookers";
718
				$this->payment_id = '15';
719
			break;
720
			case 'moneybookers_cc':
721
				$payment_name = "Moneybookers CC";
722
				$this->payment_id = '15';
723
			break;
724
			case 'moneybookers_cgb':
725
				$payment_name = "Moneybookers CGB";
726
				$this->payment_id = '15';
727
			break;
728
			case 'moneybookers_csi':
729
				$payment_name = "Moneybookers CSI";
730
				$this->payment_id = '15';
731
			break;
732
			case 'moneybookers_elv':
733
				$payment_name = "Moneybookers ELV";
734
				$this->payment_id = '15';
735
			break;
736
			case 'moneybookers_giropay':
737
				$payment_name = "Moneybookers GIROPAY";
738
				$this->payment_id = '15';
739
			break;
740
			case 'moneybookers_ideal':
741
				$payment_name = "Moneybookers IDEAL";
742
				$this->payment_id = '15';
743
			break;
744
			case 'moneybookers_mae':
745
				$payment_name = "Moneybookers MAE";
746
				$this->payment_id = '15';
747
			break;
748
			case 'moneybookers_netpay':
749
				$payment_name = "Moneybookers NETPAY";
750
				$this->payment_id = '15';
751
			break;
752
			case 'moneybookers_psp':
753
				$payment_name = "Moneybookers PSP";
754
				$this->payment_id = '15';
755
			break;
756
			case 'moneybookers_pwy':
757
				$payment_name = "Moneybookers PWY";
758
				$this->payment_id = '15';
759
			break;
760
			case 'moneybookers_sft':
761
				$payment_name = "Moneybookers SFT";
762
				$this->payment_id = '15';
763
			break;
764
			case 'moneybookers_wlt':
765
				$payment_name = "Moneybookers WLT";
766
				$this->payment_id = '15';
767
			break;
768
			case 'paypal':
769
			case 'paypalexpress':
770
			case 'paypal_gambio':
771
			case 'paypa_ipn':
772
				$this->payment_id = '5';
773
				$this->payment_name = "Paypal";
774
			break;
775
			
776
			case 'sofortueberweisung':
777
			case 'sofortueberweisungredirect':
778
			case 'sofortueberweisung_direct':
779
			case 'sofortueberweisungvorkasse':
780
				$this->payment_id = '12';
781
				$this->payment_name = "Sofort?berweisung";
782
			break;
783
			case 'billsafe':
784
				$this->payment_id = '18';
785
				$this->payment_name = "Billsafe";
786
			break;			
787
			case 'ipayment':
788
				$this->payment_id = '99';
789
				$this->payment_name = "IPayment";
790
			break;			
791
			case 'cc':
792
				$this->payment_id = '99';
793
				$this->payment_name = "Kreditkarte";
794
			break;
795
			default:
796
				$this->payment_id = '99';
797
				$this->payment_name = "sonstige%20Zahlungsweise";
798
		}
799
	}
800
	
801
	function xtc_get_attributes_ab_productsid($product_id, $attribute_name,$options_name,$language='')
802
    {
803
		if ($language=='') $language=$_SESSION['languages_id'];
804
		$options_value_id_query=xtc_db_query("SELECT
805
			pa.ab_productsid
806
			FROM
807
			".TABLE_PRODUCTS_ATTRIBUTES." pa
808
			INNER JOIN ".TABLE_PRODUCTS_OPTIONS." po ON po.products_options_id = pa.options_id
809
			INNER JOIN ".TABLE_PRODUCTS_OPTIONS_VALUES." pov ON pa.options_values_id = pov.products_options_values_id
810
			WHERE
811
			po.language_id = '".$language."' AND
812
			po.products_options_name = '".$options_name."' AND
813
			pov.language_id = '".$language."' AND
814
			pov.products_options_values_name = '".$attribute_name."' AND 
815
			pa.products_id='".$product_id."'");
816

    
817

    
818
		$options_attr_data = xtc_db_fetch_array($options_value_id_query);
819
		return $options_attr_data['ab_productsid'];	
820
    	
821
    }
822
	
823
	function xtc_get_attributes_products_attributes_id($product_id, $attribute_name,$options_name,$language='')
824
    {
825
		if ($language=='') $language=$_SESSION['languages_id'];
826
		$options_value_id_query=xtc_db_query("SELECT
827
			pa.products_attributes_id
828
			FROM
829
			".TABLE_PRODUCTS_ATTRIBUTES." pa
830
			INNER JOIN ".TABLE_PRODUCTS_OPTIONS." po ON po.products_options_id = pa.options_id
831
			INNER JOIN ".TABLE_PRODUCTS_OPTIONS_VALUES." pov ON pa.options_values_id = pov.products_options_values_id
832
			WHERE
833
			po.language_id = '".$language."' AND
834
			po.products_options_name = '".$options_name."' AND
835
			pov.language_id = '".$language."' AND
836
			pov.products_options_values_name = '".$attribute_name."' AND 
837
			pa.products_id='".$product_id."'");
838

    
839

    
840
		$options_attr_data = xtc_db_fetch_array($options_value_id_query);
841
		return $options_attr_data['products_attributes_id'];	
842
    	
843
    }
844
	
845
	function get_ot_total_fee($customers_status_show_price_tax, &$tax_rate, $xt_currency, $fee)
846
	{
847
		//?bergabe Brutto/Netto
848
		if ($pDATA['allow_tax']==0) 
849
		{
850
			if ($customers_status_show_price_tax == 1)
851
				$tax_rate=0;
852
			else
853
				$fee=((($fee/100)*$tax_rate)+$fee);
854
			
855
		}
856
		
857
		//W?hrung ber?cksichtigen
858
		if ((int)$xt_currency > 0)
859
			$fee = $fee * $xt_currency;
860
		
861
		return $this->change_dec_separator($fee);
862
		
863
	}
864
	
865
	function change_dec_separator($value)
866
	{
867
		return preg_replace("/\./", ",", $value);
868
	}
869

    
870
}
871
?>
    (1-1/1)