<?php 
define('T_HOST','83.220.163.100');
define('T_PORT',443);
define('T_CACHEDIR','cache/');




function QueryQuotes($query,$cacheDir=T_CACHEDIR)
{
	$fName = $cacheDir.crc32($query);
	if(file_exists($fName) && (time()-filemtime($fName))<2) 
		readfile($fName);
	else
	{
		$ptr=fsockopen(T_HOST,T_PORT); 
		if($ptr)
		{
			$buf = '';   // collect all data to buffer
			if(fputs($ptr,"WWAP-$query\nQUIT\n")!=FALSE)
			while(!feof($ptr)) 
			{
				$line=fgets($ptr,128); 
				if($line=="end\r\n") break; 
				$buf .= $line; 
			} 
			fclose($ptr);
		}
		else
			$buf = "No Quotes<br/>\r\n"; 
		//--- save to cache
		$fp=@fopen($fName,'w');
		if($fp) { fputs($fp,$buf); fclose($fp); }
	}
	return $buf;
}

function MQ_GetParam($line)
{
	list($para,$sell,$buy) = explode(chr(0x09),$line);
	return array($para,$sell,$buy);
}


header('Content-type: text/vnd.wap.wml');
print( "<?xml version=\"1.0\"?>" );
?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
<meta http-equiv="Content-type" content="text/vnd.wap.wml"/>
<meta http-equiv="Cache-Control" content="no-cache, max-age=0, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
</head>
<card id="forex" title="WAP.FOREX-STREAM.COM: Main" ontimer="wap.wml">



<?php
if($_GET['action']!='')
{
	echo '<timer value="99999"/><p align="center"><img alt=""  src="http://fxteam.ru/charts/'.strtoupper($_GET['action']).'1440_320x200x4.gif"  localsrc="icon" align="center"  height=""  width=""  vspace=""  hspace="" /></p>';
}
else 
{
	echo '<timer value="250"/><p align="center">';
	$res = QueryQuotes('EURUSD,GBPUSD,USDCHF,USDJPY,AUDUSD,USDCAD,EURGBP,EURJPY,EURCHF,GBPJPY,GBPCHF,NZDUSD,EURAUD,USDNOK,USDSEK,USDDKK,USDSGD,CHFJPY,');
	$res=str_replace(array("\r","\n"),array('',''),$res);
	$info = explode("<br/>",$res);
	array_splice($info,-1,1);
	array_splice($info,-1,1);
	foreach($info as $key=>$value)
	{
		$toLink=explode(" ",$value);
		echo '<anchor>'.$value.'<go href="wap.wml?action='.$toLink[0].'"/></anchor><br/>';
	}
	echo '</p>';
}

print '<p align="center">';
print '<anchor>Contacts<go href="about.wml"/></anchor><br/>';
print '<anchor>Login<go href="login.wml"/></anchor><br/>';
print '<anchor>Refresh<go href="'.$_SERVER['REQUEST_URI'].'"/></anchor>';
print '</p>';
print '</card>';
print '</wml>';
?>