<?php


require_once("syncinclude.php");

$return=3;
if (auth())
{
	if (intval($_POST['KeyBestellung']))
	{
		$return=0;
		
		//hole order		
		$cur_query = eS_execute_query("select * from orders where orders_id=".intval($_POST['KeyBestellung']));
		$Kunde = go_db_fetch_object($cur_query);

		//zusatzinfos vom kunden holen		
		$cur_query = eS_execute_query("select attendees.attendees_gender, attendees.attendees_newsletter, attendees.attendees_fax, date_format(attendees.attendees_dob, \"%d.%m.%Y\") as geburtsdatum from orders, attendees where orders.attendees_id=attendees.attendees_id and attendees.attendees_id=".$Kunde->attendees_id);
		$cust = go_db_fetch_object($cur_query);
		
		$Kunde->attendees_gender = $cust->attendees_gender;
		$Kunde->attendees_newsletter = $cust->attendees_newsletter;
		$Kunde->attendees_fax = $cust->attendees_fax;
		$Kunde->attendees_vat_id = $cust->attendees_vat_id;
		$Kunde->geburtsdatum = $cust->geburtsdatum;
		
		$Kunde->cAnrede="Frau";
		if ($Kunde->attendees_gender=="m")
			$Kunde->cAnrede="Herr";
			
		$Kunde->cHaendler="N";
			
		$Kunde->cNewsletter="N";
		if ($Kunde->attendees_newsletter)
			$Kunde->cNewsletter="Y";
			
		//falls kein kunde existiert, key muss irgendwo her!
		if (!$Kunde->attendees_id)
			$Kunde->attendees_id = 10000000-$Kunde->orders_id;

		echo(CSVkonform($Kunde->attendees_id).';');
		echo(CSVkonform($Kunde->attendees_id).';');
		echo(';');
		echo('"*****";');
		echo(CSVkonform($Kunde->cAnrede).';');
		echo(';'); //Titel
		echo(CSVkonform(substr($Kunde->billing_name,0,strpos($Kunde->billing_name," "))).';');
		echo(CSVkonform(substr($Kunde->billing_name,strpos($Kunde->billing_name," ")+1)).';');
		echo(CSVkonform($Kunde->billing_company).';');
		echo(CSVkonform($Kunde->billing_street_address).';');
		echo(CSVkonform($Kunde->billing_postcode).';');
		echo(CSVkonform($Kunde->billing_city).';');
		echo(CSVkonform($Kunde->billing_land).';');
		echo(CSVkonform($Kunde->attendees_telephone).';');
		echo(CSVkonform($Kunde->attendees_fax).';');
		echo(CSVkonform($Kunde->attendees_email_address).';');
		echo(CSVkonform($Kunde->cHaendler).';');
		echo(';'); //Rabatt
		echo(';'); // ustid
		echo(CSVkonform($Kunde->cNewsletter).';');
		echo(CSVkonform($Kunde->geburtsdatum).';'); //Geburtstag
		echo(CSVkonform($Kunde->attendees_suburb).';'); //adresszusatz
		echo(';'); //www
		echo("\n");
 	}
	else
		$return=5;
}

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