<?php
define('NTOP', 1);
require_once ('connect.php');
require_once ('core.php');
require_once ('function.php');

$saits = mysql_query("SELECT * FROM `".$prefix."sait`");
mysql_query("UPDATE `".$prefix."stat` SET `update` = '1'");

$timeon = mysql_fetch_array(mysql_query("SELECT * FROM `".$prefix."stat`"));
if($timeon['update'] == 1){

while($row = mysql_fetch_array($saits)){
$all_hosts = $row['all_hosts']+$row['hosts'];
$all_hits = $row['all_hits']+$row['hits'];
$all_out = $row['all_out']+$row['out'];
$all_in = $row['all_in']+$row['in'];

$up = mysql_query("UPDATE `".$prefix."sait` SET `of_hosts` = '".$row['hosts']."', `of_hits` = '".$row['hits']."', `of_in` = '".$row['in']."', `of_out` = '".$row['out']."', `all_hits` = '".$all_hits."', `all_hosts` = '".$all_hosts."', `all_in` = '".$all_in."', `all_out` = '".$all_out."' WHERE `id` = '".$row['id']."'");

if(time() > $row['obnov']){
$tt = time()+2592000;
mysql_query("TRUNCATE TABLE `".$prefix."reputation` WHERE `id_sait`='".$row['id']."'");
mysql_query("UPDATE `".$prefix."sait` SET `obnov` = '".$tt."', `plus` = '0', `minus` = '0', `all_hits` = '".$row['of_hits']."', `all_hosts` = '".$row['of_hosts']."', `all_in` = '".$row['of_in']."', `all_out` = '".$row['of_out']."' WHERE `id`='".$row['id']."'");
}}

$timeon = mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."rek` WHERE `time` < '".time()."' AND `time` > '0'"));

if($timeon > 0)mysql_query("DELETE FROM `".$prefix."rek` WHERE `time` < '".time()."' AND `time` > '0'");

$update = mysql_query("UPDATE `".$prefix."sait` SET `hosts` = '0', `hits` = '0', `in` = '0', `out` = '0'");
mysql_query("TRUNCATE TABLE `".$prefix."hits`");
mysql_query("TRUNCATE TABLE `".$prefix."hosts`");
mysql_query("TRUNCATE TABLE `".$prefix."go`");
mysql_query("TRUNCATE TABLE `".$prefix."sait_online`");
mysql_query("OPTIMIZE TABLE  `".$prefix."sait_online`");
mysql_query("OPTIMIZE TABLE  `".$prefix."go`");
mysql_query("OPTIMIZE TABLE  `".$prefix."hits`");
mysql_query("OPTIMIZE TABLE  `".$prefix."hosts`");
mysql_query("OPTIMIZE TABLE  `".$prefix."reputation`");
mysql_query("OPTIMIZE TABLE  `".$prefix."sait`");
mysql_query("OPTIMIZE TABLE  `".$prefix."users`");
mysql_query("UPDATE `".$prefix."stat` SET `update` = '0'");
}
?>