<?php
    if(isset($_GET["data"]))
        $tab= unserialize(urldecode(stripslashes($_GET["data"])));
    
	if(isset($_GET["data"]))
	    $size=$_GET["size"];
 
    Header("Content-Type: image/png");
    $im_height = 30;
    $im_width  = 600;
    $im = ImageCreate($im_width,$im_height);
 
    $black = ImageColorAllocate($im, 0, 0, 0);
    $white = ImageColorAllocate($im, 255, 255, 255);
	$fond  = ImageColorAllocate($im, 80, 95, 112);
	imagecolortransparent($im, $fond);
    
	imagefilledrectangle ($im, 0, 0, $im_width, $im_height, $fond);
	imageline ( $im, 0, $im_height/2, $im_width, $im_height/2, $black);


	$barheigth=10;
	$decal=5;	
	$count=0;
	foreach ($tab as $ipid => $value){
		$data=$value["location"];
		$loc=split("T\[",$data);
		++$count;
		
		/*
		$xx=rand(30,230);
		$yy=rand(30,230);
		$zz=rand(30,230);
		*/
		
		if( ereg("IPR([0-9][0-9])([0-9][0-9])([0-9][0-9])", $ipid, $regs) ){
			$xx=5*($regs[1]+$regs[2]+$regs[3]);
			$yy=3*($regs[2]);
			$zz=2*($regs[3]);
		}
		
		
		$color  = ImageColorAllocate($im, $xx, $yy, $zz);
		$color2 = ImageColorAllocate($im, $xx-15, $yy-15, $zz-15);
		$color3 = ImageColorAllocate($im, $xx-30, $yy-30, $zz-30);

		
		/*
		$style = array ($color,$color,$color,$fond,$fond,$fond,);
		imagesetstyle ($im, $style);
		*/
		
		for($a=0;$a<count($loc);++$a){
			if ( ereg ("([0-9]+)-([0-9]+)\]", $loc[$a], $regs) ) {
			   $x1=($regs[1]*$im_width)/$size;
			   $x2=($regs[2]*$im_width)/$size;
			   imagefilledrectangle ($im, $x1, 0+$decal, $x2, $barheigth+$decal, $color3);
               imagefilledrectangle ($im, $x1, 3+$decal, $x2, $barheigth+$decal-3, $color2);
			   imagefilledrectangle ($im, $x1, 5+$decal, $x2, $barheigth+$decal-5, $color);
			   
			   imagerectangle ($im, $x1, 0+$decal, $x2, $barheigth+$decal, $black);
			   ImageString($im, 0,  $x1+(($x2-$x1)/2), 1+$decal, $count, $white);
			}
		}
		if($decal==19){$decal=-2;}
		$decal+=7;
	}
	
    ImagePNG($im);
    ImageDestroy($im);
 
?>