<?php
if($anneesuiv=='now') {
	$eventdiv_select = "SELECT * FROM ".$prefix."_edtevent event
	INNER JOIN ".$prefix."_edtbrik brik
	ON event.brik_id = brik.brik_id
	LEFT JOIN ".$prefix."_sequences seq
	ON seq.seq_id = brik.seq_id
	LEFT JOIN ".$prefix."_edtcode code
	ON code.code = brik.code
	WHERE brik.division = '".$diveval."' AND event.week >= $renweek 
	ORDER BY event.dtstart";
}
else if($anneesuiv=='past') {
	$eventdiv_select = "SELECT * FROM ".$prefix."_edtevent event
	INNER JOIN ".$prefix."_edtbrik brik
	ON event.brik_id = brik.brik_id
	LEFT JOIN ".$prefix."_sequences seq
	ON seq.seq_id = brik.seq_id
	LEFT JOIN ".$prefix."_edtcode code
	ON code.code = brik.code
	WHERE brik.division = '".$diveval."' AND dtstart > '$date1' AND dtstart < '$date2'
	ORDER BY event.dtstart";
}
$eventdiv = mysqli_query($bdd,$eventdiv_select);
$eventdiv_nb = mysqli_num_rows($eventdiv);
if($eventdiv_nb!=0) {
	$edt_suivi .= '<div class="edtsuividiv"><p><b><a href="edt.php?page=eleves&division='.$diveval.'">'.SAV3.$diveval.'</a>'.DOTS.'</b></p><ul>';
	$edt_suivi_pdfnb .= '<div class="edtsuividiv"><p><b>'.SAV3.$diveval.DOTS.'</b></p><ul>';
	$edt_suivi_pdfcolor .= '<div class="edtsuividiv"><p><b>'.SAV3.$diveval.DOTS.'</b></p><ul>';
	foreach($eventdiv as $eventdiv_info) {
		if($anneesuiv=='now') {
			$eventcount_select = "SELECT uid FROM ".$prefix."_edtevent event
			INNER JOIN ".$prefix."_edtbrik brik
			ON event.brik_id = brik.brik_id
			LEFT JOIN ".$prefix."_sequences seq
			ON seq.seq_id = brik.seq_id
			WHERE brik.division = '$diveval' AND event.seq_id = '".$eventdiv_info['seq_id']."' AND brik.code = '".$eventdiv_info['code']."' AND event.dtstart < '".$eventdiv_info['dtstart']."' AND event.week >= $renweek";
		}
		else if($anneesuiv=='past') {
			$eventcount_select = "SELECT uid FROM ".$prefix."_edtevent event
			INNER JOIN ".$prefix."_edtbrik brik
			ON event.brik_id = brik.brik_id
			LEFT JOIN ".$prefix."_sequences seq
			ON seq.seq_id = brik.seq_id
			WHERE brik.division = '$diveval' AND event.seq_id = '".$eventdiv_info['seq_id']."' AND brik.code = '".$eventdiv_info['code']."' AND event.dtstart > '$date1' AND event.dtstart < '".$eventdiv_info['dtstart']."'";
		}
		$eventcount = mysqli_query($bdd,$eventcount_select);
		$eventcount_nb = mysqli_num_rows($eventcount);
		$dday = date("Ymd");
		$edt_suivi .= '<li class="seanceitem" style="background-color:';
		$edt_suivi_pdfnb .= '<li class="seanceitem" style="background-color:';
		$edt_suivi_pdfcolor .= '<li class="seanceitem" style="background-color:';
		if($eventdiv_info['bgcolor_code']!='') { $edt_suivi .= $eventdiv_info['bgcolor_code'].';">'; $edt_suivi_pdfcolor .= $eventdiv_info['bgcolor_code'].';">'; }
		else { $edt_suivi .= '#fff;">'; $edt_suivi_pdfcolor .= '#fff;">'; }
		$edt_suivi_pdfnb .= '#fff;">';
		$edt_suivi_s = '';
		if(substr($eventdiv_info['dtstart'],0,8)>=$dday) { $edt_suivi_s .= '<b>'; }
		$edt_suivi_s .= 'le '.substr($eventdiv_info['dtstart'],6,2).'/'.substr($eventdiv_info['dtstart'],4,2).'/'.substr($eventdiv_info['dtstart'],0,4).DOTS.' ';
		if($eventdiv_info['code']!='') { $edt_suivi_s .= $eventdiv_info['code'].' - '; }
		if($eventdiv_info['progression']!='1000') { $edt_suivi_s .= $eventdiv_info['progression'].'. '; }
		$edt_suivi_s .= ''.$eventdiv_info['seq_nom'].' ('.SEAN2.' n°'.($eventcount_nb+1).' - Durée : ';
		if($eventdiv_info['duration']==5) { $edt_suivi_s .= '0,5)'; }
		else { 
			$edt_suivi_s .= substr($eventdiv_info['duration'],0,1);
			if(substr($eventdiv_info['duration'],1,1)!=0) {
				$edt_suivi_s .= ','.substr($eventdiv_info['duration'],1,1);
			}
			$edt_suivi_s .= ')';
		}
		if(substr($eventdiv_info['dtstart'],0,8)>=$dday) { $edt_suivi_s .= '</b>'; }
		$edt_suivi_s .= '</li>';
		$edt_suivi .= $edt_suivi_s;
		$edt_suivi_pdfnb .= $edt_suivi_s;
		$edt_suivi_pdfcolor .= $edt_suivi_s;
	}
	$edt_suivi .= '</ul></div>';
	$edt_suivi_pdfnb .= '</ul></div>';
	$edt_suivi_pdfcolor .= '</ul></div>';
}
?>