<?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'][1]!="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 = 'edit'; 
		include('include/header.php');
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="index.php">'.ACCUEIL.'</a></p>';
	}
else { $error="";
	if(isset($_POST['zipval'])){
	    $post = $_POST;
	    $file_folder = 'seqfichiers/'.$prefix.'/'; // dossier pour charger des fichiers
	    if(extension_loaded('zip')){ // Vérification si l'extension ZIP est disponible
	        if(isset($post['files']) and count($post['files']) > 0){ // Vérification si des fichiers sont sélectionnés
	            $zip = new ZipArchive(); // Lecture librairie zip
	            $zip_name = 'idlog_files_'.date('Ymd').".zip"; // nom Zip
	            if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){ // Ouverture du zip pour carger les fichiers
	                $error .=  ZIPECHEC;
	            }
	            foreach($post['files'] as $file){
	                $check = mysqli_fetch_assoc(mysqli_query($bdd,"SELECT * FROM ".$prefix."_seqdocs WHERE docurl = '".$file."'"));
	                $zip->addFile($file_folder.$file); // Ajout des fichiers dans le zip
	                $zip->renameName($file_folder.$file,$check['docname']);
	            }
	            $zip->close();
	            if(file_exists($zip_name)){
	                header('Content-type: application/zip');
	                header('Content-Disposition: attachment; filename="'.$zip_name.'"');
	                readfile($zip_name);
	                unlink($zip_name);
	            }
	        } else
	            $error .= ZIPSELECT;
	    } else
	        $error .= ZIPNOEXT;
	}?>
<html>
<head>

	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Séquences - 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>
	<?php 
	include('js/idl/seq_ajax_niveau.php'); 
	include('include/suggest_notions.php');
	?>
	<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';
		    }
		}
		function toggleModu(divid,aplus,aminus,amin2){
			if(document.getElementById(divid).style.display == "none"){
				document.getElementById(divid).style.display = "block";
				document.getElementById(aplus).style.display = "none";
				document.getElementById(aminus).style.display = "inline-block";
				document.getElementById(amin2).style.display = "none";
			}else{
				document.getElementById(divid).style.display = "none";
				document.getElementById(aplus).style.display = "inline-block";
				document.getElementById(aminus).style.display = "none";
				document.getElementById(amin2).style.display = "inline-block";
			}
		}
	</script>
	<script type="text/javascript" src="include/tinymce/tinymce.min.js"></script>
	<?php include('js/idl/chat_box.php'); ?>
</head>

<body>
	
	<?php $page_header = 'edit'; ?>
	<?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_edit.php'); ?>
		<article id="art_edit">
			<?php 
			if(!isset($_GET['page'])) {
				$verif_tabseq = mysqli_query($bdd,"SELECT * FROM ".$prefix."_sequences");
				$nb_seq = mysqli_num_rows($verif_tabseq);
				if($nb_seq==0) {
					echo '<h1>'.SEQUT.'</h1><h2>'.SEQNO.' <a href="edit.php?page=creation">'.SEQCREA.'</a>.</h2>';
				}
				else {
					include('./contenu/edit_consult.php');
				}
			}
			else {
				switch($_GET['page']) {
					case'creation':
						include('./contenu/edit_crea.php');
						break;
					case'consult':
						include('./contenu/edit_consult.php');
						break;
					case'docs':
						include('./contenu/edit_documents.php');
						break;
					case'impexp':
						include('./contenu/edit_impexp.php');
						break;
				}
			}
			?>
		</article>
	
	</section>

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