<?php
$q = Core::query("SELECT * FROM `user_sites`");
	require('seo.php');
while($post = $q -> fetch()){
//тИЦ и PR
$tiz=getTCY($post['url']);
$pr=GetPageRank($post['url']);
	Core::query("UPDATE `user_sites` SET `tiz` = '".$tiz."', `pr`='".$pr."' where `id` = '$post[id]'");

//Считаем статистику по дням
//Хосты
	Core::query("UPDATE `user_sites` SET `host7` = '$post[host6]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `host6` = '$post[host5]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `host5` = '$post[host4]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `host4` = '$post[host3]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `host3` = '$post[host2]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `host2` = '$post[host]' where `id` = '$post[id]'");
//Хиты
	Core::query("UPDATE `user_sites` SET `hit7` = '$post[hit6]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `hit6` = '$post[hit5]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `hit5` = '$post[hit4]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `hit4` = '$post[hit3]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `hit3` = '$post[hit2]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `hit2` = '$post[hit]' where `id` = '$post[id]'");

// Вчера
	Core::query("UPDATE `user_sites` SET `host_day` = '$post[host]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `hit_day` = '$post[hit]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `v_top_day` = '$post[v_top]' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `iz_top_day` = '$post[iz_top]' where `id` = '$post[id]'");
	// За все время
	Core::query("UPDATE `user_sites` SET `host_all` = '".($post['host_all'] + $post['host'])."' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `hit_all` = '".($post['hit_all'] + $post['hit'])."' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `v_top_all` = '".($post['v_top_all'] + $post['v_top'])."' where `id` = '$post[id]'");
	Core::query("UPDATE `user_sites` SET `iz_top_all` = '".($post['iz_top_all'] + $post['iz_top'])."' where `id` = '$post[id]'");
	if($post['host_week_count'] <= 7){
		// Если не прошла неделя продолжаем писать хиты и добавлять счетчик
		Core::query("UPDATE `user_sites` SET `host_week_count` = '".($post['host_week_count'] + 1)."' where `id` = '$post[id]'");
		Core::query("UPDATE `user_sites` SET `host_week` = '".($post['host_week'] + $post['host'])."' where `id` = '$post[id]'");
		Core::query("UPDATE `user_sites` SET `hit_week` = '".($post['hit_week'] + $post['hit'])."' where `id` = '$post[id]'");
		Core::query("UPDATE `user_sites` SET `v_top_week` = '".($post['v_top_week'] + $post['v_top'])."' where `id` = '$post[id]'");
		Core::query("UPDATE `user_sites` SET `iz_top_week` = '".($post['iz_top_week'] + $post['iz_top'])."' where `id` = '$post[id]'");
}else{
		// Если неделя прошла, обнуляем хиты счетчик за неделю
		Core::query("UPDATE `user_sites` SET `host_week_count` = '1' where `id` = '$post[id]'");
		Core::query("UPDATE `user_sites` SET `host_week` = '".$post['host']."' where `id` = '$post[id]'");
		Core::query("UPDATE `user_sites` SET `hit_week` = '".$post['hit']."' where `id` = '$post[id]'");
		Core::query("UPDATE `user_sites` SET `v_top_week` = '".$post['v_top']."' where `id` = '$post[id]'");
		Core::query("UPDATE `user_sites` SET `iz_top_week` = '".$post['iz_top']."' where `id` = '$post[id]'");
	}
}
Core::query("UPDATE `user_sites` SET `host` = '0', `hit` = '0'");
Core::query("UPDATE `user_sites` SET `v_top` = '0', `iz_top` = '0'");
Core::query("TRUNCATE `ip`");
Core::query("TRUNCATE `online`");
Core::query("TRUNCATE `golos`");
Core::query("TRUNCATE `ip_v_top`");
Core::query("TRUNCATE `ip_iz_top`");
?>