@@ -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,32 +105,50 @@ 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,2)); |
| 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 | $data = array_merge($row,$data); |
| 119 | - if ($data['ident'] == null) $data['ident'] = $icao; |
|
| 135 | + if ($data['ident'] == null) { |
|
| 136 | + $data['ident'] = $icao; |
|
| 137 | + } |
|
| 120 | 138 | if ($data['title'] == null) { |
| 121 | 139 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
| 122 | - } else $data['message'] = strtolower($data['title']); |
|
| 140 | + } else { |
|
| 141 | + $data['message'] = strtolower($data['title']); |
|
| 142 | + } |
|
| 123 | 143 | $result[] = $data; |
| 124 | 144 | $i++; |
| 125 | 145 | } |
| 126 | 146 | if (isset($result)) { |
| 127 | 147 | $result[0]['query_number_rows'] = $i; |
| 128 | 148 | return $result; |
| 149 | + } else { |
|
| 150 | + return array(); |
|
| 129 | 151 | } |
| 130 | - else return array(); |
|
| 131 | 152 | } |
| 132 | 153 | |
| 133 | 154 | |
@@ -137,7 +158,9 @@ discard block |
||
| 137 | 158 | */ |
| 138 | 159 | public function import($file) { |
| 139 | 160 | global $globalTransaction, $globalDebug; |
| 140 | - if ($globalDebug) echo 'Import '.$file."\n"; |
|
| 161 | + if ($globalDebug) { |
|
| 162 | + echo 'Import '.$file."\n"; |
|
| 163 | + } |
|
| 141 | 164 | $result = array(); |
| 142 | 165 | if (file_exists($file)) { |
| 143 | 166 | if (($handle = fopen($file,'r')) !== FALSE) { |
@@ -148,8 +171,11 @@ discard block |
||
| 148 | 171 | } |
| 149 | 172 | fclose($handle); |
| 150 | 173 | } |
| 151 | - if (!empty($result)) $this->add($result,true); |
|
| 152 | - elseif ($globalDebug) echo 'Nothing to import'; |
|
| 174 | + if (!empty($result)) { |
|
| 175 | + $this->add($result,true); |
|
| 176 | + } elseif ($globalDebug) { |
|
| 177 | + echo 'Nothing to import'; |
|
| 178 | + } |
|
| 153 | 179 | } |
| 154 | 180 | } |
| 155 | 181 | |
@@ -183,15 +209,20 @@ discard block |
||
| 183 | 209 | } |
| 184 | 210 | fclose($handle); |
| 185 | 211 | } |
| 186 | - } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
| 212 | + } elseif ($globalDebug) { |
|
| 213 | + echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
| 214 | + } |
|
| 187 | 215 | //print_r($all_md5_new); |
| 188 | 216 | //print_r($all_md5); |
| 189 | 217 | $result = $Common->arr_diff($all_md5_new,$all_md5); |
| 190 | 218 | //print_r($result); |
| 191 | 219 | foreach ($result as $file => $md5) { |
| 192 | 220 | $Common->download('https://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
| 193 | - if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 194 | - elseif ($globalDebug) echo 'Download '.$file.' failed'; |
|
| 221 | + if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) { |
|
| 222 | + $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 223 | + } elseif ($globalDebug) { |
|
| 224 | + echo 'Download '.$file.' failed'; |
|
| 225 | + } |
|
| 195 | 226 | } |
| 196 | 227 | } |
| 197 | 228 | |
@@ -202,13 +233,17 @@ discard block |
||
| 202 | 233 | $Connection = new Connection(); |
| 203 | 234 | $Image = new Image(); |
| 204 | 235 | |
| 205 | - if (empty($crash)) return false; |
|
| 236 | + if (empty($crash)) { |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 206 | 239 | if (!$new) { |
| 207 | 240 | $query_delete = 'DELETE FROM accidents WHERE source = :source'; |
| 208 | 241 | $sthd = $Connection->db->prepare($query_delete); |
| 209 | 242 | $sthd->execute(array(':source' => $crash[0]['source'])); |
| 210 | 243 | } |
| 211 | - if ($globalTransaction) $Connection->db->beginTransaction(); |
|
| 244 | + if ($globalTransaction) { |
|
| 245 | + $Connection->db->beginTransaction(); |
|
| 246 | + } |
|
| 212 | 247 | $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); |
| 213 | 248 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
| 214 | 249 | $sth_check = $Connection->db->prepare($query_check); |
@@ -243,9 +278,13 @@ discard block |
||
| 243 | 278 | $Connection->db->beginTransaction(); |
| 244 | 279 | } |
| 245 | 280 | } |
| 246 | - if ($globalTransaction) $Connection->db->commit(); |
|
| 281 | + if ($globalTransaction) { |
|
| 282 | + $Connection->db->commit(); |
|
| 283 | + } |
|
| 247 | 284 | } catch(PDOException $e) { |
| 248 | - if ($globalTransaction) $Connection->db->rollBack(); |
|
| 285 | + if ($globalTransaction) { |
|
| 286 | + $Connection->db->rollBack(); |
|
| 287 | + } |
|
| 249 | 288 | echo $e->getMessage(); |
| 250 | 289 | } |
| 251 | 290 | $sth_check->closeCursor(); |
@@ -280,8 +319,11 @@ discard block |
||
| 280 | 319 | return "error : ".$e->getMessage(); |
| 281 | 320 | } |
| 282 | 321 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
| 283 | - if ($row['nb'] > 0) return false; |
|
| 284 | - else return true; |
|
| 322 | + if ($row['nb'] > 0) { |
|
| 323 | + return false; |
|
| 324 | + } else { |
|
| 325 | + return true; |
|
| 326 | + } |
|
| 285 | 327 | } |
| 286 | 328 | |
| 287 | 329 | public static function insert_last_accidents_update() { |