<?php

echo FSTATS_TIT12;

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

// Définition des sessions selon l'académie
include('caloffsco.php');

if($acadexist=""||($acad_info['pays']=='fra'&&$acad_info['academie']=="")) {
	echo FSTATS_AVERT3;
}
else {
	include('freq_stats_form.php');

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

	$year = $_POST['fullyear'];
	if(mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_periodes WHERE anneesco = '".$year."'"))==0) {
		echo FSTATS_AVERT4;
	}

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

	$totalfreq = mysqli_query($bdd,"SELECT freq.freq_id FROM ".$prefix."_freq freq WHERE freq.date_freq >= '".$day1."' AND freq.date_freq <= '".$day2."' ".$filtre_activs."");
	$totalfreq_nb = mysqli_num_rows($totalfreq);
	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'); 

		echo '<form name="statscform" method="GET" action="">
		<input type="hidden" name="page" value="stats" />
		<input type="hidden" name="stat" value="periodes" />
		<div class="box"><select name="s" id="statschoix">';
			$stcode = array('zero','nbpermonth','nbpermonthperniv','nbpersession','nbpersessionperniv');
			$stname = $stname7;
			if(mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_periodes WHERE anneesco = '".$year."'"))!=0) {
				array_push($stcode,'nbperperiode');
				array_push($stcode,'nbperperiodeperniv');
				array_push($stname,ST_OPTPER1);
				array_push($stname,ST_OPTPER2);				
			}
			array_push($stcode,'all');
			array_push($stname,ST_ALL);
			for($sno=0;$sno<count($stcode);$sno++) {
				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_per_div.php');
	} 
}
?>