<?php
$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'"));
if(!isset($liste['freq_id'])) {
	$liste['freq_id']=0;
}
if($freq_excluopt_raisons['valeur']==1) {
	$causes_reg = mysqli_query($bdd,"SELECT * FROM ".$prefix."_exclucauses ORDER BY exclucause_txt ASC");
	echo '<p>'.FREQ_EXC2.' <input type="text" class="inptxt" id="cause'.$liste['freq_id'].'" name="cause" placeholder="';
	if(mysqli_num_rows($causes_reg)>0) {
		echo FREQ_EXC1;
	}
	echo '" />';
	if(mysqli_num_rows($causes_reg)>0) {
	 	echo '<br><br>'.FREQ_EXC3.' <div class="box"><select id="infocauseslisting'.$liste['freq_id'].'" name="infocauseslisting" value="0"><option value="0"></option>';
	 	foreach($causes_reg as $causes_liste) {
	 		echo '<option value="'.$causes_liste['exclucause_id'].'">'.$causes_liste['exclucause_txt'].'</option>';
	 	}
	 	echo '</select></div>';
	}  else { echo '<input type="hidden" value="0" id="infocauseslisting'.$liste['freq_id'].'" name="infocauseslisting" />'; }
	echo '</p>';
}
echo '<p>'.FREQ_EXC4.' <input type="date" class="inptxt" id="creaexclu'.$liste['freq_id'].'" name="creaexclu" value="'.date('Y-m-d').'" /></p>';
if($freq_excluopt_signal['valeur']==1) {
	if($freq_excluopt_signalduree['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_signalduree['valeur']+1) { break; }
			$date = $datecheck['date'];
			$i++;
		}
	}
	echo '<p>'.FREQ_EXC5.' '.TO3.' <input type="date" class="inptxt" id="signal'.$liste['freq_id'].'" name="signal" value="'.@$date.'" /></p>';
}
if($freq_excluopt_exc['valeur']==1) {
	if($freq_excluopt_excduree['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_excduree['valeur']+1) { break; }
			$date2 = $datecheck['date'];
			$i++;
		}
	}
	echo '<p>'.FREQ_EXC6.' '.TO3.' <input type="date" class="inptxt" id="duree'.$liste['freq_id'].'" name="duree" value="'.@$date2.'" /></p>';
}
echo '<p>'.FREQ_EXC7.' ';
$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 {
	$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="v'.$liste['freq_id'].$check_activ['code_activ'].'" ';
		if($activdef['valeur']=='TOUTES'||(preg_match('/'.$check_activ['code_activ'].'/', $activdef['valeur']))) { echo 'checked'; }
		echo ' /> <label for="v'.$liste['freq_id'].$check_activ['code_activ'].'">'.$check_activ['nom_activ'].'</label>';
	}
	echo '</p>';
}
?>