@@ -85,8 +85,11 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 234 | 273 | return $value === "" ? NULL : $value; |
| 235 | 274 | }, $cr); |
| 236 | 275 | if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
| 237 | - if (!strpos($cr['registration'],'-')) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
| 276 | + if (!strpos($cr['registration'],'-')) { |
|
| 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 |
||
| 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 |
||
| 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() { |