<?php

echo '<h2>'.FSTATS_TIT8.'</h2>';

if($grappes_check==1) {
	echo FSTATS_AVERT1;
}

include('freq_stats_form.php');

echo '<h2>'.FROM21.' '.$affday1.' '.TO2.' '.$affday2.'</h2>';

echo '<p>'.FSTATS_TIT2.' ';

$totalfreq_nb = mysqli_num_rows(mysqli_query($bdd,"SELECT freq.freq_id FROM ".$prefix."_freq freq WHERE freq.date_freq >= '".$day1."' AND freq.date_freq <= '".$day2."' ".$filtre_activs.""));
if($grappes_check==1) {
	$elegrap_nb = mysqli_query($bdd,"SELECT nombre FROM ".$prefix."_freqgrappes WHERE date_freq >= '".$day1."' AND date_freq <= '".$day2."' AND passage = '0' ".$filtre_activs."");
	while($elegrap = mysqli_fetch_assoc($elegrap_nb)) {
		$totalfreq_nb += $elegrap['nombre'];
	}
}
if($totalfreq_nb==0) {
	echo FSTATS_INF1;
}
else {
	echo $totalfreq_nb;
	echo ' '.ELEVS1.'.</p>';

	//récupération des niveaux et couleurs par niveau
	include('freq_stats_nivcolors.php'); 

	$tabWeeks = array();
	foreach (new DatePeriod($jourP1date, new DateInterval('P7D') /* pas de sept jours */, $jourP2date) as $dt) {
		$week = $dt->format('oW');
		array_push($tabWeeks, $week);
	}

	echo '<form name="statscform" method="GET" action="">
	<input type="hidden" name="page" value="stats" />
	<input type="hidden" name="stat" value="default" />
	<div class="box"><select name="s" id="statschoix">';
		$stcode = array('zero','nbperniv','percentperniv','nbperdiv','percentperdiv','nbperweek','nbperweekperniv','nbperday','nbperdayperniv','all');
		$stname = $stname3;
		for($sno=0;$sno<count($stcode);$sno++) {
			if($stcode[$sno]=="nbperday"||$stcode[$sno]=='nbperdayperniv') {
				if(count($tabWeeks)<6) {
					echo '<option value="'.$stcode[$sno].'"';
					if(isset($_GET['s'])) {
						if($_GET['s']==$stcode[$sno]) {
							echo ' selected ';
						}
					}
					echo '>'.$stname[$sno].'</option>';
				}
			}
			else {
				echo '<option value="'.$stcode[$sno].'"';
				if(isset($_GET['s'])) {
					if($_GET['s']==$stcode[$sno]) {
						echo ' selected ';
					}
				}
				echo '>'.$stname[$sno].'</option>';
			}
		}
		echo '</select></div> <input type="submit" class="bouton boutfreq" value="'.CHOOSE.'" />
	</form>';

	echo '</article><article id="artleft" class="freqsep">';

	include('stats/freq_stats_def_div.php');

} ?>