<?php
// данные по IP
function defineOperator($ip)
{
$ips=explode('.',$ip);
$ipnum=$ips[3]+$ips[2]*256+$ips[1]*256*256+$ips[0]*256*256*256;
$sql_result=mysql_query ("SELECT `top_operators`.`id` FROM `top_operators` INNER JOIN `top_ip` ON `top_ip`.`id_operator`=`top_operators`.`id` WHERE $ipnum BETWEEN `top_ip`.`ip1` AND `top_ip`.`ip2` LIMIT 1;");
if(mysql_num_rows($sql_result))
{
$id_operator=mysql_fetch_assoc($sql_result);
return $id_operator['id'];
}
else return 0;
}
$id_operator=defineOperator($_SERVER['REMOTE_ADDR']);
$week_day=date("w");
$today=date("Ymd");
$result=mysql_query("SELECT * FROM `top_operators_stat` WHERE `date`='".$today."' AND `day_week`='".$week_day."' AND `uid`='".$uid."' AND `id_operator`='".$id_operator."' LIMIT 1;");
if(!mysql_num_rows($result))
{
$dayNext=$week_day+7;
if($dayNext>7)
$dayNext-=7;
$cntDay=8-$dayNext;
$nextMonday=date('Ymd',mktime(0,0,0,date("m"),date("d")+$cntDay));
mysql_query("INSERT INTO `top_operators_stat` VALUES ('','".$uid."','".$nextMonday."','".$today."','".$week_day."','".$id_operator."','0');");
$operator_count=0;
}
else
{
$row=mysql_fetch_array($result);
$operator_count=$row['count'];
}
$operator_count++;
// сохранение
mysql_query("UPDATE `top_operators_stat` SET `count`='".$operator_count."' WHERE `date`='".$today."' AND `day_week`='".$week_day."' AND `uid`='".$uid."' AND `id_operator`='".$id_operator."' LIMIT 1;");
?>