<?php
echo '<meta charset="utf-8" />';

if(isset($_SESSION['user_droits'])) {
	$droits = substr($_SESSION['user_droits'],3,1);
	
	if ($droits==1) 	{
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="./index.php">'.ACCUEIL.'</a></p>';
	}
	else {
		function Age($date_naissance) {
			$arr1 = explode('/', $date_naissance);
			$arr2 = explode('/', date('d/m/Y'));
			if(($arr1[1] < $arr2[1]) || (($arr1[1] == $arr2[1]) && ($arr1[0] <= $arr2[0])))
			return $arr2[2] - $arr1[2];
			return $arr2[2] - $arr1[2] - 1;
		}

		?><style type="text/css">
		#mfr1 { background-color: #fff; }
		#mfr1 td { border: 3px #B90404 solid; }
		</style><?php

		echo '<h1>'.FREQT.' '.$_SESSION['lieu_genre1'].$_SESSION['lieu_nom'].'</h1>';
		
		//Vérification des suspensions
		include('db/proc/freq_finsuspension.php');
		
		//horaire
		$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires");
		$hor_nb = mysqli_num_rows($hor);
		
		if(!isset($_SESSION['timestop'])) { $_SESSION['timestop']=0; }

		//option créneau, classe et appel
		$crenchoix = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_cienchoix'");
		$crenchoix_info = mysqli_fetch_assoc($crenchoix);
		if($crenchoix_info['valeur']!=$_SESSION['crenchoix']&&$_SESSION['crenchoix']!='def') {
			$crenchoix_info['valeur']=$_SESSION['crenchoix'];
		}
		$classe = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_classe'");
		$classe_info = mysqli_fetch_assoc($classe);
		$classe_info_valeur = substr($classe_info['valeur'],0,1);
		if(substr($classe_info['valeur'],0,1)!=substr($_SESSION['classinscript'],0,1)&&$_SESSION['classinscript']!='def') {
			$classe_info_valeur=substr($_SESSION['classinscript'],0,1);
		}
		$seance_appel = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_parametres WHERE param_nom = 'freq_seance_appel'"));
		if($seance_appel['valeur']!=$_SESSION['affgroupe']&&$_SESSION['affgroupe']!='def') {
			$seance_appel['valeur']=$_SESSION['affgroupe'];
		}
		$pronote_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_inscritpronote'"));
		$appelchoix = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_appel'");
		$appelchoix_info = mysqli_fetch_assoc($appelchoix);
		$verrtest = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_verractiv'"));
		$verresp = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_verrespace'"));
		$espopt = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'espaces_gestion'"));
		$esp0 = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'espaces_first'"));
		$res_activ = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_resactiv'"));
		$reseleve_could=mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_reseleve'"));
		$reseleve_activ = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_parametres WHERE param_nom = 'freq_reseleve_activ'"));
		$crpre_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_crprechoix'"));
		if($crpre_info['valeur']!=$_SESSION['inscprec']&&$_SESSION['inscprec']!='def') {
			$crpre_info['valeur']=$_SESSION['inscprec'];
		}
		$inscriptr_check = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freqres_inscriptallday'");
		$inscriptr_check_info = mysqli_fetch_assoc($inscriptr_check);
		if($inscriptr_check_info['valeur']!=$_SESSION['inscriptallday']&&$_SESSION['inscriptallday']!='def') {
			$inscriptr_check_info['valeur']=$_SESSION['inscriptallday'];
		}
		$excluopt_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt'"));
		$check_activ_obli = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_activ_obli'"));
		$activcren = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_parametres WHERE param_nom = 'freq_activitescreneaux'"));
		if($activcren['valeur']!='0') {
			$actcren = explode(';',$activcren['valeur']);
			foreach ($actcren as $val) {
		        $moment = substr($val, 0, 1);   // M, A, P...
		        $idActiv = substr($val, 1);     // 8, 12, 6
		        $defaultActivites[$moment] = $idActiv;
		    }
		}
							
		if($droits==2) {
			// Suppression de résidus de réservations :
			$dday = date("Y-m-d");
			mysqli_query($bdd,"UPDATE ".$prefix."_freqres SET statut = '4' WHERE date_freqres < DATE(CONVERT_TZ(UTC_TIMESTAMP(), 'UTC', '".$fuseau."')) AND statut = '0'");
					
			// S'il n'y a pas d'élève(s) dans la base :
			$verif_tabeleves = mysqli_query($bdd,"SELECT * FROM ".$prefix."_eleves");
			$nb_ele = mysqli_num_rows($verif_tabeleves);
			if($nb_ele==0) {
				echo '<a href="database.php">'.FREQC_IND1.'</a>.';
			}
		}
	
		// S'il n'y a pas d'horaires configurés :
		
		if($hor_nb==0) {
			$crenforactiv = '';
			if($droits==2) {
				echo '<p><a href="param.php?page=horaires">'.FREQ_HORNEED.'</a>.</p>';
			}
			else {
				echo '<p>'.FREQC_IND2.'</p>';
			}
		}
	
		else {
			if(@$inscriptr_check_info['valeur']=='1'||$_SESSION['affresa_norights']=='1') {
				$pagelisteresa = 0;
				include('./db/proc/freq_res_all.php');
			}
			echo '<h2>'.date("d/m/Y").' - '.date("H:i");
			$nb_anticip = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_creneausuiv'"));
			if($nb_anticip['valeur']!=$_SESSION['minutes']&&$_SESSION['minutes']!='def') {
				$nb_anticip['valeur']=$_SESSION['minutes'];
			}
			$heureh = date("H:i:s");
			$soluce = 0;
			$anticipe=0;
		
			// Boucle pour définir le créneau actuel :			
			foreach($hor as $creneau_info) {
				if($heureh >= $creneau_info['debut']&&$heureh < $creneau_info['fin']) {
										
					$anticipe=0;
					if($nb_anticip['valeur']!=0) {
						$interval = (mktime(substr($creneau_info['fin'],0,2),substr($creneau_info['fin'],3,2),substr($creneau_info['fin'],6,2),date('m'),date('d'),date('Y'))-strtotime($heureh));
						if($interval<(60* (int) $nb_anticip['valeur'])) {
							$creneau_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE num_creneau = ".($creneau_info['num_creneau']+1).""));
							$anticipe = 1;
							if(!isset($creneau_info['hor_name'])){
								$creneau_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE (num_creneau = (SELECT MAX(num_creneau) FROM ".$prefix."_horaires))"));
								$anticipe=0;
							}
						}
					}

					echo '<br>';
					if($anticipe==1) {
						echo '<span class="signal">';
					}
					echo FREQC_IND3.' ';
					$cren = $creneau_info['hor_name'];
					$creneau = $creneau_info['hor_name'];
					$deb_cren = substr("$cren", 0, 1);
					$crenforactiv = $deb_cren;
					$crenpdf ='';
					echo MOMENT[$deb_cren];
					$crenpdf .= MOMENT[$deb_cren];
					$fin_cren = substr("$cren", 1, 1);
					echo ' '.$fin_cren.' '.FROM.' ';
					$crenpdf .= ' '.$fin_cren.' '.FROM.' ';
					$deb = $creneau_info['debut'];
					$dh = substr("$deb", 0, 2);
					$dm = substr("$deb", 3, 2);
					echo $dh.'h'.$dm.' '.TO.' ';
					$crenpdf .= $dh.'h'.$dm.' '.TO.' ';
					$fin = $creneau_info['fin'];
					$fh = substr("$fin", 0, 2);
					$fm = substr("$fin", 3, 2);
					echo $fh.'h'.$fm.'</h2>';
					$crenpdf .= $fh.'h'.$fm;
					$soluce = 1;
					if(substr($appelchoix_info['valeur'],0,1)==2){
						if(substr($appelchoix_info['valeur'],2,1)==2) {
							if($cren!=substr($appelchoix_info['valeur'],4,2)) {
								mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '2:1:".$cren."' WHERE param_nom = 'freq_appel'");
							}
						}
					}
					$_SESSION['ccren'] = $cren;
					$_SESSION['num'] = $creneau_info['num_creneau'];
					$_SESSION['creneau'] = $creneau_info['hor_name'];
					$_SESSION['droits'] = $droits;
					$_SESSION['espopt'] = $espopt['valeur'];
					$_SESSION['esp0'] = $esp0['valeur'];
					$_SESSION['crenpdf'] = $crenpdf;
					break;
				}
			}
			$antday=0;
			if($nb_anticip['valeur']!=0&&$soluce==0) { //anticipation sur le premier créneau de la journée
				foreach($hor as $creneau_info) {
					$interval = (mktime(substr($creneau_info['debut'],0,2),substr($creneau_info['debut'],3,2),substr($creneau_info['debut'],6,2),date('m'),date('d'),date('Y'))-strtotime($heureh));
					if($interval<(60* (int) $nb_anticip['valeur'])) {
						$creneau_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE num_creneau = ".($creneau_info['num_creneau']).""));
						$anticipe = 1;
						echo '<br>';
						if($anticipe==1) {
							echo '<span class="signal">';
						}
						echo FREQC_IND3.' ';
						$_SESSION['nextday'] = Date('Y-m-d', strtotime(date('Y-m-d').' +1 Day'));
						$antday = 1;
						echo 'le '.substr($_SESSION['nextday'],8,2).'/'.substr($_SESSION['nextday'],5,2).'/'.substr($_SESSION['nextday'],0,4).' - ';
						$cren = $creneau_info['hor_name'];
						$creneau = $creneau_info['hor_name'];
						$deb_cren = substr("$cren", 0, 1);
						$crenforactiv = $deb_cren;
						echo MOMENT[$deb_cren];
						$fin_cren = substr("$cren", 1, 1);
						echo ' '.$fin_cren.' '.FROM.' ';
						$deb = $creneau_info['debut'];
						$dh = substr("$deb", 0, 2);
						$dm = substr("$deb", 3, 2);
						echo ''.$dh.'h'.$dm.' '.TO.' ';
						$fin = $creneau_info['fin'];
						$fh = substr("$fin", 0, 2);
						$fm = substr("$fin", 3, 2);
						$hantday = $dh.$dm.'00';
						echo ''.$fh.'h'.$fm.'</h2>';
						$soluce = 1;
						if(substr($appelchoix_info['valeur'],0,1)==2){
							if(substr($appelchoix_info['valeur'],2,1)==2) {
								if($cren!=substr($appelchoix_info['valeur'],4,2)) {
									mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '2:1:".$cren."' WHERE param_nom = 'freq_appel'");
								}
							}
						}
						$_SESSION['ccren'] = $cren;
						$_SESSION['num'] = $creneau_info['num_creneau'];
						break;
					}
				}
			}
			else {
				if(isset($_SESSION['nextday'])) {
					unset($_SESSION['nextday']);
				}
			}
			
			if($anticipe==1) {
				echo '</span>';
			}
			echo '</h2>';
			
			if($droits!=3&&$droits!=5) {
				// Suppression de résidus de réservations (affinés au créneau) :
				$dday = date("Y-m-d");
				$freqres = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqres WHERE statut ='0'");
				while($freqres_info = mysqli_fetch_assoc($freqres)) {
					$creneau = $freqres_info['hor_name'];
					$hor = mysqli_query($bdd,"SELECT num_creneau FROM ".$prefix."_horaires WHERE hor_name = '".$creneau."'");
					$hor_info = mysqli_fetch_assoc($hor);
					if(isset($_SESSION['num'])) {
						if($freqres_info['date_freqres'] == $dday && $hor_info['num_creneau'] < $_SESSION['num']) {
							mysqli_query($bdd,"UPDATE ".$prefix."_freqres SET statut = '4' WHERE date_freqres < DATE(CONVERT_TZ(UTC_TIMESTAMP(), 'UTC', '".$fuseau."')) AND hor_name = '".$creneau."' AND statut = '0'");
						}
					}
				}
				
				// Si choix du créneau impossible :
				if($freq_gestion_jourscren['valeur']==0) {
					$creneau_info['hor_freq'] = @intval(substr($creneau_info['hor_freq'],0,3));
				}
				else {
					$creneau_info['hor_freq'] = @intval(substr($creneau_info['hor_freq'], strpos($creneau_info['hor_freq'], date('D')) + strlen(date('D')), 3));
				}
				if($crenchoix_info['valeur']==0&&$soluce==0) {
					// Message en cas d'absence de créneau :
					echo '<p>'.FREQ_HORERR2;
					if($droits==2) {
						echo '<br>'.PARAM_LINK1;
					}
					echo '</p>';
				}
				else if($crenchoix_info['valeur']==0&&$creneau_info['hor_freq']=="000") {
					$crenforactiv = '';
					echo '<p>'.FREQ_NO1.'</p>';
				}
				
				// Gestion de l'inscription des élèves :
				else if($soluce==1||$crenchoix_info['valeur']==1) {
					// Gestion du forcing en cas d'exclusion
					if(isset($_POST['ins_forcing'])) {
						for($i=1;$i<=$_SESSION['forcing_multi'];$i++) {
							if(isset($_POST['forc_check'.$i])) {
								if(mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_freq WHERE eleves_id = '".$_SESSION['forc'.$i][3]."' AND date_freq = '".$_SESSION['forc'.$i][4]."' AND hor_name = '".$_SESSION['forc'.$i][5]."' AND code_activ = '".$_SESSION['forc'.$i][6]."'"))==1) {
									if($espopt['valeur']==1) { $espsql = ", espace_id = '".$_SESSION['forc'.$i][10]."' "; }
									else { $espsql = ""; }
									$hcheck = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT h_sortie_2, h_sortie_3 FROM ".$prefix."_freq WHERE eleves_id = '".$_SESSION['forc'.$i][3]."' AND date_freq = '".$_SESSION['forc'.$i][4]."' AND hor_name = '".$_SESSION['forc'.$i][5]."' AND code_activ = '".$_SESSION['forc'.$i][6]."'"));
									$h_inscrit = date('Ymd').'T'.date('His');
									if(@strlen($hcheck['h_sortie_2'])==15) { $hs = 'h_inscription3'; }
									else { $hs = 'h_inscription2'; }
									mysqli_query($bdd,"UPDATE ".$prefix."_freq SET cas = ''".$espsql.", ".$hs." = '".$h_inscrit."' WHERE eleves_id = '".$_SESSION['forc'.$i][3]."' AND date_freq = '".$_SESSION['forc'.$i][4]."' AND hor_name = '".$_SESSION['forc'.$i][5]."' AND code_activ = '".$_SESSION['forc'.$i][6]."'");
								}
								else {
									if($espopt['valeur']==1) {
										mysqli_query($bdd,"INSERT INTO ".$prefix."_freq (eleves_id, date_freq, hor_name, code_activ, division, sexe, h_inscription, user_id, espace_id) VALUES ('".$_SESSION['forc'.$i][3]."', '".$_SESSION['forc'.$i][4]."', '".$_SESSION['forc'.$i][5]."', '".$_SESSION['forc'.$i][6]."', '".$_SESSION['forc'.$i][7]."', '".$_SESSION['forc'.$i][8]."', '".$_SESSION['forc'.$i][9]."', '".$_SESSION['user_id']."', '".$_SESSION['forc'.$i][10]."')");
									}
									else {
										mysqli_query($bdd,"INSERT INTO ".$prefix."_freq (eleves_id, date_freq, hor_name, code_activ, division, sexe, h_inscription, user_id, espace_id) VALUES ('".$_SESSION['forc'.$i][3]."', '".$_SESSION['forc'.$i][4]."', '".$_SESSION['forc'.$i][5]."', '".$_SESSION['forc'.$i][6]."', '".$_SESSION['forc'.$i][7]."', '".$_SESSION['forc'.$i][8]."', '".$_SESSION['forc'.$i][9]."', '".$_SESSION['user_id']."', '0')");
									}
								}
							}
						}
					}
					$_SESSION['forcing_multi']=0;
					// Gestion de l'enregistrement des inscrits nominatifs dans la BDD
					if(isset($_POST['inscrire'])&&@$_POST['pronliste']=="") {
						$per_eleve = 1;
						$grappes = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_grappes'"));
						if($grappes['valeur']==1) {
							if($_POST['nbgrap']!=0&&$_POST['nbgrap']!="") {
								if($_POST['nivgrap']==""&&$_POST['divgrap']=="") {
									echo '<p class="signal">'.FREQC_IND4.'</p>';
									$per_eleve = 0;
								}
								else {
									include('./db/proc/freq_inscript_grappes.php');
									$per_eleve = 0;
								}
							}
						}
						if($per_eleve == 1) {
							//sélection de l'élève
							include('./db/proc/eleve_select.php');
							include('./db/proc/freq_inscript_eleves.php');
							if(isset($_SESSION['forcing_multi'])) {
								echo '<form method="POST" action="" name="ins_forcing" class="padd2">';
								for($i=1;$i<=$_SESSION['forcing_multi'];$i++) {
									if($_SESSION['forcing_reason']=='exc') {
										echo '<p class="signal"><input type="checkbox" name="forc_check'.$i.'" id="forc_check'.$i.'" checked /> <label for="forc_check'.$i.'"> '.FREQ_NORESA7.' '.$_SESSION['forc'.$i][0].' '.$_SESSION['forc'.$i][1].' ('.$_SESSION['forc'.$i][2].').</label></p>';
									}
									else {
										echo '<p class="signal"><input type="checkbox" name="forc_check'.$i.'" id="forc_check'.$i.'" checked /> <label for="forc_check'.$i.'">'.FREQ_NORESA81.' '.$_SESSION['forc'.$i][0].' '.$_SESSION['forc'.$i][1].' ('.$_SESSION['forc'.$i][2].') - '.@$_SESSION['forc'.$i][11];
										if(@$_SESSION['forc'.$i][12]==0) {
											echo ' ('.$esp0['valeur'].')';
										}
										else {
											$espace_n = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_espaces WHERE espace_id = '".$_SESSION['forc'.$i][12]."'"));
											echo ' ('.$espace_n['espace_nom'].')'; 
										}
										echo '.</label></p>';
									}
								}
								if($_SESSION['forcing_multi']>0) {
									echo '<input class="bouton boutfreq" type="submit" name="ins_forcing" value="'.FREQ_FORCING1.'" /></form>';
								}
							}
						}
					}
					
					// AFFICHAGE ACCUEIL
					if($soluce==0&&!isset($_POST['inscrire'])) {
						$crenforactiv = '';
						echo '<p>'.FREQ_NO1.'</p>';
					}
					if($soluce==0&&$droits!=2) {
						echo '<p>'.FREQC_IND5.'</p>';
					}
					else {
						//formulaire de suggestion
						echo '<form method="POST" id="incription" name="inscript" action="" class="padd3">';
						if($soluce==0) {
							echo '<input type="hidden" name="soluce" value="0" />';
						}
						else {
							echo '<input type="hidden" name="soluce" value="1" />';
						}
						// Si inscription par grappes :
						$grappes = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_grappes'"));
						if($grappes['valeur']==1) {
							// formulaire
							echo '<div class="grappes preins" name="noprint"><table class="left">
							<tr name="noprint"><td name="noprint" colspan="5">'.LEVEL.DOTS.' 
							<div class="box"><select name="nivgrap" value="">';
							echo '<option></option>';
							$niv1 = array('6','5','4','3','2','1','t','a');
							$nivname = array('6ème','5ème','4ème','3ème','2nde','1re','Tale','Autre');
							$verif_nivs = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_statsniv'"));
							if($verif_nivs['valeur']=="COL" OR $verif_nivs['valeur']=="CIT") { 
								for($no=0;$no<4;$no++) {
									echo '<option value="'.$niv1[$no].'"';
									if(isset($_SESSION['nivgrap'])) {
										if($_SESSION['nivgrap']==$niv1[$no]) { 
											echo ' selected '; 
										}
									}
									echo '>'.$nivname[$no].'</option>';
								}
							}
							if($verif_nivs['valeur']=="LYC" OR $verif_nivs['valeur']=="LYA" OR $verif_nivs['valeur']=="CIT") { 
								for($no=4;$no<7;$no++) {
									echo '<option value="'.$niv1[$no].'"';
									if(isset($_SESSION['nivgrap'])) {
										if($_SESSION['nivgrap']==$niv1[$no]) { 
											echo ' selected '; 
										}
									}
									echo '>'.$nivname[$no].'</option>';
								} 
							}
							if($verif_nivs['valeur']=="LYA" OR $verif_nivs['valeur']=="CIA") { 
								echo '<option value="'.$niv1[7].'"';
								if(isset($_SESSION['nivgrap'])) {
									if($_SESSION['nivgrap']==$niv1[7]) { 
										echo ' selected '; 
									}
								}
								echo '>'.$nivname[7].'</option>';
							}
							echo '</select></div></td></tr><tr name="noprint"><td name="noprint" colspan="5">'.DIV.DOTS.' 
							<div class="box"><select name="divgrap" value="">';
							echo '<option></option>';
							$liste_division = mysqli_query($bdd,"SELECT division FROM ".$prefix."_eleves WHERE categ = '1' GROUP BY division ORDER BY division ASC");
							while($listegd = mysqli_fetch_assoc($liste_division)) {
								echo '<option';
								if(isset($_SESSION['divgrap'])) {
									if($_SESSION['divgrap']==$listegd['division']) {
										echo ' selected ';
									}
								}
								echo '>'.$listegd['division'].'</option>';
							}
							$liste_groupe = mysqli_query($bdd,"SELECT groupe_nom FROM ".$prefix."_groupes WHERE groupe_actif = 1 GROUP BY groupe_nom ORDER BY groupe_nom ASC");
							while($listegg = mysqli_fetch_assoc($liste_groupe)) {
								echo '<option';
								if(isset($_SESSION['divgrap'])) {
									if($_SESSION['divgrap']==$listegd['groupe_nom']) {
										echo ' selected ';
									}
								}
								echo '>'.$listegg['groupe_nom'].'</option>';
							}
							echo '</select></div></td></tr><tr name="noprint"><td name="noprint" colspan="5">'.NUMBER.DOTS.' <input type="number" name="nbgrap" value="0" style="width:50px;" /></td></tr>';
							$passverif = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_passages'"));
							if($passverif['valeur']==1) { echo '<tr name="noprint"><td name="noprint" colspan="5">'.PASS.DOTS.' <input type="checkbox" name="passgrap" id="passgrap"';
							if(isset($_SESSION['passgrap'])) {
								if($_SESSION['passgrap']==1) {
									echo ' checked';
								}
							}	
							echo ' /></td></tr>'; }
							
							if(isset($_SESSION['nextday'])) {
								$dday = $_SESSION['nextday'];
							}
							//inscrits
							@$grappes_ins = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqgrappes freqg LEFT JOIN ".$prefix."_espaces espaces ON freqg.espace_id = espaces.espace_id WHERE freqg.date_freq = '".$dday."' AND freqg.hor_name = '".$cren."' AND freqg.passage = '0' ORDER BY freqg.niveau DESC, freqg.division ASC");
							if(mysqli_num_rows($grappes_ins)>0) {
								echo '<tr><td colspan="5"><b>'.GRAPS1.DOTS.'</b></td></tr>';
								while($grappe = mysqli_fetch_assoc($grappes_ins)) {
									$activ_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT nom_activ FROM ".$prefix."_freqactiv WHERE code_activ = '".$grappe['code_activ']."'"));
									echo '<tr><td>';
										if($grappe['niveau']=='6') { echo '6ème'; }
										else if($grappe['niveau']=='5') { echo '5ème'; }
										else if($grappe['niveau']=='4') { echo '4ème'; }
										else if($grappe['niveau']=='3') { echo '3ème'; }
										else if($grappe['niveau']=='2') { echo '2nde'; }
										else if($grappe['niveau']=='1') { echo '1re'; }
										else if($grappe['niveau']=='t') { echo 'Tale'; }
										else if($grappe['niveau']=='a') { echo 'Autre'; }
										echo '</td><td>'.$grappe['division'].'</td><td>'.$grappe['nombre'].'</td><td';
										if($espopt['valeur']==0) { echo ' colspan="2"'; }
										echo '>'.$activ_info['nom_activ'].'</td>';
										if($espopt['valeur']==1) {
											if($grappe['espace_id']!=0) { 
												echo '<td>'.$grappe['espace_nom'].'</td>'; }
											else { echo '<td>'.$esp0['valeur'].'</td>'; }
										}
										echo '</tr>';
								}
							}
							if($passverif['valeur']==1) {
								$grappes_insp = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqgrappes WHERE dtstart LIKE '".substr($dday,0,4).substr($dday,5,2).substr($dday,8,2)."%' AND passage = '1' ORDER BY dtstart DESC");
								if(mysqli_num_rows($grappes_insp)>0) {
									echo '<tr><td colspan="5"><b>'.PASS2.'</b></td></tr>';
									while($grappe = mysqli_fetch_assoc($grappes_insp)) {
										echo '<tr><td>';
										if($grappe['niveau']=='6') { echo '6ème'; }
										else if($grappe['niveau']=='5') { echo '5ème'; }
										else if($grappe['niveau']=='4') { echo '4ème'; }
										else if($grappe['niveau']=='3') { echo '3ème'; }
										else if($grappe['niveau']=='2') { echo '2nde'; }
										else if($grappe['niveau']=='1') { echo '1re'; }
										else if($grappe['niveau']=='t') { echo 'Tale'; }
										else if($grappe['niveau']=='a') { echo 'Autre'; }
										echo '</td><td>'.$grappe['division'].'</td><td>'.$grappe['nombre'].'</td><td colspan="2">'.substr($grappe['dtstart'],-6,2).':'.substr($grappe['dtstart'],-4,2).'</td></tr>';
									}
								}
							}
							echo'</table></div>';
						}
						
						// Si choix du créneau possible :
						if($crenchoix_info['valeur']==1&&($droits==2||$droits==6||$droits==4)) {
							echo '<p name="noprint"><a href="javascript:;clearTimeout(timer);" id="chg_metarefresh" style="color:black;text-decoration:none;" onmouseover="this.style.textDecoration=\'underline\';" onmouseout="this.style.textDecoration=\'none\';" onmousedown="toggleDiv(\'divcren\');" onclick = "setTimeout(function() { window.location = window.location;
								}, 240000);">
							<i class="fas fa-angle-double-right"></i> <b>'.FREQC_IND6.'</b></a></p>';
							echo '<div name="noprint" id="divcren"';
							if(isset($_SESSION['datepickchoix'])) {
								if($_SESSION['datepickchoix']!="") {
									echo '>';
								}
								else echo ' style="display:none;">';
							}
							else { echo ' style="display:none;">'; }
							?><input type="button" class="boutontab" onclick="clearTimeout(timer);setTimeout(function() { window.location = window.location;
									}, 240000);" id="clear" value="Vider les champs" />
							<script>
								var element = document.getElementById("clear");
								element.addEventListener("click", function() {
								var param = "clear";
								document.getElementById("datepick").value="";
								document.getElementById("crenpicker").value="";
								$.ajax({
								    type: "POST",
								    data: { param: param },
								    url: "js/idl/freq_ind_syn.php",
								});
							});
							</script><?php
							echo '<p name="noprint">Date : <input type="date" onclick="clearTimeout(timer);setTimeout(function() { window.location = window.location;
									}, 240000);" class="datepick inptxt" id="datepick" name="datepick" value="';
							if(isset($_SESSION['datepickchoix'])) {
								if($_SESSION['datepickchoix']!="") {
									echo $_SESSION['datepickchoix'];
								}
							}
							else {
								echo date('Y-m-d');
							}
							echo '">
							<br><br>Créneau : <div class="box"><select name="crenpicker" onclick="clearTimeout(timer);setTimeout(function() { window.location = window.location;
									}, 240000);" id="crenpicker" value="">';
							echo '<option></option>';
							if($freq_gestion_jourscren['valeur']==0) {
								$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE hor_freq LIKE '001%' ORDER BY num_creneau ASC");
							}
							else {
								$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE hor_freq LIKE '%001%' ORDER BY num_creneau ASC");
							}
							foreach($hor as $liste) {
								$cren = $liste['hor_name'];
								$deb_cren = substr("$cren", 0, 1);
								echo '<option value="'.$liste['hor_name'].'"';
								if(isset($_SESSION['crenpickerchoix'])) {
									if($_SESSION['crenpickerchoix']==$liste['hor_name']) {
										echo ' selected ';
									}
								}
								echo '>'.$liste['hor_name'].' - ';
								echo MOMENT[$deb_cren];
								$deb = $liste['debut'];
								$dh = substr("$deb", 0, 2);
								$dm = substr("$deb", 3, 2);
								echo ' '.FROM.' '.$dh.'h'.$dm.' '.TO.' ';
								$fin = $liste['fin'];
								$fh = substr("$fin", 0, 2);
								$fm = substr("$fin", 3, 2);
								echo ''.$fh.'h'.$fm.'';
								echo '</option>';
							}
							echo '</select></div></p>';
							echo '<input type="radio" name="seance" id="seanon" value="non" checked /><span name="noprint"><label for="seanon">'.FREQC_IND7.'</label></span>
							<br /><input type="radio" name="seance" id="seaoui" class="seance" value="create" /><span name="noprint"><label for="seaoui">'.FREQC_IND8.' </label></span>
							<div class="box"><select name="sequence" id="seqchoix" value=""';
							if($grappes['valeur']==1) { echo ' style="width:400px;" '; }
							echo '><option></option>';
							$liste_sequence = mysqli_query($bdd,"SELECT * FROM ".$prefix."_sequences ORDER BY niveau ASC, seq_nom ASC");
							while($listes = mysqli_fetch_assoc($liste_sequence)) {
								echo '<option value="'.$listes['seq_id'].'">';
								if($listes['niveau']=='6') { echo '6ème'; }
								else if($listes['niveau']=='5') { echo '5ème'; }
								else if($listes['niveau']=='4') { echo '4ème'; }
								else if($listes['niveau']=='3') { echo '3ème'; }
								else if($listes['niveau']=='2') { echo '2nde'; }
								else if($listes['niveau']=='1') { echo '1re'; }
								else if($listes['niveau']=='t') { echo 'Tale'; }
								else if($listes['niveau']=='a') { echo 'Autre'; }
								echo ' : '.$listes['seq_nom'].'</option>';
							}
							echo '</select></div>';?>
							<script>
							document.getElementById("seqchoix").onchange = function() {
								var radios = this.form.elements["seance"];
								// loop through list of radio buttons
								for (var i=0, len=radios.length; i<len; i++) {
									var r = radios[i]; // current radio button
									if ( r.value === "create" ) { // standard shipping
										r.checked = true; // set checked
									} else { // not standard shipping
										r.checked = false; // unchecked
									}
								}
								var radios = this.form.elements["selectactiv"];
								// loop through list of radio buttons
								for (var i=0, len=radios.length; i<len; i++) {
									var r = radios[i]; // current radio button
									if ( r.value === "SEAN" ) { // standard shipping
										r.checked = true; // set checked
									} else { // not standard shipping
										r.checked = false; // unchecked
									}
								}
							}
							</script>
							</div><?php
						}
						
						//Si possibilité d'inscrire une classe :
						if($classe_info_valeur==1&&($droits==2||$droits==6||$droits==4)&&$onlycode_check_info['valeur']=='0') {
							$page_check = 'ins';
							include('./db/proc/groupe_select.php');
						}

						//Si possibilité d'inscrire depuis pron. :
						if($pronote_info['valeur']==1&&($droits==2||$droits==6||$droits==4)&&$onlycode_check_info['valeur']=='0') {
							echo '<p name="noprint" style="margin-top:-17px;"><a href="javascript:;clearTimeout(timer);" style="color:black;text-decoration:none;" onmouseover="this.style.textDecoration=\'underline\';" onmouseout="this.style.textDecoration=\'none\';" onmousedown="toggleDiv(\'divpron\');" onclick = "setTimeout(function() { window.location = window.location;
								}, 240000);"><i class="fas fa-angle-double-right"></i> <b>'.FREQC_IND9.'</b></a></p>';
							if(isset($_POST['inscrire'])&&@$_POST['pronliste']!="") {
								include('./db/proc/groupe_pronote.php');
							}
							echo '<div id="divpron" style="display:none;">';
							echo '<textarea rows="30" cols="40" name="pronliste" value=""></textarea>';
							echo '</div>';
							echo '<p />';
						}
														
						//Choix de l'élève :
						echo '<table name="form">
							<tr>
								<td><label for="eleves">';
								if($onlycode_check_info['valeur']=='1') {
									echo CODE3.DOTS;
								}
								else {
									echo NAMECH;
								}
								echo '</label></td>
								<td>
								  <input type="text" autocomplete="off" class="inptxt" name="eleve" size="20"';
								if($onlycode_check_info['valeur']=='0') {
									echo 'id="eleves"';
								}
								else { echo 'id="code_input"'; }
								echo 'value="">
								</td>
							</tr>';
						$activ = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE activ_activ = 1");
						$nb_activ = mysqli_num_rows($activ);
						//choix de l'activité :
						if($nb_activ>0) {
							echo'<tr name="noprint"><td name="noprint">'.ACTIV.DOTS.'</td><td name="noprint" style="max-width:600px;">';
							$activd = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE activ_activ = 1");
							while($liste = mysqli_fetch_assoc($activd)) {
								if($liste['code_activ']=="ZERO") { }
								else {
									echo '<label class="nowarp" for="'.$liste['code_activ'].'">';
									echo '<input type="radio" onclick="toggleValid(\'valida\', \'validb\');" name="selectactiv" id="'.$liste['code_activ'].'" value="'.$liste['code_activ'].'" '; 
									if(isset($_SESSION['code_activ'])&&$verrtest['valeur']==0) {
										if($_SESSION['code_activ']==$liste['code_activ']) {
											echo 'checked';
										}
									}
									else {
										if (
										        isset($defaultActivites[$crenforactiv]) &&
										        $defaultActivites[$crenforactiv] == $liste['code_activ']
										    ) {
										        echo ' checked';
										    }
										else if($liste['default_activ']==1) { echo 'checked'; }
									}
									echo ' />';
									echo $liste['nom_activ'].'</label> ';
									if(@$_SESSION['align_activ']=='v') { echo '<br>'; }
								}
							}
							echo '</td></tr>';
						}
						//choix de l'espace :
						if($espopt['valeur']==1) {
							$espnb = mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_espaces WHERE auth_freq = 1"));
							if($espnb>0) {
								echo'<tr name="noprint"><td name="noprint">'.ZONE.DOTS.'</td><td name="noprint">';
								$espaces = mysqli_query($bdd,"SELECT * FROM ".$prefix."_espaces WHERE auth_freq = 1 ORDER BY espace_nom");
								$esp0 = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'espaces_first'"));
								echo '<input type="radio" name="selectespace" id="esp0" value="0" checked /><label for="esp0">'.$esp0['valeur'].'</label>';
								if(@$_SESSION['align_espace']=='v') { echo '<br>'; }
								foreach($espaces as $espace) {
									echo '<input type="radio" name="selectespace" id="esp'.$espace['espace_id'].'" value="'.$espace['espace_id'].'" '; 
									if(isset($_SESSION['espace_id'])&&$verresp['valeur']==0) {
										if($_SESSION['espace_id']==$espace['espace_id']) {
											echo 'checked';
										}
									}
									else {
										if(isset($_SESSION['espuser'])) {
											if($_SESSION['espuser']==$espace['espace_id']) { echo 'checked'; }
										}
										else if($espace['default_espace']==1) { echo 'checked'; }
									}
									echo ' /><label for="esp'.$espace['espace_id'].'">'.$espace['espace_nom'].'</label>';
									if(@$_SESSION['align_espace']=='v') { echo '<br>'; }
								}
								echo '</td></tr>';
							}
						}
						echo '</table></div>';
						// Recherche de séance EDT et proposition d'inscription dans la séance EDT :
						$colorsys = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_coloration'");
						$colorsys_info = mysqli_fetch_assoc($colorsys);
						$jouraff = date("Ymd");
						$ant = strtotime(date("H:i:s"))+(60* (int) $nb_anticip['valeur']);
						$heure_ant = date("His",$ant);
						if($antday==1) {
							$jouraff = Date('Ymd', strtotime(date('Ymd').' +1 Day'));
							$heure_ant = $hantday;
						}
						// Récupération des données BDD de event et briques :
						$tabevent_select = 
						"SELECT event.uid, event.dtstart, event.dtend, event.week, brik.brik_id, brik.code, brik.seq_id, brik.division, SUBSTR(brik.division,1,9), brik.textelibre, brik.close  
						FROM ".$prefix."_edtevent event
						INNER JOIN ".$prefix."_edtbrik brik
						ON event.brik_id = brik.brik_id
						WHERE event.dtstart <= '".$jouraff.'T'.$heure_ant."' AND event.dtend >= '".$jouraff.'T'.$heure_ant."'";
						$tabevent = mysqli_query($bdd,$tabevent_select);
						$tabevent_nb = mysqli_num_rows($tabevent);
						// Affichage de la cellule :
						if($tabevent_nb>=1) {
							while($tabevent_info = mysqli_fetch_assoc($tabevent)) {
								// texte libre :
								if($tabevent_info['textelibre']!=""&&$tabevent_info['close']=='1') {
									if($colorsys_info['valeur']=='niv') {
										$color = mysqli_query($bdd,"SELECT bgcolor FROM ".$prefix."_edtnivcolor WHERE niveau = 'r'");
										$color_info = mysqli_fetch_assoc($color);
										$bgcolor = $color_info['bgcolor'];
									}
									else if($colorsys_info['valeur']=='cod') {
										$bgcolor = '#fff';
									}
									if($bgcolor=='') { $bgcolor = "#ffffff"; }
									echo '<div class="cartouche" style="background-color:'.$bgcolor.';margin-top:10px;" name="'.$tabevent_info['brik_id'].'">';
									if(@strlen($tabevent_info['textelibre'])>20) { echo '<span class="txtlibre_2">'; }
									else { echo '<span class="txtlibre_1">'; }
									echo $tabevent_info['textelibre'].'</span></div>';
								}
								// classe :
								else if($tabevent_info['textelibre']=='') {
									$seq = mysqli_query($bdd,"SELECT seq_id, seq_nom, SUBSTR(seq_nom,1,13) FROM ".$prefix."_sequences WHERE seq_id ='".$tabevent_info['seq_id']."'");
									$seq_info = mysqli_fetch_assoc($seq);
									$seq_nomaff = mb_ereg_replace("[?]","",mb_convert_encoding($seq_info['SUBSTR(seq_nom,1,13)'],"utf-8"));
									$divaff = mb_ereg_replace("[?]","",mb_convert_encoding($tabevent_info['SUBSTR(brik.division,1,9)'],"utf-8"));
									if($colorsys_info['valeur']=='niv') {
										$colorniv = null;
										if($nivs_info['valeur']=="PER") { 
											foreach ($sorted_caracs as $prefixe => $niveau) {
											    // Si la division commence par ce préfixe, on a trouvé le niveau
											    if (strpos($tabevent_info['division'], $prefixe) === 0) {
											        $colorniv = $niveau;
											        break; // On arrête la boucle une fois le niveau trouvé
											    }
											}
											if($colorniv!==null&&@$colorniv!='r') {
												$color = mysqli_query($bdd,"SELECT bgcolor FROM ".$prefix."_edtnivcolor WHERE niveau = '".$colorniv."'");
												$color_info = mysqli_fetch_assoc($color);
												$bgcolor = $color_info['bgcolor'];
											}
										}
										else {
											$colorniv = substr($tabevent_info['division'],0,1);
											if($colorniv!='6'&&$colorniv!='5'&&$colorniv!='4'&&$colorniv!='3'&&$colorniv!='2'&&$colorniv!='1'&&$colorniv!='t'&&$colorniv!='T') { $colorniv = 'a'; }
											$color = mysqli_query($bdd,"SELECT bgcolor FROM ".$prefix."_edtnivcolor WHERE niveau = '".$colorniv."'");
											$color_info = mysqli_fetch_assoc($color);
											$bgcolor = $color_info['bgcolor'];
										}
									}
									else if($colorsys_info['valeur']=='cod') {
										$color = mysqli_query($bdd,"SELECT bgcolor_code FROM ".$prefix."_edtcode WHERE code = '".$tabevent_info['code']."'");
										$color_info = mysqli_fetch_assoc($color);
										$bgcolor = $color_info['bgcolor_code'];
									}
									if($bgcolor=='') { $bgcolor = "#ffffff"; }
									echo '<input type="radio" name="seance" class="seance" id="seq'.$tabevent_info['seq_id'].'" onclick="clearTimeout(timer);setTimeout(function() { window.location = window.location;
									}, 240000);" value="'.$tabevent_info['seq_id'].'" /><div class="cartouche" style="background-color:'.$bgcolor.';margin-top:10px;display:inline-block;" name="'.$tabevent_info['brik_id'].'">';
									echo '<label onclick="clearTimeout(timer);setTimeout(function() { window.location = window.location;
									}, 240000);" for ="seq'.$tabevent_info['seq_id'].'"><span';
									if($seq_nomaff=="") { echo ' class="txtlibre_1"'; }
									echo'>';
									if(@strlen($divaff)>5) {
										echo $divaff;
										if($tabevent_info['code']!="") {
											echo '<br>'.$tabevent_info['code'].'';
										}
									}
									else {
										echo $divaff;
										if($tabevent_info['code']!="") {
											echo ' - '.$tabevent_info['code'].'';
										}
										if($seq_nomaff!="") {
											echo '<br>'.$seq_nomaff.'';
											if($seq_nomaff!=$seq_info['seq_nom']) {
												echo '...';
											}
										}
									}
									echo '</span></label></div>';
								}
								echo '<br> <br><div id="annul" style="display:none;"><input type="radio" name="seance" id="seqnon" value="non" /><div class="cartouche" style="background-color:#eeeeee;display:inline-block;"><span style="padding-top:20px;"><label for ="seqnon">'.FREQC_IND10.'</label></span></div></div>';
							}
						}
						?><script>
						var seance = document.getElementsByClassName("seance");
						for(var i = 0; i < seance.length; i++) {
							seance[i].onchange = function() {
								var radios = this.form.elements["selectactiv"];
								// loop through list of radio buttons
								for (var i=0, len=radios.length; i<len; i++) {
									var r = radios[i]; // current radio button
									if ( r.value === "SEAN" ) { // standard shipping
										r.checked = true; // set checked
									} else { // not standard shipping
										r.checked = false; // unchecked
									}
								}
								document.getElementById("annul").style="display:inline-block";				
								<?php
								if($classe_info_valeur==1&&$seance_appel['valeur']==1) {
									echo "document.getElementById(\"divclasse\").style=\"display:block\";
									document.getElementById('classe').value = '".@$divaff."';
									go();";
								}
								?>					
							}
						}
						</script><?php
						// gestion des inscriptions sur plusieurs créneaux de suite
						$nb_cren = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_multiinscrit'"));
						if($nb_cren['valeur']!=$_SESSION['nbcren']&&$_SESSION['nbcren']!='def') {
							$nb_cren['valeur']=$_SESSION['nbcren'];
						}
						if($nb_cren['valeur']!=0) {							
							for($i=1;$i<=$nb_cren['valeur'];$i++) {
								if($freq_gestion_jourscren['valeur']==0) {
									$crensuiv[$i] = mysqli_fetch_array(mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE num_creneau = ".($creneau_info['num_creneau']+$i)." AND hor_freq LIKE '001%'"));
								}
								else {
									$crensuiv[$i] = mysqli_fetch_array(mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE num_creneau = ".($creneau_info['num_creneau']+$i)." AND hor_freq LIKE '%".date('D')."001%'"));
								}
								if(isset($crensuiv[$i]['num_creneau'])) {
									if($i==1) {
										echo '<p>'.FREQC_IND11.'</p>';
									}
									echo '<input type="checkbox" id="crensuivok'.$i.'" name="crensuivok'.$i.'" /><label for="crensuivok'.$i.'"> ';
									$hor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_horaires WHERE hor_name = '".$crensuiv[$i]['hor_name']."'");
									while($liste = mysqli_fetch_assoc($hor)) {
										$cren = $liste['hor_name'];
										$deb_cren = substr("$cren", 0, 1);
										echo $liste['hor_name'].' - ';
										echo MOMENT[$deb_cren];
										$deb = $liste['debut'];
										$dh = substr("$deb", 0, 2);
										$dm = substr("$deb", 3, 2);
										echo ' '.FROM.' '.$dh.'h'.$dm.' '.TO.' ';
										$fin = $liste['fin'];
										$fh = substr("$fin", 0, 2);
										$fm = substr("$fin", 3, 2);
										echo ''.$fh.'h'.$fm.'</label><br>';
									}
								}
							}
						}
						// fin du formulaire d'inscription :
						if($check_activ_obli['valeur']==1&&mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE default_activ = '1'"))==0) {
							echo '<div id="valida" style="display:block;">';
							echo '<p class="paddvalid1"><input class="bouton inptxtf boutfreq" type="submit" id="inssub" name="inscrire" value="'.FREQC_IND12.'" disabled />';
							echo '</p></div>';	
						}
						if($check_activ_obli['valeur']==1&&mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE default_activ = '1'"))==0) {
							echo '<div id="validb" style="display:none;">';
						}
						echo '<p class="paddvalid1"><input class="bouton inptxtf boutfreq" type="submit" id="inssub" name="inscrire" value="'.FREQ_BUTTON1.'" /></p>';
						if($check_activ_obli['valeur']==1&&mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE default_activ = '1'"))==0) {
							echo '</div>';
						}
						echo '</form>';

					}
				}
		
				// Gestion des réservations à confirmer
				include('./db/proc/freq_confirmreserv.php');
				if($soluce==1&&substr($crpre_info['valeur'],1,1)=='h') {		
					include('./db/proc/freq_creneauprec.php');
				}				
			}
			
			if($droits==3&&$soluce==0) {
				$crenforactiv = '';
				echo '<p>'.FREQ_NO1.'</p>';
			}
			
			if($soluce==1) {
				// Gestion de l'affichage des présents
				$dday = date("Y-m-d");
				if(isset($_SESSION['nextday'])) {
					$dday = $_SESSION['nextday'];
				}
				$ccren_day = $dday;
				$ccren_cren = $_SESSION['ccren'];
				// récupération de l'ordre d'affichage souhaité
				$ordreaff = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_ordreaff'");
				$ordreaff_info = mysqli_fetch_assoc($ordreaff);
				if($ordreaff_info['valeur']=="div") {
					$ordre = "ORDER BY eleves.division ASC, eleves.nom ASC, eleves.prenom ASC";
				}
				else if($ordreaff_info['valeur']=="nom") {
					$ordre = "ORDER BY eleves.nom ASC, eleves.prenom ASC";
				}
				else if($ordreaff_info['valeur']=="hor") {
					$ordre = "ORDER BY GREATEST (coalesce(freq.h_inscription2,0), coalesce(freq.h_inscription3,0), coalesce(freq.h_inscription,0)) DESC";
				}
				else if($ordreaff_info['valeur']=="act") {
					$ordre = "ORDER BY freq.code_activ ASC";
				}
				else if($ordreaff_info['valeur']=="esp") {
					$ordre = "ORDER BY espaces.espace_nom ASC, eleves.division ASC, eleves.nom ASC, eleves.prenom ASC";
				}
				$filtre_consult = "";
				if($droits==3) {
					$filtre_select = "SELECT code_activ FROM ".$prefix."_freqactiv WHERE consult_activ = 0";
					$filtre = mysqli_query($bdd,$filtre_select);
					$filtre_nb = mysqli_num_rows($filtre);
					if($filtre_nb!=0) {
						while($filtre_info = mysqli_fetch_assoc($filtre)) {
							$filtre_consult .= " WHERE freq.code_activ <> '".$filtre_info['code_activ']."'";
						}
					}
				}
				$_SESSION['filtre_consult'] = $filtre_consult;
				$_SESSION['ccren_day'] = $ccren_day;
				$_SESSION['ccren_cren'] = $ccren_cren;
				// affichage proprement dit
				$inscrits_select = "SELECT freq.freq_id, freq.eleves_id, freq.date_freq, freq.hor_name, freq.code_activ, freq.cas, freq.h_inscription, freq.h_inscription2, freq.h_inscription3, freq.h_sortie, freq.h_sortie_2, freq.h_sortie_3, freq.espace_id, espaces.espace_nom, eleves.nom, eleves.prenom, eleves.division, eleves.naissance 
				FROM (
				    SELECT * 
				    FROM ".$prefix."_freq 
				    WHERE date_freq = '".$ccren_day."' AND hor_name = '".$ccren_cren."' AND cas NOT IN ('sor', 'exc')
				) freq
				INNER JOIN ".$prefix."_eleves eleves
				ON freq.eleves_id = eleves.eleves_id
				LEFT JOIN ".$prefix."_espaces espaces
				ON espaces.espace_id = freq.espace_id
				".$filtre_consult."
				".$ordre."";
				$inscrits = mysqli_query($bdd,$inscrits_select);
				$nb_inscrits = mysqli_num_rows($inscrits);
				if($api_info['valeur']=='1') {
					writeInscriptionCount($nb_inscrits, $prefix);
				}
				
				//en tant que consult:
				if($droits==3) {
					$appelchoix = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_appel'");
					$appelchoix_info = mysqli_fetch_assoc($appelchoix);
					if(substr($appelchoix_info['valeur'],2,1)==1) {
						echo '<p name="noprint">'.FREQC_IND13.'</p>';
					}
					else {
						echo '<p class="signal" name="noprint"><b>'.FREQC_IND14.'</b></p>';
					}
				}
				//gestion pour les anniversaires
				$birthday = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_parametres WHERE param_nom = 'freq_birthday_img'"));
				//gestion de la visualisation des activités
				$check_consultactiv_opt = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_consultactiv'"));				
				echo '<div class="preinsp"><br><h3>'.FREQ_INF3.' (<span id="inscrits_nb">'.$nb_inscrits.'</span>) :</h3>';
				$mail_inscrits = '<style> table { border-collapse:collapse; } td { border:1px solid grey; padding: 5px; } </style>';
				$mail_inscrits .= '<h2>'.MAILLIST.' '.date("d/m/Y").' '.EN.' '.$creneau_info['hor_name'].' ('.@$crenpdf.')</h2>';
				$mail_inscrits .= '<h3>'.FREQ_INF3.' ('.$nb_inscrits.') :</h3>';
				if($nb_inscrits > 0) {
					if($espopt['valeur']==1) {
						$visesp = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_vision_espaces_ins'"));
						if($visesp['valeur']==1) {
							$day = date('Y-m-d');
							include('db/proc/freq_inscrits_esp_tableau.php');
						}
					}
					if($espopt['valeur']==0) {
						//gestion du seuil
						$crennum = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT quota_freq FROM ".$prefix."_horaires WHERE hor_name = '".$creneau_info['hor_name']."'"));
						if($freq_gestion_jourscren['valeur']==0) {
							$quota_freq = intval(substr($crennum['quota_freq'],0,3));
						}
						else {
							$quota_freq = intval(substr($crennum['quota_freq'], strpos($crennum['quota_freq'], date('D')) + strlen(date('D')), 3));
						}
						if($quota_freq==0) {
							$sin = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_seuilnbi'");
							$sin_info = mysqli_fetch_assoc($sin);
						}
						else {
							$sin_info['valeur'] = $quota_freq;
						}
						$_SESSION['quota_freq'] = $sin_info['valeur'];

						$sir = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_seuilreaci'");
						$sir_info = mysqli_fetch_assoc($sir);
						if($nb_inscrits>=$sin_info['valeur']&&$sir_info['valeur']=='alert') {
							if($sin_info['valeur']!=0) {
								echo '<p name="seuil"><b>'.FREQ_SEUIL4.'</b></p>';
								
							}
						}
						else if($nb_inscrits>=$sin_info['valeur']&&$sir_info['valeur']=='stopp') {
							if($sin_info['valeur']!=0) {
								echo '<p name="seuil"><b>'.FREQ_SEUIL5.'</b></p>';
							}
						}
					}
				}
				echo '<table id="listeinscrits">'; $mail_inscrits .= '<table>';
				if($nb_inscrits == 0) {
					echo '<p id="aucun">'.NONE.'.</p>';
				}				
				else {					
					$excluform=0;
					//inscrits									
					foreach($inscrits as $liste) {
						$activ = mysqli_query($bdd,"SELECT nom_activ FROM ".$prefix."_freqactiv WHERE code_activ = '".$liste['code_activ']."'");
						$activ_info = mysqli_fetch_assoc($activ);
						echo '<tr id="freq'.$liste['freq_id'].'">'; $mail_inscrits .= '<tr>';
						if($ordreaff_info['valeur']=="hor") {
							if(@strlen($liste['h_inscription3'])==15) { $hi = '3'; }
							else if(@strlen($liste['h_inscription2'])==15) { $hi = '2'; }
							else { $hi = ''; }
							echo '<td>'.substr($liste['h_inscription'.$hi],9,2).':'.substr($liste['h_inscription'.$hi],11,2).'</td>';
							$mail_inscrits .= '<td>'.substr($liste['h_inscription'.$hi],9,2).':'.substr($liste['h_inscription'.$hi],11,2).'</td>';
						}
						echo '<td>'.$liste['division'].' - '.$liste['nom'].' '.$liste['prenom'].'</td>';
						$mail_inscrits .= '<td>'.$liste['division'].' - '.$liste['nom'].' '.$liste['prenom'].'</td>';
						if($droits==3&&$check_consultactiv_opt['valeur']==0) { }
						else {
							if(@$activ_info['nom_activ']=="") {
								echo '<td></td>'; $mail_inscrits .= '<td></td>';
							}
							else {
								echo '<td>'.@$activ_info['nom_activ'].'</td>';
								$mail_inscrits .= '<td>'.@$activ_info['nom_activ'].'</td>';
							}
						}
						if($espopt['valeur']==1) {
							if($liste['espace_id']!=0) { 
								echo '<td>'.$liste['espace_nom'].'</td>'; 
								$mail_inscrits .= '<td>'.$liste['espace_nom'].'</td>';
							}
							else { 
								echo '<td>'.$esp0['valeur'].'</td>'; 
								$mail_inscrits .= '<td>'.$esp0['valeur'].'</td>'; 
							}
						}
						$buttonchoix = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_inscritbutton'"));
						if($droits==2||($droits==4&&($buttonchoix['valeur']==1||$_SESSION['buttonsor']!='0'||$_SESSION['buttonexc']!='0'||$_SESSION['retardsaff1']!='0'||$_SESSION['retardsaff2']!='0'))||($droits==6&&($buttonchoix['valeur']==1||$_SESSION['buttonsor']!='0'||$_SESSION['buttonexc']!='0'||$_SESSION['retardsaff1']!='0'||$_SESSION['retardsaff2']!='0'))) {
							if($_SESSION['buttonsor']!='0'||$_SESSION['buttonexc']!='0') {
								echo '<td name="noprint">';
							}
							if($_SESSION['buttonsor']!='0') {
								echo '<input class="boutontab" type="submit" onclick="sor'.$liste['freq_id'].'(this);" value="'.FREQJ_ORDER8.'" name="sor'.$liste['freq_id'].'" />';
							}
							if($_SESSION['buttonexc']!='0') {
								echo ' <input class="boutontab" type="submit" value="'.FREQJ_ORDER9.'"';
								if($excluopt_info['valeur']==0) {
									echo ' onclick="exc'.$liste['freq_id'].'(this);" ';
								}
								else if($excluopt_info['valeur']==1) {
									echo ' onmousedown="toggleDiv(\'excdiv'.$liste['freq_id'].'\');" ';
								}
								echo 'name="exc'.$liste['freq_id'].'" />';
								echo '<div id="excdiv'.$liste['freq_id'].'" class="parambrik" style="display:none;">';
								$eleve_id = $liste['eleves_id'];
								$causes_reg = mysqli_query($bdd,"SELECT * FROM ".$prefix."_exclucauses ORDER BY exclucause_txt ASC");
								echo '<p class="signal">'.FREQJ_ORDER9.' '.FROM.' '.$liste['prenom'].' '.$liste['nom'].' - '.$liste['division'].' :</p>';
								include('db/proc/freq_exclu_newform.php');
								echo '<input class="bouton boutfreq" type="submit" value="'.FREQC_IND15.'" onclick="details_exc'.$liste['freq_id'].'(this);" name="details_exc'.$liste['freq_id'].'" /></p>';
								echo '</div>';
							}
							if($_SESSION['buttonsor']!='0'||$_SESSION['buttonexc']!='0') {
								echo '<script type="text/javascript">
									function sor'.$liste['freq_id'].'(param) {
									var param = "sortie";
									document.getElementById("freq'.$liste['freq_id'].'").style.display = "none";
									var eleve_id = "'.$liste['eleves_id'].'"; 
									var freq_id = "'.$liste['freq_id'].'";
									var rnb = document.getElementById("inscrits_nb").textContent;
									var new_rnb = rnb-1;
									document.getElementById("inscrits_nb").textContent = new_rnb; ';
									if($espopt['valeur']==1&&@$nb_inscrits_esp>0) {
										echo 'var rne = document.getElementById("nb_tresp'.$liste['espace_id'].'").textContent;
										var new_rne = rne-1;
										if(new_rne===0) {
											document.getElementById("tresp'.$liste['espace_id'].'").style.display = "none";
										}
										else {
											document.getElementById("nb_tresp'.$liste['espace_id'].'").textContent = new_rne;
										}	';								
									}
						            echo '$.ajax({
									    type: "POST",
									    data: { param: param, eleve_id: eleve_id, freq_id: freq_id, new_rnb: new_rnb },
									    url: "js/idl/freq_ind_syn.php",
										    success: function(data){
										        $("#zone").html(data);
										        $("#eleves").focus();
										    }
									   });
									}
								</script>';
								echo '<script type="text/javascript">
									function exc'.$liste['freq_id'].'(param) {
									var param = "exclu";
									document.getElementById("freq'.$liste['freq_id'].'").style.display = "none";
									var eleve_id = "'.$liste['eleves_id'].'"; 
									var freq_id = "'.$liste['freq_id'].'";
									var rnb = document.getElementById("inscrits_nb").textContent;
									var new_rnb = rnb-1;
									document.getElementById("inscrits_nb").textContent = new_rnb; 
									';
									if($espopt['valeur']==1&&@$nb_inscrits_esp>0) {
										echo '
										var rne = document.getElementById("nb_tresp'.$liste['espace_id'].'").textContent;
										var new_rne = rne-1;
										if(new_rne===0) {
											document.getElementById("tresp'.$liste['espace_id'].'").style.display = "none";
										}
										else {
											document.getElementById("nb_tresp'.$liste['espace_id'].'").textContent = new_rne;
										}	';								
									}      
						            echo '$.ajax({
									    type: "POST",
									    data: { param: param, eleve_id: eleve_id, freq_id: freq_id },
									    url: "js/idl/freq_ind_syn.php",
									    success: function(data){
									        $("#zone").html(data);
									        $("#eleves").focus();
									    }
									   });
									}
								</script>';
								$activ = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE code_activ <> 'ZERO' ORDER BY nom_activ ASC");
								echo '<script type="text/javascript">
									function details_exc'.$liste['freq_id'].'(param) {
									var param = "detexclu";
									document.getElementById("freq'.$liste['freq_id'].'").style.display = "none";
									var eleve_id = "'.$liste['eleves_id'].'"; 
									var freq_id = "'.$liste['freq_id'].'"; 
									var cause = document.getElementById("cause'.$liste['freq_id'].'").value; 
									var infocauseslisting = document.getElementById("infocauseslisting'.$liste['freq_id'].'").value;
									var signal = document.getElementById("signal'.$liste['freq_id'].'").value;
									var duree = document.getElementById("duree'.$liste['freq_id'].'").value;
									var creaexclu = document.getElementById("creaexclu'.$liste['freq_id'].'").value; ';
									foreach($activ as $check_activ) {
										echo ' var c'.$check_activ['code_activ'].' = document.getElementById("v'.$liste['freq_id'].$check_activ['code_activ'].'").checked;
										if(c'.$check_activ['code_activ'].'===false) {
											var t'.$check_activ['code_activ'].' = "";
										}
										else {
											var t'.$check_activ['code_activ'].' = "'.$check_activ['code_activ'].'";
										}';
									}      
									echo 'var rnb = document.getElementById("inscrits_nb").textContent;
									var new_rnb = rnb-1;
									document.getElementById("inscrits_nb").textContent = new_rnb; ';
									if($espopt['valeur']==1&&@$nb_inscrits_esp>0) {
										echo 'var rne = document.getElementById("nb_tresp'.$liste['espace_id'].'").textContent;
										var new_rne = rne-1;
										if(new_rne===0) {
											document.getElementById("tresp'.$liste['espace_id'].'").style.display = "none";
										}
										else {
											document.getElementById("nb_tresp'.$liste['espace_id'].'").textContent = new_rne;
										}	';								
									}
						            echo '$.ajax({
									    type: "POST",
									    data: { param: param, eleve_id: eleve_id, freq_id: freq_id, cause: cause, infocauseslisting: infocauseslisting, signal: signal, duree: duree, creaexclu: creaexclu'; 
									    foreach($activ as $check_activ) { echo ', t'.$check_activ['code_activ'].':t'.$check_activ['code_activ'].' '; } 
									    echo '},
									    url: "js/idl/freq_ind_syn.php",
									    success: function(data){
									        $("#zone").html(data);
									        $("#eleves").focus();
									    }
									   });
									}
								</script>';
								echo '</td>';
							}
							if($droits==2||$buttonchoix['valeur']==1||$_SESSION['retardsaff1']!='0'||$_SESSION['retardsaff2']!='0') {
								echo '<td class="noborder" name="noprint">';
								if($_SESSION['retardsaff1']!='0'||$_SESSION['retardsaff2']!='0') {
									$resas = mysqli_query($bdd,"SELECT * FROM ".$prefix."_sigbresas WHERE eleves_id = '".$liste['eleves_id']."' AND date_statut <= '".date('Y-m-d')."' ORDER BY date_statut ASC");
									$resas_nb = mysqli_num_rows($resas);
									if($resas_nb!=0) {
										echo '<span style="font-size: 1.5em; color: #D90606;"><i class="fa-solid fa-book" title="';
										if($_SESSION['retardsaff2']=='1') {
											echo RESA3;
											if($resas_nb>1) { echo PLURIEL; }
											echo ' '.RESA8;
											if($resas_nb>1) { echo 's'; }
										}
										else {
											if($resas_nb>1) { $i=1; }
											while($resas_info = mysqli_fetch_assoc($resas)) {
												if($resas_nb>1) { echo ''.$i.'. '; }
												if($resas_info['titre']!="") {
													echo $resas_info['titre'].'. ';
												}
												if($resas_info['date_statut']!="0000-00-00") {
													$date = date('d/m/Y', strtotime(str_replace("/","-",$resas_info['date_statut'])));
													echo FROM3.' '.$date.'. ';
												}
												if($resas_nb>1) { echo ''; $i++; }
											}
										}
										echo '"></i></span>';
									}
									echo '</td><td class="noborder" name="noprint">';
									$retards = mysqli_query($bdd,"SELECT * FROM ".$prefix."_retards WHERE eleves_id = '".$liste['eleves_id']."' AND retour_date < '".date('Y-m-d')."' ORDER BY retour_date ASC");
									$retards_nb = mysqli_num_rows($retards);
									if($retards_nb!=0) {
										echo '<span style="font-size: 1.5em; color: #D90606;"><i class="fa-solid fa-stopwatch" title="';
										if($_SESSION['retardsaff2']=='1') {
											echo FREQC_IND16;
											if($resas_nb>1) { echo PLURIEL; }
											echo FREQC_IND17;
											if($resas_nb>1) { echo PLURIEL; }
										}
										else {
											if($retards_nb>1) { $i=1; }
											while($retards_info = mysqli_fetch_assoc($retards)) {
												if($retards_nb>1) { echo ''.$i.'. '; }
												if($retards_info['titre']!="") {
													echo $retards_info['titre'].'. ';
												}
												if($retards_info['retour_date']!="0000-00-00") {
													$date = date('d/m/Y', strtotime(str_replace("/","-",$retards_info['retour_date'])));
													echo FREQ_GEST1.' '.$date.'. ';
												}
												if($retards_info['niv_alerte']!=0) {
													echo FREQ_GEST2.' ';
													if($retards_info['niv_alerte']=="1") { echo FREQ_GEST3; }
													else if($retards_info['niv_alerte']=="2") { echo FREQ_GEST4; }
													else if($retards_info['niv_alerte']=="3") { echo FREQ_GEST5; }
													echo '. ';
												}
												if($retards_nb>1) { echo ''; $i++; }
											}
										}
										echo '"></i></span>';
									}
								}
								echo '</td>';
								if($droits==2||$buttonchoix['valeur']==1||$_SESSION['buttonexc']=='1') {
									echo '<td class="noborder" name="noprint">';
									$exclusion = mysqli_query($bdd,"SELECT * FROM ".$prefix."_exclusions exclusions LEFT JOIN ".$prefix."_exclucauses causes ON exclusions.exclucause_id = causes.exclucause_id WHERE eleves_id = '".$liste['eleves_id']."' AND (date_info >= '".date('Y-m-d')."' OR date_fin >= '".date('Y-m-d')."')");
									$exc_nb = mysqli_num_rows($exclusion);
									if($exc_nb!=0) {
										$exc_info = mysqli_fetch_assoc($exclusion);
										echo '<span style="font-size: 1.5em; color: #D90606;"><i class="fa-solid fa-ban" title="';
										echo FREQT2.' '.FROM.' '.substr($exc_info['date_exclusion'],8,2).'/'.substr($exc_info['date_exclusion'],5,2).'/'.substr($exc_info['date_exclusion'],0,4).' '.TO2.' '.substr($exc_info['date_fin'],8,2).'/'.substr($exc_info['date_fin'],5,2).'/'.substr($exc_info['date_fin'],0,4).'.';
										echo '"></i></span>';
									}
									echo '</td><td class="noborder" name="noprint">';
									$limits = mysqli_query($bdd,"SELECT * FROM ".$prefix."_limits limits LEFT JOIN ".$prefix."_limitstxt txt ON limits.limittxt_id = txt.limittxt_id WHERE eleves_id = '".$liste['eleves_id']."' AND date_fin >= '".date('Y-m-d')."'");
									$limits_nb = mysqli_num_rows($limits);
									if($limits_nb!=0) {
										echo '<td class="noborder" name="noprint"><span style="font-size: 1.5em; color: #D90606;"><i class="fa-solid fa-hand" title="';
										if($limits_nb>1) { $i=1; }
										foreach($limits as $limit_info) {
											if($limits_nb>1) { if($i>1) { echo ' '; } echo $i.'. '; }
											echo $limit_info['limits_txt'].' '.FROM3.' '.substr($limit_info['date_debut'],8,2).'/'.substr($limit_info['date_debut'],5,2).'/'.substr($limit_info['date_debut'],0,4).'';
											if($limit_info['date_fin']>=date('Y-m-d')) {
												echo ' '.TO3.' '.substr($limit_info['date_fin'],8,2).'/'.substr($limit_info['date_fin'],5,2).'/'.substr($limit_info['date_fin'],0,4).'.';
											}
											if($limits_nb>1) { echo ''; $i++; }
										}
										echo '"></i></span>';
									}
								}
							}
						}
						echo '</td><td class="noborder" name="noprint">';
						if($birthday['valeur']==1&&(substr($liste['naissance'],5,5)==date('m-d'))) {
							$naissance = $liste['naissance'];
							$annee = substr($naissance, 0, -6);
							$mois = substr($naissance, 5, -3);
							$jour = substr($naissance, -2);
							$date = $jour.'/'.$mois.'/'.$annee;							
							$age = Age($date);
							echo '<span style="font-size: 1.5em; color: #D90606;"><i class="fa-solid fa-cake-candles" title="'.$age.' ans"></i></span>';
						}
						echo '</td></tr>'; 						
						$mail_inscrits .= '</tr>';						
					}					
				}
				echo '</table></div>'; $mail_inscrits .= '</table>';
				$_SESSION['freq_liste'] = $mail_inscrits;
				if($nb_inscrits > 0) {
					//Impression :
					echo '<br> <br><form method="POST" action="" name="mailing">'.PDF_EXTRS.' 
					<div class="box"><select id="ordrfin" name="ordrefin"><option value="div"';
					if($ordreaff_info['valeur']=="div") { echo ' selected '; }
					echo '>'.ORDER4.'</option><option value="act"';
					if($ordreaff_info['valeur']=="act") { echo ' selected '; }
					echo '>'.ORDER5.'</option><option value="nom"';
					if($ordreaff_info['valeur']=="nom") { echo ' selected '; }
					echo '>'.ORDER6.'</option><option value="hor"';
					if($ordreaff_info['valeur']=="hor") { echo ' selected '; }
					echo '>'.ORDER9.'</option>';
					if($espopt['valeur']==1) { 
						echo '<option value="esp"';
						if($ordreaff_info['valeur']=="esp") { echo ' selected '; }
						echo '>'.ORDER8.'</option>';
					}
					echo '</select></div><br>';
					echo '&nbsp; &nbsp; <a onclick="submitpdf();" id="preview-pdf"><img src="img/pdf-icon.png" title="'.PDF_EXTRACT.'"/></a>';
					// Envoi par mail
					if(@$_SESSION['auth_mail']==1) {
						if(isset($_POST['mail_send'])) {
							include('./db/proc/freq_extract_order.php');
							include('./db/proc/mailing/mailing_inscrits.php');
						}
						echo '&nbsp; &nbsp; <a href="javascript:;clearTimeout(timer);" id="mail" onmousedown="toggleDiv(\'divmail\');" onclick = "setTimeout(function() { window.location = window.location;
								}, 240000);"><img src="img/div/mail.png" title="'.FREQ_SEND1.'" name="noprint" class="printer" /></a>';
						echo '<div name="noprint" id="divmail" style="display:none;">
						<p>'.FREQ_SEND2.'</p>
						';
						$mails = mysqli_query($bdd,"SELECT * FROM ".$prefix."_user WHERE mail <> ''");
						if(mysqli_num_rows($mails)>0) {
							while($mail=mysqli_fetch_array($mails)) {
								echo '<input type="checkbox" name="mail[]" id="'.$mail['mail'].'" value="'.$mail['mail'].'" checked /><label for="'.$mail['mail'].'"> '.$mail['login'].' : '.$mail['mail'].'</label><br>';
							}
						}
						echo MAILOTH.' (1)'.DOTS.' <input type="email" name="mail1" /><br>
						'.MAILOTH.' (2)'.DOTS.' <input type="email" name="mail2" /><br>
						<input type="hidden" name="ordredeb" value="'.$ordreaff_info['valeur'].'" />
						<input class="bouton boutfreq paddvalid1" type="submit" name="mail_send" value="'.SEND.'" />';
						echo '</div>';
					}
					echo '</form>';
					if(isset($_POST['havepdf'])) {
						include('./include/pdf_loaders/freq_liste.php');
					}
				    echo '<form id="loadpdf" action="./include/pdf_loaders/freq_liste.php" method="post"><input type="hidden" name="havepdf" value="1" /><input type="hidden" name="ordredeb" value="'.$ordreaff_info['valeur'].'" /><input type="hidden" id="ordrefin" name="ordrefin" value="1" /></form>';

				    echo '<script type="text/javascript">
				    function submitpdf(){
				    	document.getElementById("ordrefin").value = document.getElementById("ordrfin").value;
				    	$("#loadpdf").submit()
				    }
				    </script></p>';
				}
				// Gestion du signalement de l'appel
				$appelchoix = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_appel'");
				$appelchoix_info = mysqli_fetch_assoc($appelchoix);
				if (substr($appelchoix_info['valeur'],0,1)==2) {
					//en tant qu'admin:
					if($droits==2||$droits==4||$droits==6) {
						//formulaire:
						echo '<br><span id="appeldist">';
						if(substr($appelchoix_info['valeur'],2,1)==1) {
							echo '<input type="submit" onclick="appeld(\'appelok\');" id="appelok" name="appelok" value="" title="'.FREQC_IND18.'" />'; 
						}
						else {
							echo '<input type="submit" onclick="appeld(\'appelback\');" id="appelback" name="appelback" value="" title="'.FREQC_IND19.'" />';
						}
						echo '</span>';
						echo '<script type="text/javascript">
						function appeld(aptype) {
							var param = "appelgo";
							if(aptype=="appelok") {
								var val = "2:2:'.$_SESSION['ccren'].'";
								document.getElementById("appeldist").innerHTML = "<input type=\"submit\" onclick=\"appeld(\'appelback\');\" id=\"appelback\" name=\"appelback\" value=\"\" title=\"'.FREQC_IND19.'\" />";
							}
							else if(aptype=="appelback") {
								var val = "2:1:'.$_SESSION['ccren'].'";
								document.getElementById("appeldist").innerHTML = "<input type=\"submit\" onclick=\"appeld(\'appelok\');\" id=\"appelok\" name=\"appelok\" value=\"\" title=\"'.FREQC_IND18.'\" />";
							}
							$.ajax({
							    type: "POST",
							    data: { param: param, val: val },
							    url: "js/idl/freq_ind_syn.php",
							    success: function(data){
							        $("#zone").html(data);
							        $("#eleves").focus(); 
							    }
							});
						}
						</script>';
					}
				}
				if(@$_SESSION['freqinscritsafter']!='0') {
					include('./db/proc/freq_inscrits_after.php');
				}
			}
			if($soluce==1&&substr($crpre_info['valeur'],1,1)=='b') {		
				// Gestion des inscrits du créneau précédent
				include('./db/proc/freq_creneauprec.php');
			}
			if($_SESSION['timestop']==0) {
				?><script type="text/javascript">
				var timer = setTimeout(function() {
				  window.location = window.location;
				}, 60000);
				</script><?php
			}
			if($onlycode_check_info['valeur']=='0') {
			?><script type="text/javascript">
				document.getElementById('eleves').focus();
			</script><?php
			}
			else {
				?><script type="text/javascript">
					document.getElementById('code_input').focus();
				</script><?php
			}
		}
	}
}
	
else {
	include('include/noaccess.php');
	echo '<br><a href="./index.php">'.ACCUEIL.'</a></p>';
}
?>
