@@ -26,20 +26,20 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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,20 +102,20 @@ discard block |
||
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,2)); |
|
108 | + $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 2)); |
|
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 | - $data = array_merge($row,$data); |
|
118 | + $data = array_merge($row, $data); |
|
119 | 119 | if ($data['ident'] == null) $data['ident'] = $icao; |
120 | 120 | if ($data['title'] == null) { |
121 | 121 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | if ($globalDebug) echo 'Import '.$file."\n"; |
141 | 141 | $result = array(); |
142 | 142 | if (file_exists($file)) { |
143 | - if (($handle = fopen($file,'r')) !== FALSE) { |
|
144 | - while (($data = fgetcsv($handle,2000,",")) !== FALSE) { |
|
143 | + if (($handle = fopen($file, 'r')) !== FALSE) { |
|
144 | + while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) { |
|
145 | 145 | if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') { |
146 | - $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],'source' => 'website_fam'); |
|
146 | + $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], 'source' => 'website_fam'); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | fclose($handle); |
150 | 150 | } |
151 | - if (!empty($result)) $this->add($result,true); |
|
151 | + if (!empty($result)) $this->add($result, true); |
|
152 | 152 | elseif ($globalDebug) echo 'Nothing to import'; |
153 | 153 | } |
154 | 154 | } |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | $all_md5_new = array(); |
162 | 162 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
163 | 163 | if ($this->check_accidents_nb() > 0) { |
164 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
165 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
164 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
165 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
166 | 166 | if (isset($data[1])) { |
167 | 167 | $year = $data[0]; |
168 | 168 | $all_md5[$year] = $data[1]; |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | } |
173 | 173 | } |
174 | 174 | } |
175 | - $Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
175 | + $Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5', dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
176 | 176 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
177 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
178 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
177 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
178 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
179 | 179 | if (isset($data[1])) { |
180 | 180 | $year = $data[0]; |
181 | 181 | $all_md5_new[$year] = $data[1]; |
@@ -184,16 +184,16 @@ discard block |
||
184 | 184 | fclose($handle); |
185 | 185 | } elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
186 | 186 | } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
187 | - $result = $Common->arr_diff($all_md5_new,$all_md5); |
|
187 | + $result = $Common->arr_diff($all_md5_new, $all_md5); |
|
188 | 188 | if (empty($result) && $globalDebug) echo 'Nothing to update'; |
189 | 189 | foreach ($result as $file => $md5) { |
190 | - $Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
|
190 | + $Common->download('http://data.flightairmap.fr/data/cr/'.$file, dirname(__FILE__).'/../install/tmp/'.$file); |
|
191 | 191 | if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
192 | 192 | elseif ($globalDebug) echo 'Download '.$file.' failed'; |
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - public function add($crash,$new = false) { |
|
196 | + public function add($crash, $new = false) { |
|
197 | 197 | global $globalTransaction, $globalDebug; |
198 | 198 | require_once('class.Connection.php'); |
199 | 199 | require_once('class.Image.php'); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $sthd->execute(array(':source' => $crash[0]['source'])); |
210 | 210 | } |
211 | 211 | if ($globalTransaction) $Connection->db->beginTransaction(); |
212 | - $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); |
|
212 | + $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 | 213 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
214 | 214 | $sth_check = $Connection->db->prepare($query_check); |
215 | 215 | $query = 'INSERT INTO accidents (aircraft_manufacturer,aircraft_name,ident,registration,date,url,country,place,title,fatalities,latitude,longitude,type,source) VALUES (:aircraft_manufacturer,:aircraft_name,:ident,:registration,:date,:url,:country,:place,:title,:fatalities,:latitude,:longitude,:type,:source)'; |
@@ -222,15 +222,15 @@ discard block |
||
222 | 222 | $cr = array_map(function($value) { |
223 | 223 | return $value === "" ? NULL : $value; |
224 | 224 | }, $cr); |
225 | - if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
|
226 | - if (!strpos('-',$cr['registration'])) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
227 | - $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
|
225 | + if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/', $cr['registration'])) { |
|
226 | + if (!strpos('-', $cr['registration'])) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
227 | + $query_check_values = array(':registration' => $cr['registration'], ':date' => date('Y-m-d', $cr['date']), ':type' => $cr['type'], ':source' => $cr['source']); |
|
228 | 228 | $sth_check->execute($query_check_values); |
229 | 229 | $result_check = $sth_check->fetch(PDO::FETCH_ASSOC); |
230 | 230 | if ($result_check['nb'] == 0) { |
231 | - $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']); |
|
231 | + $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']); |
|
232 | 232 | $sth->execute($query_values); |
233 | - if ($cr['date'] > time()-(30*86400)) { |
|
233 | + if ($cr['date'] > time() - (30*86400)) { |
|
234 | 234 | if (empty($Image->getSpotterImage($cr['registration']))) { |
235 | 235 | //if ($globalDebug) echo 'Get image...'."\n"; |
236 | 236 | $Image->addSpotterImage($cr['registration']); |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
242 | - if ($globalTransaction && $j % 100 == 0) { |
|
242 | + if ($globalTransaction && $j%100 == 0) { |
|
243 | 243 | $Connection->db->commit(); |
244 | 244 | $Connection->db->beginTransaction(); |
245 | 245 | } |
246 | 246 | } |
247 | 247 | if ($globalTransaction) $Connection->db->commit(); |
248 | - } catch(PDOException $e) { |
|
248 | + } catch (PDOException $e) { |
|
249 | 249 | if ($globalTransaction) $Connection->db->rollBack(); |
250 | 250 | echo $e->getMessage(); |
251 | 251 | } |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $Connection = new Connection(); |
260 | 260 | $sth = $Connection->db->prepare($query); |
261 | 261 | $sth->execute(); |
262 | - } catch(PDOException $e) { |
|
262 | + } catch (PDOException $e) { |
|
263 | 263 | return "error : ".$e->getMessage(); |
264 | 264 | } |
265 | 265 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | $Connection = new Connection(); |
278 | 278 | $sth = $Connection->db->prepare($query); |
279 | 279 | $sth->execute(); |
280 | - } catch(PDOException $e) { |
|
280 | + } catch (PDOException $e) { |
|
281 | 281 | return "error : ".$e->getMessage(); |
282 | 282 | } |
283 | 283 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | $Connection = new Connection(); |
293 | 293 | $sth = $Connection->db->prepare($query); |
294 | 294 | $sth->execute(); |
295 | - } catch(PDOException $e) { |
|
295 | + } catch (PDOException $e) { |
|
296 | 296 | return "error : ".$e->getMessage(); |
297 | 297 | } |
298 | 298 | } |
@@ -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 | |
@@ -182,14 +208,23 @@ discard block |
||
182 | 208 | } |
183 | 209 | } |
184 | 210 | fclose($handle); |
185 | - } elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
|
186 | - } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
211 | + } elseif ($globalDebug) { |
|
212 | + echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
|
213 | + } |
|
214 | + } elseif ($globalDebug) { |
|
215 | + echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
216 | + } |
|
187 | 217 | $result = $Common->arr_diff($all_md5_new,$all_md5); |
188 | - if (empty($result) && $globalDebug) echo 'Nothing to update'; |
|
218 | + if (empty($result) && $globalDebug) { |
|
219 | + echo 'Nothing to update'; |
|
220 | + } |
|
189 | 221 | foreach ($result as $file => $md5) { |
190 | 222 | $Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
191 | - if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
192 | - elseif ($globalDebug) echo 'Download '.$file.' failed'; |
|
223 | + if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) { |
|
224 | + $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
225 | + } elseif ($globalDebug) { |
|
226 | + echo 'Download '.$file.' failed'; |
|
227 | + } |
|
193 | 228 | } |
194 | 229 | } |
195 | 230 | |
@@ -202,13 +237,17 @@ discard block |
||
202 | 237 | $Image = new Image(); |
203 | 238 | $Spotter = new Spotter(); |
204 | 239 | |
205 | - if (empty($crash)) return false; |
|
240 | + if (empty($crash)) { |
|
241 | + return false; |
|
242 | + } |
|
206 | 243 | if (!$new) { |
207 | 244 | $query_delete = 'DELETE FROM accidents WHERE source = :source'; |
208 | 245 | $sthd = $Connection->db->prepare($query_delete); |
209 | 246 | $sthd->execute(array(':source' => $crash[0]['source'])); |
210 | 247 | } |
211 | - if ($globalTransaction) $Connection->db->beginTransaction(); |
|
248 | + if ($globalTransaction) { |
|
249 | + $Connection->db->beginTransaction(); |
|
250 | + } |
|
212 | 251 | $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 | 252 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
214 | 253 | $sth_check = $Connection->db->prepare($query_check); |
@@ -223,7 +262,9 @@ discard block |
||
223 | 262 | return $value === "" ? NULL : $value; |
224 | 263 | }, $cr); |
225 | 264 | if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
226 | - if (!strpos('-',$cr['registration'])) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
265 | + if (!strpos('-',$cr['registration'])) { |
|
266 | + $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
267 | + } |
|
227 | 268 | $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
228 | 269 | $sth_check->execute($query_check_values); |
229 | 270 | $result_check = $sth_check->fetch(PDO::FETCH_ASSOC); |
@@ -244,9 +285,13 @@ discard block |
||
244 | 285 | $Connection->db->beginTransaction(); |
245 | 286 | } |
246 | 287 | } |
247 | - if ($globalTransaction) $Connection->db->commit(); |
|
288 | + if ($globalTransaction) { |
|
289 | + $Connection->db->commit(); |
|
290 | + } |
|
248 | 291 | } catch(PDOException $e) { |
249 | - if ($globalTransaction) $Connection->db->rollBack(); |
|
292 | + if ($globalTransaction) { |
|
293 | + $Connection->db->rollBack(); |
|
294 | + } |
|
250 | 295 | echo $e->getMessage(); |
251 | 296 | } |
252 | 297 | $sth_check->closeCursor(); |
@@ -281,8 +326,11 @@ discard block |
||
281 | 326 | return "error : ".$e->getMessage(); |
282 | 327 | } |
283 | 328 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
284 | - if ($row['nb'] > 0) return false; |
|
285 | - else return true; |
|
329 | + if ($row['nb'] > 0) { |
|
330 | + return false; |
|
331 | + } else { |
|
332 | + return true; |
|
333 | + } |
|
286 | 334 | } |
287 | 335 | |
288 | 336 | public static function insert_last_accidents_update() { |