<?php require_once(dirname(__DIR__, 1) . '/config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
echo '<meta charset="utf-8" />
<script language=javascript>
	function OuvrirPopup(page,nom,option) {
	  window.open(page,nom,option);
	}
</script>';
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">
		#mev2 { background-color: #fff; }
		#mev2 td { border: 3px #089608 solid; }
		#mev1 td { border:0; }
		</style><?php
		echo '<h1>'.EVALC6.'</h1>
		<h2>'.EVALC7.'</h2>
		<form method="POST" action="eval.php?page=eleve" class="padd4">
			<table class="noborder">
				<tr>
					<td><label for="eleves">'.NAMECH.'</label></td>
					<td>
					  <input class="inptxt" autocomplete="off" aria-autocomplete="none" type="text" name="eleve" size="20" id="eleves" value="">
					</td>
				</tr>
				<tr><td colspan="2" style="text-align:right;"><input class="bouton boutev" type="submit" value="'.EVALC8.'" name="elechoix" /></td></tr>
			</table>
		</form>';
	}
	if(isset($_POST['elechoix'])||isset($_SESSION['eleves_id'])) {
		if(isset($_POST['eleve'])) {
			$_SESSION['eleve']=$_POST['eleve'];
		}
		if(isset($_SESSION['eleve'])||isset($_POST['eleve'])) {
			//sélection de l'élève
			include('./db/proc/eleve_select.php');
			
			$diveval = $eleve_info['division'];
			$_SESSION['id'] = $eleve_id;
			$_SESSION['diveval'] = $diveval;
			$_SESSION['nom'] = $eleve_info['nom'];
			$_SESSION['prenom'] = $eleve_info['prenom'];
			$_SESSION['div'] = $diveval;
			$deb_diveval = substr("$diveval", 0, 1);
			echo '</article><article id="artleft">';
			echo '<h2>'.$eleve_info['nom'].' '.$eleve_info['prenom'].' '.$diveval.'</h2>';
			
			$eval_select = '1';
			include('db/proc/eval_select_ele.php');	
			
			//sortie PDF
			$_SESSION['eval_pdf'] = "eleve";
			echo '<p><a onclick="submitpdf();" id="preview-pdf"><img src="img/pdf-icon.png" title="'.PDF_EXTRACT.'"/></a> <a href="javascript:OuvrirPopup(\'db/proc/eval_impress_ele.php\',\'\',\'top=10,left=10,location=no,width=1100,height=600, status=no, scrollbars=yes\')"><img src="img/printer.png" title="'.PRINT2.'"/></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="'.$eleve_info['nom'].' '.$eleve_info['prenom'].' '.$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>';
			include('db/proc/eval_select_elepast.php');
		}
	}
	echo "<script type=\"text/javascript\">
				document.getElementById('eleves').focus();
			</script>";
}
else {
	include('include/noaccess.php');
	echo '<br><a href="../index.php">'.ACCUEIL.'</a></p>';
}
?>
