<?php


require_once("syncinclude.php");

$return=3;
if (auth())
{
	$return=5;
	if (intval($_POST['KeyBestellPos']))
	{		
		$return = 0;
		//hole einstellungen
		$cur_query = eS_execute_query("select languages_id from eazysales_einstellungen");
		$einstellungen = go_db_fetch_object($cur_query);

		//hole orders_items_id
		$orders_items_id = getFremdBestellPos(intval($_POST['KeyBestellPos']));
			
		//hole alle Eigenschaften, die ausgew�hlt wurden zu dieser bestellung
		$cur_query = eS_execute_query("select orders_items_characteristics.*, orders_items.items_tax, orders_items.items_id from orders_items_characteristics, orders_items where orders_items_characteristics.orders_items_id=".$orders_items_id." and orders_items.orders_items_id=orders_items_characteristics.orders_items_id order by orders_items_characteristics.orders_items_id");
		while ($WarenkorbPosEigenschaft = go_db_fetch_object($cur_query))
		{
			$preisprefix=1;
			if ($WarenkorbPosEigenschaft->price_prefix=="-")
				$preisprefix=-1;

			//hole attribut
			$attribut_query = eS_execute_query("select items_characteristics.items_characteristics_id from items_characteristics, items_options, items_options_values where items_characteristics.items_id=".$WarenkorbPosEigenschaft->items_id." and items_characteristics.options_id=items_options.items_options_id and items_characteristics.options_values_id=items_options_values.items_options_values_id and items_characteristics.options_values_price=".go_db_real_escape_string($WarenkorbPosEigenschaft->options_values_price)." and items_options.items_options_name=\"".go_db_real_escape_string($WarenkorbPosEigenschaft->items_options)."\" and items_options.language_id=".$einstellungen->languages_id." and items_options_values.items_options_values_name=\"".$WarenkorbPosEigenschaft->items_options_values."\" and items_options_values.language_id=".$einstellungen->languages_id);
			
			$attribut_arr = go_db_fetch_row($attribut_query);
			
			echo(CSVkonform($WarenkorbPosEigenschaft->orders_items_characteristics_id).';');
			echo(CSVkonform(intval($_POST['KeyBestellPos'])).';');
			echo(';');
			echo(CSVkonform(getEsEigenschaftsWert($attribut_arr[0],getEsArtikel($WarenkorbPosEigenschaft->items_id))).';');
			echo(CSVkonform(($WarenkorbPosEigenschaft->options_values_price+$WarenkorbPosEigenschaft->options_values_price*$WarenkorbPosEigenschaft->items_tax/100)*$preisprefix).';');
			echo("\n");
		}
	}
}

go_db_close();
echo($return);
logge($return);
?>