<?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">
		#med1 { background-color: #fff; }
		#med1 td { border: 3px #DEBB22 solid; }
		</style><?php
		if(!isset($_GET['seq_id'])) {
			$docs=0;
			$nb_seq = mysqli_num_rows(mysqli_query($bdd,"SELECT seq_id FROM ".$prefix."_sequences WHERE seq_actif = 1"));
			if($nb_seq==0) {
				echo '<h1>'.SEQUT.'</h1><h2>'.SEQNO.' <a href="edit.php?page=creation">'.SEQCREA.'</a>.</h2>';
			}
		
			else {
				echo '<h1>'.SEQUT.'</h1>';
				include('db/proc/etab_config_check.php');				
				$autres = '';
				for($i=0;$i<count($tabDebniveau);$i++) {
					$seqs = mysqli_query($bdd,"SELECT seq_id, seq_nom, niveau, date_crea, date_maj, seq_complete, seq_actif, progression FROM ".$prefix."_sequences WHERE niveau = '".$tabDebniveau[$i]."' AND seq_actif = 1");
					$nb_seqs = mysqli_num_rows($seqs);
					if($nb_seqs>0) {
						echo '<h2>'.$tabNiveau[$i].'</h2>';
						$seqs = mysqli_query($bdd,"SELECT seq_id, seq_nom, niveau, date_crea, date_maj, seq_complete, seq_actif, progression FROM ".$prefix."_sequences WHERE niveau = '".$tabDebniveau[$i]."' AND seq_actif = 1 ORDER BY progression, seq_nom");
						include('./db/proc/edit_consult_listage.php');
					}
					$autres .= " niveau <> '".$tabDebniveau[$i]."' ";
					if(($i+1)<count($tabDebniveau)) {
						$autres .= " AND ";
					}
				}
				$seqs = mysqli_query($bdd,"SELECT seq_id, seq_nom, niveau, date_crea, date_maj, seq_complete, seq_actif, progression FROM ".$prefix."_sequences WHERE ".$autres."");
				$nb_seqs = mysqli_num_rows($seqs);
				if($nb_seqs>0) {
					echo '<h2>'.EDITC_CON1.'</h2>';
					$seqs = mysqli_query($bdd,"SELECT seq_id, seq_nom, niveau, date_crea, date_maj, seq_complete, seq_actif, progression FROM ".$prefix."_sequences WHERE ".$autres." AND seq_actif = 1 ORDER BY progression, seq_nom");
					include('./db/proc/edit_consult_listage.php');
				}
			}
			$nb_seq_arch = mysqli_num_rows(mysqli_query($bdd,"SELECT * FROM ".$prefix."_sequences WHERE seq_actif = 0"));
			if($nb_seq_arch>0) {
				echo '<h1>'.EDITC_CON2.'</h1>';
				for($i=0;$i<count($tabDebniveau);$i++) {
					$seqs = mysqli_query($bdd,"SELECT seq_id, seq_nom, niveau, date_crea, date_maj, seq_complete, seq_actif, progression FROM ".$prefix."_sequences WHERE niveau = '".$tabDebniveau[$i]."' AND seq_actif = 0");
					$nb_seqs = mysqli_num_rows($seqs);
					if($nb_seqs>0) {
						echo '<h2>'.$tabNiveau[$i].'</h2>';
						include('./db/proc/edit_consult_listage.php');
					}
				}
			}
		}
		else {
			if(isset($_GET['modif'])) {
				include('./db/proc/edit_consult_modif.php');
			}
			else {
				include('./db/proc/edit_consult_fiche.php');
			}
		}
	}
}
else {
	include('include/noaccess.php');
	echo '<br><a href="../index.php">'.ACCUEIL.'</a></p>';
}
	?>
