<?php
if($j!=1) {
	$jourP1suite = strtotime(date("Y-m-d",strtotime($jourP1)) . " +".($j-1)." day");
	$jourP1suit = date('Y-m-d',$jourP1suite);
	$jourP1sui = new DateTime($jourP1suit);
	$jourP1date = $jourP1sui;
}
else {
	$jourP1date = new DateTime($jourP1);
}
$creneauele_nb=0;
$weekdown=0;
foreach(new DatePeriod($jourP1date, new DateInterval('P7D') , $jourP2date) as $dt) {
	$date = $dt->format('Y-m-d');
	//on soustrait des semaines celles où le jour est fermé
	$fermeture_nb = mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_calendrier WHERE date = '".$date."' AND statut = 0"));
	if($fermeture_nb==1) {
		$weekdown++;
	}
	//on récupère le nombre d'élèves, additionné
	$nb = mysqli_num_rows(mysqli_query($bdd,"SELECT freq_id FROM ".$prefix."_freq WHERE (date_freq = '".$date."' AND hor_name = '".$plage_nom[$h]."') ".$filtre_activs.""));
	if($grappes_check==1) {
		$elegrap_nb = mysqli_query($bdd,"SELECT nombre FROM ".$prefix."_freqgrappes WHERE (date_freq = '".$date."' AND hor_name = '".$plage_nom[$h]."') AND passage = '0' ".$filtre_activs."");
		while($elegrap = mysqli_fetch_assoc($elegrap_nb)) {
			$nb += $elegrap['nombre'];
		}
	}
	$creneauele_nb+=$nb;
}

$jouraff = date("Ymd", mktime(0,0,0,$mois,$jour-1+$j,$annee));
$horstart = substr($plageH[$h],0,2).substr($plageH[$h],3,2).'00';
$horend = substr($plageHend[$h],0,2).substr($plageHend[$h],3,2).'00';
$dtstart = $jouraff.'T'.$horstart;
$dtend = $jouraff.'T'.$horend;

// Affichage de la cellule :
echo '<div id="inbrik'.$h.$j.$usercode.'" class="td recept_open ';
if(($nb_week-($weekdown-$nb_close_week))>0) {
	$nbele_cren = round(($creneauele_nb/($nb_week-($weekdown-$nb_close_week))),2);
}
else { $nbele_cren = 0; }
if($nbele_cren==0) {
	echo 'nuance1" ';
}
else if($nbele_cren<=($moyenele_cren/1.5)) {
	echo 'nuance2" ';
}
else if($nbele_cren<=($moyenele_cren/1.2)) {
	echo 'nuance3" ';
}
else if($nbele_cren<=($moyenele_cren*1.2)&&$nbele_cren>=($moyenele_cren/1.2)) {
	echo 'nuance4" ';
}
else if($nbele_cren>=($moyenele_cren*1.5)) {
	echo 'nuance5" ';
}
else if($nbele_cren>=($moyenele_cren*1.2)) {
	echo 'nuance6" ';
}
else { echo '"'; }
echo ' style="height:'.$heighthor[$h].'px">';
echo '<!--'.$j.$plage_nom[$h].' - '.$creneauele_nb.' / ('.$nb_week.'-('.$weekdown.'-'.$nb_close_week.') = -->'.$nbele_cren.'</div>';
$total_jour += $nbele_cren;
?>