<?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'][2] ?? 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 = 'edt'; 
		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 EDT1; ?> - InfodocLog</title>
	<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="css/jquery-ui.css">
	<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" src="js/html2canvas.js"></script>
	<script type="text/javascript" src="include/tinymce/tinymce.min.js"></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>
	<?php include('js/idl/chat_box.php'); ?>
</head>

<body>
	
	<?php $page_header = 'edt'; ?>
	<?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');
	}
	$resavisu = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_resvisuedt'"));
	?>
	<section>
		<?php include('include/nav/nav_edt.php'); ?>
		
		<article id="art_edt">
			<?php
			$freq_gestion_jourscren = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_gestion_jourscren'"));
			$colorsys_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_coloration'"));
			$colortex_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'edt_color_text'"));
			$nivs_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_statsniv'"));
			$espopt = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'espaces_gestion'"));
			$nodiv = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_reseleve_nodiv'"));
			if($nivs_info['valeur']=="PER") { 
				$carac_info = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'freq_statsniv_persoc'"));
				$caracs = explode(",", $carac_info['valeur']);
				$caracs_assoc = array_combine($caracs, $caracs);
				// $caracs_assoc est un tableau associatif
				// Copier $caracs_assoc dans un nouveau tableau pour ne pas affecter l'original
				$sorted_caracs = $caracs_assoc;
				// Trier par longueur des clés en ordre décroissant
				uksort($sorted_caracs, function($a, $b) {
				    return strlen($b) - strlen($a);  // Trier par longueur des clés
				});
			}
			if(!isset($_GET['page'])) {
				include('./contenu/edt_create.php');
			}
			else {
				switch($_GET['page']) {
					case'create':
						include('./contenu/edt_create.php');
						break;
					case'briques':
						include('./contenu/edt_briques.php');
						break;
					case'agenda':
						include('./contenu/edt_agenda.php');
						break;
					case'eleves':
						include('./contenu/edt_eleves.php');
						break;
					case'statsedt':
						include('./contenu/edt_stats.php');
						break;
					case'param':
						include('./contenu/edt_param.php');
						break;
				}
			}
			?>
		</article>
	
	</section>
	<footer id="foot_edt">
	<?php include('include/footer.php'); ?>
	</footer>
</body>
</html>
<?php
}
}
else {
	echo '<link rel="stylesheet" type="text/css" href="css/idl_solo.css" />';
	$page_header = 'edt';
	include('include/header.php');
	include('include/noaccess.php');
	echo '<br><a href="index.php">'.ACCUEIL.'</a></p>';
}
mysqli_close($bdd);
?>