<?php session_start(); ?>
<!doctype html>
<?php require_once('config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
if(isset($_SESSION['user_droits_arr'])) {
	$droits = (string)($_SESSION['user_droits_arr'] ?? '');
	$_SESSION['user_droits'] = trim($droits);
	if (($_SESSION['user_droits'][0] ?? 0) !='2') {
		echo '<link rel="stylesheet" type="text/css" href="css/idl_solo.css" />
		<link rel="stylesheet" type="text/css" href="css/idl_print.css" media="print" />';
		$page_header = 'eval'; 
		include('include/header.php');
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="index.php">'.ACCUEIL.'</a></p>';
	}
else { ?>
<html>
<head>

	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title><?php echo EVALT; ?> - InfodocLog</title>
	<link rel="stylesheet" href="css/jquery-ui.css">
	<link rel="stylesheet" type="text/css" href="css/idl_solo.css" />
	<link rel="stylesheet" type="text/css" href="css/idl_solo_resp.css" />
	<link rel="stylesheet" type="text/css" href="css/idl_print.css" media="print" />
	<link rel="stylesheet" href="include/fontawesome/css/all.css">
	<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
	<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
	<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
	<script type="text/javascript" src="js/jquery-3.7.1.js"></script>
	<script type="text/javascript" src="js/jquery-ui.js"></script>
	<script type='text/javascript'>

		function getXhr(){
			const ALERT2 = "<?php echo ALERT2; ?>";
			var xhr = null; 
			if(window.XMLHttpRequest) // Firefox et autres
			   xhr = new XMLHttpRequest(); 
			else if(window.ActiveXObject){ // Internet Explorer 
			   try {
						xhr = new ActiveXObject("Msxml2.XMLHTTP");
					} catch (e) {
						xhr = new ActiveXObject("Microsoft.XMLHTTP");
					}
			}
			else { // XMLHttpRequest non supporté par le navigateur 
			   alert(ALERT2); 
			   xhr = false; 
			} 
			return xhr;
		}

		/**
		* Méthode qui sera appelée sur le click du bouton la division
		*/
		function div(){
			
			var xhr = getXhr();
			xhr.onreadystatechange = function(){
				if(xhr.readyState == 4 && xhr.status == 200){
					leselect = xhr.responseText;
					document.getElementById('seqch').innerHTML = leselect;
				}
			}

			xhr.open("POST","db/proc/eval_select_seq.php",true);
			xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			sel = document.getElementById('division');
			idauteur = sel.options[sel.selectedIndex].value;
			xhr.send("idAuteur="+idauteur);
		}
		</script>
		<script language="javascript">
			function toggleDiv(divid){
				var element = document.getElementById(divid);
			    if (element.style.display === 'none') {
			        element.style.display = 'block';
			    } else {
			        element.style.display = 'none';
			    }
			}
		</script>
		<script type="text/javascript">
			jQuery(function($){
				$('.div-loading').hide(); // On masque le gif au chargement de la page
				$('.ajax-load').click(function(e){
					// Affichage du gif de chargement et envoi requête AJAX
					$('.div-loading').show();
					$.get(
						'eval.php',
						function(data){
							$('.div-loading').hide(); // On masque le gif 
						}
					);
				});
			});
		</script>
		<script>
		    $(function() {
	        $("#eleves").autocomplete({
	            source: function(request, response) {
	                $.ajax({
	                    url: "include/suggestions.php",
	                    dataType: "json",
	                    data: {
	                        term: request.term
	                    },
	                    success: function(data) {
	                        response(data);
	                    }
	                });
	            }
	        });
	    });
	    </script>
	    <?php include('js/idl/chat_box.php'); ?>
</head>

<body>
	
	<?php $page_header = 'eval'; ?>
	<?php include('include/header.php'); 
	if(isset($_SESSION['user_droits'])&&isset($bdd)) {
		$dnns = @mysqli_fetch_array(mysqli_query($bdd,"SELECT COUNT(user_id) AS nb FROM ".$prefix."_userconnect WHERE user_id='".$_SESSION['user_id']."'"));
        if(@$dnns['nb']>0) {
            @mysqli_query($bdd,"UPDATE ".$prefix."_userconnect SET connected='".time()."' WHERE user_id='".$_SESSION['user_id']."'");
        }
        else {
            @mysqli_query($bdd,"INSERT INTO ".$prefix."_userconnect (user_id, connected) values ('".$_SESSION['user_id']."', '".time()."')");
        }											
		include('include/chat_div.php');
	}?>
	
	<section>
		<?php include('include/nav/nav_eval.php'); ?>
		<article id="art_eval">
			<?php
			if(!isset($_GET['page'])) {
				$verif_tabeleves = mysqli_query($bdd,"SELECT * FROM ".$prefix."_eleves");
				$nb_ele = mysqli_num_rows($verif_tabeleves);
				if($nb_ele==0) {
					echo '<h1>'.EVAL2.'</h1><h2>'.NOELEV.'</h2>';
				}
				else {
					include('./contenu/eval_classe.php');
				}
			}
			else {
				switch($_GET['page']) {
					case'classe':
						include('./contenu/eval_classe.php');
						break;
					case'eleve':
						include('./contenu/eval_eleve.php');
						break;
					case'sequence':
						include('./contenu/eval_sequ.php');
						break;
					case'print':
						include('./contenu/eval_print.php');
						break;
				}
			}
			?>
		</article>
	
	</section>
	<footer id="foot_eval">
	<?php include('include/footer.php'); ?>
	</footer>
</body>
</html>
<?php
}
}
else {
	echo '<link rel="stylesheet" type="text/css" href="css/idl_solo.css" />';
	$page_header = 'eval'; 
	include('include/header.php');
	include('include/noaccess.php');
	echo '<br><a href="index.php">'.ACCUEIL.'</a></p>';
}
mysqli_close($bdd);
?>
