Location: PHPKode > projects > phpCAMALEO > common/includes/oanda.inc
<?php
#=============================================
#
#	include for GetText.php
#
#=============================================
$beg=$test+strlen($str_to_search);
$end=strpos($record,'=',$beg);
$from_currency=substr($record,$beg,$end-$beg);
$eur_to_usd=$_SESSION[eur_to_usd];
#
# $eur_to_usd=0; # debug
#
if($eur_to_usd==0) 
{
	# http://www.oanda.com/convert/classic?exch=EUR&expr=USD&value=1
	#
	include_once($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'fun2inc/get_http_header.inc');	# 9 Oct 2006
	$oanda=get_http_header('www.oanda.com','/convert/classic?exch=EUR&expr=USD&value=1','all','raw');
	#
	# Excerpt of the oanda page:
	#
	#		<!-- conversion result starts  --> 
	#				<p>
	#		            <b><font color="#153168"> <font color="#bc0a17">1</font> 
	#		              Euro = <font color="#bc0a17"> 1.29090</font> 
	#		              US Dollar </font></b> <!-- conversion result ends  --> <br>
	#
	#--- Isolate the previous excerpt into $tmp
	#
	$str_to_search='<!-- conversion result starts  -->';
	$str_to_end='<!-- conversion result ends  -->';
	$beg_rate=strpos($oanda, $str_to_search,0)+strlen($str_to_search);
	if($beg_rate==strlen($str_to_search))
	{
		#
		#--- Did not found $str_to_search
		#
		$tmp=1.33322; 		# $39,99 -> €29,99
	}
	else
	{
		$end_rate=strpos($oanda,$str_to_end,$beg_rate);
		$tmp=substr($oanda,$beg_rate,$end_rate-$beg_rate);
		#
		#--- Isolate the exchange rate into $tmp
		#
		$str_to_search='Euro =';
		$tmp1=strpos($tmp,$str_to_search,0);

		$str_to_search='">';
		$tmp1=strpos($tmp,$str_to_search,$tmp1);
		$str_to_end='</font>';
		$beg_rate=strpos($tmp,$str_to_search,$tmp1)+strlen($str_to_search);
		$end_rate=strpos($tmp,$str_to_end,$beg_rate);
		$tmp=substr($tmp,$beg_rate,$end_rate-$beg_rate);
		$tmp=str_replace(' ','',$tmp);
	}
	#
	#--- Get the exchange rate
	#
	if($tmp<=0)
	{
		include_once($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'fun2inc/send_email_once.inc');	# 9 Oct 2006
		$subject = 'WARNING: Something is going wrong at OANDA.com!';
		$body 	 = 'Please check the exchange need at '.
					'http://www.oanda.com/convert/classic?exch=EUR&expr=USD&value=1 '.
					'as it is now set to: 1 EUR = '.$tmp.' USD !!'.
					"\nMost probably the page is changed =(".
				    "\n\nThis email is generated by GetText.php\n\n*End of email*";
		$result=send_email_once($_SESSION[misc][E_ADMIN],'','',$subject,$body,'1','*oanda');
		$tmp=1.33322; 		# $39,99 -> €29,99
	}
	$eur_to_usd=$tmp;
	$_SESSION[eur_to_usd]=$tmp;
	if($tmp<1.25007 || $tmp>1.42872)
	{
		include_once($_SERVER[DOCUMENT_ROOT].$_SESSION[misc][folder].'fun2inc/send_email_once.inc');	# 9 Oct 2006
		$subject = 'WARNING: Check the $/€ exchange rate at OANDA.com!';
		$body    = 'Please check the exchange rate at '.
				   'http://www.oanda.com/convert/classic?exch=EUR&expr=USD&value=1 '.
				   'as it is now set to: 1 EUR = '.$tmp.' USD.'.
				   "\n\nWith this value the price in € differs more than the allowed delta (€2). ".
				   'The actually allowed "single license" price range is € 27,99-31,99.'.
				   "\n\nThis email is generated by GetText.php\n\n*End of email*";
		$result=send_email_once($_SESSION[misc][E_ADMIN],'','',$subject,$body,'1','*oanda');
	}
}
#
#--- Replace the converted value
#
$tmp=substr($record,$end+1,strlen($record));
$record=substr($record,0,$beg);
switch ($currency)
{
	case 'USDtoEUR':
		$end_currency=$from_currency/$eur_to_usd;
		$record=str_replace('PHP=USDtoEUR',number_format($end_currency,2,',','.'),$record);
		break;

	case 'EURtoUSD':
		$end_currency=$from_currency*$eur_to_usd;
		$record=str_replace('PHP=EURtoUSD',number_format($end_currency,2,'.',','),$record);
		break;

	default:
		#-- Do nothing
}
$record.=$tmp;
?>
Return current item: phpCAMALEO