Completed
Push — master ( 8ce5a2...3d964c )
by Yannick
07:50
created
require/class.Accident.php 2 patches
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -26,20 +26,20 @@  discard block
 block discarded – undo
26 26
 	*
27 27
 	* @return Array Return Accidents data in array
28 28
 	*/
29
-	public function getAccidentData($limit = '',$type = '',$date = '') {
29
+	public function getAccidentData($limit = '', $type = '', $date = '') {
30 30
 		global $globalURL, $globalDBdriver;
31 31
 		$Image = new Image($this->db);
32 32
 		$Spotter = new Spotter($this->db);
33 33
 		$Translation = new Translation($this->db);
34
-		$date = filter_var($date,FILTER_SANITIZE_STRING);
34
+		$date = filter_var($date, FILTER_SANITIZE_STRING);
35 35
 		date_default_timezone_set('UTC');
36 36
 		$result = array();
37 37
 		$limit_query = '';
38 38
 		if ($limit != "")
39 39
 		{
40 40
 			$limit_array = explode(",", $limit);
41
-			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
42
-			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
41
+			$limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT);
42
+			$limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT);
43 43
 			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
44 44
 			{
45 45
 				$limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0];
@@ -48,20 +48,20 @@  discard block
 block discarded – undo
48 48
 
49 49
 		if ($type != '') {
50 50
 			if ($date != '') {
51
-				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) {
51
+				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $date)) {
52 52
 					$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date = :date GROUP BY registration) ORDER BY date DESC".$limit_query;
53 53
 				} else {
54 54
 					$date = $date.'%';
55 55
 					$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND to_char(date,'YYYY-MM-DD') LIKE :date GROUP BY registration) ORDER BY date DESC".$limit_query;
56 56
 				}
57
-				$query_values = array(':type' => $type,':date' => $date);
57
+				$query_values = array(':type' => $type, ':date' => $date);
58 58
 			} else {
59 59
 				$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;
60 60
 				$query_values = array(':type' => $type);
61 61
 			}
62 62
 		} else {
63 63
 			if ($date != '') {
64
-				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) {
64
+				if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $date)) {
65 65
 					$query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE date = :date GROUP BY registration) ORDER BY date DESC".$limit_query;
66 66
 				} else {
67 67
 					$date = $date.'%';
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		try {
78 78
 			$sth = $this->db->prepare($query);
79 79
 			$sth->execute($query_values);
80
-		} catch(PDOException $e) {
80
+		} catch (PDOException $e) {
81 81
 			return "error : ".$e->getMessage();
82 82
 		}
83 83
 		$i = 0;
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 			$data = array();
86 86
 			if ($row['registration'] != '') {
87 87
 				$image_array = $Image->getSpotterImage($row['registration']);
88
-				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']));
89
-				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
88
+				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']));
89
+				else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
90 90
 				$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
91 91
 				$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
92 92
 				if (!empty($aircraft_info)) {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 					$data['aircraft_name'] = $aircraft_info[0]['type'];
95 95
 					$data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer'];
96 96
 				} else {
97
-					$data = array_merge($data,array('aircraft_type' => 'NA'));
97
+					$data = array_merge($data, array('aircraft_type' => 'NA'));
98 98
 				}
99 99
 				$owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']);
100 100
 				if (!empty($owner_data)) {
@@ -102,18 +102,18 @@  discard block
 block discarded – undo
102 102
 					$data['aircraft_base'] = $owner_data['base'];
103 103
 					$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
104 104
 				}
105
-			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
105
+			} else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => ''));
106 106
 			if ($row['registration'] == '') $row['registration'] = 'NA';
107 107
 			if ($row['ident'] == '') $row['ident'] = 'NA';
108
-			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3));
108
+			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 3));
109 109
 			if (isset($identicao[0])) {
110
-				if (substr($row['ident'],0,2) == 'AF') {
111
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
112
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
113
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
114
-				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
110
+				if (substr($row['ident'], 0, 2) == 'AF') {
111
+					if (filter_var(substr($row['ident'], 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
112
+					else $icao = 'AFR'.ltrim(substr($row['ident'], 2), '0');
113
+				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'], 2), '0');
114
+				$data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name']));
115 115
 			} else $icao = $row['ident'];
116
-			$icao = $Translation->checkTranslation($icao,false);
116
+			$icao = $Translation->checkTranslation($icao, false);
117 117
 			//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
118 118
 			if ($row['airline_name'] != '' && !isset($data['airline_name'])) {
119 119
 				//echo 'Check airline info... for '.$row['airline_name'].' ';
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
 				if (!empty($airline_info)) {
123 123
 					//echo 'data found !'."\n";
124 124
 					//print_r($airline_info);
125
-					$data = array_merge($data,$airline_info);
125
+					$data = array_merge($data, $airline_info);
126 126
 				} 
127 127
 				//else echo 'No data...'."\n";
128 128
 			}
129
-			$data = array_merge($row,$data);
129
+			$data = array_merge($row, $data);
130 130
 			if ($data['ident'] == null) $data['ident'] = $icao;
131 131
 			if ($data['title'] == null) {
132 132
 				$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
 		if ($globalDebug) echo 'Import '.$file."\n";
152 152
 		$result = array();
153 153
 		if (file_exists($file)) {
154
-			if (($handle = fopen($file,'r')) !== FALSE) {
155
-				while (($data = fgetcsv($handle,2000,",")) !== FALSE) {
154
+			if (($handle = fopen($file, 'r')) !== FALSE) {
155
+				while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) {
156 156
 					if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') {
157
-						$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],'operator' => $data[13],'source' => 'website_fam');
157
+						$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], 'operator' => $data[13], 'source' => 'website_fam');
158 158
 					}
159 159
 				}
160 160
 				fclose($handle);
161 161
 			}
162
-			if (!empty($result)) $this->add($result,true);
162
+			if (!empty($result)) $this->add($result, true);
163 163
 			elseif ($globalDebug) echo 'Nothing to import';
164 164
 		}
165 165
 	}
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 		$all_md5_new = array();
173 173
 		if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) {
174 174
 			if ($this->check_accidents_nb() > 0) {
175
-				if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) {
176
-					while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) {
175
+				if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) {
176
+					while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) {
177 177
 						if (isset($data[1])) {
178 178
 							$year = $data[0];
179 179
 							$all_md5[$year] = $data[1];
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
 				}
184 184
 			}
185 185
 		}
186
-		$Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5');
186
+		$Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5', dirname(__FILE__).'/../install/tmp/cr-all.md5');
187 187
 		if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) {
188
-			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) {
189
-				while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) {
188
+			if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) {
189
+				while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) {
190 190
 					if (isset($data[1])) {
191 191
 						$year = $data[0];
192 192
 						$all_md5_new[$year] = $data[1];
@@ -195,16 +195,16 @@  discard block
 block discarded – undo
195 195
 				fclose($handle);
196 196
 			} elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
197 197
 		} elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
198
-		$result = $Common->arr_diff($all_md5_new,$all_md5);
198
+		$result = $Common->arr_diff($all_md5_new, $all_md5);
199 199
 		if (empty($result) && $globalDebug) echo 'Nothing to update';
200 200
 		foreach ($result as $file => $md5) {
201
-			$Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
201
+			$Common->download('http://data.flightairmap.fr/data/cr/'.$file, dirname(__FILE__).'/../install/tmp/'.$file);
202 202
 			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
203 203
 			elseif ($globalDebug) echo 'Download '.$file.' failed';
204 204
 		}
205 205
 	}
206 206
 
207
-	public function add($crash,$new = false) {
207
+	public function add($crash, $new = false) {
208 208
 		global $globalTransaction, $globalDebug;
209 209
 		require_once('class.Connection.php');
210 210
 		require_once('class.Image.php');
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 			$sthd->execute(array(':source' => $crash[0]['source']));
221 221
 		}
222 222
 		if ($globalTransaction) $Connection->db->beginTransaction();
223
-		$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,'operator' => null);
223
+		$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, 'operator' => null);
224 224
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
225 225
 		$sth_check = $Connection->db->prepare($query_check);
226 226
 		$query = 'INSERT INTO accidents (aircraft_manufacturer,aircraft_name,ident,registration,date,url,country,place,title,fatalities,latitude,longitude,type,airline_name,source) VALUES (:aircraft_manufacturer,:aircraft_name,:ident,:registration,:date,:url,:country,:place,:title,:fatalities,:latitude,:longitude,:type,:airline_name,:source)';
@@ -233,31 +233,31 @@  discard block
 block discarded – undo
233 233
 				$cr = array_map(function($value) {
234 234
 					return $value === "" ? NULL : $value;
235 235
 				}, $cr);
236
-				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) {
237
-					if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
238
-					$query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']);
236
+				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/', $cr['registration'])) {
237
+					if (strpos($cr['registration'], '-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
238
+					$query_check_values = array(':registration' => $cr['registration'], ':date' => date('Y-m-d', $cr['date']), ':type' => $cr['type'], ':source' => $cr['source']);
239 239
 					$sth_check->execute($query_check_values);
240 240
 					$result_check = $sth_check->fetch(PDO::FETCH_ASSOC);
241 241
 					if ($result_check['nb'] == 0) {
242
-						$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'],':airline_name' => $cr['operator']);
242
+						$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'], ':airline_name' => $cr['operator']);
243 243
 						$sth->execute($query_values);
244
-						if ($cr['date'] > time()-(30*86400)) {
244
+						if ($cr['date'] > time() - (30*86400)) {
245 245
 							if (empty($Image->getSpotterImage($cr['registration']))) {
246 246
 								//if ($globalDebug) echo 'Get image...'."\n";
247 247
 								$Image->addSpotterImage($cr['registration']);
248 248
 							}
249 249
 							// elseif ($globalDebug) echo 'Image already in DB'."\n";
250 250
 						}
251
-						$Spotter->setHighlightFlightByRegistration($cr['registration'],$cr['title'],date('Y-m-d',$cr['date']));
251
+						$Spotter->setHighlightFlightByRegistration($cr['registration'], $cr['title'], date('Y-m-d', $cr['date']));
252 252
 					}
253 253
 				}
254
-				if ($globalTransaction && $j % 1000 == 0) {
254
+				if ($globalTransaction && $j%1000 == 0) {
255 255
 					$Connection->db->commit();
256 256
 					$Connection->db->beginTransaction();
257 257
 				}
258 258
 			}
259 259
 			if ($globalTransaction) $Connection->db->commit();
260
-		} catch(PDOException $e) {
260
+		} catch (PDOException $e) {
261 261
 			if ($globalTransaction) $Connection->db->rollBack();
262 262
 			echo $e->getMessage();
263 263
 		}
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 			$Connection = new Connection();
272 272
 			$sth = $Connection->db->prepare($query);
273 273
 			$sth->execute();
274
-		} catch(PDOException $e) {
274
+		} catch (PDOException $e) {
275 275
 			return "error : ".$e->getMessage();
276 276
 		}
277 277
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 			$Connection = new Connection();
290 290
 			$sth = $Connection->db->prepare($query);
291 291
 			$sth->execute();
292
-		} catch(PDOException $e) {
292
+		} catch (PDOException $e) {
293 293
 			return "error : ".$e->getMessage();
294 294
 		}
295 295
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 			$Connection = new Connection();
305 305
 			$sth = $Connection->db->prepare($query);
306 306
 			$sth->execute();
307
-		} catch(PDOException $e) {
307
+		} catch (PDOException $e) {
308 308
 			return "error : ".$e->getMessage();
309 309
 		}
310 310
 	}
Please login to merge, or discard this patch.
Braces   +75 added lines, -27 removed lines patch added patch discarded remove patch
@@ -85,8 +85,11 @@  discard block
 block discarded – undo
85 85
 			$data = array();
86 86
 			if ($row['registration'] != '') {
87 87
 				$image_array = $Image->getSpotterImage($row['registration']);
88
-				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']));
89
-				else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
88
+				if (count($image_array) > 0) {
89
+					$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']));
90
+				} else {
91
+					$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
92
+				}
90 93
 				$aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']);
91 94
 				$aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type);
92 95
 				if (!empty($aircraft_info)) {
@@ -102,17 +105,30 @@  discard block
 block discarded – undo
102 105
 					$data['aircraft_base'] = $owner_data['base'];
103 106
 					$data['aircraft_date_first_reg'] = $owner_data['date_first_reg'];
104 107
 				}
105
-			} else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
106
-			if ($row['registration'] == '') $row['registration'] = 'NA';
107
-			if ($row['ident'] == '') $row['ident'] = 'NA';
108
+			} else {
109
+				$data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => ''));
110
+			}
111
+			if ($row['registration'] == '') {
112
+				$row['registration'] = 'NA';
113
+			}
114
+			if ($row['ident'] == '') {
115
+				$row['ident'] = 'NA';
116
+			}
108 117
 			$identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3));
109 118
 			if (isset($identicao[0])) {
110 119
 				if (substr($row['ident'],0,2) == 'AF') {
111
-					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident'];
112
-					else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
113
-				} else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
120
+					if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) {
121
+						$icao = $row['ident'];
122
+					} else {
123
+						$icao = 'AFR'.ltrim(substr($row['ident'],2),'0');
124
+					}
125
+				} else {
126
+					$icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0');
127
+				}
114 128
 				$data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name']));
115
-			} else $icao = $row['ident'];
129
+			} else {
130
+				$icao = $row['ident'];
131
+			}
116 132
 			$icao = $Translation->checkTranslation($icao,false);
117 133
 			//$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url']));
118 134
 			if ($row['airline_name'] != '' && !isset($data['airline_name'])) {
@@ -127,18 +143,23 @@  discard block
 block discarded – undo
127 143
 				//else echo 'No data...'."\n";
128 144
 			}
129 145
 			$data = array_merge($row,$data);
130
-			if ($data['ident'] == null) $data['ident'] = $icao;
146
+			if ($data['ident'] == null) {
147
+				$data['ident'] = $icao;
148
+			}
131 149
 			if ($data['title'] == null) {
132 150
 				$data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country'];
133
-			} else $data['message'] = strtolower($data['title']);
151
+			} else {
152
+				$data['message'] = strtolower($data['title']);
153
+			}
134 154
 			$result[] = $data;
135 155
 			$i++;
136 156
 		}
137 157
 		if (isset($result)) {
138 158
 			$result[0]['query_number_rows'] = $i;
139 159
 			return $result;
160
+		} else {
161
+			return array();
140 162
 		}
141
-		else return array();
142 163
 	}
143 164
 	
144 165
 	
@@ -148,7 +169,9 @@  discard block
 block discarded – undo
148 169
 	*/
149 170
 	public function import($file) {
150 171
 		global $globalTransaction, $globalDebug;
151
-		if ($globalDebug) echo 'Import '.$file."\n";
172
+		if ($globalDebug) {
173
+			echo 'Import '.$file."\n";
174
+		}
152 175
 		$result = array();
153 176
 		if (file_exists($file)) {
154 177
 			if (($handle = fopen($file,'r')) !== FALSE) {
@@ -159,8 +182,11 @@  discard block
 block discarded – undo
159 182
 				}
160 183
 				fclose($handle);
161 184
 			}
162
-			if (!empty($result)) $this->add($result,true);
163
-			elseif ($globalDebug) echo 'Nothing to import';
185
+			if (!empty($result)) {
186
+				$this->add($result,true);
187
+			} elseif ($globalDebug) {
188
+				echo 'Nothing to import';
189
+			}
164 190
 		}
165 191
 	}
166 192
 
@@ -193,14 +219,23 @@  discard block
 block discarded – undo
193 219
 					}
194 220
 				}
195 221
 				fclose($handle);
196
-			} elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
197
-		} elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
222
+			} elseif ($globalDebug) {
223
+				echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5';
224
+			}
225
+		} elseif ($globalDebug) {
226
+			echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.';
227
+		}
198 228
 		$result = $Common->arr_diff($all_md5_new,$all_md5);
199
-		if (empty($result) && $globalDebug) echo 'Nothing to update';
229
+		if (empty($result) && $globalDebug) {
230
+			echo 'Nothing to update';
231
+		}
200 232
 		foreach ($result as $file => $md5) {
201 233
 			$Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file);
202
-			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file);
203
-			elseif ($globalDebug) echo 'Download '.$file.' failed';
234
+			if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) {
235
+				$this->import(dirname(__FILE__).'/../install/tmp/'.$file);
236
+			} elseif ($globalDebug) {
237
+				echo 'Download '.$file.' failed';
238
+			}
204 239
 		}
205 240
 	}
206 241
 
@@ -213,13 +248,17 @@  discard block
 block discarded – undo
213 248
 		$Image = new Image();
214 249
 		$Spotter = new Spotter();
215 250
 
216
-		if (empty($crash)) return false;
251
+		if (empty($crash)) {
252
+			return false;
253
+		}
217 254
 		if (!$new) {
218 255
 			$query_delete = 'DELETE FROM accidents WHERE source = :source';
219 256
 			$sthd = $Connection->db->prepare($query_delete);
220 257
 			$sthd->execute(array(':source' => $crash[0]['source']));
221 258
 		}
222
-		if ($globalTransaction) $Connection->db->beginTransaction();
259
+		if ($globalTransaction) {
260
+			$Connection->db->beginTransaction();
261
+		}
223 262
 		$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,'operator' => null);
224 263
 		$query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source';
225 264
 		$sth_check = $Connection->db->prepare($query_check);
@@ -234,7 +273,9 @@  discard block
 block discarded – undo
234 273
 					return $value === "" ? NULL : $value;
235 274
 				}, $cr);
236 275
 				if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) {
237
-					if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
276
+					if (strpos($cr['registration'],'-') === FALSE) {
277
+						$cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']);
278
+					}
238 279
 					$query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']);
239 280
 					$sth_check->execute($query_check_values);
240 281
 					$result_check = $sth_check->fetch(PDO::FETCH_ASSOC);
@@ -256,9 +297,13 @@  discard block
 block discarded – undo
256 297
 					$Connection->db->beginTransaction();
257 298
 				}
258 299
 			}
259
-			if ($globalTransaction) $Connection->db->commit();
300
+			if ($globalTransaction) {
301
+				$Connection->db->commit();
302
+			}
260 303
 		} catch(PDOException $e) {
261
-			if ($globalTransaction) $Connection->db->rollBack();
304
+			if ($globalTransaction) {
305
+				$Connection->db->rollBack();
306
+			}
262 307
 			echo $e->getMessage();
263 308
 		}
264 309
 		$sth_check->closeCursor();
@@ -293,8 +338,11 @@  discard block
 block discarded – undo
293 338
 			return "error : ".$e->getMessage();
294 339
 		}
295 340
 		$row = $sth->fetch(PDO::FETCH_ASSOC);
296
-		if ($row['nb'] > 0) return false;
297
-		else return true;
341
+		if ($row['nb'] > 0) {
342
+			return false;
343
+		} else {
344
+			return true;
345
+		}
298 346
 	}
299 347
 
300 348
 	public static function insert_last_accidents_update() {
Please login to merge, or discard this patch.