<?php
session_start();
define('NTOP', 1);
$title = 'Информация о сайте';
require_once('../system/connect.php');
require_once('../system/core.php');
require_once('../system/function.php');
require_once('head.php');
$isset = mysql_query("SELECT * FROM `".$prefix."sait` WHERE `id` = '".$id."'");
if(mysql_num_rows($isset) == 0)
	{
		echo '<div class="error">';
		echo 'Сайта нет в базе! <br/>';
		echo '</div>';
	}
else
	{	
		$online_sait = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait_online` WHERE `id_sait` = '".$id."'"));
		$user = mysql_fetch_array($isset);
		if($user['ban'] == 1)
			{
				echo '<div class="error">';
				echo 'Сайта забанен! <br/>';
				echo '</div>';
				require_once('foot.php');
				exit;
			}
		if($user['status'] == 0)
			{
				echo '<div class="error">';
				echo 'Вы не можете смотреть статистику данного сайта , так как он проходит модерацию! <br/>';
				echo '</div>';
				require_once('foot.php');
				exit;
			}
				echo '<div class="top"><div class="title2"><font color="#fff"><strong>'.$user['url'].'</strong> <small>('.$online_sait.' чел. онлайн)</small></font></div><div class="clear"></div></div>';
				switch($act)
					{
						default:

						$category = mysql_fetch_array(mysql_query("SELECT * FROM `".$prefix."cat` WHERE `id` = '".$user['category']."'"));
						$rat_plus = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."reputation` WHERE `id_sait` = '".$id."' AND `type` = 'plus'"));
						$rat_minus = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."reputation` WHERE `id_sait` = '".$id."' AND `type` = 'minus'"));
						$all_rat = $rat_plus + $rat_minus;
						if($rat_plus > 0)
							{
								$procent_plus = round(($rat_plus/$all_rat)*100,1);
							}
						else
							{
								$procent_plus = '0';
							}
						if($rat_minus > 0)
							{
								$procent_minus = round(($rat_minus/$all_rat)*100,1);
							}
						else
							{
								$procent_minus = '0';
							}
						$proverka_reputation = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."reputation` WHERE `ip` = '".$ip."' AND `time` > '".(time()-86400)."' AND `id_sait` = '".$id."'"));
						echo '<div class="main"><strong>Общее</strong><br/>';
						echo 'Адрес: <a href="http://'.$set['home'].'/out/'.$user['id'].'"><strong>'.$user['url'].'</strong></a><br/>';
						echo 'Категория: <a href="http://'.$set['home'].'/m/category/view/'.$user['category'].'"><strong>'.$category['name'].'</strong></a><br/>';
						echo 'Описание: '.$user['about'].'</div>
<div class="main"><strong>Сегодня</strong><br />
Хосты: '.$user['hosts'].' | Хиты: '.$user['hits'].'<br />
В топ: '.$user['in'].' | Из топа: '.$user['out'].'</div>
<div class="main"><strong>Вчера</strong><br />
Хосты: '.$user['of_hosts'].' | Хиты: '.$user['of_hits'].'<br />
В топ: '.$user['of_in'].' | Из топа: '.$user['of_out'].'</div>
<div class="main"><strong>Всего</strong><br />
Хосты: '.$user['all_hosts'].' | Хиты: '.$user['all_hits'].'<br />
В топ: '.$user['all_in'].' | Из топа: '.$user['all_out'].'</div>';
						
			
			echo '<div class="main">Статистика :<br/>';
			echo '<strong>Информация о сайте</strong> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/all">Общая</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/hours">По часам</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/ip">По IP</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/operators">По операторам</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/online">По Онлайн</a>';
			echo '</div>';
				break;
	case 'all':
		$online = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait_online` WHERE `id_sait` = '".$id."'"));
	echo '<div class="navi3"><table width="100%" border="0" cellspacing="1" cellpadding="2">
	<tr class="table_name">
	<td colspan=2>Сегодня</span></td></tr>
	<tr class="main"><td>Хосты:</td> <td>'.$user['hosts'].'</td></tr>
	<tr class="main"><td>Хиты:</td> <td>'.$user['hits'].'</td> </tr>
	<tr class="main"><td>В ТОП:</td> <td>'.$user['in'].'</td> </tr>
	<tr class="main"><td>ИЗ ТОПА:</td> <td>'.$user['out'].'</td> </tr>

	<tr class="table_name">
	<td colspan=2>Вчера</span></td></tr><tr>
	<tr class="main"><td>Хосты:</td> <td>'.$user['of_hosts'].'</td></tr>
	<tr class="main"><td>Хиты:</td> <td>'.$user['of_hits'].'</td> </tr>
	<tr class="main"><td>В ТОП:</td> <td>'.$user['of_in'].'</td> </tr>
	<tr class="main"><td>ИЗ ТОПА:</td> <td>'.$user['of_out'].'</td> </tr>

	<tr class="table_name">
	<td colspan=2>Всего</span></td></tr><tr>
	<tr class="main"><td>Хосты:</td> <td>'.$user['all_hosts'].'</td></tr>
	<tr class="main"><td>Хиты:</td> <td>'.$user['all_hits'].'</td> </tr>
	<tr class="main"><td>В ТОП:</td> <td>'.$user['all_in'].'</td> </tr>
	<tr class="main"><td>ИЗ ТОПА:</td> <td>'.$user['all_out'].'</td> </tr></table>';
		echo '</div><div class="main">Статистика :<br/>';
		echo '<a href="http://'.$set['home'].'/stats/'.$id.'">Информация о сайте</a> | <strong>Общая</strong> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/hours">По часам</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/ip">По IP</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/operators">По операторам</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/online">По Онлайн</a></div>';
		break;
	  case 'hours':
	echo '<div class="navi3"><tr class="navi3">
	<table width="100%" border="0" cellspacing="1" cellpadding="2">
	<tr class="table_name"><td>Промежуток времени</td><td>Хосты</td><td>Хиты</td></div>';
		for($hour = 0; $hour< 24; $hour++)
		{
		$start_time = mktime($hour, 0, 0, date("m"), date("d"), date("Y"));
		$finish_time = mktime($hour+1, 0, 0, date("m"), date("d"), date("Y"));
		$hosts = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."hosts` WHERE `time` BETWEEN '".$start_time."' AND '".$finish_time."' AND `id_sait` = '".$id."'"));
		$hits = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."hits` WHERE `time` BETWEEN '".$start_time."' AND '".$finish_time."' AND `id_sait` = '".$id."'"));
			if(strlen($hour) == 1)
			{
			$hour = '0'.$hour;
			}
			if(strlen($hour + 1) == 1)
			{
			$f = '0'.($hour + 1);
			}
				else
			{
			$f = $f + 1;
			}
     if($hosts > 0 || $hits > 0){
		echo '<tr class="main"><td>'.$hour.':00 - '.($f).':00</td> <td>'.$hosts.'</td> <td>'.$hits.'</td></tr>';
             }
		}
		echo '</table>';
	echo '</div><div class="main">Статистика :<br/>';
	echo '<a href="http://'.$set['home'].'/stats/'.$id.'">Информация о сайте</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/all">Общая</a> | <strong>По часам</strong> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/ip">По IP </a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/operators">По операторам</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/online">По Онлайн</a></div>';
		break;
	case 'ip':
		$start_time = mktime(00, 00, 00, date("m"), date("d"), date("Y"));
		$finish_time = mktime(23, 59, 59, date("m"), date("d"), date("Y"));
		$al = mysql_query("SELECT COUNT(`ip`) FROM `".$prefix."hits` WHERE `time` BETWEEN '".$start_time."' AND '".$finish_time."' AND `id_sait` = '".$id."'");
		$all = mysql_result($al,0);
		$count = mysql_num_rows(mysql_query("SELECT DISTINCT `ip` as `ip`, COUNT(`ip`) AS `count` FROM `".$prefix."hits` WHERE `time` BETWEEN '".$start_time."' AND '".$finish_time."' AND `id_sait` = '".$id."' GROUP BY `ip`"));
			if($count > 0)
		{
		echo '<div class="navi3"><tr class="navi2">
		<table width="100%" border="0" cellspacing="1" cellpadding="2">
		<tr class="table_name"><td>IP</td><td>Хиты</td><td>Проценты</td></tr>';
	$total=intval(($count-1)/$pages)+1; 
	$page=abs(intval($_GET['page'])); 
	if(empty($page) OR $page < 0)
	{
	$page = 1; 
	}
	if($page > $total)
	{
	$page = $total; 
	}
	$past=intval($count/$pages);  
	$start=$page*$pages-$pages; 
	     $query = mysql_query("SELECT DISTINCT `ip` as `ip`, COUNT(`ip`) AS `count` FROM `".$prefix."hits` WHERE `time` BETWEEN '".$start_time."' AND '".$finish_time."' AND `id_sait` = '".$id."'  GROUP BY `ip` LIMIT ".$start.",".$pages."");
		while($stata = mysql_fetch_array($query))
		{
		$procent = ($stata['count'] / $all) * 100;
		echo '<tr class="main"><td>'.$stata['ip'].'</td> <td>'.$stata['count'].'</td> <td>'.round($procent, 1).'%</td</tr>';
		}
		echo '</table></div>';
	navigation($count,$pages,$page,'http://'.$set['home'].'/stats/'.$id.'/ip/',$total);
		}
	else
		{
		echo 'Нет статистики по IP для этого сайта сегодня.<br/>';
		}
	echo '</div><div class="main">Статистика :<br/>';
	echo '<a href="http://'.$set['home'].'/stats/'.$id.'">Информация о сайте</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/all">Общая</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/hours">По часам</a> | <strong>По IP</strong> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/operators">По операторам</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/online">По Онлайн</a></div>';
	break;
	     case 'operators':
$start_time = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$finish_time = mktime(23, 59, 59, date("m"), date("d"), date("Y"));
$all = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."hits` WHERE `time` BETWEEN '".$start_time."' AND '".$finish_time."' AND `id_sait` = '".$id."'"));
$opera = mysql_query("SELECT DISTINCT `".$prefix."hits`.`operator`, COUNT(`".$prefix."hits`.`operator`) AS `count`, `".$prefix."ip_name`.`operator` as `name` FROM `".$prefix."hits`, `".$prefix."ip_name` WHERE `".$prefix."hits`.`id_sait` = '".$id."' AND `".$prefix."hits`.`time` BETWEEN '".$start_time."' AND '".$finish_time."' AND `".$prefix."hits`.`operator` = `".$prefix."ip_name`.`id` GROUP BY `".$prefix."hits`.`operator` ORDER BY 2 DESC");
$oper_count = mysql_num_rows($opera);
if($oper_count > 0)
{
echo '<div class="navi3"><tr class="navi3">
		<table width="100%" border="0" cellspacing="1" cellpadding="2">
		<tr class="table_name"><td>Оператор</td><td>Хиты</td><td>Проценты</td></tr>';
	$total=intval(($oper_count-1)/$pages)+1; 
	$page=abs(intval($_GET['page'])); 
	if(empty($page) OR $page < 0)
		{
	$page = 1; 
		}
	if($page > $total)
		{
	$page = $total; 
		}
	$past=intval($oper_count/$pages);  
	$start=$page*$pages-$pages; 
$oper = mysql_query("SELECT DISTINCT `".$prefix."hits`.`operator`, COUNT(`".$prefix."hits`.`operator`) AS `count`, `".$prefix."ip_name`.`operator` as `name` FROM `".$prefix."hits`, `".$prefix."ip_name` WHERE `".$prefix."hits`.`id_sait` = '".$id."' AND `time` BETWEEN '".$start_time."' AND '".$finish_time."' AND `".$prefix."hits`.`operator` = `".$prefix."ip_name`.`id` GROUP BY `".$prefix."hits`.`operator` ORDER BY 2 DESC LIMIT ".$start.",".$pages."");
while($op = mysql_fetch_array($oper)){

$strana = mysql_fetch_array(mysql_query("SELECT * FROM `".$prefix."ip_name` WHERE `operator` = '".$op['name']."'"));

$procent = ($op['count'] / $all) * 100;
echo '<tr class="main"><td>['.$strana['coun'].']'.$op['name'].'</td><td>('.$strana['country'].'): [<b>'.$op['count'].'</td><td>'.round($procent, 2).'%</b>]</td><td>';}
echo'</table></div>';
navigation($oper_count,$pages,$page,'http://'.$set['home'].'/stats/'.$id.'/operators/',$total);
}else{
echo 'Нет статистики по операторам для этого сайта сегодня.</div>';}
echo '</div><div class="main">Статистика :<br/>';
	echo '<a href="http://'.$set['home'].'/stats/'.$id.'">Информация о сайте</a>  
| <a href="http://'.$set['home'].'/stats/'.$id.'/all">Общая</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/hours">По часам</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/ip">По IP</a> | <strong>По операторам</strong> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/online">По Онлайн</a></div>';
	break;


		case 'online':
		$all = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."sait_online` WHERE `id_sait` = '".$id."'"));
		if($all != 0)
			{ 
	echo '<div class="navi3"><tr class="title">
	<table width="100%" border="0" cellspacing="1" cellpadding="2">
	<tr class="table_name"><td>IP</td><td>UA</td><td>Время</td></tr>';
		$total=intval(($all-1)/$pages)+1; 
		$page=abs(intval($_GET['page'])); 
		if(empty($page) OR $page < 0)
			{
		$page = 1; 
			}
		if($page > $total)
			{
		$page = $total; 
			}
		$past=intval($all/$pages);  
		$start=$page*$pages-$pages; 
		   $onl = mysql_query("SELECT * FROM `".$prefix."sait_online` WHERE `id_sait` = '".$id."' LIMIT ".$start.",".$pages."");
			while($row = mysql_fetch_array($onl)) 
				{
	echo '<tr class="main"><td>'.$row['ip'].'</td> <td>'.$row['ua'].'</td> <td>'.data($row['time']).'</td></tr>';
									}
								echo '</table></div>';

		navigation($all,$pages,$page,'http://'.$set['home'].'/stats/'.$id.'/online/',$total);
		}
			else
		{
	echo 'Нет статистики по онлайн для этого сайта сегодня.<br/>';
		}
		echo '</div><div class="main">Статистика :<br/>';
		echo '<a href="http://'.$set['home'].'/stats/'.$id.'">Информация о сайте</a>  
| <a href="http://'.$set['home'].'/stats/'.$id.'/all">Общая</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/hours">По часам</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/ip">По IP</a> 
| <a href="http://'.$set['home'].'/stats/'.$id.'/operators">По операторам</a> | <strong>По Онлайн</strong></div>';
	break;
					}
	}

require_once('foot.php');
?>