<?php
function getip() {
if(getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif(getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} else {
$ip = getenv("REMOTE_ADDR");
}
return $ip;
}
include "../cfg.php";
$id = intval($_GET['id']);
$get_user_info = mysql_query("SELECT no_adult, adult, url, user_id FROM webmasters WHERE id = ".$id." AND status != 2 LIMIT 1");
$row = mysql_fetch_array($get_user_info);
$no_adult = $row['no_adult'];
$adult = $row['adult'];
$urlwm = $row['url'];
$wm_id = $row['user_id'];
$sql = "";
if(!$no_adult) {
$sql .= " AND adult = 0";
}
if($adult) {
$sql .= " AND no_adult != 1";
}
// --------- ПОЕХАЛИ ---------
if($row) {
$hash=md5($key.$_SERVER['REMOTE_ADDR']);
if ($_GET['hash']!=$hash)
{
$f=fopen("log.txt","a");
fputs($f,$wm_id."\t".$id."\t".$_SERVER['REMOTE_ADDR']."\t".date("Y-m-d H:i:s")."\t".$_SERVER['HTTP_REFERER']."\t".$_SERVER['HTTP_USER_AGENT']."\n");
fclose($f);
}
$ip = getip(); // Переменная с IP
$brauzer = $_SERVER["HTTP_USER_AGENT"]; // Браузер
$count = mysql_num_rows(mysql_query("SELECT id FROM popup WHERE clx > 0 AND status = 0"));
if($count == 0) {
print "<html><head><script language=\"javascript\">top.location.href=\"".$cfgPartnerSiteUrl."\";</script></head></html>";
} else {
$nums = rand(0, $count - 1);
$cfgPouseClick = time() - 300;
$get_popup = mysql_query("SELECT id, url, user_id FROM popup WHERE clx > 0 AND status = 0".$sql." LIMIT ".$nums.",1");
$row = mysql_fetch_array($get_popup);
$sid = $row['id'];
$url = $row['url'];
$user_id = $row['user_id'];
$time = time() - 86400;
$count_click = mysql_num_rows(mysql_query("SELECT id FROM log_popup WHERE (ip = '".$ip."' AND date > ".$time.") OR (brouser = '".$brauzer."' AND date > ".$cfgPouseClick.")"));
if($count_click) {
print "<html><head><script language=\"javascript\">top.location.href=\"http://blowclick.ru</script></head></html>";
} else {
$one_porcent = $cfgPopUp / 100;
$admin_percent = sprintf("%01.4f", $one_porcent * $cfgPopUpPerc);
$wm_percent = $cfgPopUp - $admin_percent;
$pRefSum = 0; // Сумма рефералу
if(!chan($cfgLohotron)) {
mysql_query("UPDATE users SET balance=balance+".$wm_percent." WHERE id=".$wm_id." LIMIT 1");
mysql_query("UPDATE users SET recconcurs=recconcurs+".$wm_percent." WHERE id=".$user_id." LIMIT 1");
mysql_query("UPDATE webmasters SET clx_today=clx_today+1, m_today=m_today+".$wm_percent." WHERE id=".$id." LIMIT 1");
// Дошла очередь и до рефералов
$sql = "SELECT ref_id FROM users WHERE id = ".$wm_id." LIMIT 1";
$wmr = mysql_query($sql);
$row = mysql_fetch_array($wmr);
$wm_ref = $row['ref_id']; // ID реферала ВЕБ-мастера
$sql = "SELECT ref_id FROM users WHERE id = ".$user_id." LIMIT 1";
$advr = mysql_query($sql);
$row = mysql_fetch_array($advr);
$rek_ref = $row['ref_id']; // ID реферала рекламодателя
if($rek_ref != 0) {
$pRefSum = sprintf("%01.4f", $admin_percent / 100 * $cfgRefPerc);
mysql_query("UPDATE users SET balance=balance+".$pRefSum.", ref_money=ref_money+".$pRefSum." WHERE id=".$rek_ref." LIMIT 1");
mysql_query("UPDATE users SET ref_money=ref_money+".$pRefSum." WHERE id=".$user_id." LIMIT 1");
}
if($wm_ref != 0) {
$pRefSum = sprintf("%01.4f", $admin_percent / 100 * $cfgRefPerc);
mysql_query("UPDATE users SET balance=balance+".$pRefSum.", ref_money=ref_money+".$pRefSum." WHERE id=".$wm_ref." LIMIT 1");
mysql_query("UPDATE users SET ref_money=ref_money+".$pRefSum." WHERE id=".$wm_id." LIMIT 1");
}
// Закончили с рефералами
$fn = "yes.txt";
$f = fopen($fn, "a+");
fwrite($f, "1");
fclose($f);
} else {
$fn = "no.txt";
$f = fopen($fn, "a+");
fwrite($f, "1");
fclose($f);
}
mysql_query("UPDATE popup SET clx=clx-1, count=count+1 WHERE id=".$sid." LIMIT 1");
mysql_query("INSERT INTO log_popup (date, ip, idw, ids, price, url, brouser, fromurl) VALUES (".time().", '".$ip."', ".$id.", ".$sid.", ".$cfgPopUp.", '".$urlwm."', '".$brauzer."', '".$_SERVER['REMOTE_ADDR']."')");
// МЕСТО ГДЕ МОЖНО ПИСАТЬ СТАТИСТИКУ АДМИНУ
$date = date("d.m.Y");
mysql_query("UPDATE logs SET popup = popup + ".$admin_percent." WHERE date = '".$date."' LIMIT 1");
print "<html><head><script language=\"javascript\">top.location.href=\"".$url ."\";</script></head></html>";
}
}
} else {
print "<html><head><script language=\"javascript\">top.location.href=\"".$cfgSiteUrl."\";</script></head></html>";
}
?>