<?php require_once(dirname(__DIR__, 1) . '/config.php');
require_once(BASE_PATH . '/db/idl_connect.php');
echo '<meta charset="utf-8" />';
if(isset($_SESSION['user_droits'])) {
	if($_SESSION['user_droits'][1]!="2") {
		echo '<p class="noaccess">'.NOMODULE.'<br><a href="./index.php">'.ACCUEIL.'</a></p>';
	}
	else {
		?><style type="text/css">
		#med3 { background-color: #fff; }
		#med3 td { border: 3px #DEBB22 solid; }
		#med2 td { border: 0; }
		</style><?php
		$nb_seq = mysqli_num_rows(mysqli_query($bdd,"SELECT seq_id FROM ".$prefix."_sequences WHERE seq_actif = 1"));
		$nb_docs = mysqli_num_rows(mysqli_query($bdd,"SELECT seq_id FROM ".$prefix."_seqdocs"));
		if($nb_seq==0) {
			echo '<h1>'.EDITC_DOC1.'</h1><h2>'.EDITC_DOC2.' <a href="edit.php?page=creation">'.SEQCREA.'</a>.</h2>';
		}
		else if($nb_docs==0) {
			echo '<h1>'.EDITC_DOC1.'</h1><h2>'.EDITC_DOC2.' <a href="edit.php?page=consult">'.EDITNAV1.'</a>.</h2>';
		}
		else {
			$glob_taille = 0;
			$docus = mysqli_query($bdd,"SELECT * FROM ".$prefix."_seqdocs ORDER BY docname ASC");
			foreach($docus as $docu) {
				$filename = 'seqfichiers/'.$prefix.'/'.$docu['docurl'];
				if (file_exists($filename)) {
					$taille = @number_format(filesize('seqfichiers/'.$prefix.'/'.$docu['docurl'])/1048,2);
					@$glob_taille += @$taille;
				}
			}
			echo '<h1>'.EDITC_DOC1.' ('.$nb_docs.' : '.$glob_taille.' kB)</h1>';
			include('db/proc/freq_stats_nivcolors.php');
			for($i=0;$i<count($tabDebniveau);$i++) {
				$seqs = mysqli_query($bdd,"SELECT seq.seq_id, seq_nom, niveau, date_crea, date_maj, seq_complete, seq_actif, progression FROM ".$prefix."_sequences seq INNER JOIN ".$prefix."_seqdocs sd ON sd.seq_id = seq.seq_id WHERE seq.niveau = '".$tabDebniveau[$i]."' AND seq.seq_actif = 1");
				$nb_seqs = mysqli_num_rows($seqs);
				$docs=1;
				if($nb_seqs>0) {
					echo '<h2>'.$tabNiveau[$i].'</h2>';
					$seqs = mysqli_query($bdd,"SELECT seq.seq_id, seq_nom, niveau, date_crea, date_maj, seq_complete, seq_actif, progression FROM ".$prefix."_sequences seq INNER JOIN ".$prefix."_seqdocs sd ON sd.seq_id = seq.seq_id WHERE niveau = '".$tabDebniveau[$i]."' AND seq_actif = 1 ORDER BY progression, seq_nom");
					include('./db/proc/edit_consult_listage.php');
				}
			}
			
			echo "<script language='javascript'>
				window.onmousedown = function (e) {
			    var el = e.target;
			    if (el.tagName.toLowerCase() == 'option' && el.parentNode.hasAttribute('multiple')) {
			        e.preventDefault();

			        if (el.hasAttribute('selected')) el.removeAttribute('selected');
			        else el.setAttribute('selected', '');

			        var select = el.parentNode.cloneNode(true);
			        el.parentNode.parentNode.replaceChild(select, el.parentNode);
			    }
			}
			</script>";
			echo ZIPDL;
			if (!extension_loaded('zip')) {
				echo ZIPNOEXT2;
			}
			else {
				$docus = mysqli_query($bdd,"SELECT * FROM ".$prefix."_seqdocs ORDER BY docname ASC");
				echo '<form method="POST" action="" name="zip"><select name="files[]" class="inptxt" id="savedocs" multiple size="'.(mysqli_num_rows($docus)+1).'">';
				foreach($docus as $docu) {
					$filename = 'seqfichiers/'.$prefix.'/'.$docu['docurl'];
					if (file_exists($filename)) {
						$taille = @number_format(filesize('seqfichiers/'.$prefix.'/'.$docu['docurl'])/1048,2);
						echo '<option value="'.$docu['docurl'].'" title="'.$docu['docname'].'" selected>';
						if($docu['docname']!='') { echo $docu['docname']; }
						else { echo $docu['docurl']; }
						echo ' - '.$taille.' kB</option>';	
					}				
				}
				echo '<select><br><input type="submit" value="'.DOWNLOAD.'" name="zipval" class="bouton boutseq"></form>';				
			}
		}			
		
	}
}
else {
	include('include/noaccess.php');
	echo '<br><a href="../index.php">'.ACCUEIL.'</a></p>';
}
	?>
