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