<?php
$jourabbr = array('lu','ma','me','je','ve','sa','di');
// Calcul du nombre de créneaux ouverts dans une semaine :
if($freq_gestion_jourscren['valeur']==0) {
	// nombre de créneaux matin
	$nbcrenmat_nb = mysqli_num_rows(mysqli_query($bdd,"SELECT hor_id FROM ".$prefix."_horaires WHERE hor_name LIKE 'M%' AND hor_freq LIKE '001%'"));
	// nombre de créneaux midi
	$nbcrenmid_nb = mysqli_num_rows(mysqli_query($bdd,"SELECT hor_id FROM ".$prefix."_horaires WHERE hor_name LIKE 'R%' AND hor_freq LIKE '001%'"));
	// nombre de créneaux après-midi
	$nbcrenapr_nb = mysqli_num_rows(mysqli_query($bdd,"SELECT hor_id FROM ".$prefix."_horaires WHERE hor_name LIKE 'A%' AND hor_freq LIKE '001%'"));
	// nombre de jours am
	$nbjouram_nb = mysqli_num_rows(mysqli_query($bdd,"SELECT id FROM ".$prefix."_hordemis WHERE demijour LIKE '%am' AND statut=1"));
	// nombre de jours am et pm
	$midi=0;
	foreach($jourabbr as $jourcheck) {
		$nbjour_nb = mysqli_num_rows(mysqli_query($bdd,"SELECT id FROM ".$prefix."_hordemis WHERE demijour = '".$jourcheck."%' AND statut=1"));
		if($nbjour_nb==2) { $midi+=1; }
	}
	// nombre de jours pm
	$nbjourpm_nb = mysqli_num_rows(mysqli_query($bdd,"SELECT id FROM ".$prefix."_hordemis WHERE demijour LIKE '%pm' AND statut=1"));

	$nb_creneaux = ($nbcrenmat_nb*$nbjouram_nb)+($nbcrenmid_nb*$midi)+($nbcrenapr_nb*$nbjourpm_nb);
}
else {
	$i=0;
	$nb_creneaux = 0;
	foreach($daysOfWeek as $key => $val) {
		$key = strtoupper(substr($key,0,1)).substr($key,1,2);
		if(mysqli_num_rows(mysqli_query($bdd,"SELECT id FROM ".$prefix."_hordemis WHERE demijour = '".$jourabbr[$i]."%' AND statut=1"))!=2) {
			$nb_creneaux += mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE hor_freq LIKE '%".$key."001%'"));
		}
		$i++;
	}
}
?>
