<?php
// юзер агенты
$mobile_ua=array(
"SIE"=>1,
"Nokia"=>2,
"SAMSUNG"=>3,
"SEC"=>3,
"SGH"=>3,
"MOT"=>4,
"Motorola"=>4,
"LG"=>5,
"SAGEM"=>6,
"SonyEricsson"=>7,
"Alcatel"=>8,
"SHARP"=>9,
"PANTECH"=>10,
"Panasonic"=>11,
);
// производители
$mobile_name=array(
1=>"Siemens",
2=>"Nokia",
3=>"Samsung",
4=>"Motorola",
5=>"LG",
6=>"Sagem",
7=>"SonyEricsson",
8=>"Alcatel",
9=>"Sharp",
10=>"Pantech",
11=>"Panasonic",
);
// определение тела
$browser=explode("/",$ua);
$result=false;
$week_day=date("w");
$today=date("Ymd");
// поиск тела
foreach($mobile_ua as $ua_mobile=>$index_name)
{
if(strpos($browser[0],$ua_mobile)!==false)
{
// подсчет
$result=mysql_query("SELECT `".$mobile_name[$index_name]."` FROM `top_weeks` WHERE `date`='".$today."' AND `day_week`='".$week_day."' AND `uid`='".$uid."' LIMIT 1;");
$row=mysql_fetch_array($result);
if(empty($row))
{
$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_weeks` VALUES ('','".$uid."','".$nextMonday."','".$today."','".$week_day."','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');");
$tel_count=0;
}
else
{
$tel_count=$row[$mobile_name[$index_name]];
}
$tel_count++;
// сохранение
mysql_query("UPDATE `top_weeks` SET `".$mobile_name[$index_name]."`='".$tel_count."' WHERE `date`='".$today."' AND `day_week`='".$week_day."' AND `uid`='".$uid."' LIMIT 1;");
$result=true;
break;
}
}
// другие
if(!$result)
{
// подсчет когад браузер не отределен
$result=mysql_query("SELECT `Other` FROM `top_weeks` WHERE `date`='".$today."' AND `day_week`='".$week_day."' AND `uid`='".$uid."' LIMIT 1;");
$row=mysql_fetch_array($result);
if(empty($row))
{
$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_weeks` VALUES ('','".$uid."','".$nextMonday."','".$today."','".$week_day."','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0');");
$tel_count=0;
}
else
{
$tel_count=$row['Other'];
}
$tel_count++;
// сохранение
mysql_query("UPDATE `top_weeks` SET `Other`='".$tel_count."' WHERE `date`='".$today."' AND `day_week`='".$week_day."' AND `uid`='".$uid."' LIMIT 1;");
}
?>