<?php
	$labels = "";
	$data = "";
		
	// On récupère dans la base de données tous les champs de la grille actuelle
	$sql = "SELECT * FROM libdesc_grille WHERE id_grille = '" . $_SESSION['id_grille'] . "'";
	$req = cleanPDOQuery($sql);
	$num = $req->rowCount();
	$i = 0;
			
	while($res = $req->fetch())
	{
		$labels .= '"' . $res['description_champ'] . '"';
		$i++;
		if($i < $num)
		{
			$labels .= ', ';
		}
	}
		
	// On récupère dans la base de données toutes les valeurs des champs de la grille actuelle
	$sql = "SELECT * FROM donnees_grilles WHERE id_grille = '" . $_SESSION['id_grille'] . "' AND id_patient = '" . $_SESSION['id_patient'] . "' AND id_docteur = '" . $_SESSION['id_docteur'] . "' AND id_etablissement = '" . $_SESSION['id_etablissement'] . "' AND donnees_grilles.date <= NOW() ORDER BY id_champ ASC, donnees_grilles.date DESC";
	$req = cleanPDOQuery($sql);
	$nb = $req->rowCount();
	$id_chmp = 1;
	$i = 0;
	
	while ($res = $req->fetch()) {
		
		if($res['id_champ'] == $id_chmp) {
					
			if($res['valeur'] <= 1)	{ $val = 0; }
			else if($res['valeur'] > 7)	{ $val = 7; }
			else { $val = $res['valeur']-1;}
			
			$val += 1;
			
			$data .= '"' . $val . '"';
			$i++;
			if($i < $num)
			{
				$data .= ', ';
			}			
			$id_chmp++;
			
		}
	}
		
?>	
<section>



<script>

	// cas iPad
	if (__TERMINAL__ == 'iPad') {
		
   		if(__ORIENTATION__ == 'Paysage')
    	{		// portrait
				var w = Math.min($(window).width()-20, $(window).height()-440);
				var h = Math.max($(window).width()-20, $(window).height()-420);
				var v = (h-w)/2+30;
				
				var a = ($(window).height()-w)/2 + 140;
				
		document.write("<div id=\"spidergraphcontainer\" style=\"top:"+a+"px;left:"+v+"px;width:" + w + "px;height:" + w + "px;\"></div>");
		}
		
		else
		{	// paysage
			var w = Math.min($(window).width()-20, $(window).height()-400);
				var h = Math.max($(window).width()-20, $(window).height()-380);
				var v = (h-w)/2;
			document.write("<div id=\"spidergraphcontainer\" style=\"margin-top:155px;left:"+v+"px;width:" + w + "px;height:" + w + "px;\"></div>");
		}
	}
	
	
	// cas Android
	else if (__TERMINAL__ == 'Android') {
		
   		if(__ORIENTATION__ == 'Paysage')
    	{		
		// paysage
				var w = Math.min($(window).width()-20, $(window).height()-400);
				var h = Math.max($(window).width()-20, $(window).height()-380);
				var v = (h-w)/2+20;
				
				//var a = ($(window).height()-w)/2 + 44;
				
		document.write("<div id=\"spidergraphcontainer\" style=\"margin-top:155px;left:"+v+"px;width:" + w + "px;height:" + w + "px;\"></div>");
		}
		// portrait
		else
		{
			
			var w = Math.min($(window).width()-20, $(window).height()-540);
			var h = Math.max($(window).width()-20, $(window).height()-520);
			var v = (h-w)/2+30;
			var a = ($(window).height()-w)/2 + 140;
			
			document.write("<div id=\"spidergraphcontainer\" style=\"top:"+a+"px;left:"+v+"px;width:" + w + "px;height:" + w + "px;\"></div>");
			
			
	
			
		}
	}

	else {
	// Cas PC
		if(typeof __ORIENTATION__ === 'undefined')
    	{
				var w = Math.min($(window).width()-20, $(window).height()-400);
				var h = Math.max($(window).width()-20, $(window).height()-380);
				var v = (h-w)/2;
		document.write("<div id=\"spidergraphcontainer\" style=\"margin-top:150px;left:"+v+"px;width:" + w + "px;height:" + w + "px;\"></div>");
		}
		
		else
		{
			var w = Math.min($(window).width()-20, $(window).height()-520);
			document.write("<div style=\"width:80px;height:300px;\"><div id=\"spidergraphcontainer\" style=\"width:" + w + "px;height:" + w + "px;\"></div></div>");
		}
	}
		
		
		 $(window).ready( function() {
			 
			 $('#spidergraphcontainer').spidergraph({
				'fields': __GRILLE__.champs,
				'gridcolor': 'rgba(0,0,0,1)'   
			});
			
			 $('#spidergraphcontainer').spidergraph('addlayer', { 	
				'strokecolor': 'rgba(0,0,0,1)',
				'fillcolor': 'rgba(193,195,198,0.5)',
				//'dotcolor' : 'rgba(151,187,205,1)',
				'data': __GRILLE__.valeurgrille,
				'linear': true
			});    
		
		});
		
</script>

</section>

























