@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | * @param String $date get data for a date |
30 | 30 | * @return Array Return Accidents data in array |
31 | 31 | */ |
32 | - public function getAccidentData($limit = '',$type = '',$date = '') { |
|
32 | + public function getAccidentData($limit = '', $type = '', $date = '') { |
|
33 | 33 | global $globalURL, $globalDBdriver; |
34 | 34 | $Image = new Image($this->db); |
35 | 35 | $Spotter = new Spotter($this->db); |
36 | 36 | $Translation = new Translation($this->db); |
37 | - $date = filter_var($date,FILTER_SANITIZE_STRING); |
|
37 | + $date = filter_var($date, FILTER_SANITIZE_STRING); |
|
38 | 38 | date_default_timezone_set('UTC'); |
39 | 39 | $result = array(); |
40 | 40 | $limit_query = ''; |
41 | 41 | if ($limit != "") |
42 | 42 | { |
43 | 43 | $limit_array = explode(",", $limit); |
44 | - $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
|
45 | - $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
|
44 | + $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT); |
|
45 | + $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT); |
|
46 | 46 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
47 | 47 | { |
48 | 48 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
@@ -51,29 +51,29 @@ discard block |
||
51 | 51 | |
52 | 52 | if ($type != '') { |
53 | 53 | if ($date != '') { |
54 | - if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) { |
|
54 | + if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $date)) { |
|
55 | 55 | $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 accidents.date DESC".$limit_query; |
56 | 56 | //$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
57 | - $query_values = array(':type' => $type,':date' => $date); |
|
58 | - } elseif (preg_match("/^[0-9]{4}-[0-9]{2}$/",$date)) { |
|
57 | + $query_values = array(':type' => $type, ':date' => $date); |
|
58 | + } elseif (preg_match("/^[0-9]{4}-[0-9]{2}$/", $date)) { |
|
59 | 59 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND date BETWEEN :dated AND :datef GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
60 | - $query_values = array(':type' => $type,':dated' => $date.'-01', ':datef' => $date.'-31'); |
|
61 | - } elseif (preg_match("/^[0-9]{4}$/",$date)) { |
|
60 | + $query_values = array(':type' => $type, ':dated' => $date.'-01', ':datef' => $date.'-31'); |
|
61 | + } elseif (preg_match("/^[0-9]{4}$/", $date)) { |
|
62 | 62 | if ($globalDBdriver == 'mysql') { |
63 | 63 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND YEAR(date) = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
64 | 64 | } else { |
65 | 65 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND EXTRACT(YEAR FROM date) = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
66 | 66 | } |
67 | - $query_values = array(':type' => $type,':date' => $date); |
|
67 | + $query_values = array(':type' => $type, ':date' => $date); |
|
68 | 68 | } else { |
69 | 69 | $date = $date.'%'; |
70 | 70 | if ($globalDBdriver == 'mysql') { |
71 | 71 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE type = :type AND DATE_FORMAT(date,'%Y-%m-%d') LIKE :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
72 | - $query_values = array(':type' => $type,':date' => $date); |
|
72 | + $query_values = array(':type' => $type, ':date' => $date); |
|
73 | 73 | } else { |
74 | 74 | $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 accidents.date DESC".$limit_query; |
75 | 75 | //$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration 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 accidents.date DESC".$limit_query; |
76 | - $query_values = array(':type' => $type,':date' => $date); |
|
76 | + $query_values = array(':type' => $type, ':date' => $date); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | } else { |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | } else { |
85 | 85 | if ($date != '') { |
86 | - if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/",$date)) { |
|
86 | + if (preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $date)) { |
|
87 | 87 | $query = "SELECT * FROM accidents WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
88 | 88 | //$query = "SELECT accidents.registration, accidents.ident, accidents.date, accidents.url, accidents.country, accidents.place, accidents.title, accidents.fatalities, accidents.type, accidents.ident, accidents.aircraft_manufacturer, accidents.aircraft_name, accidents.airline_name, accidents.airline_icao, spotter_output.flightaware_id FROM accidents LEFT OUTER JOIN spotter_output ON accidents.registration = spotter_output.registration WHERE accidents_id IN (SELECT max(accidents_id) FROM accidents WHERE date = :date GROUP BY registration) ORDER BY accidents.date DESC".$limit_query; |
89 | 89 | } else { |
@@ -102,19 +102,19 @@ discard block |
||
102 | 102 | try { |
103 | 103 | $sth = $this->db->prepare($query); |
104 | 104 | $sth->execute($query_values); |
105 | - } catch(PDOException $e) { |
|
105 | + } catch (PDOException $e) { |
|
106 | 106 | echo "error : ".$e->getMessage(); |
107 | 107 | } |
108 | 108 | $i = 0; |
109 | 109 | while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
110 | 110 | //print_r($row); |
111 | 111 | //echo $row['flightaware_id']; |
112 | - if (preg_match('/^[\w\-]+$/',$row['registration'])) { |
|
112 | + if (preg_match('/^[\w\-]+$/', $row['registration'])) { |
|
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) $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' => '')); |
|
118 | 118 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
119 | 119 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
120 | 120 | if (!empty($aircraft_info)) { |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $data['aircraft_name'] = $aircraft_info[0]['type']; |
123 | 123 | $data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer']; |
124 | 124 | } else { |
125 | - $data = array_merge($data,array('aircraft_type' => 'NA')); |
|
125 | + $data = array_merge($data, array('aircraft_type' => 'NA')); |
|
126 | 126 | } |
127 | 127 | $owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']); |
128 | 128 | if (!empty($owner_data)) { |
@@ -130,18 +130,18 @@ discard block |
||
130 | 130 | $data['aircraft_base'] = $owner_data['base']; |
131 | 131 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
132 | 132 | } |
133 | - } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
133 | + } else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => '')); |
|
134 | 134 | if ($row['registration'] == '') $row['registration'] = 'NA'; |
135 | 135 | if ($row['ident'] == '') $row['ident'] = 'NA'; |
136 | - $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3)); |
|
136 | + $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 3)); |
|
137 | 137 | if (isset($identicao[0])) { |
138 | - 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'); |
|
142 | - $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
|
138 | + 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'); |
|
142 | + $data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name'])); |
|
143 | 143 | } else $icao = $row['ident']; |
144 | - $icao = $Translation->checkTranslation($icao,false); |
|
144 | + $icao = $Translation->checkTranslation($icao, false); |
|
145 | 145 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
146 | 146 | if ($row['airline_name'] != '' && !isset($data['airline_name'])) { |
147 | 147 | //echo 'Check airline info... for '.$row['airline_name'].' '; |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | if (!empty($airline_info)) { |
151 | 151 | //echo 'data found !'."\n"; |
152 | 152 | //print_r($airline_info); |
153 | - $data = array_merge($data,$airline_info); |
|
153 | + $data = array_merge($data, $airline_info); |
|
154 | 154 | } |
155 | 155 | //else echo 'No data...'."\n"; |
156 | 156 | } |
157 | - $data = array_merge($row,$data); |
|
157 | + $data = array_merge($row, $data); |
|
158 | 158 | if ($data['ident'] == null) $data['ident'] = $icao; |
159 | 159 | if ($data['title'] == null) { |
160 | 160 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | try { |
191 | 191 | $sth = $this->db->prepare($query); |
192 | 192 | $sth->execute(); |
193 | - } catch(PDOException $e) { |
|
193 | + } catch (PDOException $e) { |
|
194 | 194 | echo "Error : ".$e->getMessage(); |
195 | 195 | } |
196 | 196 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | try { |
211 | 211 | $sth = $this->db->prepare($query); |
212 | 212 | $sth->execute(); |
213 | - } catch(PDOException $e) { |
|
213 | + } catch (PDOException $e) { |
|
214 | 214 | echo "Error : ".$e->getMessage(); |
215 | 215 | } |
216 | 216 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -225,15 +225,15 @@ discard block |
||
225 | 225 | if ($globalDebug) echo 'Import '.$file."\n"; |
226 | 226 | $result = array(); |
227 | 227 | if (file_exists($file)) { |
228 | - if (($handle = fopen($file,'r')) !== FALSE) { |
|
229 | - while (($data = fgetcsv($handle,2000,",")) !== FALSE) { |
|
228 | + if (($handle = fopen($file, 'r')) !== FALSE) { |
|
229 | + while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) { |
|
230 | 230 | if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') { |
231 | - $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],'operator' => $data[13],'source' => 'website_fam'); |
|
231 | + $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], 'operator' => $data[13], 'source' => 'website_fam'); |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | fclose($handle); |
235 | 235 | } |
236 | - if (!empty($result)) $this->add($result,true); |
|
236 | + if (!empty($result)) $this->add($result, true); |
|
237 | 237 | elseif ($globalDebug) echo 'Nothing to import'; |
238 | 238 | } |
239 | 239 | } |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | $all_md5_new = array(); |
250 | 250 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
251 | 251 | if ($this->check_accidents_nb() > 0) { |
252 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
253 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
252 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
253 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
254 | 254 | if (isset($data[1])) { |
255 | 255 | $year = $data[0]; |
256 | 256 | $all_md5[$year] = $data[1]; |
@@ -260,10 +260,10 @@ discard block |
||
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
263 | - $Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
263 | + $Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5', dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
264 | 264 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
265 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
266 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
265 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
266 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
267 | 267 | if (isset($data[1])) { |
268 | 268 | $year = $data[0]; |
269 | 269 | $all_md5_new[$year] = $data[1]; |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | fclose($handle); |
273 | 273 | } elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
274 | 274 | } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
275 | - $result = $Common->arr_diff($all_md5_new,$all_md5); |
|
275 | + $result = $Common->arr_diff($all_md5_new, $all_md5); |
|
276 | 276 | if (empty($result) && $globalDebug) echo 'Nothing to update'; |
277 | 277 | foreach ($result as $file => $md5) { |
278 | - $Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
|
278 | + $Common->download('http://data.flightairmap.fr/data/cr/'.$file, dirname(__FILE__).'/../install/tmp/'.$file); |
|
279 | 279 | if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
280 | 280 | elseif ($globalDebug) echo 'Download '.$file.' failed'; |
281 | 281 | } |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * Add data to DB |
286 | 286 | * @param Array $crash An array with accidents/incidents data |
287 | 287 | */ |
288 | - public function add($crash,$new = false) { |
|
288 | + public function add($crash, $new = false) { |
|
289 | 289 | global $globalTransaction, $globalDebug; |
290 | 290 | require_once('class.Connection.php'); |
291 | 291 | require_once('class.Image.php'); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | $sthd->execute(array(':source' => $crash[0]['source'])); |
302 | 302 | } |
303 | 303 | if ($globalTransaction) $Connection->db->beginTransaction(); |
304 | - $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); |
|
304 | + $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 | 305 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
306 | 306 | $sth_check = $Connection->db->prepare($query_check); |
307 | 307 | $query = 'INSERT INTO accidents (aircraft_manufacturer,aircraft_name,ident,registration,date,url,country,place,title,fatalities,latitude,longitude,type,airline_name,source) VALUES (:aircraft_manufacturer,:aircraft_name,:ident,:registration,:date,:url,:country,:place,:title,:fatalities,:latitude,:longitude,:type,:airline_name,:source)'; |
@@ -314,31 +314,31 @@ discard block |
||
314 | 314 | $cr = array_map(function($value) { |
315 | 315 | return $value === "" ? NULL : $value; |
316 | 316 | }, $cr); |
317 | - 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']); |
|
319 | - $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
|
317 | + 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']); |
|
319 | + $query_check_values = array(':registration' => $cr['registration'], ':date' => date('Y-m-d', $cr['date']), ':type' => $cr['type'], ':source' => $cr['source']); |
|
320 | 320 | $sth_check->execute($query_check_values); |
321 | 321 | $result_check = $sth_check->fetch(PDO::FETCH_ASSOC); |
322 | 322 | if ($result_check['nb'] == 0) { |
323 | - $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'],':airline_name' => $cr['operator']); |
|
323 | + $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'], ':airline_name' => $cr['operator']); |
|
324 | 324 | $sth->execute($query_values); |
325 | - if ($cr['date'] > time()-(30*86400)) { |
|
325 | + if ($cr['date'] > time() - (30*86400)) { |
|
326 | 326 | if (empty($Image->getSpotterImage($cr['registration']))) { |
327 | 327 | //if ($globalDebug) echo 'Get image...'."\n"; |
328 | 328 | $Image->addSpotterImage($cr['registration']); |
329 | 329 | } |
330 | 330 | // elseif ($globalDebug) echo 'Image already in DB'."\n"; |
331 | 331 | } |
332 | - $Spotter->setHighlightFlightByRegistration($cr['registration'],$cr['title'],date('Y-m-d',$cr['date'])); |
|
332 | + $Spotter->setHighlightFlightByRegistration($cr['registration'], $cr['title'], date('Y-m-d', $cr['date'])); |
|
333 | 333 | } |
334 | 334 | } |
335 | - if ($globalTransaction && $j % 1000 == 0) { |
|
335 | + if ($globalTransaction && $j%1000 == 0) { |
|
336 | 336 | $Connection->db->commit(); |
337 | 337 | $Connection->db->beginTransaction(); |
338 | 338 | } |
339 | 339 | } |
340 | 340 | if ($globalTransaction) $Connection->db->commit(); |
341 | - } catch(PDOException $e) { |
|
341 | + } catch (PDOException $e) { |
|
342 | 342 | if ($globalTransaction) $Connection->db->rollBack(); |
343 | 343 | echo $e->getMessage(); |
344 | 344 | } |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | $Connection = new Connection(); |
357 | 357 | $sth = $Connection->db->prepare($query); |
358 | 358 | $sth->execute(); |
359 | - } catch(PDOException $e) { |
|
359 | + } catch (PDOException $e) { |
|
360 | 360 | return "error : ".$e->getMessage(); |
361 | 361 | } |
362 | 362 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | $Connection = new Connection(); |
375 | 375 | $sth = $Connection->db->prepare($query); |
376 | 376 | $sth->execute(); |
377 | - } catch(PDOException $e) { |
|
377 | + } catch (PDOException $e) { |
|
378 | 378 | return "error : ".$e->getMessage(); |
379 | 379 | } |
380 | 380 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | $Connection = new Connection(); |
390 | 390 | $sth = $Connection->db->prepare($query); |
391 | 391 | $sth->execute(); |
392 | - } catch(PDOException $e) { |
|
392 | + } catch (PDOException $e) { |
|
393 | 393 | return "error : ".$e->getMessage(); |
394 | 394 | } |
395 | 395 | } |
@@ -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() { |