<?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 gro�e 
  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
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/
?>
<?php

include('load_this/load_this_bigware_10.php');   

if (!go_session_is_registered('attendee_id')) {
	$navigation->set_snapshot(array('mode' => 'SSL', 'page' => $GLOBALS[CONFIG_NAME_FILE][main_bigware_51]));
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_40], '', 'SSL'));
}

if (!go_session_is_registered('sendto')) {
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_51], '', 'SSL'));
}
if ( (go_not_null(CONSTITUENT_PAYMENT_INSTALLED)) && (!go_session_is_registered('payment')) ) {
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_51], '', 'SSL'));
} 
if (isset($cart->cartID) && go_session_is_registered('cartID')) {
	if ($cart->cartID != $cartID) {
		go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_66], '', 'SSL'));
	}
}

$duplication_check_query = go_db_query("SELECT COUNT(*) AS count FROM orders WHERE attendees_id = '" . $attendee_id . "' AND TIME_TO_SEC(TIMEDIFF(NOW(), date_purchased)) < 120");
$duplication_check = go_db_fetch_array($duplication_check_query);  		
if ($duplication_check['count'] > 0) {
	$cart->reset(true); 
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_20], 'duplication_error=1', 'SSL'));
}

$path_parts1 = pathinfo($_FILES['datei1']['name']);
$path_parts2 = pathinfo($_FILES['datei2']['name']);
$path_parts3 = pathinfo($_FILES['datei3']['name']);
$path_parts4 = pathinfo($_FILES['datei4']['name']);
$path_parts5 = pathinfo($_FILES['datei5']['name']);
$today = date("_d_m_y_H_i_s"); 

if ($_FILES['datei1']['name'] != ''){

	$pos = substr_count($_FILES['datei1']['name'], '.jpg');
	$pos2 = substr_count($_FILES['datei1']['name'], '.gif');
	$pos3 = substr_count($_FILES['datei1']['name'], '.tif');
	$pos4 = substr_count($_FILES['datei1']['name'], '.png');

	if ($pos > 0 OR $pos2 > 0 OR $pos3 > 0 OR $pos4 > 0) {


		if($_FILES['datei1']['size'] <  1024000)
		{
			move_uploaded_file($_FILES['datei1']['tmp_name'], FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_1." . $path_parts1["extension"]);
			@chmod (FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_1." . $path_parts1["extension"], 0777);
			$datei1_erfolg ='Die Datei 1 wurde nach  <a href="' . HTTP_SERVER . FOLDER_RELATIV_HTTP_CATALOG . FOLDER_RELATIV_PICTURES  . 'kundenpics/' . $attendee_id . $today . '_1.' . $path_parts1["extension"] . '" target="_blank">Bild 1</a> hochgeladen';
			$upload_richtig = 1;
		}

		else
		{
			$datei1_error = 'Die Datei 1 darf nicht gr��er als 1000 kb sein oder leer lassen<br>';
			$fehler = 1;
		}

	}

	else
	{
		$datei1_error = 'Datei 1: Bitte nur GIF JPG oder TIF Bilder hochladen oder leer lassen<br>';
		$fehler = 1;
	}		    
} 
else{
	$_FILES['datei1']['name'] = '';

}  



if ($_FILES['datei2']['name'] != ''){

	$pos = substr_count($_FILES['datei2']['name'], '.jpg');
	$pos2 = substr_count($_FILES['datei2']['name'], '.gif');
	$pos3 = substr_count($_FILES['datei2']['name'], '.tif');
	$pos4 = substr_count($_FILES['datei1']['name'], '.png');

	if ($pos > 0 OR $pos2 > 0 OR $pos3 > 0 OR $pos4 > 0) {

		if($_FILES['datei2']['size'] <  1024000)
		{

			move_uploaded_file($_FILES['datei2']['tmp_name'], FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_2." . $path_parts2["extension"]);
			@chmod (FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_2." . $path_parts2["extension"], 0777);
			$datei2_erfolg ='Die Datei 2 wurde nach  <a href="' . HTTP_SERVER . FOLDER_RELATIV_HTTP_CATALOG . FOLDER_RELATIV_PICTURES  . 'kundenpics/' . $attendee_id . $today . '_2.' . $path_parts2["extension"] . '" target="_blank">Bild 2</a> hochgeladen';
			$upload_richtig = 1;				      	

		}

		else
		{
			$datei2_error = 'Die Datei 2 darf nicht gr��er als 1000 kb sein oder leer lassen<br>';
			$fehler = 1;
		}

	}

	else
	{
		$datei2_error = 'Datei 2: Bitte nur GIF JPG oder TIF Bilder hochladen oder leer lassen<br>';
		$fehler = 1;
	}		    
} 
else{
	$_FILES['datei2']['name'] = '';

}  		  


if ($_FILES['datei3']['name'] != ''){

	$pos = substr_count($_FILES['datei3']['name'], '.jpg');
	$pos2 = substr_count($_FILES['datei3']['name'], '.gif');
	$pos3 = substr_count($_FILES['datei2']['name'], '.tif');
	$pos4 = substr_count($_FILES['datei1']['name'], '.png');

	if ($pos > 0 OR $pos2 > 0 OR $pos3 > 0 OR $pos4 > 0) {

		if($_FILES['datei3']['size'] <  1024000)
		{
			move_uploaded_file($_FILES['datei3']['tmp_name'], FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_3." . $path_parts3["extension"]);
			@chmod (FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_3." . $path_parts3["extension"], 0777);
			$datei3_erfolg ='Die Datei 3 wurde nach  <a href="' . HTTP_SERVER . FOLDER_RELATIV_HTTP_CATALOG . FOLDER_RELATIV_PICTURES  . 'kundenpics/' . $attendee_id . $today . '_3.' . $path_parts3["extension"] . '" target="_blank">Bild 3</a> hochgeladen';
			$upload_richtig = 1;	
		}

		else
		{
			$datei3_error = 'Die Datei 3 darf nicht gr��er als 1000 kb sein oder leer lassen<br>';
			$fehler = 1;
		}

	}

	else
	{
		$datei3_error = 'Datei 3: Bitte nur GIF JPG oder TIF Bilder hochladen oder leer lassen<br>';
		$fehler = 1;
	}		    
} 
else{
	$_FILES['datei3']['name'] = '';

}  	


if ($_FILES['datei4']['name'] != ''){

	$pos = substr_count($_FILES['datei4']['name'], '.jpg');
	$pos2 = substr_count($_FILES['datei4']['name'], '.gif');
	$pos3 = substr_count($_FILES['datei4']['name'], '.tif');
	$pos4 = substr_count($_FILES['datei1']['name'], '.png');

	if ($pos > 0 OR $pos2 > 0 OR $pos3 > 0 OR $pos4 > 0) {

		if($_FILES['datei4']['size'] <  1024000)
		{
			move_uploaded_file($_FILES['datei4']['tmp_name'], FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_4." . $path_parts4["extension"]);
			@chmod (FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_4." . $path_parts4["extension"], 0777);
			$datei4_erfolg ='Die Datei 4 wurde nach  <a href="' . HTTP_SERVER . FOLDER_RELATIV_HTTP_CATALOG . FOLDER_RELATIV_PICTURES  . 'kundenpics/' . $attendee_id . $today . '_4.' . $path_parts4["extension"] . '" target="_blank">Bild 4</a> hochgeladen';
			$upload_richtig = 1;	
		}

		else
		{
			$datei4_error = 'Die Datei 4 darf nicht gr��er als 1000 kb sein oder leer lassen<br>';
			$fehler = 1;
		}

	}

	else
	{
		$datei4_error = 'Datei 4: Bitte nur GIF JPG oder TIF Bilder hochladen oder leer lassen<br>';
		$fehler = 1;
	}		    
} 
else{
	$_FILES['datei4']['name'] = '';

}  	


if ($_FILES['datei5']['name'] != ''){

	$pos = substr_count($_FILES['datei5']['name'], '.jpg');
	$pos2 = substr_count($_FILES['datei5']['name'], '.gif');
	$pos3 = substr_count($_FILES['datei5']['name'], '.tif');
	$pos4 = substr_count($_FILES['datei1']['name'], '.png');

	if ($pos > 0 OR $pos2 > 0 OR $pos3 > 0 OR $pos4 > 0) {

		if($_FILES['datei5']['size'] <  1024000)
		{
			move_uploaded_file($_FILES['datei5']['tmp_name'], FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_5." . $path_parts5["extension"]);
			@chmod (FOLDER_ABSOLUT_CATALOG . FOLDER_RELATIV_PICTURES . "kundenpics/" . $attendee_id . $today . "_5." . $path_parts5["extension"], 0777);
			$datei5_erfolg ='Die Datei 5 wurde nach  <a href="' . HTTP_SERVER . FOLDER_RELATIV_HTTP_CATALOG . FOLDER_RELATIV_PICTURES  . 'kundenpics/' . $attendee_id . $today . '_5.' . $path_parts5["extension"] . '" target="_blank">Bild 5</a> hochgeladen';
			$upload_richtig = 1;	
		}

		else
		{
			$datei5_error = 'Die Datei 5 darf nicht gr��er als 1000 kb sein oder leer lassen<br>';
			$fehler = 1;
		}

	}

	else
	{
		$datei5_error = 'Datei 5: Bitte nur GIF JPG oder TIF Bilder hochladen oder leer lassen<br>';
		$fehler = 1;
	}		    
} 
else{
	$_FILES['datei5']['name'] = '';

}  	

if ($fehler	== '1'){
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_7], 'datei1_error=' . $datei1_error . '&datei2_error=' . $datei2_error . '&datei3_error=' . $datei3_error . '&datei4_error=' . $datei4_error . '&datei5_error=' . $datei5_error, 'SSL'));
}

include(FOLDER_RELATIV_LANGUAGES . $language . '/' . $GLOBALS[CONFIG_NAME_FILE][main_bigware_62]); 
require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_16]);
if ($crchange_covers) $payment='';
$payment_modules = new payment($payment); 
require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_18]);
$shipping_modules = new shipping($shipping);
require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_14]);

if (OPTIMIZE_ORDER == 'true'){

	$check_query = go_db_query("select count(*) as count from temp_serialize where user = '" . $attendee_id . "' AND was = 'get_items'");
	$check = go_db_fetch_array($check_query);  		
	if ($check['count'] > 0) {	
		$my_items_query = go_db_query("SELECT serialize_code FROM temp_serialize WHERE user = '" . $attendee_id . "' AND was = 'get_items'");
		$my_items_result=go_db_fetch_array($my_items_query);    
		$my_hidden_items = array_in_one_hidden_decode($my_items_result['serialize_code']);
	}  		  
}

$order = new order; 
$payment_modules->before_process();
require(FOLDER_RELATIV_CLASSES . $GLOBALS[CONFIG_NAME_FILE_CLASSES][classes_bigware_15]);
$order_total_modules = new order_total;
$order_totals = $order_total_modules->process();
$sql_data_array = array('attendees_id' => $attendee_id,
		'attendees_group_id' => $order->attendee['group_id'],
		'attendees_name' => $order->attendee['firstname'] . ' ' . $order->attendee['lastname'],
		'attendees_company' => $order->attendee['company'],
		'attendees_street_address' => $order->attendee['street_address'],
		'attendees_street_address2' => $order->attendee['street_address2'],
		'attendees_suburb' => $order->attendee['suburb'],
		'attendees_city' => $order->attendee['city'],
		'attendees_postcode' => $order->attendee['postcode'], 
		'attendees_state' => $order->attendee['state'], 
		'attendees_land' => $order->attendee['land']['title'], 
		'attendees_telephone' => $order->attendee['telephone'], 
		'attendees_email_address' => $order->attendee['email_address'],
		'attendees_form_of_address_id' => $order->attendee['format_id'], 
		'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'], 
		'delivery_company' => $order->delivery['company'],
		'billing_piva' => $order->billing['piva'],
		'billing_cf' => $order->billing['cf'],
		'delivery_street_address' => $order->delivery['street_address'],
		'delivery_street_address2' => $order->delivery['street_address2'], 
		'delivery_suburb' => $order->delivery['suburb'], 
		'delivery_city' => $order->delivery['city'], 
		'delivery_postcode' => $order->delivery['postcode'], 
		'delivery_state' => $order->delivery['state'], 
		'delivery_land' => $order->delivery['land']['title'], 
		'delivery_form_of_address_id' => $order->delivery['format_id'], 
		'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'], 
		'billing_company' => $order->billing['company'],
		'billing_street_address' => $order->billing['street_address'], 
		'billing_street_address2' => $order->billing['street_address2'], 
		'billing_suburb' => $order->billing['suburb'], 
		'billing_city' => $order->billing['city'], 
		'billing_postcode' => $order->billing['postcode'], 
		'billing_state' => $order->billing['state'], 
		'billing_land' => $order->billing['land']['title'], 
		'billing_form_of_address_id' => $order->billing['format_id'], 
		'payment_method' => $order->info['payment_method'], 
		'billing_form_of_address_id' => $order->billing['format_id'], 
		'payment_method' => $order->info['payment_method'],
		'payment_class' => $order->info['payment_class'],
		'shipping_method' => $order->info['shipping_method'],
		'shipping_class' => $order->info['shipping_class'],                          
		'cc_type' => $order->info['cc_type'], 
		'cc_type' => $order->info['cc_type'], 
		'cc_owner' => $order->info['cc_owner'], 
		'cc_number' => $order->info['cc_number'], 
		'cc_code' => $order->info['cc_code'], 
		'cc_expires' => $order->info['cc_expires'], 
		'date_purchased' => 'now()', 
		'orders_status' => $order->info['order_status'], 
		'currency' => $order->info['currency'], 
		'currency_value' => $order->info['currency_value']);
go_db_carry(DB_TBL_ORDERS, $sql_data_array);
$insert_id = go_db_insert_id();
for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
	$sql_data_array = array('orders_id' => $insert_id,
			'title' => $order_totals[$i]['title'],
			'text' => $order_totals[$i]['text'],
			'value' => $order_totals[$i]['value'], 
			'class' => $order_totals[$i]['code'], 
			'sort_order' => $order_totals[$i]['sort_order']);
	go_db_carry(DB_TBL_ORDERS_TOTAL, $sql_data_array);
}
$attendee_inform = (SEND_EMAILS == 'true') ? '1' : '0';
$sql_data_array = array('orders_id' => $insert_id, 
		'orders_status_id' => $order->info['order_status'], 
		'date_added' => 'now()', 
		'attendee_notified' => $attendee_inform,
		'comments' => $order->info['comments']);
go_db_carry(DB_TBL_ORDERS_STATUS_HISTORY, $sql_data_array);
$order_totals_table_beginn = '<table border="0" cellpadding="5" cellspacing="0">';
$order_totals_zelle_beginn = '<tr><td width="280" style="font-size: 12px">';
$order_totals_zelle_mitte = '</td><td style="font-size: 12px" align="right">';
$order_totals_zelle_end = '</td></tr>';
$order_totals_table_end = '</table>'; 
if (EMAIL_USE_HTML == 'true'){
	$items_ordered = $order_totals_table_beginn;
}
else{
	$items_ordered = '';
}
$subtotal = 0;
$total_tax = 0;

$fax_query_raw = "SELECT attendees_fax FROM " . DB_TBL_ATTENDEES . " WHERE attendees_id = '" .$attendee_id. "'";  
$fax_query = go_db_query($fax_query_raw);
if (go_db_num_rows($fax_query) > 0) {
	$fax_values = go_db_fetch_array($fax_query);
	$kundenfax = $fax_values['attendees_fax'];
}

//////////// Sortierung mit usort, anhand einer Vergleichsfunktion ////////////////
function cmp($a, $b) {
	return strcmp($a["name"], $b["name"]);
}
usort($order->items, "cmp");
//////////////////////////////////////////////////////////////////////////////////

for ($i=0, $n=sizeof($order->items); $i<$n; $i++) { 
	if (STOCK_LIMITED == 'true') {
		if (DOWNLOAD_ENABLED == 'true') {
			$stock_query_raw = "SELECT items_quantity, items_bundle, pad.items_characteristics_filename 
				FROM (((" . DB_TBL_ITEMS . " p)
							LEFT JOIN " . DB_TBL_ITEMS_CHARACTERISTICS . " pa
							ON p.items_id=pa.items_id)
						LEFT JOIN " . DB_TBL_ITEMS_CHARACTERISTICS_DOWNLOAD . " pad
						ON pa.items_characteristics_id=pad.items_characteristics_id)
				WHERE p.items_id = '" . go_get_prid($order->items[$i]['id']) . "'";  
				$items_characteristics = $order->items[$i]['characteristics'];
			if (is_array($items_characteristics)) {
				$stock_query_raw .= " AND pa.options_id = '" . $items_characteristics[0]['option_id'] . "' AND pa.options_values_id = '" . $items_characteristics[0]['value_id'] . "'";
			}
			$stock_query = go_db_query($stock_query_raw);
		} else {
			$stock_query = go_db_query("select items_quantity, items_bundle from " . DB_TBL_ITEMS . " where items_id = '" . go_get_prid($order->items[$i]['id']) . "'");
		}
		if (go_db_num_rows($stock_query) > 0) {
			$stock_values = go_db_fetch_array($stock_query); 

			if ($stock_values['items_bundle'] == 'yes') {

				if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/bundle')) {
					require(FOLDER_ABSOLUT_CATALOG . 'modules/bundle/main_bigware_62.php');
				}

			} else {
				// order item is normal and should be treated as such
				// $report_text .= "Normal item found in order : " . go_get_prid($order->items[$i]['id']) . "\n";        

				if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['items_characteristics_filename'])) {
					$stock_left = $stock_values['items_quantity'] - $order->items[$i]['qty'];
				} else {
					$stock_left = $stock_values['items_quantity'];
				}
				go_db_query("update " . DB_TBL_ITEMS . " set items_quantity = '" . $stock_left . "' where items_id = '" . go_get_prid($order->items[$i]['id']) . "'");
				if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
					go_db_query("update " . DB_TBL_ITEMS . " set items_status = '0' where items_id = '" . go_get_prid($order->items[$i]['id']) . "'");
				}
			}
		}
	}

	$add_cart_variable = array_in_one_hidden_decode($order->items[$i]['add_cart_variable_serialize']);
	$order->items[$i]['add_cart_variable_serialize'] = $item_laenge_breite_result['add_cart_variable_serialize'];
	if (is_array ($add_cart_variable)){
		foreach ($add_cart_variable as $key => $val){
			$order->items[$i][$key] = $val;
		}
	}	  

	go_db_query("update " . DB_TBL_ITEMS . " set items_ordered = items_ordered + " . sprintf('%d', $order->items[$i]['qty']) . " where items_id = '" . go_get_prid($order->items[$i]['id']) . "'");
	if ($order->items[$i]['items_price_option'] > 0) {
		$getImMeterQuery[$i] = go_db_query("select immeter, inmeter_breite from price_option where id=".$order->items[$i]['items_price_option']);
		$getImMeter[$i] = go_db_result($getImMeterQuery[$i],0,'immeter');
		$getInMeter_breite[$i] = go_db_result($getImMeterQuery[$i],0,'inmeter_breite');
	}
	else {
		$getImMeter[$i]=1000;
		$getInMeter_breite[$i]=1000;
	}
	if (EMAIL_USE_HTML == 'true') {
		if ($order->items[$i]['items_price_option']!=0){
			if ($order->items[$i]['items_price_option']==1){$price_option_name="qm";}
			elseif ($order->items[$i]['items_price_option']==2){$price_option_name="qmm";}
			elseif ($order->items[$i]['items_price_option']==3){$price_option_name="lfdm";}
			elseif ($order->items[$i]['items_price_option']==4){$price_option_name="U lfdm";}
			if ($order->items[$i]['items_price_option'] == 4){
				$quadratur_display = (($order->items[$i]['laenge']*2/$getImMeter[$i])+($order->items[$i]['breite']*2/$getInMeter_breite[$i]));	
			} 
			else {
				$quadratur_display = (($order->items[$i]['laenge']/$getImMeter[$i])*($order->items[$i]['breite']/$getInMeter_breite[$i]));
			}

			$final_price = $quadratur_display * $order->items[$i]['final_price'] + $order->items[$i]['qty'] * $order->items[$i]['items_basis_price'];

			if ($order->items[$i]['items_basis_price'] > 0) {
				$basis_price = ' + ' . $order->items[$i]['qty'] . ' x ' .$currencies->display_price($order->items[$i]['items_basis_price'], $order->items[$i]['tax']);
			} else {
				$basis_price = '';
			}


			$displayDim = '<br> - ' . $order->items[$i]['qty'] . ' x ' . $quadratur_display . ' ' . $price_option_name . ' x ' . $currencies->display_price($order->items[$i]['final_price'], $order->items[$i]['tax']) . $basis_price . '<br> - Abmessung: ' . $order->items[$i]['laenge'].' mm x '.$order->items[$i]['breite']. ' mm<br> - ' . $order->items[$i]['price_option_comment'];
			$displayDim_admin_attachment = "\n - " . $order->items[$i]['qty'] . ' x ' . $quadratur_display . ' ' . $price_option_name . ' x ' . $currencies->display_price($order->items[$i]['final_price'], $order->items[$i]['tax']) . $basis_price . "\n - " . 'Abmessung: ' . $order->items[$i]['laenge'].' mm x '.$order->items[$i]['breite']. ' mm' . "\n - " . $order->items[$i]['price_option_comment'];			
		} else { 
			$displayDim="";
			$final_price = $order->items[$i]['final_price'];
		}	

		//Loopthrough5

		if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/masseinheitenartikel')) {
			require(FOLDER_ABSOLUT_CATALOG . 'modules/masseinheitenartikel/main_bigware_62.php');
		}
		if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/domain_reg')) {
			require(FOLDER_ABSOLUT_CATALOG . 'modules/domain_reg/main_bigware_62b.php');
		}
		if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/extra_costumer_input_for_items')) {
			require(FOLDER_ABSOLUT_CATALOG . 'modules/extra_costumer_input_for_items/main_bigware_62a.php');
		}			
		if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/download')) {
			require(FOLDER_ABSOLUT_CATALOG . 'modules/download/main_bigware_62.php');
		}			

	} else {
		if ($order->items[$i]['items_price_option']!=0){
			if ($order->items[$i]['items_price_option']==1){$price_option_name="qm";}
			elseif ($order->items[$i]['items_price_option']==2){$price_option_name="qmm";}
			elseif ($order->items[$i]['items_price_option']==3){$price_option_name="lfdm";}
			elseif ($order->items[$i]['items_price_option']==4){$price_option_name="U lfdm";}

			if ($order->items[$i]['items_price_option'] == 4){
				$quadratur_display = (($order->items[$i]['laenge']*2/$getImMeter[$i])+($order->items[$i]['breite']*2/$getInMeter_breite[$i]));	
			} else {
				$quadratur_display = (($order->items[$i]['laenge']/$getImMeter[$i])*($order->items[$i]['breite']/$getInMeter_breite[$i]));
			}
			$final_price = $quadratur_display * $order->items[$i]['final_price'] + $order->items[$i]['qty'] * $order->items[$i]['items_basis_price'];
			if ($order->items[$i]['items_basis_price'] > 0) {
				$basis_price = ' + ' . $order->items[$i]['quantity'] . ' x ' .$currencies->display_price($order->items[$i]['items_basis_price'], $order->items[$i]['tax']);
			} else {
				$basis_price = '';
			}
			$displayDim = "\n - " . $order->items[$i]['qty'] . ' x ' . $quadratur_display . ' ' . $price_option_name . ' x ' . $currencies->display_price($order->items[$i]['final_price'], $order->items[$i]['tax']) . $basis_price . "\n - " . 'Abmessung: ' . $order->items[$i]['laenge'].' mm x '.$order->items[$i]['breite']. ' mm' . "\n - " . $order->items[$i]['price_option_comment'];
		} else { 
			$displayDim="";
			$final_price = $order->items[$i]['final_price'];
		}  


		//Loopthrough6

		if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/masseinheitenartikel')) {
			require(FOLDER_ABSOLUT_CATALOG . 'modules/masseinheitenartikel/main_bigware_62b.php');
		}
		if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/domain_reg')) {
			require(FOLDER_ABSOLUT_CATALOG . 'modules/domain_reg/main_bigware_62c.php');
		}
		if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/extra_costumer_input_for_items')) {
			require(FOLDER_ABSOLUT_CATALOG . 'modules/extra_costumer_input_for_items/main_bigware_62b.php');
		}	
		if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/download')) {
			require(FOLDER_ABSOLUT_CATALOG . 'modules/download/main_bigware_62b.php');
		}			

	} 
	$sql_data_array = array('orders_id' => $insert_id, 
			'items_id' => go_get_prid($order->items[$i]['id']), 
			'items_model' => $order->items[$i]['model'], 
			'items_name' => $order->items[$i]['name'], 
			'items_price' => $order->items[$i]['items_price'], 
			'items_basis_price' => $order->items[$i]['items_basis_price'], 
			'final_price' => $final_price, 
			'items_tax' => $order->items[$i]['tax'], 
			'items_quantity' => $order->items[$i]['qty'],
			'items_laenge' => $order->items[$i]['laenge'],
			'items_breite' => $order->items[$i]['breite'],
			'items_price_option' => $order->items[$i]['items_price_option'],
			'items_price_option_comment' => $order->items[$i]['price_option_comment'],
			'items_display_opt_price' => $displayDim);
	go_db_carry(DB_TBL_ORDERS_ITEMS, $sql_data_array);
	$order_items_id = go_db_insert_id();


	if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/download')) {
		require(FOLDER_ABSOLUT_CATALOG . 'modules/download/main_bigware_62c.php');
	}		    


	$order_total_modules->update_crchange_member($i); 
	$characteristics_exist = '0';
	$items_ordered_characteristics = '';  
	if (isset($order->items[$i]['characteristics'])) {
		$characteristics_exist = '1';
		for ($j=0, $n2=sizeof($order->items[$i]['characteristics']); $j<$n2; $j++) {

			if (KONFIGURATOR=='true'){ 
				if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/konfigurator')) {
					include(FOLDER_ABSOLUT_CATALOG . 'modules/konfigurator/main_bigware_62a.php');
				}
				else{			  	
					if (!isset($order->items[$i]['characteristics'][$j]['value_id'])){
						$attr_options_conf_values_id_array = array(); $attr_options_conf_id_array = array();
						$items_characteristics_keys = array_keys($order->items[$i]['characteristics'][$j]);
						for ($a=0;$a<sizeof($items_characteristics_keys);$a++){
							$attr_options_conf_values_id_array[] = $order->items[$i]['characteristics'][$j][$items_characteristics_keys[$a]]['value_id'];
							$attr_options_conf_id_array[] = $order->items[$i]['characteristics'][$j][$items_characteristics_keys[$a]]['option_id'];
						}
						$attr_options_conf_values_id = implode(", ",$attr_options_conf_values_id_array);
						$attr_options_conf_id = implode(", ",$attr_options_conf_id_array); 
						$characteristics = go_db_query("select popt.items_options_conf_name, poval.items_options_conf_values_name, pa.options_conf_values_price, pa.price_prefix, pa.items_characteristics_conf_id from " . DB_TBL_ITEMS_OPTIONS_CONF . " popt, " . DB_TBL_ITEMS_OPTIONS_CONF_VALUES . " poval, " . DB_TBL_ITEMS_CHARACTERISTICS_CONF . " pa where pa.items_id = '" . $order->items[$i]['id'] . "' and pa.options_conf_id in (" . $attr_options_conf_id . ") and pa.options_conf_id = popt.items_options_conf_id and pa.options_conf_values_id in (" .$attr_options_conf_values_id . ") and pa.options_conf_values_id = poval.items_options_conf_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'"); 
					}//array
					else {
						$characteristics = go_db_query("select popt.items_options_conf_name, poval.items_options_conf_values_name, pa.options_conf_values_price, pa.price_prefix, pa.items_characteristics_conf_id from " . DB_TBL_ITEMS_OPTIONS_CONF . " popt, " . DB_TBL_ITEMS_OPTIONS_CONF_VALUES . " poval, " . DB_TBL_ITEMS_CHARACTERISTICS_CONF . " pa where pa.items_id = '" . $order->items[$i]['id'] . "' and pa.options_conf_id = '" . $order->items[$i]['characteristics'][$j]['option_id'] . "' and pa.options_conf_id = popt.items_options_conf_id and pa.options_conf_values_id = '" . $order->items[$i]['characteristics'][$j]['value_id'] . "' and pa.options_conf_values_id = poval.items_options_conf_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
					}//not array
				}// not file_exists

			}//konfigurator
			else {
				$characteristics = go_db_query("select popt.items_options_name, poval.items_options_values_name, pa.options_values_price, pa.price_prefix, pa.items_characteristics_id from " . DB_TBL_ITEMS_OPTIONS . " popt, " . DB_TBL_ITEMS_OPTIONS_VALUES . " poval, " . DB_TBL_ITEMS_CHARACTERISTICS . " pa where pa.items_id = '" . $order->items[$i]['id'] . "' and pa.options_id = '" . $order->items[$i]['characteristics'][$j]['option_id'] . "' and pa.options_id = popt.items_options_id and pa.options_values_id = '" . $order->items[$i]['characteristics'][$j]['value_id'] . "' and pa.options_values_id = poval.items_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
			}//not konfigurator


			if (KONFIGURATOR=='true'){

				if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/konfigurator')) {
					include(FOLDER_ABSOLUT_CATALOG . 'modules/konfigurator/main_bigware_62b.php');
				}
				else{
					while($characteristics_values = go_db_fetch_array($characteristics)){
						$sql_data_array = array('orders_id' => $insert_id, 
								'orders_items_id' => $order_items_id, 
								'items_options_conf' => $characteristics_values['items_options_conf_name'],
								'items_options_conf_values' => $characteristics_values['items_options_conf_values_name'], 
								'options_conf_values_price' => $characteristics_values['options_conf_values_price'], 
								'price_prefix' => $characteristics_values['price_prefix']);
						go_db_carry(DB_TBL_ORDERS_ITEMS_CHARACTERISTICS_CONF, $sql_data_array);
						$items_ordered_characteristics .= "\n\t" . $characteristics_values['items_options_conf_name'] . ': ' . $characteristics_values['items_options_conf_values_name'];

						$values_qty_query = go_db_query("SELECT qty FROM " . DB_TBL_ITEMS_CHARACTERISTICS_CONF . " WHERE items_characteristics_conf_id='" . $characteristics_values['items_characteristics_conf_id'] . "'");
						$values_qty_query_result=go_db_fetch_array($values_qty_query);       		
						if ($values_qty_query_result['qty'] > 0){  
							$menge = $values_qty_query_result['qty']-$order->items[$i]['qty'];
							go_db_query("update " . DB_TBL_ITEMS_CHARACTERISTICS_CONF . " SET qty='" . trim($menge) . "' WHERE items_characteristics_conf_id='" . $characteristics_values['items_characteristics_conf_id'] . "'");    
						}
					}	// while					
				} // not file_exists


			}//konfigurator
			else {
				$characteristics_values = go_db_fetch_array($characteristics);
				$sql_data_array = array('orders_id' => $insert_id, 
						'orders_items_id' => $order_items_id, 
						'items_options' => $characteristics_values['items_options_name'],
						'items_options_values' => $characteristics_values['items_options_values_name'], 
						'options_values_price' => $characteristics_values['options_values_price'], 
						'price_prefix' => $characteristics_values['price_prefix']);
				go_db_carry(DB_TBL_ORDERS_ITEMS_CHARACTERISTICS, $sql_data_array);


				$items_ordered_characteristics .= "\n\t" . $characteristics_values['items_options_name'] . ': ' . $characteristics_values['items_options_values_name'];
				$values_qty_query = go_db_query("SELECT qty FROM " . DB_TBL_ITEMS_CHARACTERISTICS . " WHERE items_characteristics_id='" . $characteristics_values['items_characteristics_id'] . "'");
				$values_qty_query_result=go_db_fetch_array($values_qty_query);       		
				if ($values_qty_query_result['qty'] > 0){  
					$menge = $values_qty_query_result['qty']-$order->items[$i]['qty'];
					go_db_query("update " . DB_TBL_ITEMS_CHARACTERISTICS . " SET qty='" . trim($menge) . "' WHERE items_characteristics_id='" . $characteristics_values['items_characteristics_id'] . "'");    
				}
			}//not konfigurator
		}
	}  

	$total_weight += ($order->items[$i]['qty'] * $order->items[$i]['weight']);
	if ($order->items[$i]['items_price_option'] == 4){ 
		$total_tax += go_calculate_tax($total_items_price, $items_tax) * $order->items[$i]['qty'] * (($order->items[$i]['laenge']*2/$getImMeter[$i])+($order->items[$i]['breite']*2/$getInMeter_breite[$i]));
	}
	else { 
		$total_tax += go_calculate_tax($total_items_price, $items_tax) * $order->items[$i]['qty'] * ($order->items[$i]['laenge']/$getImMeter[$i])*($order->items[$i]['breite']/$getInMeter_breite[$i]);  	
	}
	$total_cost += $total_items_price;      
	if (EMAIL_USE_HTML == 'true'){
		$items_ordered .=  $order_totals_zelle_beginn.$order->items[$i]['qty'] . ' x ' . $order->items[$i]['name'] . ' (' . $order->items[$i]['model'] . ') = <br>' . $displayDim ."<br><i style=\"font-size:9px;\">". $items_ordered_characteristics ."</i>". $order_totals_zelle_mitte . $currencies->display_price_shopping_card($order->items[$i]['final_price'], $order->items[$i]['tax'], $order->items[$i]['qty'],$order->items[$i]['laenge'],$order->items[$i]['breite'],$getImMeter[$i],$getInMeter_breite[$i],$order->items[$i]['items_price_option'], $order->items[$i]['price_option_comment'], $order->items[$i]['items_basis_price']) . $order_totals_zelle_end;
		$items_ordered_admin_attachment .= $order->items[$i]['qty'] . ' x ' . $order->items[$i]['name'] . ' (' . $order->items[$i]['model'] . ') = ' . $currencies->display_price_shopping_card($order->items[$i]['final_price'], $order->items[$i]['tax'], $order->items[$i]['qty'],$order->items[$i]['laenge'],$order->items[$i]['breite'],$getImMeter[$i],$getInMeter_breite[$i],$order->items[$i]['items_price_option'], $order->items[$i]['price_option_comment'], $order->items[$i]['items_basis_price']) . $items_ordered_characteristics . "\n" . $displayDim_admin_attachment . "\n";	
	}
	else{

		$items_ordered .= $order->items[$i]['qty'] . ' x ' . $order->items[$i]['name'] . ' (' . $order->items[$i]['model'] . ') = ' . $currencies->display_price_shopping_card($order->items[$i]['final_price'], $order->items[$i]['tax'], $order->items[$i]['qty'],$order->items[$i]['laenge'],$order->items[$i]['breite'],$getImMeter[$i],$getInMeter_breite[$i],$order->items[$i]['items_price_option'], $order->items[$i]['price_option_comment'], $order->items[$i]['items_basis_price']) . $order->items[$i]['domain'] . $order->items[$i]['ext'] . $order->items[$i]['kk'] . $items_ordered_characteristics . "\n" . $displayDim . "\n";	
		$items_ordered_admin_attachment = $items_ordered;
	}
}

if (EMAIL_USE_HTML == 'true'){
	$items_ordered .= $order_totals_table_end;
}

$order_total_modules->apply_crchange(); 
if (EMAIL_USE_HTML == 'true'){
	$text_query = go_db_query("SELECT * FROM email_template_text where txt_html = 2 and language_id = '" . $languages_id . "' AND site_name = 'confirmation_request'");
}
else{
	$text_query = go_db_query("SELECT * FROM email_template_text where txt_html = 1 and language_id = '" . $languages_id . "' AND site_name = 'confirmation_request'");
}

if (file_exists(FOLDER_ABSOLUT_CATALOG . 'modules/order_email_attachment')) {
	if (XML_ATTACHMENT_ON == "true"){
		require(FOLDER_ABSOLUT_CATALOG . 'modules/order_email_attachment/main_bigware_62.php');
	}
}

$werte = go_db_fetch_array($text_query);
$text = $werte["email_text_one"];

$text = preg_replace('/<-SHOP_NAME->|&lt;-SHOP_NAME-&gt;/', SHOP_NAME, $text);
$text = preg_replace('/<-insert_id->|&lt;-insert_id-&gt;/', $insert_id, $text);
$text = preg_replace('/<-INVOICE_URL->|&lt;-INVOICE_URL-&gt;/', go_href_link($GLOBALS[CONFIG_NAME_FILE][member_history_more], 'order_id=' . $insert_id, 'SSL', false), $text);
$text = preg_replace('/<-DATE_ORDERED->|&lt;-DATE_ORDERED-&gt;/', pagadors_strftime(DATE_FORMAT_LONG), $text);

if ($order->info['comments']) {
	$text = preg_replace('/<-Customer_Comments->|&lt;-Customer_Comments-&gt;/', go_db_output($order->info['comments']), $text);
}
else{
	$text = preg_replace('/<-Customer_Comments->|&lt;-Customer_Comments-&gt;/', '', $text);
}

$text = preg_replace('/<-Item_List->|&lt;-Item_List-&gt;/', $items_ordered, $text);
if (EMAIL_USE_HTML == 'true'){
	$list_total = $order_totals_table_beginn;
	for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
		$list_total .= $order_totals_zelle_beginn . $order_totals[$i]['title'] . $order_totals_zelle_mitte . $order_totals[$i]['text'] . $order_totals_zelle_end;
	}
	$list_total .= $order_totals_table_end;
}
else{
	for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
		$list_total .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
	}
}	
$text = preg_replace('/<-List_Total->|&lt;-List_Total-&gt;/', $list_total, $text);
if ($order->content_type != 'virtual') {
	$text = preg_replace('/<-DELIVERY_Adress->|&lt;-DELIVERY_Adress-&gt;/', go_address_label($attendee_id, $sendto, 0, '', "\n"), $text);
}
elseif($order->content_type == 'virtual') {
	if ((DOWNLOAD_ENABLED == 'true') && isset($characteristics_values['items_characteristics_filename']) && go_not_null($characteristics_values['items_characteristics_filename'])) {
		$text = preg_replace('/<-DELIVERY_Adress->|&lt;-DELIVERY_Adress-&gt;/', "Nach Zahlungseingang k�nnen Sie Ihr Produkt hier downloaden. Sie erhalten dann eine seperate EMail: \n" . go_href_link($GLOBALS[CONFIG_NAME_FILE][member_history_more], 'order_id=' . $insert_id, 'SSL', false), $text);
	}
	else{
		$text = preg_replace('/<-DELIVERY_Adress->|&lt;-DELIVERY_Adress-&gt;/', '', $text);
	}	
}
else{
	$text = preg_replace('/<-DELIVERY_Adress->|&lt;-DELIVERY_Adress-&gt;/', '', $text);

}
$text = preg_replace('/<-BILL_Adress->|&lt;-BILL_Adress-&gt;/', go_address_label($attendee_id, $billto, 0, '', "\n"), $text);  

if (is_object($$payment)) {
	$payment_class = $$payment;
	$text = preg_replace('/<-Payment_Modul_Text->|&lt;-Payment_Modul_Text-&gt;/', $payment_class->title, $text); 
	$text = preg_replace('/<-Payment_Modul_Text_Footer->|&lt;-Payment_Modul_Text_Footer-&gt;/', $payment_class->email_footer, $text); 
}

$text = preg_replace('/<-FIRST_NAME_CUSTOMER->|&lt;-FIRST_NAME_CUSTOMER-&gt;/', $order->attendee['firstname'], $text);
$text = preg_replace('/<-LAST_NAME_CUSTOMER->|&lt;-LAST_NAME_CUSTOMER-&gt;/', $order->attendee['lastname'], $text);
if (EMAIL_USE_HTML == 'true'){
	$text = preg_replace('/<-STREET_CUSTOMER->|&lt;-STREET_CUSTOMER-&gt;/', $order->attendee['street_address'] . "\n" . $order->attendee['street_address2'], $text);
}else{
	$text = preg_replace('/<-STREET_CUSTOMER->|&lt;-STREET_CUSTOMER-&gt;/', $order->attendee['street_address'] . "\n" . '<br>' . $order->attendee['street_address2'], $text);
}
$text = preg_replace('/<-POSTCODE_CUSTOMER->|&lt;-POSTCODE_CUSTOMER-&gt;/', $order->attendee['postcode'], $text);
$text = preg_replace('/<-CITY_CUSTOMER->|&lt;-CITY_CUSTOMER-&gt;/', $order->attendee['city'], $text);
if (EMAIL_USE_HTML == 'true'){
	$text = preg_replace('/<-MY_LOGO->|&lt;-MY_LOGO-&gt;/', '<img border="0" src="' . HTTP_SERVER . FOLDER_RELATIV_HTTP_CATALOG . FOLDER_RELATIV_PICTURES . CHANGE_INVOICE_LOGO . '">', $text);
}else{
	$text = preg_replace('/<-MY_LOGO->|&lt;-MY_LOGO-&gt;/', '', $text);
}	  
$sql_give_back = go_db_query("SELECT Text FROM " . DB_TBL_INFO_GIVE_BACK . " where language_id='" . $languages_id . "'");
$give_back = go_db_fetch_array($sql_give_back); 
$text = preg_replace('/<-WIDERUFSBELEHRUNG->|&lt;-WIDERUFSBELEHRUNG-&gt;/i', $give_back['Text'], $text);  
$sql_agb = go_db_query("SELECT Text FROM " . DB_TBL_INFO_CONDITIONS . " where language_id='" . $languages_id . "'");
$agb = go_db_fetch_array($sql_agb);
$text = preg_replace('/<-AGB->|&lt;-AGB-&gt;/i', $agb['Text'], $text); 
$text = preg_replace('/<-FIRMENANSCHRIFT->|&lt;-FIRMENANSCHRIFT-&gt;/', SHOP_NAME_ADDRESS, $text);
$text = preg_replace('/<-FINANZAMT->|&lt;-FINANZAMT-&gt;/', OWNER_BANK_FA, $text);
$text = preg_replace('/<-STEUERNUMMER->|&lt;-STEUERNUMMER-&gt;/', OWNER_BANK_TAX_NUMBER, $text);
$text = preg_replace('/<-USTID->|&lt;-USTID-&gt;/', OWNER_BANK_UST_NUMBER, $text);
$text = preg_replace('/<-BANKNAME->|&lt;-BANKNAME-&gt;/', OWNER_BANK_NAME, $text);
$text = preg_replace('/<-KONTOINHABER->|&lt;-KONTOINHABER-&gt;/', OWNER_BANK_MEMBER, $text);
$text = preg_replace('/<-BLZ->|&lt;--&gt;/', SHOP_OWNER_BLZ, $text);
$text = preg_replace('/<-KONTONUMMER->|&lt;-BLZ-&gt;/', OWNER_BANK, $text);
$text = preg_replace('/<-SWIFT->|&lt;-SWIFT-&gt;/', OWNER_BANK_SWIFT, $text);
$text = preg_replace('/<-IBAN->|&lt;-IBAN-&gt;/', OWNER_BANK_IBAN, $text);
$text = preg_replace('/<-FAXVONKUNDE->|&lt;-FAXVONKUNDE-&gt;/', $kundenfax, $text);
$text = preg_replace('/<-TELEVONKUNDE->|&lt;-TELEVONKUNDE-&gt;/', $order->attendee['telephone'], $text);
$text = preg_replace('/<-KUNDENEMAIL->|&lt;-KUNDENEMAIL-&gt;/', $order->attendee['email_address'], $text);
$text = preg_replace('/<-KOMMENTAR->|&lt;-KOMMENTAR-&gt;/', $order->info['comments'], $text);

if ($$payment->code=='banktransfer') { 
	if (EMAIL_USE_HTML == 'true'){
		$bankaccount_data = "<b>" . CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_TITLE . "</b><br>";
		$bankaccount_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_BANK_OWNER . " " . $_POST['banktransfer_owner'] . "<br>";
		$bankaccount_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_BANK_BLZ . " " . $_POST['banktransfer_blz'] . "<br>";
		$bankaccount_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_BANK_NUMBER . " " . $_POST['banktransfer_number'] . "<br>";
		$bankaccount_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_BANK_NAME . " " . $_POST['banktransfer_bankname'] . "<br>";
	}
	else{
		$bankaccount_data = CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_TITLE . "\n\n";
		$bankaccount_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_BANK_OWNER . " " . $_POST['banktransfer_owner'] . "\n";
		$bankaccount_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_BANK_BLZ . " " . $_POST['banktransfer_blz'] . "\n";
		$bankaccount_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_BANK_NUMBER . " " . $_POST['banktransfer_number'] . "\n";
		$bankaccount_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_TEXT_BANK_NAME . " " . $_POST['banktransfer_bankname'] . "\n";

	}	
	$text = preg_replace('/<-BANKTRANSFER_DATA->|&lt;-BANKTRANSFER_DATA-&gt;/', $bankaccount_data, $text);
}
else{
	$text = preg_replace('/<-BANKTRANSFER_DATA->|&lt;-BANKTRANSFER_DATA-&gt;/', '', $text);
}
// edit Richy SEPA Variable
if ($$payment->code=='banktransfer_sepa') { 
	if (EMAIL_USE_HTML == 'true'){
		$bankaccount_sepa_data = "<b>" . CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_TITLE . "</b><br>";
		$bankaccount_sepa_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_BANK_OWNER . " " . $_POST['banktransfer_sepa_owner'] . "<br>";
		$bankaccount_sepa_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_BANK_IBAN. " " . $_POST['banktransfer_sepa_iban'] . "<br>";
		$bankaccount_sepa_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_BANK_BIC . " " . $_POST['banktransfer_sepa_bic'] . "<br>";
		$bankaccount_sepa_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_BANK_NAME . " " . $_POST['banktransfer_sepa_bankname'] . "<br>";
	}
	else{
		$bankaccount_sepa_data = CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_TITLE . "\n\n";
		$bankaccount_sepa_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_BANK_OWNER . " " . $_POST['banktransfer_sepa_owner'] . "\n";
		$bankaccount_sepa_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_BANK_IBAN. " " . $_POST['banktransfer_sepa_iban'] . "\n";
		$bankaccount_sepa_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_BANK_BIC . " " . $_POST['banktransfer_sepa_bic'] . "\n";
		$bankaccount_sepa_data .= CONSTITUENT_PAYMENT_BANKTRANSFER_SEPA_TEXT_BANK_NAME . " " . $_POST['banktransfer_bankname'] . "\n";

	}	
	$text = preg_replace('/<-BANKTRANSFER_SEPA_DATA->|&lt;-BANKTRANSFER_SEPA_DATA-&gt;/', $bankaccount_sepa_data, $text);
}
else{
	$text = preg_replace('/<-BANKTRANSFER_SEPA_DATA->|&lt;-BANKTRANSFER_SEPA_DATA-&gt;/', '', $text);
}
// edit ende Richy

$email_order = $text;


$query = "SELECT normal_mail_aus
FROM afterbuy WHERE id = '1'";
$result = go_db_QUERY($query);
$number = go_db_NUMROWS($result);

$normal_mail_aus = go_db_result($result,0,"normal_mail_aus");

$email_text_subject = preg_replace('/<-order_id->/i', $insert_id, EMAIL_TEXT_SUBJECT);

if ($normal_mail_aus == "nein"){
	go_mail($order->attendee['firstname'] . ' ' . $order->attendee['lastname'], $order->attendee['email_address'], $email_text_subject, $email_order, SHOP_OWNER, SHOP_OWNER_EMAIL_ADDRESS);
} 

if ($upload_richtig == 1){

	$email_text_upload= 'Der Kunde ' . $order->attendee['firstname'] . ' ' . $order->attendee['lastname'] . ' hat Bilder zu seiner Bestellung, mit der Bestellnummer ' . $insert_id . ', hochgeladen. Hier das Ergebnis:' . "\n\n" . $datei1_erfolg . "\n" . $datei2_erfolg . "\n" .  $datei3_erfolg . "\n" . $datei4_erfolg . "\n" . $datei5_erfolg . "\n";

	go_mail($order->attendee['firstname'] . ' ' . $order->attendee['lastname'], SHOP_OWNER_EMAIL_ADDRESS, $email_text_subject, $email_text_upload, SHOP_OWNER, SHOP_OWNER_EMAIL_ADDRESS);

}	


if (SEND_EXTRA_ORDER_EMAILS_TO != '') { 
	if ($_POST['banktransfer_owner'] != ""){
		if($_POST['banktransfer_fax'] != "on"){
			$email_order .= "\n";
			$email_order .= "Kontoinhaber: ". $_POST['banktransfer_owner'] . "\n";
			$email_order .= "BLZ:          ". $_POST['banktransfer_blz'] . "\n";
			$email_order .= "Konto:        ". $_POST['banktransfer_number'] . "\n";
			$email_order .= "Bank:         ". $_POST['banktransfer_bankname'] . "\n";
			if ($_POST['banktransfer_status'] == 0 || $_POST['banktransfer_status'] == 2){
				$email_order .= "Pr�fstatus:   OK\r\n";
			}else{
				$email_order .= "Pr�fstatus:   Es ist ein Problem aufgetreten, bitte beobachten!\r\n";
			}
		}else{
			$email_order .= "\n";
			$email_order .= "Kontodaten werden per Fax best&auml;tigt\n";
		}
	} 
	go_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $email_text_subject, $email_order, $order->attendee['firstname'] . ' ' . $order->attendee['lastname'], $order->attendee['email_address']);
} 
$payment_modules->after_process();
$cart->reset(true); 
go_session_unregister('sendto');
go_session_unregister('billto');
go_session_unregister('shipping');
go_session_unregister('payment');
go_session_unregister('comments');
if(go_session_is_registered('crchange_covers')) go_session_unregister('crchange_covers');
$order_total_modules->clear_posts();
if ($attendee_id != ''){
	$check_query = go_db_query("select count(*) as count from temp_serialize where user = '" . $attendee_id . "'");
	$check = go_db_fetch_array($check_query);
	if ($check['count'] > 0) {
		go_db_query("delete from temp_serialize where user = '" . $attendee_id . "'");
	}
}  

if ($$payment->code=='worldpay') { 
	$payment_modules->process_button();
	header("Location:". isohtmlspecialchars($$payment->form_action_url."?".$$payment->get_variables));
} else if ($$payment->code=='paypal') {
	$payment_modules->process_button();
	header("Location:". $$payment->form_action_url."?".$$payment->get_variables.'&item_name='.isohtmlspecialchars(SHOP_NAME." [".CONSTITUENT_PAYMENT_PAYPAL_TEXT_ORDER.": $insert_id]"));
} else {
	go_forward(go_href_link($GLOBALS[CONFIG_NAME_FILE][main_bigware_20], '', 'SSL'));
}

require(FOLDER_RELATIV_INCLUDES . 'load_this_bigware_3.php');
?>
