Просмотр файла top/graphic_24.php

Размер файла: 2.7Kb
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
@include "./config.php";

//проверка  ввода id
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;

$hour_data = array();
$hour_host = array();

// текущий час, и дата
$hour = date("H");
$today = date("Ymd");

$temp_hour = $hour;
$temp_date = $today;
for ($i=0;$i<24;$i++)
{
	// данные за текущий час
	$result = mysql_query("SELECT count,host FROM count_24 WHERE hour=$temp_hour AND date=$temp_date AND uid=$uid ORDER BY id DESC LIMIT 1");
	$row=mysql_fetch_row($result);
	
	// поверка наличия записи в базе
	if (empty($row[0]))
	{
		$hour_data[] = 0;
		$hour_host[] = 0;
	}else{
		$hour_data[] = $row[0];
		$hour_host[] = $row[1];
	}
	$temp_hour--;
	if ($temp_hour < 0)
	{
		$temp_hour = 23;
		$day = substr($temp_date,-2,2);
		if ($day-1 <= 0)
		{
			$month = substr($temp_date,-4,2);
			$temp_date = date("Ymd",mktime(0,0,0,$day-1,$month,date("Y")));
			
		} else $temp_date--;
	}
}
// максим посещаемость
$max = 0;
foreach ($hour_data as $value){
	if ($value > $max) $max = $value;
}
foreach ($hour_host as $value){
	if ($value > $max) $max = $value;
}
if ($max == 0) $max = 1;
// процентное соотношение хитов
$per_hit = array();
foreach ($hour_data as $value){
	$per_hit[] = $value*0.90/$max;
}
// процентное соотношение хостов
$per_host = array();
foreach ($hour_host as $value){
	$per_host[] = $value*0.90/$max;
}
$img = @imageCreateFromPNG("img/stat24.png");

// линейный 
$color1 = imageColorAllocate($img, 255,0,0);
$color2 = imageColorAllocate($img, 0,0,255);
$imageH = 96;
$imageW = 47;
$collW = 4;
$x1 = 101;
$y1 = (int)($imageW - $imageW*$per_hit[0] + 7);
$y1_host = (int)($imageW - $imageW*$per_host[0] + 7);
$x2 = $x1 - 3;
if ($hour_data[0] != 0 && $mark_graph) imageString($img,1,$x1,$y1-7,$hour_data[0],$color2);
for($i=1;$i<count($hour_data);$i++)
{
	// хиты
	$y2 = (int)($imageW - $imageW*$per_hit[$i] + 7);
	imageLine($img,$x1,$y1,$x2,$y2,$color1);
	
	// хосты 
	$y2_host = (int)($imageW - $imageW*$per_host[$i] + 7);
	imageLine($img,$x1,$y1_host,$x2,$y2_host,$color2);
	if ($hour_data[$i] != 0 && $mark_graph) imageString($img,1,$x2,$y2-7,$hour_data[$i],$color2);
	$y1 = $y2;
	$y1_host = $y2_host;
	$x1 -= $collW;
	$x2 -= $collW;
}
Header("Content-type: image/png");
ImagePNG($img);
ImageDestroy($img);
?>