<?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=$REMOTE_ADDR;
$ua=$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 ip FROM online_ip WHERE ip='$ip' AND uid=$uid";
$result = mysql_query($sql);
$row=mysql_fetch_row($result);
if(empty($row[0])){
mysql_query("INSERT INTO online_ip VALUES ($uid,'$ip')");
}
$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];
//
$image=$type[0];
if($type[0]==2 or $type[0]==3){
$image.=$typeStat[0];
}
if(!$p or $p=="")
$p=1;
$image=$p;
$img = @imageCreateFromPNG("img/".$image.".png");
$color = imagecolorallocate($img, 255,255,255);
$red = imagecolorallocate($img, 246,8,8);
if($image==1){
$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$online")-3);
$x4 = (ImageSX($img) - 5*strlen("$count_24")-3);
$x5 = (ImageSX($img) - 5*strlen("$all_count")-3);
//$x6 = (ImageSX($img) - 5*strlen("$top_place")-72);
$y = 9;
Imagestring($img,3,2,0,"BEST",$red);
Imagestring($img,3,3,10,"TOP",$red);
//Imagestring($img,1,$x6,$y+16,"$top_place",$red);
Imagestring($img,1,31,1,"ELENA.NSK.RU",$red);
imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2, $y+8,"$host_today", $color);
imageString($img, 1, $x3, $y+15,"$online", $color);
imageString($img, 1, $x4, $y+23,"$count_24", $color);
imageString($img, 1, $x5, $y+31,"$all_count", $color);
}
if($image==21){
$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$online")-3);
$y = 9;
Imagestring($img,1,27,1,"ELENA.NSK.RU",$red);
imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2, $y+8,"$host_today", $color);
imageString($img, 1, $x3, $y+15,"$online", $color);
}
if($image==22){
$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$all_count")-3);
$y = 9;
Imagestring($img,1,27,1,"ELENA.NSK.RU",$red);
imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2, $y+8,"$host_today", $color);
imageString($img, 1, $x3, $y+15,"$all_count", $color);
}
if($image==23){
$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$x3 = (ImageSX($img) - 5*strlen("$count_24")-3);
$y = 9;
Imagestring($img,1,27,2,"ELENA.NSK.RU",$red);
imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2, $y+8,"$host_today", $color);
imageString($img, 1, $x3, $y+15,"$count_24", $color);
}
if($image==31){
$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$all_count")-3);
$y = 9;
Imagestring($img,1,27,1,"ELENA.NSK.RU",$red);
imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2, $y+8,"$all_count", $color);
}
if($image==32){
$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$host_today")-3);
$y = 9;
Imagestring($img,1,27,1,"ELENA.NSK.RU",$red);
imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2, $y+8,"$host_today", $color);
}
if($image==33){
$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$x2 = (ImageSX($img) - 5*strlen("$online")-3);
$y = 9;
Imagestring($img,1,27,1,"ELENA.NSK.RU",$red);
imageString($img, 1, $x1, $y,"$count_today", $color);
imageString($img, 1, $x2, $y+8,"$online", $color);
}
if($image==4){
$x1 = (ImageSX($img) - 5*strlen("$count_today")-3);
$y = 1;
Imagestring($img,1,2,1,"ELENA.NSK.RU",$red);
imageString($img, 1, $x1, $y,"$count_today", $color);
}
Header("Content-type: image/png");
ImagePNG($img);
ImageDestroy($img);
?>