<?php
require_once('Sys/connect.php');
require_once('Sys/core.php');
require_once('Sys/function.php');
if(!$id OR $id < 1)
	{
		exit('Не верно введен ID');
	}
$isset = $mysqli->query("SELECT `id`,`url` FROM `".$prefix."sait` WHERE `status` != '0' AND `id` = '".$id."'");
if($isset->num_rows == 0)
	{
		exit('Данного сайт нет , либо он не активирован.');
	}
$sait = $isset->fetch_assoc();
$mysqli->query("UPDATE `".$prefix."stats` SET `value` = (`value` + 1) WHERE `name` = 'out'");
$mysqli->query("UPDATE `".$prefix."stats` SET `value` = (`value` + 1) WHERE `name` = 'allOut'");
$mysqli->query("UPDATE `".$prefix."sait` SET `out` = (`out` + 1), `allOut` = (`allOut` + 1) WHERE `id` = '".$id."'");
$day = $mysqli->query("SELECT * FROM `".$prefix."days` WHERE `sid` = '".$id."' AND `month` = '".date("m")."'");
if($day->num_rows > 0)
	{
		$dayRow = $day->fetch_assoc();
		if(!empty($dayRow[''.date("d").'']))
			{
				$dayArray = explode('|',$dayRow[''.date("d").'']);
				$mysqli->query("UPDATE `".$prefix."days` SET `".date("d")."` = '".$dayArray[0]."|".$dayArray[1]."|".$dayArray[2]."|".($dayArray[3] + 1)."' WHERE `sid` = '".$id."' AND `month` = '".date("m")."'");
			}
		else
			{
				$mysqli->query("UPDATE `".$prefix."days` SET `".date("d")."` = '0|0|0|1' WHERE `sid` = '".$id."' AND `month` = '".date("m")."'");
			}
	}
else
	{
		$mysqli->query("INSERT INTO `".$prefix."days` SET `sid` = '".$id."', `month` = '".date("m")."', `".date("d")."` = '0|0|0|1'");
	}
$month = $mysqli->query("SELECT * FROM `".$prefix."month` WHERE `sid` = '".$id."'");
if($month->num_rows > 0)
	{
		$monthRow = $month->fetch_assoc();
		if(!empty($monthRow[''.date("m").'']))
			{
				$monthArray = explode('|',$monthRow[''.date("m").'']);
				$mysqli->query("UPDATE `".$prefix."month` SET `".date("m")."` = '".$monthArray[0]."|".$monthArray[1]."|".$monthArray[2]."|".($monthArray[3] + 1)."' WHERE `sid` = '".$id."'");
			}
		else
			{
				$mysqli->query("UPDATE `".$prefix."month` SET `".date("m")."` = '0|0|0|1' WHERE `sid` = '".$id."'");
			}
	}
else
	{
		$mysqli->query("INSERT INTO `".$prefix."month` SET `sid` = '".$id."', `".date("m")."` = '0|0|0|1'");
	}
$hour = (int)date("H");
if($hour == 23)
	{
		$hourD = '23:00-00:00';
	}
else
	{
		if(strlen($hour) == 1)
			{															
				$hourr = '0'.$hour;														
			}
		else
			{
				$hourr = $hour;										
			}
		if(strlen($hour + 1) == 1)
			{
				$hour2 = '0'.($hour + 1);
			}
		else
			{
				$hour2 = $hour + 1;
			}
		$hourD = ''.$hourr.':00-'.$hour2.':00';
	}
$hours = $mysqli->query("SELECT * FROM `".$prefix."hours` WHERE `sid` = '".$id."'");
if($hours->num_rows > 0)
	{
		$hoursRow = $hours->fetch_assoc();
		if(!empty($hoursRow[''.$hourD.'']))
			{
				$hoursArray = explode('|',$hoursRow[''.$hourD.'']);
				$mysqli->query("UPDATE `".$prefix."hours` SET `".$hourD."` = '".$hoursArray[0]."|".$hoursArray[1]."|".$hoursArray[2]."|".($hoursArray[3] + 1)."' WHERE `sid` = '".$id."'");
			}
		else
			{
				$mysqli->query("UPDATE `".$prefix."hours` SET `".$hourD."` = '0|0|0|1' WHERE `sid` = '".$id."'");
			}
	}
else
	{
		$mysqli->query("INSERT INTO `".$prefix."hours` SET `sid` = '".$id."', `".$hourD."` = '0|0|0|1'");
	}
header('Location: http://'.$sait['url']);
?>