<?php
// formulaire pour l'année
$year = date("Y");
echo '<form method="POST" name="annees" action="" class="padd3">
'.STATS_YEAR5.' ';
if(isset($_POST['nbyear'])){
	$_SESSION['nb_year'] = $_POST['nbyear'];
	if(@$_POST['frag']=='allyea') {
		$_SESSION['frag']='allyea';
		$day2 = $lastday;
	}
	else if(@$_POST['frag']=='actday') {
		$day2 = date('Y-m-d');
		$_SESSION['frag']='actday';
	}
}
else if(!isset($_SESSION['nb_year'])) { $_SESSION['nb_year'] = "2a"; }
$j=0;
for($i=($year+2);$i>($year-8);$i--) {
	$checkyear = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freq WHERE date_freq >= '".$i."-08-01' AND date_freq <= '".($i+1)."-07-31'");
	$checkyear_nb = mysqli_num_rows($checkyear);
	if($checkyear_nb!=0) {
		$j++;
	}
}
if($j==2) {
	echo STATS_YEAR6;
	echo '<input type="radio" name="frag" value="actday"';
	if(!isset($_POST['frag'])&&!isset($_SESSION['frag'])) { echo 'checked'; }
	else if($_POST['frag']=='actday'||$_SESSION['frag']=='actday') { echo 'checked'; }
	echo ' />'.STATS_YEAR3.' 
	<input type="radio" name="frag" value="allyea"';
	if($_SESSION['frag']=='allyea') { echo 'checked'; }
	echo ' />'.STATS_YEAR4.' ';
	echo '<input type="hidden" name="nbyear" value="2" />';
	echo '<input class="bouton boutedt" type="submit" value="'.VALID.'" name="anneechoix" />';
}
else if($j>2) {
	echo '<div class="box"><select name="nbyear">';
	echo '<option value="2a';
	if(isset($_SESSION['nb_year'])) { 
		if($_SESSION['nb_year']=='2a') { echo ' selected '; }
	}
	echo '">2 '.STATS_YEAR7.'</option>';
	for($k=3;$k<=$j;$k++) {
		echo '<option value="'.$k.'p"';
		if(isset($_SESSION['nb_year'])) { 
			if($_SESSION['nb_year']==''.$k.'p') { echo ' selected '; } 
		}
		echo '>'.($k-1).' '.STATS_YEAR8.'</option>';
		echo '<option value="'.$k.'a"';
		if(isset($_SESSION['nb_year'])) { 
			if($_SESSION['nb_year']==''.$k.'a') { echo ' selected '; } 
		}
		echo '>'.$k.' '.STATS_YEAR7.'</option>';
	}
	echo '</select></div>';
	echo ' <input class="bouton boutedt" type="submit" value="'.VALID.'" name="anneechoix" />';
}
echo '</form>';

$year1 = substr($renweek,0,4);
if($acadexist=="fnc"||$acadexist=="civ") { $anneesco = $year1; }
else { $anneesco = $year1.'/'.($year1+1); }
$day1 = $rentree;
if(!isset($_SESSION['frag'])) { $_SESSION['frag'] = 'noday'; }
if($_SESSION['frag']=='allyea'&&!isset($_POST['frag'])) {
	$day2 = $lastday;
}
else if($_SESSION['frag']=='actday'&&!isset($_POST['frag'])) {
	$day2 = date('Y-m-d');
}
else if(date('Y-m-d')<$day2&&!isset($_POST['frag'])) {
	$day2 = date('Y-m-d');
	$_SESSION['frag']='actday';
}
else if($_POST['frag']=='allyea') {
	$_SESSION['frag']='allyea';
	$day2 = $lastday;
}
else if($_POST['frag']=='actday') {
	$day2 = date('Y-m-d');
	$_SESSION['frag']='actday';
}

$dayP1 = strtotime($day1);
$dayname1 = date('D',$dayP1);
if($dayname1=="Mon") { 
	$jourP1 = date("Y-m-d", $dayP1);
}
else {
	$jourP1 = date("Y-m-d", strtotime("Previous Monday", $dayP1));
}
$jourP1date = new DateTime($jourP1);
$dayP2 = strtotime($day2);
$dayname2 = date('D',$dayP2);
if($dayname2=="Mon") {
	$jourP2to = strtotime(date("Y-m-d",$dayP2) . " +7 day");
	$jourP2last = strtotime(date("Y-m-d",$dayP2) . " +6 day");
}
else {
	$jourP2to = strtotime(date("Y-m-d",strtotime("Previous Monday", $dayP2)) . " +7 day");
	$jourP2last = strtotime(date("Y-m-d",strtotime("Previous Monday", $dayP2)) . " +6 day");
}
$jourP2 = date('Y-m-d',$jourP2to);
$jourP2dim = date('Y-m-d',$jourP2last);
$jourP2date = new DateTime($jourP2);
?>