<?php
define('NTOP', 1);
require_once ('system/connect.php');
require_once ('system/core.php');
require_once ('system/function.php');
$saits = mysql_query("SELECT * FROM `".$prefix."sait`");

$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']."' WHERE `id` = '".$row['id']."'");

}

$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`");
}
$log = "Top Update: ".data(time())."\r\n";
$fp = fopen("top_log.ntop", "a");
fwrite($fp, $log);
fclose($fp);
?>
