<?php
$bdd = mysqli_connect($server,$user,$pwd,$base);
echo '<p style="text-align:center;font-size:1.4em;padding-top:5px;">'.INSTALLSAVOIRS.'</p>'; flush(); ob_flush();
if (($handle = fopen("apd_savoirs.csv", "r")) !== FALSE) {
	while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
		$att0 = mysqli_real_escape_string($bdd,$data[0]);
		$att1 = mysqli_real_escape_string($bdd,$data[1]);
		$att2 = mysqli_real_escape_string($bdd,$data[2]);
		$att3 = mysqli_real_escape_string($bdd,$data[3]);
		$att4 = mysqli_real_escape_string($bdd,$data[4]);
		$att5 = mysqli_real_escape_string($bdd,$data[5]);
		mysqli_query($bdd,"INSERT INTO preidlog_savoirsmaj (s_id, nom_savoir, niveau, champs_id, notions, base) VALUES ('" . $att0 . "', '" . $att1 . "', '" . $att2 . "', '" . $att3 . "', '" . $att4 . "', '" . $att5 . "')");
	}
	fclose($handle);
}
// Intégration des éléments relatifs aux axes dans preidlog_savchamps
$ce01_s = 'Environnements informationnels et numériques';
$ce01 = mysqli_real_escape_string($bdd,$ce01_s);
$cp02_s = 'Processus d\'information et de documentation';
$cp02 = mysqli_real_escape_string($bdd,$cp02_s);
$cr03_s = 'Recul critique sur les médias, les TIC et l\'information';
$cr03 = mysqli_real_escape_string($bdd,$cr03_s);
$ct04_s = 'Responsabilité légale et éthique relative à l\'information';
$ct04 = mysqli_real_escape_string($bdd,$ct04_s);
mysqli_query($bdd,"INSERT INTO preidlog_savchamps (champs_id, champs_nom, bgcolor) VALUES ('CE01', '".$ce01."', '#CEF6CE')");
mysqli_query($bdd,"INSERT INTO preidlog_savchamps (champs_id, champs_nom, bgcolor) VALUES ('CP02', '".$cp02."', '#F5F6CE')");
mysqli_query($bdd,"INSERT INTO preidlog_savchamps (champs_id, champs_nom, bgcolor) VALUES ('CR03', '".$cr03."', '#CECEF6')");
mysqli_query($bdd,"INSERT INTO preidlog_savchamps (champs_id, champs_nom, bgcolor) VALUES ('CT04', '".$ct04."', '#F6CED8')");
$au01_s = 'Utiliser les médias et les informations de manière autonome';
$au01 = mysqli_real_escape_string($bdd,$au01_s);
$ex02_s = 'Exploiter l\'information de manière raisonnée';
$ex02 = mysqli_real_escape_string($bdd,$ex02_s);
$me03_s = 'Utiliser les médias de manière responsable';
$me03 = mysqli_real_escape_string($bdd,$me03_s);
$pr04_s = 'Produire, communiquer, partager des informations';
$pr04 = mysqli_real_escape_string($bdd,$pr04_s);
mysqli_query($bdd,"INSERT INTO preidlog_savchamps (champs_id, champs_nom, bgcolor) VALUES ('AU01', '".$au01."', '#CEF6CE')");
mysqli_query($bdd,"INSERT INTO preidlog_savchamps (champs_id, champs_nom, bgcolor) VALUES ('EX02', '".$ex02."', '#F5F6CE')");
mysqli_query($bdd,"INSERT INTO preidlog_savchamps (champs_id, champs_nom, bgcolor) VALUES ('ME03', '".$me03."', '#CECEF6')");
mysqli_query($bdd,"INSERT INTO preidlog_savchamps (champs_id, champs_nom, bgcolor) VALUES ('PR04', '".$pr04."', '#F6CED8')");

$tabDebniveau = array('6', '5', '4', '3', '2', '1', 't');
foreach($tabDebniveau as $divdeb) {
	// Intégration dans la table preidlog_savoirs* des savoirs pour le niveau
	$sql = mysqli_query($bdd,"SELECT * FROM preidlog_savoirsmaj WHERE niveau = '".$divdeb."e'");
	while($sql_info=mysqli_fetch_assoc($sql)) {
		$att0 = mysqli_real_escape_string($bdd,$sql_info['s_id']);
		$att1 = mysqli_real_escape_string($bdd,$sql_info['nom_savoir']);
		$att2 = mysqli_real_escape_string($bdd,$sql_info['niveau']);
		$att3 = mysqli_real_escape_string($bdd,$sql_info['champs_id']);
		$att4 = mysqli_real_escape_string($bdd,$sql_info['notions']);
		$att5 = mysqli_real_escape_string($bdd,$sql_info['base']);
		mysqli_query($bdd,"INSERT INTO preidlog_savoirs".$divdeb." (s".$divdeb."_id, nom_savoir, niveau, champs_id, notions, base) VALUES ('" . $att0 . "', '" . $att1 . "', '" . $att2 . "', '" . $att3 . "', '" . $att4 . "', '" . $att5 . "')");
	}
}
// Suppression des lignes de la table temporaire preidlog_savoirsmaj
mysqli_query($bdd,"DELETE FROM preidlog_savoirsmaj");	
?>