<?php
$id = isset( $_GET['id'] ) ? (int) $_GET['id'] : 0;
$_SESSION['click'] = isset( $_SESSION['click'] ) ? (int) $_SESSION['click'] : NULL;
$_SESSION['click_time'] = isset( $_SESSION['click_time'] ) ? $_SESSION['click_time'] : NULL;
if( $_SESSION['click'] || strpos($ua, 'Google') !== false || strpos($ua, 'Yandex') !== false || strpos($ua, 'Rambler') !== false )
{
redirect('http://' . $_SERVER['HTTP_HOST'] . gen_uri('index', $id, $nocache, '', false));
}
if( !$sql->query("SELECT * FROM `" . CATALOGUE_SITES . "` WHERE `id` = " . $id . ";") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( $sql->num_rows() < 1 )
{
redirect('http://' . $_SERVER['HTTP_HOST'] . gen_uri('index', '', $nocache, '', false));
}
$site = $sql->fetch_assoc();
$query = "SELECT * FROM `" . CATALOGUE_IPS . "` WHERE INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "') BETWEEN `start_ip` AND `end_ip`;";
if( !$sql->query($query) )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$_SESSION['mp'] = $sql->num_rows() > 0 ? $sql->result($sql->result, 0, 'provider_id') : 0;
if( $_SESSION['mp'] == 0 && $site['in_today_all'] >= 5 && ($site['in_today_mp'] * 100) / $site['in_today_all'] < $config['mp_percent'] )
{
if( $site['black_list'] == false && $site['owner'] == 'user' )
{
if( !$sql->query("INSERT INTO `" . CATALOGUE_LOGS . "` SELECT * FROM `" . CATALOGUE_CLICKS . "` WHERE `site_id` = " . $id . ";") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( !$sql->query("UPDATE `" . CATALOGUE_SITES . "` SET `black_list` = 1 WHERE `id` = " . $id . ";") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
}
redirect('http://' . $_SERVER['HTTP_HOST'] . gen_uri('index', $id, $nocache, '', false));
}
else if( $_SESSION['mp'] && $site['in_today_all'] >= 5 )
{
if( !$sql->query("SELECT COUNT(*) FROM `" . CATALOGUE_CLICKS . "` WHERE `provider_id` = " . $_SESSION['mp'] . ";") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$pp = $site['in_today_all'] ? ($sql->result($sql->result, 0) * 100) / $site['in_today_all'] : NULL;
if( $pp > $config['provider_percent'] )
{
redirect('http://' . $_SERVER['HTTP_HOST'] . gen_uri('index', $id, $nocache, '', false));
}
}
$crc_32 = crc32( $_SERVER['REMOTE_ADDR'] . $ua );
if( !$sql->query("SELECT COUNT(*) FROM `" . CATALOGUE_CLICKS . "` WHERE `site_id` = " . $id . " AND `crc32` = " . $crc_32 . " AND `dt` > UNIX_TIMESTAMP() - 10800;") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( $sql->result($sql->result, 0) > 0 || $_SESSION['click'] > time() - 10800 )
{
redirect('http://' . $_SERVER['HTTP_HOST'] . gen_uri('index', $id, $nocache, '', false));
}
$_SESSION['click'] = $id;
$_SESSION['click_ip'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['click_ua'] = $ua;
redirect('http://' . $_SERVER['HTTP_HOST'] . gen_uri('index', $id, $nocache, '', false));
?>