@@ -113,8 +113,11 @@ discard block |
||
113 | 113 | $data = array(); |
114 | 114 | if ($row['registration'] != '') { |
115 | 115 | $image_array = $Image->getSpotterImage($row['registration']); |
116 | - 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'])); |
|
117 | - else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
116 | + if (count($image_array) > 0) { |
|
117 | + $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'])); |
|
118 | + } else { |
|
119 | + $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
120 | + } |
|
118 | 121 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
119 | 122 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
120 | 123 | if (!empty($aircraft_info)) { |
@@ -130,17 +133,30 @@ discard block |
||
130 | 133 | $data['aircraft_base'] = $owner_data['base']; |
131 | 134 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
132 | 135 | } |
133 | - } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
134 | - if ($row['registration'] == '') $row['registration'] = 'NA'; |
|
135 | - if ($row['ident'] == '') $row['ident'] = 'NA'; |
|
136 | + } else { |
|
137 | + $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
138 | + } |
|
139 | + if ($row['registration'] == '') { |
|
140 | + $row['registration'] = 'NA'; |
|
141 | + } |
|
142 | + if ($row['ident'] == '') { |
|
143 | + $row['ident'] = 'NA'; |
|
144 | + } |
|
136 | 145 | $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3)); |
137 | 146 | if (isset($identicao[0])) { |
138 | 147 | if (substr($row['ident'],0,2) == 'AF') { |
139 | - if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
140 | - else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
141 | - } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
148 | + if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) { |
|
149 | + $icao = $row['ident']; |
|
150 | + } else { |
|
151 | + $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
152 | + } |
|
153 | + } else { |
|
154 | + $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
155 | + } |
|
142 | 156 | $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
143 | - } else $icao = $row['ident']; |
|
157 | + } else { |
|
158 | + $icao = $row['ident']; |
|
159 | + } |
|
144 | 160 | $icao = $Translation->checkTranslation($icao,false); |
145 | 161 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
146 | 162 | if ($row['airline_name'] != '' && !isset($data['airline_name'])) { |
@@ -155,10 +171,14 @@ discard block |
||
155 | 171 | //else echo 'No data...'."\n"; |
156 | 172 | } |
157 | 173 | $data = array_merge($row,$data); |
158 | - if ($data['ident'] == null) $data['ident'] = $icao; |
|
174 | + if ($data['ident'] == null) { |
|
175 | + $data['ident'] = $icao; |
|
176 | + } |
|
159 | 177 | if ($data['title'] == null) { |
160 | 178 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
161 | - } else $data['message'] = strtolower($data['title']); |
|
179 | + } else { |
|
180 | + $data['message'] = strtolower($data['title']); |
|
181 | + } |
|
162 | 182 | $ids = $Spotter->getAllIDByRegistration($data['registration']); |
163 | 183 | $date = $data['date']; |
164 | 184 | if (isset($ids[$date])) { |
@@ -177,8 +197,9 @@ discard block |
||
177 | 197 | if (isset($result)) { |
178 | 198 | $result[0]['query_number_rows'] = $i; |
179 | 199 | return $result; |
200 | + } else { |
|
201 | + return array(); |
|
180 | 202 | } |
181 | - else return array(); |
|
182 | 203 | } |
183 | 204 | |
184 | 205 | /* |
@@ -222,7 +243,9 @@ discard block |
||
222 | 243 | */ |
223 | 244 | public function import($file) { |
224 | 245 | global $globalTransaction, $globalDebug; |
225 | - if ($globalDebug) echo 'Import '.$file."\n"; |
|
246 | + if ($globalDebug) { |
|
247 | + echo 'Import '.$file."\n"; |
|
248 | + } |
|
226 | 249 | $result = array(); |
227 | 250 | if (file_exists($file)) { |
228 | 251 | if (($handle = fopen($file,'r')) !== FALSE) { |
@@ -233,8 +256,11 @@ discard block |
||
233 | 256 | } |
234 | 257 | fclose($handle); |
235 | 258 | } |
236 | - if (!empty($result)) $this->add($result,true); |
|
237 | - elseif ($globalDebug) echo 'Nothing to import'; |
|
259 | + if (!empty($result)) { |
|
260 | + $this->add($result,true); |
|
261 | + } elseif ($globalDebug) { |
|
262 | + echo 'Nothing to import'; |
|
263 | + } |
|
238 | 264 | } |
239 | 265 | } |
240 | 266 | |
@@ -270,14 +296,23 @@ discard block |
||
270 | 296 | } |
271 | 297 | } |
272 | 298 | fclose($handle); |
273 | - } elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
|
274 | - } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
299 | + } elseif ($globalDebug) { |
|
300 | + echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
|
301 | + } |
|
302 | + } elseif ($globalDebug) { |
|
303 | + echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
304 | + } |
|
275 | 305 | $result = $Common->arr_diff($all_md5_new,$all_md5); |
276 | - if (empty($result) && $globalDebug) echo 'Nothing to update'; |
|
306 | + if (empty($result) && $globalDebug) { |
|
307 | + echo 'Nothing to update'; |
|
308 | + } |
|
277 | 309 | foreach ($result as $file => $md5) { |
278 | 310 | $Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
279 | - if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
280 | - elseif ($globalDebug) echo 'Download '.$file.' failed'; |
|
311 | + if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) { |
|
312 | + $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
313 | + } elseif ($globalDebug) { |
|
314 | + echo 'Download '.$file.' failed'; |
|
315 | + } |
|
281 | 316 | } |
282 | 317 | } |
283 | 318 | |
@@ -294,13 +329,17 @@ discard block |
||
294 | 329 | $Image = new Image(); |
295 | 330 | $Spotter = new Spotter(); |
296 | 331 | |
297 | - if (empty($crash)) return false; |
|
332 | + if (empty($crash)) { |
|
333 | + return false; |
|
334 | + } |
|
298 | 335 | if (!$new) { |
299 | 336 | $query_delete = 'DELETE FROM accidents WHERE source = :source'; |
300 | 337 | $sthd = $Connection->db->prepare($query_delete); |
301 | 338 | $sthd->execute(array(':source' => $crash[0]['source'])); |
302 | 339 | } |
303 | - if ($globalTransaction) $Connection->db->beginTransaction(); |
|
340 | + if ($globalTransaction) { |
|
341 | + $Connection->db->beginTransaction(); |
|
342 | + } |
|
304 | 343 | $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); |
305 | 344 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
306 | 345 | $sth_check = $Connection->db->prepare($query_check); |
@@ -315,7 +354,9 @@ discard block |
||
315 | 354 | return $value === "" ? NULL : $value; |
316 | 355 | }, $cr); |
317 | 356 | if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
318 | - if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
357 | + if (strpos($cr['registration'],'-') === FALSE) { |
|
358 | + $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
359 | + } |
|
319 | 360 | $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
320 | 361 | $sth_check->execute($query_check_values); |
321 | 362 | $result_check = $sth_check->fetch(PDO::FETCH_ASSOC); |
@@ -337,9 +378,13 @@ discard block |
||
337 | 378 | $Connection->db->beginTransaction(); |
338 | 379 | } |
339 | 380 | } |
340 | - if ($globalTransaction) $Connection->db->commit(); |
|
381 | + if ($globalTransaction) { |
|
382 | + $Connection->db->commit(); |
|
383 | + } |
|
341 | 384 | } catch(PDOException $e) { |
342 | - if ($globalTransaction) $Connection->db->rollBack(); |
|
385 | + if ($globalTransaction) { |
|
386 | + $Connection->db->rollBack(); |
|
387 | + } |
|
343 | 388 | echo $e->getMessage(); |
344 | 389 | } |
345 | 390 | $sth_check->closeCursor(); |
@@ -378,8 +423,11 @@ discard block |
||
378 | 423 | return "error : ".$e->getMessage(); |
379 | 424 | } |
380 | 425 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
381 | - if ($row['nb'] > 0) return false; |
|
382 | - else return true; |
|
426 | + if ($row['nb'] > 0) { |
|
427 | + return false; |
|
428 | + } else { |
|
429 | + return true; |
|
430 | + } |
|
383 | 431 | } |
384 | 432 | |
385 | 433 | public static function insert_last_accidents_update() { |