<?php

	# mark core  v1.0
    # author Drk in
	# date 24.10.19 	

	# core

	require_once ( $_SERVER['DOCUMENT_ROOT']."/_core/system.php" );

	$id =  isset( $_GET['id'] ) ? system::abs($_GET['id']): 0;

	if (cache_pf::ch($id) === false)system::header('/','Ошибка, ID не найден');

	$act = cache_pf::check($id);

	if ($act['ban'] == 1)system::header('/','Ошибка, сайт заблокирован');

	if ($act['mode'] == 1)system::header('/','Ошибка, сайт на модерации');

	if ($act['hide'] == 0 || isset($user) && $act['user'] == $user['id'] || isset($user) && $user['admin'] == 1): $r = 1; else: system::header('/link/'.$id,'Ошибка, владелец сайта предпочёл скрыть статистику.'); endif;

	# meta

	$title = 'Cтатистика сайта '.system::check($act['url']).' по часам » Мобильные WAP сайты';
	$description = system::check($config['description']);
	$keywords = system::check($config['keywords']);
	$tl = 'Статистика сайта '.system::check($act['url']).' по часам';
	
	# head

	require_once ( head );

	echo '
	<div class="touch"><table border="1" width="100%" style="text-align:center;">
	<tbody><tr>
	<td><b>Период</b></td><td>хостов</td><td>хитов</td><td>в топ/из топа</td>
	</tr>';

	for($h = 0; $h< 24; $h++):

	$st = mktime($h, 0, 0, date("m"), date("d"), date("Y")); 
	$et = mktime($h + 1, 0, 0, date("m"), date("d"), date("Y")); 	
	
	$hs = DB :: $dbh -> querySingle("SELECT count(id) FROM hs WHERE time  BETWEEN {$st} AND {$et} AND pf = ?", array($id));
	$ht = DB :: $dbh -> querySingle("SELECT count(id) FROM ht WHERE time  BETWEEN {$st} AND {$et} AND pf = ?", array($id));	
	$in = DB :: $dbh -> querySingle("SELECT count(id) FROM `in` WHERE time  BETWEEN {$st} AND {$et} AND pf = ?", array($id));	
	$ou = DB :: $dbh -> querySingle("SELECT count(id) FROM ou WHERE time  BETWEEN {$st} AND {$et} AND pf = ?", array($id));					

	if (strlen($h) == 1) $h = '0'.$h; 
	if (strlen($h + 1) == 1): $f = '0'.($h + 1); else: $f = $f + 1; endif;	

	echo '
	<tr>
	<td><font color="#0097f6">'.$h.':00 - '.$f.':00</font></td>
	<td><font color="green">'.$hs.'</font></td>
	<td><font color="red">'.$ht.'</font></td>
	<td>'.$in.'/'.$ou.'</td>
	</tr>
	';	

	endfor;	

	echo '
	</tbody></table></div>
	<a href="'.site.'/link/'.$id.'" class="touch">« Cтатистика</a>
	<a href="'.site.'" class="touch">« На главную</a>
	';

	# foot 

	require_once ( foot );

?>