1
|
|
|
<?php |
2
|
|
|
//require_once('libs/simple_html_dom.php'); |
3
|
|
|
require(dirname(__FILE__).'/../require/settings.php'); |
4
|
|
|
require_once(dirname(__FILE__).'/../require/class.Common.php'); |
5
|
|
|
require_once(dirname(__FILE__).'/../require/class.Connection.php'); |
6
|
|
|
|
7
|
|
|
$tmp_dir = dirname(__FILE__).'/tmp/'; |
8
|
|
|
//$globalDebug = true; |
9
|
|
|
//$globalTransaction = true; |
10
|
|
|
class update_db { |
11
|
|
|
public static $db_sqlite; |
12
|
|
|
|
13
|
|
|
public static function download($url, $file, $referer = '') { |
14
|
|
|
global $globalProxy, $globalForceIPv4; |
15
|
|
|
$fp = fopen($file, 'w'); |
16
|
|
|
$ch = curl_init(); |
17
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
18
|
|
|
if (isset($globalForceIPv4) && $globalForceIPv4) { |
19
|
|
|
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){ |
20
|
|
|
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
if (isset($globalProxy) && $globalProxy != '') { |
24
|
|
|
curl_setopt($ch, CURLOPT_PROXY, $globalProxy); |
25
|
|
|
} |
26
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
27
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
28
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 200); |
29
|
|
|
if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer); |
30
|
|
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
31
|
|
|
curl_setopt($ch, CURLOPT_FILE, $fp); |
32
|
|
|
curl_exec($ch); |
33
|
|
|
curl_close($ch); |
34
|
|
|
fclose($fp); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function gunzip($in_file,$out_file_name = '') { |
38
|
|
|
//echo $in_file.' -> '.$out_file_name."\n"; |
39
|
|
|
$buffer_size = 4096; // read 4kb at a time |
40
|
|
|
if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); |
41
|
|
|
if ($in_file != '' && file_exists($in_file)) { |
42
|
|
|
// PHP version of Ubuntu use gzopen64 instead of gzopen |
43
|
|
|
if (function_exists('gzopen')) $file = gzopen($in_file,'rb'); |
44
|
|
|
elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb'); |
45
|
|
|
else { |
46
|
|
|
echo 'gzopen not available'; |
47
|
|
|
die; |
48
|
|
|
} |
49
|
|
|
$out_file = fopen($out_file_name, 'wb'); |
50
|
|
|
while(!gzeof($file)) { |
51
|
|
|
fwrite($out_file, gzread($file, $buffer_size)); |
52
|
|
|
} |
53
|
|
|
fclose($out_file); |
54
|
|
|
gzclose($file); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public static function unzip($in_file) { |
59
|
|
|
if ($in_file != '' && file_exists($in_file)) { |
60
|
|
|
$path = pathinfo(realpath($in_file), PATHINFO_DIRNAME); |
61
|
|
|
$zip = new ZipArchive; |
62
|
|
|
$res = $zip->open($in_file); |
63
|
|
|
if ($res === TRUE) { |
64
|
|
|
$zip->extractTo($path); |
65
|
|
|
$zip->close(); |
66
|
|
|
} else return false; |
67
|
|
|
} else return false; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public static function connect_sqlite($database) { |
71
|
|
|
try { |
72
|
|
|
self::$db_sqlite = new PDO('sqlite:'.$database); |
73
|
|
|
self::$db_sqlite->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
74
|
|
|
} catch(PDOException $e) { |
75
|
|
|
return "error : ".$e->getMessage(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public static function retrieve_route_sqlite_to_dest($database_file) { |
80
|
|
|
global $globalDebug, $globalTransaction; |
81
|
|
|
//$query = 'TRUNCATE TABLE routes'; |
82
|
|
|
if ($globalDebug) echo " - Delete previous routes from DB -"; |
83
|
|
|
$query = "DELETE FROM routes WHERE Source = '' OR Source = :source"; |
84
|
|
|
$Connection = new Connection(); |
85
|
|
|
try { |
86
|
|
|
//$Connection = new Connection(); |
87
|
|
|
$sth = $Connection->db->prepare($query); |
88
|
|
|
$sth->execute(array(':source' => $database_file)); |
89
|
|
|
} catch(PDOException $e) { |
90
|
|
|
return "error : ".$e->getMessage(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if ($globalDebug) echo " - Add routes to DB -"; |
94
|
|
|
update_db::connect_sqlite($database_file); |
95
|
|
|
//$query = 'select Route.RouteID, Route.callsign, operator.Icao AS operator_icao, FromAir.Icao AS FromAirportIcao, ToAir.Icao AS ToAirportIcao from Route inner join operator ON Route.operatorId = operator.operatorId LEFT JOIN Airport AS FromAir ON route.FromAirportId = FromAir.AirportId LEFT JOIN Airport AS ToAir ON ToAir.AirportID = route.ToAirportID'; |
96
|
|
|
$query = "select Route.RouteID, Route.callsign, operator.Icao AS operator_icao, FromAir.Icao AS FromAirportIcao, ToAir.Icao AS ToAirportIcao, rstp.allstop AS AllStop from Route inner join operator ON Route.operatorId = operator.operatorId LEFT JOIN Airport AS FromAir ON route.FromAirportId = FromAir.AirportId LEFT JOIN Airport AS ToAir ON ToAir.AirportID = route.ToAirportID LEFT JOIN (select RouteId,GROUP_CONCAT(icao,' ') as allstop from routestop left join Airport as air ON routestop.AirportId = air.AirportID group by RouteID) AS rstp ON Route.RouteID = rstp.RouteID"; |
97
|
|
|
try { |
98
|
|
|
$sth = update_db::$db_sqlite->prepare($query); |
99
|
|
|
$sth->execute(); |
100
|
|
|
} catch(PDOException $e) { |
101
|
|
|
return "error : ".$e->getMessage(); |
102
|
|
|
} |
103
|
|
|
//$query_dest = 'INSERT INTO routes (`RouteID`,`CallSign`,`Operator_ICAO`,`FromAirport_ICAO`,`ToAirport_ICAO`,`RouteStop`,`Source`) VALUES (:RouteID, :CallSign, :Operator_ICAO, :FromAirport_ICAO, :ToAirport_ICAO, :routestop, :source)'; |
104
|
|
|
$query_dest = 'INSERT INTO routes (CallSign,Operator_ICAO,FromAirport_ICAO,ToAirport_ICAO,RouteStop,Source) VALUES (:CallSign, :Operator_ICAO, :FromAirport_ICAO, :ToAirport_ICAO, :routestop, :source)'; |
105
|
|
|
$Connection = new Connection(); |
106
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
107
|
|
|
try { |
108
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
109
|
|
|
while ($values = $sth->fetch(PDO::FETCH_ASSOC)) { |
110
|
|
|
//$query_dest_values = array(':RouteID' => $values['RouteId'],':CallSign' => $values['Callsign'],':Operator_ICAO' => $values['operator_icao'],':FromAirport_ICAO' => $values['FromAirportIcao'],':ToAirport_ICAO' => $values['ToAirportIcao'],':routestop' => $values['AllStop'],':source' => $database_file); |
111
|
|
|
$query_dest_values = array(':CallSign' => $values['Callsign'],':Operator_ICAO' => $values['operator_icao'],':FromAirport_ICAO' => $values['FromAirportIcao'],':ToAirport_ICAO' => $values['ToAirportIcao'],':routestop' => $values['AllStop'],':source' => $database_file); |
112
|
|
|
$sth_dest->execute($query_dest_values); |
113
|
|
|
} |
114
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
115
|
|
|
} catch(PDOException $e) { |
116
|
|
|
if ($globalTransaction) $Connection->db->rollBack(); |
|
|
|
|
117
|
|
|
return "error : ".$e->getMessage(); |
118
|
|
|
} |
119
|
|
|
return ''; |
120
|
|
|
} |
121
|
|
|
public static function retrieve_route_oneworld($database_file) { |
122
|
|
|
global $globalDebug, $globalTransaction; |
123
|
|
|
//$query = 'TRUNCATE TABLE routes'; |
124
|
|
|
if ($globalDebug) echo " - Delete previous routes from DB -"; |
125
|
|
|
$query = "DELETE FROM routes WHERE Source = '' OR Source = :source"; |
126
|
|
|
$Connection = new Connection(); |
127
|
|
|
try { |
128
|
|
|
//$Connection = new Connection(); |
129
|
|
|
$sth = $Connection->db->prepare($query); |
130
|
|
|
$sth->execute(array(':source' => 'oneworld')); |
131
|
|
|
} catch(PDOException $e) { |
132
|
|
|
return "error : ".$e->getMessage(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
if ($globalDebug) echo " - Add routes to DB -"; |
136
|
|
|
require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
137
|
|
|
$Spotter = new Spotter(); |
138
|
|
|
if ($fh = fopen($database_file,"r")) { |
139
|
|
|
$query_dest = 'INSERT INTO routes (CallSign,Operator_ICAO,FromAirport_ICAO,FromAirport_Time,ToAirport_ICAO,ToAirport_Time,RouteStop,Source) VALUES (:CallSign, :Operator_ICAO, :FromAirport_ICAO,:FromAirport_Time, :ToAirport_ICAO, :ToAirport_Time,:routestop, :source)'; |
140
|
|
|
$Connection = new Connection(); |
141
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
142
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
143
|
|
|
while (!feof($fh)) { |
144
|
|
|
$line = fgetcsv($fh,9999,','); |
145
|
|
|
if ($line[0] != '') { |
146
|
|
|
if (($line[2] == '-' || ($line[2] != '-' && (strtotime($line[2]) > time()))) && ($line[3] == '-' || ($line[3] != '-' && (strtotime($line[3]) < time())))) { |
147
|
|
|
try { |
148
|
|
|
$query_dest_values = array(':CallSign' => str_replace('*','',$line[7]),':Operator_ICAO' => '',':FromAirport_ICAO' => $Spotter->getAirportICAO($line[0]),':FromAirport_Time' => $line[5],':ToAirport_ICAO' => $Spotter->getAirportICAO($line[1]),':ToAirport_Time' => $line[6],':routestop' => '',':source' => 'oneworld'); |
149
|
|
|
$sth_dest->execute($query_dest_values); |
150
|
|
|
} catch(PDOException $e) { |
151
|
|
|
if ($globalTransaction) $Connection->db->rollBack(); |
|
|
|
|
152
|
|
|
return "error : ".$e->getMessage(); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
158
|
|
|
} |
159
|
|
|
return ''; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public static function retrieve_route_skyteam($database_file) { |
163
|
|
|
global $globalDebug, $globalTransaction; |
164
|
|
|
//$query = 'TRUNCATE TABLE routes'; |
165
|
|
|
if ($globalDebug) echo " - Delete previous routes from DB -"; |
166
|
|
|
$query = "DELETE FROM routes WHERE Source = '' OR Source = :source"; |
167
|
|
|
$Connection = new Connection(); |
168
|
|
|
try { |
169
|
|
|
//$Connection = new Connection(); |
170
|
|
|
$sth = $Connection->db->prepare($query); |
171
|
|
|
$sth->execute(array(':source' => 'skyteam')); |
172
|
|
|
} catch(PDOException $e) { |
173
|
|
|
return "error : ".$e->getMessage(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
if ($globalDebug) echo " - Add routes to DB -"; |
177
|
|
|
|
178
|
|
|
require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
179
|
|
|
$Spotter = new Spotter(); |
180
|
|
|
if ($fh = fopen($database_file,"r")) { |
181
|
|
|
$query_dest = 'INSERT INTO routes (CallSign,Operator_ICAO,FromAirport_ICAO,FromAirport_Time,ToAirport_ICAO,ToAirport_Time,RouteStop,Source) VALUES (:CallSign, :Operator_ICAO, :FromAirport_ICAO,:FromAirport_Time, :ToAirport_ICAO, :ToAirport_Time,:routestop, :source)'; |
182
|
|
|
$Connection = new Connection(); |
183
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
184
|
|
|
try { |
185
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
186
|
|
|
while (!feof($fh)) { |
187
|
|
|
$line = fgetcsv($fh,9999,','); |
188
|
|
|
if ($line[0] != '') { |
189
|
|
|
$datebe = explode(' - ',$line[2]); |
190
|
|
|
if (strtotime($datebe[0]) > time() && strtotime($datebe[1]) < time()) { |
191
|
|
|
$query_dest_values = array(':CallSign' => str_replace('*','',$line[6]),':Operator_ICAO' => '',':FromAirport_ICAO' => $Spotter->getAirportICAO($line[0]),':FromAirport_Time' => $line[4],':ToAirport_ICAO' => $Spotter->getAirportICAO($line[1]),':ToAirport_Time' => $line[5],':routestop' => '',':source' => 'skyteam'); |
192
|
|
|
$sth_dest->execute($query_dest_values); |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
197
|
|
|
} catch(PDOException $e) { |
198
|
|
|
if ($globalTransaction) $Connection->db->rollBack(); |
|
|
|
|
199
|
|
|
return "error : ".$e->getMessage(); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
return ''; |
203
|
|
|
} |
204
|
|
|
public static function retrieve_modes_sqlite_to_dest($database_file) { |
205
|
|
|
global $globalTransaction; |
206
|
|
|
//$query = 'TRUNCATE TABLE aircraft_modes'; |
207
|
|
|
$query = "DELETE FROM aircraft_modes WHERE Source = '' OR Source IS NULL OR Source = :source"; |
208
|
|
|
try { |
209
|
|
|
$Connection = new Connection(); |
210
|
|
|
$sth = $Connection->db->prepare($query); |
211
|
|
|
$sth->execute(array(':source' => $database_file)); |
212
|
|
|
} catch(PDOException $e) { |
213
|
|
|
return "error : ".$e->getMessage(); |
214
|
|
|
} |
215
|
|
|
$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source IS NULL OR Source = :source"; |
216
|
|
|
try { |
217
|
|
|
$Connection = new Connection(); |
218
|
|
|
$sth = $Connection->db->prepare($query); |
219
|
|
|
$sth->execute(array(':source' => $database_file)); |
220
|
|
|
} catch(PDOException $e) { |
221
|
|
|
return "error : ".$e->getMessage(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
update_db::connect_sqlite($database_file); |
225
|
|
|
$query = 'select * from Aircraft'; |
226
|
|
|
try { |
227
|
|
|
$sth = update_db::$db_sqlite->prepare($query); |
228
|
|
|
$sth->execute(); |
229
|
|
|
} catch(PDOException $e) { |
230
|
|
|
return "error : ".$e->getMessage(); |
231
|
|
|
} |
232
|
|
|
//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)'; |
233
|
|
|
$query_dest = 'INSERT INTO aircraft_modes (LastModified, ModeS,ModeSCountry,Registration,ICAOTypeCode,type_flight,Source) VALUES (:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:type,:source)'; |
234
|
|
|
|
235
|
|
|
$query_dest_owner = 'INSERT INTO aircraft_owner (registration,owner,Source) VALUES (:registration,:owner,:source)'; |
236
|
|
|
|
237
|
|
|
$Connection = new Connection(); |
238
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
239
|
|
|
$sth_dest_owner = $Connection->db->prepare($query_dest_owner); |
240
|
|
|
try { |
241
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
242
|
|
|
while ($values = $sth->fetch(PDO::FETCH_ASSOC)) { |
243
|
|
|
//$query_dest_values = array(':AircraftID' => $values['AircraftID'],':FirstCreated' => $values['FirstCreated'],':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':SerialNo' => $values['SerialNo'], ':OperatorFlagCode' => $values['OperatorFlagCode'], ':Manufacturer' => $values['Manufacturer'], ':Type' => $values['Type'], ':FirstRegDate' => $values['FirstRegDate'], ':CurrentRegDate' => $values['CurrentRegDate'], ':Country' => $values['Country'], ':PreviousID' => $values['PreviousID'], ':DeRegDate' => $values['DeRegDate'], ':Status' => $values['Status'], ':PopularName' => $values['PopularName'],':GenericName' => $values['GenericName'],':AircraftClass' => $values['AircraftClass'], ':Engines' => $values['Engines'], ':OwnershipStatus' => $values['OwnershipStatus'],':RegisteredOwners' => $values['RegisteredOwners'],':MTOW' => $values['MTOW'], ':TotalHours' => $values['TotalHours'],':YearBuilt' => $values['YearBuilt'], ':CofACategory' => $values['CofACategory'], ':CofAExpiry' => $values['CofAExpiry'], ':UserNotes' => $values['UserNotes'], ':Interested' => $values['Interested'], ':UserTag' => $values['UserTag'], ':InfoUrl' => $values['InfoURL'], ':PictureUrl1' => $values['PictureURL1'], ':PictureUrl2' => $values['PictureURL2'], ':PictureUrl3' => $values['PictureURL3'], ':UserBool1' => $values['UserBool1'], ':UserBool2' => $values['UserBool2'], ':UserBool3' => $values['UserBool3'], ':UserBool4' => $values['UserBool4'], ':UserBool5' => $values['UserBool5'], ':UserString1' => $values['UserString1'], ':UserString2' => $values['UserString2'], ':UserString3' => $values['UserString3'], ':UserString4' => $values['UserString4'], ':UserString5' => $values['UserString5'], ':UserInt1' => $values['UserInt1'], ':UserInt2' => $values['UserInt2'], ':UserInt3' => $values['UserInt3'], ':UserInt4' => $values['UserInt4'], ':UserInt5' => $values['UserInt5']); |
244
|
|
|
if ($values['UserString4'] == 'M') $type = 'military'; |
245
|
|
|
else $type = null; |
246
|
|
|
$query_dest_values = array(':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file,':type' => $type); |
247
|
|
|
$sth_dest->execute($query_dest_values); |
248
|
|
|
if ($values['RegisteredOwners'] != '' && $values['RegisteredOwners'] != NULL && $values['RegisteredOwners'] != 'Private') { |
249
|
|
|
$query_dest_owner_values = array(':registration' => $values['Registration'],':source' => $database_file,':owner' => $values['RegisteredOwners']); |
250
|
|
|
$sth_dest_owner->execute($query_dest_owner_values); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
254
|
|
|
} catch(PDOException $e) { |
255
|
|
|
return "error : ".$e->getMessage(); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
// Remove data already in DB from ACARS |
259
|
|
|
$query = "DELETE FROM aircraft_modes WHERE Source = :source AND ModeS IN (SELECT * FROM (SELECT ModeS FROM aircraft_modes WHERE Source = 'ACARS') _alias)"; |
260
|
|
|
try { |
261
|
|
|
$Connection = new Connection(); |
262
|
|
|
$sth = $Connection->db->prepare($query); |
263
|
|
|
$sth->execute(array(':source' => $database_file)); |
264
|
|
|
} catch(PDOException $e) { |
265
|
|
|
return "error : ".$e->getMessage(); |
266
|
|
|
} |
267
|
|
|
return ''; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public static function retrieve_modes_flarmnet($database_file) { |
271
|
|
|
global $globalTransaction; |
272
|
|
|
$Common = new Common(); |
273
|
|
|
//$query = 'TRUNCATE TABLE aircraft_modes'; |
274
|
|
|
$query = "DELETE FROM aircraft_modes WHERE Source = '' OR Source IS NULL OR Source = :source"; |
275
|
|
|
try { |
276
|
|
|
$Connection = new Connection(); |
277
|
|
|
$sth = $Connection->db->prepare($query); |
278
|
|
|
$sth->execute(array(':source' => $database_file)); |
279
|
|
|
} catch(PDOException $e) { |
280
|
|
|
return "error : ".$e->getMessage(); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
if ($fh = fopen($database_file,"r")) { |
284
|
|
|
//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)'; |
285
|
|
|
$query_dest = 'INSERT INTO aircraft_modes (ModeS,Registration,ICAOTypeCode,Source,source_type) VALUES (:ModeS,:Registration,:ICAOTypeCode,:source,:source_type)'; |
286
|
|
|
|
287
|
|
|
$Connection = new Connection(); |
288
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
289
|
|
|
try { |
290
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
291
|
|
|
while (!feof($fh)) { |
292
|
|
|
$values = array(); |
293
|
|
|
$line = $Common->hex2str(fgets($fh,9999)); |
294
|
|
|
//FFFFFF RIDEAU VALLEY SOARINGASW-20 C-FBKN MZ 123.400 |
295
|
|
|
$values['ModeS'] = substr($line,0,6); |
296
|
|
|
$values['Registration'] = trim(substr($line,69,6)); |
297
|
|
|
$aircraft_name = trim(substr($line,48,6)); |
298
|
|
|
// Check if we can find ICAO, else set it to GLID |
299
|
|
|
$aircraft_name_split = explode(' ',$aircraft_name); |
300
|
|
|
$search_more = ''; |
301
|
|
|
if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'"; |
302
|
|
|
$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more; |
303
|
|
|
$sth_search = $Connection->db->prepare($query_search); |
304
|
|
|
try { |
305
|
|
|
$sth_search->execute(); |
306
|
|
|
$result = $sth_search->fetch(PDO::FETCH_ASSOC); |
307
|
|
|
//if (count($result) > 0) { |
308
|
|
|
if (isset($result['icao']) && $result['icao'] != '') { |
309
|
|
|
$values['ICAOTypeCode'] = $result['icao']; |
310
|
|
|
} |
311
|
|
|
} catch(PDOException $e) { |
312
|
|
|
return "error : ".$e->getMessage(); |
313
|
|
|
} |
314
|
|
|
if (!isset($values['ICAOTypeCode'])) $values['ICAOTypeCode'] = 'GLID'; |
315
|
|
|
// Add data to db |
316
|
|
|
if ($values['Registration'] != '' && $values['Registration'] != '0000') { |
317
|
|
|
//$query_dest_values = array(':AircraftID' => $values['AircraftID'],':FirstCreated' => $values['FirstCreated'],':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':SerialNo' => $values['SerialNo'], ':OperatorFlagCode' => $values['OperatorFlagCode'], ':Manufacturer' => $values['Manufacturer'], ':Type' => $values['Type'], ':FirstRegDate' => $values['FirstRegDate'], ':CurrentRegDate' => $values['CurrentRegDate'], ':Country' => $values['Country'], ':PreviousID' => $values['PreviousID'], ':DeRegDate' => $values['DeRegDate'], ':Status' => $values['Status'], ':PopularName' => $values['PopularName'],':GenericName' => $values['GenericName'],':AircraftClass' => $values['AircraftClass'], ':Engines' => $values['Engines'], ':OwnershipStatus' => $values['OwnershipStatus'],':RegisteredOwners' => $values['RegisteredOwners'],':MTOW' => $values['MTOW'], ':TotalHours' => $values['TotalHours'],':YearBuilt' => $values['YearBuilt'], ':CofACategory' => $values['CofACategory'], ':CofAExpiry' => $values['CofAExpiry'], ':UserNotes' => $values['UserNotes'], ':Interested' => $values['Interested'], ':UserTag' => $values['UserTag'], ':InfoUrl' => $values['InfoURL'], ':PictureUrl1' => $values['PictureURL1'], ':PictureUrl2' => $values['PictureURL2'], ':PictureUrl3' => $values['PictureURL3'], ':UserBool1' => $values['UserBool1'], ':UserBool2' => $values['UserBool2'], ':UserBool3' => $values['UserBool3'], ':UserBool4' => $values['UserBool4'], ':UserBool5' => $values['UserBool5'], ':UserString1' => $values['UserString1'], ':UserString2' => $values['UserString2'], ':UserString3' => $values['UserString3'], ':UserString4' => $values['UserString4'], ':UserString5' => $values['UserString5'], ':UserInt1' => $values['UserInt1'], ':UserInt2' => $values['UserInt2'], ':UserInt3' => $values['UserInt3'], ':UserInt4' => $values['UserInt4'], ':UserInt5' => $values['UserInt5']); |
318
|
|
|
$query_dest_values = array(':ModeS' => $values['ModeS'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file,':source_type' => 'flarm'); |
319
|
|
|
//print_r($query_dest_values); |
320
|
|
|
$sth_dest->execute($query_dest_values); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
324
|
|
|
} catch(PDOException $e) { |
325
|
|
|
return "error : ".$e->getMessage(); |
326
|
|
|
} |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
$query = "DELETE FROM aircraft_modes WHERE Source = :source AND ModeS IN (SELECT * FROM (SELECT ModeS FROM aircraft_modes WHERE Source = 'ACARS') _alias)"; |
330
|
|
|
try { |
331
|
|
|
$Connection = new Connection(); |
332
|
|
|
$sth = $Connection->db->prepare($query); |
333
|
|
|
$sth->execute(array(':source' => $database_file)); |
334
|
|
|
} catch(PDOException $e) { |
335
|
|
|
return "error : ".$e->getMessage(); |
336
|
|
|
} |
337
|
|
|
return ''; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
public static function retrieve_modes_ogn($database_file) { |
341
|
|
|
global $globalTransaction; |
342
|
|
|
//$query = 'TRUNCATE TABLE aircraft_modes'; |
343
|
|
|
$query = "DELETE FROM aircraft_modes WHERE Source = '' OR Source IS NULL OR Source = :source"; |
344
|
|
|
try { |
345
|
|
|
$Connection = new Connection(); |
346
|
|
|
$sth = $Connection->db->prepare($query); |
347
|
|
|
$sth->execute(array(':source' => $database_file)); |
348
|
|
|
} catch(PDOException $e) { |
349
|
|
|
return "error : ".$e->getMessage(); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
if ($fh = fopen($database_file,"r")) { |
353
|
|
|
//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)'; |
354
|
|
|
$query_dest = 'INSERT INTO aircraft_modes (LastModified,ModeS,Registration,ICAOTypeCode,Source,source_type) VALUES (:lastmodified,:ModeS,:Registration,:ICAOTypeCode,:source,:source_type)'; |
355
|
|
|
|
356
|
|
|
$Connection = new Connection(); |
357
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
358
|
|
|
try { |
359
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
360
|
|
|
$tmp = fgetcsv($fh,9999,',',"'"); |
|
|
|
|
361
|
|
|
while (!feof($fh)) { |
362
|
|
|
$line = fgetcsv($fh,9999,',',"'"); |
363
|
|
|
|
364
|
|
|
//FFFFFF RIDEAU VALLEY SOARINGASW-20 C-FBKN MZ 123.400 |
365
|
|
|
//print_r($line); |
366
|
|
|
$values['ModeS'] = $line[1]; |
|
|
|
|
367
|
|
|
$values['Registration'] = $line[3]; |
|
|
|
|
368
|
|
|
$values['ICAOTypeCode'] = ''; |
369
|
|
|
$aircraft_name = $line[2]; |
370
|
|
|
// Check if we can find ICAO, else set it to GLID |
371
|
|
|
$aircraft_name_split = explode(' ',$aircraft_name); |
372
|
|
|
$search_more = ''; |
373
|
|
|
if (count($aircraft_name) > 1 && strlen($aircraft_name_split[1]) > 3) $search_more .= " AND LIKE '%".$aircraft_name_split[0]."%'"; |
374
|
|
|
$query_search = "SELECT * FROM aircraft WHERE type LIKE '%".$aircraft_name."%'".$search_more; |
375
|
|
|
$sth_search = $Connection->db->prepare($query_search); |
376
|
|
|
try { |
377
|
|
|
$sth_search->execute(); |
378
|
|
|
$result = $sth_search->fetch(PDO::FETCH_ASSOC); |
379
|
|
|
if (isset($result['icao']) && $result['icao'] != '') $values['ICAOTypeCode'] = $result['icao']; |
380
|
|
|
} catch(PDOException $e) { |
381
|
|
|
return "error : ".$e->getMessage(); |
382
|
|
|
} |
383
|
|
|
//if (!isset($values['ICAOTypeCode'])) $values['ICAOTypeCode'] = 'GLID'; |
384
|
|
|
// Add data to db |
385
|
|
|
if ($values['Registration'] != '' && $values['Registration'] != '0000' && $values['ICAOTypeCode'] != '') { |
386
|
|
|
//$query_dest_values = array(':AircraftID' => $values['AircraftID'],':FirstCreated' => $values['FirstCreated'],':LastModified' => $values['LastModified'],':ModeS' => $values['ModeS'],':ModeSCountry' => $values['ModeSCountry'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':SerialNo' => $values['SerialNo'], ':OperatorFlagCode' => $values['OperatorFlagCode'], ':Manufacturer' => $values['Manufacturer'], ':Type' => $values['Type'], ':FirstRegDate' => $values['FirstRegDate'], ':CurrentRegDate' => $values['CurrentRegDate'], ':Country' => $values['Country'], ':PreviousID' => $values['PreviousID'], ':DeRegDate' => $values['DeRegDate'], ':Status' => $values['Status'], ':PopularName' => $values['PopularName'],':GenericName' => $values['GenericName'],':AircraftClass' => $values['AircraftClass'], ':Engines' => $values['Engines'], ':OwnershipStatus' => $values['OwnershipStatus'],':RegisteredOwners' => $values['RegisteredOwners'],':MTOW' => $values['MTOW'], ':TotalHours' => $values['TotalHours'],':YearBuilt' => $values['YearBuilt'], ':CofACategory' => $values['CofACategory'], ':CofAExpiry' => $values['CofAExpiry'], ':UserNotes' => $values['UserNotes'], ':Interested' => $values['Interested'], ':UserTag' => $values['UserTag'], ':InfoUrl' => $values['InfoURL'], ':PictureUrl1' => $values['PictureURL1'], ':PictureUrl2' => $values['PictureURL2'], ':PictureUrl3' => $values['PictureURL3'], ':UserBool1' => $values['UserBool1'], ':UserBool2' => $values['UserBool2'], ':UserBool3' => $values['UserBool3'], ':UserBool4' => $values['UserBool4'], ':UserBool5' => $values['UserBool5'], ':UserString1' => $values['UserString1'], ':UserString2' => $values['UserString2'], ':UserString3' => $values['UserString3'], ':UserString4' => $values['UserString4'], ':UserString5' => $values['UserString5'], ':UserInt1' => $values['UserInt1'], ':UserInt2' => $values['UserInt2'], ':UserInt3' => $values['UserInt3'], ':UserInt4' => $values['UserInt4'], ':UserInt5' => $values['UserInt5']); |
387
|
|
|
$query_dest_values = array(':lastmodified' => date('Y-m-d H:m:s'),':ModeS' => $values['ModeS'],':Registration' => $values['Registration'],':ICAOTypeCode' => $values['ICAOTypeCode'],':source' => $database_file,':source_type' => 'flarm'); |
388
|
|
|
//print_r($query_dest_values); |
389
|
|
|
$sth_dest->execute($query_dest_values); |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
393
|
|
|
} catch(PDOException $e) { |
394
|
|
|
return "error : ".$e->getMessage(); |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
$query = "DELETE FROM aircraft_modes WHERE Source = :source AND ModeS IN (SELECT * FROM (SELECT ModeS FROM aircraft_modes WHERE Source = 'ACARS') _alias)"; |
399
|
|
|
try { |
400
|
|
|
$Connection = new Connection(); |
401
|
|
|
$sth = $Connection->db->prepare($query); |
402
|
|
|
$sth->execute(array(':source' => $database_file)); |
403
|
|
|
} catch(PDOException $e) { |
404
|
|
|
return "error : ".$e->getMessage(); |
405
|
|
|
} |
406
|
|
|
return ''; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
public static function retrieve_owner($database_file,$country = 'F') { |
410
|
|
|
global $globalTransaction, $globalMasterSource; |
411
|
|
|
//$query = 'TRUNCATE TABLE aircraft_modes'; |
412
|
|
|
$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source IS NULL OR Source = :source; DELETE FROM aircraft_modes WHERE Source = :source;"; |
413
|
|
|
try { |
414
|
|
|
$Connection = new Connection(); |
415
|
|
|
$sth = $Connection->db->prepare($query); |
416
|
|
|
$sth->execute(array(':source' => $database_file)); |
417
|
|
|
} catch(PDOException $e) { |
418
|
|
|
return "error : ".$e->getMessage(); |
419
|
|
|
} |
420
|
|
|
require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
421
|
|
|
$Spotter = new Spotter(); |
422
|
|
|
if ($fh = fopen($database_file,"r")) { |
423
|
|
|
//$query_dest = 'INSERT INTO aircraft_modes (`AircraftID`,`FirstCreated`,`LastModified`, `ModeS`,`ModeSCountry`,`Registration`,`ICAOTypeCode`,`SerialNo`, `OperatorFlagCode`, `Manufacturer`, `Type`, `FirstRegDate`, `CurrentRegDate`, `Country`, `PreviousID`, `DeRegDate`, `Status`, `PopularName`,`GenericName`,`AircraftClass`, `Engines`, `OwnershipStatus`,`RegisteredOwners`,`MTOW`, `TotalHours`, `YearBuilt`, `CofACategory`, `CofAExpiry`, `UserNotes`, `Interested`, `UserTag`, `InfoUrl`, `PictureUrl1`, `PictureUrl2`, `PictureUrl3`, `UserBool1`, `UserBool2`, `UserBool3`, `UserBool4`, `UserBool5`, `UserString1`, `UserString2`, `UserString3`, `UserString4`, `UserString5`, `UserInt1`, `UserInt2`, `UserInt3`, `UserInt4`, `UserInt5`) VALUES (:AircraftID,:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:SerialNo, :OperatorFlagCode, :Manufacturer, :Type, :FirstRegDate, :CurrentRegDate, :Country, :PreviousID, :DeRegDate, :Status, :PopularName,:GenericName,:AircraftClass, :Engines, :OwnershipStatus,:RegisteredOwners,:MTOW, :TotalHours,:YearBuilt, :CofACategory, :CofAExpiry, :UserNotes, :Interested, :UserTag, :InfoUrl, :PictureUrl1, :PictureUrl2, :PictureUrl3, :UserBool1, :UserBool2, :UserBool3, :UserBool4, :UserBool5, :UserString1, :UserString2, :UserString3, :UserString4, :UserString5, :UserInt1, :UserInt2, :UserInt3, :UserInt4, :UserInt5)'; |
424
|
|
|
$query_dest = 'INSERT INTO aircraft_owner (registration,base,owner,date_first_reg,Source) VALUES (:registration,:base,:owner,:date_first_reg,:source)'; |
425
|
|
|
$query_modes = 'INSERT INTO aircraft_modes (ModeS,ModeSCountry,Registration,ICAOTypeCode,Source) VALUES (:modes,:modescountry,:registration,:icaotypecode,:source)'; |
426
|
|
|
|
427
|
|
|
$Connection = new Connection(); |
428
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
429
|
|
|
$sth_modes = $Connection->db->prepare($query_modes); |
430
|
|
|
try { |
431
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
432
|
|
|
$tmp = fgetcsv($fh,9999,',','"'); |
|
|
|
|
433
|
|
|
while (!feof($fh)) { |
434
|
|
|
$line = fgetcsv($fh,9999,',','"'); |
435
|
|
|
$values = array(); |
436
|
|
|
//print_r($line); |
437
|
|
|
if ($country == 'F') { |
438
|
|
|
$values['registration'] = $line[0]; |
439
|
|
|
$values['base'] = $line[4]; |
440
|
|
|
$values['owner'] = $line[5]; |
441
|
|
|
if ($line[6] == '') $values['date_first_reg'] = null; |
442
|
|
|
else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6])); |
443
|
|
|
$values['cancel'] = $line[7]; |
444
|
|
|
} elseif ($country == 'EI') { |
445
|
|
|
// TODO : add modeS & reg to aircraft_modes |
446
|
|
|
$values['registration'] = $line[0]; |
447
|
|
|
$values['base'] = $line[3]; |
448
|
|
|
$values['owner'] = $line[2]; |
449
|
|
|
if ($line[1] == '') $values['date_first_reg'] = null; |
450
|
|
|
else $values['date_first_reg'] = date("Y-m-d",strtotime($line[1])); |
451
|
|
|
$values['cancel'] = ''; |
452
|
|
|
$values['modes'] = $line[7]; |
453
|
|
|
$values['icao'] = $line[8]; |
454
|
|
|
|
455
|
|
|
} elseif ($country == 'HB') { |
456
|
|
|
// TODO : add modeS & reg to aircraft_modes |
457
|
|
|
$values['registration'] = $line[0]; |
458
|
|
|
$values['base'] = null; |
459
|
|
|
$values['owner'] = $line[5]; |
460
|
|
|
$values['date_first_reg'] = null; |
461
|
|
|
$values['cancel'] = ''; |
462
|
|
|
$values['modes'] = $line[4]; |
463
|
|
|
$values['icao'] = $line[7]; |
464
|
|
|
} elseif ($country == 'OK') { |
465
|
|
|
// TODO : add modeS & reg to aircraft_modes |
466
|
|
|
$values['registration'] = $line[3]; |
467
|
|
|
$values['base'] = null; |
468
|
|
|
$values['owner'] = $line[5]; |
469
|
|
|
if ($line[18] == '') $values['date_first_reg'] = null; |
470
|
|
|
else $values['date_first_reg'] = date("Y-m-d",strtotime($line[18])); |
471
|
|
|
$values['cancel'] = ''; |
472
|
|
|
} elseif ($country == 'VH') { |
473
|
|
|
// TODO : add modeS & reg to aircraft_modes |
474
|
|
|
$values['registration'] = $line[0]; |
475
|
|
|
$values['base'] = null; |
476
|
|
|
$values['owner'] = $line[12]; |
477
|
|
|
if ($line[28] == '') $values['date_first_reg'] = null; |
478
|
|
|
else $values['date_first_reg'] = date("Y-m-d",strtotime($line[28])); |
479
|
|
|
|
480
|
|
|
$values['cancel'] = $line[39]; |
481
|
|
|
} elseif ($country == 'OE' || $country == '9A' || $country == 'VP' || $country == 'LX' || $country == 'P2' || $country == 'HC') { |
482
|
|
|
$values['registration'] = $line[0]; |
483
|
|
|
$values['base'] = null; |
484
|
|
|
$values['owner'] = $line[4]; |
485
|
|
|
$values['date_first_reg'] = null; |
486
|
|
|
$values['cancel'] = ''; |
487
|
|
|
} elseif ($country == 'CC') { |
488
|
|
|
$values['registration'] = $line[0]; |
489
|
|
|
$values['base'] = null; |
490
|
|
|
$values['owner'] = $line[6]; |
491
|
|
|
$values['date_first_reg'] = null; |
492
|
|
|
$values['cancel'] = ''; |
493
|
|
|
} elseif ($country == 'HJ') { |
494
|
|
|
$values['registration'] = $line[0]; |
495
|
|
|
$values['base'] = null; |
496
|
|
|
$values['owner'] = $line[8]; |
497
|
|
|
if ($line[7] == '') $values['date_first_reg'] = null; |
498
|
|
|
else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7])); |
499
|
|
|
$values['cancel'] = ''; |
500
|
|
|
} elseif ($country == 'PP') { |
501
|
|
|
$values['registration'] = $line[0]; |
502
|
|
|
$values['base'] = null; |
503
|
|
|
$values['owner'] = $line[4]; |
504
|
|
|
if ($line[6] == '') $values['date_first_reg'] = null; |
505
|
|
|
else $values['date_first_reg'] = date("Y-m-d",strtotime($line[6])); |
506
|
|
|
$values['cancel'] = $line[7]; |
507
|
|
|
} elseif ($country == 'E7') { |
508
|
|
|
$values['registration'] = $line[0]; |
509
|
|
|
$values['base'] = null; |
510
|
|
|
$values['owner'] = $line[4]; |
511
|
|
|
if ($line[5] == '') $values['date_first_reg'] = null; |
512
|
|
|
else $values['date_first_reg'] = date("Y-m-d",strtotime($line[5])); |
513
|
|
|
$values['cancel'] = ''; |
514
|
|
|
} elseif ($country == '8Q') { |
515
|
|
|
$values['registration'] = $line[0]; |
516
|
|
|
$values['base'] = null; |
517
|
|
|
$values['owner'] = $line[3]; |
518
|
|
|
if ($line[7] == '') $values['date_first_reg'] = null; |
519
|
|
|
else $values['date_first_reg'] = date("Y-m-d",strtotime($line[7])); |
520
|
|
|
$values['cancel'] = ''; |
521
|
|
|
} elseif ($country == 'ZK') { |
522
|
|
|
$values['registration'] = $line[0]; |
523
|
|
|
$values['base'] = null; |
524
|
|
|
$values['owner'] = $line[3]; |
525
|
|
|
$values['date_first_reg'] = null; |
526
|
|
|
$values['cancel'] = ''; |
527
|
|
|
$values['modes'] = $line[5]; |
528
|
|
|
$values['icao'] = $line[9]; |
529
|
|
|
} elseif ($country == 'M') { |
530
|
|
|
$values['registration'] = $line[0]; |
531
|
|
|
$values['base'] = null; |
532
|
|
|
$values['owner'] = $line[6]; |
533
|
|
|
$values['date_first_reg'] = date("Y-m-d",strtotime($line[5])); |
534
|
|
|
$values['cancel'] = date("Y-m-d",strtotime($line[8])); |
535
|
|
|
$values['modes'] = $line[4]; |
536
|
|
|
$values['icao'] = $line[10]; |
537
|
|
|
} elseif ($country == 'OY') { |
538
|
|
|
$values['registration'] = $line[0]; |
539
|
|
|
$values['date_first_reg'] = date("Y-m-d",strtotime($line[4])); |
540
|
|
|
$values['modes'] = $line[5]; |
541
|
|
|
$values['icao'] = $line[6]; |
542
|
|
|
} elseif ($country == 'PH') { |
543
|
|
|
$values['registration'] = $line[0]; |
544
|
|
|
$values['date_first_reg'] = date("Y-m-d",strtotime($line[3])); |
545
|
|
|
$values['modes'] = $line[4]; |
546
|
|
|
$values['icao'] = $line[5]; |
547
|
|
|
} elseif ($country == 'OM' || $country == 'TF') { |
548
|
|
|
$values['registration'] = $line[0]; |
549
|
|
|
$values['base'] = null; |
550
|
|
|
$values['owner'] = $line[3]; |
551
|
|
|
$values['date_first_reg'] = null; |
552
|
|
|
$values['cancel'] = ''; |
553
|
|
|
} |
554
|
|
|
if (isset($values['cancel']) && $values['cancel'] == '' && $values['registration'] != null && isset($values['owner'])) { |
555
|
|
|
$query_dest_values = array(':registration' => $values['registration'],':base' => $values['base'],':date_first_reg' => $values['date_first_reg'],':owner' => $values['owner'],':source' => $database_file); |
556
|
|
|
$sth_dest->execute($query_dest_values); |
557
|
|
|
} |
558
|
|
|
if ($globalMasterSource && $values['registration'] != null && isset($values['modes']) && $values['modes'] != '') { |
559
|
|
|
$modescountry = $Spotter->countryFromAircraftRegistration($values['registration']); |
560
|
|
|
$query_modes_values = array(':registration' => $values['registration'],':modes' => $values['modes'],':modescountry' => $modescountry,':icaotypecode' => $values['icao'],':source' => $database_file); |
561
|
|
|
$sth_modes->execute($query_modes_values); |
562
|
|
|
} |
563
|
|
|
} |
564
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
565
|
|
|
} catch(PDOException $e) { |
566
|
|
|
return "error : ".$e->getMessage(); |
567
|
|
|
} |
568
|
|
|
} |
569
|
|
|
return ''; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
/* |
573
|
|
|
* This function is used to create a list of airports. Sources : Wikipedia, ourairports.com ans partow.net |
574
|
|
|
*/ |
575
|
|
|
public static function update_airports() { |
576
|
|
|
global $tmp_dir, $globalTransaction, $globalDebug; |
577
|
|
|
|
578
|
|
|
require_once(dirname(__FILE__).'/libs/sparqllib.php'); |
579
|
|
|
$db = sparql_connect('http://dbpedia.org/sparql'); |
|
|
|
|
580
|
|
|
$query = ' |
581
|
|
|
PREFIX dbo: <http://dbpedia.org/ontology/> |
582
|
|
|
PREFIX dbp: <http://dbpedia.org/property/> |
583
|
|
|
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> |
584
|
|
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
585
|
|
|
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> |
586
|
|
|
SELECT ?name ?icao ?iata ?faa ?lid ?latitude ?longitude ?airport ?homepage ?type ?country ?country_bis ?altitude ?image |
587
|
|
|
FROM <http://dbpedia.org> |
588
|
|
|
WHERE { |
589
|
|
|
?airport rdf:type <http://dbpedia.org/ontology/Airport> . |
590
|
|
|
|
591
|
|
|
OPTIONAL { |
592
|
|
|
?airport dbo:icaoLocationIdentifier ?icao . |
593
|
|
|
FILTER regex(?icao, "^[A-Z0-9]{4}$") |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
OPTIONAL { |
597
|
|
|
?airport dbo:iataLocationIdentifier ?iata . |
598
|
|
|
FILTER regex(?iata, "^[A-Z0-9]{3}$") |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
OPTIONAL { |
602
|
|
|
?airport dbo:locationIdentifier ?lid . |
603
|
|
|
FILTER regex(?lid, "^[A-Z0-9]{4}$") |
604
|
|
|
FILTER (!bound(?icao) || (bound(?icao) && (?icao != ?lid))) |
605
|
|
|
OPTIONAL { |
606
|
|
|
?airport_y rdf:type <http://dbpedia.org/ontology/Airport> . |
607
|
|
|
?airport_y dbo:icaoLocationIdentifier ?other_icao . |
608
|
|
|
FILTER (bound(?lid) && (?airport_y != ?airport && ?lid = ?other_icao)) |
609
|
|
|
} |
610
|
|
|
FILTER (!bound(?other_icao)) |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
OPTIONAL { |
614
|
|
|
?airport dbo:faaLocationIdentifier ?faa . |
615
|
|
|
FILTER regex(?faa, "^[A-Z0-9]{3}$") |
616
|
|
|
FILTER (!bound(?iata) || (bound(?iata) && (?iata != ?faa))) |
617
|
|
|
OPTIONAL { |
618
|
|
|
?airport_x rdf:type <http://dbpedia.org/ontology/Airport> . |
619
|
|
|
?airport_x dbo:iataLocationIdentifier ?other_iata . |
620
|
|
|
FILTER (bound(?faa) && (?airport_x != ?airport && ?faa = ?other_iata)) |
621
|
|
|
} |
622
|
|
|
FILTER (!bound(?other_iata)) |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
FILTER (bound(?icao) || bound(?iata) || bound(?faa) || bound(?lid)) |
626
|
|
|
|
627
|
|
|
OPTIONAL { |
628
|
|
|
?airport rdfs:label ?name |
629
|
|
|
FILTER (lang(?name) = "en") |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
OPTIONAL { |
633
|
|
|
?airport foaf:homepage ?homepage |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
OPTIONAL { |
637
|
|
|
?airport dbp:coordinatesRegion ?country |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
OPTIONAL { |
641
|
|
|
?airport dbp:type ?type |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
OPTIONAL { |
645
|
|
|
?airport dbo:elevation ?altitude |
646
|
|
|
} |
647
|
|
|
OPTIONAL { |
648
|
|
|
?airport dbp:image ?image |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
{ |
652
|
|
|
?airport geo:lat ?latitude . |
653
|
|
|
?airport geo:long ?longitude . |
654
|
|
|
FILTER (datatype(?latitude) = xsd:float) |
655
|
|
|
FILTER (datatype(?longitude) = xsd:float) |
656
|
|
|
} UNION { |
657
|
|
|
?airport geo:lat ?latitude . |
658
|
|
|
?airport geo:long ?longitude . |
659
|
|
|
FILTER (datatype(?latitude) = xsd:double) |
660
|
|
|
FILTER (datatype(?longitude) = xsd:double) |
661
|
|
|
OPTIONAL { |
662
|
|
|
?airport geo:lat ?lat_f . |
663
|
|
|
?airport geo:long ?long_f . |
664
|
|
|
FILTER (datatype(?lat_f) = xsd:float) |
665
|
|
|
FILTER (datatype(?long_f) = xsd:float) |
666
|
|
|
} |
667
|
|
|
FILTER (!bound(?lat_f) && !bound(?long_f)) |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
} |
671
|
|
|
ORDER BY ?airport |
672
|
|
|
'; |
673
|
|
|
$result = sparql_query($query); |
674
|
|
|
|
675
|
|
|
/* |
676
|
|
|
$query = 'TRUNCATE TABLE airport'; |
677
|
|
|
try { |
678
|
|
|
$Connection = new Connection(); |
679
|
|
|
$sth = $Connection->db->prepare($query); |
680
|
|
|
$sth->execute(); |
681
|
|
|
} catch(PDOException $e) { |
682
|
|
|
return "error : ".$e->getMessage(); |
683
|
|
|
} |
684
|
|
|
*/ |
685
|
|
|
/* |
686
|
|
|
$query = 'ALTER TABLE airport DROP INDEX icaoidx'; |
687
|
|
|
try { |
688
|
|
|
$Connection = new Connection(); |
689
|
|
|
$sth = $Connection->db->prepare($query); |
690
|
|
|
$sth->execute(); |
691
|
|
|
} catch(PDOException $e) { |
692
|
|
|
return "error : ".$e->getMessage(); |
693
|
|
|
} |
694
|
|
|
*/ |
695
|
|
|
|
696
|
|
|
$query_dest = "INSERT INTO airport (name,city,country,iata,icao,latitude,longitude,altitude,type,home_link,wikipedia_link,image_thumb,image) |
697
|
|
|
VALUES (:name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link, :image_thumb, :image)"; |
698
|
|
|
$Connection = new Connection(); |
699
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
700
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
701
|
|
|
|
702
|
|
|
$i = 0; |
703
|
|
|
while($row = sparql_fetch_array($result)) |
704
|
|
|
{ |
705
|
|
|
if ($i >= 1) { |
706
|
|
|
//print_r($row); |
707
|
|
|
if (!isset($row['iata'])) $row['iata'] = ''; |
708
|
|
|
if (!isset($row['icao'])) $row['icao'] = ''; |
709
|
|
|
if (!isset($row['type'])) $row['type'] = ''; |
710
|
|
|
if (!isset($row['altitude'])) $row['altitude'] = ''; |
711
|
|
|
if (isset($row['city_bis'])) { |
712
|
|
|
$row['city'] = $row['city_bis']; |
713
|
|
|
} |
714
|
|
|
if (!isset($row['city'])) $row['city'] = ''; |
715
|
|
|
if (!isset($row['country'])) $row['country'] = ''; |
716
|
|
|
if (!isset($row['homepage'])) $row['homepage'] = ''; |
717
|
|
|
if (!isset($row['wikipedia_page'])) $row['wikipedia_page'] = ''; |
718
|
|
|
if (!isset($row['name'])) continue; |
719
|
|
|
if (!isset($row['image'])) { |
720
|
|
|
$row['image'] = ''; |
721
|
|
|
$row['image_thumb'] = ''; |
722
|
|
|
} else { |
723
|
|
|
$image = str_replace(' ','_',$row['image']); |
724
|
|
|
$digest = md5($image); |
725
|
|
|
$folder = $digest[0] . '/' . $digest[0] . $digest[1] . '/' . $image . '/220px-' . $image; |
726
|
|
|
$row['image_thumb'] = 'http://upload.wikimedia.org/wikipedia/commons/thumb/' . $folder; |
727
|
|
|
$folder = $digest[0] . '/' . $digest[0] . $digest[1] . '/' . $image; |
728
|
|
|
$row['image'] = 'http://upload.wikimedia.org/wikipedia/commons/' . $folder; |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
$country = explode('-',$row['country']); |
732
|
|
|
$row['country'] = $country[0]; |
733
|
|
|
|
734
|
|
|
$row['type'] = trim($row['type']); |
735
|
|
|
if ($row['type'] == 'Military: Naval Auxiliary Air Station' || $row['type'] == 'http://dbpedia.org/resource/Naval_air_station' || $row['type'] == 'Military: Naval Air Station' || $row['type'] == 'Military Northern Fleet' || $row['type'] == 'Military and industrial' || $row['type'] == 'Military: Royal Air Force station' || $row['type'] == 'http://dbpedia.org/resource/Military_airbase' || $row['type'] == 'Military: Naval air station' || preg_match('/air base/i',$row['name'])) { |
736
|
|
|
$row['type'] = 'military'; |
737
|
|
|
} elseif ($row['type'] == 'http://dbpedia.org/resource/Airport' || $row['type'] == 'Civil' || $row['type'] == 'Public use' || $row['type'] == 'Public' || $row['type'] == 'http://dbpedia.org/resource/Civilian' || $row['type'] == 'Public, Civilian' || $row['type'] == 'Public / Military' || $row['type'] == 'Private & Civilian' || $row['type'] == 'Civilian and Military' || $row['type'] == 'Public/military' || $row['type'] == 'Active With Few Facilities' || $row['type'] == '?ivilian' || $row['type'] == 'Civil/Military' || $row['type'] == 'NA' || $row['type'] == 'Public/Military') { |
738
|
|
|
$row['type'] = 'small_airport'; |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
$row['city'] = urldecode(str_replace('_',' ',str_replace('http://dbpedia.org/resource/','',$row['city']))); |
742
|
|
|
$query_dest_values = array(':name' => $row['name'],':iata' => $row['iata'],':icao' => $row['icao'],':latitude' => $row['latitude'],':longitude' => $row['longitude'],':altitude' => round($row['altitude']),':type' => $row['type'],':city' => $row['city'],':country' => $row['country'],':home_link' => $row['homepage'],':wikipedia_link' => $row['wikipedia_page'],':image' => $row['image'],':image_thumb' => $row['image_thumb']); |
743
|
|
|
//print_r($query_dest_values); |
744
|
|
|
|
745
|
|
|
if ($row['icao'] != '') { |
746
|
|
|
try { |
747
|
|
|
$sth = $Connection->db->prepare('SELECT COUNT(*) FROM airport WHERE icao = :icao'); |
748
|
|
|
$sth->execute(array(':icao' => $row['icao'])); |
749
|
|
|
} catch(PDOException $e) { |
750
|
|
|
return "error : ".$e->getMessage(); |
751
|
|
|
} |
752
|
|
|
if ($sth->fetchColumn() > 0) { |
753
|
|
|
// Update ? |
754
|
|
|
$query = 'UPDATE airport SET type = :type WHERE icao = :icao'; |
755
|
|
|
try { |
756
|
|
|
$sth = $Connection->db->prepare($query); |
757
|
|
|
$sth->execute(array(':icao' => $row['icao'],':type' => $row['type'])); |
758
|
|
|
} catch(PDOException $e) { |
759
|
|
|
return "error : ".$e->getMessage(); |
760
|
|
|
} |
761
|
|
|
echo $row['icao'].' : '.$row['type']."\n"; |
762
|
|
|
} else { |
763
|
|
|
try { |
764
|
|
|
$sth_dest->execute($query_dest_values); |
765
|
|
|
} catch(PDOException $e) { |
766
|
|
|
return "error : ".$e->getMessage(); |
767
|
|
|
} |
768
|
|
|
} |
769
|
|
|
} |
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
$i++; |
773
|
|
|
} |
774
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
775
|
|
|
/* |
776
|
|
|
echo "Delete duplicate rows...\n"; |
777
|
|
|
$query = 'ALTER IGNORE TABLE airport ADD UNIQUE INDEX icaoidx (icao)'; |
778
|
|
|
try { |
779
|
|
|
$Connection = new Connection(); |
780
|
|
|
$sth = $Connection->db->prepare($query); |
781
|
|
|
$sth->execute(); |
782
|
|
|
} catch(PDOException $e) { |
783
|
|
|
return "error : ".$e->getMessage(); |
784
|
|
|
} |
785
|
|
|
*/ |
786
|
|
|
|
787
|
|
|
|
788
|
|
|
/* |
789
|
|
|
if ($globalDebug) echo "Insert Not available Airport...\n"; |
790
|
|
|
$query = "INSERT INTO airport (airport_id,name,city,country,iata,icao,latitude,longitude,altitude,type,home_link,wikipedia_link,image,image_thumb) |
791
|
|
|
VALUES (:airport_id, :name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link, :image, :image_thumb)"; |
792
|
|
|
$query_values = array(':airport_id' => $i, ':name' => 'Not available',':iata' => 'NA',':icao' => 'NA',':latitude' => '0',':longitude' => '0',':altitude' => '0',':type' => 'NA',':city' => 'N/A',':country' => 'N/A',':home_link' => '',':wikipedia_link' => '',':image' => '',':image_thumb' => ''); |
793
|
|
|
try { |
794
|
|
|
$Connection = new Connection(); |
795
|
|
|
$sth = $Connection->db->prepare($query); |
796
|
|
|
$sth->execute($query_values); |
797
|
|
|
} catch(PDOException $e) { |
798
|
|
|
return "error : ".$e->getMessage(); |
799
|
|
|
} |
800
|
|
|
*/ |
801
|
|
|
$i++; |
802
|
|
|
/* |
803
|
|
|
$query = 'DELETE FROM airport WHERE airport_id IN (SELECT * FROM (SELECT min(a.airport_id) FROM airport a GROUP BY a.icao) x)'; |
804
|
|
|
try { |
805
|
|
|
$Connection = new Connection(); |
806
|
|
|
$sth = $Connection->db->prepare($query); |
807
|
|
|
$sth->execute(); |
808
|
|
|
} catch(PDOException $e) { |
809
|
|
|
return "error : ".$e->getMessage(); |
810
|
|
|
} |
811
|
|
|
*/ |
812
|
|
|
|
813
|
|
|
echo "Download data from ourairports.com...\n"; |
814
|
|
|
$delimiter = ','; |
815
|
|
|
$out_file = $tmp_dir.'airports.csv'; |
816
|
|
|
update_db::download('http://ourairports.com/data/airports.csv',$out_file); |
817
|
|
|
if (!file_exists($out_file) || !is_readable($out_file)) return FALSE; |
818
|
|
|
echo "Add data from ourairports.com...\n"; |
819
|
|
|
|
820
|
|
|
$header = NULL; |
821
|
|
|
if (($handle = fopen($out_file, 'r')) !== FALSE) |
822
|
|
|
{ |
823
|
|
|
$Connection = new Connection(); |
824
|
|
|
//$Connection->db->beginTransaction(); |
825
|
|
|
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
826
|
|
|
{ |
827
|
|
|
if(!$header) $header = $row; |
828
|
|
|
else { |
829
|
|
|
$data = array(); |
|
|
|
|
830
|
|
|
$data = array_combine($header, $row); |
831
|
|
|
try { |
832
|
|
|
$sth = $Connection->db->prepare('SELECT COUNT(*) FROM airport WHERE icao = :icao'); |
833
|
|
|
$sth->execute(array(':icao' => $data['ident'])); |
834
|
|
|
} catch(PDOException $e) { |
835
|
|
|
return "error : ".$e->getMessage(); |
836
|
|
|
} |
837
|
|
|
if ($sth->fetchColumn() > 0) { |
838
|
|
|
$query = 'UPDATE airport SET type = :type WHERE icao = :icao'; |
839
|
|
|
try { |
840
|
|
|
$sth = $Connection->db->prepare($query); |
841
|
|
|
$sth->execute(array(':icao' => $data['ident'],':type' => $data['type'])); |
842
|
|
|
} catch(PDOException $e) { |
843
|
|
|
return "error : ".$e->getMessage(); |
844
|
|
|
} |
845
|
|
|
} else { |
846
|
|
|
if ($data['gps_code'] == $data['ident']) { |
847
|
|
|
$query = "INSERT INTO airport (name,city,country,iata,icao,latitude,longitude,altitude,type,home_link,wikipedia_link) |
848
|
|
|
VALUES (:name, :city, :country, :iata, :icao, :latitude, :longitude, :altitude, :type, :home_link, :wikipedia_link)"; |
849
|
|
|
$query_values = array(':name' => $data['name'],':iata' => $data['iata_code'],':icao' => $data['gps_code'],':latitude' => $data['latitude_deg'],':longitude' => $data['longitude_deg'],':altitude' => round($data['elevation_ft']),':type' => $data['type'],':city' => $data['municipality'],':country' => $data['iso_country'],':home_link' => $data['home_link'],':wikipedia_link' => $data['wikipedia_link']); |
850
|
|
|
try { |
851
|
|
|
$sth = $Connection->db->prepare($query); |
852
|
|
|
$sth->execute($query_values); |
853
|
|
|
} catch(PDOException $e) { |
854
|
|
|
return "error : ".$e->getMessage(); |
855
|
|
|
} |
856
|
|
|
$i++; |
857
|
|
|
} |
858
|
|
|
} |
859
|
|
|
} |
860
|
|
|
} |
861
|
|
|
fclose($handle); |
862
|
|
|
//$Connection->db->commit(); |
863
|
|
|
} |
864
|
|
|
|
865
|
|
|
|
866
|
|
|
echo "Download data from another free database...\n"; |
867
|
|
|
$out_file = $tmp_dir.'GlobalAirportDatabase.zip'; |
868
|
|
|
update_db::download('http://www.partow.net/downloads/GlobalAirportDatabase.zip',$out_file); |
869
|
|
|
if (!file_exists($out_file) || !is_readable($out_file)) return FALSE; |
870
|
|
|
update_db::unzip($out_file); |
871
|
|
|
$header = NULL; |
872
|
|
|
echo "Add data from another free database...\n"; |
873
|
|
|
$delimiter = ':'; |
874
|
|
|
$Connection = new Connection(); |
875
|
|
|
if (($handle = fopen($tmp_dir.'GlobalAirportDatabase.txt', 'r')) !== FALSE) |
876
|
|
|
{ |
877
|
|
|
//$Connection->db->beginTransaction(); |
878
|
|
|
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
879
|
|
|
{ |
880
|
|
|
if(!$header) $header = $row; |
881
|
|
|
else { |
882
|
|
|
$data = $row; |
883
|
|
|
|
884
|
|
|
$query = 'UPDATE airport SET city = :city, country = :country WHERE icao = :icao'; |
885
|
|
|
try { |
886
|
|
|
$sth = $Connection->db->prepare($query); |
887
|
|
|
$sth->execute(array(':icao' => $data[0],':city' => ucwords(strtolower($data[3])),':country' => ucwords(strtolower($data[4])))); |
888
|
|
|
} catch(PDOException $e) { |
889
|
|
|
return "error : ".$e->getMessage(); |
890
|
|
|
} |
891
|
|
|
} |
892
|
|
|
} |
893
|
|
|
fclose($handle); |
894
|
|
|
//$Connection->db->commit(); |
895
|
|
|
} |
896
|
|
|
|
897
|
|
|
echo "Put type military for all air base"; |
898
|
|
|
$Connection = new Connection(); |
899
|
|
|
try { |
900
|
|
|
$sth = $Connection->db->prepare("SELECT icao FROM airport WHERE name LIKE '%Air Base%'"); |
901
|
|
|
$sth->execute(); |
902
|
|
|
} catch(PDOException $e) { |
903
|
|
|
return "error : ".$e->getMessage(); |
904
|
|
|
} |
905
|
|
|
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { |
906
|
|
|
$query2 = 'UPDATE airport SET type = :type WHERE icao = :icao'; |
907
|
|
|
try { |
908
|
|
|
$sth2 = $Connection->db->prepare($query2); |
909
|
|
|
$sth2->execute(array(':icao' => $row['icao'],':type' => 'military')); |
910
|
|
|
} catch(PDOException $e) { |
911
|
|
|
return "error : ".$e->getMessage(); |
912
|
|
|
} |
913
|
|
|
} |
914
|
|
|
return "success"; |
915
|
|
|
} |
916
|
|
|
|
917
|
|
|
public static function translation() { |
918
|
|
|
require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
919
|
|
|
global $tmp_dir, $globalTransaction; |
920
|
|
|
$Spotter = new Spotter(); |
921
|
|
|
//$out_file = $tmp_dir.'translation.zip'; |
922
|
|
|
//update_db::download('http://www.acarsd.org/download/translation.php',$out_file); |
923
|
|
|
//if (!file_exists($out_file) || !is_readable($out_file)) return FALSE; |
924
|
|
|
|
925
|
|
|
//$query = 'TRUNCATE TABLE translation'; |
926
|
|
|
$query = "DELETE FROM translation WHERE Source = '' OR Source = :source"; |
927
|
|
|
try { |
928
|
|
|
$Connection = new Connection(); |
929
|
|
|
$sth = $Connection->db->prepare($query); |
930
|
|
|
$sth->execute(array(':source' => 'translation.csv')); |
931
|
|
|
} catch(PDOException $e) { |
932
|
|
|
return "error : ".$e->getMessage(); |
933
|
|
|
} |
934
|
|
|
|
935
|
|
|
|
936
|
|
|
//update_db::unzip($out_file); |
937
|
|
|
$header = NULL; |
|
|
|
|
938
|
|
|
$delimiter = ';'; |
939
|
|
|
$Connection = new Connection(); |
940
|
|
|
if (($handle = fopen($tmp_dir.'translation.csv', 'r')) !== FALSE) |
941
|
|
|
{ |
942
|
|
|
$i = 0; |
943
|
|
|
//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); |
944
|
|
|
//$Connection->db->beginTransaction(); |
945
|
|
|
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
946
|
|
|
{ |
947
|
|
|
$i++; |
948
|
|
|
if($i > 12) { |
949
|
|
|
$data = $row; |
950
|
|
|
$operator = $data[2]; |
951
|
|
|
if ($operator != '' && is_numeric(substr(substr($operator, 0, 3), -1, 1))) { |
952
|
|
|
$airline_array = $Spotter->getAllAirlineInfo(substr($operator, 0, 2)); |
953
|
|
|
//echo substr($operator, 0, 2)."\n";; |
954
|
|
|
if (count($airline_array) > 0) { |
955
|
|
|
//print_r($airline_array); |
956
|
|
|
$operator = $airline_array[0]['icao'].substr($operator,2); |
957
|
|
|
} |
958
|
|
|
} |
959
|
|
|
|
960
|
|
|
$operator_correct = $data[3]; |
961
|
|
|
if ($operator_correct != '' && is_numeric(substr(substr($operator_correct, 0, 3), -1, 1))) { |
962
|
|
|
$airline_array = $Spotter->getAllAirlineInfo(substr($operator_correct, 0, 2)); |
963
|
|
|
if (count($airline_array) > 0) { |
964
|
|
|
$operator_correct = $airline_array[0]['icao'].substr($operator_correct,2); |
965
|
|
|
} |
966
|
|
|
} |
967
|
|
|
$query = 'INSERT INTO translation (Reg,Reg_correct,Operator,Operator_correct,Source) VALUES (:Reg, :Reg_correct, :Operator, :Operator_correct, :source)'; |
968
|
|
|
try { |
969
|
|
|
$sth = $Connection->db->prepare($query); |
970
|
|
|
$sth->execute(array(':Reg' => $data[0],':Reg_correct' => $data[1],':Operator' => $operator,':Operator_correct' => $operator_correct, ':source' => 'translation.csv')); |
971
|
|
|
} catch(PDOException $e) { |
972
|
|
|
return "error : ".$e->getMessage(); |
973
|
|
|
} |
974
|
|
|
} |
975
|
|
|
} |
976
|
|
|
fclose($handle); |
977
|
|
|
//$Connection->db->commit(); |
978
|
|
|
} |
979
|
|
|
return ''; |
980
|
|
|
} |
981
|
|
|
|
982
|
|
|
public static function translation_fam() { |
983
|
|
|
global $tmp_dir, $globalTransaction; |
984
|
|
|
$query = "DELETE FROM translation WHERE Source = '' OR Source = :source"; |
985
|
|
|
try { |
986
|
|
|
$Connection = new Connection(); |
987
|
|
|
$sth = $Connection->db->prepare($query); |
988
|
|
|
$sth->execute(array(':source' => 'website_fam')); |
989
|
|
|
} catch(PDOException $e) { |
990
|
|
|
return "error : ".$e->getMessage(); |
991
|
|
|
} |
992
|
|
|
//update_db::unzip($out_file); |
993
|
|
|
$header = NULL; |
|
|
|
|
994
|
|
|
$delimiter = "\t"; |
995
|
|
|
$Connection = new Connection(); |
996
|
|
|
if (($handle = fopen($tmp_dir.'translation.tsv', 'r')) !== FALSE) |
997
|
|
|
{ |
998
|
|
|
$i = 0; |
999
|
|
|
//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); |
1000
|
|
|
//$Connection->db->beginTransaction(); |
1001
|
|
|
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1002
|
|
|
{ |
1003
|
|
|
if ($i > 0) { |
1004
|
|
|
$query = 'INSERT INTO translation (Reg,Reg_correct,Operator,Operator_correct,Source) VALUES (:Reg, :Reg_correct, :Operator, :Operator_correct, :source)'; |
1005
|
|
|
try { |
1006
|
|
|
$sth = $Connection->db->prepare($query); |
1007
|
|
|
$sth->execute(array(':Reg' => $data[0],':Reg_correct' => $data[1],':Operator' => $data[2],':Operator_correct' => $data[3], ':source' => 'website_fam')); |
1008
|
|
|
} catch(PDOException $e) { |
1009
|
|
|
return "error : ".$e->getMessage(); |
1010
|
|
|
} |
1011
|
|
|
} |
1012
|
|
|
$i++; |
1013
|
|
|
} |
1014
|
|
|
fclose($handle); |
1015
|
|
|
//$Connection->db->commit(); |
1016
|
|
|
} |
1017
|
|
|
return ''; |
1018
|
|
|
} |
1019
|
|
|
|
1020
|
|
|
/* |
1021
|
|
|
* This function use FAA public data. |
1022
|
|
|
* With the help of data from other source, Mfr id is added to manufacturer table. Then ModeS with ICAO are added based on that. |
1023
|
|
|
*/ |
1024
|
|
|
public static function modes_faa() { |
1025
|
|
|
global $tmp_dir, $globalTransaction, $globalDebug; |
1026
|
|
|
$query = "DELETE FROM aircraft_modes WHERE Source = '' OR Source = :source"; |
1027
|
|
|
try { |
1028
|
|
|
$Connection = new Connection(); |
1029
|
|
|
$sth = $Connection->db->prepare($query); |
1030
|
|
|
$sth->execute(array(':source' => 'website_faa')); |
1031
|
|
|
} catch(PDOException $e) { |
1032
|
|
|
return "error : ".$e->getMessage(); |
1033
|
|
|
} |
1034
|
|
|
|
1035
|
|
|
$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source = :source"; |
1036
|
|
|
try { |
1037
|
|
|
$Connection = new Connection(); |
1038
|
|
|
$sth = $Connection->db->prepare($query); |
1039
|
|
|
$sth->execute(array(':source' => 'website_faa')); |
1040
|
|
|
} catch(PDOException $e) { |
1041
|
|
|
return "error : ".$e->getMessage(); |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
$delimiter = ","; |
1045
|
|
|
$mfr = array(); |
|
|
|
|
1046
|
|
|
$Connection = new Connection(); |
1047
|
|
|
if (($handle = fopen($tmp_dir.'MASTER.txt', 'r')) !== FALSE) |
1048
|
|
|
{ |
1049
|
|
|
$i = 0; |
1050
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1051
|
|
|
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1052
|
|
|
{ |
1053
|
|
|
if ($i > 0) { |
1054
|
|
|
$query_search = 'SELECT icaotypecode FROM aircraft_modes WHERE registration = :registration AND Source <> :source LIMIT 1'; |
1055
|
|
|
try { |
1056
|
|
|
$sths = $Connection->db->prepare($query_search); |
1057
|
|
|
$sths->execute(array(':registration' => 'N'.$data[0],':source' => 'website_faa')); |
1058
|
|
|
} catch(PDOException $e) { |
1059
|
|
|
return "error s : ".$e->getMessage(); |
1060
|
|
|
} |
1061
|
|
|
$result_search = $sths->fetchAll(PDO::FETCH_ASSOC); |
1062
|
|
|
if (!empty($result_search)) { |
1063
|
|
|
if ($globalDebug) echo '.'; |
1064
|
|
|
//if ($globalDBdriver == 'mysql') { |
1065
|
|
|
// $queryi = 'INSERT INTO faamfr (mfr,icao) VALUES (:mfr,:icao) ON DUPLICATE KEY UPDATE icao = :icao'; |
1066
|
|
|
//} else { |
1067
|
|
|
$queryi = "INSERT INTO faamfr (mfr,icao) SELECT :mfr,:icao WHERE NOT EXISTS (SELECT 1 FROM faamfr WHERE mfr = :mfr);"; |
1068
|
|
|
//} |
1069
|
|
|
try { |
1070
|
|
|
$sthi = $Connection->db->prepare($queryi); |
1071
|
|
|
$sthi->execute(array(':mfr' => $data[2],':icao' => $result_search[0]['icaotypecode'])); |
1072
|
|
|
} catch(PDOException $e) { |
1073
|
|
|
return "error u : ".$e->getMessage(); |
1074
|
|
|
} |
1075
|
|
|
} else { |
1076
|
|
|
$query_search_mfr = 'SELECT icao FROM faamfr WHERE mfr = :mfr'; |
1077
|
|
|
try { |
1078
|
|
|
$sthsm = $Connection->db->prepare($query_search_mfr); |
1079
|
|
|
$sthsm->execute(array(':mfr' => $data[2])); |
1080
|
|
|
} catch(PDOException $e) { |
1081
|
|
|
return "error mfr : ".$e->getMessage(); |
1082
|
|
|
} |
1083
|
|
|
$result_search_mfr = $sthsm->fetchAll(PDO::FETCH_ASSOC); |
1084
|
|
|
if (!empty($result_search_mfr)) { |
1085
|
|
|
if (trim($data[16]) == '' && trim($data[23]) != '') $data[16] = $data[23]; |
1086
|
|
|
if (trim($data[16]) == '' && trim($data[15]) != '') $data[16] = $data[15]; |
1087
|
|
|
$queryf = 'INSERT INTO aircraft_modes (FirstCreated,LastModified,ModeS,ModeSCountry,Registration,ICAOTypeCode,Source) VALUES (:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:source)'; |
1088
|
|
|
try { |
1089
|
|
|
$sthf = $Connection->db->prepare($queryf); |
1090
|
|
|
$sthf->execute(array(':FirstCreated' => $data[16],':LastModified' => $data[15],':ModeS' => $data[33],':ModeSCountry' => $data[14], ':Registration' => 'N'.$data[0],':ICAOTypeCode' => $result_search_mfr[0]['icao'],':source' => 'website_faa')); |
1091
|
|
|
} catch(PDOException $e) { |
1092
|
|
|
return "error f : ".$e->getMessage(); |
1093
|
|
|
} |
1094
|
|
|
} |
1095
|
|
|
} |
1096
|
|
|
if (strtotime($data[29]) > time()) { |
1097
|
|
|
if ($globalDebug) echo 'i'; |
1098
|
|
|
$query = 'INSERT INTO aircraft_owner (registration,base,owner,date_first_reg,Source) VALUES (:registration,:base,:owner,:date_first_reg,:source)'; |
1099
|
|
|
try { |
1100
|
|
|
$sth = $Connection->db->prepare($query); |
1101
|
|
|
$sth->execute(array(':registration' => 'N'.$data[0],':base' => $data[9],':owner' => ucwords(strtolower($data[6])),':date_first_reg' => date('Y-m-d',strtotime($data[23])), ':source' => 'website_faa')); |
1102
|
|
|
} catch(PDOException $e) { |
1103
|
|
|
return "error i : ".$e->getMessage(); |
1104
|
|
|
} |
1105
|
|
|
} |
1106
|
|
|
} |
1107
|
|
|
if ($i % 90 == 0) { |
1108
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1109
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1110
|
|
|
} |
1111
|
|
|
$i++; |
1112
|
|
|
} |
1113
|
|
|
fclose($handle); |
1114
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1115
|
|
|
} |
1116
|
|
|
return ''; |
1117
|
|
|
} |
1118
|
|
|
|
1119
|
|
|
public static function modes_fam() { |
1120
|
|
|
global $tmp_dir, $globalTransaction; |
1121
|
|
|
$query = "DELETE FROM aircraft_modes WHERE Source = '' OR Source = :source"; |
1122
|
|
|
try { |
1123
|
|
|
$Connection = new Connection(); |
1124
|
|
|
$sth = $Connection->db->prepare($query); |
1125
|
|
|
$sth->execute(array(':source' => 'website_fam')); |
1126
|
|
|
} catch(PDOException $e) { |
1127
|
|
|
return "error : ".$e->getMessage(); |
1128
|
|
|
} |
1129
|
|
|
$delimiter = "\t"; |
1130
|
|
|
$Connection = new Connection(); |
1131
|
|
|
if (($handle = fopen($tmp_dir.'modes.tsv', 'r')) !== FALSE) |
1132
|
|
|
{ |
1133
|
|
|
$i = 0; |
1134
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1135
|
|
|
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1136
|
|
|
{ |
1137
|
|
|
if ($i > 0) { |
1138
|
|
|
if ($data[1] == 'NULL') $data[1] = $data[0]; |
1139
|
|
|
$query = 'INSERT INTO aircraft_modes (FirstCreated,LastModified,ModeS,ModeSCountry,Registration,ICAOTypeCode,type_flight,Source) VALUES (:FirstCreated,:LastModified,:ModeS,:ModeSCountry,:Registration,:ICAOTypeCode,:type_flight,:source)'; |
1140
|
|
|
try { |
1141
|
|
|
$sth = $Connection->db->prepare($query); |
1142
|
|
|
$sth->execute(array(':FirstCreated' => $data[0],':LastModified' => $data[1],':ModeS' => $data[2],':ModeSCountry' => $data[3], ':Registration' => $data[4],':ICAOTypeCode' => $data[5],':type_flight' => $data[6],':source' => 'website_fam')); |
1143
|
|
|
} catch(PDOException $e) { |
1144
|
|
|
return "error : ".$e->getMessage(); |
1145
|
|
|
} |
1146
|
|
|
} |
1147
|
|
|
$i++; |
1148
|
|
|
} |
1149
|
|
|
fclose($handle); |
1150
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1151
|
|
|
} |
1152
|
|
|
return ''; |
1153
|
|
|
} |
1154
|
|
|
|
1155
|
|
|
public static function airlines_fam() { |
1156
|
|
|
global $tmp_dir, $globalTransaction, $globalDBdriver; |
1157
|
|
|
$Connection = new Connection(); |
1158
|
|
|
/* |
1159
|
|
|
if ($globalDBdriver == 'mysql') { |
1160
|
|
|
$query = "LOCK TABLE airlines WRITE"; |
1161
|
|
|
} else { |
1162
|
|
|
$query = "LOCK TABLE airlines IN ACCESS EXCLUSIVE WORK"; |
1163
|
|
|
} |
1164
|
|
|
try { |
1165
|
|
|
$sth = $Connection->db->prepare($query); |
1166
|
|
|
$sth->execute(); |
1167
|
|
|
} catch(PDOException $e) { |
1168
|
|
|
return "error : ".$e->getMessage(); |
1169
|
|
|
} |
1170
|
|
|
*/ |
1171
|
|
|
$query = "DELETE FROM airlines WHERE forsource IS NULL"; |
1172
|
|
|
try { |
1173
|
|
|
$sth = $Connection->db->prepare($query); |
1174
|
|
|
$sth->execute(); |
1175
|
|
|
} catch(PDOException $e) { |
1176
|
|
|
return "error : ".$e->getMessage(); |
1177
|
|
|
} |
1178
|
|
|
$delimiter = "\t"; |
1179
|
|
|
if (($handle = fopen($tmp_dir.'airlines.tsv', 'r')) !== FALSE) |
1180
|
|
|
{ |
1181
|
|
|
$i = 0; |
1182
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1183
|
|
|
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1184
|
|
|
{ |
1185
|
|
|
if ($i > 0) { |
1186
|
|
|
if ($data[1] == 'NULL') $data[1] = $data[0]; |
1187
|
|
|
$query = 'INSERT INTO airlines (airline_id,name,alias,iata,icao,callsign,country,active,type,home_link,wikipedia_link,alliance,ban_eu) VALUES (0,:name,:alias,:iata,:icao,:callsign,:country,:active,:type,:home,:wikipedia_link,:alliance,:ban_eu)'; |
1188
|
|
|
try { |
1189
|
|
|
$sth = $Connection->db->prepare($query); |
1190
|
|
|
$sth->execute(array(':name' => $data[0],':alias' => $data[1],':iata' => $data[2],':icao' => $data[3], ':callsign' => $data[4],':country' => $data[5],':active' => $data[6],':type' => $data[7],':home' => $data[8],':wikipedia_link' => $data[9],':alliance' => $data[10],':ban_eu' => $data[11])); |
1191
|
|
|
} catch(PDOException $e) { |
1192
|
|
|
return "error : ".$e->getMessage(); |
1193
|
|
|
} |
1194
|
|
|
} |
1195
|
|
|
$i++; |
1196
|
|
|
} |
1197
|
|
|
fclose($handle); |
1198
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1199
|
|
|
} |
1200
|
|
|
/* |
1201
|
|
|
$query = "UNLOCK TABLES"; |
1202
|
|
|
try { |
1203
|
|
|
$sth = $Connection->db->prepare($query); |
1204
|
|
|
$sth->execute(); |
1205
|
|
|
} catch(PDOException $e) { |
1206
|
|
|
return "error : ".$e->getMessage(); |
1207
|
|
|
} |
1208
|
|
|
*/ |
1209
|
|
|
return ''; |
1210
|
|
|
} |
1211
|
|
|
|
1212
|
|
|
public static function owner_fam() { |
1213
|
|
|
global $tmp_dir, $globalTransaction; |
1214
|
|
|
$query = "DELETE FROM aircraft_owner WHERE Source = '' OR Source = :source"; |
1215
|
|
|
try { |
1216
|
|
|
$Connection = new Connection(); |
1217
|
|
|
$sth = $Connection->db->prepare($query); |
1218
|
|
|
$sth->execute(array(':source' => 'website_fam')); |
1219
|
|
|
} catch(PDOException $e) { |
1220
|
|
|
return "error : ".$e->getMessage(); |
1221
|
|
|
} |
1222
|
|
|
|
1223
|
|
|
$delimiter = "\t"; |
1224
|
|
|
$Connection = new Connection(); |
1225
|
|
|
if (($handle = fopen($tmp_dir.'owners.tsv', 'r')) !== FALSE) |
1226
|
|
|
{ |
1227
|
|
|
$i = 0; |
1228
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1229
|
|
|
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1230
|
|
|
{ |
1231
|
|
|
if ($i > 0) { |
1232
|
|
|
$query = 'INSERT INTO aircraft_owner (registration,base,owner,date_first_reg,Source) VALUES (:registration,:base,:owner,NULL,:source)'; |
1233
|
|
|
try { |
1234
|
|
|
$sth = $Connection->db->prepare($query); |
1235
|
|
|
$sth->execute(array(':registration' => $data[0],':base' => $data[1],':owner' => $data[2], ':source' => 'website_fam')); |
1236
|
|
|
} catch(PDOException $e) { |
1237
|
|
|
//print_r($data); |
1238
|
|
|
return "error : ".$e->getMessage(); |
1239
|
|
|
} |
1240
|
|
|
} |
1241
|
|
|
$i++; |
1242
|
|
|
} |
1243
|
|
|
fclose($handle); |
1244
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1245
|
|
|
} |
1246
|
|
|
return ''; |
1247
|
|
|
} |
1248
|
|
|
|
1249
|
|
|
public static function routes_fam() { |
1250
|
|
|
global $tmp_dir, $globalTransaction, $globalDebug; |
1251
|
|
|
$query = "DELETE FROM routes WHERE Source = '' OR Source = :source"; |
1252
|
|
|
try { |
1253
|
|
|
$Connection = new Connection(); |
1254
|
|
|
$sth = $Connection->db->prepare($query); |
1255
|
|
|
$sth->execute(array(':source' => 'website_fam')); |
1256
|
|
|
} catch(PDOException $e) { |
1257
|
|
|
return "error : ".$e->getMessage(); |
1258
|
|
|
} |
1259
|
|
|
$delimiter = "\t"; |
1260
|
|
|
$Connection = new Connection(); |
1261
|
|
|
if (($handle = fopen($tmp_dir.'routes.tsv', 'r')) !== FALSE) |
1262
|
|
|
{ |
1263
|
|
|
$i = 0; |
1264
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1265
|
|
|
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1266
|
|
|
{ |
1267
|
|
|
if ($i > 0) { |
1268
|
|
|
$data = array_map(function($v) { return $v === 'NULL' ? NULL : $v; },$data); |
1269
|
|
|
$query = 'INSERT INTO routes (CallSign,Operator_ICAO,FromAirport_ICAO,FromAirport_Time,ToAirport_ICAO,ToAirport_Time,RouteStop,Source) VALUES (:CallSign,:Operator_ICAO,:FromAirport_ICAO,:FromAirport_Time,:ToAirport_ICAO,:ToAirport_Time,:RouteStop,:source)'; |
1270
|
|
|
try { |
1271
|
|
|
$sth = $Connection->db->prepare($query); |
1272
|
|
|
$sth->execute(array(':CallSign' => $data[0],':Operator_ICAO' => $data[1],':FromAirport_ICAO' => $data[2],':FromAirport_Time' => $data[3], ':ToAirport_ICAO' => $data[4],':ToAirport_Time' => $data[5],':RouteStop' => $data[6],':source' => 'website_fam')); |
1273
|
|
|
} catch(PDOException $e) { |
1274
|
|
|
if ($globalDebug) echo "error: ".$e->getMessage()." - data: ".implode(',',$data); |
1275
|
|
|
die(); |
1276
|
|
|
} |
1277
|
|
|
} |
1278
|
|
|
if ($globalTransaction && $i % 2000 == 0) { |
1279
|
|
|
$Connection->db->commit(); |
1280
|
|
|
if ($globalDebug) echo '.'; |
1281
|
|
|
$Connection->db->beginTransaction(); |
1282
|
|
|
} |
1283
|
|
|
$i++; |
1284
|
|
|
} |
1285
|
|
|
fclose($handle); |
1286
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1287
|
|
|
} |
1288
|
|
|
return ''; |
1289
|
|
|
} |
1290
|
|
|
|
1291
|
|
|
public static function marine_identity_fam() { |
1292
|
|
|
global $tmp_dir, $globalTransaction; |
1293
|
|
|
$query = "TRUNCATE TABLE marine_identity"; |
1294
|
|
|
try { |
1295
|
|
|
$Connection = new Connection(); |
1296
|
|
|
$sth = $Connection->db->prepare($query); |
1297
|
|
|
$sth->execute(); |
1298
|
|
|
} catch(PDOException $e) { |
1299
|
|
|
return "error : ".$e->getMessage(); |
1300
|
|
|
} |
1301
|
|
|
|
1302
|
|
|
|
1303
|
|
|
//update_db::unzip($out_file); |
1304
|
|
|
$delimiter = "\t"; |
1305
|
|
|
$Connection = new Connection(); |
1306
|
|
|
if (($handle = fopen($tmp_dir.'marine_identity.tsv', 'r')) !== FALSE) |
1307
|
|
|
{ |
1308
|
|
|
$i = 0; |
1309
|
|
|
//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); |
1310
|
|
|
//$Connection->db->beginTransaction(); |
1311
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1312
|
|
|
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1313
|
|
|
{ |
1314
|
|
|
if ($i > 0) { |
1315
|
|
|
$data = array_map(function($v) { return $v === 'NULL' ? NULL : $v; },$data); |
1316
|
|
|
$query = 'INSERT INTO marine_identity (mmsi,imo,call_sign,ship_name,length,gross_tonnage,dead_weight,width,country,engine_power,type) VALUES (:mmsi,:imo,:call_sign,:ship_name,:length,:gross_tonnage,:dead_weight,:width,:country,:engine_power,:type)'; |
1317
|
|
|
try { |
1318
|
|
|
$sth = $Connection->db->prepare($query); |
1319
|
|
|
$sth->execute(array(':mmsi' => $data[0],':imo' => $data[1],':call_sign' => $data[2],':ship_name' => $data[3], ':length' => $data[4],':gross_tonnage' => $data[5],':dead_weight' => $data[6],':width' => $data[7],':country' => $data[8],':engine_power' => $data[9],':type' => $data[10])); |
1320
|
|
|
} catch(PDOException $e) { |
1321
|
|
|
return "error : ".$e->getMessage(); |
1322
|
|
|
} |
1323
|
|
|
} |
1324
|
|
|
$i++; |
1325
|
|
|
} |
1326
|
|
|
fclose($handle); |
1327
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1328
|
|
|
} |
1329
|
|
|
return ''; |
1330
|
|
|
} |
1331
|
|
|
|
1332
|
|
|
public static function satellite_fam() { |
1333
|
|
|
global $tmp_dir, $globalTransaction; |
1334
|
|
|
$query = "TRUNCATE TABLE satellite"; |
1335
|
|
|
try { |
1336
|
|
|
$Connection = new Connection(); |
1337
|
|
|
$sth = $Connection->db->prepare($query); |
1338
|
|
|
$sth->execute(); |
1339
|
|
|
} catch(PDOException $e) { |
1340
|
|
|
return "error : ".$e->getMessage(); |
1341
|
|
|
} |
1342
|
|
|
$delimiter = "\t"; |
1343
|
|
|
$Connection = new Connection(); |
1344
|
|
|
if (($handle = fopen($tmp_dir.'satellite.tsv', 'r')) !== FALSE) |
1345
|
|
|
{ |
1346
|
|
|
$i = 0; |
1347
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1348
|
|
|
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1349
|
|
|
{ |
1350
|
|
|
if ($i > 0) { |
1351
|
|
|
$data = array_map(function($v) { return $v === 'NULL' ? NULL : $v; },$data); |
1352
|
|
|
$query = 'INSERT INTO satellite (name, name_alternate, country_un, country_owner, owner, users, purpose, purpose_detailed, orbit, type, longitude_geo, perigee, apogee, eccentricity, inclination, period, launch_mass, dry_mass, power, launch_date, lifetime, contractor, country_contractor, launch_site, launch_vehicule, cospar, norad, comments, source_orbital, sources) |
1353
|
|
|
VALUES (:name, :name_alternate, :country_un, :country_owner, :owner, :users, :purpose, :purpose_detailed, :orbit, :type, :longitude_geo, :perigee, :apogee, :eccentricity, :inclination, :period, :launch_mass, :dry_mass, :power, :launch_date, :lifetime, :contractor, :country_contractor, :launch_site, :launch_vehicule, :cospar, :norad, :comments, :source_orbital, :sources)'; |
1354
|
|
|
try { |
1355
|
|
|
$sth = $Connection->db->prepare($query); |
1356
|
|
|
$sth->execute(array(':name' => $data[0], ':name_alternate' => $data[1], ':country_un' => $data[2], ':country_owner' => $data[3], ':owner' => $data[4], ':users' => $data[5], ':purpose' => $data[6], ':purpose_detailed' => $data[7], ':orbit' => $data[8], ':type' => $data[9], ':longitude_geo' => $data[10], ':perigee' => !empty($data[11]) ? $data[11] : NULL, ':apogee' => !empty($data[12]) ? $data[12] : NULL, ':eccentricity' => $data[13], ':inclination' => $data[14], ':period' => !empty($data[15]) ? $data[15] : NULL, ':launch_mass' => !empty($data[16]) ? $data[16] : NULL, ':dry_mass' => !empty($data[17]) ? $data[17] : NULL, ':power' => !empty($data[18]) ? $data[18] : NULL, ':launch_date' => $data[19], ':lifetime' => $data[20], ':contractor' => $data[21],':country_contractor' => $data[22], ':launch_site' => $data[23], ':launch_vehicule' => $data[24], ':cospar' => $data[25], ':norad' => $data[26], ':comments' => $data[27], ':source_orbital' => $data[28], ':sources' => $data[29])); |
1357
|
|
|
} catch(PDOException $e) { |
1358
|
|
|
return "error : ".$e->getMessage(); |
1359
|
|
|
} |
1360
|
|
|
} |
1361
|
|
|
$i++; |
1362
|
|
|
} |
1363
|
|
|
fclose($handle); |
1364
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1365
|
|
|
} |
1366
|
|
|
return ''; |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
public static function banned_fam() { |
1370
|
|
|
global $tmp_dir, $globalTransaction; |
1371
|
|
|
$query = "UPDATE airlines SET ban_eu = 0"; |
1372
|
|
|
try { |
1373
|
|
|
$Connection = new Connection(); |
1374
|
|
|
$sth = $Connection->db->prepare($query); |
1375
|
|
|
$sth->execute(); |
1376
|
|
|
} catch(PDOException $e) { |
1377
|
|
|
return "error : ".$e->getMessage(); |
1378
|
|
|
} |
1379
|
|
|
|
1380
|
|
|
$Connection = new Connection(); |
1381
|
|
|
if (($handle = fopen($tmp_dir.'ban_eu.csv', 'r')) !== FALSE) |
1382
|
|
|
{ |
1383
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1384
|
|
|
while (($data = fgetcsv($handle, 1000)) !== FALSE) |
1385
|
|
|
{ |
1386
|
|
|
$query = 'UPDATE airlines SET ban_eu = 1 WHERE icao = :icao AND forsource IS NULL'; |
1387
|
|
|
if ($data[0] != '') { |
1388
|
|
|
$icao = $data[0]; |
1389
|
|
|
try { |
1390
|
|
|
$sth = $Connection->db->prepare($query); |
1391
|
|
|
$sth->execute(array(':icao' => $icao)); |
1392
|
|
|
} catch(PDOException $e) { |
1393
|
|
|
return "error : ".$e->getMessage(); |
1394
|
|
|
} |
1395
|
|
|
} |
1396
|
|
|
} |
1397
|
|
|
fclose($handle); |
1398
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1399
|
|
|
} |
1400
|
|
|
return ''; |
1401
|
|
|
} |
1402
|
|
|
|
1403
|
|
|
public static function tle($filename,$tletype) { |
1404
|
|
|
require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
1405
|
|
|
global $tmp_dir, $globalTransaction; |
1406
|
|
|
//$Spotter = new Spotter(); |
1407
|
|
|
|
1408
|
|
|
$query = "DELETE FROM tle WHERE tle_source = '' OR tle_source = :source"; |
1409
|
|
|
try { |
1410
|
|
|
$Connection = new Connection(); |
1411
|
|
|
$sth = $Connection->db->prepare($query); |
1412
|
|
|
$sth->execute(array(':source' => $filename)); |
1413
|
|
|
} catch(PDOException $e) { |
1414
|
|
|
return "error : ".$e->getMessage(); |
1415
|
|
|
} |
1416
|
|
|
|
1417
|
|
|
$Connection = new Connection(); |
1418
|
|
|
if (($handle = fopen($filename, 'r')) !== FALSE) |
1419
|
|
|
{ |
1420
|
|
|
$i = 0; |
1421
|
|
|
//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); |
1422
|
|
|
//$Connection->db->beginTransaction(); |
1423
|
|
|
$dbdata = array(); |
1424
|
|
|
while (($data = fgets($handle, 1000)) !== FALSE) |
1425
|
|
|
{ |
1426
|
|
|
if ($i == 0) { |
1427
|
|
|
$dbdata['name'] = trim($data); |
1428
|
|
|
$i++; |
1429
|
|
|
} elseif ($i == 1) { |
1430
|
|
|
$dbdata['tle1'] = trim($data); |
1431
|
|
|
$i++; |
1432
|
|
|
} elseif ($i == 2) { |
1433
|
|
|
$dbdata['tle2'] = trim($data); |
1434
|
|
|
//print_r($dbdata); |
1435
|
|
|
$query = 'INSERT INTO tle (tle_name,tle_tle1,tle_tle2,tle_type,tle_source) VALUES (:name, :tle1, :tle2, :type, :source)'; |
1436
|
|
|
try { |
1437
|
|
|
$sth = $Connection->db->prepare($query); |
1438
|
|
|
$sth->execute(array(':name' => $dbdata['name'],':tle1' => $dbdata['tle1'],':tle2' => $dbdata['tle2'], ':type' => $tletype,':source' => $filename)); |
1439
|
|
|
} catch(PDOException $e) { |
1440
|
|
|
return "error : ".$e->getMessage(); |
1441
|
|
|
} |
1442
|
|
|
|
1443
|
|
|
$i = 0; |
1444
|
|
|
} |
1445
|
|
|
} |
1446
|
|
|
fclose($handle); |
1447
|
|
|
//$Connection->db->commit(); |
1448
|
|
|
} |
1449
|
|
|
return ''; |
1450
|
|
|
} |
1451
|
|
|
|
1452
|
|
|
public static function satellite_ucsdb($filename) { |
1453
|
|
|
global $tmp_dir, $globalTransaction; |
1454
|
|
|
$query = "DELETE FROM satellite"; |
1455
|
|
|
try { |
1456
|
|
|
$Connection = new Connection(); |
1457
|
|
|
$sth = $Connection->db->prepare($query); |
1458
|
|
|
$sth->execute(array(':source' => $filename)); |
1459
|
|
|
} catch(PDOException $e) { |
1460
|
|
|
return "error : ".$e->getMessage(); |
1461
|
|
|
} |
1462
|
|
|
|
1463
|
|
|
$Connection = new Connection(); |
1464
|
|
|
if (($handle = fopen($filename, 'r')) !== FALSE) |
1465
|
|
|
{ |
1466
|
|
|
$i = 0; |
1467
|
|
|
//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); |
1468
|
|
|
//$Connection->db->beginTransaction(); |
1469
|
|
|
while (($data = fgetcsv($handle, 1000,"\t")) !== FALSE) |
1470
|
|
|
{ |
1471
|
|
|
if ($i > 0 && $data[0] != '') { |
1472
|
|
|
$sources = trim($data[28].' '.$data[29].' '.$data[30].' '.$data[31].' '.$data[32].' '.$data[33]); |
1473
|
|
|
$period = str_replace(',','',$data[14]); |
1474
|
|
|
if (!empty($period) && strpos($period,'days')) $period = str_replace(' days','',$period)*24*60; |
1475
|
|
|
if ($data[18] != '') $launch_date = date('Y-m-d',strtotime($data[18])); |
1476
|
|
|
else $launch_date = NULL; |
1477
|
|
|
$data = array_map(function($value) { |
1478
|
|
|
return trim($value) === '' ? null : $value; |
1479
|
|
|
}, $data); |
1480
|
|
|
//print_r($data); |
1481
|
|
|
$query = 'INSERT INTO satellite (name, name_alternate, country_un, country_owner, owner, users, purpose, purpose_detailed, orbit, type, longitude_geo, perigee, apogee, eccentricity, inclination, period, launch_mass, dry_mass, power, launch_date, lifetime, contractor, country_contractor, launch_site, launch_vehicule, cospar, norad, comments, source_orbital, sources) |
1482
|
|
|
VALUES (:name, :name_alternate, :country_un, :country_owner, :owner, :users, :purpose, :purpose_detailed, :orbit, :type, :longitude_geo, :perigee, :apogee, :eccentricity, :inclination, :period, :launch_mass, :dry_mass, :power, :launch_date, :lifetime, :contractor, :country_contractor, :launch_site, :launch_vehicule, :cospar, :norad, :comments, :source_orbital, :sources)'; |
1483
|
|
|
try { |
1484
|
|
|
$sth = $Connection->db->prepare($query); |
1485
|
|
|
$sth->execute(array(':name' => $data[0], ':name_alternate' => '', ':country_un' => $data[1], ':country_owner' => $data[2], ':owner' => $data[3], ':users' => $data[4], ':purpose' => $data[5], ':purpose_detailed' => $data[6], ':orbit' => $data[7], ':type' => $data[8], ':longitude_geo' => $data[9], ':perigee' => !empty($data[10]) ? str_replace(',','',$data[10]) : NULL, ':apogee' => !empty($data[11]) ? str_replace(',','',$data[11]) : NULL, ':eccentricity' => $data[12], ':inclination' => $data[13], ':period' => !empty($period) ? $period : NULL, ':launch_mass' => !empty($data[15]) ? str_replace(array('+',','),'',$data[15]) : NULL, ':dry_mass' => !empty($data[16]) ? str_replace(array(',','-1900',' (BOL)',' (EOL)'),'',$data[16]) : NULL, ':power' => !empty($data[17]) ? str_replace(array(',',' (BOL)',' (EOL)'),'',$data[17]) : NULL, ':launch_date' => $launch_date, ':lifetime' => $data[19], ':contractor' => $data[20],':country_contractor' => $data[21], ':launch_site' => $data[22], ':launch_vehicule' => $data[23], ':cospar' => $data[24], ':norad' => $data[25], ':comments' => $data[26], ':source_orbital' => $data[27], ':sources' => $sources)); |
1486
|
|
|
} catch(PDOException $e) { |
1487
|
|
|
return "error : ".$e->getMessage(); |
1488
|
|
|
} |
1489
|
|
|
} |
1490
|
|
|
$i++; |
1491
|
|
|
} |
1492
|
|
|
fclose($handle); |
1493
|
|
|
//$Connection->db->commit(); |
1494
|
|
|
} |
1495
|
|
|
return ''; |
1496
|
|
|
} |
1497
|
|
|
|
1498
|
|
|
public static function satellite_celestrak($filename) { |
1499
|
|
|
global $tmp_dir, $globalTransaction; |
1500
|
|
|
$satcat_sources = array( |
1501
|
|
|
'AB' => array('country' => 'Multinational', 'owner' => 'Arab Satellite Communications Org. (ASCO)'), |
1502
|
|
|
'ABS' => array('country' => 'Multinational', 'owner' => 'Asia Broadcast Satellite Ltd.'), |
1503
|
|
|
'AC' => array('country' => 'China', 'owner' => 'Asia Satellite Telecommunications Co. Ltd.'), |
1504
|
|
|
'ALG' => array('country' => 'Algeria', 'owner' => ''), |
1505
|
|
|
'ARGN' => array('country' => 'Argentina', 'owner' => ''), |
1506
|
|
|
'ASRA' => array('country' => 'Austria', 'owner' => ''), |
1507
|
|
|
'AUS' => array('country' => 'Australia', 'owner' => ''), |
1508
|
|
|
'AZER' => array('country' => 'Azerbaijan', 'owner' => ''), |
1509
|
|
|
'BEL' => array('country' => 'Belgium', 'owner' => ''), |
1510
|
|
|
'BELA' => array('country' => 'Belarus', 'owner' => ''), |
1511
|
|
|
'BERM' => array('country' => 'Bermuda', 'owner' => ''), |
1512
|
|
|
'BOL' => array('country' => 'Bolivia', 'owner' => ''), |
1513
|
|
|
'BUL' => array('country' => 'Bulgaria', 'owner' => ''), |
1514
|
|
|
'BRAZ' => array('country' => 'Brazil', 'owner' => ''), |
1515
|
|
|
'CA' => array('country' => 'Canada', 'owner' => ''), |
1516
|
|
|
'CHBZ' => array('country' => 'China/Brazil', 'owner' => ''), |
1517
|
|
|
'CHLE' => array('country' => 'Chile', 'owner' => ''), |
1518
|
|
|
'CIS' => array('country' => 'Russia', 'owner' => ''), |
1519
|
|
|
'COL' => array('country' => 'Colombia', 'owner' => ''), |
1520
|
|
|
'CZCH' => array('country' => 'Czech Republic (former Czechoslovakia)', 'owner' => ''), |
1521
|
|
|
'DEN' => array('country' => 'Denmark', 'owner' => ''), |
1522
|
|
|
'ECU' => array('country' => 'Ecuador', 'owner' => ''), |
1523
|
|
|
'EGYP' => array('country' => 'Egypt', 'owner' => ''), |
1524
|
|
|
'ESA' => array('country' => 'Multinational', 'owner' => 'European Space Agency'), |
1525
|
|
|
'ESRO' => array('country' => 'Multinational', 'owner' => 'European Space Research Organization'), |
1526
|
|
|
'EST' => array('country' => 'Estonia','owner' => ''), |
1527
|
|
|
'EUME' => array('country' => 'Multinational', 'owner' => 'EUMETSAT (European Organization for the Exploitation of Meteorological Satellites)'), |
1528
|
|
|
'EUTE' => array('country' => 'Multinational', 'owner' => 'European Telecommunications Satellite Consortium (EUTELSAT)'), |
1529
|
|
|
'FGER' => array('country' => 'France/Germany', 'owner' => ''), |
1530
|
|
|
'FIN' => array('country' => 'Finland', 'owner' => ''), |
1531
|
|
|
'FR' => array('country' => 'France', 'owner' => ''), |
1532
|
|
|
'FRIT' => array('country' => 'France/Italy', 'owner' => ''), |
1533
|
|
|
'GER' => array('country' => 'Germany', 'owner' => ''), |
1534
|
|
|
'GLOB' => array('country' => 'USA', 'owner' => 'Globalstar'), |
1535
|
|
|
'GREC' => array('country' => 'Greece', 'owner' => ''), |
1536
|
|
|
'HUN' => array('country' => 'Hungary', 'owner' => ''), |
1537
|
|
|
'IM' => array('country' => 'United Kingdom', 'owner' => 'INMARSAT, Ltd.'), |
1538
|
|
|
'IND' => array('country' => 'India', 'owner' => ''), |
1539
|
|
|
'INDO' => array('country' => 'Indonesia', 'owner' => ''), |
1540
|
|
|
'IRAN' => array('country' => 'Iran', 'owner' => ''), |
1541
|
|
|
'IRAQ' => array('country' => 'Iraq', 'owner' => ''), |
1542
|
|
|
'IRID' => array('country' => 'USA', 'owner' => 'Iridium Satellite LLC'), |
1543
|
|
|
'ISRA' => array('country' => 'Israel', 'owner' => ''), |
1544
|
|
|
'ISRO' => array('country' => 'India', 'owner' => 'Indian Space Research Organisation (ISRO)'), |
1545
|
|
|
'ISS' => array('country' => 'Multinational', 'owner' => 'NASA/Multinational'), |
1546
|
|
|
'IT' => array('country' => 'Italy', 'owner' => ''), |
1547
|
|
|
'ITSO' => array('country' => 'USA', 'owner' => 'Intelsat, S.A.'), |
1548
|
|
|
'JPN' => array('country' => 'Japan', 'owner' => ''), |
1549
|
|
|
'KAZ' => array('country' => 'Kazakhstan', 'owner' => ''), |
1550
|
|
|
'LAOS' => array('country' => 'Laos', 'owner' => ''), |
1551
|
|
|
'LTU' => array('country' => 'Lithuania', 'owner' => ''), |
1552
|
|
|
'LUXE' => array('country' => 'Luxembourg', 'owner' => ''), |
1553
|
|
|
'MALA' => array('country' => 'Malaysia', 'owner' => ''), |
1554
|
|
|
'MEX' => array('country' => 'Mexico', 'owner' => ''), |
1555
|
|
|
'NATO' => array('country' => 'Multinational', 'owner' => 'North Atlantic Treaty Organization'), |
1556
|
|
|
'NETH' => array('country' => 'Netherlands', 'owner' => ''), |
1557
|
|
|
'NICO' => array('country' => 'USA', 'owner' => 'New ICO'), |
1558
|
|
|
'NIG' => array('country' => 'Nigeria', 'owner' => ''), |
1559
|
|
|
'NKOR' => array('country' => 'North Korea', 'owner' => ''), |
1560
|
|
|
'NOR' => array('country' => 'Norway', 'owner' => ''), |
1561
|
|
|
'O3B' => array('country' => 'United Kingdom', 'owner' => 'O3b Networks Ltd.'), |
1562
|
|
|
'ORB' => array('country' => 'USA', 'owner' => 'ORBCOMM Inc.'), |
1563
|
|
|
'PAKI' => array('country' => 'Pakistan', 'owner' => ''), |
1564
|
|
|
'PERU' => array('country' => 'Peru', 'owner' => ''), |
1565
|
|
|
'POL' => array('country' => 'Poland', 'owner' => ''), |
1566
|
|
|
'POR' => array('country' => 'Portugal', 'owner' => ''), |
1567
|
|
|
'PRC' => array('country' => 'China', 'owner' => ''), |
1568
|
|
|
'PRES' => array('country' => 'Multinational', 'owner' => 'China/ESA'), |
1569
|
|
|
'RASC' => array('country' => 'Multinational', 'owner' => 'Regional African Satellite Communications Organisation (RASCOM)'), |
1570
|
|
|
'ROC' => array('country' => 'Taiwan', 'owner' => ''), |
1571
|
|
|
'ROM' => array('country' => 'Romania', 'owner' => ''), |
1572
|
|
|
'RP' => array('country' => 'Philippines', 'owner' => ''), |
1573
|
|
|
'SAFR' => array('country' => 'South Africa', 'owner' => ''), |
1574
|
|
|
'SAUD' => array('country' => 'Saudi Arabia', 'owner' => ''), |
1575
|
|
|
'SEAL' => array('country' => 'USA', 'owner' => ''), |
1576
|
|
|
'SES' => array('country' => 'Multinational', 'owner' => 'SES World Skies'), |
1577
|
|
|
'SING' => array('country' => 'Singapore', 'owner' => ''), |
1578
|
|
|
'SKOR' => array('country' => 'South Korea', 'owner' => ''), |
1579
|
|
|
'SPN' => array('country' => 'Spain', 'owner' => ''), |
1580
|
|
|
'STCT' => array('country' => 'Singapore/Taiwan', 'owner' => ''), |
1581
|
|
|
'SWED' => array('country' => 'Sweden', 'owner' => ''), |
1582
|
|
|
'SWTZ' => array('country' => 'Switzerland', 'owner' => ''), |
1583
|
|
|
'THAI' => array('country' => 'Thailand', 'owner' => ''), |
1584
|
|
|
'TMMC' => array('country' => 'Turkmenistan/Monaco', 'owner' => ''), |
1585
|
|
|
'TURK' => array('country' => 'Turkey', 'owner' => ''), |
1586
|
|
|
'UAE' => array('country' => 'United Arab Emirates', 'owner' => ''), |
1587
|
|
|
'UK' => array('country' => 'United Kingdom', 'owner' => ''), |
1588
|
|
|
'UKR' => array('country' => 'Ukraine', 'owner' => ''), |
1589
|
|
|
'URY' => array('country' => 'Uruguay', 'owner' => ''), |
1590
|
|
|
'US' => array('country' => 'USA', 'owner' => ''), |
1591
|
|
|
'USBZ' => array('country' => 'USA/Brazil', 'owner' => ''), |
1592
|
|
|
'VENZ' => array('country' => 'Venezuela', 'owner' => ''), |
1593
|
|
|
'VTNM' => array('country' => 'Vietnam', 'owner' => '') |
1594
|
|
|
); |
1595
|
|
|
$satcat_launch_site = array( |
1596
|
|
|
'AFETR' => 'Cape Canaveral', |
1597
|
|
|
'AFWTR' => 'Vandenberg AFB', |
1598
|
|
|
'CAS' => 'Canaries Airspace', |
1599
|
|
|
'DLS' => 'Dombarovsky Air Base', |
1600
|
|
|
'ERAS' => 'Eastern Range Airspace', |
1601
|
|
|
'FRGUI' => 'Guiana Space Center', |
1602
|
|
|
'HGSTR' => 'Hammaguira Space Track Range, Algeria', |
1603
|
|
|
'JSC' => 'Jiuquan Satellite Launch Center', |
1604
|
|
|
'KODAK' => 'Kodiak Launch Complex', |
1605
|
|
|
'KSCUT' => 'Uchinoura Space Center', |
1606
|
|
|
'KWAJ' => 'Kwajalein Island', |
1607
|
|
|
'KYMSC' => 'Kapustin Yar Missile and Space Complex, Russia', |
1608
|
|
|
'NSC' => 'Naro Space Center', |
1609
|
|
|
'PLMSC' => 'Plesetsk Cosmodrome', |
1610
|
|
|
'SEAL' => 'Sea Launch', |
1611
|
|
|
'SEMLS' => 'Semnan Satellite Launch Site, Iran', |
1612
|
|
|
'SNMLP' => 'San Marco Launch Platform, Indian Ocean (Kenya)', |
1613
|
|
|
'SRILR' => 'Satish Dhawan Space Center', |
1614
|
|
|
'SUBL' => 'Submarine Launch Platform (mobile), Russia', |
1615
|
|
|
'SVOBO' => 'Svobodny Cosmodrome', |
1616
|
|
|
'TAISC' => 'Taiyuan Launch Center', |
1617
|
|
|
'TANSC' => 'Tanegashima Space Center', |
1618
|
|
|
'TYMSC' => 'Baikonur Cosmodrome', |
1619
|
|
|
'VOSTO' => 'Vostochny Cosmodrome', |
1620
|
|
|
'WLPIS' => 'Wallops Island Flight Facility', |
1621
|
|
|
'WOMRA' => 'Woomera, Australia', |
1622
|
|
|
'WRAS' => 'Western Range Airspace', |
1623
|
|
|
'WSC' => 'Wenchang Satellite Launch Center', |
1624
|
|
|
'XICLF' => 'Xichang Satellite Launch Center', |
1625
|
|
|
'YAVNE' => 'Palmachim Launch Complex', |
1626
|
|
|
'YUN' => 'Yunsong Launch Site' |
1627
|
|
|
); |
1628
|
|
|
|
1629
|
|
|
/* |
1630
|
|
|
$query = "DELETE FROM satellite"; |
1631
|
|
|
try { |
1632
|
|
|
$Connection = new Connection(); |
1633
|
|
|
$sth = $Connection->db->prepare($query); |
1634
|
|
|
$sth->execute(array(':source' => $filename)); |
1635
|
|
|
} catch(PDOException $e) { |
1636
|
|
|
return "error : ".$e->getMessage(); |
1637
|
|
|
} |
1638
|
|
|
*/ |
1639
|
|
|
|
1640
|
|
|
$Connection = new Connection(); |
1641
|
|
|
if (($handle = fopen($filename, 'r')) !== FALSE) |
1642
|
|
|
{ |
1643
|
|
|
$i = 0; |
1644
|
|
|
//$Connection->db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); |
1645
|
|
|
//$Connection->db->beginTransaction(); |
1646
|
|
|
while (($data = fgets($handle, 1000)) !== FALSE) |
1647
|
|
|
{ |
1648
|
|
|
if ($data != '') { |
1649
|
|
|
$result = array(); |
1650
|
|
|
$result['cospar'] = trim(substr($data,0,11)); |
1651
|
|
|
$result['norad'] = trim(substr($data,13,6)); |
1652
|
|
|
$result['operational'] = trim(substr($data,21,1)); |
1653
|
|
|
$result['name'] = trim(substr($data,23,24)); |
1654
|
|
|
/* |
1655
|
|
|
* R/B(1) = Rocket body, first stage |
1656
|
|
|
* R/B(2) = Rocket body, second stage |
1657
|
|
|
* DEB = Debris |
1658
|
|
|
* PLAT = Platform |
1659
|
|
|
* Items in parentheses are alternate names |
1660
|
|
|
* Items in brackets indicate type of object |
1661
|
|
|
(e.g., BREEZE-M DEB [TANK] = tank) |
1662
|
|
|
* An ampersand (&) indicates two or more objects are attached |
1663
|
|
|
*/ |
1664
|
|
|
|
1665
|
|
|
$owner_code = trim(substr($data,49,5)); |
1666
|
|
|
|
1667
|
|
|
if (!isset($satcat_sources[$owner_code])) { |
1668
|
|
|
echo $data; |
1669
|
|
|
echo 'owner_code: '.$owner_code."\n"; |
1670
|
|
|
} |
1671
|
|
|
if (!isset($satcat_launch_site[trim(substr($data,68,5))])) { |
1672
|
|
|
echo 'launch_site_code: '.trim(substr($data,68,5))."\n"; |
1673
|
|
|
} |
1674
|
|
|
|
1675
|
|
|
if ($owner_code != 'TBD' && isset($satcat_sources[$owner_code]) && isset($satcat_launch_site[trim(substr($data,68,5))])) { |
1676
|
|
|
$result['country_owner'] = $satcat_sources[$owner_code]['country']; |
1677
|
|
|
$result['owner'] = $satcat_sources[$owner_code]['owner']; |
1678
|
|
|
$result['launch_date'] = trim(substr($data,56,10)); |
1679
|
|
|
$launch_site_code = trim(substr($data,68,5)); |
1680
|
|
|
$result['launch_site'] = $satcat_launch_site[$launch_site_code]; |
1681
|
|
|
$result['lifetime'] = trim(substr($data,75,10)); |
1682
|
|
|
$result['period'] = trim(substr($data,87,7)); |
1683
|
|
|
$result['inclination'] = trim(substr($data,96,5)); |
1684
|
|
|
$result['apogee'] = trim(substr($data,103,6)); |
1685
|
|
|
$result['perigee'] = trim(substr($data,111,6)); |
1686
|
|
|
//$result['radarcross'] = trim(substr($data,119,8)); |
1687
|
|
|
$result['status'] = trim(substr($data,129,3)); |
1688
|
|
|
//print_r($result); |
1689
|
|
|
$result = array_map(function($value) { |
1690
|
|
|
return trim($value) === '' ? null : $value; |
1691
|
|
|
}, $result); |
1692
|
|
|
//print_r($data); |
1693
|
|
|
if ($result['operational'] != 'D') { |
1694
|
|
|
$query = "SELECT * FROM satellite WHERE cospar = :cospar LIMIT 1"; |
1695
|
|
|
try { |
1696
|
|
|
$Connection = new Connection(); |
1697
|
|
|
$sth = $Connection->db->prepare($query); |
1698
|
|
|
$sth->execute(array(':cospar' => $result['cospar'])); |
1699
|
|
|
$exist = $sth->fetchAll(PDO::FETCH_ASSOC); |
1700
|
|
|
} catch(PDOException $e) { |
1701
|
|
|
return "error : ".$e->getMessage(); |
1702
|
|
|
} |
1703
|
|
|
if (empty($exist)) { |
1704
|
|
|
$query = 'INSERT INTO satellite (name, name_alternate, country_un, country_owner, owner, users, purpose, purpose_detailed, orbit, type, longitude_geo, perigee, apogee, eccentricity, inclination, period, launch_mass, dry_mass, power, launch_date, lifetime, contractor, country_contractor, launch_site, launch_vehicule, cospar, norad, comments, source_orbital, sources) |
1705
|
|
|
VALUES (:name, :name_alternate, :country_un, :country_owner, :owner, :users, :purpose, :purpose_detailed, :orbit, :type, :longitude_geo, :perigee, :apogee, :eccentricity, :inclination, :period, :launch_mass, :dry_mass, :power, :launch_date, :lifetime, :contractor, :country_contractor, :launch_site, :launch_vehicule, :cospar, :norad, :comments, :source_orbital, :sources)'; |
1706
|
|
|
try { |
1707
|
|
|
$sth = $Connection->db->prepare($query); |
1708
|
|
|
$sth->execute(array( |
1709
|
|
|
':name' => $result['name'], ':name_alternate' => '', ':country_un' => '', ':country_owner' => $result['country_owner'], ':owner' => $result['owner'], ':users' => '', ':purpose' => '', ':purpose_detailed' => '', ':orbit' => $result['status'], |
1710
|
|
|
':type' => '', ':longitude_geo' => NULL, ':perigee' => !empty($result['perigee']) ? $result['perigee'] : NULL, ':apogee' => !empty($result['apogee']) ? $result['apogee'] : NULL, ':eccentricity' => NULL, ':inclination' => $result['inclination'], |
1711
|
|
|
':period' => !empty($result['period']) ? $result['period'] : NULL, ':launch_mass' => NULL, ':dry_mass' => NULL, ':power' => NULL, ':launch_date' => $result['launch_date'], ':lifetime' => $result['lifetime'], |
1712
|
|
|
':contractor' => '',':country_contractor' => '', ':launch_site' => $result['launch_site'], ':launch_vehicule' => '', ':cospar' => $result['cospar'], ':norad' => $result['norad'], ':comments' => '', ':source_orbital' => '', ':sources' => '' |
1713
|
|
|
) |
1714
|
|
|
); |
1715
|
|
|
} catch(PDOException $e) { |
1716
|
|
|
return "error : ".$e->getMessage(); |
1717
|
|
|
} |
1718
|
|
|
} elseif ($exist[0]['name'] != $result['name'] && $exist[0]['name_alternate'] != $result['name']) { |
1719
|
|
|
$query = "UPDATE satellite SET name_alternate = :name_alternate WHERE cospar = :cospar"; |
1720
|
|
|
try { |
1721
|
|
|
$Connection = new Connection(); |
1722
|
|
|
$sth = $Connection->db->prepare($query); |
1723
|
|
|
$sth->execute(array(':name_alternate' => $result['name'],':cospar' => $result['cospar'])); |
1724
|
|
|
} catch(PDOException $e) { |
1725
|
|
|
return "error : ".$e->getMessage(); |
1726
|
|
|
} |
1727
|
|
|
} |
1728
|
|
|
} |
1729
|
|
|
} |
1730
|
|
|
} |
1731
|
|
|
$i++; |
1732
|
|
|
} |
1733
|
|
|
fclose($handle); |
1734
|
|
|
//$Connection->db->commit(); |
1735
|
|
|
} |
1736
|
|
|
return ''; |
1737
|
|
|
} |
1738
|
|
|
|
1739
|
|
|
/** |
1740
|
|
|
* Convert a HTML table to an array |
1741
|
|
|
* @param String $data HTML page |
1742
|
|
|
* @return Array array of the tables in HTML page |
1743
|
|
|
*/ |
1744
|
|
|
/* |
1745
|
|
|
private static function table2array($data) { |
1746
|
|
|
$html = str_get_html($data); |
1747
|
|
|
$tabledata=array(); |
1748
|
|
|
foreach($html->find('tr') as $element) |
1749
|
|
|
{ |
1750
|
|
|
$td = array(); |
1751
|
|
|
foreach( $element->find('th') as $row) |
1752
|
|
|
{ |
1753
|
|
|
$td [] = trim($row->plaintext); |
1754
|
|
|
} |
1755
|
|
|
$td=array_filter($td); |
1756
|
|
|
$tabledata[] = $td; |
1757
|
|
|
|
1758
|
|
|
$td = array(); |
1759
|
|
|
$tdi = array(); |
1760
|
|
|
foreach( $element->find('td') as $row) |
1761
|
|
|
{ |
1762
|
|
|
$td [] = trim($row->plaintext); |
1763
|
|
|
$tdi [] = trim($row->innertext); |
1764
|
|
|
} |
1765
|
|
|
$td=array_filter($td); |
1766
|
|
|
$tdi=array_filter($tdi); |
1767
|
|
|
// $tabledata[]=array_merge($td,$tdi); |
1768
|
|
|
$tabledata[]=$td; |
1769
|
|
|
} |
1770
|
|
|
return(array_filter($tabledata)); |
1771
|
|
|
} |
1772
|
|
|
*/ |
1773
|
|
|
/** |
1774
|
|
|
* Get data from form result |
1775
|
|
|
* @param String $url form URL |
1776
|
|
|
* @return String the result |
1777
|
|
|
*/ |
1778
|
|
|
/* |
1779
|
|
|
private static function getData($url) { |
1780
|
|
|
$ch = curl_init(); |
1781
|
|
|
curl_setopt($ch, CURLOPT_URL, $url); |
1782
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
1783
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
1784
|
|
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
1785
|
|
|
return curl_exec($ch); |
1786
|
|
|
} |
1787
|
|
|
*/ |
1788
|
|
|
/* |
1789
|
|
|
public static function waypoints() { |
1790
|
|
|
$data = update_db::getData('http://www.fallingrain.com/world/FR/waypoints.html'); |
1791
|
|
|
$table = update_db::table2array($data); |
1792
|
|
|
// print_r($table); |
1793
|
|
|
$query = 'TRUNCATE TABLE waypoints'; |
1794
|
|
|
try { |
1795
|
|
|
$Connection = new Connection(); |
1796
|
|
|
$sth = $Connection->db->prepare($query); |
1797
|
|
|
$sth->execute(); |
1798
|
|
|
} catch(PDOException $e) { |
1799
|
|
|
return "error : ".$e->getMessage(); |
1800
|
|
|
} |
1801
|
|
|
|
1802
|
|
|
$query_dest = 'INSERT INTO waypoints (ident,latitude,longitude,control,usage) VALUES (:ident, :latitude, :longitude, :control, :usage)'; |
1803
|
|
|
$Connection = new Connection(); |
1804
|
|
|
$sth_dest = $Connection->db->prepare($query_dest); |
1805
|
|
|
$Connection->db->beginTransaction(); |
1806
|
|
|
foreach ($table as $row) { |
1807
|
|
|
if ($row[0] != 'Ident') { |
1808
|
|
|
$ident = $row[0]; |
1809
|
|
|
$latitude = $row[2]; |
1810
|
|
|
$longitude = $row[3]; |
1811
|
|
|
$control = $row[4]; |
1812
|
|
|
if (isset($row[5])) $usage = $row[5]; else $usage = ''; |
1813
|
|
|
$query_dest_values = array(':ident' => $ident,':latitude' => $latitude,':longitude' => $longitude,':control' => $control,':usage' => $usage); |
1814
|
|
|
try { |
1815
|
|
|
$sth_dest->execute($query_dest_values); |
1816
|
|
|
} catch(PDOException $e) { |
1817
|
|
|
return "error : ".$e->getMessage(); |
1818
|
|
|
} |
1819
|
|
|
} |
1820
|
|
|
} |
1821
|
|
|
$Connection->db->commit(); |
1822
|
|
|
|
1823
|
|
|
} |
1824
|
|
|
*/ |
1825
|
|
|
public static function waypoints($filename) { |
1826
|
|
|
//require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
1827
|
|
|
global $tmp_dir, $globalTransaction; |
1828
|
|
|
//$Spotter = new Spotter(); |
1829
|
|
|
//$out_file = $tmp_dir.'translation.zip'; |
1830
|
|
|
//update_db::download('http://www.acarsd.org/download/translation.php',$out_file); |
1831
|
|
|
//if (!file_exists($out_file) || !is_readable($out_file)) return FALSE; |
1832
|
|
|
$Connection = new Connection(); |
1833
|
|
|
//update_db::unzip($out_file); |
1834
|
|
|
$header = NULL; |
|
|
|
|
1835
|
|
|
$delimiter = ' '; |
1836
|
|
|
if (($handle = fopen($filename, 'r')) !== FALSE) |
1837
|
|
|
{ |
1838
|
|
|
$i = 0; |
1839
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1840
|
|
|
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1841
|
|
|
{ |
1842
|
|
|
$i++; |
1843
|
|
|
if($i > 3 && count($row) > 2) { |
1844
|
|
|
$data = array_values(array_filter($row)); |
1845
|
|
|
$cntdata = count($data); |
1846
|
|
|
if ($cntdata > 10) { |
1847
|
|
|
$value = $data[9]; |
1848
|
|
|
|
1849
|
|
|
for ($i =10;$i < $cntdata;$i++) { |
1850
|
|
|
$value .= ' '.$data[$i]; |
1851
|
|
|
} |
1852
|
|
|
$data[9] = $value; |
1853
|
|
|
} |
1854
|
|
|
//print_r($data); |
1855
|
|
|
if (count($data) > 9) { |
1856
|
|
|
$query = 'INSERT INTO waypoints (name_begin,latitude_begin,longitude_begin,name_end,latitude_end,longitude_end,high,base,top,segment_name) VALUES (:name_begin, :latitude_begin, :longitude_begin, :name_end, :latitude_end, :longitude_end, :high, :base, :top, :segment_name)'; |
1857
|
|
|
try { |
1858
|
|
|
$sth = $Connection->db->prepare($query); |
1859
|
|
|
$sth->execute(array(':name_begin' => $data[0],':latitude_begin' => $data[1],':longitude_begin' => $data[2],':name_end' => $data[3], ':latitude_end' => $data[4], ':longitude_end' => $data[5], ':high' => $data[6], ':base' => $data[7], ':top' => $data[8], ':segment_name' => $data[9])); |
1860
|
|
|
} catch(PDOException $e) { |
1861
|
|
|
return "error : ".$e->getMessage(); |
1862
|
|
|
} |
1863
|
|
|
} |
1864
|
|
|
} |
1865
|
|
|
} |
1866
|
|
|
fclose($handle); |
1867
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1868
|
|
|
} |
1869
|
|
|
return ''; |
1870
|
|
|
} |
1871
|
|
|
|
1872
|
|
|
public static function update_fires() { |
1873
|
|
|
global $tmp_dir, $globalTransaction, $globalDebug; |
1874
|
|
|
require_once(dirname(__FILE__).'/../require/class.Source.php'); |
1875
|
|
|
$delimiter = ','; |
|
|
|
|
1876
|
|
|
$Common = new Common(); |
1877
|
|
|
$Common->download('http://firms.modaps.eosdis.nasa.gov/active_fire/viirs/text/VNP14IMGTDL_NRT_Global_24h.csv',$tmp_dir.'fires.csv'); |
1878
|
|
|
$Connection = new Connection(); |
|
|
|
|
1879
|
|
|
$Source = new Source(); |
1880
|
|
|
$Source->deleteLocationByType('fires'); |
1881
|
|
|
$i = 0; |
1882
|
|
|
if (($handle = fopen($tmp_dir.'fires.csv','r')) !== false) { |
1883
|
|
|
while (($row = fgetcsv($handle,1000)) !== false) { |
1884
|
|
|
if ($i > 0 && $row[0] != '' && $row[8] != 'low') { |
1885
|
|
|
$description = array('bright_t14' => $row[2],'scan' => $row[3],'track' => $row[4],'sat' => $row[7],'confidence' => $row[8],'version' => $row[9],'bright_t15' => $row[10],'frp' => $row[11],'daynight' => $row[12]); |
1886
|
|
|
$Source->addLocation('',$row[0],$row[1],null,'','','fires','fire.png','fires',0,0,$row[5].' '.substr($row[6],0,2).':'.substr($row[6],2,2),json_encode($description)); |
1887
|
|
|
} |
1888
|
|
|
$i++; |
1889
|
|
|
} |
1890
|
|
|
} |
1891
|
|
|
} |
1892
|
|
|
|
1893
|
|
|
public static function ivao_airlines($filename) { |
1894
|
|
|
//require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
1895
|
|
|
global $tmp_dir, $globalTransaction; |
1896
|
|
|
//$query = 'TRUNCATE TABLE airlines'; |
1897
|
|
|
$query = "DELETE FROM airlines WHERE forsource = 'ivao'"; |
1898
|
|
|
try { |
1899
|
|
|
$Connection = new Connection(); |
1900
|
|
|
$sth = $Connection->db->prepare($query); |
1901
|
|
|
$sth->execute(); |
1902
|
|
|
} catch(PDOException $e) { |
1903
|
|
|
return "error : ".$e->getMessage(); |
1904
|
|
|
} |
1905
|
|
|
$header = NULL; |
|
|
|
|
1906
|
|
|
$delimiter = ':'; |
1907
|
|
|
$Connection = new Connection(); |
1908
|
|
|
if (($handle = fopen($filename, 'r')) !== FALSE) |
1909
|
|
|
{ |
1910
|
|
|
if ($globalTransaction) $Connection->db->beginTransaction(); |
1911
|
|
|
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1912
|
|
|
{ |
1913
|
|
|
if(count($row) > 1) { |
1914
|
|
|
$query = "INSERT INTO airlines (name,icao,active,forsource) VALUES (:name, :icao, 'Y','ivao')"; |
1915
|
|
|
try { |
1916
|
|
|
$sth = $Connection->db->prepare($query); |
1917
|
|
|
$sth->execute(array(':name' => $row[1],':icao' => $row[0])); |
1918
|
|
|
} catch(PDOException $e) { |
1919
|
|
|
return "error : ".$e->getMessage(); |
1920
|
|
|
} |
1921
|
|
|
} |
1922
|
|
|
} |
1923
|
|
|
fclose($handle); |
1924
|
|
|
if ($globalTransaction) $Connection->db->commit(); |
1925
|
|
|
} |
1926
|
|
|
return ''; |
1927
|
|
|
} |
1928
|
|
|
|
1929
|
|
|
public static function update_airspace() { |
1930
|
|
|
global $tmp_dir, $globalDBdriver; |
1931
|
|
|
include_once('class.create_db.php'); |
1932
|
|
|
$Connection = new Connection(); |
1933
|
|
|
if ($Connection->tableExists('airspace')) { |
1934
|
|
|
$query = 'DROP TABLE airspace'; |
1935
|
|
|
try { |
1936
|
|
|
$sth = $Connection->db->prepare($query); |
1937
|
|
|
$sth->execute(); |
1938
|
|
|
} catch(PDOException $e) { |
1939
|
|
|
return "error : ".$e->getMessage(); |
1940
|
|
|
} |
1941
|
|
|
} |
1942
|
|
|
|
1943
|
|
|
|
1944
|
|
|
if ($globalDBdriver == 'mysql') update_db::gunzip('../db/airspace.sql.gz',$tmp_dir.'airspace.sql'); |
1945
|
|
|
else { |
1946
|
|
|
update_db::gunzip('../db/pgsql/airspace.sql.gz',$tmp_dir.'airspace.sql'); |
1947
|
|
|
$query = "CREATE EXTENSION postgis"; |
1948
|
|
|
$Connection = new Connection(null,null,$_SESSION['database_root'],$_SESSION['database_rootpass']); |
1949
|
|
|
try { |
1950
|
|
|
$sth = $Connection->db->prepare($query); |
1951
|
|
|
$sth->execute(); |
1952
|
|
|
} catch(PDOException $e) { |
1953
|
|
|
return "error : ".$e->getMessage(); |
1954
|
|
|
} |
1955
|
|
|
} |
1956
|
|
|
$error = create_db::import_file($tmp_dir.'airspace.sql'); |
1957
|
|
|
return $error; |
1958
|
|
|
} |
1959
|
|
|
|
1960
|
|
|
public static function update_notam_fam() { |
1961
|
|
|
global $tmp_dir, $globalDebug; |
1962
|
|
|
include_once('class.create_db.php'); |
1963
|
|
|
require_once(dirname(__FILE__).'/../require/class.NOTAM.php'); |
1964
|
|
|
if ($globalDebug) echo "NOTAM from FlightAirMap website : Download..."; |
1965
|
|
|
update_db::download('http://data.flightairmap.com/data/notam.txt.gz.md5',$tmp_dir.'notam.txt.gz.md5'); |
1966
|
|
|
$error = ''; |
1967
|
|
|
if (file_exists($tmp_dir.'notam.txt.gz.md5')) { |
1968
|
|
|
$notam_md5_file = explode(' ',file_get_contents($tmp_dir.'notam.txt.gz.md5')); |
1969
|
|
|
$notam_md5 = $notam_md5_file[0]; |
1970
|
|
|
if (!update_db::check_notam_version($notam_md5)) { |
1971
|
|
|
update_db::download('http://data.flightairmap.com/data/notam.txt.gz',$tmp_dir.'notam.txt.gz'); |
1972
|
|
|
if (file_exists($tmp_dir.'notam.txt.gz')) { |
1973
|
|
|
if (md5_file($tmp_dir.'notam.txt.gz') == $notam_md5) { |
1974
|
|
|
if ($globalDebug) echo "Gunzip..."; |
1975
|
|
|
update_db::gunzip($tmp_dir.'notam.txt.gz'); |
1976
|
|
|
if ($globalDebug) echo "Add to DB..."; |
1977
|
|
|
//$error = create_db::import_file($tmp_dir.'notam.sql'); |
1978
|
|
|
$NOTAM = new NOTAM(); |
1979
|
|
|
$NOTAM->updateNOTAMfromTextFile($tmp_dir.'notam.txt'); |
1980
|
|
|
update_db::insert_notam_version($notam_md5); |
1981
|
|
|
} else $error = "File ".$tmp_dir.'notam.txt.gz'." md5 failed. Download failed."; |
1982
|
|
|
} else $error = "File ".$tmp_dir.'notam.txt.gz'." doesn't exist. Download failed."; |
1983
|
|
|
} elseif ($globalDebug) echo "No new version."; |
1984
|
|
|
} else $error = "File ".$tmp_dir.'notam.txt.gz.md5'." doesn't exist. Download failed."; |
1985
|
|
|
if ($error != '') { |
1986
|
|
|
return $error; |
1987
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
1988
|
|
|
return ''; |
1989
|
|
|
} |
1990
|
|
|
|
1991
|
|
|
public static function update_vatsim() { |
1992
|
|
|
global $tmp_dir; |
1993
|
|
|
include_once('class.create_db.php'); |
1994
|
|
|
$error = create_db::import_file('../db/vatsim/airlines.sql'); |
1995
|
|
|
return $error; |
1996
|
|
|
} |
1997
|
|
|
|
1998
|
|
|
public static function update_countries() { |
1999
|
|
|
global $tmp_dir, $globalDBdriver; |
2000
|
|
|
include_once('class.create_db.php'); |
2001
|
|
|
$Connection = new Connection(); |
2002
|
|
|
if ($Connection->tableExists('countries')) { |
2003
|
|
|
$query = 'DROP TABLE countries'; |
2004
|
|
|
try { |
2005
|
|
|
$sth = $Connection->db->prepare($query); |
2006
|
|
|
$sth->execute(); |
2007
|
|
|
} catch(PDOException $e) { |
2008
|
|
|
echo "error : ".$e->getMessage(); |
2009
|
|
|
} |
2010
|
|
|
} |
2011
|
|
|
if ($globalDBdriver == 'mysql') { |
2012
|
|
|
update_db::gunzip('../db/countries.sql.gz',$tmp_dir.'countries.sql'); |
2013
|
|
|
} else { |
2014
|
|
|
update_db::gunzip('../db/pgsql/countries.sql.gz',$tmp_dir.'countries.sql'); |
2015
|
|
|
} |
2016
|
|
|
$error = create_db::import_file($tmp_dir.'countries.sql'); |
2017
|
|
|
return $error; |
2018
|
|
|
} |
2019
|
|
|
|
2020
|
|
|
|
2021
|
|
|
public static function update_waypoints() { |
2022
|
|
|
global $tmp_dir; |
2023
|
|
|
// update_db::download('http://dev.x-plane.com/update/data/AptNav201310XP1000.zip',$tmp_dir.'AptNav.zip'); |
2024
|
|
|
// update_db::unzip($tmp_dir.'AptNav.zip'); |
2025
|
|
|
// update_db::download('https://gitorious.org/fg/fgdata/raw/e81f8a15424a175a7b715f8f7eb8f4147b802a27:Navaids/awy.dat.gz',$tmp_dir.'awy.dat.gz'); |
2026
|
|
|
// update_db::download('http://sourceforge.net/p/flightgear/fgdata/ci/next/tree/Navaids/awy.dat.gz?format=raw',$tmp_dir.'awy.dat.gz','http://sourceforge.net'); |
2027
|
|
|
update_db::download('http://pkgs.fedoraproject.org/repo/extras/FlightGear-Atlas/awy.dat.gz/f530c9d1c4b31a288ba88dcc8224268b/awy.dat.gz',$tmp_dir.'awy.dat.gz','http://sourceforge.net'); |
2028
|
|
|
update_db::gunzip($tmp_dir.'awy.dat.gz'); |
2029
|
|
|
$error = update_db::waypoints($tmp_dir.'awy.dat'); |
2030
|
|
|
return $error; |
2031
|
|
|
} |
2032
|
|
|
|
2033
|
|
|
public static function update_ivao() { |
2034
|
|
|
global $tmp_dir, $globalDebug; |
2035
|
|
|
$Common = new Common(); |
2036
|
|
|
$error = ''; |
2037
|
|
|
//Direct download forbidden |
2038
|
|
|
//if ($globalDebug) echo "IVAO : Download..."; |
2039
|
|
|
//update_db::download('http://fr.mirror.ivao.aero/software/ivae_feb2013.zip',$tmp_dir.'ivae_feb2013.zip'); |
2040
|
|
|
if (extension_loaded('zip')) { |
2041
|
|
|
if (file_exists($tmp_dir.'ivae_feb2013.zip')) { |
2042
|
|
|
if ($globalDebug) echo "Unzip..."; |
2043
|
|
|
update_db::unzip($tmp_dir.'ivae_feb2013.zip'); |
2044
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2045
|
|
|
update_db::ivao_airlines($tmp_dir.'data/airlines.dat'); |
2046
|
|
|
if ($globalDebug) echo "Copy airlines logos to airlines images directory..."; |
2047
|
|
|
if (is_writable(dirname(__FILE__).'/../images/airlines')) { |
2048
|
|
|
if (!$Common->xcopy($tmp_dir.'logos/',dirname(__FILE__).'/../images/airlines/')) $error = "Failed to copy airlines logo."; |
2049
|
|
|
} else $error = "The directory ".dirname(__FILE__).'/../images/airlines'." must be writable"; |
2050
|
|
|
} else $error = "File ".$tmp_dir.'ivao.zip'." doesn't exist. Download failed."; |
2051
|
|
|
} else $error = "ZIP module not loaded but required for IVAO."; |
2052
|
|
|
if ($error != '') { |
2053
|
|
|
return $error; |
2054
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2055
|
|
|
return ''; |
2056
|
|
|
} |
2057
|
|
|
|
2058
|
|
|
public static function update_routes() { |
2059
|
|
|
global $tmp_dir, $globalDebug; |
2060
|
|
|
$error = ''; |
|
|
|
|
2061
|
|
|
if ($globalDebug) echo "Routes : Download..."; |
2062
|
|
|
update_db::download('http://www.virtualradarserver.co.uk/Files/StandingData.sqb.gz',$tmp_dir.'StandingData.sqb.gz'); |
2063
|
|
|
if (file_exists($tmp_dir.'StandingData.sqb.gz')) { |
2064
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2065
|
|
|
update_db::gunzip($tmp_dir.'StandingData.sqb.gz'); |
2066
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2067
|
|
|
$error = update_db::retrieve_route_sqlite_to_dest($tmp_dir.'StandingData.sqb'); |
2068
|
|
|
} else $error = "File ".$tmp_dir.'StandingData.sqb.gz'." doesn't exist. Download failed."; |
2069
|
|
|
if ($error != '') { |
2070
|
|
|
return $error; |
2071
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2072
|
|
|
return ''; |
2073
|
|
|
} |
2074
|
|
|
public static function update_oneworld() { |
2075
|
|
|
global $tmp_dir, $globalDebug; |
2076
|
|
|
$error = ''; |
|
|
|
|
2077
|
|
|
if ($globalDebug) echo "Schedules Oneworld : Download..."; |
2078
|
|
|
update_db::download('http://data.flightairmap.com/data/schedules/oneworld.csv.gz',$tmp_dir.'oneworld.csv.gz'); |
2079
|
|
|
if (file_exists($tmp_dir.'oneworld.csv.gz')) { |
2080
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2081
|
|
|
update_db::gunzip($tmp_dir.'oneworld.csv.gz'); |
2082
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2083
|
|
|
$error = update_db::retrieve_route_oneworld($tmp_dir.'oneworld.csv'); |
2084
|
|
|
} else $error = "File ".$tmp_dir.'oneworld.csv.gz'." doesn't exist. Download failed."; |
2085
|
|
|
if ($error != '') { |
2086
|
|
|
return $error; |
2087
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2088
|
|
|
return ''; |
2089
|
|
|
} |
2090
|
|
|
public static function update_skyteam() { |
2091
|
|
|
global $tmp_dir, $globalDebug; |
2092
|
|
|
$error = ''; |
|
|
|
|
2093
|
|
|
if ($globalDebug) echo "Schedules Skyteam : Download..."; |
2094
|
|
|
update_db::download('http://data.flightairmap.com/data/schedules/skyteam.csv.gz',$tmp_dir.'skyteam.csv.gz'); |
2095
|
|
|
if (file_exists($tmp_dir.'skyteam.csv.gz')) { |
2096
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2097
|
|
|
update_db::gunzip($tmp_dir.'skyteam.csv.gz'); |
2098
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2099
|
|
|
$error = update_db::retrieve_route_skyteam($tmp_dir.'skyteam.csv'); |
2100
|
|
|
} else $error = "File ".$tmp_dir.'skyteam.csv.gz'." doesn't exist. Download failed."; |
2101
|
|
|
if ($error != '') { |
2102
|
|
|
return $error; |
2103
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2104
|
|
|
return ''; |
2105
|
|
|
} |
2106
|
|
|
public static function update_ModeS() { |
2107
|
|
|
global $tmp_dir, $globalDebug; |
2108
|
|
|
/* |
2109
|
|
|
if ($globalDebug) echo "Modes : Download..."; |
2110
|
|
|
update_db::download('http://pp-sqb.mantma.co.uk/basestation_latest.zip',$tmp_dir.'basestation_latest.zip'); |
2111
|
|
|
if ($globalDebug) echo "Unzip..."; |
2112
|
|
|
update_db::unzip($tmp_dir.'basestation_latest.zip'); |
2113
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2114
|
|
|
$error = update_db::retrieve_modes_sqlite_to_dest($tmp_dir.'/basestation_latest/basestation.sqb'); |
2115
|
|
|
if ($error != true) { |
2116
|
|
|
echo $error; |
2117
|
|
|
exit; |
2118
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2119
|
|
|
*/ |
2120
|
|
|
if ($globalDebug) echo "Modes : Download..."; |
2121
|
|
|
// update_db::download('http://planebase.biz/sqb.php?f=basestationall.zip',$tmp_dir.'basestation_latest.zip','http://planebase.biz/bstnsqb'); |
2122
|
|
|
update_db::download('http://data.flightairmap.com/data/BaseStation.sqb.gz',$tmp_dir.'BaseStation.sqb.gz'); |
2123
|
|
|
|
2124
|
|
|
// if (file_exists($tmp_dir.'basestation_latest.zip')) { |
2125
|
|
|
if (file_exists($tmp_dir.'BaseStation.sqb.gz')) { |
2126
|
|
|
if ($globalDebug) echo "Unzip..."; |
2127
|
|
|
// update_db::unzip($tmp_dir.'basestation_latest.zip'); |
2128
|
|
|
update_db::gunzip($tmp_dir.'BaseStation.sqb.gz'); |
2129
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2130
|
|
|
$error = update_db::retrieve_modes_sqlite_to_dest($tmp_dir.'BaseStation.sqb'); |
2131
|
|
|
// $error = update_db::retrieve_modes_sqlite_to_dest($tmp_dir.'basestation.sqb'); |
2132
|
|
|
} else $error = "File ".$tmp_dir.'basestation_latest.zip'." doesn't exist. Download failed."; |
2133
|
|
|
if ($error != '') { |
2134
|
|
|
return $error; |
2135
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2136
|
|
|
return ''; |
2137
|
|
|
} |
2138
|
|
|
|
2139
|
|
|
public static function update_ModeS_faa() { |
2140
|
|
|
global $tmp_dir, $globalDebug; |
2141
|
|
|
if ($globalDebug) echo "Modes FAA: Download..."; |
2142
|
|
|
update_db::download('http://registry.faa.gov/database/ReleasableAircraft.zip',$tmp_dir.'ReleasableAircraft.zip'); |
2143
|
|
|
if (file_exists($tmp_dir.'ReleasableAircraft.zip')) { |
2144
|
|
|
if ($globalDebug) echo "Unzip..."; |
2145
|
|
|
update_db::unzip($tmp_dir.'ReleasableAircraft.zip'); |
2146
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2147
|
|
|
$error = update_db::modes_faa(); |
2148
|
|
|
} else $error = "File ".$tmp_dir.'ReleasableAircraft.zip'." doesn't exist. Download failed."; |
2149
|
|
|
if ($error != '') { |
2150
|
|
|
return $error; |
2151
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2152
|
|
|
return ''; |
2153
|
|
|
} |
2154
|
|
|
|
2155
|
|
|
public static function update_ModeS_flarm() { |
2156
|
|
|
global $tmp_dir, $globalDebug; |
2157
|
|
|
if ($globalDebug) echo "Modes Flarmnet: Download..."; |
2158
|
|
|
update_db::download('http://flarmnet.org/files/data.fln',$tmp_dir.'data.fln'); |
2159
|
|
|
if (file_exists($tmp_dir.'data.fln')) { |
2160
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2161
|
|
|
$error = update_db::retrieve_modes_flarmnet($tmp_dir.'data.fln'); |
2162
|
|
|
} else $error = "File ".$tmp_dir.'data.fln'." doesn't exist. Download failed."; |
2163
|
|
|
if ($error != '') { |
2164
|
|
|
return $error; |
2165
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2166
|
|
|
return ''; |
2167
|
|
|
} |
2168
|
|
|
|
2169
|
|
|
public static function update_ModeS_ogn() { |
2170
|
|
|
global $tmp_dir, $globalDebug; |
2171
|
|
|
if ($globalDebug) echo "Modes OGN: Download..."; |
2172
|
|
|
update_db::download('http://ddb.glidernet.org/download/',$tmp_dir.'ogn.csv'); |
2173
|
|
|
if (file_exists($tmp_dir.'ogn.csv')) { |
2174
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2175
|
|
|
$error = update_db::retrieve_modes_ogn($tmp_dir.'ogn.csv'); |
2176
|
|
|
} else $error = "File ".$tmp_dir.'ogn.csv'." doesn't exist. Download failed."; |
2177
|
|
|
if ($error != '') { |
2178
|
|
|
return $error; |
2179
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2180
|
|
|
return ''; |
2181
|
|
|
} |
2182
|
|
|
|
2183
|
|
|
public static function update_owner() { |
2184
|
|
|
global $tmp_dir, $globalDebug, $globalMasterSource; |
2185
|
|
|
|
2186
|
|
|
if ($globalDebug) echo "Owner France: Download..."; |
2187
|
|
|
update_db::download('http://antonakis.co.uk/registers/France.txt',$tmp_dir.'owner_f.csv'); |
2188
|
|
|
if (file_exists($tmp_dir.'owner_f.csv')) { |
2189
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2190
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_f.csv','F'); |
2191
|
|
|
} else $error = "File ".$tmp_dir.'owner_f.csv'." doesn't exist. Download failed."; |
2192
|
|
|
if ($error != '') { |
2193
|
|
|
return $error; |
2194
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2195
|
|
|
|
2196
|
|
|
if ($globalDebug) echo "Owner Ireland: Download..."; |
2197
|
|
|
update_db::download('http://antonakis.co.uk/registers/Ireland.txt',$tmp_dir.'owner_ei.csv'); |
2198
|
|
|
if (file_exists($tmp_dir.'owner_ei.csv')) { |
2199
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2200
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_ei.csv','EI'); |
2201
|
|
|
} else $error = "File ".$tmp_dir.'owner_ei.csv'." doesn't exist. Download failed."; |
2202
|
|
|
if ($error != '') { |
2203
|
|
|
return $error; |
2204
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2205
|
|
|
if ($globalDebug) echo "Owner Switzerland: Download..."; |
2206
|
|
|
update_db::download('http://antonakis.co.uk/registers/Switzerland.txt',$tmp_dir.'owner_hb.csv'); |
2207
|
|
|
if (file_exists($tmp_dir.'owner_hb.csv')) { |
2208
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2209
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_hb.csv','HB'); |
2210
|
|
|
} else $error = "File ".$tmp_dir.'owner_hb.csv'." doesn't exist. Download failed."; |
2211
|
|
|
if ($error != '') { |
2212
|
|
|
return $error; |
2213
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2214
|
|
|
if ($globalDebug) echo "Owner Czech Republic: Download..."; |
2215
|
|
|
update_db::download('http://antonakis.co.uk/registers/CzechRepublic.txt',$tmp_dir.'owner_ok.csv'); |
2216
|
|
|
if (file_exists($tmp_dir.'owner_ok.csv')) { |
2217
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2218
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_ok.csv','OK'); |
2219
|
|
|
} else $error = "File ".$tmp_dir.'owner_ok.csv'." doesn't exist. Download failed."; |
2220
|
|
|
if ($error != '') { |
2221
|
|
|
return $error; |
2222
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2223
|
|
|
if ($globalDebug) echo "Owner Australia: Download..."; |
2224
|
|
|
update_db::download('http://antonakis.co.uk/registers/Australia.txt',$tmp_dir.'owner_vh.csv'); |
2225
|
|
|
if (file_exists($tmp_dir.'owner_vh.csv')) { |
2226
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2227
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_vh.csv','VH'); |
2228
|
|
|
} else $error = "File ".$tmp_dir.'owner_vh.csv'." doesn't exist. Download failed."; |
2229
|
|
|
if ($error != '') { |
2230
|
|
|
return $error; |
2231
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2232
|
|
|
if ($globalDebug) echo "Owner Austria: Download..."; |
2233
|
|
|
update_db::download('http://antonakis.co.uk/registers/Austria.txt',$tmp_dir.'owner_oe.csv'); |
2234
|
|
|
if (file_exists($tmp_dir.'owner_oe.csv')) { |
2235
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2236
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_oe.csv','OE'); |
2237
|
|
|
} else $error = "File ".$tmp_dir.'owner_oe.csv'." doesn't exist. Download failed."; |
2238
|
|
|
if ($error != '') { |
2239
|
|
|
return $error; |
2240
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2241
|
|
|
if ($globalDebug) echo "Owner Chile: Download..."; |
2242
|
|
|
update_db::download('http://antonakis.co.uk/registers/Chile.txt',$tmp_dir.'owner_cc.csv'); |
2243
|
|
|
if (file_exists($tmp_dir.'owner_cc.csv')) { |
2244
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2245
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_cc.csv','CC'); |
2246
|
|
|
} else $error = "File ".$tmp_dir.'owner_cc.csv'." doesn't exist. Download failed."; |
2247
|
|
|
if ($error != '') { |
2248
|
|
|
return $error; |
2249
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2250
|
|
|
if ($globalDebug) echo "Owner Colombia: Download..."; |
2251
|
|
|
update_db::download('http://antonakis.co.uk/registers/Colombia.txt',$tmp_dir.'owner_hj.csv'); |
2252
|
|
|
if (file_exists($tmp_dir.'owner_hj.csv')) { |
2253
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2254
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_hj.csv','HJ'); |
2255
|
|
|
} else $error = "File ".$tmp_dir.'owner_hj.csv'." doesn't exist. Download failed."; |
2256
|
|
|
if ($error != '') { |
2257
|
|
|
return $error; |
2258
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2259
|
|
|
if ($globalDebug) echo "Owner Bosnia Herzegobina: Download..."; |
2260
|
|
|
update_db::download('http://antonakis.co.uk/registers/BosniaHerzegovina.txt',$tmp_dir.'owner_e7.csv'); |
2261
|
|
|
if (file_exists($tmp_dir.'owner_e7.csv')) { |
2262
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2263
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_e7.csv','E7'); |
2264
|
|
|
} else $error = "File ".$tmp_dir.'owner_e7.csv'." doesn't exist. Download failed."; |
2265
|
|
|
if ($error != '') { |
2266
|
|
|
return $error; |
2267
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2268
|
|
|
if ($globalDebug) echo "Owner Brazil: Download..."; |
2269
|
|
|
update_db::download('http://antonakis.co.uk/registers/Brazil.txt',$tmp_dir.'owner_pp.csv'); |
2270
|
|
|
if (file_exists($tmp_dir.'owner_pp.csv')) { |
2271
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2272
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_pp.csv','PP'); |
2273
|
|
|
} else $error = "File ".$tmp_dir.'owner_pp.csv'." doesn't exist. Download failed."; |
2274
|
|
|
if ($error != '') { |
2275
|
|
|
return $error; |
2276
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2277
|
|
|
if ($globalDebug) echo "Owner Cayman Islands: Download..."; |
2278
|
|
|
update_db::download('http://antonakis.co.uk/registers/CaymanIslands.txt',$tmp_dir.'owner_vp.csv'); |
2279
|
|
|
if (file_exists($tmp_dir.'owner_vp.csv')) { |
2280
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2281
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_vp.csv','VP'); |
2282
|
|
|
} else $error = "File ".$tmp_dir.'owner_vp.csv'." doesn't exist. Download failed."; |
2283
|
|
|
if ($error != '') { |
2284
|
|
|
return $error; |
2285
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2286
|
|
|
if ($globalDebug) echo "Owner Croatia: Download..."; |
2287
|
|
|
update_db::download('http://antonakis.co.uk/registers/Croatia.txt',$tmp_dir.'owner_9a.csv'); |
2288
|
|
|
if (file_exists($tmp_dir.'owner_9a.csv')) { |
2289
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2290
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_9a.csv','9A'); |
2291
|
|
|
} else $error = "File ".$tmp_dir.'owner_9a.csv'." doesn't exist. Download failed."; |
2292
|
|
|
if ($error != '') { |
2293
|
|
|
return $error; |
2294
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2295
|
|
|
if ($globalDebug) echo "Owner Luxembourg: Download..."; |
2296
|
|
|
update_db::download('http://antonakis.co.uk/registers/Luxembourg.txt',$tmp_dir.'owner_lx.csv'); |
2297
|
|
|
if (file_exists($tmp_dir.'owner_lx.csv')) { |
2298
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2299
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_lx.csv','LX'); |
2300
|
|
|
} else $error = "File ".$tmp_dir.'owner_lx.csv'." doesn't exist. Download failed."; |
2301
|
|
|
if ($error != '') { |
2302
|
|
|
return $error; |
2303
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2304
|
|
|
if ($globalDebug) echo "Owner Maldives: Download..."; |
2305
|
|
|
update_db::download('http://antonakis.co.uk/registers/Maldives.txt',$tmp_dir.'owner_8q.csv'); |
2306
|
|
|
if (file_exists($tmp_dir.'owner_8q.csv')) { |
2307
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2308
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_8q.csv','8Q'); |
2309
|
|
|
} else $error = "File ".$tmp_dir.'owner_8q.csv'." doesn't exist. Download failed."; |
2310
|
|
|
if ($error != '') { |
2311
|
|
|
return $error; |
2312
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2313
|
|
|
if ($globalDebug) echo "Owner New Zealand: Download..."; |
2314
|
|
|
update_db::download('http://antonakis.co.uk/registers/NewZealand.txt',$tmp_dir.'owner_zk.csv'); |
2315
|
|
|
if (file_exists($tmp_dir.'owner_zk.csv')) { |
2316
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2317
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_zk.csv','ZK'); |
2318
|
|
|
} else $error = "File ".$tmp_dir.'owner_zk.csv'." doesn't exist. Download failed."; |
2319
|
|
|
if ($error != '') { |
2320
|
|
|
return $error; |
2321
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2322
|
|
|
if ($globalDebug) echo "Owner Papua New Guinea: Download..."; |
2323
|
|
|
update_db::download('http://antonakis.co.uk/registers/PapuaNewGuinea.txt',$tmp_dir.'owner_p2.csv'); |
2324
|
|
|
if (file_exists($tmp_dir.'owner_p2.csv')) { |
2325
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2326
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_p2.csv','P2'); |
2327
|
|
|
} else $error = "File ".$tmp_dir.'owner_p2.csv'." doesn't exist. Download failed."; |
2328
|
|
|
if ($error != '') { |
2329
|
|
|
return $error; |
2330
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2331
|
|
|
if ($globalDebug) echo "Owner Slovakia: Download..."; |
2332
|
|
|
update_db::download('http://antonakis.co.uk/registers/Slovakia.txt',$tmp_dir.'owner_om.csv'); |
2333
|
|
|
if (file_exists($tmp_dir.'owner_om.csv')) { |
2334
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2335
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_om.csv','OM'); |
2336
|
|
|
} else $error = "File ".$tmp_dir.'owner_om.csv'." doesn't exist. Download failed."; |
2337
|
|
|
if ($error != '') { |
2338
|
|
|
return $error; |
2339
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2340
|
|
|
if ($globalDebug) echo "Owner Ecuador: Download..."; |
2341
|
|
|
update_db::download('http://antonakis.co.uk/registers/Ecuador.txt',$tmp_dir.'owner_hc.csv'); |
2342
|
|
|
if (file_exists($tmp_dir.'owner_hc.csv')) { |
2343
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2344
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_hc.csv','HC'); |
2345
|
|
|
} else $error = "File ".$tmp_dir.'owner_hc.csv'." doesn't exist. Download failed."; |
2346
|
|
|
if ($error != '') { |
2347
|
|
|
return $error; |
2348
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2349
|
|
|
if ($globalDebug) echo "Owner Iceland: Download..."; |
2350
|
|
|
update_db::download('http://antonakis.co.uk/registers/Iceland.txt',$tmp_dir.'owner_tf.csv'); |
2351
|
|
|
if (file_exists($tmp_dir.'owner_tf.csv')) { |
2352
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2353
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_tf.csv','TF'); |
2354
|
|
|
} else $error = "File ".$tmp_dir.'owner_tf.csv'." doesn't exist. Download failed."; |
2355
|
|
|
if ($error != '') { |
2356
|
|
|
return $error; |
2357
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2358
|
|
|
if ($globalDebug) echo "Owner Isle of Man: Download..."; |
2359
|
|
|
update_db::download('http://antonakis.co.uk/registers/IsleOfMan.txt',$tmp_dir.'owner_m.csv'); |
2360
|
|
|
if (file_exists($tmp_dir.'owner_m.csv')) { |
2361
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2362
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_m.csv','M'); |
2363
|
|
|
} else $error = "File ".$tmp_dir.'owner_m.csv'." doesn't exist. Download failed."; |
2364
|
|
|
if ($error != '') { |
2365
|
|
|
return $error; |
2366
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2367
|
|
|
if ($globalMasterSource) { |
2368
|
|
|
if ($globalDebug) echo "ModeS Netherlands: Download..."; |
2369
|
|
|
update_db::download('http://antonakis.co.uk/registers/Netherlands.txt',$tmp_dir.'owner_ph.csv'); |
2370
|
|
|
if (file_exists($tmp_dir.'owner_ph.csv')) { |
2371
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2372
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_ph.csv','PH'); |
2373
|
|
|
} else $error = "File ".$tmp_dir.'owner_ph.csv'." doesn't exist. Download failed."; |
2374
|
|
|
if ($error != '') { |
2375
|
|
|
return $error; |
2376
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2377
|
|
|
if ($globalDebug) echo "ModeS Denmark: Download..."; |
2378
|
|
|
update_db::download('http://antonakis.co.uk/registers/Denmark.txt',$tmp_dir.'owner_oy.csv'); |
2379
|
|
|
if (file_exists($tmp_dir.'owner_oy.csv')) { |
2380
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2381
|
|
|
$error = update_db::retrieve_owner($tmp_dir.'owner_oy.csv','OY'); |
2382
|
|
|
} else $error = "File ".$tmp_dir.'owner_oy.csv'." doesn't exist. Download failed."; |
2383
|
|
|
if ($error != '') { |
2384
|
|
|
return $error; |
2385
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2386
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2387
|
|
|
return ''; |
2388
|
|
|
} |
2389
|
|
|
|
2390
|
|
|
public static function update_translation() { |
2391
|
|
|
global $tmp_dir, $globalDebug; |
2392
|
|
|
$error = ''; |
|
|
|
|
2393
|
|
|
if ($globalDebug) echo "Translation : Download..."; |
2394
|
|
|
update_db::download('http://www.acarsd.org/download/translation.php',$tmp_dir.'translation.zip'); |
2395
|
|
|
if (file_exists($tmp_dir.'translation.zip')) { |
2396
|
|
|
if ($globalDebug) echo "Unzip..."; |
2397
|
|
|
update_db::unzip($tmp_dir.'translation.zip'); |
2398
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2399
|
|
|
$error = update_db::translation(); |
2400
|
|
|
} else $error = "File ".$tmp_dir.'translation.zip'." doesn't exist. Download failed."; |
2401
|
|
|
if ($error != '') { |
2402
|
|
|
return $error; |
2403
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2404
|
|
|
return ''; |
2405
|
|
|
} |
2406
|
|
|
|
2407
|
|
|
public static function update_translation_fam() { |
2408
|
|
|
global $tmp_dir, $globalDebug; |
2409
|
|
|
$error = ''; |
|
|
|
|
2410
|
|
|
if ($globalDebug) echo "Translation from FlightAirMap website : Download..."; |
2411
|
|
|
update_db::download('http://data.flightairmap.com/data/translation.tsv.gz',$tmp_dir.'translation.tsv.gz'); |
2412
|
|
|
update_db::download('http://data.flightairmap.com/data/translation.tsv.gz.md5',$tmp_dir.'translation.tsv.gz.md5'); |
2413
|
|
|
if (file_exists($tmp_dir.'translation.tsv.gz') && file_exists($tmp_dir.'translation.tsv.gz')) { |
2414
|
|
|
$translation_md5_file = explode(' ',file_get_contents($tmp_dir.'translation.tsv.gz.md5')); |
2415
|
|
|
$translation_md5 = $translation_md5_file[0]; |
2416
|
|
|
if (md5_file($tmp_dir.'translation.tsv.gz') == $translation_md5) { |
2417
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2418
|
|
|
update_db::gunzip($tmp_dir.'translation.tsv.gz'); |
2419
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2420
|
|
|
$error = update_db::translation_fam(); |
2421
|
|
|
} else $error = "File ".$tmp_dir.'translation.tsv.gz'." md5 failed. Download failed."; |
2422
|
|
|
} else $error = "File ".$tmp_dir.'translation.tsv.gz'." doesn't exist. Download failed."; |
2423
|
|
|
if ($error != '') { |
2424
|
|
|
return $error; |
2425
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2426
|
|
|
return ''; |
2427
|
|
|
} |
2428
|
|
|
public static function update_ModeS_fam() { |
2429
|
|
|
global $tmp_dir, $globalDebug; |
2430
|
|
|
$error = ''; |
|
|
|
|
2431
|
|
|
if ($globalDebug) echo "ModeS from FlightAirMap website : Download..."; |
2432
|
|
|
update_db::download('http://data.flightairmap.com/data/modes.tsv.gz',$tmp_dir.'modes.tsv.gz'); |
2433
|
|
|
update_db::download('http://data.flightairmap.com/data/modes.tsv.gz.md5',$tmp_dir.'modes.tsv.gz.md5'); |
2434
|
|
|
if (file_exists($tmp_dir.'modes.tsv.gz') && file_exists($tmp_dir.'modes.tsv.gz.md5')) { |
2435
|
|
|
$modes_md5_file = explode(' ',file_get_contents($tmp_dir.'modes.tsv.gz.md5')); |
2436
|
|
|
$modes_md5 = $modes_md5_file[0]; |
2437
|
|
|
if (md5_file($tmp_dir.'modes.tsv.gz') == $modes_md5) { |
2438
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2439
|
|
|
update_db::gunzip($tmp_dir.'modes.tsv.gz'); |
2440
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2441
|
|
|
$error = update_db::modes_fam(); |
2442
|
|
|
} else $error = "File ".$tmp_dir.'modes.tsv.gz'." md5 failed. Download failed."; |
2443
|
|
|
} else $error = "File ".$tmp_dir.'modes.tsv.gz'." doesn't exist. Download failed."; |
2444
|
|
|
if ($error != '') { |
2445
|
|
|
return $error; |
2446
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2447
|
|
|
return ''; |
2448
|
|
|
} |
2449
|
|
|
|
2450
|
|
|
public static function update_airlines_fam() { |
2451
|
|
|
global $tmp_dir, $globalDebug; |
2452
|
|
|
$error = ''; |
2453
|
|
|
if ($globalDebug) echo "Airlines from FlightAirMap website : Download..."; |
2454
|
|
|
update_db::download('http://data.flightairmap.com/data/airlines.tsv.gz.md5',$tmp_dir.'airlines.tsv.gz.md5'); |
2455
|
|
|
if (file_exists($tmp_dir.'airlines.tsv.gz.md5')) { |
2456
|
|
|
$airlines_md5_file = explode(' ',file_get_contents($tmp_dir.'airlines.tsv.gz.md5')); |
2457
|
|
|
$airlines_md5 = $airlines_md5_file[0]; |
2458
|
|
|
if (!update_db::check_airlines_version($airlines_md5)) { |
2459
|
|
|
update_db::download('http://data.flightairmap.com/data/airlines.tsv.gz',$tmp_dir.'airlines.tsv.gz'); |
2460
|
|
|
if (file_exists($tmp_dir.'airlines.tsv.gz')) { |
2461
|
|
|
if (md5_file($tmp_dir.'airlines.tsv.gz') == $airlines_md5) { |
2462
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2463
|
|
|
update_db::gunzip($tmp_dir.'airlines.tsv.gz'); |
2464
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2465
|
|
|
$error = update_db::airlines_fam(); |
2466
|
|
|
update_db::insert_airlines_version($airlines_md5); |
2467
|
|
|
} else $error = "File ".$tmp_dir.'airlines.tsv.gz'." md5 failed. Download failed."; |
2468
|
|
|
} else $error = "File ".$tmp_dir.'airlines.tsv.gz'." doesn't exist. Download failed."; |
2469
|
|
|
} elseif ($globalDebug) echo "No update."; |
2470
|
|
|
} else $error = "File ".$tmp_dir.'airlines.tsv.gz.md5'." doesn't exist. Download failed."; |
2471
|
|
|
if ($error != '') { |
2472
|
|
|
return $error; |
2473
|
|
|
} else { |
2474
|
|
|
if ($globalDebug) echo "Done\n"; |
2475
|
|
|
} |
2476
|
|
|
return ''; |
2477
|
|
|
} |
2478
|
|
|
|
2479
|
|
|
public static function update_owner_fam() { |
2480
|
|
|
global $tmp_dir, $globalDebug, $globalOwner; |
2481
|
|
|
if ($globalDebug) echo "owner from FlightAirMap website : Download..."; |
2482
|
|
|
$error = ''; |
|
|
|
|
2483
|
|
|
if ($globalOwner === TRUE) { |
2484
|
|
|
update_db::download('http://data.flightairmap.com/data/owners_all.tsv.gz',$tmp_dir.'owners.tsv.gz'); |
2485
|
|
|
update_db::download('http://data.flightairmap.com/data/owners_all.tsv.gz.md5',$tmp_dir.'owners.tsv.gz.md5'); |
2486
|
|
|
} else { |
2487
|
|
|
update_db::download('http://data.flightairmap.com/data/owners.tsv.gz',$tmp_dir.'owners.tsv.gz'); |
2488
|
|
|
update_db::download('http://data.flightairmap.com/data/owners.tsv.gz.md5',$tmp_dir.'owners.tsv.gz.md5'); |
2489
|
|
|
} |
2490
|
|
|
if (file_exists($tmp_dir.'owners.tsv.gz') && file_exists($tmp_dir.'owners.tsv.gz.md5')) { |
2491
|
|
|
$owners_md5_file = explode(' ',file_get_contents($tmp_dir.'owners.tsv.gz.md5')); |
2492
|
|
|
$owners_md5 = $owners_md5_file[0]; |
2493
|
|
|
if (md5_file($tmp_dir.'owners.tsv.gz') == $owners_md5) { |
2494
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2495
|
|
|
update_db::gunzip($tmp_dir.'owners.tsv.gz'); |
2496
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2497
|
|
|
$error = update_db::owner_fam(); |
2498
|
|
|
} else $error = "File ".$tmp_dir.'owners.tsv.gz'." md5 failed. Download failed."; |
2499
|
|
|
} else $error = "File ".$tmp_dir.'owners.tsv.gz'." doesn't exist. Download failed."; |
2500
|
|
|
if ($error != '') { |
2501
|
|
|
return $error; |
2502
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2503
|
|
|
return ''; |
2504
|
|
|
} |
2505
|
|
|
public static function update_routes_fam() { |
2506
|
|
|
global $tmp_dir, $globalDebug; |
2507
|
|
|
if ($globalDebug) echo "Routes from FlightAirMap website : Download..."; |
2508
|
|
|
update_db::download('http://data.flightairmap.com/data/routes.tsv.gz',$tmp_dir.'routes.tsv.gz'); |
2509
|
|
|
update_db::download('http://data.flightairmap.com/data/routes.tsv.gz.md5',$tmp_dir.'routes.tsv.gz.md5'); |
2510
|
|
|
if (file_exists($tmp_dir.'routes.tsv.gz') && file_exists($tmp_dir.'routes.tsv.gz.md5')) { |
2511
|
|
|
$routes_md5_file = explode(' ',file_get_contents($tmp_dir.'routes.tsv.gz.md5')); |
2512
|
|
|
$routes_md5 = $routes_md5_file[0]; |
2513
|
|
|
if (md5_file($tmp_dir.'routes.tsv.gz') == $routes_md5) { |
2514
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2515
|
|
|
update_db::gunzip($tmp_dir.'routes.tsv.gz'); |
2516
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2517
|
|
|
$error = update_db::routes_fam(); |
2518
|
|
|
} else $error = "File ".$tmp_dir.'routes.tsv.gz'." md5 failed. Download failed."; |
2519
|
|
|
} else $error = "File ".$tmp_dir.'routes.tsv.gz'." doesn't exist. Download failed."; |
2520
|
|
|
if ($error != '') { |
2521
|
|
|
return $error; |
2522
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2523
|
|
|
return ''; |
2524
|
|
|
} |
2525
|
|
|
public static function update_marine_identity_fam() { |
2526
|
|
|
global $tmp_dir, $globalDebug; |
2527
|
|
|
update_db::download('http://data.flightairmap.com/data/marine_identity.tsv.gz.md5',$tmp_dir.'marine_identity.tsv.gz.md5'); |
2528
|
|
|
if (file_exists($tmp_dir.'marine_identity.tsv.gz.md5')) { |
2529
|
|
|
$marine_identity_md5_file = explode(' ',file_get_contents($tmp_dir.'marine_identity.tsv.gz.md5')); |
2530
|
|
|
$marine_identity_md5 = $marine_identity_md5_file[0]; |
2531
|
|
|
if (!update_db::check_marine_identity_version($marine_identity_md5)) { |
2532
|
|
|
if ($globalDebug) echo "Marine identity from FlightAirMap website : Download..."; |
2533
|
|
|
update_db::download('http://data.flightairmap.com/data/marine_identity.tsv.gz',$tmp_dir.'marine_identity.tsv.gz'); |
2534
|
|
|
if (file_exists($tmp_dir.'marine_identity.tsv.gz')) { |
2535
|
|
|
if (md5_file($tmp_dir.'marine_identity.tsv.gz') == $marine_identity_md5) { |
2536
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2537
|
|
|
update_db::gunzip($tmp_dir.'marine_identity.tsv.gz'); |
2538
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2539
|
|
|
$error = update_db::marine_identity_fam(); |
2540
|
|
|
} else $error = "File ".$tmp_dir.'marine_identity.tsv.gz'." md5 failed. Download failed."; |
2541
|
|
|
} else $error = "File ".$tmp_dir.'marine_identity.tsv.gz'." doesn't exist. Download failed."; |
2542
|
|
|
if ($error != '') { |
2543
|
|
|
return $error; |
2544
|
|
|
} else { |
2545
|
|
|
update_db::insert_marine_identity_version($marine_identity_md5); |
2546
|
|
|
if ($globalDebug) echo "Done\n"; |
2547
|
|
|
} |
2548
|
|
|
} |
2549
|
|
|
} |
2550
|
|
|
return ''; |
2551
|
|
|
} |
2552
|
|
|
|
2553
|
|
|
public static function update_satellite_fam() { |
2554
|
|
|
global $tmp_dir, $globalDebug; |
2555
|
|
|
update_db::download('http://data.flightairmap.com/data/satellite.tsv.gz.md5',$tmp_dir.'satellite.tsv.gz.md5'); |
2556
|
|
|
if (file_exists($tmp_dir.'satellite.tsv.gz.md5')) { |
2557
|
|
|
$satellite_md5_file = explode(' ',file_get_contents($tmp_dir.'satellite.tsv.gz.md5')); |
2558
|
|
|
$satellite_md5 = $satellite_md5_file[0]; |
2559
|
|
|
if (!update_db::check_satellite_version($satellite_md5)) { |
2560
|
|
|
if ($globalDebug) echo "Satellite from FlightAirMap website : Download..."; |
2561
|
|
|
update_db::download('http://data.flightairmap.com/data/satellite.tsv.gz',$tmp_dir.'satellite.tsv.gz'); |
2562
|
|
|
if (file_exists($tmp_dir.'satellite.tsv.gz')) { |
2563
|
|
|
if (md5_file($tmp_dir.'satellite.tsv.gz') == $satellite_md5) { |
2564
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2565
|
|
|
update_db::gunzip($tmp_dir.'satellite.tsv.gz'); |
2566
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2567
|
|
|
$error = update_db::satellite_fam(); |
2568
|
|
|
} else $error = "File ".$tmp_dir.'satellite.tsv.gz'." md5 failed. Download failed."; |
2569
|
|
|
} else $error = "File ".$tmp_dir.'satellite.tsv.gz'." doesn't exist. Download failed."; |
2570
|
|
|
if ($error != '') { |
2571
|
|
|
return $error; |
2572
|
|
|
} else { |
2573
|
|
|
update_db::insert_satellite_version($satellite_md5); |
2574
|
|
|
if ($globalDebug) echo "Done\n"; |
2575
|
|
|
} |
2576
|
|
|
} |
2577
|
|
|
} |
2578
|
|
|
return ''; |
2579
|
|
|
} |
2580
|
|
|
public static function update_banned_fam() { |
2581
|
|
|
global $tmp_dir, $globalDebug; |
2582
|
|
|
if ($globalDebug) echo "Banned airlines in Europe from FlightAirMap website : Download..."; |
2583
|
|
|
update_db::download('http://data.flightairmap.com/data/ban-eu.csv',$tmp_dir.'ban_eu.csv'); |
2584
|
|
|
if (file_exists($tmp_dir.'ban_eu.csv')) { |
2585
|
|
|
//if ($globalDebug) echo "Gunzip..."; |
2586
|
|
|
//update_db::gunzip($tmp_dir.'ban_ue.csv'); |
2587
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2588
|
|
|
$error = update_db::banned_fam(); |
2589
|
|
|
} else $error = "File ".$tmp_dir.'ban_eu.csv'." doesn't exist. Download failed."; |
2590
|
|
|
if ($error != '') { |
2591
|
|
|
return $error; |
2592
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2593
|
|
|
return ''; |
2594
|
|
|
} |
2595
|
|
|
|
2596
|
|
|
public static function update_airspace_fam() { |
2597
|
|
|
global $tmp_dir, $globalDebug, $globalDBdriver; |
2598
|
|
|
include_once('class.create_db.php'); |
2599
|
|
|
$error = ''; |
2600
|
|
|
if ($globalDebug) echo "Airspace from FlightAirMap website : Download..."; |
2601
|
|
|
if ($globalDBdriver == 'mysql') { |
2602
|
|
|
update_db::download('http://data.flightairmap.com/data/airspace_mysql.sql.gz.md5',$tmp_dir.'airspace.sql.gz.md5'); |
2603
|
|
|
} else { |
2604
|
|
|
update_db::download('http://data.flightairmap.com/data/airspace_pgsql.sql.gz.md5',$tmp_dir.'airspace.sql.gz.md5'); |
2605
|
|
|
} |
2606
|
|
|
if (file_exists($tmp_dir.'airspace.sql.gz.md5')) { |
2607
|
|
|
$airspace_md5_file = explode(' ',file_get_contents($tmp_dir.'airspace.sql.gz.md5')); |
2608
|
|
|
$airspace_md5 = $airspace_md5_file[0]; |
2609
|
|
|
if (!update_db::check_airspace_version($airspace_md5)) { |
2610
|
|
|
if ($globalDBdriver == 'mysql') { |
2611
|
|
|
update_db::download('http://data.flightairmap.com/data/airspace_mysql.sql.gz',$tmp_dir.'airspace.sql.gz'); |
2612
|
|
|
} else { |
2613
|
|
|
update_db::download('http://data.flightairmap.com/data/airspace_pgsql.sql.gz',$tmp_dir.'airspace.sql.gz'); |
2614
|
|
|
} |
2615
|
|
|
if (file_exists($tmp_dir.'airspace.sql.gz')) { |
2616
|
|
|
if (md5_file($tmp_dir.'airspace.sql.gz') == $airspace_md5) { |
2617
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2618
|
|
|
update_db::gunzip($tmp_dir.'airspace.sql.gz'); |
2619
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2620
|
|
|
$Connection = new Connection(); |
2621
|
|
|
if ($Connection->tableExists('airspace')) { |
2622
|
|
|
$query = 'DROP TABLE airspace'; |
2623
|
|
|
try { |
2624
|
|
|
$sth = $Connection->db->prepare($query); |
2625
|
|
|
$sth->execute(); |
2626
|
|
|
} catch(PDOException $e) { |
2627
|
|
|
return "error : ".$e->getMessage(); |
2628
|
|
|
} |
2629
|
|
|
} |
2630
|
|
|
$error = create_db::import_file($tmp_dir.'airspace.sql'); |
2631
|
|
|
update_db::insert_airspace_version($airspace_md5); |
2632
|
|
|
} else $error = "File ".$tmp_dir.'airspace.sql.gz'." md5 failed. Download failed."; |
2633
|
|
|
} else $error = "File ".$tmp_dir.'airspace.sql.gz'." doesn't exist. Download failed."; |
2634
|
|
|
} |
2635
|
|
|
} else $error = "File ".$tmp_dir.'airspace.sql.gz.md5'." doesn't exist. Download failed."; |
2636
|
|
|
if ($error != '') { |
2637
|
|
|
return $error; |
2638
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2639
|
|
|
return ''; |
2640
|
|
|
} |
2641
|
|
|
|
2642
|
|
|
public static function update_geoid_fam() { |
2643
|
|
|
global $tmp_dir, $globalDebug, $globalGeoidSource; |
2644
|
|
|
$error = ''; |
2645
|
|
|
if ($globalDebug) echo "Geoid from FlightAirMap website : Download..."; |
2646
|
|
|
update_db::download('http://data.flightairmap.com/data/geoid/'.$globalGeoidSource.'.pgm.gz.md5',$tmp_dir.$globalGeoidSource.'.pgm.gz.md5'); |
2647
|
|
|
if (file_exists($tmp_dir.$globalGeoidSource.'.pgm.gz.md5')) { |
2648
|
|
|
$geoid_md5_file = explode(' ',file_get_contents($tmp_dir.$globalGeoidSource.'.pgm.gz.md5')); |
2649
|
|
|
$geoid_md5 = $geoid_md5_file[0]; |
2650
|
|
|
if (!update_db::check_geoid_version($geoid_md5)) { |
2651
|
|
|
update_db::download('http://data.flightairmap.com/data/geoid/'.$globalGeoidSource.'.pgm.gz',$tmp_dir.$globalGeoidSource.'.pgm.gz'); |
2652
|
|
|
if (file_exists($tmp_dir.$globalGeoidSource.'.pgm.gz')) { |
2653
|
|
|
if (md5_file($tmp_dir.$globalGeoidSource.'.pgm.gz') == $geoid_md5) { |
2654
|
|
|
if ($globalDebug) echo "Gunzip..."; |
2655
|
|
|
update_db::gunzip($tmp_dir.$globalGeoidSource.'.pgm.gz',dirname(__FILE__).'/../data/'.$globalGeoidSource.'.pgm'); |
2656
|
|
|
if (file_exists(dirname(__FILE__).'/../data/'.$globalGeoidSource.'.pgm')) { |
2657
|
|
|
update_db::insert_geoid_version($geoid_md5); |
2658
|
|
|
} |
2659
|
|
|
} else $error = "File ".$tmp_dir.$globalGeoidSource.'.pgm.gz'." md5 failed. Download failed."; |
2660
|
|
|
} else $error = "File ".$tmp_dir.$globalGeoidSource.'.pgm.gz'." doesn't exist. Download failed."; |
2661
|
|
|
} |
2662
|
|
|
} else $error = "File ".$tmp_dir.$globalGeoidSource.'.pgm.gz.md5'." doesn't exist. Download failed."; |
2663
|
|
|
if ($error != '') { |
2664
|
|
|
return $error; |
2665
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2666
|
|
|
return ''; |
2667
|
|
|
} |
2668
|
|
|
|
2669
|
|
|
public static function update_tle() { |
2670
|
|
|
global $tmp_dir, $globalDebug; |
2671
|
|
|
if ($globalDebug) echo "Download TLE : Download..."; |
2672
|
|
|
$alltle = array('stations.txt','gps-ops.txt','glo-ops.txt','galileo.txt','weather.txt','noaa.txt','goes.txt','resource.txt','dmc.txt','tdrss.txt','geo.txt','intelsat.txt','gorizont.txt', |
2673
|
|
|
'raduga.txt','molniya.txt','iridium.txt','orbcomm.txt','globalstar.txt','amateur.txt','x-comm.txt','other-comm.txt','sbas.txt','nnss.txt','musson.txt','science.txt','geodetic.txt', |
2674
|
|
|
'engineering.txt','education.txt','military.txt','radar.txt','cubesat.txt','other.txt','tle-new.txt','visual.txt','sarsat.txt','argos.txt','ses.txt','iridium-NEXT.txt','beidou.txt'); |
2675
|
|
|
foreach ($alltle as $filename) { |
2676
|
|
|
if ($globalDebug) echo "downloading ".$filename.'...'; |
2677
|
|
|
update_db::download('http://celestrak.com/NORAD/elements/'.$filename,$tmp_dir.$filename); |
2678
|
|
|
if (file_exists($tmp_dir.$filename)) { |
2679
|
|
|
if ($globalDebug) echo "Add to DB ".$filename."..."; |
2680
|
|
|
$error = update_db::tle($tmp_dir.$filename,str_replace('.txt','',$filename)); |
2681
|
|
|
} else $error = "File ".$tmp_dir.$filename." doesn't exist. Download failed."; |
2682
|
|
|
if ($error != '') { |
2683
|
|
|
echo $error."\n"; |
2684
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2685
|
|
|
} |
2686
|
|
|
return ''; |
2687
|
|
|
} |
2688
|
|
|
|
2689
|
|
|
public static function update_ucsdb() { |
2690
|
|
|
global $tmp_dir, $globalDebug; |
2691
|
|
|
if ($globalDebug) echo "Download UCS DB : Download..."; |
2692
|
|
|
update_db::download('https://s3.amazonaws.com/ucs-documents/nuclear-weapons/sat-database/4-11-17-update/UCS_Satellite_Database_officialname_1-1-17.txt',$tmp_dir.'UCS_Satellite_Database_officialname_1-1-17.txt'); |
2693
|
|
|
if (file_exists($tmp_dir.'UCS_Satellite_Database_officialname_1-1-17.txt')) { |
2694
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2695
|
|
|
$error = update_db::satellite_ucsdb($tmp_dir.'UCS_Satellite_Database_officialname_1-1-17.txt'); |
2696
|
|
|
} else $error = "File ".$tmp_dir.'UCS_Satellite_Database_officialname_1-1-17.txt'." doesn't exist. Download failed."; |
2697
|
|
|
if ($error != '') { |
2698
|
|
|
echo $error."\n"; |
2699
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2700
|
|
|
return ''; |
2701
|
|
|
} |
2702
|
|
|
|
2703
|
|
|
public static function update_celestrak() { |
2704
|
|
|
global $tmp_dir, $globalDebug; |
2705
|
|
|
if ($globalDebug) echo "Download Celestrak DB : Download..."; |
2706
|
|
|
update_db::download('http://celestrak.com/pub/satcat.txt',$tmp_dir.'satcat.txt'); |
2707
|
|
|
if (file_exists($tmp_dir.'satcat.txt')) { |
2708
|
|
|
if ($globalDebug) echo "Add to DB..."; |
2709
|
|
|
$error = update_db::satellite_celestrak($tmp_dir.'satcat.txt'); |
2710
|
|
|
} else $error = "File ".$tmp_dir.'satcat.txt'." doesn't exist. Download failed."; |
2711
|
|
|
if ($error != '') { |
2712
|
|
|
echo $error."\n"; |
2713
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2714
|
|
|
return ''; |
2715
|
|
|
} |
2716
|
|
|
|
2717
|
|
|
public static function update_models() { |
2718
|
|
|
global $tmp_dir, $globalDebug; |
2719
|
|
|
$error = ''; |
2720
|
|
|
if ($globalDebug) echo "Models from FlightAirMap website : Download..."; |
2721
|
|
|
update_db::download('http://data.flightairmap.com/data/models/models.md5sum',$tmp_dir.'models.md5sum'); |
2722
|
|
|
if (file_exists($tmp_dir.'models.md5sum')) { |
2723
|
|
|
if ($globalDebug) echo "Check files...\n"; |
2724
|
|
|
$newmodelsdb = array(); |
2725
|
|
|
if (($handle = fopen($tmp_dir.'models.md5sum','r')) !== FALSE) { |
2726
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2727
|
|
|
$model = trim($row[2]); |
2728
|
|
|
$newmodelsdb[$model] = trim($row[0]); |
2729
|
|
|
} |
2730
|
|
|
} |
2731
|
|
|
$modelsdb = array(); |
2732
|
|
|
if (file_exists(dirname(__FILE__).'/../models/models.md5sum')) { |
2733
|
|
|
if (($handle = fopen(dirname(__FILE__).'/../models/models.md5sum','r')) !== FALSE) { |
2734
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2735
|
|
|
$model = trim($row[2]); |
2736
|
|
|
$modelsdb[$model] = trim($row[0]); |
2737
|
|
|
} |
2738
|
|
|
} |
2739
|
|
|
} |
2740
|
|
|
$diff = array_diff($newmodelsdb,$modelsdb); |
2741
|
|
|
foreach ($diff as $key => $value) { |
2742
|
|
|
if ($globalDebug) echo 'Downloading model '.$key.' ...'."\n"; |
2743
|
|
|
update_db::download('http://data.flightairmap.com/data/models/'.$key,dirname(__FILE__).'/../models/'.$key); |
2744
|
|
|
|
2745
|
|
|
} |
2746
|
|
|
update_db::download('http://data.flightairmap.com/data/models/models.md5sum',dirname(__FILE__).'/../models/models.md5sum'); |
2747
|
|
|
} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed."; |
2748
|
|
|
if ($error != '') { |
2749
|
|
|
return $error; |
2750
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2751
|
|
|
if ($globalDebug) echo "glTF 2.0 Models from FlightAirMap website : Download..."; |
2752
|
|
|
update_db::download('http://data.flightairmap.com/data/models/gltf2/models.md5sum',$tmp_dir.'modelsgltf2.md5sum'); |
2753
|
|
|
if (file_exists($tmp_dir.'modelsgltf2.md5sum')) { |
2754
|
|
|
if ($globalDebug) echo "Check files...\n"; |
2755
|
|
|
$newmodelsdb = array(); |
2756
|
|
|
if (($handle = fopen($tmp_dir.'modelsgltf2.md5sum','r')) !== FALSE) { |
2757
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2758
|
|
|
$model = trim($row[2]); |
2759
|
|
|
$newmodelsdb[$model] = trim($row[0]); |
2760
|
|
|
} |
2761
|
|
|
} |
2762
|
|
|
$modelsdb = array(); |
2763
|
|
|
if (file_exists(dirname(__FILE__).'/../models/gltf2/models.md5sum')) { |
2764
|
|
|
if (($handle = fopen(dirname(__FILE__).'/../models/gltf2/models.md5sum','r')) !== FALSE) { |
2765
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2766
|
|
|
$model = trim($row[2]); |
2767
|
|
|
$modelsdb[$model] = trim($row[0]); |
2768
|
|
|
} |
2769
|
|
|
} |
2770
|
|
|
} |
2771
|
|
|
$diff = array_diff($newmodelsdb,$modelsdb); |
2772
|
|
|
foreach ($diff as $key => $value) { |
2773
|
|
|
if ($globalDebug) echo 'Downloading model '.$key.' ...'."\n"; |
2774
|
|
|
update_db::download('http://data.flightairmap.com/data/models/gltf2/'.$key,dirname(__FILE__).'/../models/gltf2/'.$key); |
2775
|
|
|
|
2776
|
|
|
} |
2777
|
|
|
update_db::download('http://data.flightairmap.com/data/models/gltf2/models.md5sum',dirname(__FILE__).'/../models/gltf2/models.md5sum'); |
2778
|
|
|
} else $error = "File ".$tmp_dir.'modelsgltf2.md5sum'." doesn't exist. Download failed."; |
2779
|
|
|
if ($error != '') { |
2780
|
|
|
return $error; |
2781
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2782
|
|
|
return ''; |
2783
|
|
|
} |
2784
|
|
|
|
2785
|
|
|
public static function update_liveries() { |
2786
|
|
|
global $tmp_dir, $globalDebug; |
2787
|
|
|
$error = ''; |
2788
|
|
|
if ($globalDebug) echo "Liveries from FlightAirMap website : Download..."; |
2789
|
|
|
update_db::download('http://data.flightairmap.com/data/models/gltf2/liveries/liveries.md5sum',$tmp_dir.'liveries.md5sum'); |
2790
|
|
|
if (file_exists($tmp_dir.'liveries.md5sum')) { |
2791
|
|
|
if ($globalDebug) echo "Check files...\n"; |
2792
|
|
|
$newmodelsdb = array(); |
2793
|
|
|
if (($handle = fopen($tmp_dir.'liveries.md5sum','r')) !== FALSE) { |
2794
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2795
|
|
|
$model = trim($row[2]); |
2796
|
|
|
$newmodelsdb[$model] = trim($row[0]); |
2797
|
|
|
} |
2798
|
|
|
} |
2799
|
|
|
$modelsdb = array(); |
2800
|
|
|
if (file_exists(dirname(__FILE__).'/../models/gltf2/liveries/liveries.md5sum')) { |
2801
|
|
|
if (($handle = fopen(dirname(__FILE__).'/../models/gltf2/liveries/liveries.md5sum','r')) !== FALSE) { |
2802
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2803
|
|
|
$model = trim($row[2]); |
2804
|
|
|
$modelsdb[$model] = trim($row[0]); |
2805
|
|
|
} |
2806
|
|
|
} |
2807
|
|
|
} |
2808
|
|
|
$diff = array_diff($newmodelsdb,$modelsdb); |
2809
|
|
|
foreach ($diff as $key => $value) { |
2810
|
|
|
if ($globalDebug) echo 'Downloading liveries '.$key.' ...'."\n"; |
2811
|
|
|
update_db::download('http://data.flightairmap.com/data/models/gltf2/liveries/'.$key,dirname(__FILE__).'/../models/gltf2/liveries/'.$key); |
2812
|
|
|
|
2813
|
|
|
} |
2814
|
|
|
update_db::download('http://data.flightairmap.com/data/models/gltf2/liveries/liveries.md5sum',dirname(__FILE__).'/../models/gltf2/liveries/liveries.md5sum'); |
2815
|
|
|
} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed."; |
2816
|
|
|
if ($error != '') { |
2817
|
|
|
return $error; |
2818
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2819
|
|
|
return ''; |
2820
|
|
|
} |
2821
|
|
|
|
2822
|
|
|
public static function update_space_models() { |
2823
|
|
|
global $tmp_dir, $globalDebug; |
2824
|
|
|
$error = ''; |
2825
|
|
|
if ($globalDebug) echo "Space models from FlightAirMap website : Download..."; |
2826
|
|
|
update_db::download('http://data.flightairmap.com/data/models/space/space_models.md5sum',$tmp_dir.'space_models.md5sum'); |
2827
|
|
|
if (file_exists($tmp_dir.'space_models.md5sum')) { |
2828
|
|
|
if ($globalDebug) echo "Check files...\n"; |
2829
|
|
|
$newmodelsdb = array(); |
2830
|
|
|
if (($handle = fopen($tmp_dir.'space_models.md5sum','r')) !== FALSE) { |
2831
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2832
|
|
|
$model = trim($row[2]); |
2833
|
|
|
$newmodelsdb[$model] = trim($row[0]); |
2834
|
|
|
} |
2835
|
|
|
} |
2836
|
|
|
$modelsdb = array(); |
2837
|
|
|
if (file_exists(dirname(__FILE__).'/../models/space/space_models.md5sum')) { |
2838
|
|
|
if (($handle = fopen(dirname(__FILE__).'/../models/space/space_models.md5sum','r')) !== FALSE) { |
2839
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2840
|
|
|
$model = trim($row[2]); |
2841
|
|
|
$modelsdb[$model] = trim($row[0]); |
2842
|
|
|
} |
2843
|
|
|
} |
2844
|
|
|
} |
2845
|
|
|
$diff = array_diff($newmodelsdb,$modelsdb); |
2846
|
|
|
foreach ($diff as $key => $value) { |
2847
|
|
|
if ($globalDebug) echo 'Downloading space model '.$key.' ...'."\n"; |
2848
|
|
|
update_db::download('http://data.flightairmap.com/data/models/space/'.$key,dirname(__FILE__).'/../models/space/'.$key); |
2849
|
|
|
|
2850
|
|
|
} |
2851
|
|
|
update_db::download('http://data.flightairmap.com/data/models/space/space_models.md5sum',dirname(__FILE__).'/../models/space/space_models.md5sum'); |
2852
|
|
|
} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed."; |
2853
|
|
|
if ($error != '') { |
2854
|
|
|
return $error; |
2855
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2856
|
|
|
return ''; |
2857
|
|
|
} |
2858
|
|
|
|
2859
|
|
|
public static function update_vehicules_models() { |
2860
|
|
|
global $tmp_dir, $globalDebug; |
2861
|
|
|
$error = ''; |
2862
|
|
|
if ($globalDebug) echo "Vehicules models from FlightAirMap website : Download..."; |
2863
|
|
|
update_db::download('http://data.flightairmap.com/data/models/vehicules/vehicules_models.md5sum',$tmp_dir.'vehicules_models.md5sum'); |
2864
|
|
|
if (file_exists($tmp_dir.'vehicules_models.md5sum')) { |
2865
|
|
|
if ($globalDebug) echo "Check files...\n"; |
2866
|
|
|
$newmodelsdb = array(); |
2867
|
|
|
if (($handle = fopen($tmp_dir.'vehicules_models.md5sum','r')) !== FALSE) { |
2868
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2869
|
|
|
$model = trim($row[2]); |
2870
|
|
|
$newmodelsdb[$model] = trim($row[0]); |
2871
|
|
|
} |
2872
|
|
|
} |
2873
|
|
|
$modelsdb = array(); |
2874
|
|
|
if (file_exists(dirname(__FILE__).'/../models/vehicules/vehicules_models.md5sum')) { |
2875
|
|
|
if (($handle = fopen(dirname(__FILE__).'/../models/vehicules/vehicules_models.md5sum','r')) !== FALSE) { |
2876
|
|
|
while (($row = fgetcsv($handle,1000," ")) !== FALSE) { |
2877
|
|
|
$model = trim($row[2]); |
2878
|
|
|
$modelsdb[$model] = trim($row[0]); |
2879
|
|
|
} |
2880
|
|
|
} |
2881
|
|
|
} |
2882
|
|
|
$diff = array_diff($newmodelsdb,$modelsdb); |
2883
|
|
|
foreach ($diff as $key => $value) { |
2884
|
|
|
if ($globalDebug) echo 'Downloading vehicules model '.$key.' ...'."\n"; |
2885
|
|
|
update_db::download('http://data.flightairmap.com/data/models/vehicules/'.$key,dirname(__FILE__).'/../models/vehicules/'.$key); |
2886
|
|
|
|
2887
|
|
|
} |
2888
|
|
|
update_db::download('http://data.flightairmap.com/data/models/vehicules/vehicules_models.md5sum',dirname(__FILE__).'/../models/vehicules/vehicules_models.md5sum'); |
2889
|
|
|
} else $error = "File ".$tmp_dir.'models.md5sum'." doesn't exist. Download failed."; |
2890
|
|
|
if ($error != '') { |
2891
|
|
|
return $error; |
2892
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
2893
|
|
|
return ''; |
2894
|
|
|
} |
2895
|
|
|
|
2896
|
|
|
public static function update_aircraft() { |
2897
|
|
|
global $tmp_dir, $globalDebug; |
2898
|
|
|
date_default_timezone_set('UTC'); |
2899
|
|
|
$Common = new Common(); |
2900
|
|
|
$data = $Common->getData('https://www4.icao.int/doc8643/External/AircraftTypes','post',array('X-Requested-With: XMLHttpRequest','Accept: application/json, text/javascript, */*; q=0.01','Host: www4.icao.int','Origin: https://www.icao.int','Content-Length: 0'),'','','https://www.icao.int/publications/DOC8643/Pages/Search.aspx',60); |
2901
|
|
|
$all = json_decode($data,true); |
2902
|
|
|
$Connection = new Connection(); |
2903
|
|
|
$querychk = "SELECT COUNT(1) as nb FROM aircraft WHERE icao = :icao"; |
2904
|
|
|
$sth = $Connection->db->prepare($querychk); |
2905
|
|
|
$queryins = "INSERT INTO aircraft (icao,type,manufacturer,aircraft_shadow,aircraft_description,engine_type,engine_count,wake_category,official_page) VALUES (:icao,:type,:manufacturer,:aircraft_shadow,:aircraft_description,:engine_type,:engine_count,:wake_category,'')"; |
2906
|
|
|
$queryup = "UPDATE aircraft SET type = :type WHERE icao = :icao"; |
2907
|
|
|
$sthins = $Connection->db->prepare($queryins); |
2908
|
|
|
$sthup = $Connection->db->prepare($queryup); |
2909
|
|
|
$allicao = array(); |
2910
|
|
|
foreach ($all as $model) { |
2911
|
|
|
$icao = $model['Designator']; |
2912
|
|
|
if (!isset($allicao[$icao])) { |
2913
|
|
|
$aircraft_shadow = 'generic_'.substr($model['EngineType'],0,1).$model['EngineCount'].$model['WTC'].'.png'; |
2914
|
|
|
$allicao[$icao] = array(':icao' => $icao,':type' => $model['ModelFullName'],':manufacturer' => $model['ManufacturerCode'],':aircraft_shadow' => $aircraft_shadow,':aircraft_description' => $model['AircraftDescription'],':engine_type' => $model['EngineType'],':engine_count' => $model['EngineCount'],':wake_category' => $model['WTC']); |
2915
|
|
|
} else { |
2916
|
|
|
$allicao[$icao][':type'] = $allicao[$icao][':type'].'/'.$model['ModelFullName']; |
2917
|
|
|
} |
2918
|
|
|
} |
2919
|
|
|
foreach ($allicao as $icao => $airdata) { |
2920
|
|
|
try { |
2921
|
|
|
$sth->execute(array(':icao' => $icao)); |
2922
|
|
|
$exist = $sth->fetchAll(PDO::FETCH_ASSOC); |
2923
|
|
|
if ($exist[0]['nb'] == 0) { |
2924
|
|
|
$sthins->execute($airdata); |
2925
|
|
|
} else { |
2926
|
|
|
$sthup->execute(array(':type' => $airdata[':type'],':icao' => $icao)); |
2927
|
|
|
} |
2928
|
|
|
} catch(PDOException $e) { |
2929
|
|
|
return "error : ".$e->getMessage(); |
2930
|
|
|
} |
2931
|
|
|
} |
2932
|
|
|
|
2933
|
|
|
/* |
2934
|
|
|
foreach ($all as $model) { |
2935
|
|
|
try { |
2936
|
|
|
$sth->execute(array(':icao' => $model['Designator'])); |
2937
|
|
|
$exist = $sth->fetchAll(PDO::FETCH_ASSOC); |
2938
|
|
|
if ($exist[0]['nb'] == 0) { |
2939
|
|
|
echo 'ICAO: '.$model['Designator'].' is not available'."\n"; |
2940
|
|
|
$aircraft_shadow = 'generic_'.substr($model['EngineType'],0,1).$model['EngineCount'].$model['WTC'].'.png'; |
2941
|
|
|
$sthins->execute(array(':icao' => $model['Designator'],':type' => $model['ModelFullName'],':manufacturer' => $model['ManufacturerCode'],':aircraft_shadow' => $aircraft_shadow,':aircraft_description' => $model['AircraftDescription'],':engine_type' => $model['EngineType'],':engine_count' => $model['EngineCount'],':wake_category' => $model['WTC'])); |
2942
|
|
|
} |
2943
|
|
|
} catch(PDOException $e) { |
2944
|
|
|
return "error : ".$e->getMessage(); |
2945
|
|
|
} |
2946
|
|
|
} |
2947
|
|
|
*/ |
2948
|
|
|
} |
2949
|
|
|
|
2950
|
|
|
public static function update_notam() { |
2951
|
|
|
global $tmp_dir, $globalDebug, $globalNOTAMSource; |
2952
|
|
|
require(dirname(__FILE__).'/../require/class.NOTAM.php'); |
2953
|
|
|
$Common = new Common(); |
2954
|
|
|
date_default_timezone_set('UTC'); |
2955
|
|
|
$query = 'TRUNCATE TABLE notam'; |
2956
|
|
|
try { |
2957
|
|
|
$Connection = new Connection(); |
2958
|
|
|
$sth = $Connection->db->prepare($query); |
2959
|
|
|
$sth->execute(); |
2960
|
|
|
} catch(PDOException $e) { |
2961
|
|
|
return "error : ".$e->getMessage(); |
2962
|
|
|
} |
2963
|
|
|
|
2964
|
|
|
$error = ''; |
2965
|
|
|
if ($globalDebug) echo "Notam : Download..."; |
2966
|
|
|
update_db::download($globalNOTAMSource,$tmp_dir.'notam.rss'); |
2967
|
|
|
if (file_exists($tmp_dir.'notam.rss')) { |
2968
|
|
|
$notams = json_decode(json_encode(simplexml_load_file($tmp_dir.'notam.rss')),true); |
2969
|
|
|
foreach ($notams['channel']['item'] as $notam) { |
2970
|
|
|
$title = explode(':',$notam['title']); |
2971
|
|
|
$data['ref'] = trim($title[0]); |
|
|
|
|
2972
|
|
|
unset($title[0]); |
2973
|
|
|
$data['title'] = trim(implode(':',$title)); |
|
|
|
|
2974
|
|
|
$description = strip_tags($notam['description'],'<pre>'); |
2975
|
|
|
preg_match(':^(.*?)<pre>:',$description,$match); |
2976
|
|
|
$q = explode('/',$match[1]); |
2977
|
|
|
$data['fir'] = $q[0]; |
2978
|
|
|
$data['code'] = $q[1]; |
2979
|
|
|
$ifrvfr = $q[2]; |
2980
|
|
|
if ($ifrvfr == 'IV') $data['rules'] = 'IFR/VFR'; |
2981
|
|
|
if ($ifrvfr == 'I') $data['rules'] = 'IFR'; |
2982
|
|
|
if ($ifrvfr == 'V') $data['rules'] = 'VFR'; |
2983
|
|
|
if ($q[4] == 'A') $data['scope'] = 'Airport warning'; |
2984
|
|
|
if ($q[4] == 'E') $data['scope'] = 'Enroute warning'; |
2985
|
|
|
if ($q[4] == 'W') $data['scope'] = 'Navigation warning'; |
2986
|
|
|
if ($q[4] == 'AE') $data['scope'] = 'Airport/Enroute warning'; |
2987
|
|
|
if ($q[4] == 'AW') $data['scope'] = 'Airport/Navigation warning'; |
2988
|
|
|
//$data['scope'] = $q[4]; |
2989
|
|
|
$data['lower_limit'] = $q[5]; |
2990
|
|
|
$data['upper_limit'] = $q[6]; |
2991
|
|
|
$latlonrad = $q[7]; |
2992
|
|
|
sscanf($latlonrad,'%4c%c%5c%c%3d',$las,$lac,$lns,$lnc,$radius); |
|
|
|
|
2993
|
|
|
$latitude = $Common->convertDec($las,'latitude'); |
2994
|
|
|
$longitude = $Common->convertDec($lns,'longitude'); |
2995
|
|
|
if ($lac == 'S') $latitude = '-'.$latitude; |
2996
|
|
|
if ($lnc == 'W') $longitude = '-'.$longitude; |
2997
|
|
|
$data['center_latitude'] = $latitude; |
2998
|
|
|
$data['center_longitude'] = $longitude; |
2999
|
|
|
$data['radius'] = intval($radius); |
3000
|
|
|
|
3001
|
|
|
preg_match(':<pre>(.*?)</pre>:',$description,$match); |
3002
|
|
|
$data['text'] = $match[1]; |
3003
|
|
|
preg_match(':</pre>(.*?)$:',$description,$match); |
3004
|
|
|
$fromto = $match[1]; |
3005
|
|
|
preg_match('#FROM:(.*?)TO:#',$fromto,$match); |
3006
|
|
|
$fromall = trim($match[1]); |
3007
|
|
|
preg_match('#^(.*?) \((.*?)\)$#',$fromall,$match); |
3008
|
|
|
$from = trim($match[1]); |
3009
|
|
|
$data['date_begin'] = date("Y-m-d H:i:s",strtotime($from)); |
3010
|
|
|
preg_match('#TO:(.*?)$#',$fromto,$match); |
3011
|
|
|
$toall = trim($match[1]); |
3012
|
|
|
if (!preg_match(':Permanent:',$toall)) { |
3013
|
|
|
preg_match('#^(.*?) \((.*?)\)#',$toall,$match); |
3014
|
|
|
$to = trim($match[1]); |
3015
|
|
|
$data['date_end'] = date("Y-m-d H:i:s",strtotime($to)); |
3016
|
|
|
$data['permanent'] = 0; |
3017
|
|
|
} else { |
3018
|
|
|
$data['date_end'] = NULL; |
3019
|
|
|
$data['permanent'] = 1; |
3020
|
|
|
} |
3021
|
|
|
$data['full_notam'] = $notam['title'].'<br>'.$notam['description']; |
3022
|
|
|
$NOTAM = new NOTAM(); |
3023
|
|
|
$NOTAM->addNOTAM($data['ref'],$data['title'],'',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['center_latitude'],$data['center_longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']); |
3024
|
|
|
unset($data); |
3025
|
|
|
} |
3026
|
|
|
} else $error = "File ".$tmp_dir.'notam.rss'." doesn't exist. Download failed."; |
3027
|
|
|
if ($error != '') { |
3028
|
|
|
return $error; |
3029
|
|
|
} elseif ($globalDebug) echo "Done\n"; |
3030
|
|
|
return ''; |
3031
|
|
|
} |
3032
|
|
|
|
3033
|
|
|
public static function create_airspace() { |
3034
|
|
|
global $globalDBdriver, $globalDebug, $tmp_dir, $globalDBhost, $globalDBuser, $globalDBname, $globalDBpass, $globalDBport; |
3035
|
|
|
$Connection = new Connection(); |
3036
|
|
|
if ($Connection->tableExists('airspace')) { |
3037
|
|
|
if ($globalDBdriver == 'mysql') { |
3038
|
|
|
$query = 'DROP TABLE geometry_columns; DROP TABLE spatial_ref_sys;DROP TABLE airspace;'; |
3039
|
|
|
} else { |
3040
|
|
|
$query = 'DROP TABLE airspace'; |
3041
|
|
|
} |
3042
|
|
|
try { |
3043
|
|
|
$Connection = new Connection(); |
3044
|
|
|
$sth = $Connection->db->prepare($query); |
3045
|
|
|
$sth->execute(); |
3046
|
|
|
} catch(PDOException $e) { |
3047
|
|
|
return "error : ".$e->getMessage(); |
3048
|
|
|
} |
3049
|
|
|
} |
3050
|
|
|
$Common = new Common(); |
3051
|
|
|
$airspace_lst = $Common->getData('https://raw.githubusercontent.com/XCSoar/xcsoar-data-repository/master/data/airspace.json'); |
3052
|
|
|
$airspace_json = json_decode($airspace_lst,true); |
3053
|
|
|
foreach ($airspace_json['records'] as $airspace) { |
3054
|
|
|
if ($globalDebug) echo $airspace['name']."...\n"; |
3055
|
|
|
update_db::download($airspace['uri'],$tmp_dir.$airspace['name']); |
3056
|
|
|
if (file_exists($tmp_dir.$airspace['name'])) { |
3057
|
|
|
file_put_contents($tmp_dir.$airspace['name'], utf8_encode(file_get_contents($tmp_dir.$airspace['name']))); |
3058
|
|
|
//system('recode l9..utf8 '.$tmp_dir.$airspace['name']); |
3059
|
|
|
if ($globalDBdriver == 'mysql') { |
3060
|
|
|
system('ogr2ogr -update -append -f "MySQL" MySQL:"'.$globalDBname.',host='.$globalDBhost.',user='.$globalDBuser.',password='.$globalDBpass.',port='.$globalDBport.'" -nln airspace -nlt POLYGON -skipfailures -lco ENGINE=MyISAM "'.$tmp_dir.$airspace['name'].'"'); |
3061
|
|
|
} else { |
3062
|
|
|
system('ogr2ogr -append -f "PostgreSQL" PG:"host='.$globalDBhost.' user='.$globalDBuser.' dbname='.$globalDBname.' password='.$globalDBpass.' port='.$globalDBport.'" -nln airspace -nlt POLYGON -skipfailures "'.$tmp_dir.$airspace['name'].'"'); |
3063
|
|
|
} |
3064
|
|
|
} |
3065
|
|
|
} |
3066
|
|
|
} |
3067
|
|
|
|
3068
|
|
|
public static function fix_icaotype() { |
3069
|
|
|
require_once(dirname(__FILE__).'/../require/class.Spotter.php'); |
3070
|
|
|
$Spotter = new Spotter(); |
3071
|
|
|
foreach ($Spotter->aircraft_correct_icaotype as $old => $new) { |
3072
|
|
|
$query = 'UPDATE aircraft_modes SET ICAOTypeCode = :new WHERE ICAOTypeCode = :old'; |
3073
|
|
|
try { |
3074
|
|
|
$Connection = new Connection(); |
3075
|
|
|
$sth = $Connection->db->prepare($query); |
3076
|
|
|
$sth->execute(array(':new' => $new, ':old' => $old)); |
3077
|
|
|
} catch(PDOException $e) { |
3078
|
|
|
return "error : ".$e->getMessage(); |
3079
|
|
|
} |
3080
|
|
|
} |
3081
|
|
|
} |
3082
|
|
|
|
3083
|
|
|
public static function check_last_update() { |
3084
|
|
|
global $globalDBdriver; |
3085
|
|
|
if ($globalDBdriver == 'mysql') { |
3086
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_db' AND value > DATE_SUB(NOW(), INTERVAL 15 DAY)"; |
3087
|
|
|
} else { |
3088
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_db' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '15 DAYS'"; |
3089
|
|
|
} |
3090
|
|
|
try { |
3091
|
|
|
$Connection = new Connection(); |
3092
|
|
|
$sth = $Connection->db->prepare($query); |
3093
|
|
|
$sth->execute(); |
3094
|
|
|
} catch(PDOException $e) { |
3095
|
|
|
return "error : ".$e->getMessage(); |
3096
|
|
|
} |
3097
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3098
|
|
|
if ($row['nb'] > 0) return false; |
3099
|
|
|
else return true; |
3100
|
|
|
} |
3101
|
|
|
|
3102
|
|
|
public static function insert_last_update() { |
3103
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_db'; |
3104
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_db',NOW());"; |
3105
|
|
|
try { |
3106
|
|
|
$Connection = new Connection(); |
3107
|
|
|
$sth = $Connection->db->prepare($query); |
3108
|
|
|
$sth->execute(); |
3109
|
|
|
} catch(PDOException $e) { |
3110
|
|
|
return "error : ".$e->getMessage(); |
3111
|
|
|
} |
3112
|
|
|
} |
3113
|
|
|
|
3114
|
|
|
public static function check_airspace_version($version) { |
3115
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'airspace_version' AND value = :version"; |
3116
|
|
|
try { |
3117
|
|
|
$Connection = new Connection(); |
3118
|
|
|
$sth = $Connection->db->prepare($query); |
3119
|
|
|
$sth->execute(array(':version' => $version)); |
3120
|
|
|
} catch(PDOException $e) { |
3121
|
|
|
return "error : ".$e->getMessage(); |
3122
|
|
|
} |
3123
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3124
|
|
|
if ($row['nb'] > 0) return true; |
3125
|
|
|
else return false; |
3126
|
|
|
} |
3127
|
|
|
|
3128
|
|
|
public static function check_geoid_version($version) { |
3129
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'geoid_version' AND value = :version"; |
3130
|
|
|
try { |
3131
|
|
|
$Connection = new Connection(); |
3132
|
|
|
$sth = $Connection->db->prepare($query); |
3133
|
|
|
$sth->execute(array(':version' => $version)); |
3134
|
|
|
} catch(PDOException $e) { |
3135
|
|
|
return "error : ".$e->getMessage(); |
3136
|
|
|
} |
3137
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3138
|
|
|
if ($row['nb'] > 0) return true; |
3139
|
|
|
else return false; |
3140
|
|
|
} |
3141
|
|
|
|
3142
|
|
|
public static function check_marine_identity_version($version) { |
3143
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'marine_identity_version' AND value = :version"; |
3144
|
|
|
try { |
3145
|
|
|
$Connection = new Connection(); |
3146
|
|
|
$sth = $Connection->db->prepare($query); |
3147
|
|
|
$sth->execute(array(':version' => $version)); |
3148
|
|
|
} catch(PDOException $e) { |
3149
|
|
|
return "error : ".$e->getMessage(); |
3150
|
|
|
} |
3151
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3152
|
|
|
if ($row['nb'] > 0) return true; |
3153
|
|
|
else return false; |
3154
|
|
|
} |
3155
|
|
|
|
3156
|
|
|
public static function check_satellite_version($version) { |
3157
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'satellite_version' AND value = :version"; |
3158
|
|
|
try { |
3159
|
|
|
$Connection = new Connection(); |
3160
|
|
|
$sth = $Connection->db->prepare($query); |
3161
|
|
|
$sth->execute(array(':version' => $version)); |
3162
|
|
|
} catch(PDOException $e) { |
3163
|
|
|
return "error : ".$e->getMessage(); |
3164
|
|
|
} |
3165
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3166
|
|
|
if ($row['nb'] > 0) return true; |
3167
|
|
|
else return false; |
3168
|
|
|
} |
3169
|
|
|
|
3170
|
|
|
public static function check_airlines_version($version) { |
3171
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'airlines_version' AND value = :version"; |
3172
|
|
|
try { |
3173
|
|
|
$Connection = new Connection(); |
3174
|
|
|
$sth = $Connection->db->prepare($query); |
3175
|
|
|
$sth->execute(array(':version' => $version)); |
3176
|
|
|
} catch(PDOException $e) { |
3177
|
|
|
return "error : ".$e->getMessage(); |
3178
|
|
|
} |
3179
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3180
|
|
|
if ($row['nb'] > 0) return true; |
3181
|
|
|
else return false; |
3182
|
|
|
} |
3183
|
|
|
|
3184
|
|
|
public static function check_notam_version($version) { |
3185
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'notam_version' AND value = :version"; |
3186
|
|
|
try { |
3187
|
|
|
$Connection = new Connection(); |
3188
|
|
|
$sth = $Connection->db->prepare($query); |
3189
|
|
|
$sth->execute(array(':version' => $version)); |
3190
|
|
|
} catch(PDOException $e) { |
3191
|
|
|
return "error : ".$e->getMessage(); |
3192
|
|
|
} |
3193
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3194
|
|
|
if ($row['nb'] > 0) return true; |
3195
|
|
|
else return false; |
3196
|
|
|
} |
3197
|
|
|
|
3198
|
|
|
public static function insert_airlines_version($version) { |
3199
|
|
|
$query = "DELETE FROM config WHERE name = 'airlines_version'; |
3200
|
|
|
INSERT INTO config (name,value) VALUES ('airlines_version',:version);"; |
3201
|
|
|
try { |
3202
|
|
|
$Connection = new Connection(); |
3203
|
|
|
$sth = $Connection->db->prepare($query); |
3204
|
|
|
$sth->execute(array(':version' => $version)); |
3205
|
|
|
} catch(PDOException $e) { |
3206
|
|
|
return "error : ".$e->getMessage(); |
3207
|
|
|
} |
3208
|
|
|
} |
3209
|
|
|
|
3210
|
|
|
public static function insert_notam_version($version) { |
3211
|
|
|
$query = "DELETE FROM config WHERE name = 'notam_version'; |
3212
|
|
|
INSERT INTO config (name,value) VALUES ('notam_version',:version);"; |
3213
|
|
|
try { |
3214
|
|
|
$Connection = new Connection(); |
3215
|
|
|
$sth = $Connection->db->prepare($query); |
3216
|
|
|
$sth->execute(array(':version' => $version)); |
3217
|
|
|
} catch(PDOException $e) { |
3218
|
|
|
return "error : ".$e->getMessage(); |
3219
|
|
|
} |
3220
|
|
|
} |
3221
|
|
|
|
3222
|
|
|
public static function insert_airspace_version($version) { |
3223
|
|
|
$query = "DELETE FROM config WHERE name = 'airspace_version'; |
3224
|
|
|
INSERT INTO config (name,value) VALUES ('airspace_version',:version);"; |
3225
|
|
|
try { |
3226
|
|
|
$Connection = new Connection(); |
3227
|
|
|
$sth = $Connection->db->prepare($query); |
3228
|
|
|
$sth->execute(array(':version' => $version)); |
3229
|
|
|
} catch(PDOException $e) { |
3230
|
|
|
return "error : ".$e->getMessage(); |
3231
|
|
|
} |
3232
|
|
|
} |
3233
|
|
|
|
3234
|
|
|
public static function insert_geoid_version($version) { |
3235
|
|
|
$query = "DELETE FROM config WHERE name = 'geoid_version'; |
3236
|
|
|
INSERT INTO config (name,value) VALUES ('geoid_version',:version);"; |
3237
|
|
|
try { |
3238
|
|
|
$Connection = new Connection(); |
3239
|
|
|
$sth = $Connection->db->prepare($query); |
3240
|
|
|
$sth->execute(array(':version' => $version)); |
3241
|
|
|
} catch(PDOException $e) { |
3242
|
|
|
return "error : ".$e->getMessage(); |
3243
|
|
|
} |
3244
|
|
|
} |
3245
|
|
|
|
3246
|
|
|
public static function insert_marine_identity_version($version) { |
3247
|
|
|
$query = "DELETE FROM config WHERE name = 'marine_identity_version'; |
3248
|
|
|
INSERT INTO config (name,value) VALUES ('marine_identity_version',:version);"; |
3249
|
|
|
try { |
3250
|
|
|
$Connection = new Connection(); |
3251
|
|
|
$sth = $Connection->db->prepare($query); |
3252
|
|
|
$sth->execute(array(':version' => $version)); |
3253
|
|
|
} catch(PDOException $e) { |
3254
|
|
|
return "error : ".$e->getMessage(); |
3255
|
|
|
} |
3256
|
|
|
} |
3257
|
|
|
|
3258
|
|
|
public static function insert_satellite_version($version) { |
3259
|
|
|
$query = "DELETE FROM config WHERE name = 'satellite_version'; |
3260
|
|
|
INSERT INTO config (name,value) VALUES ('satellite_version',:version);"; |
3261
|
|
|
try { |
3262
|
|
|
$Connection = new Connection(); |
3263
|
|
|
$sth = $Connection->db->prepare($query); |
3264
|
|
|
$sth->execute(array(':version' => $version)); |
3265
|
|
|
} catch(PDOException $e) { |
3266
|
|
|
return "error : ".$e->getMessage(); |
3267
|
|
|
} |
3268
|
|
|
} |
3269
|
|
|
|
3270
|
|
|
public static function check_last_notam_update() { |
3271
|
|
|
global $globalDBdriver; |
3272
|
|
|
if ($globalDBdriver == 'mysql') { |
3273
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_notam_db' AND value > DATE_SUB(NOW(), INTERVAL 1 DAY)"; |
3274
|
|
|
} else { |
3275
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_notam_db' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '1 DAYS'"; |
3276
|
|
|
} |
3277
|
|
|
try { |
3278
|
|
|
$Connection = new Connection(); |
3279
|
|
|
$sth = $Connection->db->prepare($query); |
3280
|
|
|
$sth->execute(); |
3281
|
|
|
} catch(PDOException $e) { |
3282
|
|
|
return "error : ".$e->getMessage(); |
3283
|
|
|
} |
3284
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3285
|
|
|
if ($row['nb'] > 0) return false; |
3286
|
|
|
else return true; |
3287
|
|
|
} |
3288
|
|
|
|
3289
|
|
|
public static function insert_last_notam_update() { |
3290
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_notam_db'; |
3291
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_notam_db',NOW());"; |
3292
|
|
|
try { |
3293
|
|
|
$Connection = new Connection(); |
3294
|
|
|
$sth = $Connection->db->prepare($query); |
3295
|
|
|
$sth->execute(); |
3296
|
|
|
} catch(PDOException $e) { |
3297
|
|
|
return "error : ".$e->getMessage(); |
3298
|
|
|
} |
3299
|
|
|
} |
3300
|
|
|
|
3301
|
|
|
public static function check_last_airspace_update() { |
3302
|
|
|
global $globalDBdriver; |
3303
|
|
|
if ($globalDBdriver == 'mysql') { |
3304
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_airspace_db' AND value > DATE_SUB(NOW(), INTERVAL 7 DAY)"; |
3305
|
|
|
} else { |
3306
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_airspace_db' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '7 DAYS'"; |
3307
|
|
|
} |
3308
|
|
|
try { |
3309
|
|
|
$Connection = new Connection(); |
3310
|
|
|
$sth = $Connection->db->prepare($query); |
3311
|
|
|
$sth->execute(); |
3312
|
|
|
} catch(PDOException $e) { |
3313
|
|
|
return "error : ".$e->getMessage(); |
3314
|
|
|
} |
3315
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3316
|
|
|
if ($row['nb'] > 0) return false; |
3317
|
|
|
else return true; |
3318
|
|
|
} |
3319
|
|
|
|
3320
|
|
|
public static function insert_last_airspace_update() { |
3321
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_airspace_db'; |
3322
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_airspace_db',NOW());"; |
3323
|
|
|
try { |
3324
|
|
|
$Connection = new Connection(); |
3325
|
|
|
$sth = $Connection->db->prepare($query); |
3326
|
|
|
$sth->execute(); |
3327
|
|
|
} catch(PDOException $e) { |
3328
|
|
|
return "error : ".$e->getMessage(); |
3329
|
|
|
} |
3330
|
|
|
} |
3331
|
|
|
|
3332
|
|
|
public static function check_last_geoid_update() { |
3333
|
|
|
global $globalDBdriver; |
3334
|
|
|
if ($globalDBdriver == 'mysql') { |
3335
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_geoid' AND value > DATE_SUB(NOW(), INTERVAL 7 DAY)"; |
3336
|
|
|
} else { |
3337
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_geoid' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '7 DAYS'"; |
3338
|
|
|
} |
3339
|
|
|
try { |
3340
|
|
|
$Connection = new Connection(); |
3341
|
|
|
$sth = $Connection->db->prepare($query); |
3342
|
|
|
$sth->execute(); |
3343
|
|
|
} catch(PDOException $e) { |
3344
|
|
|
return "error : ".$e->getMessage(); |
3345
|
|
|
} |
3346
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3347
|
|
|
if ($row['nb'] > 0) return false; |
3348
|
|
|
else return true; |
3349
|
|
|
} |
3350
|
|
|
|
3351
|
|
|
public static function insert_last_geoid_update() { |
3352
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_geoid'; |
3353
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_geoid',NOW());"; |
3354
|
|
|
try { |
3355
|
|
|
$Connection = new Connection(); |
3356
|
|
|
$sth = $Connection->db->prepare($query); |
3357
|
|
|
$sth->execute(); |
3358
|
|
|
} catch(PDOException $e) { |
3359
|
|
|
return "error : ".$e->getMessage(); |
3360
|
|
|
} |
3361
|
|
|
} |
3362
|
|
|
|
3363
|
|
|
public static function check_last_owner_update() { |
3364
|
|
|
global $globalDBdriver; |
3365
|
|
|
if ($globalDBdriver == 'mysql') { |
3366
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_owner_db' AND value > DATE_SUB(NOW(), INTERVAL 15 DAY)"; |
3367
|
|
|
} else { |
3368
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_owner_db' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '15 DAYS'"; |
3369
|
|
|
} |
3370
|
|
|
try { |
3371
|
|
|
$Connection = new Connection(); |
3372
|
|
|
$sth = $Connection->db->prepare($query); |
3373
|
|
|
$sth->execute(); |
3374
|
|
|
} catch(PDOException $e) { |
3375
|
|
|
return "error : ".$e->getMessage(); |
3376
|
|
|
} |
3377
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3378
|
|
|
if ($row['nb'] > 0) return false; |
3379
|
|
|
else return true; |
3380
|
|
|
} |
3381
|
|
|
|
3382
|
|
|
public static function insert_last_owner_update() { |
3383
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_owner_db'; |
3384
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_owner_db',NOW());"; |
3385
|
|
|
try { |
3386
|
|
|
$Connection = new Connection(); |
3387
|
|
|
$sth = $Connection->db->prepare($query); |
3388
|
|
|
$sth->execute(); |
3389
|
|
|
} catch(PDOException $e) { |
3390
|
|
|
return "error : ".$e->getMessage(); |
3391
|
|
|
} |
3392
|
|
|
} |
3393
|
|
|
|
3394
|
|
|
public static function check_last_fires_update() { |
3395
|
|
|
global $globalDBdriver; |
3396
|
|
|
if ($globalDBdriver == 'mysql') { |
3397
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_fires' AND value > DATE_SUB(NOW(), INTERVAL 1 HOUR)"; |
3398
|
|
|
} else { |
3399
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_fires' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '1 HOUR'"; |
3400
|
|
|
} |
3401
|
|
|
try { |
3402
|
|
|
$Connection = new Connection(); |
3403
|
|
|
$sth = $Connection->db->prepare($query); |
3404
|
|
|
$sth->execute(); |
3405
|
|
|
} catch(PDOException $e) { |
3406
|
|
|
return "error : ".$e->getMessage(); |
3407
|
|
|
} |
3408
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3409
|
|
|
if ($row['nb'] > 0) return false; |
3410
|
|
|
else return true; |
3411
|
|
|
} |
3412
|
|
|
|
3413
|
|
|
public static function insert_last_fires_update() { |
3414
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_fires'; |
3415
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_fires',NOW());"; |
3416
|
|
|
try { |
3417
|
|
|
$Connection = new Connection(); |
3418
|
|
|
$sth = $Connection->db->prepare($query); |
3419
|
|
|
$sth->execute(); |
3420
|
|
|
} catch(PDOException $e) { |
3421
|
|
|
return "error : ".$e->getMessage(); |
3422
|
|
|
} |
3423
|
|
|
} |
3424
|
|
|
|
3425
|
|
|
public static function check_last_airlines_update() { |
3426
|
|
|
global $globalDBdriver; |
3427
|
|
|
if ($globalDBdriver == 'mysql') { |
3428
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_airlines_db' AND value > DATE_SUB(NOW(), INTERVAL 15 DAY)"; |
3429
|
|
|
} else { |
3430
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_airlines_db' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '15 DAYS'"; |
3431
|
|
|
} |
3432
|
|
|
try { |
3433
|
|
|
$Connection = new Connection(); |
3434
|
|
|
$sth = $Connection->db->prepare($query); |
3435
|
|
|
$sth->execute(); |
3436
|
|
|
} catch(PDOException $e) { |
3437
|
|
|
return "error : ".$e->getMessage(); |
3438
|
|
|
} |
3439
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3440
|
|
|
if ($row['nb'] > 0) return false; |
3441
|
|
|
else return true; |
3442
|
|
|
} |
3443
|
|
|
|
3444
|
|
|
public static function insert_last_airlines_update() { |
3445
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_airlines_db'; |
3446
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_airlines_db',NOW());"; |
3447
|
|
|
try { |
3448
|
|
|
$Connection = new Connection(); |
3449
|
|
|
$sth = $Connection->db->prepare($query); |
3450
|
|
|
$sth->execute(); |
3451
|
|
|
} catch(PDOException $e) { |
3452
|
|
|
return "error : ".$e->getMessage(); |
3453
|
|
|
} |
3454
|
|
|
} |
3455
|
|
|
|
3456
|
|
|
public static function check_last_schedules_update() { |
3457
|
|
|
global $globalDBdriver; |
3458
|
|
|
if ($globalDBdriver == 'mysql') { |
3459
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_schedules' AND value > DATE_SUB(NOW(), INTERVAL 15 DAY)"; |
3460
|
|
|
} else { |
3461
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_schedules' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '15 DAYS'"; |
3462
|
|
|
} |
3463
|
|
|
try { |
3464
|
|
|
$Connection = new Connection(); |
3465
|
|
|
$sth = $Connection->db->prepare($query); |
3466
|
|
|
$sth->execute(); |
3467
|
|
|
} catch(PDOException $e) { |
3468
|
|
|
return "error : ".$e->getMessage(); |
3469
|
|
|
} |
3470
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3471
|
|
|
if ($row['nb'] > 0) return false; |
3472
|
|
|
else return true; |
3473
|
|
|
} |
3474
|
|
|
|
3475
|
|
|
public static function insert_last_schedules_update() { |
3476
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_schedules'; |
3477
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_schedules',NOW());"; |
3478
|
|
|
try { |
3479
|
|
|
$Connection = new Connection(); |
3480
|
|
|
$sth = $Connection->db->prepare($query); |
3481
|
|
|
$sth->execute(); |
3482
|
|
|
} catch(PDOException $e) { |
3483
|
|
|
return "error : ".$e->getMessage(); |
3484
|
|
|
} |
3485
|
|
|
} |
3486
|
|
|
|
3487
|
|
|
public static function check_last_tle_update() { |
3488
|
|
|
global $globalDBdriver; |
3489
|
|
|
if ($globalDBdriver == 'mysql') { |
3490
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_tle' AND value > DATE_SUB(NOW(), INTERVAL 7 DAY)"; |
3491
|
|
|
} else { |
3492
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_tle' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '7 DAYS'"; |
3493
|
|
|
} |
3494
|
|
|
try { |
3495
|
|
|
$Connection = new Connection(); |
3496
|
|
|
$sth = $Connection->db->prepare($query); |
3497
|
|
|
$sth->execute(); |
3498
|
|
|
} catch(PDOException $e) { |
3499
|
|
|
return "error : ".$e->getMessage(); |
3500
|
|
|
} |
3501
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3502
|
|
|
if ($row['nb'] > 0) return false; |
3503
|
|
|
else return true; |
3504
|
|
|
} |
3505
|
|
|
|
3506
|
|
|
public static function insert_last_tle_update() { |
3507
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_tle'; |
3508
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_tle',NOW());"; |
3509
|
|
|
try { |
3510
|
|
|
$Connection = new Connection(); |
3511
|
|
|
$sth = $Connection->db->prepare($query); |
3512
|
|
|
$sth->execute(); |
3513
|
|
|
} catch(PDOException $e) { |
3514
|
|
|
return "error : ".$e->getMessage(); |
3515
|
|
|
} |
3516
|
|
|
} |
3517
|
|
|
|
3518
|
|
|
public static function check_last_ucsdb_update() { |
3519
|
|
|
global $globalDBdriver; |
3520
|
|
|
if ($globalDBdriver == 'mysql') { |
3521
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_ucsdb' AND value > DATE_SUB(NOW(), INTERVAL 1 MONTH)"; |
3522
|
|
|
} else { |
3523
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_ucsdb' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '1 MONTH'"; |
3524
|
|
|
} |
3525
|
|
|
try { |
3526
|
|
|
$Connection = new Connection(); |
3527
|
|
|
$sth = $Connection->db->prepare($query); |
3528
|
|
|
$sth->execute(); |
3529
|
|
|
} catch(PDOException $e) { |
3530
|
|
|
return "error : ".$e->getMessage(); |
3531
|
|
|
} |
3532
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3533
|
|
|
if ($row['nb'] > 0) return false; |
3534
|
|
|
else return true; |
3535
|
|
|
} |
3536
|
|
|
|
3537
|
|
|
public static function insert_last_ucsdb_update() { |
3538
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_ucsdb'; |
3539
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_ucsdb',NOW());"; |
3540
|
|
|
try { |
3541
|
|
|
$Connection = new Connection(); |
3542
|
|
|
$sth = $Connection->db->prepare($query); |
3543
|
|
|
$sth->execute(); |
3544
|
|
|
} catch(PDOException $e) { |
3545
|
|
|
return "error : ".$e->getMessage(); |
3546
|
|
|
} |
3547
|
|
|
} |
3548
|
|
|
|
3549
|
|
|
public static function check_last_celestrak_update() { |
3550
|
|
|
global $globalDBdriver; |
3551
|
|
|
if ($globalDBdriver == 'mysql') { |
3552
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_celestrak' AND value > DATE_SUB(NOW(), INTERVAL 7 DAY)"; |
3553
|
|
|
} else { |
3554
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_celestrak' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '7 DAYS'"; |
3555
|
|
|
} |
3556
|
|
|
try { |
3557
|
|
|
$Connection = new Connection(); |
3558
|
|
|
$sth = $Connection->db->prepare($query); |
3559
|
|
|
$sth->execute(); |
3560
|
|
|
} catch(PDOException $e) { |
3561
|
|
|
return "error : ".$e->getMessage(); |
3562
|
|
|
} |
3563
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3564
|
|
|
if ($row['nb'] > 0) return false; |
3565
|
|
|
else return true; |
3566
|
|
|
} |
3567
|
|
|
|
3568
|
|
|
public static function insert_last_celestrak_update() { |
3569
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_celestrak'; |
3570
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_celestrak',NOW());"; |
3571
|
|
|
try { |
3572
|
|
|
$Connection = new Connection(); |
3573
|
|
|
$sth = $Connection->db->prepare($query); |
3574
|
|
|
$sth->execute(); |
3575
|
|
|
} catch(PDOException $e) { |
3576
|
|
|
return "error : ".$e->getMessage(); |
3577
|
|
|
} |
3578
|
|
|
} |
3579
|
|
|
|
3580
|
|
|
public static function check_last_marine_identity_update() { |
3581
|
|
|
global $globalDBdriver; |
3582
|
|
|
if ($globalDBdriver == 'mysql') { |
3583
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_marine_identity' AND value > DATE_SUB(NOW(), INTERVAL 7 DAY)"; |
3584
|
|
|
} else { |
3585
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_marine_identity' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '7 DAYS'"; |
3586
|
|
|
} |
3587
|
|
|
try { |
3588
|
|
|
$Connection = new Connection(); |
3589
|
|
|
$sth = $Connection->db->prepare($query); |
3590
|
|
|
$sth->execute(); |
3591
|
|
|
} catch(PDOException $e) { |
3592
|
|
|
return "error : ".$e->getMessage(); |
3593
|
|
|
} |
3594
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3595
|
|
|
if ($row['nb'] > 0) return false; |
3596
|
|
|
else return true; |
3597
|
|
|
} |
3598
|
|
|
|
3599
|
|
|
public static function check_last_satellite_update() { |
3600
|
|
|
global $globalDBdriver; |
3601
|
|
|
if ($globalDBdriver == 'mysql') { |
3602
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_satellite' AND value > DATE_SUB(NOW(), INTERVAL 1 DAY)"; |
3603
|
|
|
} else { |
3604
|
|
|
$query = "SELECT COUNT(*) as nb FROM config WHERE name = 'last_update_satellite' AND value::timestamp > CURRENT_TIMESTAMP - INTERVAL '1 DAYS'"; |
3605
|
|
|
} |
3606
|
|
|
try { |
3607
|
|
|
$Connection = new Connection(); |
3608
|
|
|
$sth = $Connection->db->prepare($query); |
3609
|
|
|
$sth->execute(); |
3610
|
|
|
} catch(PDOException $e) { |
3611
|
|
|
return "error : ".$e->getMessage(); |
3612
|
|
|
} |
3613
|
|
|
$row = $sth->fetch(PDO::FETCH_ASSOC); |
3614
|
|
|
if ($row['nb'] > 0) return false; |
3615
|
|
|
else return true; |
3616
|
|
|
} |
3617
|
|
|
|
3618
|
|
|
public static function insert_last_marine_identity_update() { |
3619
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_marine_identity'; |
3620
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_marine_identity',NOW());"; |
3621
|
|
|
try { |
3622
|
|
|
$Connection = new Connection(); |
3623
|
|
|
$sth = $Connection->db->prepare($query); |
3624
|
|
|
$sth->execute(); |
3625
|
|
|
} catch(PDOException $e) { |
3626
|
|
|
return "error : ".$e->getMessage(); |
3627
|
|
|
} |
3628
|
|
|
} |
3629
|
|
|
|
3630
|
|
|
public static function insert_last_satellite_update() { |
3631
|
|
|
$query = "DELETE FROM config WHERE name = 'last_update_satellite'; |
3632
|
|
|
INSERT INTO config (name,value) VALUES ('last_update_satellite',NOW());"; |
3633
|
|
|
try { |
3634
|
|
|
$Connection = new Connection(); |
3635
|
|
|
$sth = $Connection->db->prepare($query); |
3636
|
|
|
$sth->execute(); |
3637
|
|
|
} catch(PDOException $e) { |
3638
|
|
|
return "error : ".$e->getMessage(); |
3639
|
|
|
} |
3640
|
|
|
} |
3641
|
|
|
|
3642
|
|
|
public static function delete_duplicatemodes() { |
3643
|
|
|
global $globalDBdriver; |
3644
|
|
|
if ($globalDBdriver == 'mysql') { |
3645
|
|
|
$query = "DELETE a FROM aircraft_modes a, aircraft_modes b WHERE a.ModeS = b.ModeS AND a.FirstCreated < b.FirstCreated AND a.Source != 'ACARS'"; |
3646
|
|
|
} else { |
3647
|
|
|
$query = "DELETE FROM aircraft_modes WHERE AircraftID IN (SELECT AircraftID FROM (SELECT AircraftID, ROW_NUMBER() OVER (partition BY ModeS ORDER BY FirstCreated) AS rnum FROM aircraft_modes) t WHERE t.rnum > 1) AND Source != 'ACARS'"; |
3648
|
|
|
} |
3649
|
|
|
try { |
3650
|
|
|
$Connection = new Connection(); |
3651
|
|
|
$sth = $Connection->db->prepare($query); |
3652
|
|
|
$sth->execute(); |
3653
|
|
|
} catch(PDOException $e) { |
3654
|
|
|
return "error : ".$e->getMessage(); |
3655
|
|
|
} |
3656
|
|
|
} |
3657
|
|
|
public static function delete_duplicateowner() { |
3658
|
|
|
global $globalDBdriver; |
3659
|
|
|
if ($globalDBdriver == 'mysql') { |
3660
|
|
|
$query = "DELETE a FROM aircraft_owner a, aircraft_owner b WHERE a.registration = b.registration AND a.owner_id < b.owner_id"; |
3661
|
|
|
} else { |
3662
|
|
|
$query = "DELETE FROM aircraft_owner WHERE owner_id IN (SELECT owner_id FROM (SELECT owner_id, ROW_NUMBER() OVER (partition BY registration ORDER BY owner_id) AS rnum FROM aircraft_owner) t WHERE t.rnum > 1)"; |
3663
|
|
|
} |
3664
|
|
|
try { |
3665
|
|
|
$Connection = new Connection(); |
3666
|
|
|
$sth = $Connection->db->prepare($query); |
3667
|
|
|
$sth->execute(); |
3668
|
|
|
} catch(PDOException $e) { |
3669
|
|
|
return "error : ".$e->getMessage(); |
3670
|
|
|
} |
3671
|
|
|
} |
3672
|
|
|
|
3673
|
|
|
public static function update_all() { |
3674
|
|
|
global $globalMasterServer, $globalMasterSource; |
3675
|
|
|
if (!isset($globalMasterServer) || !$globalMasterServer) { |
3676
|
|
|
if (isset($globalMasterSource) && $globalMasterSource) { |
3677
|
|
|
echo update_db::update_routes(); |
3678
|
|
|
echo update_db::update_translation(); |
3679
|
|
|
//echo update_db::update_notam_fam(); |
3680
|
|
|
echo update_db::update_ModeS(); |
3681
|
|
|
//echo update_db::update_ModeS_flarm(); |
3682
|
|
|
echo update_db::update_ModeS_ogn(); |
3683
|
|
|
echo update_db::update_ModeS_faa(); |
3684
|
|
|
echo update_db::fix_icaotype(); |
3685
|
|
|
echo update_db::update_banned_fam(); |
3686
|
|
|
//echo update_db::update_celestrak(); |
3687
|
|
|
//echo update_db::delete_duplicatemodes(); |
3688
|
|
|
} else { |
3689
|
|
|
//echo update_db::update_routes(); |
3690
|
|
|
echo update_db::update_routes_fam(); |
3691
|
|
|
//echo update_db::update_translation(); |
3692
|
|
|
echo update_db::update_translation_fam(); |
3693
|
|
|
//echo update_db::update_notam_fam(); |
3694
|
|
|
//echo update_db::update_ModeS(); |
3695
|
|
|
echo update_db::update_ModeS_fam(); |
3696
|
|
|
//echo update_db::update_ModeS_flarm(); |
3697
|
|
|
echo update_db::update_ModeS_ogn(); |
3698
|
|
|
//echo update_db::delete_duplicatemodes(); |
3699
|
|
|
echo update_db::update_banned_fam(); |
3700
|
|
|
} |
3701
|
|
|
} |
3702
|
|
|
} |
3703
|
|
|
} |
3704
|
|
|
|
3705
|
|
|
//echo update_db::update_airports(); |
3706
|
|
|
//echo update_db::translation(); |
3707
|
|
|
//echo update_db::update_waypoints(); |
3708
|
|
|
//echo update_db::update_airspace(); |
3709
|
|
|
//echo update_db::update_notam(); |
3710
|
|
|
//echo update_db::update_ivao(); |
3711
|
|
|
//echo update_db::update_ModeS_flarm(); |
3712
|
|
|
//echo update_db::update_ModeS_ogn(); |
3713
|
|
|
//echo update_db::update_aircraft(); |
3714
|
|
|
//$update_db = new update_db(); |
3715
|
|
|
//echo update_db::update_owner(); |
3716
|
|
|
//update_db::update_translation_fam(); |
3717
|
|
|
//echo update_db::update_routes(); |
3718
|
|
|
//update_db::update_models(); |
3719
|
|
|
//echo $update_db::update_skyteam(); |
3720
|
|
|
//echo $update_db::update_tle(); |
3721
|
|
|
//echo update_db::update_notam_fam(); |
3722
|
|
|
//echo update_db::create_airspace(); |
3723
|
|
|
//echo update_db::update_ModeS(); |
3724
|
|
|
//echo update_db::update_ModeS_fam(); |
3725
|
|
|
//echo update_db::update_routes_fam(); |
3726
|
|
|
//echo update_db::update_ModeS_faa(); |
3727
|
|
|
//echo update_db::update_banned_fam(); |
3728
|
|
|
//echo update_db::modes_faa(); |
3729
|
|
|
//echo update_db::update_owner_fam(); |
3730
|
|
|
//echo update_db::delete_duplicateowner(); |
3731
|
|
|
//echo update_db::fix_icaotype(); |
3732
|
|
|
//echo update_db::satellite_ucsdb('tmp/UCS_Satellite_Database_officialname_1-1-17.txt'); |
3733
|
|
|
//echo update_db::update_celestrak(); |
3734
|
|
|
//echo update_db::update_aircraft(); |
3735
|
|
|
|
3736
|
|
|
?> |
3737
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.