<?php
    
    
    
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';



$banss='84300';

if(!isset($user))
{
echo"Доступ закрыт не авторизированым пользователям<br />";
include_once '../sys/inc/tfoot.php';
exit();
}

if(isset($_GET['mod']))
{
$mod = $_GET['mod'];
}
else
{
$mod = "";
}

switch($mod)
{


case 'go':
$prise='5';

	if(!isset($_GET['id']))
	{
	echo"Произошла ошибка<br />";
	}
	else
	{
	$id =intval($_GET['id']);
	$q=mysql_query("SELECT * FROM `balls_list` WHERE `id` = '$id'");
			if(@mysql_affected_rows() > 0)
		{
		$m=mysql_fetch_array($q);

				mysql_query("DELETE FROM `balls_go` WHERE `time` < '".(time()-$banss)."' ");
				$qw = mysql_query("SELECT * FROM `balls_go` WHERE `id_user` = '$user[id]' && `id_link` = '$m[id]' && `time` > '".(time()-$banss)."'");
				if(@mysql_affected_rows() > 0)
				{
				$m=mysql_fetch_array($qw);
				echo"Переходить по одной и тойже сылке можна не чаще чем раз в 24 часа<br />\nВаш последний переход: ".vremja($m['time'])."\n<br />";
				}
				else
				{
				mysql_query("INSERT INTO `balls_go` SET `id_user` = '$user[id]', `id_link` = '$m[id]', `time` ='".time()."';");     
				mysql_query("UPDATE `balls_list` SET `kol` = '".($m['kol']+1)."' WHERE `id` ='$m[id]';");
				mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+$m['prise'])."' WHERE `id` ='$user[id]';");				
				header("Location: $m[url]");
				echo"<a href='$m[url]'>Переходим..</a><br />";			
				}	
		}
		else
		{
		echo"Произошла ошибка<br />";		
		}
	
	}

break;
default:

//$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `balls_list`"),0);
$i='0';
$q=mysql_query("SELECT * FROM `balls_list` ORDER by `id` DESC");
while($post=mysql_fetch_array($q))
{
$qw = mysql_query("SELECT * FROM `balls_go` WHERE `id_user` = '$user[id]' && `id_link` = '$post[id]' && `time` > '".($time-$banss)."'");
if(@mysql_affected_rows() <= 0)
{
$i++;
}
}
if ($i==0)
{

}
$q=mysql_query("SELECT * FROM `balls_list` ORDER by `id` DESC");
while($post=mysql_fetch_array($q))
{
$qw = mysql_query("SELECT * FROM `balls_go` WHERE `id_user` = '$user[id]' && `id_link` = '$post[id]' && `time` > '".($time-$banss)."'");
if(@mysql_affected_rows() <= 0)
{
echo"<a href='?mod=go&amp;id=$post[id]'>$post[name]</a> ($post[prise] баллов)<br />\n";
}
}

break;
}

?>