<?php require_once(dirname(__DIR__, 1) . '/config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
echo '<meta charset="utf-8" />';
if(isset($_SESSION['user_droits'])) {
	if($_SESSION['user_droits'][0]!="2")
	{
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="./index.php">'.ACCUEIL.'</a></p>';
	}
	else {
		?><style type="text/css">
		#mev1 { background-color: #fff; }
		#mev1 td { border: 3px #089608 solid; }
		</style><?php
		if(isset($_SESSION['diveval'])||isset($_GET['div'])) {
			if(isset($_GET['div'])) {
				$diveval = $_GET['div'];
			}
			else {
				$diveval = $_SESSION['diveval'];
				$_GET['div'] = $diveval;
			}
			$_SESSION['diveval'] = $diveval;
		}
		echo '<div class="div-loading"><img class="ajax-loading" src="img/div/loadingImage.gif" alt="Loading" /></div>';
		echo '<h1>'.EVALC1.'</h1>
		<h2>'.EVALC2.'</h2>
		<form method="GET" action="eval.php?page=classe" class="padd2" onsubmit="return loadingEval();">
			<input type="hidden" name="page" value="classe" />
			'.DATAEXP1.' <div class="box"><select name="div" value=""><option></option>';
				$liste_division = mysqli_query($bdd,"SELECT division FROM ".$prefix."_eleves WHERE categ = '1' GROUP BY division ORDER BY division ASC");
				while($liste = mysqli_fetch_assoc($liste_division)) {
					echo '<option';
					if(isset($_SESSION['diveval'])) {
						if($_SESSION['diveval']==$liste['division']) {
							echo ' selected ';
						}
					}
					echo '>'.$liste['division'].'</option>';
				}
				$liste_groupe = mysqli_query($bdd,"SELECT groupe_nom FROM ".$prefix."_groupes WHERE groupe_actif = 1 ORDER BY groupe_nom ASC");
				while($liste = mysqli_fetch_assoc($liste_groupe)) {
					echo '<option';
					if(isset($_SESSION['diveval'])) {
						if($_SESSION['diveval']==$liste['groupe_nom']) {
							echo ' selected ';
						}
					}
					echo '>'.$liste['groupe_nom'].'</option>';
				}
			echo '</select></div>&nbsp; 
			<input class="bouton boutev ajax-load" type="submit" value="'.EVALC3.'" />
			</form>';
	}
	if(isset($_GET['div'])||isset($_SESSION['diveval'])) {
		if(isset($_GET['div'])) {
			$diveval = $_GET['div'];
		}
		else {
			$diveval = $_SESSION['diveval'];
		}
		$_SESSION['diveval'] = $diveval;
		//groupe ou division :
		$divgr = mysqli_query($bdd,"SELECT division FROM ".$prefix."_eleves WHERE division = '$diveval'");
		$divgr_nb = mysqli_num_rows($divgr);
		if($divgr_nb==0) {
			$nbeleves_diveval_select = "SELECT * FROM ".$prefix."_eleves eleves
			INNER JOIN ".$prefix."_groupele groupele
			ON groupele.eleves_id = eleves.eleves_id
			INNER JOIN ".$prefix."_groupes groupes
			ON groupele.groupe_id = groupes.groupe_id 
			WHERE groupe_nom = '$diveval'";
			$nbeleves_diveval = mysqli_query($bdd,$nbeleves_diveval_select);
			$nbeleves = mysqli_num_rows($nbeleves_diveval);
			$divougr = "groupe";
		}
		else {
			$nbeleves_diveval = mysqli_query($bdd,"SELECT * FROM ".$prefix."_eleves WHERE division = '$diveval'");
			$nbeleves = mysqli_num_rows($nbeleves_diveval);
			$divougr = "division";
		}
		echo '</article><article id="artleft">';
		//gestion des affichages :
		$deb_diveval = substr("$diveval", 0, 1);
		echo '<h2>'.$diveval.' ('.$nbeleves.' élèves)</h2>';
		include('db/proc/eval_select_div.php');	
		//sortie PDF
		$_SESSION['eval_pdf'] = "division";
		echo '<p><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/mailing/mailing_eval.php');
			}
			echo '&nbsp; &nbsp; <a href="javascript:;clearTimeout(timer);" id="mail" onmousedown="toggleDiv(\'divmail\');"><img src="img/div/mail.png" title="'.EVALC4.'" name="noprint" class="printer" /></a>';
			echo '<div name="noprint" id="divmail" style="display:none;">
			<br>'.EVALC5.'
			<form method="POST" action="" name="mailing">';
			$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="concerned" value="'.$diveval.'" />
			<input class="bouton boutev paddvalid1" type="submit" name="mail_send" value="'.SEND.'" /></form>';
			echo '</div>';
		}
		if(isset($_POST['havepdf'])) {
			include('./include/pdf_loaders/evaluations.php');
		}
	    echo '<form id="loadpdf" action="./include/pdf_loaders/evaluations.php" method="post"><input type="hidden" name="havepdf" value="1" /></form>';

	    echo '<script type="text/javascript">
	    function submitpdf(){
	    	$("#loadpdf").submit()
	    }
	    </script></p>';
	}
}
else {
	include('include/noaccess.php');
	echo '<br><a href="../index.php">'.ACCUEIL.'</a></p>';
}
?>
