@@ -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,7 +102,7 @@ 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; |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | //print_r($row); |
| 111 | 111 | //echo $row['flightaware_id']; |
| 112 | 112 | $data = array(); |
| 113 | - if ($row['registration'] != '' && preg_match('/^[\w\-]+$/',$row['registration'])) { |
|
| 113 | + if ($row['registration'] != '' && preg_match('/^[\w\-]+$/', $row['registration'])) { |
|
| 114 | 114 | $image_array = $Image->getSpotterImage($row['registration']); |
| 115 | - 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'])); |
|
| 116 | - else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 115 | + 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'])); |
|
| 116 | + else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => '')); |
|
| 117 | 117 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
| 118 | 118 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
| 119 | 119 | if (!empty($aircraft_info)) { |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $data['aircraft_name'] = $aircraft_info[0]['type']; |
| 122 | 122 | $data['aircraft_manufacturer'] = $aircraft_info[0]['manufacturer']; |
| 123 | 123 | } else { |
| 124 | - $data = array_merge($data,array('aircraft_type' => 'NA')); |
|
| 124 | + $data = array_merge($data, array('aircraft_type' => 'NA')); |
|
| 125 | 125 | } |
| 126 | 126 | $owner_data = $Spotter->getAircraftOwnerByRegistration($row['registration']); |
| 127 | 127 | if (!empty($owner_data)) { |
@@ -129,18 +129,18 @@ discard block |
||
| 129 | 129 | $data['aircraft_base'] = $owner_data['base']; |
| 130 | 130 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
| 131 | 131 | } |
| 132 | - } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 132 | + } else $data = array_merge($data, array('image' => '', 'image_thumbnail' => '', 'image_copyright' => '', 'image_source' => '', 'image_source_website' => '')); |
|
| 133 | 133 | if ($row['registration'] == '') $row['registration'] = 'NA'; |
| 134 | 134 | if ($row['ident'] == '') $row['ident'] = 'NA'; |
| 135 | - $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3)); |
|
| 135 | + $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'], 0, 3)); |
|
| 136 | 136 | if (isset($identicao[0])) { |
| 137 | - if (substr($row['ident'],0,2) == 'AF') { |
|
| 138 | - if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
| 139 | - else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
| 140 | - } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
| 141 | - $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
|
| 137 | + if (substr($row['ident'], 0, 2) == 'AF') { |
|
| 138 | + if (filter_var(substr($row['ident'], 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
| 139 | + else $icao = 'AFR'.ltrim(substr($row['ident'], 2), '0'); |
|
| 140 | + } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'], 2), '0'); |
|
| 141 | + $data = array_merge($data, array('airline_icao' => $identicao[0]['icao'], 'airline_name' => $identicao[0]['name'])); |
|
| 142 | 142 | } else $icao = $row['ident']; |
| 143 | - $icao = $Translation->checkTranslation($icao,false); |
|
| 143 | + $icao = $Translation->checkTranslation($icao, false); |
|
| 144 | 144 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
| 145 | 145 | if ($row['airline_name'] != '' && !isset($data['airline_name'])) { |
| 146 | 146 | //echo 'Check airline info... for '.$row['airline_name'].' '; |
@@ -149,11 +149,11 @@ discard block |
||
| 149 | 149 | if (!empty($airline_info)) { |
| 150 | 150 | //echo 'data found !'."\n"; |
| 151 | 151 | //print_r($airline_info); |
| 152 | - $data = array_merge($data,$airline_info); |
|
| 152 | + $data = array_merge($data, $airline_info); |
|
| 153 | 153 | } |
| 154 | 154 | //else echo 'No data...'."\n"; |
| 155 | 155 | } |
| 156 | - $data = array_merge($row,$data); |
|
| 156 | + $data = array_merge($row, $data); |
|
| 157 | 157 | if ($data['ident'] == null) $data['ident'] = $icao; |
| 158 | 158 | if ($data['title'] == null) { |
| 159 | 159 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | try { |
| 189 | 189 | $sth = $this->db->prepare($query); |
| 190 | 190 | $sth->execute(); |
| 191 | - } catch(PDOException $e) { |
|
| 191 | + } catch (PDOException $e) { |
|
| 192 | 192 | echo "Error : ".$e->getMessage(); |
| 193 | 193 | } |
| 194 | 194 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | try { |
| 209 | 209 | $sth = $this->db->prepare($query); |
| 210 | 210 | $sth->execute(); |
| 211 | - } catch(PDOException $e) { |
|
| 211 | + } catch (PDOException $e) { |
|
| 212 | 212 | echo "Error : ".$e->getMessage(); |
| 213 | 213 | } |
| 214 | 214 | return $sth->fetchAll(PDO::FETCH_ASSOC); |
@@ -223,15 +223,15 @@ discard block |
||
| 223 | 223 | if ($globalDebug) echo 'Import '.$file."\n"; |
| 224 | 224 | $result = array(); |
| 225 | 225 | if (file_exists($file)) { |
| 226 | - if (($handle = fopen($file,'r')) !== FALSE) { |
|
| 227 | - while (($data = fgetcsv($handle,2000,",")) !== FALSE) { |
|
| 226 | + if (($handle = fopen($file, 'r')) !== FALSE) { |
|
| 227 | + while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) { |
|
| 228 | 228 | if (isset($data[1]) && $data[1] != '0000-00-00 00:00:00') { |
| 229 | - $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'); |
|
| 229 | + $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'); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | fclose($handle); |
| 233 | 233 | } |
| 234 | - if (!empty($result)) $this->add($result,true); |
|
| 234 | + if (!empty($result)) $this->add($result, true); |
|
| 235 | 235 | elseif ($globalDebug) echo 'Nothing to import'; |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -247,8 +247,8 @@ discard block |
||
| 247 | 247 | $all_md5_new = array(); |
| 248 | 248 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
| 249 | 249 | if ($this->check_accidents_nb() > 0) { |
| 250 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
| 251 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
| 250 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
| 251 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
| 252 | 252 | if (isset($data[1])) { |
| 253 | 253 | $year = $data[0]; |
| 254 | 254 | $all_md5[$year] = $data[1]; |
@@ -258,10 +258,10 @@ discard block |
||
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | - $Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5',dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
| 261 | + $Common->download('http://data.flightairmap.fr/data/cr/cr-all.md5', dirname(__FILE__).'/../install/tmp/cr-all.md5'); |
|
| 262 | 262 | if (file_exists(dirname(__FILE__).'/../install/tmp/cr-all.md5')) { |
| 263 | - if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5','r')) !== FALSE) { |
|
| 264 | - while (($data = fgetcsv($handle,2000,"\t")) !== FALSE) { |
|
| 263 | + if (($handle = fopen(dirname(__FILE__).'/../install/tmp/cr-all.md5', 'r')) !== FALSE) { |
|
| 264 | + while (($data = fgetcsv($handle, 2000, "\t")) !== FALSE) { |
|
| 265 | 265 | if (isset($data[1])) { |
| 266 | 266 | $year = $data[0]; |
| 267 | 267 | $all_md5_new[$year] = $data[1]; |
@@ -270,10 +270,10 @@ discard block |
||
| 270 | 270 | fclose($handle); |
| 271 | 271 | } elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
| 272 | 272 | } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
| 273 | - $result = $Common->arr_diff($all_md5_new,$all_md5); |
|
| 273 | + $result = $Common->arr_diff($all_md5_new, $all_md5); |
|
| 274 | 274 | if (empty($result) && $globalDebug) echo 'Nothing to update'; |
| 275 | 275 | foreach ($result as $file => $md5) { |
| 276 | - $Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 276 | + $Common->download('http://data.flightairmap.fr/data/cr/'.$file, dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 277 | 277 | if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
| 278 | 278 | elseif ($globalDebug) echo 'Download '.$file.' failed'; |
| 279 | 279 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * Add data to DB |
| 284 | 284 | * @param Array $crash An array with accidents/incidents data |
| 285 | 285 | */ |
| 286 | - public function add($crash,$new = false) { |
|
| 286 | + public function add($crash, $new = false) { |
|
| 287 | 287 | global $globalTransaction, $globalDebug; |
| 288 | 288 | require_once('class.Connection.php'); |
| 289 | 289 | require_once('class.Image.php'); |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $sthd->execute(array(':source' => $crash[0]['source'])); |
| 300 | 300 | } |
| 301 | 301 | if ($globalTransaction) $Connection->db->beginTransaction(); |
| 302 | - $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); |
|
| 302 | + $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); |
|
| 303 | 303 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
| 304 | 304 | $sth_check = $Connection->db->prepare($query_check); |
| 305 | 305 | $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)'; |
@@ -312,31 +312,31 @@ discard block |
||
| 312 | 312 | $cr = array_map(function($value) { |
| 313 | 313 | return $value === "" ? NULL : $value; |
| 314 | 314 | }, $cr); |
| 315 | - if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
|
| 316 | - if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
| 317 | - $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
|
| 315 | + if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/', $cr['registration'])) { |
|
| 316 | + if (strpos($cr['registration'], '-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
| 317 | + $query_check_values = array(':registration' => $cr['registration'], ':date' => date('Y-m-d', $cr['date']), ':type' => $cr['type'], ':source' => $cr['source']); |
|
| 318 | 318 | $sth_check->execute($query_check_values); |
| 319 | 319 | $result_check = $sth_check->fetch(PDO::FETCH_ASSOC); |
| 320 | 320 | if ($result_check['nb'] == 0) { |
| 321 | - $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']); |
|
| 321 | + $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']); |
|
| 322 | 322 | $sth->execute($query_values); |
| 323 | - if ($cr['date'] > time()-(30*86400)) { |
|
| 323 | + if ($cr['date'] > time() - (30*86400)) { |
|
| 324 | 324 | if (empty($Image->getSpotterImage($cr['registration']))) { |
| 325 | 325 | //if ($globalDebug) echo 'Get image...'."\n"; |
| 326 | 326 | $Image->addSpotterImage($cr['registration']); |
| 327 | 327 | } |
| 328 | 328 | // elseif ($globalDebug) echo 'Image already in DB'."\n"; |
| 329 | 329 | } |
| 330 | - $Spotter->setHighlightFlightByRegistration($cr['registration'],$cr['title'],date('Y-m-d',$cr['date'])); |
|
| 330 | + $Spotter->setHighlightFlightByRegistration($cr['registration'], $cr['title'], date('Y-m-d', $cr['date'])); |
|
| 331 | 331 | } |
| 332 | 332 | } |
| 333 | - if ($globalTransaction && $j % 1000 == 0) { |
|
| 333 | + if ($globalTransaction && $j%1000 == 0) { |
|
| 334 | 334 | $Connection->db->commit(); |
| 335 | 335 | $Connection->db->beginTransaction(); |
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | if ($globalTransaction) $Connection->db->commit(); |
| 339 | - } catch(PDOException $e) { |
|
| 339 | + } catch (PDOException $e) { |
|
| 340 | 340 | if ($globalTransaction) $Connection->db->rollBack(); |
| 341 | 341 | echo $e->getMessage(); |
| 342 | 342 | } |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | $Connection = new Connection(); |
| 355 | 355 | $sth = $Connection->db->prepare($query); |
| 356 | 356 | $sth->execute(); |
| 357 | - } catch(PDOException $e) { |
|
| 357 | + } catch (PDOException $e) { |
|
| 358 | 358 | return "error : ".$e->getMessage(); |
| 359 | 359 | } |
| 360 | 360 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | $Connection = new Connection(); |
| 373 | 373 | $sth = $Connection->db->prepare($query); |
| 374 | 374 | $sth->execute(); |
| 375 | - } catch(PDOException $e) { |
|
| 375 | + } catch (PDOException $e) { |
|
| 376 | 376 | return "error : ".$e->getMessage(); |
| 377 | 377 | } |
| 378 | 378 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | $Connection = new Connection(); |
| 388 | 388 | $sth = $Connection->db->prepare($query); |
| 389 | 389 | $sth->execute(); |
| 390 | - } catch(PDOException $e) { |
|
| 390 | + } catch (PDOException $e) { |
|
| 391 | 391 | return "error : ".$e->getMessage(); |
| 392 | 392 | } |
| 393 | 393 | } |
@@ -112,8 +112,11 @@ discard block |
||
| 112 | 112 | $data = array(); |
| 113 | 113 | if ($row['registration'] != '' && preg_match('/^[\w\-]+$/',$row['registration'])) { |
| 114 | 114 | $image_array = $Image->getSpotterImage($row['registration']); |
| 115 | - 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'])); |
|
| 116 | - else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 115 | + if (count($image_array) > 0) { |
|
| 116 | + $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 { |
|
| 118 | + $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 119 | + } |
|
| 117 | 120 | $aircraft_type = $Spotter->getAllAircraftTypeByRegistration($row['registration']); |
| 118 | 121 | $aircraft_info = $Spotter->getAllAircraftInfo($aircraft_type); |
| 119 | 122 | if (!empty($aircraft_info)) { |
@@ -129,17 +132,30 @@ discard block |
||
| 129 | 132 | $data['aircraft_base'] = $owner_data['base']; |
| 130 | 133 | $data['aircraft_date_first_reg'] = $owner_data['date_first_reg']; |
| 131 | 134 | } |
| 132 | - } else $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 133 | - if ($row['registration'] == '') $row['registration'] = 'NA'; |
|
| 134 | - if ($row['ident'] == '') $row['ident'] = 'NA'; |
|
| 135 | + } else { |
|
| 136 | + $data = array_merge($data,array('image' => '','image_thumbnail' => '','image_copyright' => '','image_source' => '','image_source_website' => '')); |
|
| 137 | + } |
|
| 138 | + if ($row['registration'] == '') { |
|
| 139 | + $row['registration'] = 'NA'; |
|
| 140 | + } |
|
| 141 | + if ($row['ident'] == '') { |
|
| 142 | + $row['ident'] = 'NA'; |
|
| 143 | + } |
|
| 135 | 144 | $identicao = $Spotter->getAllAirlineInfo(substr($row['ident'],0,3)); |
| 136 | 145 | if (isset($identicao[0])) { |
| 137 | 146 | if (substr($row['ident'],0,2) == 'AF') { |
| 138 | - if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $row['ident']; |
|
| 139 | - else $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
| 140 | - } else $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
| 147 | + if (filter_var(substr($row['ident'],2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) { |
|
| 148 | + $icao = $row['ident']; |
|
| 149 | + } else { |
|
| 150 | + $icao = 'AFR'.ltrim(substr($row['ident'],2),'0'); |
|
| 151 | + } |
|
| 152 | + } else { |
|
| 153 | + $icao = $identicao[0]['icao'].ltrim(substr($row['ident'],2),'0'); |
|
| 154 | + } |
|
| 141 | 155 | $data = array_merge($data,array('airline_icao' => $identicao[0]['icao'],'airline_name' => $identicao[0]['name'])); |
| 142 | - } else $icao = $row['ident']; |
|
| 156 | + } else { |
|
| 157 | + $icao = $row['ident']; |
|
| 158 | + } |
|
| 143 | 159 | $icao = $Translation->checkTranslation($icao,false); |
| 144 | 160 | //$data = array_merge($data,array('registration' => $row['registration'], 'date' => $row['date'], 'ident' => $icao,'url' => $row['url'])); |
| 145 | 161 | if ($row['airline_name'] != '' && !isset($data['airline_name'])) { |
@@ -154,10 +170,14 @@ discard block |
||
| 154 | 170 | //else echo 'No data...'."\n"; |
| 155 | 171 | } |
| 156 | 172 | $data = array_merge($row,$data); |
| 157 | - if ($data['ident'] == null) $data['ident'] = $icao; |
|
| 173 | + if ($data['ident'] == null) { |
|
| 174 | + $data['ident'] = $icao; |
|
| 175 | + } |
|
| 158 | 176 | if ($data['title'] == null) { |
| 159 | 177 | $data['message'] = $row['type'].' of '.$row['registration'].' at '.$row['place'].','.$row['country']; |
| 160 | - } else $data['message'] = strtolower($data['title']); |
|
| 178 | + } else { |
|
| 179 | + $data['message'] = strtolower($data['title']); |
|
| 180 | + } |
|
| 161 | 181 | $ids = $Spotter->getAllIDByRegistration($data['registration']); |
| 162 | 182 | $date = $data['date']; |
| 163 | 183 | if (isset($ids[$date])) { |
@@ -175,8 +195,9 @@ discard block |
||
| 175 | 195 | if (isset($result)) { |
| 176 | 196 | $result[0]['query_number_rows'] = $i; |
| 177 | 197 | return $result; |
| 198 | + } else { |
|
| 199 | + return array(); |
|
| 178 | 200 | } |
| 179 | - else return array(); |
|
| 180 | 201 | } |
| 181 | 202 | |
| 182 | 203 | /* |
@@ -220,7 +241,9 @@ discard block |
||
| 220 | 241 | */ |
| 221 | 242 | public function import($file) { |
| 222 | 243 | global $globalTransaction, $globalDebug; |
| 223 | - if ($globalDebug) echo 'Import '.$file."\n"; |
|
| 244 | + if ($globalDebug) { |
|
| 245 | + echo 'Import '.$file."\n"; |
|
| 246 | + } |
|
| 224 | 247 | $result = array(); |
| 225 | 248 | if (file_exists($file)) { |
| 226 | 249 | if (($handle = fopen($file,'r')) !== FALSE) { |
@@ -231,8 +254,11 @@ discard block |
||
| 231 | 254 | } |
| 232 | 255 | fclose($handle); |
| 233 | 256 | } |
| 234 | - if (!empty($result)) $this->add($result,true); |
|
| 235 | - elseif ($globalDebug) echo 'Nothing to import'; |
|
| 257 | + if (!empty($result)) { |
|
| 258 | + $this->add($result,true); |
|
| 259 | + } elseif ($globalDebug) { |
|
| 260 | + echo 'Nothing to import'; |
|
| 261 | + } |
|
| 236 | 262 | } |
| 237 | 263 | } |
| 238 | 264 | |
@@ -268,14 +294,23 @@ discard block |
||
| 268 | 294 | } |
| 269 | 295 | } |
| 270 | 296 | fclose($handle); |
| 271 | - } elseif ($globalDebug) echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
|
| 272 | - } elseif ($globalDebug) echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
| 297 | + } elseif ($globalDebug) { |
|
| 298 | + echo "Can't open ".dirname(__FILE__).'/../install/tmp/cr-all.md5'; |
|
| 299 | + } |
|
| 300 | + } elseif ($globalDebug) { |
|
| 301 | + echo 'Download cr-all.md5 failed. '.dirname(__FILE__).'/../install/tmp/cr-all.md5 not here.'; |
|
| 302 | + } |
|
| 273 | 303 | $result = $Common->arr_diff($all_md5_new,$all_md5); |
| 274 | - if (empty($result) && $globalDebug) echo 'Nothing to update'; |
|
| 304 | + if (empty($result) && $globalDebug) { |
|
| 305 | + echo 'Nothing to update'; |
|
| 306 | + } |
|
| 275 | 307 | foreach ($result as $file => $md5) { |
| 276 | 308 | $Common->download('http://data.flightairmap.fr/data/cr/'.$file,dirname(__FILE__).'/../install/tmp/'.$file); |
| 277 | - if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 278 | - elseif ($globalDebug) echo 'Download '.$file.' failed'; |
|
| 309 | + if (file_exists(dirname(__FILE__).'/../install/tmp/'.$file)) { |
|
| 310 | + $this->import(dirname(__FILE__).'/../install/tmp/'.$file); |
|
| 311 | + } elseif ($globalDebug) { |
|
| 312 | + echo 'Download '.$file.' failed'; |
|
| 313 | + } |
|
| 279 | 314 | } |
| 280 | 315 | } |
| 281 | 316 | |
@@ -292,13 +327,17 @@ discard block |
||
| 292 | 327 | $Image = new Image(); |
| 293 | 328 | $Spotter = new Spotter(); |
| 294 | 329 | |
| 295 | - if (empty($crash)) return false; |
|
| 330 | + if (empty($crash)) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 296 | 333 | if (!$new) { |
| 297 | 334 | $query_delete = 'DELETE FROM accidents WHERE source = :source'; |
| 298 | 335 | $sthd = $Connection->db->prepare($query_delete); |
| 299 | 336 | $sthd->execute(array(':source' => $crash[0]['source'])); |
| 300 | 337 | } |
| 301 | - if ($globalTransaction) $Connection->db->beginTransaction(); |
|
| 338 | + if ($globalTransaction) { |
|
| 339 | + $Connection->db->beginTransaction(); |
|
| 340 | + } |
|
| 302 | 341 | $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); |
| 303 | 342 | $query_check = 'SELECT COUNT(*) as nb FROM accidents WHERE registration = :registration AND date = :date AND type = :type AND source = :source'; |
| 304 | 343 | $sth_check = $Connection->db->prepare($query_check); |
@@ -313,7 +352,9 @@ discard block |
||
| 313 | 352 | return $value === "" ? NULL : $value; |
| 314 | 353 | }, $cr); |
| 315 | 354 | if ($cr['date'] != '' && $cr['registration'] != null && $cr['registration'] != '' && $cr['registration'] != '?' && $cr['registration'] != '-' && strtolower($cr['registration']) != 'unknown' && $cr['date'] < time() && !preg_match('/\s/',$cr['registration'])) { |
| 316 | - if (strpos($cr['registration'],'-') === FALSE) $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
| 355 | + if (strpos($cr['registration'],'-') === FALSE) { |
|
| 356 | + $cr['registration'] = $Spotter->convertAircraftRegistration($cr['registration']); |
|
| 357 | + } |
|
| 317 | 358 | $query_check_values = array(':registration' => $cr['registration'],':date' => date('Y-m-d',$cr['date']),':type' => $cr['type'],':source' => $cr['source']); |
| 318 | 359 | $sth_check->execute($query_check_values); |
| 319 | 360 | $result_check = $sth_check->fetch(PDO::FETCH_ASSOC); |
@@ -335,9 +376,13 @@ discard block |
||
| 335 | 376 | $Connection->db->beginTransaction(); |
| 336 | 377 | } |
| 337 | 378 | } |
| 338 | - if ($globalTransaction) $Connection->db->commit(); |
|
| 379 | + if ($globalTransaction) { |
|
| 380 | + $Connection->db->commit(); |
|
| 381 | + } |
|
| 339 | 382 | } catch(PDOException $e) { |
| 340 | - if ($globalTransaction) $Connection->db->rollBack(); |
|
| 383 | + if ($globalTransaction) { |
|
| 384 | + $Connection->db->rollBack(); |
|
| 385 | + } |
|
| 341 | 386 | echo $e->getMessage(); |
| 342 | 387 | } |
| 343 | 388 | $sth_check->closeCursor(); |
@@ -376,8 +421,11 @@ discard block |
||
| 376 | 421 | return "error : ".$e->getMessage(); |
| 377 | 422 | } |
| 378 | 423 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
| 379 | - if ($row['nb'] > 0) return false; |
|
| 380 | - else return true; |
|
| 424 | + if ($row['nb'] > 0) { |
|
| 425 | + return false; |
|
| 426 | + } else { |
|
| 427 | + return true; |
|
| 428 | + } |
|
| 381 | 429 | } |
| 382 | 430 | |
| 383 | 431 | public static function insert_last_accidents_update() { |