<?php 
if($txt_type[$i]=='seq_nom') { 
	$edit_fiche .= '<hr class="hr2n"> <h4>'.$txt_typen[$i].' : <b>'.html_entity_decode(nl2br($seq_info[$txt_type[$i]])).'</b></h4>'; 
}
else if($txt_type[$i]=='niveau') { 
	$edit_fiche .= '<hr class="hr2n"> <h4>'.$txt_typen[$i].' : ';
	include('db/proc/freq_stats_nivcolors.php');
	$key = array_search($seq_info['niveau'], $tabDebniveau);
	$edit_fiche .= $tabNiveau[$key];
	$niv = $tabNiveau[$key];
	$edit_fiche .= '</h4>';
}
else if($txt_type[$i]=='progression') { 
	$edit_fiche .= '<hr class="hr2n"> <h4>'.$txt_typen[$i].' : ';
	if($seq_info['progression']!='1000') { $edit_fiche .= $seq_info['progression']; }
	$edit_fiche .= '</h4>';
	$liste_progress = mysqli_query($bdd,"SELECT progression, seq_nom, seq_id FROM ".$prefix."_sequences WHERE niveau = '".$seq_info['niveau']."' AND progression <> '1000' ORDER BY progression");
	$liste_nb = mysqli_num_rows($liste_progress);
	if($liste_nb>0) {
		$edit_fiche .= '<div id=\'progress\'>'.EDIT_NIV.'<br>';
		while($liste = mysqli_fetch_assoc($liste_progress)) {
			$edit_fiche .= $liste['progression'].'. <a href="'.$_SESSION['url_base'].'edit.php?page=consult&seq_id='.$liste['seq_id'].'">'.$liste['seq_nom'].'</a><br>';
		}
		$edit_fiche .= '</div>';
	}
}
else if($txt_type[$i]=='date_crea'||$txt_type[$i]=='date_maj') {
	$edit_fiche .= '<hr class="hr2n"> <h4>'.$txt_typen[$i].' : ';
	$edit_fiche .= substr($seq_info[$txt_type[$i]],8,2).'/'.substr($seq_info[$txt_type[$i]],5,2).'/'.substr($seq_info[$txt_type[$i]],0,4);
	$edit_fiche .= '</h4>';
} 
else if($txt_type[$i]=='SAVOIRS') {
	if (
	    $seq_info['niveau'] != 'a' &&
	    (str_starts_with($seq_info['niveau'], '1') ||
	     str_starts_with($seq_info['niveau'], '2') ||
	     str_starts_with($seq_info['niveau'], '3') ||
	     str_starts_with($seq_info['niveau'], '4') ||
	     str_starts_with($seq_info['niveau'], '5') ||
	     str_starts_with($seq_info['niveau'], '6') ||
	     str_starts_with($seq_info['niveau'], 't'))
	) {
		$niveau = $seq_info['niveau'];
		$seqsav_select = 
		"SELECT seqsav.s_id, sav.nom_savoir savoir, SUBSTR(seqsav.s_id,-3) sidsub FROM ".$prefix."_seqsav seqsav 
		INNER JOIN ".$prefix."_savoirs".$niveau." sav
		ON seqsav.s_id = sav.s".$niveau."_id
		WHERE seqsav.seq_id = '".$seq_info['seq_id']."' AND seqsav.s_id LIKE 'APD%'
		ORDER BY seqsav.s_id";
		$seqsav = mysqli_query($bdd,$seqsav_select);
		$seqsav_nb = mysqli_num_rows($seqsav);
		if($seqsav_nb>0) {
			$edit_fiche .= '<hr class="hr2n"> <h4>'.EDIT_SAVID1.'</h4>';
			$edit_fiche .= '<ul class="consult">';
			while($liste_sav = mysqli_fetch_assoc($seqsav)) {
				$edit_fiche .= '<li> '.$liste_sav['sidsub'].' : '.$liste_sav['savoir'].'</li>';
			}
			$edit_fiche .= '</ul>';
		}
	}
	if (
	    $seq_info['niveau'] != 'a' &&
	    (str_starts_with($seq_info['niveau'], '1') ||
	     str_starts_with($seq_info['niveau'], '2') ||
	     str_starts_with($seq_info['niveau'], '3') ||
	     str_starts_with($seq_info['niveau'], '4') ||
	     str_starts_with($seq_info['niveau'], '5') ||
	     str_starts_with($seq_info['niveau'], '6') ||
	     str_starts_with($seq_info['niveau'], 't'))
	) {
		$seqemi_select = 
		"SELECT seqsav.s_id, sav.nom_savoir savoir, SUBSTR(seqsav.s_id,-3) sidsub FROM ".$prefix."_seqsav seqsav 
		INNER JOIN ".$prefix."_savoirs".$seq_info['niveau']." sav
		ON seqsav.s_id = sav.s".$seq_info['niveau']."_id
		WHERE seqsav.seq_id = '".$seq_info['seq_id']."' AND seqsav.s_id LIKE 'EMI%'
		ORDER BY seqsav.s_id";
		$seqemi = mysqli_query($bdd,$seqemi_select);
		$seqemi_nb = mysqli_num_rows($seqemi);
		if($seqemi_nb>0) {
			$edit_fiche .= '<hr class="hr2n"> <h4>'.EDIT_SAVID2.'</h4>';
			$edit_fiche .= '<ul class="consult">';
			while($liste_emi = mysqli_fetch_assoc($seqemi)) {
				$edit_fiche .= '<li> '.$liste_emi['sidsub'].' : '.$liste_emi['savoir'].'</li>';
			}
			$edit_fiche .= '</ul>';
		}
	}
	$ccr = mysqli_query($bdd,"SELECT valeur FROM ".$prefix."_parametres WHERE param_nom = 'eval_perso'");
	$ccr_info = mysqli_fetch_assoc($ccr);
	if($ccr_info['valeur']=="niveau") {
		if (
		    $seq_info['niveau'] != 'a' &&
		    (str_starts_with($seq_info['niveau'], '1') ||
		     str_starts_with($seq_info['niveau'], '2') ||
		     str_starts_with($seq_info['niveau'], '3') ||
		     str_starts_with($seq_info['niveau'], '4') ||
		     str_starts_with($seq_info['niveau'], '5') ||
		     str_starts_with($seq_info['niveau'], '6') ||
		     str_starts_with($seq_info['niveau'], 't'))
		) {
			$seqper_select = 
			"SELECT seqsav.s_id, sav.nom_savoir savoir, SUBSTR(seqsav.s_id,4,1) niv, SUBSTR(seqsav.s_id,-3) sidsub FROM ".$prefix."_seqsav seqsav 
			INNER JOIN ".$prefix."_savoirs".$seq_info['niveau']." sav
			ON seqsav.s_id = sav.s".$seq_info['niveau']."_id
			WHERE seqsav.seq_id = '".$seq_info['seq_id']."' AND seqsav.s_id LIKE 'PER%'
			ORDER BY seqsav.s_id";
			$seqper = mysqli_query($bdd,$seqper_select);
			$seqper_nb = mysqli_num_rows($seqper);
			if($seqper_nb>0) {
				$edit_fiche .= '<hr class="hr2n"> <h4>'.EDIT_SAVID3.'</h4>';
				$edit_fiche .= '<ul class="consult">';
				while($liste_per = mysqli_fetch_assoc($seqper)) {
					$edit_fiche .= '<li> '.$liste_per['niv'].'e - '.$liste_per['sidsub'].' : '.$liste_per['savoir'].'</li>';
				}
				$edit_fiche .= '</ul>';
			}
		}
	}
	else if($ccr_info['valeur']=="global") {
		$tabDebniveau = array('6', '5', '4', '3', '2', '1', 't');
		foreach($tabDebniveau as $divdeb) {
			$seqper_select = 
			"SELECT seqsav.s_id, sav.nom_savoir savoir, SUBSTR(seqsav.s_id,4,1) niv, SUBSTR(seqsav.s_id,-3) sidsub FROM ".$prefix."_seqsav seqsav 
			INNER JOIN ".$prefix."_savoirs".$divdeb." sav
			ON seqsav.s_id = sav.s".$divdeb."_id
			WHERE seqsav.seq_id = '".$seq_info['seq_id']."' AND seqsav.s_id LIKE 'PER%'
			ORDER BY seqsav.s_id";
			$seqper = mysqli_query($bdd,$seqper_select);
			$seqper_nb = mysqli_num_rows($seqper);
			if($seqper_nb>0) {
				$edit_fiche .= '<hr class="hr2n"> <h4>'.EDIT_SAVID3.'</h4>';
				$edit_fiche .= '<ul class="consult">';
				foreach($seqper as $liste_per) {
					$edit_fiche .= '<li> '.$liste_per['niv'].'e - '.$liste_per['sidsub'].' : '.$liste_per['savoir'].'</li>';
				}
				$edit_fiche .= '</ul>';
			}
		}
	}
}
else if($txt_type[$i]=='documents') {
	$seqdocs = mysqli_query($bdd,"SELECT * FROM ".$prefix."_seqdocs WHERE seq_id = '".$seq_info['seq_id']."' ORDER BY docurl ASC");
	$seqdocs_nb = mysqli_num_rows($seqdocs);
	if($seqdocs_nb>0) {
		$edit_fiche .= '<br><hr class="hr1n"> '.EDIT_DOCS;
		$edit_fiche .= '<hr class="hr2n">';
		$edit_fiche .= '<ul class="consult">';
		while($liste_docs = mysqli_fetch_assoc($seqdocs)) {
			$edit_fiche .= '<li style="list-style-type:none;">';
			if(substr($liste_docs['docname'],-4)==".pdf") {
				$edit_fiche .= '<i class="fa-regular fa-file-pdf"></i> ';
			}
			else if(substr($liste_docs['docname'],-4)==".png"||substr($liste_docs['docname'],-4)==".gif"||substr($liste_docs['docname'],-4)==".jpg") {
				$edit_fiche .= '<i class="fa-regular fa-file-image"></i> ';
			}
			else {
				$edit_fiche .= '<i class="fa-regular fa-file"></i> ';
			}
			$edit_fiche .= '<a href="'.$_SESSION['url_base'].'seqfichiers/'.$prefix.'/'.$liste_docs['docurl'].'" download="';
			if($liste_docs['docname']=="") {
				$edit_fiche .= $liste_docs['docurl']; }
			else { $edit_fiche .= $liste_docs['docname']; }
			$edit_fiche .='">';
			if($liste_docs['docname']=="") {
				$edit_fiche .= $liste_docs['docurl']; }
			else { $edit_fiche .= $liste_docs['docname']; }
			$edit_fiche .= '</a> - ';
			$taille = @number_format(filesize('seqfichiers/'.$prefix.'/'.$liste_docs['docurl'])/1048,2);
			$edit_fiche .= $taille;
			$edit_fiche .= ' kB';
			$edit_fiche .= '</li>';
		}
		$edit_fiche .= '</ul>';
	}
}
else if($txt_type[$i]=='auteur') {
	$edit_fiche .= '<hr class="hr2n"> <h4>'.$txt_typen[$i].' : '.html_entity_decode(nl2br($seq_info['auteur'])).'</h4>';
}
else if($txt_type[$i]=='notions') { 
	$nots = mysqli_query($bdd,"SELECT * FROM ".$prefix."_seqnot seqn INNER JOIN ".$prefix."_savnotions savn ON seqn.notion_id = savn.notion_id WHERE seq_id = '".$seq_info['seq_id']."' ORDER BY savn.notion_nom ASC");
	if(mysqli_num_rows($nots)>0) {
		$notsseq = [];
		foreach($nots as $not) {
			$notion_fr = $not['notion_nom'];
    		$notsseq[] = isset($translations[$notion_fr]) ? $translations[$notion_fr] : $notion_fr;			
		}
		$edit_fiche .= '<br><hr class="hr2n"> '.EDIT_NOTS1;
		$edit_fiche .= '<div class="consult"><i>'.EDIT_NOTS2.'</i><ul>';
		for($j=0;$j<=14;$j++) {
			if(isset($notsseq[$j])) {
				$edit_fiche .= '<li>'.$notsseq[$j].' <a href="https://wikinotions.apden.org/notions.php?p=consult&nom='.$notsseq[$j].'" target="_blank"><i class="fa-solid fa-eye"></i></a></li>';
			}
		}
		$edit_fiche .= '</ul></div>';
	}
	
	if($seq_info[$txt_type[$i]]!="") {
		if(mysqli_num_rows($nots)==0) {
			$edit_fiche .= '<br><hr class="hr1n"> '.EDIT_NOTS1;
			$edit_fiche .= '<hr class="hr2n">';
		}
		$edit_fiche .= '<div class="consult"><br><i>'.EDIT_NOTS3.'</i> '.html_entity_decode(nl2br($seq_info[$txt_type[$i]])).'</div>';
	}	
}
else if($txt_type[$i]=='url') {
	$edit_fiche .= '<hr class="hr2n"> <h4>'.$txt_typen[$i].' : <a href="'.$seq_info['url'].'" target="_blank">'.$seq_info['url'].'</a></h4>';
}
else if($txt_type[$i]=='licence') {
	$edit_fiche .= '<hr class="hr2n"> <h4>'.$txt_typen[$i].' : ';
	if($seq_info['licence']=='CC BY 3.0 FR') {
		$edit_fiche .= '<a href="http://creativecommons.org/licenses/by/3.0/fr/">CC BY 3.0 FR</a>';
	}
	else if($seq_info['licence']=='CC BY-ND 3.0 FR') {
		$edit_fiche .= '<a href="http://creativecommons.org/licenses/by-nd/3.0/fr/">CC BY-ND 3.0 FR</a>';
	}
	else if($seq_info['licence']=='CC BY-NC-ND 3.0 FR') {
		$edit_fiche .= '<a href="http://creativecommons.org/licenses/by-nc-nd/3.0/fr/">CC BY-NC-ND 3.0 FR</a>';
	}
	else if($seq_info['licence']=='CC BY-NC 3.0 FR') {
		$edit_fiche .= '<a href="http://creativecommons.org/licenses/by-nc/3.0/fr/">CC BY-NC 3.0 FR</a>';
	}
	else if($seq_info['licence']=='CC BY-NC-SA 3.0 FR') {
		$edit_fiche .= '<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/fr/">CC BY-NC-SA 3.0 FR</a>';
	}
	else if($seq_info['licence']=='CC BY-SA 3.0 FR') {
		$edit_fiche .= '<a href="http://creativecommons.org/licenses/by-sa/3.0/fr/">CC BY-SA 3.0 FR</a>';
	}
	else if($seq_info['licence']=='Domaine public') {
		$edit_fiche .= EDIT_DROITS1;
	}
	else {
		$edit_fiche .= EDIT_DROITS2;
	}
	$edit_fiche .= '</h4><div class="consult"><a class="preins" href="https://creativecommons.org/licenses/" target="_blank"><i>'.EDIT_DROITS3.'</i></a></div><br>';
}
else { $edit_fiche .= '<div class="consult">'.html_entity_decode(nl2br($seq_info[$txt_type[$i]])).'</div>'; }
?>