| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | require_once(dirname(__FILE__).'/class.Connection.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | require_once(dirname(__FILE__).'/class.Spotter.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | require_once(dirname(__FILE__).'/class.Image.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | require_once(dirname(__FILE__).'/class.Translation.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class Accident { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 	public $db; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	public function __construct($dbc = null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		$Connection = new Connection($dbc); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 		$this->db = $Connection->db(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	public function get() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 		$query = 'SELECT DISTINCT registration FROM accidents ORDER BY date DESC'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		$sth = $this->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		$sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		$result = $sth->fetchAll(PDO::FETCH_ASSOC); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	* Get Latest Accidents data from DB | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	* @return Array Return Accidents data in array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  | 	*/ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 	public function getLatestAccidentData($limit = '',$type = '') { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 		global $globalURL, $globalDBdriver; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 		$Image = new Image($this->db); | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 		$Spotter = new Spotter($this->db); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 		$Translation = new Translation($this->db); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 		date_default_timezone_set('UTC'); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 		$result = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 		$limit_query = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 		if ($limit != "") | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 		{ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 			$limit_array = explode(",", $limit); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0) | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 			{ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  | 		if ($type != '') { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 			$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type GROUP BY registration) ORDER BY date DESC".$limit_query; | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 			$query_values = array(':type' => $type); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 		} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 			//$query = "SELECT * FROM accidents GROUP BY registration ORDER BY date DESC".$limit_query; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 			$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents GROUP BY registration) ORDER BY date DESC".$limit_query; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 			$query_values = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 		try { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  | 			$sth = $this->db->prepare($query); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 			$sth->execute($query_values); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  | 		} catch(PDOException $e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  | 			return "error : ".$e->getMessage(); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 		$i = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  | 		while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  | 			$data = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  | 			if ($row['registration'] != '') { | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  | 				$image_array = $Image->getSpotterImage($row['registration']); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  | 				if (count($image_array) > 0) $data = array_merge($data,array('image' => $image_array[0]['image'],'image_thumbnail' => $image_array[0]['image_thumbnail'],'image_copyright' => $image_array[0]['image_copyright'],'image_source' => $image_array[0]['image_source'],'image_source_website' => $image_array[0]['image_source_website'])); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  | 				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  | 				$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  | 				$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  | 				if (!empty($aircraft_info)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  | 					$data['aircraft_type'] = $aircraft_info[0]['icao']; | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  | 					$data['aircraft_name'] = $aircraft_info[0]['type']; | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  | 					$data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer']; | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | 				} else { | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 					$data = array_merge($data,array('aircraft_type' => 'NA')); | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | 				$owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | 				if (!empty($owner_data)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 					$data['aircraft_owner'] = $owner_data['owner']; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 					$data['aircraft_base'] = $owner_data['base']; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  | 					$data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 			if ($row['registration'] == '') $row['registration'] = 'NA'; | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 			if ($row['ident'] == '') $row['ident'] = 'NA'; | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2)); | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 			if (isset($identicao[0])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 				if (substr($row['ident'],0,2) == 'AF') { | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  | 					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  | 					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  | 				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | 			} else $icao = $row['ident']; | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 			$icao = $Translation->checkTranslation($icao,false); | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 			//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  | 			$data = array_merge($row,$data); | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  | 			if ($data['ident'] == null) $data['ident'] = $icao; | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 			if ($data['title'] == null) { | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  | 				$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  | 			} else $data['message'] = strtolower($data['title']); | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  | 			$result[] = $data; | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  | 			$i++; | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 		if (isset($result)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | 			$result[0]['query_number_rows'] = $i; | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  | 			return $result; | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  | 		else return array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	/* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	* Import csv accidents file into the DB | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	* @param String $file filename of the file to import | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	*/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	public function import($file) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		global $globalTransaction, $globalDebug; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 		if ($globalDebug) echo 'Import '.$file."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		$result = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		if (file_exists($file)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 			if (($handle = fopen($file,'r')) !== FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 				while (($data = fgetcsv($handle,2000,",")) !== FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 					if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 						$result[] = array('registration' => $data[0],'date' => strtotime($data[1]),'url' => $data[2],'country' => $data[3],'place' => $data[4],'title' => $data[5],'fatalities' => $data[6],'latitude' => $data[7],'longitude' => $data[8],'type' => $data[9],'ident' => $data[10],'aircraft_manufacturer' => $data[11],'aircraft_name' => $data[12],'source' => 'website_fam'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 				fclose($handle); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 			if (!empty($result)) $this->add($result,true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 	public function download_update() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 		require_once('class.Common.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		$Common = new Common(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 		$all_md5 = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		$all_md5_new = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 		if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 			if ($this->check_accidents_nb() > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 				if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 					while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 						if (isset($data[1])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 							$year = $data[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 							$all_md5[$year] = $data[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 						} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 					fclose($handle); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 		$Common->download('https://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 		if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 				while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 					if (isset($data[1])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 						$year = $data[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 						$all_md5_new[$year] = $data[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 				fclose($handle); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 		//print_r($all_md5_new); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 		//print_r($all_md5); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		$result = $Common->arr_diff($all_md5_new,$all_md5); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 		//print_r($result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 		foreach ($result as $file => $md5) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 			$Common->download('https://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 	public function add($crash,$new = false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 		global $globalTransaction, $globalDebug; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 		require_once('class.Connection.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 		require_once('class.Image.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 		$Connection = new Connection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 		$Image = new Image(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 		if (empty($crash)) return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 		if (!$new) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 			$query_delete = 'DELETE FROM accidents WHERE source = :source'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 			$sthd = $Connection->db->prepare($query_delete); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 			$sthd->execute(array(':source' => $crash[0]['source'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 		if ($globalTransaction) $Connection->db->beginTransaction(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 		$initial_array = array('ident' => null,'type' => 'accident','url' => null,'registration' => null, 'date' => null, 'place' => null,'country' => null, 'latitude' => null, 'longitude' => null, 'fatalities' => null, 'title' => '','source' => '','aircraft_manufacturer' => null,'aircraft_name' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 		$sth_check = $Connection->db->prepare($query_check); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 		$query = 'INSERT INTO accidents (aircraft_manufacturer,aircraft_name,ident,registration,date,url,country,place,title,fatalities,latitude,longitude,type,source) VALUES (:aircraft_manufacturer,:aircraft_name,:ident,:registration,:date,:url,:country,:place,:title,:fatalities,:latitude,:longitude,:type,:source)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 		$sth = $Connection->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 		$j = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 			foreach ($crash as $cr) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 				//print_r($cr); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 				$cr = $cr + $initial_array; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 				$cr = array_map(function($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 					return $value === "" ? NULL : $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 				}, $cr); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 					$query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 					$sth_check->execute($query_check_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 					$result_check = $sth_check->fetch(PDO::FETCH_ASSOC); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 					if ($result_check['nb'] == 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 						$query_values = array(':registration' => trim($cr['registration']),':date' => date('Y-m-d',$cr['date']),':url' => $cr['url'],':country' => $cr['country'],':place' => $cr['place'],':title' => $cr['title'],':fatalities' => $cr['fatalities'],':latitude' => $cr['latitude'],':longitude' => $cr['longitude'],':type' => $cr['type'],':source' => $cr['source'],':ident' => $cr['ident'],':aircraft_manufacturer' => $cr['aircraft_manufacturer'],':aircraft_name' => $cr['aircraft_name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 						$sth->execute($query_values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 						if ($cr['date'] > time()-(30*86400)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 							if (empty($Image->getSpotterImage($cr['registration']))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 								//if ($globalDebug) echo 'Get image...'."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 								$Image->addSpotterImage($cr['registration']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 							} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 							// elseif ($globalDebug) echo 'Image already in DB'."\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 						} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 				if ($globalTransaction && $j % 90 == 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 					$Connection->db->commit(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 					$Connection->db->beginTransaction(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 			if ($globalTransaction) $Connection->db->commit(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 		} catch(PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 			if ($globalTransaction) $Connection->db->rollBack(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 			echo $e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 		$sth_check->closeCursor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 	public static function check_accidents_nb() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 		global $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 			$query = "SELECT COUNT(*) as nb FROM accidents"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 			$Connection = new Connection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 			$sth = $Connection->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 			$sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | 		} catch(PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 			return "error : ".$e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | 		$row = $sth->fetch(PDO::FETCH_ASSOC); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  | 		return $row['nb']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 	public static function check_last_accidents_update() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 		global $globalDBdriver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 		if ($globalDBdriver == 'mysql') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 			$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_accident_db' AND value > DATE_SUB(NOW(), INTERVAL 1 DAY)"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 			$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_accident_db' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '1 DAYS'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 			$Connection = new Connection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 			$sth = $Connection->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 			$sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 		} catch(PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 			return "error : ".$e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 		$row = $sth->fetch(PDO::FETCH_ASSOC); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 		if ($row['nb'] > 0) return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 		else return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 	public static function insert_last_accidents_update() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 		$query = "DELETE FROM config WHERE name = 'last_update_accident_db'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 		    INSERT INTO config (name,value) VALUES ('last_update_accident_db',NOW());"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 			$Connection = new Connection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 			$sth = $Connection->db->prepare($query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  | 			$sth->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | 		} catch(PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 			return "error : ".$e->getMessage(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 276 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 277 |  |  | ?> | 
            
                        
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.