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