Просмотр файла top-elena/graphic_7.php

Размер файла: 2.78Kb
<?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;

$week_data = array();

//
$week_day = date("w");
// 
    $dayNext =$week_day + 7;
    if ($dayNext > 7){
        $dayNext-=7;
    }
    $cntDay=8-$dayNext;
    $nextMonday=date("Ymd",mktime(23,0,0,date("m"),date("d")+$cntDay));
// 
$today = date("Ymd", time()+3600);
for ($i=1;$i<7;$i++)
{
	//
	$result = mysql_query("SELECT count FROM weeks WHERE next_mon=$nextMonday AND day_week=$i AND uid=$uid LIMIT 1");
	$row=mysql_fetch_row($result);
	//
	if (empty($row[0]))
	{
		$week_data[$i] = 0;
	}else $week_data[$i] = $row[0];
}
//
	$result = mysql_query("SELECT count FROM weeks WHERE next_mon=$nextMonday AND day_week=0 AND uid=$uid LIMIT 1");
	$row=mysql_fetch_row($result);
	//
	if (empty($row[0]))
	{
		$week_data[0] = 0;
	}else $week_data[0] = $row[0];
// 
$max = 0;
foreach ($week_data as $value){
	if ($value > $max) $max = $value;
}
if ($max == 0) $max = 1;
// 
$per_hit = array();
foreach ($week_data as $value){
	$per_hit[] = $value*0.90/$max;
}
// 
$img = @imageCreateFromPNG("img/stat7.png");
// 
$imageH = 96;
$imageW = 47;
$collW = 10;

$x1 = 12;
$y2 = 59;
$x2 = $x1 + $collW;
$colorBlack = imageColorAllocate($img, 0,0,0);

foreach ($per_hit as $index=>$percent) {
	if ($index/2 == (int)($index/2)){
		$color = imageColorAllocate($img, 255,73,73);
		$color2 = imageColorAllocate($img, 231,66,66);
		$color3 = imageColorAllocate($img, 206,60,60);
	}
	else{
		$color = imageColorAllocate($img, 131,63,255);
		$color2 = imageColorAllocate($img, 113,57,215);
		$color3 = imageColorAllocate($img, 101,53,189);
	}
	$y1 = round($imageW - $imageW*$percent + 12);
	imageFilledRectangle($img,$x1,$y1,$x2,$y2,$color);
	$points = array(
	  0  => $x1,    // x1
	  1  => $y1,    // y1
	  2  => $x1+3,    // x2
	  3  => $y1-5,   // y2
	  4  => $x1+$collW+3,    // x3
	  5  => $y1-5,    // y3
	  6  => $x2,   // x4
	  7  => $y1,    // y4
	);
	imageFilledPolygon($img,$points,4,$color2);
	$points = array(
	  0  => $x2,    // x1
	  1  => $y1,    // y1
	  2  => $x1+$collW+3,    // x2
	  3  => $y1-5,   // y2
	  4  => $x1+$collW+3,    // x3
	  5  => $y2-5,    // y3
	  6  => $x2,   // x4
	  7  => $y2,    // y4
	);
	imageFilledPolygon($img,$points,4,$color3);
	$index_week = $index + 1;
	if ($index_week == 7) $index_week = 0;
	if ($week_data[$index_week] != 0 && $mark_graph) imageString($img,1,$x1,$y1-8,$week_data[$index_week],$colorBlack);
	$x1 += $collW;
	$x2 += $collW;
}
Header("Content-type: image/png");
ImagePNG($img);
ImageDestroy($img);
?>