<?php
class log_of_visits
{

function log_of_visits()
{
global $dcms,$cache;

$d=$cache->get('log_of_visits.'.$dcms->ip_long);

if (empty($d['last_time']) || $d['last_time']<TIME)
{
mysql_query("INSERT INTO `log_of_visits_today` (`time`, `browser_type`, `id_browser`, `iplong`) VALUES ('".DAY_TIME."', '{$dcms->browser_type}', '{$dcms->browser_id}', '{$dcms->ip_long}')");
@$d['last_time']=TIME;
$cache->set('log_of_visits.'.$dcms->ip_long,$d,TIME+1);
}


}

// подведение итогов посещений по дням
function tally()
{
mysql_query("LOCK TABLES `log_of_visits_today` WRITE READ, `log_of_visits_for_days` WRITE READ");
$q=mysql_query("SELECT DISTINCT `time`  FROM `log_of_visits_today` WHERE `time` <> '".DAY_TIME."'");
while($day=mysql_fetch_assoc($q))
{
$hits['wap']=mysql_result(mysql_query("SELECT COUNT(*) FROM `log_of_visits_today` WHERE `time` = '$day[time]' AND `browser_type` = 'wap'"),0);
$hits['pda']=mysql_result(mysql_query("SELECT COUNT(*) FROM `log_of_visits_today` WHERE `time` = '$day[time]' AND `browser_type` = 'pda'"),0);
$hits['web']=mysql_result(mysql_query("SELECT COUNT(*) FROM `log_of_visits_today` WHERE `time` = '$day[time]' AND `browser_type` = 'web'"),0);

$hosts['wap']=mysql_result(mysql_query("SELECT COUNT(DISTINCT `iplong` , `id_browser`) FROM `log_of_visits_today`
WHERE `time` = '$day[time]' AND `browser_type` = 'wap'"),0);

$hosts['pda']=mysql_result(mysql_query("SELECT COUNT(DISTINCT `iplong` , `id_browser`) FROM `log_of_visits_today`
WHERE `time` = '$day[time]' AND `browser_type` = 'pda'"),0);

$hosts['web']=mysql_result(mysql_query("SELECT COUNT(DISTINCT `iplong` , `id_browser`) FROM `log_of_visits_today`
WHERE `time` = '$day[time]' AND `browser_type` = 'web'"),0);

mysql_query("INSERT INTO `log_of_visits_for_days` (`time_day`, `hits_web`,`hosts_web`,`hits_wap`,`hosts_wap`,`hits_pda`,`hosts_pda`)
VALUES ('$day[time]','$hits[web]','$hosts[web]','$hits[wap]','$hosts[wap]','$hits[pda]','$hosts[pda]')");

}
mysql_query("DELETE FROM `log_of_visits_today` WHERE `time` <> '".DAY_TIME."'");
// оптимизация таблиц после удаления данных
mysql_query("OPTIMIZE TABLE `log_of_visits_today`");
// разблокируем таблицы
mysql_query("UNLOCK TABLES");
}



}
?>