<?php
//gestion des demi-journées fermées et des heures ouvertes
if($houropen==0) {
	$nb_jclose_cumul = 0;
}
if($datecheck==0) {
	$d = $dt->format('j');
	$m = $dt->format('n');
	$y = $dt->format('Y');
}
else if($datecheck==1) {
	$d = date("j", strtotime($date." +".$k." days"));
	$m = date("n", strtotime($date." +".$k." days"));
	$y = date("Y", strtotime($date." +".$k." days"));
}
$jwhich = date("w", mktime(0, 0, 0, $m, $d, $y));
$am_check = mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_hordemis WHERE demijour = '".$tabday[$jwhich]."_am' AND statut = 1"));
$pm_check = mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_hordemis WHERE demijour = '".$tabday[$jwhich]."_pm' AND statut = 1"));
if($am_check==1) { 
	if($houropen==0) {
		$nb_jclose_cumul = 0;
	}
	else {
		// Calcul des créneaux M ouverts :
		if($freq_gestion_jourscren['valeur']==0) {
			$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE hor_name LIKE 'M%' AND hor_freq LIKE '001%'");
			$hor_nb = mysqli_num_rows($hor);
			$nb_fullhour+=$hor_nb;
			if(isset($dayhour)) { $nb_fullet+=$hor_nb; }
			$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE (hor_name LIKE 'R%' OR hor_name LIKE 'T%' OR hor_name LIKE 'H%' OR hor_name LIKE 'C%') AND hor_freq LIKE '001%' AND debut <= '12:00:00'");
			$hor_nb = mysqli_num_rows($hor);
			$nb_fullhour+=$hor_nb;
			if(isset($dayhour)) { $nb_fullet+=$hor_nb; }
		}
		else {
			$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE hor_name LIKE 'M%' AND hor_freq LIKE '%".$daylc."001%'");
			$hor_nb = mysqli_num_rows($hor);
			$nb_fullhour+=$hor_nb;
			if(isset($dayhour)) { $nb_fullet+=$hor_nb; }
			$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE (hor_name LIKE 'R%' OR hor_name LIKE 'T%' OR hor_name LIKE 'H%' OR hor_name LIKE 'C%') AND hor_freq LIKE '%".$daylc."001%' AND debut <= '12:00:00'");
			$hor_nb = mysqli_num_rows($hor);
			$nb_fullhour+=$hor_nb;
			if(isset($dayhour)) { $nb_fullet+=$hor_nb; }
		}
		
	}
}
if($pm_check==1) { 
	if($houropen==0) {
		$nb_jclose_cumul += 0.5;
	}
	else {
		if($freq_gestion_jourscren['valeur']==0) {
			$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE (hor_name LIKE 'A%' OR hor_name LIKE 'R%') AND hor_freq LIKE '001%' AND debut >= '12:00:00'");
			$hor_nb = mysqli_num_rows($hor);
			$nb_fullhour+=$hor_nb;
			if(isset($dayhour)) { $nb_fullet+=$hor_nb; }
			$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE (hor_name LIKE 'T%' OR hor_name LIKE 'H%' OR hor_name LIKE 'C%') AND hor_freq LIKE '001%' AND debut >= '12:00:00'");
			$hor_nb = mysqli_num_rows($hor);
			$nb_fullhour+=$hor_nb;
			if(isset($dayhour)) { $nb_fullet+=$hor_nb; }
		}
		else {
			$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE (hor_name LIKE 'A%' OR hor_name LIKE 'R%') AND hor_freq LIKE '%".$daylc."001%' AND debut >= '12:00:00'");
			$hor_nb = mysqli_num_rows($hor);
			$nb_fullhour+=$hor_nb;
			if(isset($dayhour)) { $nb_fullet+=$hor_nb; }
			$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE (hor_name LIKE 'T%' OR hor_name LIKE 'H%' OR hor_name LIKE 'C%') AND hor_freq LIKE '%".$daylc."001%' AND debut >= '12:00:00'");
			$hor_nb = mysqli_num_rows($hor);
			$nb_fullhour+=$hor_nb;
			if(isset($dayhour)) { $nb_fullet+=$hor_nb; }
		}
		
	}
}
?>