@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | $page_url = $globalURL.'/accident-latest'; |
10 | 10 | |
11 | -if(!isset($_GET['limit'])) |
|
11 | +if (!isset($_GET['limit'])) |
|
12 | 12 | { |
13 | 13 | $limit_start = 0; |
14 | 14 | $limit_end = 25; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | print '<div class="table column">'; |
36 | 36 | print '<p>'._("The table below shows the latest Incidents.").'</p>'; |
37 | -$spotter_array = $Accident->getAccidentData($limit_start.",".$absolute_difference,'incident'); |
|
37 | +$spotter_array = $Accident->getAccidentData($limit_start.",".$absolute_difference, 'incident'); |
|
38 | 38 | //print_r($spotter_array); |
39 | 39 | if (!empty($spotter_array) && $spotter_array[0]['query_number_rows'] != 0) { |
40 | 40 | include('table-output.php'); |
@@ -26,7 +26,7 @@ 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); |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | if ($limit != "") |
38 | 38 | { |
39 | 39 | $limit_array = explode(",", $limit); |
40 | - $limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT); |
|
41 | - $limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT); |
|
40 | + $limit_array[0] = filter_var($limit_array[0], FILTER_SANITIZE_NUMBER_INT); |
|
41 | + $limit_array[1] = filter_var($limit_array[1], FILTER_SANITIZE_NUMBER_INT); |
|
42 | 42 | if ($limit_array[0] >= 0 && $limit_array[1] >= 0) |
43 | 43 | { |
44 | 44 | $limit_query = " LIMIT ".$limit_array[1]." OFFSET ".$limit_array[0]; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | if ($type != '') { |
49 | 49 | if ($date != '') { |
50 | 50 | $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; |
51 | - $query_values = array(':type' => $type,':date' => $date); |
|
51 | + $query_values = array(':type' => $type, ':date' => $date); |
|
52 | 52 | } else { |
53 | 53 | $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; |
54 | 54 | $query_values = array(':type' => $type); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | try { |
67 | 67 | $sth = $this->db->prepare($query); |
68 | 68 | $sth->execute($query_values); |
69 | - } catch(PDOException $e) { |
|
69 | + } catch (PDOException $e) { |
|
70 | 70 | return "error : ".$e->getMessage(); |
71 | 71 | } |
72 | 72 | $i = 0; |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | $data = array(); |
75 | 75 | if ($row['registration'] != '') { |
76 | 76 | $image_array = $Image->getSpotterImage($row['registration']); |
77 | - 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'])); |
|
78 | - else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
77 | + 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'])); |
|
78 | + else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => '')); |
|
79 | 79 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
80 | 80 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
81 | 81 | if (!empty($aircraft_info)) { |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $data['aircraft_name'] = $aircraft_info[0]['type']; |
84 | 84 | $data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer']; |
85 | 85 | } else { |
86 | - $data = array_merge($data,array('aircraft_type' => 'NA')); |
|
86 | + $data = array_merge($data, array('aircraft_type' => 'NA')); |
|
87 | 87 | } |
88 | 88 | $owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']); |
89 | 89 | if (!empty($owner_data)) { |
@@ -91,20 +91,20 @@ discard block |
||
91 | 91 | $data['aircraft_base'] = $owner_data['base']; |
92 | 92 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
93 | 93 | } |
94 | - } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
94 | + } else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => '')); |
|
95 | 95 | if ($row['registration'] == '') $row['registration'] = 'NA'; |
96 | 96 | if ($row['ident'] == '') $row['ident'] = 'NA'; |
97 | - $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,2)); |
|
97 | + $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 2)); |
|
98 | 98 | if (isset($identicao[0])) { |
99 | - if (substr($row['ident'],0,2) == 'AF') { |
|
100 | - if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
101 | - else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
102 | - } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
103 | - $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
|
99 | + if (substr($row['ident'], 0, 2) == 'AF') { |
|
100 | + if (filter_var(substr($row['ident'], 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
101 | + else $icao = 'AFR'.ltrim(substr($row['ident'], 2), '0'); |
|
102 | + } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'], 2), '0'); |
|
103 | + $data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name'])); |
|
104 | 104 | } else $icao = $row['ident']; |
105 | - $icao = $Translation->checkTranslation($icao,false); |
|
105 | + $icao = $Translation->checkTranslation($icao, false); |
|
106 | 106 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
107 | - $data = array_merge($row,$data); |
|
107 | + $data = array_merge($row, $data); |
|
108 | 108 | if ($data['ident'] == null) $data['ident'] = $icao; |
109 | 109 | if ($data['title'] == null) { |
110 | 110 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
@@ -129,15 +129,15 @@ discard block |
||
129 | 129 | if ($globalDebug) echo 'Import '.$file."\n"; |
130 | 130 | $result = array(); |
131 | 131 | if (file_exists($file)) { |
132 | - if (($handle = fopen($file,'r')) !== FALSE) { |
|
133 | - while (($data = fgetcsv($handle,2000,",")) !== FALSE) { |
|
132 | + if (($handle = fopen($file, 'r')) !== FALSE) { |
|
133 | + while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) { |
|
134 | 134 | if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') { |
135 | - $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'); |
|
135 | + $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'); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | fclose($handle); |
139 | 139 | } |
140 | - if (!empty($result)) $this->add($result,true); |
|
140 | + if (!empty($result)) $this->add($result, true); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | $all_md5_new = array(); |
149 | 149 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
150 | 150 | if ($this->check_accidents_nb() > 0) { |
151 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
152 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
151 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
152 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
153 | 153 | if (isset($data[1])) { |
154 | 154 | $year = $data[0]; |
155 | 155 | $all_md5[$year] = $data[1]; |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
162 | - $Common->download('https://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
162 | + $Common->download('https://data.flightairmap.fr/data/cr/cr-all.md5', dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
163 | 163 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
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_new[$year] = $data[1]; |
@@ -173,15 +173,15 @@ discard block |
||
173 | 173 | } |
174 | 174 | //print_r($all_md5_new); |
175 | 175 | //print_r($all_md5); |
176 | - $result = $Common->arr_diff($all_md5_new,$all_md5); |
|
176 | + $result = $Common->arr_diff($all_md5_new, $all_md5); |
|
177 | 177 | //print_r($result); |
178 | 178 | foreach ($result as $file => $md5) { |
179 | - $Common->download('https://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
|
179 | + $Common->download('https://data.flightairmap.fr/data/cr/'.$file, dirname(__FILE__).'/../install/tmp/'.$file); |
|
180 | 180 | if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | - public function add($crash,$new = false) { |
|
184 | + public function add($crash, $new = false) { |
|
185 | 185 | global $globalTransaction, $globalDebug; |
186 | 186 | require_once('class.Connection.php'); |
187 | 187 | require_once('class.Image.php'); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $sthd->execute(array(':source' => $crash[0]['source'])); |
196 | 196 | } |
197 | 197 | if ($globalTransaction) $Connection->db->beginTransaction(); |
198 | - $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); |
|
198 | + $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); |
|
199 | 199 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
200 | 200 | $sth_check = $Connection->db->prepare($query_check); |
201 | 201 | $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)'; |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | $cr = array_map(function($value) { |
209 | 209 | return $value === "" ? NULL : $value; |
210 | 210 | }, $cr); |
211 | - if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
|
212 | - $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
|
211 | + if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && $cr['date'] < time() && !preg_match('/\s/', $cr['registration'])) { |
|
212 | + $query_check_values = array(':registration' => $cr['registration'], ':date' => date('Y-m-d', $cr['date']), ':type' => $cr['type'], ':source' => $cr['source']); |
|
213 | 213 | $sth_check->execute($query_check_values); |
214 | 214 | $result_check = $sth_check->fetch(PDO::FETCH_ASSOC); |
215 | 215 | if ($result_check['nb'] == 0) { |
216 | - $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']); |
|
216 | + $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']); |
|
217 | 217 | $sth->execute($query_values); |
218 | - if ($cr['date'] > time()-(30*86400)) { |
|
218 | + if ($cr['date'] > time() - (30*86400)) { |
|
219 | 219 | if (empty($Image->getSpotterImage($cr['registration']))) { |
220 | 220 | //if ($globalDebug) echo 'Get image...'."\n"; |
221 | 221 | $Image->addSpotterImage($cr['registration']); |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | } |
225 | 225 | } |
226 | 226 | } |
227 | - if ($globalTransaction && $j % 90 == 0) { |
|
227 | + if ($globalTransaction && $j%90 == 0) { |
|
228 | 228 | $Connection->db->commit(); |
229 | 229 | $Connection->db->beginTransaction(); |
230 | 230 | } |
231 | 231 | } |
232 | 232 | if ($globalTransaction) $Connection->db->commit(); |
233 | - } catch(PDOException $e) { |
|
233 | + } catch (PDOException $e) { |
|
234 | 234 | if ($globalTransaction) $Connection->db->rollBack(); |
235 | 235 | echo $e->getMessage(); |
236 | 236 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | $Connection = new Connection(); |
245 | 245 | $sth = $Connection->db->prepare($query); |
246 | 246 | $sth->execute(); |
247 | - } catch(PDOException $e) { |
|
247 | + } catch (PDOException $e) { |
|
248 | 248 | return "error : ".$e->getMessage(); |
249 | 249 | } |
250 | 250 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $Connection = new Connection(); |
263 | 263 | $sth = $Connection->db->prepare($query); |
264 | 264 | $sth->execute(); |
265 | - } catch(PDOException $e) { |
|
265 | + } catch (PDOException $e) { |
|
266 | 266 | return "error : ".$e->getMessage(); |
267 | 267 | } |
268 | 268 | $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 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | $page_url = $globalURL.'/accident-latest'; |
10 | 10 | |
11 | -if(!isset($_GET['limit'])) |
|
11 | +if (!isset($_GET['limit'])) |
|
12 | 12 | { |
13 | 13 | $limit_start = 0; |
14 | 14 | $limit_end = 25; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | print '<div class="table column">'; |
36 | 36 | print '<p>'._("The table below shows the latest Accidents.").'</p>'; |
37 | -$spotter_array = $Accident->getAccidentData($limit_start.",".$absolute_difference,'accident'); |
|
37 | +$spotter_array = $Accident->getAccidentData($limit_start.",".$absolute_difference, 'accident'); |
|
38 | 38 | //print_r($spotter_array); |
39 | 39 | if (!empty($spotter_array) && $spotter_array[0]['query_number_rows'] != 0) { |
40 | 40 | include('table-output.php'); |