<?php 
session_start(); 
?>
<!doctype html>
<?php require_once('config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
if(isset($_SESSION['user_droits'])) {
	if($_SESSION['user_droits'][5]<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 = 'database'; 
		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 DATA2; ?> - 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" src="js/jquery.tablesorter.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('include/tablesorter.php'); ?>
	<?php include('include/suggestions.php'); ?>
	<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 pour les div
		*/
		function go(){
			// POUR DIV
			var xhr = getXhr();
			xhr.onreadystatechange = function(){
				if(xhr.readyState == 4 && xhr.status == 200){
					leselect = xhr.responseText;
					document.getElementById('divselect').innerHTML = leselect;
				}
			}

			xhr.open("POST","db/proc/freq_select_div.php",true);
			xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			sel = document.getElementById('classe');
			idauteur = sel.options[sel.selectedIndex].value;
			xhr.send("idAuteur="+idauteur);
		}

		function gocar(){
			var seq_id = location.search.substring(1).split('&');
			var xhrbc = getXhr();
			xhrbc.onreadystatechange = function(){
				if(xhrbc.readyState == 4 && xhrbc.status == 200){
					leselectbc = xhrbc.responseText;
					document.getElementById('bc').innerHTML = leselectbc;
				}
			}

			xhrbc.open("POST","db/proc/database_select_bcmod.php",true);
			xhrbc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			selbc = document.getElementById('barcodes');
			idauteurbc = selbc.options[selbc.selectedIndex].value;
			xhrbc.send("idBarcodes="+idauteurbc);
		}
	</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 = 'database'; ?>
	<?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 
		$verif_tabeleves = mysqli_query($bdd,"SELECT * FROM ".$prefix."_eleves");
		$nb_ele = mysqli_num_rows($verif_tabeleves);
		include('include/nav/nav_data.php'); 
		?>
		<article id="art_database">
			<?php 
		
			if(!isset($_GET['page'])) {
				include('./contenu/database_consult.php');
				
			} else {
								
				switch($_GET['page']) {
				case'consulter':
					include('./contenu/database_consult.php');
					break;
				case'print':
					include('./contenu/database_print.php');
					break;
				case'export':
					include('./contenu/database_export.php');
					break;
				case'groupes':
					include('./contenu/database_groupes.php');
					break;
				case'ajouter':
					include('./contenu/database_ajout.php');
					break;
				case'modifier':
					include('./contenu/database_modif.php');
					break;
				case'barcodes':
					include('./contenu/database_codes.php');
					break;
				case'maj':
					include('./contenu/database_maj.php');
					break;
				case'supprimer':
					include('./contenu/database_suppr.php');
					break;
				case'installer':
					include('./contenu/database_install_eleves.php');
					break;
				}
			}
		?>
		</article>
		
	</section>
	
	<footer id="foot_db">
	<?php include('include/footer.php'); ?>
	</footer>

</body>

</html>
<?php
}	
	
}
else {
	echo '<link rel="stylesheet" type="text/css" href="css/idl_solo.css" />';
	$page_header = 'database'; 
	include('include/header.php');
	include('include/noaccess.php');
	echo '<br><a href="index.php">'.ACCUEIL.'</a></p>';
}
mysqli_close($bdd);
?>
