<?php
echo '<meta charset="utf-8" />';
if(isset($_SESSION['user_droits'])) {
	$droits = substr($_SESSION['user_droits'],3,1);
	$excluopt_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt'"));
	
	if (($droits!=2&&$droits!=5&&$droits!=6&&$excluopt_info['valeur']!=1))
	{
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="./index.php">'.ACCUEIL.'</a></p>';
	}
	else {
		?><style type="text/css">
		#mfr4 { background-color: #fff; }
		#mfr4 td { border: 3px #B90404 solid; }
		#mfr3 td { border:0; }
		</style><?php
		echo '<h1>'.FREQNAV4.'</h1>';

		//vérification et cas échéant suppression des exclusions et limitations sur n-1 et n-6 :
		$academie = mysqli_query($bdd,"SELECT * FROM ".$prefix."_etab WHERE academie <> '' OR pays <> ''");
		$etab_nb = mysqli_num_rows($academie);
		if($etab_nb!=0) {
			$acad_info = mysqli_fetch_assoc($academie);
			if($acad_info['pays']=='fra') { $acadexist = $acad_info['academie']; }
			else { $acadexist = $acad_info['pays']; }
		}
		else { $acadexist = ""; }
		include('./db/proc/caloffsco.php');
		$year6 = date("Y")-5;
		if(isset($_POST['nonnom'])) {
			if(isset($_POST['input_save'])) {
				$_SESSION['save_auto'] = '2';
				include('./db/backup.php');
			}
			if($acadexist=="fnc"||$acadexist=="civ") {
				mysqli_query($bdd,"DELETE FROM ".$prefix."_exclusions WHERE date_exclusion < '".$year6."-01-01'");
				mysqli_query($bdd,"DELETE FROM ".$prefix."_limits WHERE date_debut < '".$year6."-01-01'");
			}
			else {
				mysqli_query($bdd,"DELETE FROM ".$prefix."_exclusions WHERE date_exclusion < '".($year6-1)."-08-15'");
				mysqli_query($bdd,"DELETE FROM ".$prefix."_limits WHERE date_debut < '".($year6-1)."-08-15'");
			}
			echo '<p>'.FREQC_EXC1.'</p>';
		}
		if($acadexist=="fnc"||$acadexist=="civ") {
			$freq6_clean = mysqli_query($bdd,"SELECT * FROM ".$prefix."_exclusions WHERE date_exclusion < '".$year6."-01-01'");
			$freq6l_clean = mysqli_query($bdd,"SELECT * FROM ".$prefix."_limits WHERE date_debut < '".$year6."-01-01'");
		}
		else {
			$freq6_clean = mysqli_query($bdd,"SELECT * FROM ".$prefix."_exclusions WHERE date_exclusion < '".($year6-1)."-08-15'");
			$freq6l_clean = mysqli_query($bdd,"SELECT * FROM ".$prefix."_limits WHERE date_debut < '".($year6-1)."-08-15'");
		}
		if((mysqli_num_rows($freq6_clean)>0||mysqli_num_rows($freq6l_clean)>0)&&date('Y-m-d')>(substr($rentree,0,4).'-'.substr($rentree,5,2).'-'.substr($rentree,8,2))) {
			echo '<p class="signal maxwidth">'.EDTC_ELEV2.substr($rentree,8,2).'/'.substr($rentree,5,2).'/'.substr($rentree,0,4).EDTC_ELEV7.'</p><form action="" method="POST" name="nonnom"><input type="checkbox" name="input_save" id="input_save" /><label for="input_save"> '.DATAC_VIDE5.'</label><br><span class="ecart"><input type="submit" class="bouton boutfreq" value="'.CONFIRM.'" name="nonnom" /></span>';
			$result_tables = mysqli_query($bdd,"SHOW TABLE STATUS LIKE '".$prefix."_%'");
			$_SESSION['nb_tables'] = mysqli_num_rows($result_tables);
			if($result_tables && $result_tables->num_rows) {
				while($obj_table = mysqli_fetch_assoc($result_tables)) {
					echo '<input type="hidden" id="'.$obj_table['Name'].'" name="'.$obj_table['Name'].'" checked />';
				}
			}
			echo '<input type="hidden" name="hidden_save" id="input_save" checked />';
			echo '</form>';
		}

		$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 { $ordre = ""; }

		if(isset($_POST['excluopts_valid'])) {
			if(isset($_POST['excluoptraisons'])) { $freq_excluopt_raisons = 1; } else { $freq_excluopt_raisons=0;}
			mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '".$freq_excluopt_raisons."' WHERE param_nom = 'freq_excluopt_raisons'");
			if(isset($_POST['excluoptsignal'])) { $excluoptsignal = 1; } else { $excluoptsignal=0;}
			mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '".$excluoptsignal."' WHERE param_nom = 'freq_excluopt_signal'");
			if($_POST['excluoptsignalduree']!='0') {
				mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '".$_POST['excluoptsignalduree']."' WHERE param_nom = 'freq_excluopt_signalduree'");
			}
			if(isset($_POST['excluoptduree'])) { $excluoptduree = 1; } else { $excluoptduree=0;}
			mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '".$excluoptduree."' WHERE param_nom = 'freq_excluopt_exc'");
			if($_POST['excluoptexcduree']!='0') {
				mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '".$_POST['excluoptexcduree']."' WHERE param_nom = 'freq_excluopt_excduree'");
			}
			if(isset($_POST['excluoptlimit'])) { $excluoptlimit = 1; } else { $excluoptlimit=0;}
			mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '".$excluoptlimit."' WHERE param_nom = 'freq_excluopt_limit'");
			if($_POST['excluoptlimitduree']!='0') {
				mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '".$_POST['excluoptlimitduree']."' WHERE param_nom = 'freq_excluopt_limitduree'");
			}
			$activ = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv");
			$tableau = array();
			$string_activs = "";
			foreach($activ as $active_info) {
				$tableau[] = $active_info['code_activ'];
			}
			foreach($tableau as $activ_item) {
				$array = array_keys($_POST);
				foreach($array as $checked_item) {
					if($checked_item==$activ_item&&strlen($activ_item)==4) {
						$string_activs .= $activ_item.'-';
					}
				}
			}
			mysqli_query($bdd,"UPDATE ".$prefix."_parametres SET valeur = '".$string_activs."' WHERE param_nom = 'freq_excluopt_activs'");
		}

		$freq_excluopt_raisons = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt_raisons'"));
		$freq_excluopt_signal = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt_signal'"));
		$freq_excluopt_signalduree = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt_signalduree'"));
		$freq_excluopt_exc = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt_exc'"));
		$freq_excluopt_excduree = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt_excduree'"));
		$freq_excluopt_limit = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt_limit'"));
		$freq_excluopt_limitduree = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt_limitduree'"));
		// exclusions
		if(isset($_POST['newexclus'])) {
			include('db/proc/eleve_select.php');
			$yetexcluded=0;
			include('db/proc/freq_exclu_newconfirm.php');
		}
		if($freq_excluopt_raisons['valeur']=='1'||$freq_excluopt_signal['valeur']=='1'||$freq_excluopt_exc['valeur']=='1') {
			echo '<h2 id="excludiv">'.FDIR_STATS_TIT28.'</h2>';
			// création d'une exclusion :
			$excluform=1;
			echo '<form method="POST" action="freq.php?page=exclusions#excludiv" name="newexclus">
			<table class="noborder"><tr><td><p><b>'.FREQC_EXC2.'</b></p>
			<p><label for="eleves">'.NAMECH.'</label>
			<input type="text" autocomplete="off" aria-autocomplete="none" class="inptxt" name="eleve" size="20" id="eleves" value=""></p>';
			include('db/proc/freq_exclu_newform.php');
			echo '</td></tr><tr><td style="text-align:right;">
				<input class="bouton boutfreq" type="submit" value="'.ADD.'" name="newexclus" />
			</td></tr></table>
			</form>';

			// si exclusions enregistrées :
			$dday = date('Y-m-d');
			$excluslist = mysqli_query($bdd,"SELECT * FROM ".$prefix."_exclusions exclusions INNER JOIN ".$prefix."_eleves eleves ON exclusions.eleves_id = eleves.eleves_id LEFT JOIN ".$prefix."_exclucauses causes ON exclusions.exclucause_id = causes.exclucause_id WHERE date_info > '".$dday."' OR date_fin >= '".$dday."' ".$ordre."");
			if(mysqli_num_rows($excluslist)>0) {
				foreach($excluslist as $exclu) {
					echo '<table class="tabexclu" id="tabe'.$exclu['exclusion_id'].'"><tr><td colspan="2"><b>'.$exclu['nom'].' '.$exclu['prenom'].' ('.$exclu['division'].')</b> - '.FREQC_EXC3.' '.substr($exclu['date_exclusion'],8,2).'/'.substr($exclu['date_exclusion'],5,2).'/'.substr($exclu['date_exclusion'],0,4).'</td>';
					if($freq_excluopt_raisons['valeur']==1) {
						echo '<tr><td colspan="2">'.FREQ_EXC21.' <div class="box"><select id="excraison'.$exclu['exclusion_id'].'" name="excraison">';
						foreach($causes_reg as $causes_liste) {
					 		echo '<option value="'.$causes_liste['exclucause_id'].'"';
					 		if($exclu['exclucause_id']==$causes_liste['exclucause_id']) {
					 			echo ' selected ';
					 		}
					 		echo '>'.$causes_liste['exclucause_txt'].'</option>';
					 	}
					 	echo '</select></div>';
					}
					if($freq_excluopt_signal['valeur']==1) {
						echo '<tr><td colspan="2">'.FREQ_EXC5.' '.TO3.' <input type="date" class="inptxt" id="date_info'.$exclu['exclusion_id'].'" name="date_info" value="'.$exclu['date_info'].'" /></td></tr>';
					}
					if($freq_excluopt_exc['valeur']==1) {
						echo '<tr><td colspan="2">'.FREQ_EXC6.' '.TO3.' <input type="date" class="inptxt" id="date_fin'.$exclu['exclusion_id'].'" name="date_fin" value="'.$exclu['date_fin'].'" /></td></tr>';
					}
					echo '<tr><td colspan="3">'.FREQ_EXC71.' ';
					$activ = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE code_activ <> 'ZERO' ORDER BY nom_activ ASC");
					$nb_activ = mysqli_num_rows($activ);
					if($nb_activ==0) {
						echo NOACTIV.'.</p>';
					}
					else {
						foreach($activ as $check_activ) {
							if($check_activ['activ_activ'] == "1") { $check = "checked"; } else { $check = "0"; }
							echo '<input type="checkbox" name="'.$check_activ['code_activ'].'" id="e'.$exclu['exclusion_id'].$check_activ['code_activ'].'" ';
							if($exclu['excluactivs']=='TOUTES'||(preg_match('/'.$check_activ['code_activ'].'/', $exclu['excluactivs']))) { echo 'checked'; }
							echo ' /> <label for="e'.$exclu['exclusion_id'].$check_activ['code_activ'].'">'.$check_activ['nom_activ'].'</label>';							
						}
					}
					echo '</td></tr>';
					echo '<tr><td style="text-align:center;"><input class="boutontab" type="submit" name="exclumodif'.$exclu['exclusion_id'].'" onclick="exclumodif'.$exclu['exclusion_id'].'(\''.$exclu['exclusion_id'].'\');colorval(\'exmod'.$exclu['exclusion_id'].'\');" id="exmod'.$exclu['exclusion_id'].'" value="'.MODIFY.'" /></td><td style="text-align:center;"><input class="boutontab" type="submit" onclick="exclusuppr'.$exclu['exclusion_id'].'(\''.$exclu['exclusion_id'].'\',\'tabe'.$exclu['exclusion_id'].'\');" id="exsup'.$exclu['exclusion_id'].'" name="exclusuppr'.$exclu['exclusion_id'].'" value="'.SUPPR.'" /></td></tr>';
					echo '</table>';
					echo '<script type="text/javascript">
					function exclumodif'.$exclu['exclusion_id'].'(exclu_id) {
						var param = "exclumod";';
						if($freq_excluopt_raisons['valeur']=='0') { echo 'var excraison = "0"; '; }
						else { echo 'var excraison = document.getElementById("excraison'.$exclu['exclusion_id'].'").value; '; }
						if($freq_excluopt_signal['valeur']=='0') { echo 'var date_info = "0000-00-00"; '; }
						else { echo 'var date_info = document.getElementById("date_info'.$exclu['exclusion_id'].'").value; '; }
						if($freq_excluopt_exc['valeur']=='0') { echo 'var date_fin = "0000-00-00"; '; }
						else { echo 'var date_fin = document.getElementById("date_fin'.$exclu['exclusion_id'].'").value; '; }
						echo 'var exclu_id = '.$exclu['exclusion_id'].';';
						foreach($activ as $check_activ) {
							echo 'var checked = document.getElementById("e'.$exclu['exclusion_id'].$check_activ['code_activ'].'").checked;
							if(checked===false) {
								var '.$check_activ['code_activ'].' = "0";
							}
							else {
								var '.$check_activ['code_activ'].' = "1";
							} ';
						}
						echo '$.ajax({
						    type: "POST",
						    data: { param: param, exclu_id: exclu_id, excraison: excraison, date_info: date_info, date_fin: date_fin';
						    foreach($activ as $check_activ) {
						    	echo ', '.$check_activ['code_activ'].': '.$check_activ['code_activ'].'';
						    }
						    echo ' },
						    url: "js/idl/freq_exclu_syn.php",
						   });
						}						
					</script>';
					echo '<script type="text/javascript">
					function exclusuppr'.$exclu['exclusion_id'].'(exclu_id, divs) {
						var param = "exclusup";
						document.getElementById(divs).style.display = "none";
						var exclu_id = '.$exclu['exclusion_id'].';
						$.ajax({
						    type: "POST",
						    data: { param: param, exclu_id: exclu_id },
						    url: "js/idl/freq_exclu_syn.php",
						   });
						}						
					</script>';								
				}
			}
		}
		// limitations
		if($freq_excluopt_limit['valeur']=='1') {
			echo '<h2 id="limitdiv">Limitations</h2>';
			$espopt = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'espaces_gestion'"));
			if(isset($_POST['newlimits'])) {
				include('db/proc/eleve_select.php');
				$dday=date('Y-m-d');
				if($_POST['limit']!=""&&$_POST['limitslisting']=="0") {
					$txt = mysqli_real_escape_string($bdd,$_POST['limit']);
					if($espopt['valeur']==1) { $espchoix = $_POST['esplist']; }
					else { $espchoix = 0; }
					if(mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_limitstxt WHERE limits_txt = '".$txt."' AND espace_id = '".$espchoix."'"))==0) {						
						mysqli_query($bdd,"INSERT ".$prefix."_limitstxt (limittxt_id, limits_txt, espace_id) VALUES ('', '".$txt."', '".$espchoix."')");
					}
					$limit_id_check = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT limittxt_id FROM ".$prefix."_limitstxt WHERE limits_txt = '".$txt."'"));
					$limit_id = $limit_id_check['limittxt_id'];
				}
				else if($_POST['limitslisting']!="0") {
					$limit_id = $_POST['limitslisting'];
				}
				if($_POST['limit']!=""||$_POST['limitslisting']!="0") {
					$date_fin = $_POST['dureelimit'];
					mysqli_query($bdd,"INSERT ".$prefix."_limits (limit_id, eleves_id, limittxt_id, date_debut, date_fin) VALUES ('', '".$eleve_id."', '".$limit_id."', '".$_POST['crealimit']."', '".$date_fin."')");
				}
				else {
					echo '<p name="seuil" class="signal"><b>'.FREQC_EXC4.'</b></p>';
				}
			}
			// création d'une limitation :
			echo '<form method="POST" action="freq.php?page=exclusions#limitdiv" name="newlimits">
			<table class="noborder"><tr><td><p><b>'.FREQC_EXC5.'</b></p>
			<p><label for="elevesbis">'.NAMECH.'</label>
			<input type="text" autocomplete="off" aria-autocomplete="none" class="inptxt" name="eleve" size="20" id="elevesbis" value=""></p>';
			$limits_reg = mysqli_query($bdd,"SELECT * FROM ".$prefix."_limitstxt GROUP BY limits_txt ORDER BY limits_txt ASC");
			if(mysqli_num_rows($limits_reg)>0) {
			 	echo '<br>&nbsp; '.FREQC_EXC6.' <div class="box"><select name="limitslisting" value="0"><option value="0"></option>';
			 	foreach($limits_reg as $limits_liste) {
			 		echo '<option value="'.$limits_liste['limittxt_id'].'">'.$limits_liste['limits_txt'].'</option>';
			 	}
			 	echo '</select></div>';
			} else { echo '<input type="hidden" value="0" name="limitslisting" />'; }
			echo '<br><br>'.FREQ_EXC11.' <input type="text" class="inptxt" name="limit" placeholder="';
			if(mysqli_num_rows($limits_reg)>0) {
				echo FREQ_EXC1;
			}
			echo '" />';
			if($espopt['valeur']==1) {
				$espaces = mysqli_query($bdd,"SELECT * FROM ".$prefix."_espaces");
				echo '<br><br>'.FREQC_EXC7.' <div class="box"><select name="esplist" value="0"><option></option>';
				foreach($espaces as $espace) {
					echo '<option value="'.$espace['espace_id'].'">'.$espace['espace_nom'].'</option>';
				}
				echo '</select></div>';
			}
			if($freq_excluopt_limitduree['valeur']=='0') { $date='0000-00-00'; }
			else {
				$calendar = mysqli_query($bdd,"SELECT * FROM ".$prefix."_calendrier WHERE date > '".date('Y-m-d')."' AND statut = 1");
				$i=0;
				foreach($calendar as $datecheck) {
					if($i==$freq_excluopt_limitduree['valeur']+1) { break; }
					$date = $datecheck['date'];
					$i++;
				}
			}
			echo '<p>'.FREQ_LIM1.' <input type="date" class="inptxt" name="crealimit" value="'.date('Y-m-d').'" /></p>';
			echo '<p>'.FREQ_LIM2.' '.TO3.' <input type="date" class="inptxt" name="dureelimit" value="'.$date.'" /></p>';
			echo '</td></tr><tr><td style="text-align:right;"><input class="bouton boutfreq" type="submit" value="'.ADD.'" name="newlimits" /></td></tr></table>
			</form>';

			// si limitations enregistrées :
			$dday = date('Y-m-d');
			$limitslist = mysqli_query($bdd,"SELECT * FROM ".$prefix."_limits limits INNER JOIN ".$prefix."_eleves eleves ON limits.eleves_id = eleves.eleves_id LEFT JOIN ".$prefix."_limitstxt limitstxt ON limits.limittxt_id = limitstxt.limittxt_id WHERE date_fin >= '".$dday."' ".$ordre."");
			if(mysqli_num_rows($limitslist)>0) {
				foreach($limitslist as $limits) {
					echo '<table id="tabl'.$limits['limit_id'].'" class="tabexclu"><tr><td colspan="2"><b>'.$limits['nom'].' '.$limits['prenom'].' ('.$limits['division'].')</b> - '.FREQC_EXC8.' '.substr($limits['date_debut'],8,2).'/'.substr($limits['date_debut'],5,2).'/'.substr($limits['date_debut'],0,4).'</td>';
					echo '<tr><td colspan="2">'.FREQ_LIMIT1.DOTS.' <div class="box"><select id="limitraison'.$limits['limit_id'].'" name="limitraison">';
					foreach($limits_reg as $limits_liste) {
				 		echo '<option value="'.$limits_liste['limits_txt'].'"';
				 		if($limits['limittxt_id']==$limits_liste['limittxt_id']) {
				 			echo ' selected ';
				 		}
				 		echo '>'.$limits_liste['limits_txt'].'</option>';
				 	}
				 	echo '</select></div>';
				 	if($espopt['valeur']=='1') {
				 		echo '<tr><td colspan="2">'.FREQC_EXC9.' <div class="box"><select id="limitlieu'.$limits['limit_id'].'" name="limitlieu">';
						echo '<option value="0"';
						if($limits['espace_id']=='0') { echo ' selected ';}
						echo '>'.NONE.'</option>';
						foreach($espaces as $espace) {
							echo '<option value="'.$espace['espace_id'].'"';
							if($limits['espace_id']==$espace['espace_id']) {
					 			echo ' selected ';
					 		}
					 		echo '>'.$espace['espace_nom'].'</option>';
						}	
					 	echo '</select></div></td></tr>';
				 	}
				 	else { echo '<input type="hidden" name="limitlieu" id="limitlieu'.$limits['limit_id'].'" value="0" />'; }
					echo '<tr><td colspan="2">'.FREQ_LIM2.' '.TO3.' <input type="date" class="inptxt" name="date_fin" id="ldate_fin'.$limits['limit_id'].'" value="'.$limits['date_fin'].'" /></td></tr>';
					echo '<tr><td style="text-align:center;"><input class="boutontab" type="submit" name="limitmodif'.$limits['limit_id'].'" onclick="limitmodif'.$limits['limit_id'].'(\''.$limits['limit_id'].'\');colorval(\'limod'.$limits['limit_id'].'\');" id="limod'.$limits['limit_id'].'" value="'.MODIFY.'" /></td><td style="text-align:center;"><input class="boutontab" type="submit" onclick="limitsuppr'.$limits['limit_id'].'(\''.$limits['limit_id'].'\',\'tabl'.$limits['limit_id'].'\');" id="lisup'.$limits['limit_id'].'" name="limitsuppr'.$limits['limit_id'].'" value="'.SUPPR.'" /></td></tr>';
					echo '</table>';
					echo '<script type="text/javascript">
					function limitmodif'.$limits['limit_id'].'(limit_id) {
						var param = "limitmod";
						var limit_id = '.$limits['limit_id'].';
						var limraison = document.getElementById("limitraison'.$limits['limit_id'].'").value;
						var limlieu = document.getElementById("limitlieu'.$limits['limit_id'].'").value;
						var date_fin = document.getElementById("ldate_fin'.$limits['limit_id'].'").value;
						$.ajax({
						    type: "POST",
						    data: { param: param, limit_id: limit_id, limraison: limraison, limlieu: limlieu, date_fin: date_fin },
						    url: "js/idl/freq_exclu_syn.php",
						   });
						}						
					</script>';
					echo '<script type="text/javascript">
					function limitsuppr'.$limits['limit_id'].'(exclu_id, divs) {
						var param = "limitsup";
						document.getElementById(divs).style.display = "none";
						var limit_id = '.$limits['limit_id'].';
						$.ajax({
						    type: "POST",
						    data: { param: param, limit_id: limit_id },
						    url: "js/idl/freq_exclu_syn.php",
						   });
						}						
					</script>';			
				}
			}
		}
		echo '<h2 id="suspension">'.FREQC_PARAM50.'</h2>';
		include('db/proc/freqres_suspensions.php');	
		// options
		echo '<h2>'.OPTIONS.'</h2>';
		echo '<form method="POST" name="excluoptions" action="" class="padd3">';
		echo '<table class="noborder"><tr><td><p><input type="checkbox" id="excluoptraisons" name="excluoptraisons"';
		if ($freq_excluopt_raisons['valeur']=='1') { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="excluoptraisons"> '.FREQC_EXC10.'</label></p>';
		echo '<p><input type="checkbox" id="excluoptsignal" name="excluoptsignal"';
		if ($freq_excluopt_signal['valeur']=='1') { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="excluoptsignal"> '.FREQC_EXC11.'</label><br>';
		echo '&bull; '.FREQC_EXC12.' <input type="number" min="0" max="300" class="number" id="excluoptsignalduree" name="excluoptsignalduree"';
		echo ' value="'.$freq_excluopt_signalduree['valeur'].'"/></p>';
		echo '<p><input type="checkbox" id="excluoptduree" name="excluoptduree"';
		if ($freq_excluopt_exc['valeur']=='1') { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="excluoptduree"> '.FREQC_EXC13.'</label><br>';
		echo '&bull; '.FREQC_EXC14.' <input type="number" min="0" max="300" class="number" id="excluoptexcduree" name="excluoptexcduree"';
		echo ' value="'.$freq_excluopt_excduree['valeur'].'"/></p>';

		$activ = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv WHERE code_activ <> 'ZERO' ORDER BY nom_activ ASC");
		$nb_activ = mysqli_num_rows($activ);
		echo '<p>'.FREQC_EXC15.' ';
		if($nb_activ==0) {
			echo NOACTIV.'.</p>';
		}
		else {
			echo '<br>';
			$activdef = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_parametres WHERE param_nom = 'freq_excluopt_activs'"));
			foreach($activ as $check_activ) {
				if($check_activ['activ_activ'] == "1") { $check = "checked"; } else { $check = "0"; }
				echo '<input type="checkbox" name="'.$check_activ['code_activ'].'" id="opt'.$check_activ['code_activ'].'" ';
				if($activdef['valeur']=='TOUTES'||(preg_match('/'.$check_activ['code_activ'].'/', $activdef['valeur']))) { echo 'checked'; }
				echo ' /> <label for="opt'.$check_activ['code_activ'].'">'.$check_activ['nom_activ'].'</label>';
			}
			echo '</p>';
		}

		echo '<p><input type="checkbox" id="excluoptlimit" name="excluoptlimit"';
		if ($freq_excluopt_limit['valeur']=='1') { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="excluoptlimit"> '.FREQC_EXC16.'</label><br>';
		echo '&bull; '.FREQC_EXC17.' <input type="number" min="0" max="300" class="number" id="excluoptlimitduree" name="excluoptlimitduree"';
		echo ' value="'.$freq_excluopt_limitduree['valeur'].'"/></p>';
		echo '</td></tr><tr><td style="text-align:right;"><input class="bouton boutfreq" type="submit" value="'.VALID.'" name="excluopts_valid" /></td></tr></table>';
		echo '</form>';	
		echo '<script type="text/javascript">
		function colorval(divs) {
			var couleur = "green 2px solid";
			var couleurw = "black 1px solid";
			var color = "green";
			var colorw = "black";			    
            document.getElementById(divs).style.border = couleur;
			document.getElementById(divs).style.color = color;
			setTimeout(() => {  
				document.getElementById(divs).style.color = colorw; 
				document.getElementById(divs).style.border = couleurw;
				}, 2000);
			}
		</script>';	
	}
}
else {
	include('include/noaccess.php');
	echo '<br><a href="./index.php">'.ACCUEIL.'</a></p>';
}
?>