<?php
	include("connection.php");


	//recup des variables
	$tabGene= unserialize(urldecode(stripslashes($_GET["tabGene"])));
	$tab= unserialize(urldecode(stripslashes($_GET["tab"])));
	$tabNeg= unserialize(urldecode(stripslashes($_GET["tabNeg"])));
	$tabDev= unserialize(urldecode(stripslashes($_GET["tabDev"])));
	$tabGeneID= unserialize(urldecode(stripslashes($_GET["tabGeneID"])));
	$devSize= $_GET["devSize"];
	$geneSize= $_GET["geneSize"];
	
	
							/////////////////////////////////
							//creation de l'image de sortie//
							/////////////////////////////////
	Header("Content-Type: image/png");
	
	$sizeText=3;
	$Xspacer=30;
	$Yspacer=10;
	
	$im_height = (count($tabGene)*$Yspacer)+($devSize*ImageFontWidth($sizeText)) +50;
	$im_width = (count($tabDev)*$Xspacer) + (geneSize*ImageFontWidth($sizeText)) +$Xspacer +100;
	
	$im = ImageCreate($im_width,$im_height);
	
	$lblue = ImageColorAllocate($im, 80, 95, 112);
	$black = ImageColorAllocate($im, 0, 0, 0);
	$white = ImageColorAllocate($im, 220, 220, 220);
	$trans = ImageColorTransparent($im, $lblue);
	//$style = array ($white,$white,$white,$lblue,$lblue,$lblue,$lblue,$lblue,$lblue,$lblue);
	//imagesetstyle ($im, $style);
	
	ImageFill($im, 0,0,$lblue);


	//nom des genes
	for($a=0;$a<count($tabGene);++$a){
		$coord=$a*$Yspacer;
		$color = ImageColorAllocate($im, $coord, 3*$coord, 6*$coord);
		imageline ($im, $geneSize*ImageFontWidth($sizeText), $coord+$Yspacer/2, $im_width, $coord+$Yspacer/2, $color);
		ImageString($im, $sizeText, 0, $coord, $tabGeneID[$tabGene[$a]], $color);
	}
	
	
	//nom des stades
	reset($tabDev);
	for ($a = 0; $a < count($tabDev); $a++)
	{
		$index = key($tabDev);
		ImageStringUp($im, $sizeText, ($geneSize*ImageFontWidth($sizeText))+($a*$Xspacer)+(ImageFontHeight($sizeText)/2), $im_height-40, $tabDev[$index], $white); //50
		
		
		
		//affichage des resultats negatifs
		for($b=0; $b<count($tabNeg[$index]); ++$b){
			for($h=0; $h<count($tabGene); ++$h){
				if( $tabNeg[$index][$b] == $tabGene[$h] ){
					$coord=$h*$Yspacer;
					break;
				}
			}
			
			$color = ImageColorAllocate($im, $coord, 3*$coord, 6*$coord);
			$style = array ($black,$color,$color,$color,$color,$color,$black,$lblue,$lblue,$lblue);
			imagesetstyle ($im, $style);
			imagefilledrectangle ($im, ($geneSize*ImageFontWidth($sizeText))+($a*$Xspacer), $coord, ($geneSize*ImageFontWidth($sizeText))+($a*$Xspacer)+$Xspacer, $coord+$Yspacer, IMG_COLOR_STYLED);
		}
		
		
		//affichage des resultats positifs
		for($b=0; $b<count($tab[$index]); ++$b){
		
			for($h=0; $h<count($tabGene); ++$h){
				if( $tab[$index][$b] == $tabGene[$h] ){
					$coord=$h*$Yspacer;
					break;
				}
			}
			$color = ImageColorAllocate($im, $coord, 3*$coord, 6*$coord);
			imagefilledrectangle ($im, ($geneSize*ImageFontWidth($sizeText))+($a*$Xspacer), $coord, ($geneSize*ImageFontWidth($sizeText))+($a*$Xspacer)+$Xspacer, $coord+$Yspacer, $color);
			imagerectangle (      $im, ($geneSize*ImageFontWidth($sizeText))+($a*$Xspacer), $coord, ($geneSize*ImageFontWidth($sizeText))+($a*$Xspacer)+$Xspacer, $coord+$Yspacer, $black);
		}
		
		
		next($tabDev);
	
	}
	
	ImagePNG($im);
	ImageDestroy($im);



	
	/*
	reset($tab);
	for ($i = 0; $i < count($tab); $i++)
	{
		$index = key($tab);
		print $tab[$index][5];
		next($tab);
	}
	*/
?>