You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

64 lines
1.5 KiB

<?php
$DATAhst="localhost";
$DATAusr="root";
$DATApwd="root";
$DATAdtb="vds";
$file=array();
$points=array();
$file[] = "1_NormativaELegislazione"; $points[] = 3;
$file[] = "2_Aerodinamica"; $points[] = 3;
$file[] = "3_ProntoSoccorso"; $points[] = 2;
$file[] = "4_FisiopatologiaDelVolo"; $points[] = 2;
$file[] = "5_MeteorologiaEAerologia"; $points[] = 4;
$file[] = "6_Strumentazione"; $points[] = 2;
$file[] = "7_TecnicheDiPilotaggio"; $points[] = 4;
$file[] = "8_Materiali"; $points[] = 2;
$file[] = "9_SicurezzaDelVolo"; $points[] = 4;
$index = 8;
$conn=@mysqli_connect($DATAhst, $DATAusr, $DATApwd, $DATAdtb)or die("CONNECTION ERROR");
mysqli_set_charset($conn, "utf8");
$myfile = fopen("data/".$file[$index]."RES", "r") or die("Unable to open file!");
$responses=array();
while(!feof($myfile)) {
$row = explode("|",fgets($myfile));
$responses[$row[0]] = $row[1];
}
fclose($myfile);
$myfile = fopen("data/".$file[$index], "r") or die("Unable to open file!");
$answers = array();
$query="DELETE FROM questions";
mysqli_query($conn,$query);
while(!feof($myfile)) {
$row = explode("|",fgets($myfile));
if(substr($row[0], 0, 1) == "#") {
if(count($answers)) {
$query="INSERT questions VALUES($id, '$title', '".serialize($answers)."', ".$responses[$id].", ".$points[$index].")";
mysqli_query($conn,$query);
}
$id = substr($row[0], 1, 4);
$title = $row[1];
$answers = [];
} else {
$answers[$row[0]] = $row[1];
}
}
fclose($myfile);
?>