<?php
 
	session_start();
	include("connexion_db.php");
		
	$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 <= '" . $_GET['date'] . "' ORDER BY id_champ ASC, donnees_grilles.date DESC";
	$req = cleanPDOQuery($sql);
	$nb = $req->rowCount();
	$id_chmp = 1;
	$data = '';
	
	if($nb >= $_SESSION['nblvlgrille']) {
		while ($res = $req->fetch()) {
			
			if($res['id_champ'] == $id_chmp) {
						
				$data[] = $res['valeur'];			
				$id_chmp++;
				
			}
		}
		$resultat['etat'] = 'ok';
	} else {
		$resultat['etat'] = 'nok';
	}
	
	$resultat['nb'] = $nb;
	$resultat['data'] = $data;
	
	header('Content-Type: application/json');
 	echo json_encode($resultat);
	
?>