<?php
/*
    ANISEED, NISEED System and Database
    Copyright (C) 2007 Olivier Tassy, Fabrice Daian, Patrick Lemaire

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
    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);
 
?>