<?php
include ("func/ini.php");
###    ###
// on-off
$perehod="off";
####    ####
$sites_opsos=array(
'http://...');
$s_opsos=rand(0,3);
$url_opsos=$sites_opsos[$s_opsos];
####   OperaMini ####
$sites_opera=array(
'http://...'
);
$s_opera=rand(0,3);
$url_opera=$sites_opera[$s_opera];
####    ####
$sites_other=array(
'http://...'
);
$s_other=rand(0,3);
$url_other=$sites_other[$s_other];
###################################################
if(!isset($_GET['check']))
{
$tmp_file = strtolower(md5(uniqid()));
$tmp_fd = fopen('./go/'.$tmp_file,'w');
$data['id'] = @$_GET['id'];
$data['ip'] = @$_SERVER['REMOTE_ADDR'];
$data['refer'] = @$_SERVER['HTTP_REFERER'];
$ua = explode('/',addslashes(@$_SERVER['HTTP_USER_AGENT']));
$data['ua'] = $ua[0];
fputs($tmp_fd,serialize($data));
header("Content-type: text/vnd.wap.wml; charset=utf-8");
header("Cache-Control: no-cache");
if ($perehod=="on")
{
echo'<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC"-//WAPFORUM//DTD WML 1.2//EN""http://www.wapforum.org/DTD/wml1.2.dtd">
<wml>
<head><metahttp-equiv="Cache-Control"content="no-cache"forua="true"/></head>
<cardid="index"title="..."ontimer="click.php?check='.$tmp_file.'">
<timervalue="1"/>
<palign="left"><small><ahref="click.php?check='.$tmp_file.'">  ...</a><br/></small></p></card></wml>';
}else{
header ("Location: click.php?check=$tmp_file");
}}else{
$check = str_replace('.','',$_GET['check']);
$data = @unserialize(file_get_contents('./go/'.$check));
@unlink('./go/'.$check);
if($data){
$agent = an($_SERVER['HTTP_USER_AGENT']);
$ip = an($_SERVER['REMOTE_ADDR']);
$id = intval($data['id']);
$referer = $data['refer'];
}else{
header ("Location: click.php?check=$tmp_file");
die();
}
// 
include ("func/oper.php");
//  
$url = $url_opsos;
if ($oper=='32') { $url = $url_opera; }
if ($oper=='0') { $url = $url_other; }
//  
$datepp=date("Ymd");
if ($data['refer']!=''){
$fp = fopen ("stlogsto/".$id.".log", "a+");
if ($oper==0) $oper_name="<b>HE OPSOS!</b>";
fwrite ($fp, $date."||".$oper_name."||".$agent."||".$ip."||<b>".$referer."</b>\n");
fclose ($fp);
}else{$k=1;}
// 
$q = mysql_query("select *,INET_NTOA(`ip`) AS `ip` from `statistika` where (`id`='$id' && DATE(`date`)=CURRENT_DATE);");
while ($row = mysql_fetch_array($q)){
$ip_stat = $row['ip'];
$agent_stat = $row['agent'];
#if ($ip_stat==$ip && $agent_stat==$agent){ IP + UA
if ($ip_stat==$ip){$k=1;} #IP
}
//  
if (($otk[$oper]!=0) && $k!=1){
$qi = mysql_query("select * from `uzvers` where `id`='$id';");
$row=mysql_fetch_array($qi);
$partid = $row['partid'];
$ppid = $row['ppid'];
$all = $cena[$oper]/$c;
$timer = date("H:i");
mysql_query("insert into statistika set id='$id',date=NOW(),agent='$agent',oper='$oper',ip=INET_ATON('$ip'),referer='$referer'");
mysql_query("UPDATE `uzvers` SET `allmonth`=`allmonth`+'$all' WHERE `id`='$id';");
$partall=$cena[$oper]/$c/100*$partproc;
mysql_query("UPDATE `uzvers` SET `allmonth`=`allmonth`+'$partall' WHERE `id`='$partid';");
}
//  =)
$q = mysql_query("select * from traf where (`vkl`='1' && `zayavka`='0') ;");
$traf = mysql_fetch_array($q);
$trff = intval($traf['num']);
if ($trff != 0){
#   
if ($traf['oper'] =='comp'){
if ($oper == 1){
$url = $traf['link'];
mysql_query("UPDATE `traf` SET `num`=`num`-1 WHERE `id`='".$traf['id']."';");
header ("Location: ".$url);
die();
}
}
#    
if ($traf['oper'] =='ru'){
if ( ($oper == 1) || ($oper == 2) || ($oper == 3) || ($oper == 4) || ($oper == 5) || ($oper == 6) || ($oper == 7) || ($oper ==|| ($oper == 9) ||
($oper == 10) || ($oper == 11) || ($oper == 12) || ($oper == 13) || ($oper == 14) || ($oper == 15) || ($oper == 16) || ($oper == 37) || ($oper == 3||
($oper == 42) || ($oper == 45) || ($oper == 46) || ($oper == 47) || ($oper == 4|| ($oper == 49) || ($oper == 50) || ($oper == 82) )
{
$url = $traf['link'];
mysql_query("UPDATE `traf` SET `num`=`num`-1 WHERE `id`='".$traf['id']."';");
header ("Location: ".$url);
die();
}
}
#    
if ($traf['oper'] =='eu'){
if ( ($oper != 1) || ($oper != 2) || ($oper != 3) || ($oper != 4) || ($oper != 5) || ($oper != 6) || ($oper != 7) || ($oper !=|| ($oper != 9) ||
($oper != 10) || ($oper != 11) || ($oper != 12) || ($oper != 13) || ($oper != 14) || ($oper != 15) || ($oper != 16) || ($oper != 37) || ($oper != 3||
($oper != 42) || ($oper != 45) || ($oper != 46) || ($oper != 47) || ($oper != 4|| ($oper != 49) || ($oper != 50) || ($oper != 82) )
{
$url = $traf['link'];
mysql_query("UPDATE `traf` SET `num`=`num`-1 WHERE `id`='".$traf['id']."';");
header ("Location: ".$url);
die();
}
}
#  
if ($traf['oper'] =='bee'){
if ($oper == 2){
$url = $traf['link'];
mysql_query("UPDATE `traf` SET `num`=`num`-1 WHERE `id`='".$traf['id']."';");
header ("Location: ".$url);
die();
}}
#  
if ($traf['oper'] =='mts'){
if ($oper == 5){
$url = $traf['link'];
mysql_query("UPDATE `traf` SET `num`=`num`-1 WHERE `id`='".$traf['id']."';");
header ("Location: ".$url);
die();
}}
#  
if ($traf['oper'] =='mega'){
if ($oper == 1){
$url = $traf['link'];
mysql_query("UPDATE `traf` SET `num`=`num`-1 WHERE `id`='".$traf['id']."';");
header ("Location: ".$url);
die();
}}
#  
if ($traf['oper'] =='all'){
$url = $traf['link'];
mysql_query("UPDATE `traf` SET `num`=`num`-1 WHERE `id`='".$traf['id']."';");
header ("Location: ".$url);
die();
}}else{
mysql_query("UPDATE `traf` SET `vkl`=0 WHERE `id`='".$traf['id']."';");
}
header ("Location: ".$url);
}
?>