<?
header("Content-type: application/json");



$q=parse_url($_SERVER['REQUEST_URI'])["query"];
parse_str($q,$_GET);
$ip=ip2long($_GET['ip']);

if(!$ip)
  die;

require_once("inc/goods.php");

$res=array();
foreach ($goods as $ads) {
	$ad=$ads[mt_rand(1,10000)%sizeof($ads)];
	$data=$ad['data'][$ip%sizeof($ad['data'])];
	unset($ad['data']);
	$ad['price']=str_replace('${price}', $data['price'], $ad['price']);
	$ad['ad_id'].="_".$data['l_path'];

	$ad['link'] ="//".$_SERVER['HTTP_HOST'].'/tgo?l='.$ad['link'].$data['l_path'].'&s='.$ad['ad_id'];
	$ad['image']= "//".$_SERVER['HTTP_HOST'].'/timg/'.$ad['image'];
  $ad['cpc']=0.02;
	$res[]=$ad;
}

$out=array('nurl'=>"//".$_SERVER['HTTP_HOST'].'/tnurl?ids=${AD_IDS}','data'=>$res);

echo json_encode($out,  JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
