<?php header('Content-Type: text/html;charset=utf-8');
ini_set('display_errors', 1); 
error_reporting(E_ALL);
include_once('.htWaGlobalFunction.php');

/////


function varPostUtf8($key)
{
	$val=waRetrievePostParameter($key);
	$val = str_replace("\\\"","\"",$val);
	return $val;
}

$crbst_action=waRetrievePostParameter('crbst_action');

if ($crbst_action == "check_php")
{
?>check_php=<?php echo('true');?>&<?php
}
else
{
	$array_info_url = parse_url(waRetrieveGetServer("HTTP_REFERER"));
	$SITE_REFERER = $array_info_url['host'];
	
	$send_copy_email_to_buyer=waRetrievePostParameter('send_copy_email_to_buyer');
	
	$MAIL_TITLE_PREFIXE = varPostUtf8('MAIL_TITLE_PREFIXE');


	$WA_LABEL_PRINT = varPostUtf8('LABEL_PRINT');
	
	////
	$WA_MAIN_TITLE = varPostUtf8('MAIN_TITLE');
	$WA_PREFIXE_ORDER = varPostUtf8('PREFIXE_ORDER');
//	$WA_ID_ORDER = varPostUtf8('ID_ORDER');
	$WA_CART_TITLE = varPostUtf8('CARD_TITLE');
	$wa_html_cart= varPostUtf8('card_html');
	$wa_market_promo_code=varPostUtf8('wa_promo_code');	
	$wa_has_market_promo_code = (strlen($wa_market_promo_code)>0);
	
	$wa_infos_shipping=varPostUtf8('buyer_info_shipping');
	$wa_infos_billing=varPostUtf8('buyer_info_billing');	
	
	$WA_LABEL_TYPE_PAYMENT = varPostUtf8('LABEL_TYPE_PAYMENT');
	$WA_TYPE_PAYMENT = varPostUtf8('TYPE_PAYMENT');
	
	$WA_MESSAGE_CHECK = varPostUtf8('MESSAGE_CHECK');
	$WA_MESSAGE_WIRE = varPostUtf8('MESSAGE_WIRE');
	////
	
	$PAYPAL_EMAIL="$$WA_PAYPAL_EMAIL";
	
	$WA_PAGSEGURO_EMAIL_ACCOUNT="$$WA_PAGSEGURO_EMAIL_ACCOUNT";
	$WA_PAGSEGURO_TOKEN_ACCOUNT="$$WA_PAGSEGURO_TOKEN_ACCOUNT";
	

	$WA_LABEL_PAYPAL_CART_TITLE = varPostUtf8('LABEL_PAYPAL_CART_TITLE');
	$WA_LABEL_PROCESS_ORDER = varPostUtf8('LABEL_PROCESS_ORDER');
	$WA_LABEL_CHECKOUT_WARNING = varPostUtf8('LABEL_CHECKOUT_WARNING');
	
	$card_plain_text = varPostUtf8('card_plain_text');
	$type_payment=waRetrievePostParameter('type_payment');
	$email_buyer=waRetrievePostParameter('email_buyer');
	$email='$$CRBST_MARKET_EMAIL';
	$WA_LABEL_SELLER_INFORMATION=varPostUtf8('LABEL_SELLER_INFORMATION');
	$wa_check_information=varPostUtf8('seller_address');
	$wa_wire_information=varPostUtf8('bank_account_informations');

	$wa_market_first_name=varPostUtf8('form_first_name');
	$wa_market_last_name=varPostUtf8('form_last_name');
	$wa_market_address1=varPostUtf8('form_address1');
	$wa_market_address2=varPostUtf8('form_address2');
	$wa_market_city=varPostUtf8('form_city');
	$wa_market_zip=varPostUtf8('form_zip');
	$wa_market_state=varPostUtf8('form_state');	
	$wa_market_country=varPostUtf8('form_country');
	
	$wa_market_company=varPostUtf8('form_company');
	$wa_market_fiscal_code=varPostUtf8('form_fiscal_code');
	$wa_market_tva=varPostUtf8('form_tva');
	$wa_market_phone=varPostUtf8('form_phone');
	$wa_market_fax=varPostUtf8('form_fax');
	
	$wa_market_lang=varPostUtf8('CARD_LANG');	
	$wa_market_id_order=varPostUtf8('ID_ORDER');
	$wa_market_total_price=varPostUtf8('CARD_TOTAL_PRICE');
	$wa_market_currency=varPostUtf8('CARD_CURRENCY');
	$wa_market_email_notification=$email;
	$wa_market_email_buyer=$email_buyer;	

	$wa_check_information_plaintext = $wa_check_information;
	$wa_wire_information_plaintext  = $wa_wire_information;
	$wa_infos_shipping_plaintext  = $wa_infos_shipping;
	$wa_infos_billing_plaintext  = $wa_infos_billing;
	
	$wa_check_information = str_replace("\n","<br>",$wa_check_information);
	$wa_wire_information = str_replace("\n","<br>",$wa_wire_information);
	$wa_infos_shipping = str_replace("\n","<br>",$wa_infos_shipping);
	$wa_infos_billing = str_replace("\n","<br>",$wa_infos_billing);
	
	
	//////
	//send email!

	$email_title = $MAIL_TITLE_PREFIXE." (".$SITE_REFERER.") ".$wa_market_id_order." *".$WA_TYPE_PAYMENT."*";
	
	$txt_mail="";
	$txt_mail.= $WA_PREFIXE_ORDER." ".$wa_market_id_order." (".$WA_TYPE_PAYMENT.")\n";
	$txt_mail.= "From:\n";
	$txt_mail.= $SITE_REFERER;
	$txt_mail.= "\n";
	$txt_mail.= $WA_CART_TITLE;
	$txt_mail.= "\n";
	$txt_mail.= $card_plain_text;
	
	if (strlen($wa_market_promo_code)>0)
	{
		$txt_mail.= "PROMO CODE: ";
		$txt_mail.= $wa_market_promo_code."\n";
	}
	
	if (($type_payment=='wire')||($type_payment=='check'))
	{
		$txt_mail.= "\n";
		$txt_mail.= "------------------------\n";
		$txt_mail.= $WA_LABEL_SELLER_INFORMATION."\n";

		if ($type_payment=='wire')
		{
			$txt_mail.= "\n";
			$txt_mail.= $wa_wire_information_plaintext;
			$txt_mail.= "\n";
		}
		if ($type_payment=='check')
		{
			$txt_mail.= "\n";
			$txt_mail.= $wa_check_information_plaintext;
			$txt_mail.= "\n";
		}		
	}
	
	$txt_mail.= "------------------------\n";
	$txt_mail.= $wa_infos_shipping_plaintext;
	$txt_mail.= "\n";
	$txt_mail.= $wa_infos_billing_plaintext;
	$txt_mail.= "\n";
	
	/////

	/////
?>
	$$CRBST_MARKET_INCLUDE_FORM_GLOBAL
<?php
	
	$result_email = waSendMail($email, $email_title, $txt_mail);

	if ($send_copy_email_to_buyer=="1")
	{
		waSendMail($email_buyer, $email_title, $txt_mail);
	}	
}
?>