<?php
//inscrits					
$chgtactiv = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_chgtactiv'");
$chgtactiv_info = mysqli_fetch_assoc($chgtactiv);
if($chgtactiv_info['valeur']!=$_SESSION['journalmodif']&&$_SESSION['journalmodif']!='def') {
	$chgtactiv_info['valeur']=$_SESSION['journalmodif'];
}
echo '<table id="tablesorter" class="tablesorter journaltable center">
<thead><tr><th>'.LEVEL_TINY.'</th><th>'.DIV_TINY.'</th><th>'.NUMBER.'</th>';
if ($droits=="2"&&$chgtactiv_info['valeur']==1) {
	echo '<th name="noprint">'.NUMCORRECT.'</th>';
}
if($period==1||isset($_POST['liste_modif'])) {
	echo '<th>'.DATE.'</th>';
}
if($pass==0) {
	echo  '<th>'.CREN1.'</th><th>'.ACTIV.'</th>';
}
else { echo '<th>'.HOUR2.'</th>'; }
if($espopt['valeur']==1) { echo '<th>'.ZONE.'</th>'; }
if ($droits=="2"&&$chgtactiv_info['valeur']==1) {
	$activ = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv ORDER BY nom_activ ASC");
	$nb_activ = mysqli_num_rows($activ);
	if($nb_activ>1&&$pass==0) {
		echo '<th name="noprint">'.ACTCORRECT.'</th>';
	}
	echo '<th name="noprint">'.SUPPR.'</th>';
}
echo '</tr></thead><tbody>';

foreach($grappes_ins as $liste) {
	echo '<tr>';
	if ($droits=="2"&&$chgtactiv_info['valeur']==1) {
		echo '<form method="POST" name="chgtactiv" action="" class="padd1">';
	}
	echo '<td>';
	if($liste['niveau']=='6') { echo '6ème'; }
	else if($liste['niveau']=='5') { echo '5ème'; }
	else if($liste['niveau']=='4') { echo '4ème'; }
	else if($liste['niveau']=='3') { echo '3ème'; }
	else if($liste['niveau']=='2') { echo '2nde'; }
	else if($liste['niveau']=='1') { echo '1re'; }
	else if($liste['niveau']=='t') { echo 'Tale'; }
	else if($liste['niveau']=='a') { echo 'Autre'; }
	echo '</td><td>'.$liste['division'].'</td><td>'.$liste['nombre'].'</td>';
	if ($droits=="2"&&$chgtactiv_info['valeur']==1) {
		echo '<td name="noprint"><input type="number" name="nbgrap" value="'.$liste['nombre'].'" style="width:50px;" /> <input type="submit" class="boutontab" value=">>>" name="nb'.$liste['freqgrap_id'].'" />';
	}
	if($period==1||isset($_POST['liste_modif'])) {
		// date
		echo '<td>'.$date = $liste['date_freq'].'';
		echo '</td>';
	}
	if($pass==0) {
		// créneau
		$creneau = $liste['hor_name'];
		$hor = mysqli_query($bdd,"SELECT num_creneau, debut, fin FROM ".$prefix."_horaires WHERE hor_name = '".$creneau."'");
		$hor_info = mysqli_fetch_assoc($hor);
		$deb_cren = substr($creneau, 0, 1);
		echo '<td class="left">';
		if($hor_info['num_creneau']<10) {
			echo '0'.$hor_info['num_creneau'].' - ';
		}
		else {
			echo ''.$hor_info['num_creneau'].' - ';
		}
		echo MOMENT[$deb_cren];
		$fin_cren = substr($creneau, 1, 1);
		echo ' ('.$deb_cren.$fin_cren.') de ';
		$deb = $hor_info['debut'];
		$dh = substr($deb, 0, 2);
		$dm = substr($deb, 3, 2);
		echo ''.$dh.'h'.$dm.' à ';
		$fin = $hor_info['fin'];
		$fh = substr($fin, 0, 2);
		$fm = substr($fin, 3, 2);
		echo ''.$fh.'h'.$fm.'';
		echo '</td>';
		// activité
		$activ = mysqli_query($bdd,"SELECT nom_activ FROM ".$prefix."_freqactiv WHERE code_activ = '".$liste['code_activ']."'");
		$activ_info = mysqli_fetch_assoc($activ);
		echo '<td>'.@$activ_info['nom_activ'].'</td>';
	}
	else {
		echo '<td>'.substr($liste['dtstart'],-6,2).':'.substr($liste['dtstart'],-4,2).'</td>';
	}

	// espace
	if($espopt['valeur']==1) {
		echo '<td>';
		if($liste['espace_id']==0) { echo $esp0['valeur']; }
		else { echo $liste['espace_nom']; }
		echo '</td>';
	}

	if ($droits=="2"&&$chgtactiv_info['valeur']==1) {
		$activ = mysqli_query($bdd,"SELECT * FROM ".$prefix."_freqactiv ORDER BY nom_activ ASC");
		$nb_activ = mysqli_num_rows($activ);
		if($nb_activ>1&&$pass==0) {
			echo '<td name="noprint">';
			echo '<div class="box"><select name="chgtactiv" value=""><option></option>';
			$liste_activ = mysqli_query($bdd,"SELECT code_activ, nom_activ FROM ".$prefix."_freqactiv WHERE activ_activ = 1 ORDER BY nom_activ ASC");
			while($listea = mysqli_fetch_assoc($liste_activ)) {
				if($listea['code_activ']!="ZERO") { 
					echo '<option value="'.$listea['code_activ'].'"';
					if($liste['code_activ']==$listea['code_activ']) {
						echo ' selected ';
					}
					echo '>'.$listea['nom_activ'].'</option>';
				}
			}
			echo '</select></div> <input type="submit" class="boutontab" value=">>>" name="chgt'.$liste['freqgrap_id'].'" />';
			echo '</td>';
		}
		echo '<td name="noprint"><input type="submit" class="boutontab" value="'.SUPPR.'" name="suppr'.$liste['freqgrap_id'].'" /></td>';
	}
	if ($droits=="2"&&$chgtactiv_info['valeur']==1) {
		echo '</form>';
	}
	echo '</tr>';
	
	if(isset($_POST['nb'.$liste['freqgrap_id'].''])) {
		$freqgrap_id = $liste['freqgrap_id'];
		mysqli_query($bdd,"UPDATE ".$prefix."_freqgrappes SET nombre = '".$_POST['nbgrap']."' WHERE freqgrap_id = '".$freqgrap_id."'");
		echo '<script language="Javascript">
		<!--
		document.location.replace("freq.php?page=journal");
		// -->
		</script>';	
	}
	if(isset($_POST['chgt'.$liste['freqgrap_id'].''])) {
		$freqgrap_id = $liste['freqgrap_id'];
		mysqli_query($bdd,"UPDATE ".$prefix."_freqgrappes SET code_activ = '".$_POST['chgtactiv']."' WHERE freqgrap_id = '".$freqgrap_id."'");
		echo '<script language="Javascript">
		<!--
		document.location.replace("freq.php?page=journal");
		// -->
		</script>';	
	}
	if(isset($_POST['suppr'.$liste['freqgrap_id'].''])) {
		$freqgrap_id = $liste['freqgrap_id'];
		mysqli_query($bdd,"DELETE FROM ".$prefix."_freqgrappes WHERE freqgrap_id = '".$freqgrap_id."'");
		echo '<script language="Javascript">
		<!--
		document.location.replace("freq.php?page=journal");
		// -->
		</script>';	
	}
}
echo '</tbody></table>';
?>
