<?php
echo '<meta charset="utf-8" />';
if(isset($_SESSION['user_droits'])) {
	if($_SESSION['user_droits'][2]!=2)
	{
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="./index.php">'.ACCUEIL.'</a></p>';
	}
	else {
		?><style type="text/css">
		#mdt6 { background-color: #fff; }
		#mdt6 td { border: 3px #E77015 solid; }
		#mdt5 td { border: 0; }
		</style><?php
		echo '<div class="edt_padding"><h1>'.EDTC_PARAM1.'</h1>';
		
		// Gestion du message pour les créneaux libres :
			
		echo '<h2>'.EDTC_PARAM2.'</h2>';
		// Récupération du texte enregistré pour ouverture hors séance :
		$openmsg = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_openmsg'");
		$openmsg_info = mysqli_fetch_assoc($openmsg);
		$openmsg_txt = $openmsg_info['valeur'];
		// Formulaire :
		echo '<p>'.EDTC_PARAM3.'</p>
		<p>
			<input type="text" class="inptxt" name="openmsg" maxlength="30" id="message" value="'.$openmsg_txt.'" /></p>
			<p>Format horaire :';
			$horform_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_formhor'"));
			echo '<br><input type="radio" id="formhor1" name="formhorchoix" value="1" ';
			if($horform_info['valeur']=="1") { echo 'checked'; }
			echo ' /><label for="formhor1">'.EDTC_PARAM47.'</label> <br><input type="radio" id="formhor2" name="formhorchoix" value="2" '; 
			if($horform_info['valeur']=="2") { echo 'checked'; }
			echo ' /><label for="formhor2">'.EDTC_PARAM48.'</label><br><input type="radio" id="formhor3" name="formhorchoix" value="3" ';
			if($horform_info['valeur']=="3") { echo 'checked'; }
			echo ' /><label for="formhor3">'.EDTC_PARAM49.'</label> <br></p>
			<p class="margel1"><input class="bouton boutedt" onclick="message(this,\'messageval\');colorval(\'messageval\');" type="submit" value="'.VALID.'" name="msgvalid" id="messageval" /></p>';
		echo '<script type="text/javascript">
			function message(param, openmsg_new) {
			var param = "message";
			var openmsg_new = document.getElementById("message").value;
			var typ = document.getElementsByName("formhorchoix");              
            for(i = 0; i < typ.length; i++) {
                if(typ[i].checked)
                var typh = typ[i].value;
            }
			$.ajax({
			    type: "POST",
			    data: { param: param, openmsg_new: openmsg_new, typh: typh },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';
		
		// Gestion du message sous l'emploi du temps :
			
		echo '<h2>'.EDTC_PARAM4.'</h2>';	
		$edtmsgopt = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_msgopt'"));
		$edtmsgopt_infos = explode(";",$edtmsgopt['valeur']);
		$edttitleopt = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_titopt'"));
		$edttitleopt_infos = explode(";",$edttitleopt['valeur']);
		echo '<b>'.EDTC_PARAM6.'</b><br> <br><input type="checkbox" name="edttitre" id="edttitre"';
		if ($edttitleopt_infos[0]=='1') { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="edttitre"> '.EDTC_PARAM5.'</label><p />';
		// Récupération du texte enregistré pour affichage sous edt :
		$tit_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_tit'"));
		$tit_txt = $tit_info['valeur'];
		// Formulaire :
		echo '<div id="edttitreopt"';
		if($edttitleopt_infos[0]=='0') {
			echo ' style="display:none;" ';
		}
		echo '><p>'.EDTC_PARAM70.$_SESSION['lieu_nom'].EDTC_PARAM71.'</p><textarea name="edt_tit" id="edt_tit" maxlength="300" rows="3" cols="60">'.$tit_txt.'</textarea>
		<br>'.EDTC_PARAM8.' <input type="text" size="2" maxlength="4" name="edttitlesize" id="edttitlesize" value="'.$edttitleopt_infos[1].'" /> '.EDTC_PARAM9.' <input type="color" name="edttitlecolor" id="edttitlecolor" value="'.$edttitleopt_infos[2].'" /></div>';
		echo '<br><input type="checkbox" name="edtnotete" id="edtnotete"';
		if ($edttitleopt_infos[3]=='1') { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="edtnotete"> '.EDTC_PARAM10.'</label>
		<br>&nbsp; <br><input type="checkbox" name="edtmsgok" id="edtmsgok"';
		if ($edtmsgopt_infos[0]=='1') { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="edtmsgok"> '.EDTC_PARAM11.'</label>';
		// Récupération du texte enregistré pour affichage sous edt :
		$openmsg_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_msg'"));
		$openmsg_txt = $openmsg_info['valeur'];
		// Formulaire :
		echo '<div id="edtmsgokopt"';
		if($edtmsgopt_infos[0]=='0') {
			echo ' style="display:none;" ';
		}
		echo '><p>'.EDTC_PARAM3.'</p><textarea name="edt_msg" id="edt_msg" maxlength="300" rows="3" cols="60">'.$openmsg_txt.'</textarea>
		<br>'.EDTC_PARAM12.' <input  type="text" size="2" maxlength="4" name="edtbotmsgsize" id="edtbotmsgsize" value="'.$edtmsgopt_infos[1].'" /> '.EDTC_PARAM9.' <input type="color" name="edtbotmsgcolor" id="edtbotmsgcolor" value="'.$edtmsgopt_infos[2].'" /></div>';
		$blocnotes = mysqli_query($bdd,"SELECT * FROM ".$prefix."_agenda WHERE SUBSTRING(options, 7, 1) = '1' AND (date1 >= '".date('Y-m-d')."' OR date2 >= '".date('Y-m-d')."') ORDER BY date1 ASC");
		if(mysqli_num_rows($blocnotes)>0) {
			echo '<p>'.EDTC_AGE16.'</p>';
			@$edtmsgopt_agenda = explode("-",@$edtmsgopt_infos[3]);
			foreach($blocnotes as $blocnote) {
				$note = $blocnote['agenda_id'];
				$date1 = DateTime::createFromFormat('Y-m-d', $blocnote['date1']);
				$date2 = DateTime::createFromFormat('Y-m-d', $blocnote['date2']);
				echo '<input type="checkbox" name="note'.$note.'" id="note'.$note.'" ';
				if(in_array($note,$edtmsgopt_agenda)) { echo 'checked '; }
				echo ' /> <label for="note'.$note.'"> ';
				if($blocnote['date2']!='0000-00-00') {
					echo FROM21.' '.$date1->format('d/m/Y').' '.TO2.' '.$date2->format('d/m/Y').DOTS.' ';
				}
				else {
					echo LE.' '.$date1->format('d/m/Y').DOTS.' ';
				}
				echo $blocnote['titre'];
				echo '</label><br> ';	
			}				
		}
		echo '<p class="margel1"><input class="bouton boutedt" type="submit" value="'.VALID.'" name="edtorgavalid" onclick="extraction(this,\'extractval\');colorval(\'extractval\');" id="extractval" /></p>';
		?><script type="text/javascript">
			$("#edttitre").change(function(){
			  $("#edttitreopt").toggle($(this).is(":checked"));
			});
		</script>
		<script type="text/javascript">
			$("#edtmsgok").change(function(){
			  $("#edtmsgokopt").toggle($(this).is(":checked"));
			});
		</script>
		<script type="text/javascript">
			function extraction(param, edt_tit, edttitlesize, edttitlecolor, edt_msg, edtbotmsgsize, edtbotmsgcolor) {
			var param = "extraction";
			var checkedtit = document.getElementById("edttitre").checked;
			var checkedsup = document.getElementById("edtnotete").checked;
			var checkedmsg = document.getElementById("edtmsgok").checked;
			if(checkedtit===false) {
				var edt_tit = "";
				var edttitlesize = ""; 
				var edttitlecolor = "";
				var tit = "0";
			}
			else {
				var edt_tit = document.getElementById("edt_tit").value;
				var edttitlesize = document.getElementById("edttitlesize").value;
				var edttitlecolor = document.getElementById("edttitlecolor").value;
				var tit = "1";
			}
			if(checkedsup===false) {
				var sup = "0";
			}
			else {
				var sup = "1";
			}
			if(checkedmsg===false) {
				var edt_msg = "";
				var edtbotmsgsize = "";
				var edtbotmsgcolor = "";
				var msg = "0";
			}
			else {
				var edt_msg = document.getElementById("edt_msg").value;
				var edtbotmsgsize = document.getElementById("edtbotmsgsize").value;
				var edtbotmsgcolor = document.getElementById("edtbotmsgcolor").value;
				var msg = "1";
			}
			var selectedAgendaIds = [];
			document.querySelectorAll('input[type="checkbox"][id^="note"]').forEach(function(checkbox) {
			    if (checkbox.checked) {
			        var id = checkbox.id.replace('note', '');
			        selectedAgendaIds.push(id);
			    }
			});
			var agendaParam = selectedAgendaIds.join('-');
			$.ajax({
			    type: "POST",
			    data: { param: param, tit: tit, sup: sup, msg: msg, edt_tit: edt_tit, edttitlesize: edttitlesize, edttitlecolor: edttitlecolor, edt_msg: edt_msg, edtbotmsgsize: edtbotmsgsize, edtbotmsgcolor: edtbotmsgcolor, agenda: agendaParam },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script><?php
						
		// Gestion des codes :
			
		echo '<h2 id="gestcodes">'.EDTC_PARAM13.'</h2>';
		
		// Gestion de la suppression d'un code
		if(isset($_POST['code_suppr'])) {
			$code = mysqli_query($bdd,"DELETE FROM ".$prefix."_edtcode WHERE code = '".$_POST['supprcode']."'");
		}

		// Gestion de l'ajout d'un code
		if(isset($_POST['newcode_valid'])) {
			$codenew = mysqli_real_escape_string($bdd,trim($_POST['code']));
			$nomnew = mysqli_real_escape_string($bdd,trim($_POST['nom']));
			if(mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_edtcode WHERE code = '".$codenew."' OR nom = '".$nomnew."'"))==0) {
				mysqli_query($bdd,"INSERT INTO ".$prefix."_edtcode (code_id, code, nom, activ_code, default_code, bgcolor_code) VALUES ('', '".$codenew."', '".$nomnew."', 1, 0, '#ffffff')");
			}
		}
		
		// Gestion du choix de code par défaut
		if(isset($_POST['code_default'])) {
			$code = $_POST['defaultcode'];
			if($code!="") {
				$codedef1 = mysqli_query($bdd,"UPDATE ".$prefix."_edtcode SET activ_code = 1, default_code = 1 WHERE code = '".$code."'");
				$codedef0 = mysqli_query($bdd,"SELECT * FROM ".$prefix."_edtcode WHERE code != '".$code."'");
				foreach($codedef0 as $codedef0_info) {
					mysqli_query($bdd,"UPDATE ".$prefix."_edtcode SET default_code = 0 WHERE code = '".$codedef0_info['code']."'");
				}
			}
		}
		
		// Activations
		echo EDTC_PARAM14;
		$code = mysqli_query($bdd,"SELECT * FROM ".$prefix."_edtcode ORDER BY code ASC");
		$nb_code = mysqli_num_rows($code);
		if($nb_code==0) {
			echo EDTC_PARAM15;
		}
		else {
			echo '<table class="noborder"><tr><td>';
			foreach($code as $check_code) {
				if($check_code['activ_code'] == "1") { $check = "checked"; } else { $check = "0"; }
				echo '<input type="checkbox" name="'.$check_code['code'].'" id="c'.$check_code['code_id'].'" '.$check.'/> <label for="c'.$check_code['code_id'].'"><b>'.$check_code['code'].'</b> : '.$check_code['nom'].'</label><br>';
			}
			echo '</td></tr><tr><td style="text-align:right;"><input class="bouton boutedt" type="submit" value="'.VALID.'" onclick="codeactiv(this);colorval(\'codeactivval\');" name="activ_valid" id="codeactivval" /></td></tr></table>';
		}
		echo '<script type="text/javascript">
			function codeactiv(param) {
			var param = "codeactiv";';
			foreach($code as $check_code) {
				echo ' var c'.$check_code['code_id'].' = document.getElementById("c'.$check_code['code_id'].'").checked;
				if(c'.$check_code['code_id'].'===false) {
					var t'.$check_code['code_id'].' = 0;
				}
				else {
					var t'.$check_code['code_id'].' = 1;
				}';
			}
			echo ' $.ajax({
			    type: "POST",
			    data: { param: param'; 
			    foreach($code as $check_code) { echo ', t'.$check_code['code_id'].':t'.$check_code['code_id'].' '; } 
			    echo '},
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';
		// Choix du code par défaut
		echo '<p><b>'.EDTC_PARAM16.'</b></p>';
		if($nb_code==0) {
			echo EDTC_PARAM15;
		}
		else {
			$coded = mysqli_query($bdd,"SELECT * FROM ".$prefix."_edtcode WHERE default_code = 1");
			$nomd = mysqli_fetch_assoc($coded);
			if(isset($nomd['nom'])) {
				echo '<p>'.EDTC_PARAM17.' "<b>'.$nomd['nom'].'</b>" '.EDTC_PARAM18.'</p>';
			}
			else {
				echo EDTC_PARAM19;
			}
			echo'<form method="POST" name="defaultcode" action="edt.php?page=param#gestcodes" class="padd1">'.EDTC_PARAM20.' <div class="box"><select name="defaultcode" value=""><option></option>';
			$liste_code = mysqli_query($bdd,"SELECT code, nom FROM ".$prefix."_edtcode ORDER BY nom ASC");
			while($liste = mysqli_fetch_assoc($liste_code)) {
				if($liste['code']=="ZERO") { }
				else {
					echo '<option value="'.$liste['code'].'"';
					if(@$nomd['code']==$liste['code']) { echo ' selected '; }
					echo '>'.$liste['nom'].'</option>';
				}
			}
			echo '</select></div>&nbsp; <input class="bouton boutedt" type="submit" value="'.PARAC_ETAB39.'" name="code_default" /></form>';
		}
		// Ajout d'un code
		echo '<p><b>'.EDTC_PARAM21.'</b><br><i>'.EDTC_PARAM22.'</i></p>';
		echo '<form method="POST" name="newcode" action="edt.php?page=param#gestcodes" class="padd1">';
		echo CODE.DOTS.' <input type="text" class="inptxt" name="code" maxlength="10" />';
		echo ' '.EDTC_PARAM23.' <input type="text" class="inptxt" name="nom" maxlength="100" />';
		echo ' <input class="bouton boutedt" type="submit" value="'.VALID.'" name="newcode_valid" />';
		echo '</form>';
		// Suppression
		echo EDTC_PARAM24;
		if($nb_code==0) {
			echo EDTC_PARAM15;
		}
		else {
			echo'<form method="POST" name="supprcode" action="edt.php?page=param#gestcodes" class="padd1">'.EDTC_PARAM25.' <div class="box"><select name="supprcode" value=""><option></option>';
			$liste_code = mysqli_query($bdd,"SELECT code, nom FROM ".$prefix."_edtcode ORDER BY nom ASC");
			foreach($liste_code as $liste) {
				if($liste['code']!="ZERO"&&mysqli_num_rows(mysqli_query($bdd,"SELECT code FROM ".$prefix."_edtbrik WHERE code = '".$liste['code']."'"))==0) { 
					echo '<option value="'.$liste['code'].'"><b>'.$liste['code'].'</b> : '.$liste['nom'].'</option>';
				}
			}
			echo '</select></div>&nbsp; <input class="bouton boutedt" type="submit" value="'.SUPPR.'" name="code_suppr" /></form>';
		}		
		
		// Gestion des couleurs des briques :
			
		echo '<br><h2>'.EDTC_PARAM26.'</h2>';
		
		echo '<p><b>'.EDTC_PARAM27.'</b></p>';
		
		$cren_colors = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_crencolors'"));
		echo '<table>';
		// Affichage
		echo '<tr><td>'.EDTC_PARAM28.' </td><td><input type="color" id="cren1" name="cren1" maxlength="30" value="'.substr($cren_colors['valeur'],0,7).'" /></td></tr><tr><td>'.EDTC_PARAM29.' </td><td><input type="color" id="cren2" name="cren2" maxlength="30" value="'.substr($cren_colors['valeur'],7,7).'" /></td></tr><tr><td>'.EDTC_PARAM30.' </td><td><input type="color" id="cren3" name="cren3" maxlength="30" value="'.substr($cren_colors['valeur'],14,7).'" /></td></tr><tr><td>En-tête : </td><td><input type="color" id="cren4" name="cren4" maxlength="30" value="'.substr($cren_colors['valeur'],21,7).'" /></td></tr>';
		echo '<tr><td colspan="2" style="text-align:center;"><input class="bouton boutedt" type="submit" value="'.COLOR2.'" onclick="colorhbdef(this);colorval(\'colorhbdef\');" id="colorhbdef" name="coldefcren" />&nbsp; &nbsp; <input class="bouton boutedt" type="submit" class="preins" value="'.VALID.'" onclick="colorhbval(this);colorval(\'colorhbval\');" id="colorhbval" name="colorcren" /></td></tr>
		</table>';
		echo '<script type="text/javascript">
			function colorhbdef(param) {
			var param = "colorhbdef";
			document.getElementById("cren1").value = "#EEEEEE";
			document.getElementById("cren2").value = "#D0CCC2";
			document.getElementById("cren3").value = "#7D7777";
			document.getElementById("cren4").value = "#7D7777";			
			$.ajax({
			    type: "POST",
			    data: { param: param },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';
		echo '<script type="text/javascript">
			function colorhbval(param) {
			var param = "colorhbval";
			var cren1 = document.getElementById("cren1").value;
			var cren2 = document.getElementById("cren2").value;
			var cren3 = document.getElementById("cren3").value;
			var cren4 = document.getElementById("cren4").value;		
			$.ajax({
			    type: "POST",
			    data: { param: param, cren1: cren1, cren2: cren2, cren3: cren3, cren4: cren4 },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';

		echo '<p><b>'.EDTC_PARAM31.'</b></p>';
		// Formulaire de choix
		echo '<p><input type="radio" id="colorchoixniv" name="colorchoix" value="niv" ';
		if($colorsys_info['valeur']=="niv") { echo 'checked'; }
		echo ' /><label for="colorchoixniv">'.EDTC_PARAM32.'</label> <br><input type="radio" id="colorchoixcod" name="colorchoix" value="cod" '; 
		if($colorsys_info['valeur']=="cod") { echo 'checked'; }
		echo ' /><label for="colorchoixcod">'.EDTC_PARAM33.'</label></p>';
		echo '<div id="colortxtopt"';
		if($colorsys_info['valeur']=="cod") {
			echo ' style="display:none;" ';
		}
		echo '>';
		echo '<input type="checkbox" name="colortxt" id="colortxt"';
		if ($colortex_info['valeur']==1) { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="colortxt"> '.EDTC_PARAM46.'</label></div>';
		echo '<p class="margel1"><input class="bouton boutedt" type="submit" onclick="colortype(this);colorval(\'colortype\');" id="colortype" value="'.VALID.'" name="colorchoix_valid" /></p>';
		echo '<script type="text/javascript">
		    $(document).ready(function() {
		        $("input[name=\'colorchoix\']").change(function() {
		            // Vérifie si le bouton #colorchoixniv est sélectionné
		            if ($("#colorchoixniv").is(":checked")) {
		                $("#colortxtopt").show(); // Affiche la div
		            } else {
		                $("#colortxtopt").hide(); // Cache la div si un autre bouton est sélectionné
		            }
		        });
		    });
		</script>';
		echo '<script type="text/javascript">
			function colortype(param) {
			var param = "colortype";
			var typ = document.getElementsByName("colorchoix");              
            for(i = 0; i < typ.length; i++) {
                if(typ[i].checked)
                var typc = typ[i].value;
            }
            var colortext = document.getElementById("colortxt").checked;
            if(colortext===false) {
				var tcoltext = 0;
			}
			else {
				var tcoltext = 1;
			}
			$.ajax({
			    type: "POST",
			    data: { param: param, typc: typc, tcoltext: tcoltext },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';
						
		echo '<p id="colornivs"><b>'.EDTC_PARAM34.'</b></p>';
		
		$nivcolor = mysqli_query($bdd,"SELECT id, niveau, bgcolor FROM ".$prefix."_edtnivcolor ORDER BY id");
		echo '<table>';
		foreach($nivcolor as $champsniv) {
			// Affichage
			echo '<tr><td>';
			if($champsniv['niveau']=="6") { echo '6ème';}
			else if($champsniv['niveau']=="5") { echo '5ème'; }
			else if($champsniv['niveau']=="4") { echo '4ème'; }
			else if($champsniv['niveau']=="3") { echo '3ème'; }
			else if($champsniv['niveau']=="2") { echo '2nde'; }
			else if($champsniv['niveau']=="1") { echo '1re'; }
			else if($champsniv['niveau']=="t") { echo 'Tale'; }
			else if($champsniv['niveau']=="a") { echo EDTC_PARAM35; }
			else if($champsniv['niveau']=="r") { echo EDTC_PARAM36; }
			echo '</td>';
			echo '<td><input type="color" id="couleurniv'.$champsniv['niveau'].'" name="couleur'.$champsniv['niveau'].'" maxlength="30" value="'.$champsniv['bgcolor'].'" />';
			echo '</td></tr>';
			
		}
		echo '<tr><td colspan="2" style="text-align:center;"><input class="bouton boutedt" type="submit" value="'.COLOR2.'" onclick="colornivdef(this);colorval(\'colornivdef\');" id="colornivdef" name="coldefniv" />&nbsp; &nbsp; <input class="bouton boutedt" type="submit" class="preins" onclick="colornivval(this);colorval(\'colornivval\');" id="colornivval" value="'.VALID.'" name="colorniv" /></td></tr>
		</table>';
		echo '<script type="text/javascript">
			function colornivdef(param) {
			var param = "colornivdef";';
			foreach($nivcolor as $champsniv) {
				if($champsniv['niveau']=="6") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#F5A9A9";'; }
				else if($champsniv['niveau']=="5") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#F5D0A9";'; }
				else if($champsniv['niveau']=="4") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#E1F5A9";'; }
				else if($champsniv['niveau']=="3") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#BCF5A9";'; }
				else if($champsniv['niveau']=="2") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#A9F5BC";'; }
				else if($champsniv['niveau']=="1") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#A9F5F2";'; }
				else if($champsniv['niveau']=="t") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#A9A9F5";'; }
				else if($champsniv['niveau']=="a") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#E2A9F3";'; }
				else if($champsniv['niveau']=="r") { 
					echo 'document.getElementById("couleurniv'.$champsniv['niveau'].'").value = "#E6E6E6";'; }			
			}
			echo '$.ajax({
			    type: "POST",
			    data: { param: param },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';
		echo '<script type="text/javascript">
			function colornivval(param) {
			var param = "colornivval";';
			foreach($nivcolor as $champsniv) {
				echo ' var couleurniv'.$champsniv['niveau'].' = document.getElementById("couleurniv'.$champsniv['niveau'].'").value;
				'; 
			}							
			echo '$.ajax({
			    type: "POST",
			    data: { param: param';
			    foreach($nivcolor as $champsniv) {
			    	echo ', couleurniv'.$champsniv['niveau'].': couleurniv'.$champsniv['niveau'];
			    }
			    echo ' },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';
		
		// Codes
		echo '<p id="colorcods"><b>'.EDTC_PARAM37.'</b></p>';
		$codcolor = mysqli_query($bdd,"SELECT * FROM ".$prefix."_edtcode WHERE activ_code = 1 ORDER BY code_id ASC");
		echo '<table>';
		foreach($codcolor as $champscod) {
			echo '<tr><td>'.$champscod['code'].' : '.$champscod['nom'].'</td>';
			echo '<td><input type="color" name="couleurcod'.$champscod['code_id'].'" id="couleurcod'.$champscod['code_id'].'" idmaxlength="30" value="';
			if($champscod['bgcolor_code']=="") { echo '#FFFFFF'; }
			else {
				echo ''.$champscod['bgcolor_code'].'';
			}
			echo '" />';
			echo '</td></tr>';
		}
		echo '<tr><td colspan="2" style="text-align:center;"><input class="bouton boutedt" type="submit" value="'.COLOR2.'" onclick="colorcoddef(this);colorval(\'colorcoddef\');" id="colorcoddef" name="coldefcod" />&nbsp; &nbsp; <input class="bouton boutedt" type="submit" class="preins" onclick="colorcodval(this);colorval(\'colorcodval\');" id="colorcodval" value="'.VALID.'" name="colorcod" /></td></tr>
		</table>';
		echo '<script type="text/javascript">
			function colorcoddef(param) {
			var param = "colorcoddef";';
			$color_array = array('#FF9900','#99FF00','#CCFFFF','#FF66FF','#CC6600','#FFFF33','#99CC66', '#1E7FCB','#9900FF','#FF0033','#CCCC00','#66CC66','#EFD242','#FFF48D','#CC99CC','#E6E697','#FF6666','#F4C430','#33CC33','#3399FF');
			$i=0;				
			foreach($codcolor as $champscod) {
				echo 'document.getElementById("couleurcod'.$champscod['code_id'].'").value = "'.$color_array[$i].'";';				
				$i++;
			}
			echo '$.ajax({
			    type: "POST",
			    data: { param: param },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';
		echo '<script type="text/javascript">
			function colorcodval(param) {
			var param = "colorcodval";';
			foreach($codcolor as $champscod) {
				echo ' var couleurcod'.$champscod['code_id'].' = document.getElementById("couleurcod'.$champscod['code_id'].'").value;
				'; 
			}							
			echo '$.ajax({
			    type: "POST",
			    data: { param: param';
			    foreach($codcolor as $champscod) {
			    	echo ', couleurcod'.$champscod['code_id'].': couleurcod'.$champscod['code_id'];
			    }
			    echo ' },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';

		echo '<br><h2>'.EDTC_PARAM38.'</h2>';
		echo '<table class="noborder"><tr><td><input type="checkbox" name="edtverr" id="edtverr"';
		$crprechoix = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_brikverr'");
		$crprechoix_info = mysqli_fetch_assoc($crprechoix);
		if ($crprechoix_info['valeur']==1) { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="edtverr"> '.EDTC_PARAM39.'</label><br />';
		echo '</td></tr><tr><td style="text-align:right;"><input class="bouton boutedt" type="submit" value="'.VALID.'" onclick="verrouillage(this);colorval(\'verrouillage\');" id="verrouillage" name="edt_verrouillage" /></td></tr></table>';
		echo '<script type="text/javascript">
			function verrouillage(param) {
			var param = "verrouillage";
			var checkedver = document.getElementById("edtverr").checked;
			if(checkedver===false) {
				var verrou = "0";
			}
			else {
				var verrou = "1";
			}
			$.ajax({
			    type: "POST",
			    data: { param: param, verrou: verrou },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';

		echo '<h2>'.EDTC_PARAM40.'</h2>';
		echo '<table class="noborder"><tr><td><input type="checkbox" name="edtdupli" id="edtdupli"';
		$crprechoix = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_duplicate'");
		$crprechoix_info = mysqli_fetch_assoc($crprechoix);
		if ($crprechoix_info['valeur']==1) { $check = 'checked'; } else { $check = 0; }
		echo ' '.$check.'/><label for="edtdupli"> '.EDTC_PARAM41.'</label>';
		echo '</td></tr><tr><td style="text-align:right;"><input class="bouton boutedt" type="submit" value="'.VALID.'" onclick="multdup(this);colorval(\'multdup\');" id="multdup" name="edt_duplicate" /></td></tr></table>';
		echo '<script type="text/javascript">
			function multdup(param) {
			var param = "multdup";
			var checkeddupli = document.getElementById("edtdupli").checked;
			if(checkeddupli===false) {
				var dupli = "0";
			}
			else {
				var dupli = "1";
			}
			$.ajax({
			    type: "POST",
			    data: { param: param, dupli: dupli},
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';

		echo '<h2>'.EDTC_PARAM42.'</h2>';
		//Gestion des images des EDT
		$check_imgmode_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_imgmode'"));
		//image générique ou images spécifiques
		echo '<table class="noborder"><tr><td><input type="radio" name="edtspe" value="spe" id="edtspespe" ';
		if ($check_imgmode_info['valeur']=="spe") { echo 'checked'; }
		echo ' /><label for="edtspespe"> '.EDTC_PARAM43.'</label> ';
		//nombre d'images stockées si spécifiques
		$crprechoix_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_imgnb'"));
		echo EDTC_PARAM44.' <input type="number" name="imgnb" id="imgnb" max="20" class="number" value="'.$crprechoix_info['valeur'].'" /><br>';
		echo '<input type="radio" name="edtspe" value="gen" id="edtspegen" ';
		if ($check_imgmode_info['valeur']=="gen") { echo 'checked'; }
		echo ' /><label for="edtspegen"> '.EDTC_PARAM45.'</label><br>';
		echo '</td></tr><tr><td style="text-align:right;"><input class="bouton boutedt" type="submit" value="'.VALID.'" onclick="extract(this);colorval(\'extract\');" id="extract" name="edt_images" /></td></tr></table>';
		echo '<script type="text/javascript">
			function extract(param) {
			var param = "extract";
			var typ = document.getElementsByName("edtspe");    
			var val = document.getElementById("imgnb").value;          
            for(i = 0; i < typ.length; i++) {
                if(typ[i].checked)
                var typd = typ[i].value;
            }
			$.ajax({
			    type: "POST",
			    data: { param: param, typd: typd, val: val },
			    url: "js/idl/edt_param_syn.php",
			   });
			}
		</script>';
		
		echo'</div>';

		echo '<script type="text/javascript">
		function colorval(divs) {
			var couleur = "black 2px solid";
			var couleurw = "white 2px solid";
			var color = "black";
			var colorw = "white";			    
            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>';
}
?>
