Файл: top/count.php
Строк: 160
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
@include ("config.php");
if (empty($_GET['uid'])) exit;
$uid=$_GET['uid'];
$result = mysql_query("SELECT link FROM users WHERE uid=$uid");
$row=mysql_fetch_row($result);
if (empty($row[0])) exit;
$ip=$_SERVER['REMOTE_ADDR'];
$ua=$_SERVER['HTTP_USER_AGENT'];
$hour = date("H");
$day = date("d");
$today = date("Ymd", time()+3600);
$result = mysql_query("SELECT time FROM hits_time WHERE uid=$uid");
$row=mysql_fetch_row($result);
if(empty($row[0])){
@mysql_query("INSERT INTO hits_time VALUES ($uid,$today)");
$reset_time = $today;
} else $reset_time = $row[0];
if($today != $reset_time){
@mysql_query("DELETE FROM hits_ip WHERE uid=$uid");
@mysql_query("UPDATE hits_time SET time = $today WHERE uid=$uid");
}
$result = mysql_query("SELECT count,host FROM count_24 WHERE hour=$hour AND date=$today AND uid=$uid");
$row=mysql_fetch_row($result);
if (empty($row[0]))
{
$res = mysql_query("SELECT count(*) FROM count_24 WHERE uid=$uid");
$data = mysql_fetch_row($res);
$count_rows = $data[0];
if ($count_rows >= 24) @mysql_query("DELETE FROM count_24 WHERE uid=$uid ORDER BY id ASC LIMIT 1;");
@mysql_query("INSERT INTO count_24 VALUES ('',$uid,$today,$hour,0,0);");
$hour_count = 0;
$hour_host = 0;
}else
{
$hour_count = $row[0];
$hour_host = $row[1];
}
$hour_count++;
$result = mysql_query("SELECT ip FROM hits_ip WHERE (ip='$ip' AND ua='$ua') AND uid=$uid");
$row=mysql_fetch_row($result);
if(empty($row[0])){
$hour_host++;
}
@mysql_query("UPDATE count_24 SET count=$hour_count,host=$hour_host WHERE hour=$hour AND date=$today AND uid=$uid");
$result = mysql_query("SELECT sum(count),sum(host) FROM count_24 WHERE date=$today AND uid=$uid");
$row = mysql_fetch_row($result);
$count_today = $row[0];
$host_today = $row[1];
$today = date("Ym");
$result = mysql_query("SELECT count,host FROM months WHERE date=$today AND uid=$uid");
$row=mysql_fetch_row($result);
if (empty($row[0]))
{
@mysql_query("INSERT INTO months VALUES ('',$uid,$today,0,0);");
$this_month_count = 0;
$this_month_host = 0;
}else{
$this_month_count = $row[0];
$this_month_host = $row[1];
}
$this_month_count++;
$result = mysql_query("SELECT ip FROM hits_ip WHERE ip='$ip' AND ua='$ua' AND uid=$uid");
$row=mysql_fetch_row($result);
if(empty($row[0])){
$this_month_host++;
}
@mysql_query("UPDATE months SET count=$this_month_count,host=$this_month_host WHERE date=$today AND uid=$uid");
$week_day = date("w");
$today = date("Ymd");
$result = mysql_query("SELECT next_mon FROM weeks WHERE uid=$uid ORDER BY id ASC LIMIT 1");
$row=mysql_fetch_row($result);
if (empty($row[0]))
{
$dayNext =$week_day + 7;
if ($dayNext > 7){
$dayNext-=7;
}
$cntDay=8-$dayNext;
$nextMonday=date("Ymd",mktime(0,0,0,date("m"),date("d")+$cntDay));
}
else $nextMonday = $row[0];
if ($today >= $nextMonday)
{
$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("DELETE FROM weeks WHERE uid=$uid");
}
$result = mysql_query("SELECT count,host FROM weeks WHERE day_week=$week_day AND uid=$uid LIMIT 1");
$row=mysql_fetch_row($result);
if (empty($row[0]))
{
$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 weeks VALUES ('',$uid,$nextMonday,$today,$week_day,0,0)");
$week_day_count = 0;
$week_day_host = 0;
} else{
$week_day_count = $row[0];
$week_day_host = $row[1];
}
$week_day_count++;
$result = mysql_query("SELECT ip FROM hits_ip WHERE ip='$ip' AND ua='$ua' AND uid=$uid");
$row=mysql_fetch_row($result);
if(empty($row[0])){
$week_day_host++;
}
@mysql_query("UPDATE weeks SET count=$week_day_count,host=$week_day_host WHERE day_week=$week_day AND uid=$uid LIMIT 1");
$today = date("Ymd", time()+3600);
$result = mysql_query("SELECT time FROM online_time WHERE uid=$uid");
$row=mysql_fetch_row($result);
$now=date("ymdHi", time()+3600);
if(empty($row[0])){
@mysql_query("INSERT INTO online_time VALUES ($uid,'$now')");
$row[0]=$now;
}
if($now-$row[0] >= 10){
@mysql_query("DELETE FROM online_ip WHERE uid=$uid");
@mysql_query("UPDATE online_time SET time = '$now' WHERE uid=$uid");
}
$sql = "SELECT * FROM online_ip WHERE ip='$ip' AND uid=$uid";
$result = mysql_query($sql);
if(mysql_num_rows($result)<=0){
$sql="INSERT INTO online_ip (`uid`,`ip`) VALUES ($uid,'$ip')";
mysql_query($sql);
}
$result = mysql_query("SELECT ip FROM hits_ip WHERE (ip='$ip' AND ua='$ua') AND uid=$uid");
$row=mysql_fetch_row($result);
if(empty($row[0])){
mysql_query("INSERT INTO hits_ip VALUES ($uid,'$ip','$ua')");
}
$result = mysql_query("SELECT count(ip) FROM online_ip WHERE uid=$uid");
$row=mysql_fetch_row($result);
$online=(int)$row[0];
$today = date("Ymd", time()+3600);
$hour = date("H");
$result = mysql_query("SELECT sum(count) FROM count_24 WHERE (date=$today-1 AND hour>$hour) OR (date=$today AND hour<=$hour) AND uid=$uid");
$row = mysql_fetch_row($result);
$count_24 = (int)$row[0];
$result = mysql_query("SELECT sum(count) FROM months WHERE uid=$uid");
$row=mysql_fetch_row($result);
$all_count = (int)$row[0];
$result = mysql_query("SELECT type FROM users WHERE uid=$uid");
$type=mysql_fetch_row($result);
$result = mysql_query("SELECT typeStat FROM users WHERE uid=$uid");
$typeStat=mysql_fetch_row($result);
$result=mysql_query("SELECT count(*) FROM weeks WHERE host >= $host_today and date=$today ORDER BY host DESC");
$row=mysql_fetch_row($result);
$top_place = (int)$row[0];
$sql="SELECT * FROM users WHERE uid=$uid";
$result=mysql_query($sql,$dbh);
$row=mysql_fetch_row($result);
$image=$type[0];
if($type[0]==2 or $type[0]==3){
$image.=$typeStat[0];
}
$image=$row[8];
$img = @imageCreateFromPNG("img/".$image.".png");
$colorr = imagecolorallocate($img, 255,255,255);
$color = imagecolorallocate($img, 0,0,0);
if($image==1){
$x1 = (ImageSX($img) - 5*strlen("$host_today")-7);
$x2 = (ImageSX($img) - 5*strlen("$count_today")-7);
$x3 = (ImageSX($img) - 5*strlen("$all_count")-7);
$x4 = (ImageSX($img) - 5*strlen("$online")-7);
$y = 7;
imageString($img, 1, $x1, $y+8,"$host_today", $color);
imageString($img, 1, $x2, $y+16,"$count_today", $color);
imageString($img, 1, $x3, $y+24,"$all_count", $color);
imageString($img, 1, $x4, $y+32,"$online", $color);
}
if($image==7){
$x1 = (ImageSX($img) - 5*strlen("$host_today")-40);
$x2 = (ImageSX($img) - 5*strlen("$count_today")-6);
$y = 3;
imageString($img, 2, $x1, $y+9,"$host_today", $color);
imageString($img, 2, $x2, $y+8,"$count_today", $color);
}
if($image==3){
$x1 = (ImageSX($img) - 5*strlen("$online")-4);
$y = 1;
imageString($img, 2, $x1, $y,"$online", $color);
}
if($image==4){
$x1 = (ImageSX($img) - 5*strlen("$online")-4);
$y = 1;
imageString($img, 2, $x1, $y,"$online", $color);
}
if($image==5){
$x1 = (ImageSX($img) - 5*strlen("$host_today")-40);
$x2 = (ImageSX($img) - 5*strlen("$count_today")-6);
$y = 3;
imageString($img, 2, $x1, $y+9,"$host_today", $color);
imageString($img, 2, $x2, $y+8,"$count_today", $color);
}
if($image==6){
$x1 = (ImageSX($img) - 5*strlen("$host_today")-40);
$x2 = (ImageSX($img) - 5*strlen("$count_today")-6);
$y = 3;
imageString($img, 2, $x1, $y+9,"$host_today", $color);
imageString($img, 2, $x2, $y+8,"$count_today", $color);
}
if($image==2){
$x1 = (ImageSX($img) - 5*strlen("$online")-4);
$y = 1;
imageString($img, 2, $x1, $y,"$online", $color);
}
if($image==8){
$x1 = (ImageSX($img) - 5*strlen("$host_today")-7);
$y = -2;
imageString($img, 2, $x1, $y+1,"$host_today", $colorr);
}
Header("Content-type: image/png");
ImagePNG($img);
ImageDestroy($img);
?>