<!DOCTYPE html>
<html lang=fr>
<?php
	// appel du script de connexion
	require ('connect/mysqli_connect.php');


	// Récupération des données 
	$etudiant=3;
	$epreuve="E42A";
	
 $sql='SELECT eval_note.*,	nomEval
				FROM eval_note,eval_liste
				WHERE eval_note.numEval=eval_liste.numEval
				AND eval_liste.epreuveEval="'.$epreuve.'" AND numEtudiant='.$etudiant.' ORDER BY numEval;';	

	
	
	$result = mysqli_query ($dbcon, $sql)or die(mysqli_error($dbcon));
	$nb_eval = mysqli_num_rows($result); //compte le nombre de lignes
	$i=0;
	while ($row = mysqli_fetch_array($result, MYSQLI_BOTH))
	{
		
		$tabnote[$i]=$row;
		$note1[$i]=$tabnote[$i]['note1']*1;
		$note2[$i]=$tabnote[$i]['note2']*1;
		$note3[$i]=$tabnote[$i]['note3']*1;
		$note4[$i]=$tabnote[$i]['note4']*1;
		$note5[$i]=$tabnote[$i]['note5']*1;
		$note6[$i]=$tabnote[$i]['note6']*1;
		$note7[$i]=$tabnote[$i]['note7']*1;
		$Eval[$i]=$tabnote[$i]['numEval'];
		$xlibelle[$i]=$tabnote[$i]['nomEval'];
		$i++;
	}
	

	// CHERCHE nom ETUTDIANT selectionné
	$sql = "SELECT  * FROM acteur WHERE numAct=$etudiant;";
	$result = mysqli_query ($dbcon, $sql)or die(mysqli_error($dbcon));
	$nb_ligne = mysqli_num_rows($result); 	
	if ($nb_ligne ==0)
	{
		$erreur[]="Etudiant non trouvé contacter l'admin";
	}
	elseif ($nb_ligne !==1)
	{
		$erreur[]="Identifiants multiples : contacter l\'admin";
	}
	else
	{
		while ($row = mysqli_fetch_array($result, MYSQLI_BOTH))
		{
			$Acteur=$row;
			echo $Acteur[1];
		}
	}
	
	


echo json_encode($note1,JSON_NUMERIC_CHECK);
?>	

<script type="text/javascript">
	// // TRANSFORME DONNéés PHP en variable Java
		var etudiant = <?php echo json_encode($Acteur,JSON_NUMERIC_CHECK) ?>;
		var eval = <?php echo json_encode($Eval,JSON_NUMERIC_CHECK) ?>;
		var xlibelle = <?php echo json_encode($xlibelle) ?>;
		var note1 = <?php echo json_encode($note1,JSON_NUMERIC_CHECK) ?>;
		var note2 = <?php echo json_encode($note2,JSON_NUMERIC_CHECK) ?>;
		var note3 = <?php echo json_encode($note3,JSON_NUMERIC_CHECK) ?>;
		var note4 = <?php echo json_encode($note4,JSON_NUMERIC_CHECK) ?>;
		var note5 = <?php echo json_encode($note5,JSON_NUMERIC_CHECK) ?>;
		var note6 = <?php echo json_encode($note6,JSON_NUMERIC_CHECK) ?>;
		var note7 = <?php echo json_encode($note7,JSON_NUMERIC_CHECK) ?>;
</script>




	<head>
		<title>graph RECAP FINAL</title>
		<meta charset=utf-8>
		<meta name=viewport content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="nogstyle.css">
		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
			<script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
			<script src="http://code.highcharts.com/modules/exporting.js" type="text/javascript"></script>
			<script type="text/javascript">
			
			function creationserie(tableau)		// Crée les séries de données ?
			{
		 		var sortie = [];
		 		for (var i = 0; i < eval.length;i++)
		 		 {
		 			sortie[i] = [i, tableau[i]];	// x et y ?
				}
		 		return sortie;
			}
			
			
			$(function() {
				$('#container').highcharts({
					title: {
						text: etudiant[3],
						x: -20 //center
					},
					subtitle: {
						text: 'Récapitulatif évaluations',
						x: -20
					},
						xAxis: {
							categories: xlibelle,
					//		tickInterval: 1,
							startOnTick: true,
							},
						
						yAxis: {
							title: {
								text: 'Notes'
							},
							plotLines: [{
								value: 3,
								width: 2,
								color: '#f5b8c9'
							}]
						},
						
					 tooltip: {
        				formatter: function ()
        				 {
            			var s = '<b>' + this.x + '</b>';
            			$.each(this.points, function () {
                		s += '<br/>' + this.series.name + ': ' +this.y ;
            });

            return s;
        },
        shared: true
    },
						
						legend: {
							layout: 'vertical',
							align: 'right',
							verticalAlign: 'middle',
							borderWidth: 0
						},
						
						series: [
						{
							name: 'Critère 1',
							data: creationserie(note1)
						},
						{
							name: 'Critère 2',
							data: creationserie(note2)
						},
						{
							name: 'Critère 3',
							data: creationserie(note3)
						},
						{
							name: 'Critère  4',
							data: creationserie(note4)
						},
						{
							name: 'Critère  5',
							data: creationserie(note5)
						},
						{
							name: 'Critère  6',
							data: creationserie(note6)
						},
						{
							name: 'Critère  7',
							data: creationserie(note7)
						},
						]
					});
				});

		</script>
	</head>
	<body>

		<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
			<?php
				echo'<table ><tr><td><b>EVALUATION</b></td>';
				for($eval=0;$eval<$nb_eval;$eval++)
				{	
					echo"<td> $xlibelle[$eval]</td>";
				}	
				echo"</tr>";		
			
				for ($n=1;$n<=7;$n++)
				{
					$total[$n]=0;
					$nbre_note=0;
					echo "<tr><td>Critère $n : </td>";
					for($eval=0;$eval<$nb_eval;$eval++)
					{
						echo'<td>'.$tabnote[$eval][$n+1].'</td>';
						$total[$n]=$total[$n]+$tabnote[$eval][$n+1];
						$nbre_note++;
					}	
					
					$moyenne[$n] = number_format($total[$n]/$nbre_note,1);
					echo "<td>Total: $total[$n]<br/><B>Moyenne : $moyenne[$n]</B></td>";
					echo"</tr>";
				}
				echo"</table>";	
			?>


	</body>