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.
		
		
		
		
		
			
		
			
				
					
					
						
							74 lines
						
					
					
						
							2.0 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							74 lines
						
					
					
						
							2.0 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 = 6; | |
| 
 | |
| $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)); | |
|   if(isset($row[1])) { | |
|     $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, '".str_replace('\'','’',$title)."', '".serialize(array_slice($answers,0,3))."', ".$responses[$id].", ".$points[$index].")"; | |
|       @mysqli_query($conn,$query) or die($id ." - " . mysqli_error($conn)); | |
|       //echo $query."<br>"; | |
|  | |
|     } | |
|     $id = substr($row[0], 1, 4); | |
|     $title = $row[1]; | |
|     $answers = []; | |
|   } else { | |
|     if(isset($row[1])) { | |
|       $answers[$row[0]] = str_replace('\'','’',$row[1]); | |
|     } | |
|   } | |
| } | |
| 
 | |
| if(count($answers)) { | |
|     $query="INSERT questions VALUES($id, '".str_replace('\'','’',$title)."', '".serialize(array_slice($answers,0,3))."', ".$responses[$id].", ".$points[$index].")"; | |
|     @mysqli_query($conn,$query) or die($id ." - " . mysqli_error($conn)); | |
|     //echo $query."<br>"; | |
| }; | |
| 
 | |
| 
 | |
| fclose($myfile); | |
| 
 | |
| ?>
 |