Completed
Push — master ( 14281c...6f3189 )
by Yannick
30:26
created

NOTAM::addNOTAM()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 3
nop 17
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * This class is part of FlightAirmap. It's used to parse NOTAM
4
 *
5
 * Copyright (c) Ycarus (Yannick Chabanois) at Zugaina <[email protected]>
6
 * Licensed under AGPL license.
7
 * For more information see: https://www.flightairmap.com/
8
*/
9
require_once(dirname(__FILE__).'/settings.php');
10
require_once(dirname(__FILE__).'/class.Connection.php');
11
require_once(dirname(__FILE__).'/class.Common.php');
12
require_once(dirname(__FILE__).'/class.Spotter.php');
13
14
class NOTAM {
15
	public $db;
16
	private $abbr = array(
17
	                    'A/A' => 'Air-to-air',
18
	                    'A/G' => 'Air-to-ground',
19
	                    'AAL' => 'Above Aerodrome Level',
20
	                    'ABM' => 'Abeam',
21
	                    'ABN' => 'Aerodrome Beacon',
22
	                    'ABT' => 'About',
23
	                    'ABV' => 'Above',
24
	                    'ACC' => 'Area Control',
25
	                    'ACFT' => 'Aircraft',
26
	                    'ACK' => 'Acknowledge',
27
	                    'ACL' => 'Altimeter Check Location',
28
	                    'ACN' => 'Aircraft Classification Number',
29
	                    'ACPT' => 'Accepted',
30
	                    'ACT' => 'Active',
31
	                    'AD' => 'Aerodrome',
32
	                    'ADA' => 'Advisory Area',
33
	                    'ADC' => 'Aerodrome Chart',
34
	                    'ADDN' => 'Additional',
35
	                    'ADIZ' => 'Air defense identification zone',
36
	                    'ADJ' => 'Adjacent',
37
	                    'ADR' => 'Advisory Route',
38
	                    'ADS' => 'Automatic Dependent Surveillance',
39
	                    'ADVS' => 'Advisory Service',
40
	                    'ADZ' => 'Advised',
41
	                    'AFIL' => 'Flight Plan Filed In The Air',
42
	                    'AFIS' => 'Airport flight information service',
43
	                    'AFM' => 'Affirm',
44
	                    'AFT' => 'After',
45
	                    'AGA' => 'Aerodromes, Air Routes and Ground Aids',
46
	                    'AGN' => 'Again',
47
	                    'AIS' => 'Aeronautical information service',
48
	                    'ALERFA' => 'Alert Phase',
49
	                    'ALRS' => 'Alerting Service',
50
	                    'ALS' => 'Approach Lighting System',
51
	                    'ALT' => 'Altitude',
52
	                    'ALTN' => 'Alternate',
53
	                    'AMA' => 'Area Minimum Altitude',
54
	                    'ANC' => 'Aeronautical Chart',
55
	                    'ANCS' => 'Aeronautical Navigation Chart',
56
	                    'ANS' => 'Answer',
57
	                    'AOC' => 'Aerodrome Obstacle Chart',
58
	                    'AP' => 'Airport',
59
	                    'APCH' => 'Approach',
60
	                    'APDC' => 'Aircraft Parking/docking Chart',
61
	                    'APN' => 'Apron',
62
	                    'APNS' => 'Aprons',
63
	                    'APP' => 'Approach Control',
64
	                    'APR' => 'April',
65
	                    'APRX' => 'Approximately',
66
	                    'APSG' => 'After Passing',
67
	                    'APV' => 'Approved',
68
	                    'ARC' => 'Area Chart',
69
	                    'ARNG' => 'Arrange',
70
	                    'ARO' => 'Air Traffic Services Reporting Office',
71
	                    'ARP' => 'Aerodrome Reference Point',
72
	                    'ARR' => 'Arriving',
73
	                    'ARST' => 'Arresting',
74
	                    'ASC' => 'Ascend To',
75
	                    'ASDA' => 'Accelerate-Stop Distance Available',
76
	                    'ASPEEDG' => 'Airspeed Gain',
77
	                    'ASPEEDL' => 'Airspeed Loss',
78
	                    'ASPH' => 'Asphalt',
79
	                    'ATA' => 'Actual Time of Arrival',
80
	                    'ATD' => 'Actual Time of Departure',
81
	                    'ATFM' => 'Air Traffic Flow Management',
82
	                    'ATIS' => 'Automatic terminal information service',
83
	                    'ATM' => 'Air Traffic Management',
84
	                    'ATP' => 'At',
85
	                    'ATTN' => 'Attention',
86
	                    'ATZ' => 'Aerodrome Traffic Zone',
87
	                    'AUG' => 'August',
88
	                    'AUTH' => 'Authorization',
89
	                    'AUW' => 'All Up Weight',
90
	                    'AUX' => 'Auxiliary',
91
	                    'AVBL' => 'Available',
92
	                    'AVG' => 'Average',
93
	                    'AVGAS' => 'Aviation Gasoline',
94
	                    'AWTA' => 'Advise At What Time Able',
95
	                    'AWY' => 'Airway',
96
	                    'AWYS' => 'Airways',
97
	                    'AZM' => 'Azimuth',
98
	                    'BA' => 'Braking Action',
99
	                    'BCN' => 'Beacon',
100
	                    'BCST' => 'Broadcast',
101
	                    'BDRY' => 'Boundary',
102
	                    'BFR' => 'Before',
103
	                    'BLDG' => 'Building',
104
	                    'BLO' => 'Below Clouds',
105
	                    'BLW' => 'Below',
106
	                    'BRF' => 'Short',
107
	                    'BRG' => 'Bearing',
108
	                    'BRKG' => 'Breaking',
109
	                    'BTL' => 'Between Layers',
110
	                    'BTN' => 'Between',
111
	                    'CD' => 'Candela',
112
	                    'CDN' => 'Coordination',
113
	                    'CF' => 'Change Frequency To',
114
	                    'CFM' => 'Confirm',
115
	                    'CGL' => 'Circling Guidance Light(s)',
116
	                    'CH' => 'Channel',
117
	                    'CHG' => 'Changed',
118
	                    'CIT' => 'Near or Over Large Towns',
119
	                    'CIV' => 'Civil',
120
	                    'CK' => 'Check',
121
	                    'CL' => 'Centre Line',
122
	                    'CLBR' => 'Calibration',
123
	                    'CLD' => 'Cloud',
124
	                    'CLG' => 'Calling',
125
	                    'CLIMB-OUT' => 'Climb-out Area',
126
	                    'CLR' => 'Clearance',
127
	                    'CLRD' => 'Cleared',
128
	                    'CLSD' => 'Closed',
129
	                    'CMB' => 'Climb',
130
	                    'CMPL' => 'Complete',
131
	                    'CNL' => 'Cancel',
132
	                    'CNS' => 'Communications, Navigation And Surveillance',
133
	                    'COM' => 'Communications',
134
	                    'CONC' => 'Concrete',
135
	                    'COND' => 'Condition',
136
	                    'CONS' => 'Continuous',
137
	                    'CONST' => 'Construction',
138
	                    'CONT' => 'Continued',
139
	                    'COOR' => 'Coordination',
140
	                    'COORD' => 'Coordinates',
141
	                    'COP' => 'Change-over Point',
142
	                    'COR' => 'Correction',
143
	                    'COT' => 'At The Coast',
144
	                    'COV' => 'Covered',
145
	                    'CPDLC' => 'Controller-pilot Data Link Communications',
146
	                    'CPL' => 'Current Flight Plan',
147
	                    'CRC' => 'Cyclic Redundancy Check',
148
	                    'CRZ' => 'Cruise',
149
	                    'CTA' => 'Control area',
150
	                    'CTAM' => 'Climb To And Maintain',
151
	                    'CTC' => 'Contact',
152
	                    'CTL' => 'Control',
153
	                    'CTN' => 'Caution',
154
	                    'CTR' => 'Control Zone',
155
	                    'CVR' => 'Cockpit Voice Recorder',
156
	                    'CW' => 'Continuous Wave',
157
	                    'CWY' => 'Clearway',
158
	                    'DA' => 'Decision Altitude',
159
	                    'DCKG' => 'Docking',
160
	                    'DCP' => 'Datum Crossing Point',
161
	                    'DCPC' => 'Direct Controller-pilot Communications',
162
	                    'DCT' => 'Direct',
163
	                    'DEC' => 'December',
164
	                    'DEG' => 'Degrees',
165
	                    'DEP' => 'Departing',
166
	                    'DES' => 'Descend',
167
	                    'DEST' => 'Destination',
168
	                    'DETRESFA' => 'Distress Phase',
169
	                    'DEV' => 'Deviating',
170
	                    'DFDR' => 'Digital Flight Data Recorder',
171
	                    'DFTI' => 'Distance From Touchdown Indicator',
172
	                    'DH' => 'Decision Height',
173
	                    'DIP' => 'Diffuse',
174
	                    'DIST' => 'Distance',
175
	                    'DIV' => 'Divert',
176
	                    'DLA' => 'Delay',
177
	                    'DLY' => 'Daily',
178
	                    'DME' => 'Distance measuring equipment',
179
	                    'DNG' => 'Dangerous',
180
	                    'DOM' => 'Domestic',
181
	                    'DPT' => 'Depth',
182
	                    'DR' => 'Dead Reckoning',
183
	                    'DRG' => 'During',
184
	                    'DTAM' => 'Descend To And Maintain',
185
	                    'DTG' => 'Date-time Group',
186
	                    'DTHR' => 'Displaced Runway Threshold',
187
	                    'DTRT' => 'Deteriorating',
188
	                    'DTW' => 'Dual Tandem Wheels',
189
	                    'DUPE' => 'This Is A Duplicate Message',
190
	                    'DUR' => 'Duration',
191
	                    'DVOR' => 'Doppler VOR',
192
	                    'DW' => 'Dual Wheels',
193
	                    'EAT' => 'Expected Approach Time',
194
	                    'EB' => 'Eastbound',
195
	                    'EDA' => 'Elevation Differential Area',
196
	                    'EET' => 'Estimated Elapsed Time',
197
	                    'EFC' => 'Expect Further Clearance',
198
	                    'ELBA' => 'Emergency Location Beacon',
199
	                    'ELEV' => 'Elevation',
200
	                    'ELR' => 'Extra Long Range',
201
	                    'EM' => 'Emission',
202
	                    'EMERG' => 'Emergency',
203
	                    'END' => 'Stop-end',
204
	                    'ENE' => 'East-north-east',
205
	                    'ENG' => 'Engine',
206
	                    'ENR' => 'En-route',
207
	                    'ENRC' => 'En-route Chart',
208
	                    'EOBT' => 'Estimated Off-block Time',
209
	                    'EQPT' => 'Equipment',
210
	                    'ER' => 'Here',
211
	                    'ESE' => 'East-south-east',
212
	                    'EST' => 'Estimate',
213
	                    'ETA' => 'Estimated Time Of Arrival',
214
	                    'ETD' => 'Estimated Time Of Departure',
215
	                    'ETO' => 'Estimated Time Over Significant Point',
216
	                    'EV' => 'Every',
217
	                    'EXC' => 'Except',
218
	                    'EXER' => 'Exercise',
219
	                    'EXP' => 'Expect',
220
	                    'EXTD' => 'Extend',
221
	                    'FAC' => 'Facilities',
222
	                    'FAF' => 'Final Approach Fix',
223
	                    'FAL' => 'Facilitation of International Airtransport',
224
	                    'FAP' => 'Final Approach Point',
225
	                    'FATO' => 'Final Approach And Take-off Area',
226
	                    'FAX' => 'Fax',
227
	                    'FBL' => 'Light',
228
	                    'FCST' => 'Forecast',
229
	                    'FCT' => 'Friction Coefficient',
230
	                    'FDPS' => 'Flight Data Processing System',
231
	                    'FEB' => 'February',
232
	                    'FIR' => 'Flight information region',
233
	                    'FIS' => 'Flight information service',
234
	                    'FLD' => 'Field',
235
	                    'FLG' => 'Flashing',
236
	                    'FLR' => 'Flares',
237
	                    'FLT' => 'Flight',
238
	                    'FLTS' => 'Flights',
239
	                    'FLTCK' => 'Flight Check',
240
	                    'FLUC' => 'Fluctuating',
241
	                    'FLW' => 'Follow(s)',
242
	                    'FLY' => 'Fly',
243
	                    'FM' => 'From',
244
	                    'FMS' => 'Flight Management System',
245
	                    'FMU' => 'Flow Management Unit',
246
	                    'FNA' => 'Final Approach',
247
	                    'FPAP' => 'Flight Path Alignment Point',
248
	                    'FPL' => 'Flight Plan',
249
	                    'FPLS' => 'Flight Plans',
250
	                    'FPM' => 'Feet Per Minute',
251
	                    'FPR' => 'Flight Plan Route',
252
	                    'FR' => 'Fuel Remaining',
253
	                    'FREQ' => 'Frequency',
254
	                    'FRI' => 'Friday',
255
	                    'FRMG' => 'Missile, gun or rocket firing',
256
	                    'FRNG' => 'Firing',
257
	                    'FRONT' => 'Front',
258
	                    'FRQ' => 'Frequent',
259
	                    'FSL' => 'Full Stop Landing',
260
	                    'FSS' => 'Flight Service Station',
261
	                    'FST' => 'First',
262
	                    'FTP' => 'Fictitious Threshold Point',
263
	                    'G/A' => 'Ground-to-air',
264
	                    'G/A/G' => 'Ground-to-air and Air-to-ground',
265
	                    'GARP' => 'GBAS Azimuth Reference Point',
266
	                    'GBAS' => 'Ground-based Augmentation System',
267
	                    'GCAJ' => 'Ground Controlled Approach',
268
	                    'GCA' => 'Ground Controlled Approach System',
269
	                    'GEN' => 'General',
270
	                    'GEO' => 'Geographic or True',
271
	                    'GES' => 'Ground Earth Station',
272
	                    'GLD' => 'Glider',
273
	                    'GMC' => 'Ground Movement Chart',
274
	                    'GND' => 'Ground',
275
	                    'GNDCK' => 'Ground Check',
276
	                    'GP' => 'Glide Path',
277
	                    'GRASS' => 'Grass landing area',
278
	                    'GRVL' => 'Gravel',
279
	                    'GUND' => 'Geoid Undulation',
280
	                    'H24' => '24 Hours',
281
	                    'HAPI' => 'Helicopter Approach Path Indicator',
282
	                    'HBN' => 'Hazard Beacon',
283
	                    'HDG' => 'Heading',
284
	                    'HEL' => 'Helicopter',
285
	                    'HGT' => 'Height',
286
	                    'HJ' => 'Sunrise to Sunset',
287
	                    'HLDG' => 'Holding',
288
	                    'HN' => 'Sunset to Sunrise',
289
	                    'HO' => 'Service Available To Meet Operational Requirements',
290
	                    'HOL' => 'Holiday',
291
	                    'HOSP' => 'Hospital Aircraft',
292
	                    'HOT' => 'Height',
293
	                    'HPA' => 'Hectopascal',
294
	                    'HR' => 'Hours',
295
	                    'HRS' => 'Hours',
296
	                    'HS' => 'Service Available During Hours Of Scheduled Operations',
297
	                    'HURCN' => 'Hurricane',
298
	                    'HVY' => 'Heavy',
299
	                    'HX' => 'No Specific Working Hours',
300
	                    'HYR' => 'Higher',
301
	                    'IAC' => 'Instrument Approach Chart',
302
	                    'IAF' => 'Initial Approach Fix',
303
	                    'IAO' => 'In And Out Of Clouds',
304
	                    'IAP' => 'Instrument Approach Procedure',
305
	                    'IAR' => 'Intersection Of Air Routes',
306
	                    'IBN' => 'Identification Beacon',
307
	                    'ID' => 'Identifier',
308
	                    'IDENT' => 'Identification',
309
	                    'IFF' => 'Identification Friend/Foe',
310
	                    'IGA' => 'International General Aviation',
311
	                    'IM' => 'Inner Marker',
312
	                    'IMPR' => 'Improving',
313
	                    'IMT' => 'Immediately',
314
	                    'INA' => 'Initial Approach',
315
	                    'INBD' => 'Inbound',
316
	                    'INCERFA' => 'Uncertainty Phase',
317
	                    'INFO' => 'Information',
318
	                    'INOP' => 'Inoperative',
319
	                    'INP' => 'If Not Possible',
320
	                    'INPR' => 'In Progress',
321
	                    'INSTL' => 'Installation',
322
	                    'INSTR' => 'Instrument',
323
	                    'INT' => 'Intersection',
324
	                    'INTS' => 'Intersections',
325
	                    'INTL' => 'International',
326
	                    'INTRG' => 'Interrogator',
327
	                    'INTRP' => 'Interruption',
328
	                    'INTSF' => 'Intensifying',
329
	                    'INTST' => 'Intensity',
330
	                    'ISA' => 'International Standard Atmosphere',
331
	                    'JAN' => 'January',
332
	                    'JTST' => 'Jet stream',
333
	                    'JUL' => 'July',
334
	                    'JUN' => 'June',
335
	                    'KMH' => 'Kilometres Per Hour',
336
	                    'KPA' => 'Kilopascal',
337
	                    'KT' => 'Knots',
338
	                    'KW' => 'Kilowatts',
339
	                    'LAN' => 'Inland',
340
	                    'LAT' => 'Latitude',
341
	                    'LDA' => 'Landing Distance Available',
342
	                    'LDAH' => 'Landing Distance Available, Helicopter',
343
	                    'LDG' => 'Landing',
344
	                    'LDI' => 'Landing Direction Indicator',
345
	                    'LEN' => 'Length',
346
	                    'LGT' => 'Lighting',
347
	                    'LGTD' => 'Lighted',
348
	                    'LIH' => 'Light Intensity High',
349
	                    'LIL' => 'Light Intensity Low',
350
	                    'LIM' => 'Light Intensity Medium',
351
	                    'LLZ' => 'Localizer',
352
	                    'LM' => 'Locator, Middle',
353
	                    'LMT' => 'Local Mean Time',
354
	                    'LNG' => 'Long',
355
	                    'LO' => 'Locator, Outer',
356
	                    'LOG' => 'Located',
357
	                    'LONG' => 'Longitude',
358
	                    'LRG' => 'Long Range',
359
	                    'LTD' => 'Limited',
360
	                    'LTP' => 'Landing Threshold Point',
361
	                    'LVE' => 'Leaving',
362
	                    'LVL' => 'Level',
363
	                    'LYR' => 'Layer',
364
	                    'MAA' => 'Maximum Authorized Altitude',
365
	                    'MAG' => 'Magnetic',
366
	                    'MAINT' => 'Maintenance',
367
	                    'MAP' => 'Aeronautical Maps and Charts',
368
	                    'MAPT' => 'Missed Approach Point',
369
	                    'MAR' => 'March',
370
	                    'MAX' => 'Maximum',
371
	                    'MAY' => 'May',
372
	                    'MBST' => 'Microburst',
373
	                    'MCA' => 'Minimum Crossing Altitude',
374
	                    'MCW' => 'Modulated Continuous Wave',
375
	                    'MDA' => 'Minimum Descent Altitude',
376
	                    'MDH' => 'Minimum Descent Height',
377
	                    'MEA' => 'Minimum En-route Altitude',
378
	                    'MEHT' => 'Minimum Eye Height Over Threshold',
379
	                    'MET' => 'Meteorological',
380
	                    'MID' => 'Mid-point',
381
	                    'MIL' => 'Military',
382
	                    'MIN' => 'Minutes',
383
	                    'MKR' => 'Marker Radio Beacon',
384
	                    'MLS' => 'Microwave Landing System',
385
	                    'MM' => 'Middle Marker',
386
	                    'MNM' => 'Minimum',
387
	                    'MNPS' => 'Minimum Navigation Performance Specifications',
388
	                    'MNT' => 'Monitor',
389
	                    'MNTN' => 'Maintain',
390
	                    'MOA' => 'Military Operating Area',
391
	                    'MOC' => 'Minimum Obstacle Clearance',
392
	                    'MOD' => 'Moderate',
393
	                    'MON' => 'Monday',
394
	                    'MOPS' => 'Minimum Operational Performance Standards',
395
	                    'MOV' => 'Movement',
396
	                    'MRA' => 'Minimum Reception Altitude',
397
	                    'MRG' => 'Medium Range',
398
	                    'MRP' => 'ATS/MET Reporting Point',
399
	                    'MS' => 'Minus',
400
	                    'MSA' => 'Minimum Sector Altitude',
401
	                    'MSAW' => 'Minimum Safe Altitude Warning',
402
	                    'MSG' => 'Message',
403
	                    'MSSR' => 'Monopulse Secondary Surveillance Radar',
404
	                    'MT' => 'Mountain',
405
	                    'MTU' => 'Metric Units',
406
	                    'MTW' => 'Mountain Waves',
407
	                    'NASC' => 'National AIS System Centre',
408
	                    'NAT' => 'North Atlantic',
409
	                    'NAV' => 'Navigation',
410
	                    'NB' => 'Northbound',
411
	                    'NBFR' => 'Not Before',
412
	                    'NE' => 'North-east',
413
	                    'NEB' => 'North-eastbound',
414
	                    'NEG' => 'Negative',
415
	                    'NGT' => 'Night',
416
	                    'NIL' => 'None',
417
	                    'NML' => 'Normal',
418
	                    'NNE' => 'North-north-east',
419
	                    'NNW' => 'North-north-west',
420
	                    'NOF' => 'International NOTAM Office',
421
	                    'NOV' => 'November',
422
	                    'NOZ' => 'Normal Operating Zone',
423
	                    'NR' => 'Number',
424
	                    'NRH' => 'No Reply Heard',
425
	                    'NTL' => 'National',
426
	                    'NTZ' => 'No Transgression Zone',
427
	                    'NW' => 'North-west',
428
	                    'NWB' => 'North-westbound',
429
	                    'NXT' => 'Next',
430
	                    'O/R' => 'On Request',
431
	                    'OAC' => 'Oceanic Area Control Centre',
432
	                    'OAS' => 'Obstacle Assessment Surface',
433
	                    'OBS' => 'Observe',
434
	                    'OBST' => 'Obstacle',
435
	                    'OBSTS' => 'Obstacles',
436
	                    'OCA' => 'Oceanic Control Area',
437
	                    'OCH' => 'Obstacle Clearance Height',
438
	                    'OCL' => 'Obstacle Clearance Limit',
439
	                    'OCS' => 'Obstacle Clearance Surface',
440
	                    'OCT' => 'October',
441
	                    'OFZ' => 'Obstacle Free Zone',
442
	                    'OGN' => 'Originate',
443
	                    'OHD' => 'Overhead',
444
	                    'OM' => 'Outer Marker',
445
	                    'OPC' => 'Control Indicated Is Operational Control',
446
	                    'OPMET' => 'Operational Meteorological',
447
	                    'OPN' => 'Open',
448
	                    'OPR' => 'Operate',
449
	                    'OPS' => 'Operations',
450
	                    'ORD' => 'Order',
451
	                    'OSV' => 'Ocean Station Vessel',
452
	                    'OTLK' => 'Outlook',
453
	                    'OTP' => 'On Top',
454
	                    'OTS' => 'Organized Track System',
455
	                    'OUBD' => 'Outbound',
456
	                    'PA' => 'Precision Approach',
457
	                    'PALS' => 'Precision Approach Lighting System',
458
	                    'PANS' => 'Procedures for Air Navigation Services',
459
	                    'PAR' => 'Precision Approach Radar',
460
	                    'PARL' => 'Parallel',
461
	                    'PATC' => 'Precision Approach Terrain Chart',
462
	                    'PAX' => 'Passenger(s)',
463
	                    'PCD' => 'Proceed',
464
	                    'PCL' => 'Pilot-controlled Lighting',
465
	                    'PCN' => 'Pavement Classification Number',
466
	                    'PDC' => 'Pre-departure Clearance',
467
	                    'PDG' => 'Procedure Design Gradient',
468
	                    'PER' => 'Performance',
469
	                    'PERM' => 'Permanent',
470
	                    'PIB' => 'Pre-flight Information Bulletin',
471
	                    'PJE' => 'Parachute Jumping Exercise',
472
	                    'PLA' => 'Practice Low Approach',
473
	                    'PLN' => 'Flight Plan',
474
	                    'PLVL' => 'Present Level',
475
	                    'PN' => 'Prior Notice Required',
476
	                    'PNR' => 'Point Of No Return',
477
	                    'POB' => 'Persons On Board',
478
	                    'POSS' => 'Possible',
479
	                    'PPI' => 'Plan Position Indicator',
480
	                    'PPR' => 'Prior Permission Required',
481
	                    'PPSN' => 'Present Position',
482
	                    'PRI' => 'Primary',
483
	                    'PRKG' => 'Parking',
484
	                    'PROB' => 'Probability',
485
	                    'PROC' => 'Procedure',
486
	                    'PROV' => 'Provisional',
487
	                    'PS' => 'Plus',
488
	                    'PSG' => 'Passing',
489
	                    'PSN' => 'Position',
490
	                    'PSNS' => 'Positions',
491
	                    'PSR' => 'Primary Surveillance Radar',
492
	                    'PSYS' => 'Pressure System(s)',
493
	                    'PTN' => 'Procedure Turn',
494
	                    'PTS' => 'Polar Track Structure',
495
	                    'PWR' => 'Power',
496
	                    'QUAD' => 'Quadrant',
497
	                    'RAC' => 'Rules of The Air and Air Traffic Services',
498
	                    'RAG' => 'Runway Arresting Gear',
499
	                    'RAI' => 'Runway Alignment Indicator',
500
	                    'RASC' => 'Regional AIS System Centre',
501
	                    'RASS' => 'Remote Altimeter Setting Source',
502
	                    'RB' => 'Rescue Boat',
503
	                    'RCA' => 'Reach Cruising Altitude',
504
	                    'RCC' => 'Rescue Coordination Centre',
505
	                    'RCF' => 'Radiocommunication Failure',
506
	                    'RCH' => 'Reaching',
507
	                    'RCL' => 'Runway Centre Line',
508
	                    'RCLL' => 'Runway Centre Line Light(s)',
509
	                    'RCLR' => 'Recleared',
510
	                    'RDH' => 'Reference Datum Height',
511
	                    'RDL' => 'Radial',
512
	                    'RDO' => 'Radio',
513
	                    'RE' => 'Recent',
514
	                    'REC' => 'Receiver',
515
	                    'REDL' => 'Runway Edge Light(s)',
516
	                    'REF' => 'Refer To',
517
	                    'REG' => 'Registration',
518
	                    'RENL' => 'Runway End Light(s)',
519
	                    'REP' => 'Report',
520
	                    'REQ' => 'Requested',
521
	                    'RERTE' => 'Re-route',
522
	                    'RESA' => 'Runway End Safety Area',
523
	                    'RG' => 'Range (lights)',
524
	                    'RHC' => 'Right-hand Circuit',
525
	                    'RIF' => 'Reclearance In Flight',
526
	                    'RITE' => 'Right',
527
	                    'RL' => 'Report Leaving',
528
	                    'RLA' => 'Relay To',
529
	                    'RLCE' => 'Request Level Change En Route',
530
	                    'RLLS' => 'Runway Lead-in Lighting System',
531
	                    'RLNA' => 'Request Level Not Available',
532
	                    'RMAC' => 'Radar Minimum Altitude Chart',
533
	                    'RMK' => 'Remark',
534
	                    'RNG' => 'Radio Range',
535
	                    'RNP' => 'Required Navigation Performance',
536
	                    'ROC' => 'Rate Of Climb',
537
	                    'ROD' => 'Rate Of Descent',
538
	                    'ROFOR' => 'Route Forecast',
539
	                    'RON' => 'Receiving Only',
540
	                    'RPI' => 'Radar Position Indicator',
541
	                    'RPL' => 'Repetitive Flight Plan',
542
	                    'RPLC' => 'Replaced',
543
	                    'RPS' => 'Radar Position Symbol',
544
	                    'RQMNTS' => 'Requirements',
545
	                    'RQP' => 'Request Flight Plan',
546
	                    'RQS' => 'Request Supplementary Flight Plan',
547
	                    'RR' => 'Report Reaching',
548
	                    'RSC' => 'Rescue Sub-centre',
549
	                    'RSCD' => 'Runway Surface Condition',
550
	                    'RSP' => 'Responder Beacon',
551
	                    'RSR' => 'En-route Surveillance Radar',
552
	                    'RTE' => 'Route',
553
	                    'RTES' => 'Routes',
554
	                    'RTF' => 'Radiotelephone',
555
	                    'RTG' => 'Radiotelegraph',
556
	                    'RTHL' => 'Runway Threshold Light(s)',
557
	                    'RTN' => 'Return',
558
	                    'RTODAH' => 'Rejected Take-off Distance Available, Helicopter',
559
	                    'RTS' => 'Return To Service',
560
	                    'RTT' => 'Radioteletypewriter',
561
	                    'RTZL' => 'Runway Touchdown Zone Light(s)',
562
	                    'RUT' => 'Standard Regional Route Transmitting Frequencies',
563
	                    'RV' => 'Rescue Vessel',
564
	                    'RVSM' => 'Reduced Vertical Separation Minimum',
565
	                    'RWY' => 'Runway',
566
	                    'RWYS' => 'Runways',
567
	                    'SALS' => 'Simple Approach Lighting System',
568
	                    'SAN' => 'Sanitary',
569
	                    'SAP' => 'As Soon As Possible',
570
	                    'SAR' => 'Search and Rescue',
571
	                    'SARPS' => 'Standards and Recommended Practices',
572
	                    'SAT' => 'Saturday',
573
	                    'SATCOM' => 'Satellite Communication',
574
	                    'SB' => 'Southbound',
575
	                    'SBAS' => 'Satellite-based Augmentation System',
576
	                    'SDBY' => 'Stand by',
577
	                    'SE' => 'South-east',
578
	                    'SEA' => 'Sea',
579
	                    'SEB' => 'South-eastbound',
580
	                    'SEC' => 'Seconds',
581
	                    'SECN' => 'Section',
582
	                    'SECT' => 'Sector',
583
	                    'SELCAL' => 'Selective calling system',
584
	                    'SEP' => 'September',
585
	                    'SER' => 'Service',
586
	                    'SEV' => 'Severe',
587
	                    'SFC' => 'Surface',
588
	                    'SGL' => 'Signal',
589
	                    'SID' => 'Standard Instrument Departure',
590
	                    'SIF' => 'Selective Identification Feature',
591
	                    'SIG' => 'Significant',
592
	                    'SIMUL' => 'Simultaneous',
593
	                    'SKED' => 'Schedule',
594
	                    'SLP' => 'Speed Limiting Point',
595
	                    'SLW' => 'Slow',
596
	                    'SMC' => 'Surface Movement Control',
597
	                    'SMR' => 'Surface Movement Radar',
598
	                    'SPL' => 'Supplementary Flight Plan',
599
	                    'SPOC' => 'SAR Point Of Contact',
600
	                    'SPOT' => 'Spot Wind',
601
	                    'SR' => 'Sunrise',
602
	                    'SRA' => 'Surveillance Radar Approach',
603
	                    'SRE' => 'Surveillance Radar Element Of Precision Approach Radar System',
604
	                    'SRG' => 'Short Range',
605
	                    'SRR' => 'Search and Rescue Region',
606
	                    'SRY' => 'Secondary',
607
	                    'SS' => 'Sunset',
608
	                    'SSE' => 'South-south-east',
609
	                    'SSR' => 'Secondary Surveillance Radar',
610
	                    'SST' => 'Supersonic Transport',
611
	                    'SSW' => 'South-south-west',
612
	                    'STA' => 'Straight-in Approach',
613
	                    'STAR' => 'Standard Instrument Arrival',
614
	                    'STD' => 'Standard',
615
	                    'STN' => 'Station',
616
	                    'STNR' => 'Stationary',
617
	                    'STOL' => 'Short Take-off and Landing',
618
	                    'STS' => 'Status',
619
	                    'STWL' => 'Stopway Light(s)',
620
	                    'SUBJ' => 'Subject To',
621
	                    'SUN' => 'Sunday',
622
	                    'SUP' => 'Supplement',
623
	                    'SUPPS' => 'Regional Supplementary Procedures Service Message',
624
	                    'SVCBL' => 'Serviceable',
625
	                    'SW' => 'South-west',
626
	                    'SWB' => 'South-westbound',
627
	                    'SWY' => 'Stopway',
628
	                    'TA' => 'Transition Altitude',
629
	                    'TAA' => 'Terminal Arrival Altitude',
630
	                    'TAF' => 'Aerodrome Forecast',
631
	                    'TAIL' => 'Tail Wind',
632
	                    'TAR' => 'Terminal Area Surveillance Radar',
633
	                    'TAX' => 'Taxi',
634
	                    'TCAC' => 'Tropical Cyclone Advisory Centre',
635
	                    'TDO' => 'Tornado',
636
	                    'TDZ' => 'Touchdown Zone',
637
	                    'TECR' => 'Technical Reason',
638
	                    'TEMPO' => 'Temporarily',
639
	                    'TFC' => 'Traffic',
640
	                    'TGL' => 'Touch-and-go',
641
	                    'TGS' => 'Taxiing Guidance System',
642
	                    'THR' => 'Threshold',
643
	                    'THRU' => 'Through',
644
	                    'THU' => 'Thursday',
645
	                    'TIBA' => 'Traffic Information Broadcast By Aircraft',
646
	                    'TIL' => 'Until',
647
	                    'TIP' => 'Until Past',
648
	                    'TKOF' => 'Take-off',
649
	                    'TL' => 'Till',
650
	                    'TLOF' => 'Touchdown And Lift-off Area',
651
	                    'TMA' => 'Terminal Control Area',
652
	                    'TNA' => 'Turn Altitude',
653
	                    'TNH' => 'Turn Height',
654
	                    'TOC' => 'Top of Climb',
655
	                    'TODA' => 'Take-off Distance Available',
656
	                    'TODAH' => 'Take-off Distance Available, Helicopter',
657
	                    'TORA' => 'Take-off Run Available',
658
	                    'TP' => 'Turning Point',
659
	                    'TR' => 'Track',
660
	                    'TRA' => 'Temporary Reserved Airspace',
661
	                    'TRANS' => 'Transmitter',
662
	                    'TRL' => 'Transition Level',
663
	                    'TUE' => 'Tuesday',
664
	                    'TURB' => 'Turbulence',
665
	                    'TVOR' => 'Terminal VOR',
666
	                    'TWR' => 'Tower',
667
	                    'TWY' => 'Taxiway',
668
	                    'TWYL' => 'Taxiway-link',
669
	                    'TXT' => 'Text',
670
	                    'TYP' => 'Type of Aircraft',
671
	                    'U/S' => 'Unserviceable',
672
	                    'UAB' => 'Until Advised By',
673
	                    'UAC' => 'Upper Area Control Centre',
674
	                    'UAR' => 'Upper Air Route',
675
	                    'UDA' => 'Upper advisory area',
676
	                    'UFN' => 'Until Further Notice',
677
	                    'UHDT' => 'Unable Higher Due Traffic',
678
	                    'UIC' => 'Upper Information Centre',
679
	                    'UIR' => 'Upper Flight Information Region',
680
	                    'ULR' => 'Ultra Long Range',
681
	                    'UNA' => 'Unable',
682
	                    'UNAP' => 'Unable To Approve',
683
	                    'UNL' => 'Unlimited',
684
	                    'UNREL' => 'Unreliable',
685
	                    'UTA' => 'Upper Control Area',
686
	                    'VAAC' => 'Volcanic Ash Advisory Centre',
687
	                    'VAC' => 'Visual Approach Chart',
688
	                    'VAL' => 'In Valleys',
689
	                    'VAN' => 'Runway Control Van',
690
	                    'VAR' => 'Visual-aural Radio Range',
691
	                    'VC' => 'Vicinity',
692
	                    'VCY' => 'Vicinity',
693
	                    'VER' => 'Vertical',
694
	                    'VIS' => 'Visibility',
695
	                    'VLR' => 'Very Long Range',
696
	                    'VPA' => 'Vertical Path Angle',
697
	                    'VRB' => 'Variable',
698
	                    'VSA' => 'By Visual Reference To The Ground',
699
	                    'VSP' => 'Vertical Speed',
700
	                    'VTOL' => 'Vertical Take-off And Landing',
701
	                    'WAC' => 'World Aeronautical Chart',
702
	                    'WAFC' => 'World Area Forecast Centre',
703
	                    'WB' => 'Westbound',
704
	                    'WBAR' => 'Wing Bar Lights',
705
	                    'WDI' => 'Wind Direction Indicator',
706
	                    'WDSPR' => 'Widespread',
707
	                    'WED' => 'Wednesday',
708
	                    'WEF' => 'Effective From',
709
	                    'WI' => 'Within',
710
	                    'WID' => 'Width',
711
	                    'WIE' => 'Effective Immediately',
712
	                    'WILCO' => 'Will Comply',
713
	                    'WIND' => 'Wind',
714
	                    'WINTEM' => 'Forecast Upper Wind And Temperature For Aviation',
715
	                    'WIP' => 'Work In Progress',
716
	                    'WKN' => 'Weaken',
717
	                    'WNW' => 'West-north-west',
718
	                    'WO' => 'Without',
719
	                    'WPT' => 'Way-point',
720
	                    'WRNG' => 'Warning',
721
	                    'WSW' => 'West-south-west',
722
	                    'WT' => 'Weight',
723
	                    'WWW' => 'Worldwide Web',
724
	                    'WX' => 'Weather',
725
	                    'XBAR' => 'Crossbar',
726
	                    'XNG' => 'Crossing',
727
	                    'XS' => 'Atmospherics',
728
	                    'YCZ' => 'Yellow Caution Zone',
729
	                    'YR' => 'Your');
730
	public $code_airspace = array(
731
			    'AA' => 'Minimum altitude',
732
			    'AC' => 'Class B, C, D, or E Surface Area',
733
			    'AD' => 'Air defense identification zone',
734
			    'AE' => 'Control area',
735
			    'AF' => 'Flight information region',
736
			    'AH' => 'Upper control area',
737
			    'AL' => 'Minimum usable flight level',
738
			    'AN' => 'Area navigation route',
739
			    'AO' => 'Oceanic control area',
740
			    'AP' => 'Reporting point',
741
			    'AR' => 'ATS route',
742
			    'AT' => 'Class B Airspace',
743
			    'AU' => 'Upper flight information region',
744
			    'AV' => 'Upper advisory area',
745
			    'AX' => 'Intersection',
746
			    'AZ' => 'Aerodrome traffic zone');
747
	public $code_comradar = array(
748
			    'CA' => 'Air/ground',
749
			    'CE' => 'En route surveillance radar',
750
			    'CG' => 'Ground controlled approach system',
751
			    'CL' => 'Selective calling system',
752
			    'CM' => 'Surface movement radar',
753
			    'CP' => 'Precision approach radar',
754
			    'CR' => 'Surveillance radar element of precision approach radar system',
755
			    'CS' => 'Secondary surveillance radar',
756
			    'CT' => 'Terminal area surveillance radar');
757
	public $code_facilities = array(
758
			    'FA' => 'airport',
759
			    'FB' => 'Braking action measurement equipment',
760
			    'FC' => 'Ceiling measurement equipment',
761
			    'FD' => 'Docking system',
762
			    'FF' => 'Fire fighting and rescue',
763
			    'FG' => 'Ground movement control',
764
			    'FH' => 'Helicopter alighting area/platform',
765
			    'FL' => 'Landing direction indicator',
766
			    'FM' => 'Meteorological service',
767
			    'FO' => 'Fog dispersal system',
768
			    'FP' => 'Heliport',
769
			    'FS' => 'Snow removal equipment',
770
			    'FT' => 'Transmissometer',
771
			    'FU' => 'Fuel availability',
772
			    'FW' => 'Wind direction indicator',
773
			    'FZ' => 'Customs');
774
	public $code_instrumentlanding = array(
775
			    'ID' => 'DME associated with ILS',
776
			    'IG' => 'Glide path',
777
			    'II' => 'Inner marker',
778
			    'IL' => 'Localizer',
779
			    'IM' => 'Middle marker',
780
			    'IO' => 'Outer marker',
781
			    'IS' => 'ILS Category I',
782
			    'IT' => 'ILS Category II',
783
			    'IU' => 'ILS Category III',
784
			    'IW' => 'Microwave landing system',
785
			    'IX' => 'Locator, outer',
786
			    'IY' => 'Locator, middle');
787
	public $code_lightingfacilities = array(
788
			    'LA' => 'Approach lighting system',
789
			    'LB' => 'Airport beacon',
790
			    'LC' => 'Runway center line lights',
791
			    'LD' => 'Landing direction indicator lights',
792
			    'LE' => 'Runway edge lights',
793
			    'LF' => 'Sequenced flashing lights',
794
			    'LH' => 'High intensity runway lights',
795
			    'LI' => 'Runway end identifier lights',
796
			    'LK' => 'Category II components of approach lighting system',
797
			    'LL' => 'Low intensity runway lights',
798
			    'LM' => 'Medium intensity runway lights',
799
			    'LP' => 'Precision approach path indicator',
800
			    'LR' => 'All landing area lighting facilities',
801
			    'LS' => 'Stopway lights',
802
			    'LT' => 'Threshold lights',
803
			    'LV' => 'Visual approach slope indicator system',
804
			    'LW' => 'Heliport lighting',
805
			    'LX' => 'Taxiway center line lights',
806
			    'LY' => 'Taxiway edge lights',
807
			    'LZ' => 'Runway touchdown zone lights');
808
	public $code_movementareas = array(
809
			    'MA' => 'Movement area',
810
			    'MB' => 'Bearing strength',
811
			    'MC' => 'Clearway',
812
			    'MD' => 'Declared distances',
813
			    'MG' => 'Taxiing guidance system',
814
			    'MH' => 'Runway arresting gear',
815
			    'MK' => 'Parking area',
816
			    'MM' => 'Daylight markings',
817
			    'MN' => 'Apron',
818
			    'MP' => 'Aircraft stands',
819
			    'MR' => 'Runway',
820
			    'MS' => 'Stopway',
821
			    'MT' => 'Threshold',
822
			    'MU' => 'Runway turning bay',
823
			    'MW' => 'Strip',
824
			    'MX' => 'Taxiway');
825
	public $code_terminalfacilities = array(
826
			    'NA' => 'All radio navigation facilities',
827
			    'NB' => 'Non directional beacon',
828
			    'NC' => 'DECCA',
829
			    'ND' => 'Distance measuring equipment',
830
			    'NF' => 'Fan marker',
831
			    'NL' => 'Locator',
832
			    'NM' => 'VOR/DME',
833
			    'NN' => 'TACAN',
834
			    'NO' => 'OMEGA',
835
			    'NT' => 'VORTAC',
836
			    'NV' => 'VOR',
837
			    'NX' => 'Direction finding station');
838
	public $code_information = array(
839
			    'OA' => 'Aeronautical information service',
840
			    'OB' => 'Obstacle',
841
			    'OE' => 'Aircraft entry requirements',
842
			    'OL' => 'Obstacle lights on',
843
			    'OR' => 'Rescue coordination centre');
844
	public $code_airtraffic = array(
845
			    'PA' => 'Standard instrument arrival',
846
			    'PD' => 'Standard instrument departure',
847
			    'PF' => 'Flow control procedure',
848
			    'PH' => 'Holding procedure',
849
			    'PI' => 'Instrument approach procedure',
850
			    'PL' => 'Obstacle clearance limit',
851
			    'PM' => 'Aerodrome operating minima',
852
			    'PO' => 'Obstacle clearance altitude',
853
			    'PP' => 'Obstacle clearance height',
854
			    'PR' => 'Radio failure procedure',
855
			    'PT' => 'Transition altitude',
856
			    'PU' => 'Missed approach procedure',
857
			    'PX' => 'Minimum holding altitude',
858
			    'PZ' => 'ADIZ procedure');
859
	public $code_navigationw = array(
860
			    'RA' => 'Airspace reservation',
861
			    'RD' => 'Danger area',
862
			    'RO' => 'Overflying of',
863
			    'RP' => 'Prohibited area',
864
			    'RR' => 'Restricted area',
865
			    'RT' => 'Temporary restricted area');
866
	public $code_volmet = array(
867
			    'SA' => 'Automatic terminal information service',
868
			    'SB' => 'ATS reporting office',
869
			    'SC' => 'Area control center',
870
			    'SE' => 'Flight information service',
871
			    'SF' => 'Airport flight information service',
872
			    'SL' => 'Flow control centre',
873
			    'SO' => 'Oceanic area control centre',
874
			    'SP' => 'Approach control service',
875
			    'SS' => 'Flight service station',
876
			    'ST' => 'Airport control tower',
877
			    'SU' => 'Upper area control centre',
878
			    'SV' => 'VOLMET broadcast',
879
			    'SY' => 'Upper advisory service');
880
	public $code_warnings = array(
881
			    'WA' => 'Air display',
882
			    'WB' => 'Aerobatics',
883
			    'WC' => 'Captive balloon or kite',
884
			    'WD' => 'Demolition of explosives',
885
			    'WE' => 'Exercises',
886
			    'WF' => 'Air refueling',
887
			    'WG' => 'Glider flying',
888
			    'WJ' => 'Banner/target towing',
889
			    'WL' => 'Ascent of free balloon',
890
			    'WM' => 'Missile, gun or rocket firing',
891
			    'WP' => 'Parachute jumping exercise',
892
			    'WS' => 'Burning or blowing gas',
893
			    'WT' => 'Mass movement of aircraft',
894
			    'WV' => 'Formation flight',
895
			    'WZ' => 'model flying');
896
	public $code_sp_availabity = array(
897
			    'AC' => 'Withdrawn for maintenance',
898
			    'AD' => 'Available for daylight operation',
899
			    'AF' => 'Flight checked and found reliable',
900
			    'AG' => 'Operating but ground checked only, awaiting flight check',
901
			    'AH' => 'Hours of service are now',
902
			    'AK' => 'Resumed normal operations',
903
			    'AM' => 'Military operations only',
904
			    'AN' => 'Available for night operation',
905
			    'AO' => 'Operational',
906
			    'AP' => 'Available, prior permission required',
907
			    'AR' => 'Available on request',
908
			    'AS' => 'Unserviceable',
909
			    'AU' => 'Not available',
910
			    'AW' => 'Completely withdrawn',
911
			    'AX' => 'Previously promulgated shutdown has been cancelled');
912
	public $code_sp_changes = array(
913
			    'CA' => 'Activated',
914
			    'CC' => 'Completed',
915
			    'CD' => 'Deactivated',
916
			    'CE' => 'Erected',
917
			    'CF' => 'Operating frequency(ies) changed to',
918
			    'CG' => 'Downgraded to',
919
			    'CH' => 'Changed',
920
			    'CI' => 'dentification or radio call sign changed to',
921
			    'CL' => 'Realigned',
922
			    'CM' => 'Displaced',
923
			    'CO' => 'Operating',
924
			    'CP' => 'Operating on reduced power',
925
			    'CR' => 'Temporarily replaced by',
926
			    'CS' => 'Installed',
927
			    'CT' => 'On test, do not use');
928
	public $code_sp_hazardous = array(
929
			    'HA' => 'Braking action is',
930
			    'HB' => 'Braking coefficient is',
931
			    'HC' => 'Covered by compacted snow to depth of x Ft',
932
			    'HD' => 'Covered by dry snow to a depth of x Ft',
933
			    'HE' => 'Covered by water to a depth of x Ft',
934
			    'HF' => 'Totally free of snow and ice',
935
			    'HG' => 'Grass cutting in progress',
936
			    'HH' => 'Hazard due to',
937
			    'HI' => 'Covered by ice',
938
			    'HJ' => 'Launch planned',
939
			    'HK' => 'Migration in progress',
940
			    'HL' => 'Snow clearance completed',
941
			    'HM' => 'Marked by',
942
			    'HN' => 'Covered by wet snow or slush to a depth of x Ft',
943
			    'HO' => 'Obscured by snow',
944
			    'HP' => 'Snow clearance in progress',
945
			    'HQ' => 'Operation cancelled',
946
			    'HR' => 'Standing water',
947
			    'HS' => 'Sanding in progress',
948
			    'HT' => 'Approach according to signal area only',
949
			    'HU' => 'Launch in progress',
950
			    'HV' => 'Work completed',
951
			    'HW' => 'Work in progress',
952
			    'HX' => 'Concentration of birds',
953
			    'HY' => 'Snow banks exist',
954
			    'HZ' => 'Covered by frozen ruts and ridges');
955
	public $code_sp_limitations = array(
956
			    'LA' => 'Operating on Auxiliary Power Supply',
957
			    'LB' => 'Reserved for aircraft based therein',
958
			    'LC' => 'Closed',
959
			    'LD' => 'Unsafe',
960
			    'LE' => 'Operated without auxiliary power supply',
961
			    'LF' => 'Interference from',
962
			    'LG' => 'Operating without identification',
963
			    'LH' => 'Unserviceable for aircraft heavier than',
964
			    'LI' => 'Close to IFR operations',
965
			    'LK' => 'Operating as a fixed light',
966
			    'LL' => 'Usable for lenght of... and width of...',
967
			    'LN' => 'Close to all night operations',
968
			    'LP' => 'Prohibited to',
969
			    'LR' => 'Aircraft restricted to runways and taxiways',
970
			    'LS' => 'Subject to interruption',
971
			    'LT' => 'Limited to',
972
			    'LV' => 'Close to VFR operations',
973
			    'LW' => 'Will take place',
974
			    'LX' => 'Operating but caution advised to'); 
975
976
	public function __construct($dbc = null) {
977
		$Connection = new Connection($dbc);
978
		$this->db = $Connection->db;
979
	}
980
	public function getAllNOTAM() {
981
		global $globalDBdriver;
982
		if ($globalDBdriver == 'mysql') {
983
			$query  = 'SELECT * FROM notam WHERE radius > 0 AND date_end > UTC_TIMESTAMP() AND date_begin < UTC_TIMESTAMP()';
984
		} else {
985
			$query  = "SELECT * FROM notam WHERE radius > 0 AND date_end > CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AND date_begin < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
986
		}
987
		$query_values = array();
988
		try {
989
			$sth = $this->db->prepare($query);
990
			$sth->execute($query_values);
991
		} catch(PDOException $e) {
992
			echo "error : ".$e->getMessage();
993
		}
994
		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
995
		return $all;
996
	}
997
	public function getAllNOTAMbyFir($fir) {
998
		global $globalDBdriver;
999
		if ($globalDBdriver == 'mysql') {
1000
			$query  = 'SELECT * FROM notam WHERE date_end > UTC_TIMESTAMP() AND date_begin < UTC_TIMESTAMP() AND fir = :fir ORDER BY date_begin DESC';
1001
		} else {
1002
			$query  = "SELECT * FROM notam WHERE fir = :fir AND date_end > CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AND date_begin < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' ORDER BY date_begin DESC";
1003
		}
1004
		$query_values = array(':fir' => $fir);
1005
		try {
1006
			$sth = $this->db->prepare($query);
1007
			$sth->execute($query_values);
1008
		} catch(PDOException $e) {
1009
			echo "error : ".$e->getMessage();
1010
		}
1011
		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1012
		return $all;
1013
	}
1014
	public function getAllNOTAMtext() {
1015
		$query  = 'SELECT full_notam FROM notam';
1016
		$query_values = array();
1017
		try {
1018
			$sth = $this->db->prepare($query);
1019
			$sth->execute($query_values);
1020
		} catch(PDOException $e) {
1021
			echo "error : ".$e->getMessage();
1022
		}
1023
		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1024
		return $all;
1025
	}
1026
	public function createNOTAMtextFile($filename) {
1027
		$allnotam_result = $this->getAllNOTAMtext();
1028
		$notamtext = '';
1029
		foreach($allnotam_result as $notam) {
1030
			$notamtext .= '%%'."\n";
1031
			$notamtext .= $notam['full_notam'];
1032
			$notamtext .= "\n".'%%'."\n";
1033
		}
1034
		file_put_contents($filename,$notamtext);
1035
	}
1036
	public function parseNOTAMtextFile($filename) {
1037
		$data = file_get_contents($filename);
1038
		preg_match_all("/%%(.+?)%%/is", $data, $matches);
1039
		if (isset($matches[1])) return $matches[1];
1040
		else return array();
1041
	}
1042
	public function getAllNOTAMbyScope($scope) {
1043
		global $globalDBdriver;
1044
		if ($globalDBdriver == 'mysql') {
1045
			$query  = 'SELECT * FROM notam WHERE radius > 0 AND date_end > UTC_TIMESTAMP() AND date_begin < UTC_TIMESTAMP() AND scope = :scope';
1046
		} else {
1047
			$query  = "SELECT * FROM notam WHERE radius > 0 AND date_end > CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AND date_begin < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AND scope = :scope";
1048
		}
1049
		$query_values = array(':scope' => $scope);
1050
		try {
1051
			$sth = $this->db->prepare($query);
1052
			$sth->execute($query_values);
1053
		} catch(PDOException $e) {
1054
			echo "error : ".$e->getMessage();
1055
		}
1056
		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1057
		return $all;
1058
	}
1059
	public function getAllNOTAMbyCoord($coord) {
1060
		global $globalDBdriver;
1061
		if (is_array($coord)) {
1062
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1063
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1064
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1065
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1066
			if ($minlat > $maxlat) {
1067
				$tmplat = $minlat;
1068
				$minlat = $maxlat;
1069
				$maxlat = $tmplat;
1070
			}
1071
			if ($minlong > $maxlong) {
1072
				$tmplong = $minlong;
1073
				$minlong = $maxlong;
1074
				$maxlong = $tmplong;
1075
			}
1076
		} else return array();
1077
		if ($globalDBdriver == 'mysql') {
1078
			$query  = 'SELECT * FROM notam WHERE center_latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND center_longitude BETWEEN '.$minlong.' AND '.$maxlong.' AND radius > 0 AND date_end > UTC_TIMESTAMP() AND date_begin < UTC_TIMESTAMP()';
1079
		} else {
1080
			$query  = 'SELECT * FROM notam WHERE center_latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND center_longitude BETWEEN '.$minlong.' AND '.$maxlong." AND radius > 0 AND date_end > CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AND date_begin < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
1081
		}
1082
		$query_values = array();
1083
		try {
1084
			$sth = $this->db->prepare($query);
1085
			$sth->execute($query_values);
1086
		} catch(PDOException $e) {
1087
			echo "error : ".$e->getMessage();
1088
		}
1089
		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1090
		return $all;
1091
	}
1092
	public function getAllNOTAMbyCoordScope($coord,$scope) {
1093
		global $globalDBdriver;
1094
		if (is_array($coord)) {
1095
			$minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1096
			$minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1097
			$maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1098
			$maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
1099
		} else return array();
1100
		if ($globalDBdriver == 'mysql') {
1101
			$query  = 'SELECT * FROM notam WHERE center_latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND center_longitude BETWEEN '.$minlong.' AND '.$maxlong.' AND radius > 0 AND date_end > UTC_TIMESTAMP() AND date_begin < UTC_TIMESTAMP() AND scope = :scope';
1102
		} else {
1103
			$query  = 'SELECT * FROM notam WHERE center_latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND center_longitude BETWEEN '.$minlong.' AND '.$maxlong." AND radius > 0 AND date_end > CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AND date_begin < CURRENT_TIMESTAMP AT TIME ZONE 'UTC' AND scope = :scope";
1104
		}
1105
		$query_values = array(':scope' => $scope);
1106
		try {
1107
			$sth = $this->db->prepare($query);
1108
			$sth->execute($query_values);
1109
		} catch(PDOException $e) {
1110
			echo "error : ".$e->getMessage();
1111
		}
1112
		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1113
		return $all;
1114
	}
1115
	public function getNOTAMbyRef($ref) {
1116
		$query = "SELECT * FROM notam WHERE ref = :ref LIMIT 1";
1117
		$query_values = array('ref' => $ref);
1118
		try {
1119
			$sth = $this->db->prepare($query);
1120
			$sth->execute($query_values);
1121
		} catch(PDOException $e) {
1122
			return "error : ".$e->getMessage();
1123
		}
1124
		$all = $sth->fetchAll(PDO::FETCH_ASSOC);
1125
		if (isset($all[0])) return $all[0];
1126
		else return array();
1127
	}
1128
1129
	public function addNOTAM($ref,$title,$type,$fir,$code,$rules,$scope,$lower_limit,$upper_limit,$center_latitude,$center_longitude,$radius,$date_begin,$date_end,$permanent,$text,$full_notam) {
1130
		$query = "INSERT INTO notam (ref,title,notam_type,fir,code,rules,scope,lower_limit,upper_limit,center_latitude,center_longitude,radius,date_begin,date_end,permanent,notam_text,full_notam) VALUES (:ref,:title,:type,:fir,:code,:rules,:scope,:lower_limit,:upper_limit,:center_latitude,:center_longitude,:radius,:date_begin,:date_end,:permanent,:text,:full_notam)";
1131
		$query_values = array(':ref' => $ref,':title' => $title,':type' => $type,':fir' => $fir,':code' => $code,':rules' => $rules,':scope' => $scope,':lower_limit' => $lower_limit,':upper_limit' => $upper_limit,':center_latitude' => $center_latitude,':center_longitude' => $center_longitude,':radius' => $radius,':date_begin' => $date_begin,':date_end' => $date_end,':permanent' => $permanent,':text' => $text,':full_notam' => $full_notam);
1132
		try {
1133
			$sth = $this->db->prepare($query);
1134
			$sth->execute($query_values);
1135
		} catch(PDOException $e) {
1136
			return "error : ".$e->getMessage();
1137
		}
1138
	}
1139
1140
	public function deleteNOTAM($id) {
1141
		$query = "DELETE FROM notam WHERE id = :id";
1142
		$query_values = array(':id' => $id);
1143
		try {
1144
			$sth = $this->db->prepare($query);
1145
			$sth->execute($query_values);
1146
		} catch(PDOException $e) {
1147
			return "error : ".$e->getMessage();
1148
		}
1149
	}
1150
	public function deleteOldNOTAM() {
1151
		global $globalDBdriver;
1152
		if ($globalDBdriver == 'mysql') {
1153
			$query = "DELETE FROM notam WHERE date_end < UTC_TIMESTAMP()";
1154
		} else {
1155
			$query = "DELETE FROM notam WHERE date_end < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
1156
		}
1157
		$query_values = array();
1158
		try {
1159
			$sth = $this->db->prepare($query);
1160
			$sth->execute($query_values);
1161
		} catch(PDOException $e) {
1162
			return "error : ".$e->getMessage();
1163
		}
1164
	}
1165
	public function deleteNOTAMbyRef($ref) {
1166
		$query = "DELETE FROM notam WHERE ref = :ref";
1167
		$query_values = array(':ref' => $ref);
1168
		try {
1169
			$sth = $this->db->prepare($query);
1170
			$sth->execute($query_values);
1171
		} catch(PDOException $e) {
1172
			return "error : ".$e->getMessage();
1173
		}
1174
	}
1175
	public function deleteAllNOTAM() {
1176
		$query = "DELETE FROM notam";
1177
		try {
1178
			$sth = $this->db->prepare($query);
1179
			$sth->execute();
1180
		} catch(PDOException $e) {
1181
			return "error : ".$e->getMessage();
1182
		}
1183
	}
1184
	public function deleteAllNOTAMLocation() {
1185
		$query = "DELETE FROM notam";
1186
		try {
1187
			$sth = $this->db->prepare($query);
1188
			$sth->execute();
1189
		} catch(PDOException $e) {
1190
			return "error : ".$e->getMessage();
1191
		}
1192
	}
1193
1194
	public function updateNOTAM() {
1195
		global $globalNOTAMAirports;
1196
		if (isset($globalNOTAMAirports) && is_array($globalNOTAMAirports) && count($globalNOTAMAirports) > 0) {
1197
			foreach (array_chunk($globalNOTAMAirports,10) as $airport) {
1198
				$airport_icao = implode(',',$airport);
1199
				$alldata = $this->downloadNOTAM($airport_icao);
1200
				if (count($alldata) > 0) {
1201
					foreach ($alldata as $initial_data) {
1202
						$data = $this->parse($initial_data);
1203
						$notamref = $this->getNOTAMbyRef($data['ref']);
1204
						if (count($notamref) == 0) $this->addNOTAM($data['ref'],$data['title'],'',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1205
					}
1206
				}
1207
			}
1208
		}
1209
	}
1210
	public function updateNOTAMfromTextFile($filename) {
1211
		global $globalTransaction, $globalDebug;
1212
		$alldata = $this->parseNOTAMtextFile($filename);
1213
		if (count($alldata) > 0) {
1214
			$this->deleteOldNOTAM();
1215
			if ($globalTransaction) $this->db->beginTransaction();
1216
			$j = 0;
1217
			foreach ($alldata as $initial_data) {
1218
				$j++;
1219
				$data = $this->parse($initial_data);
1220
				$notamref = $this->getNOTAMbyRef($data['ref']);
1221
				if (!isset($notamref['notam_id'])) $this->addNOTAM($data['ref'],$data['title'],'',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1222
				if ($globalTransaction && $j % 1000 == 0) {
1223
					$this->db->commit();
1224
					if ($globalDebug) echo '.';
1225
					$this->db->beginTransaction();
1226
				}
1227
			}
1228
			if ($globalTransaction) $this->db->commit();
1229
		}
1230
	}
1231
1232
	public function updateNOTAMallAirports() {
1233
		global $globalTransaction;
1234
		$Spotter = new Spotter($this->db);
1235
		$allairports = $Spotter->getAllAirportInfo();
1236
		foreach (array_chunk($allairports,20) as $airport) {
1237
			$airports_icao = array();
1238
			foreach($airport as $icao) {
1239
				if (isset($icao['icao'])) $airports_icao[] = $icao['icao'];
1240
			}
1241
			$airport_icao = implode(',',$airports_icao);
1242
			$alldata = $this->downloadNOTAM($airport_icao);
1243
			if ($globalTransaction) $this->db->beginTransaction();
1244
			if (count($alldata) > 0) {
1245
				foreach ($alldata as $initial_data) {
1246
					//print_r($initial_data);
1247
					$data = $this->parse($initial_data);
1248
					//print_r($data);
1249
					if (isset($data['ref'])) {
1250
						$notamref = $this->getNOTAMbyRef($data['ref']);
1251
						if (count($notamref) == 0) {
1252
							if (isset($data['ref_replaced'])) $this->deleteNOTAMbyRef($data['ref_replaced']);
1253
							if (isset($data['ref_cancelled'])) $this->deleteNOTAMbyRef($data['ref_cancelled']);
1254
							elseif (isset($data['latitude']) && isset($data['scope']) && isset($data['text']) && isset($data['permanent'])) echo $this->addNOTAM($data['ref'],'','',$data['fir'],$data['code'],'',$data['scope'],$data['lower_limit'],$data['upper_limit'],$data['latitude'],$data['longitude'],$data['radius'],$data['date_begin'],$data['date_end'],$data['permanent'],$data['text'],$data['full_notam']);
1255
						}
1256
					}
1257
				}
1258
			} else echo 'Error on download. Nothing matches for '.$airport_icao."\n";
1259
			if ($globalTransaction) $this->db->commit();
1260
			sleep(5);
1261
		}
1262
	}
1263
1264
	public function downloadNOTAM($icao) {
1265
		date_default_timezone_set("UTC");
1266
		$Common = new Common();
1267
		//$url = str_replace('{icao}',$icao,'https://pilotweb.nas.faa.gov/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs&reportType=RAW&formatType=DOMESTIC&retrieveLocId={icao}&actionType=notamRetrievalByICAOs');
1268
		$url = str_replace('{icao}',$icao,'https://pilotweb.nas.faa.gov/PilotWeb/notamRetrievalByICAOAction.do?method=displayByICAOs&reportType=RAW&formatType=ICAO&retrieveLocId={icao}&actionType=notamRetrievalByICAOs');
1269
		$data = $Common->getData($url);
1270
		preg_match_all("/<pre>(.+?)<\/pre>/is", $data, $matches);
1271
		//print_r($matches);
1272
		if (isset($matches[1])) return $matches[1];
1273
		else return array();
1274
	}
1275
1276
	public function parse($data) {
1277
		global $globalDebug;
1278
		$Common = new Common();
1279
		$result = array();
1280
		$result['full_notam'] = $data;
1281
		$result['text'] = '';
1282
		$result['permanent'] = '';
1283
		$result['date_begin'] = NULL;
1284
		$result['date_end'] = NULL;
1285
		$data = str_ireplace(array("\r","\n",'\r','\n'),' ',$data);
1286
		$data = preg_split('#\s(?=([A-Z]\)\s))#',$data);
1287
		$q = false;
1288
		$a = false;
1289
		$b = false;
1290
		$c = false;
1291
		$e = false;
1292
		foreach ($data as $line) {
1293
			$line = trim($line);
1294
			if (preg_match('#(^|\s)Q\) (.*)#',$line,$matches) && $q === false) {
1295
				$line = str_replace(' ','',$line);
1296
				if (preg_match('#Q\)([A-Z]{3,4})\/([A-Z]{5})\/(IV|I|V)\/([A-Z]{1,3})\/([A-Z]{1,2})\/([0-9]{3})\/([0-9]{3})\/([0-9]{4})(N|S)([0-9]{5})(E|W)([0-9]{3}|)#',$line,$matches)) {
1297
				//if (preg_match('#Q\)([A-Z]{4})\/([A-Z]{5})\/(IV|I|V)\/([A-Z]{1,3})\/([A-Z]{1,2})\/([0-9]{3})\/([0-9]{3})\/([0-9]{4})(N|S)([0-9]{5})(E|W)([0-9]{3})#',$line,$matches)) {
1298
					$result['fir'] = $matches[1];
1299
					$result['code'] = $matches[2];
1300
					$result['title'] = $this->parse_code($result['code']);
1301
					$rules = str_split($matches[3]);
1302
					foreach ($rules as $rule) {
1303
						if ($rule == 'I') {
1304
							if (isset($result['rules'])) $result['rules'] = $result['rules'].'/IFR';
1305
							else $result['rules'] = 'IFR';
1306
						} elseif ($rule == 'V') {
1307
							if (isset($result['rules'])) $result['rules'] = $result['rules'].'/VFR';
1308
							else $result['rules'] = 'VFR';
1309
						} elseif ($rule == 'K') {
1310
							if (isset($result['rules'])) $result['rules'] = $result['rules'].'/Checklist';
1311
							else $result['rules'] = 'Checklist';
1312
						}
1313
					}
1314
					$attentions = str_split($matches[4]);
1315
					foreach ($attentions as $attention) {
1316
						if ($attention == 'N') {
1317
							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Immediate attention';
1318
							else $result['rules'] = 'Immediate attention';
1319
						} elseif ($attention == 'B') {
1320
							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Operational significance';
1321
							else $result['rules'] = 'Operational significance';
1322
						} elseif ($attention == 'O') {
1323
							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Flight operations';
1324
							else $result['rules'] = 'Flight operations';
1325
						} elseif ($attention == 'M') {
1326
							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Misc';
1327
							else $result['rules'] = 'Misc';
1328
						} elseif ($attention == 'K') {
1329
							if (isset($result['attention'])) $result['attention'] = $result['attention'].' / Checklist';
1330
							else $result['rules'] = 'Checklist';
1331
						}
1332
					}
1333
					if ($matches[5] == 'A') $result['scope'] = 'Airport warning';
1334
					elseif ($matches[5] == 'E') $result['scope'] = 'Enroute warning';
1335
					elseif ($matches[5] == 'W') $result['scope'] = 'Navigation warning';
1336
					elseif ($matches[5] == 'K') $result['scope'] = 'Checklist';
1337
					elseif ($matches[5] == 'AE') $result['scope'] = 'Airport/Enroute warning';
1338
					elseif ($matches[5] == 'AW') $result['scope'] = 'Airport/Navigation warning';
1339
					$result['lower_limit'] = $matches[6];
1340
					$result['upper_limit'] = $matches[7];
1341
					$latitude = $Common->convertDec($matches[8],'latitude');
1342
					if ($matches[9] == 'S') $latitude = -$latitude;
1343
					$longitude = $Common->convertDec($matches[10],'longitude');
1344
					if ($matches[11] == 'W') $longitude = -$longitude;
1345
					$result['latitude'] = $latitude;
1346
					$result['longitude'] = $longitude;
1347
					if ($matches[12] != '') $result['radius'] = intval($matches[12]);
1348
					else $result['radius'] = 0;
1349
					$q = true;
1350
				} elseif ($globalDebug) {
1351
					echo 'NOTAM error : '.$result['full_notam']."\n";
1352
					echo "Can't parse : ".$line."\n";
1353
				}
1354
			}
1355
			elseif (preg_match('#(^|\s)A\) (.*)#',$line,$matches) && $a === false) {
1356
				$result['icao'] = $matches[2];
1357
				$a = true;
1358
			}
1359
			elseif (preg_match('#(^|\s)B\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})#',$line,$matches) && $b === false) {
1360
				if ($matches[1] > 50) $year = '19'.$matches[2];
1361
				else $year = '20'.$matches[2];
1362
				$result['date_begin'] = $year.'/'.$matches[3].'/'.$matches[4].' '.$matches[5].':'.$matches[6];
1363
				$b = true;
1364
			}
1365
			elseif (preg_match('#(^|\s)C\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#',$line,$matches) && $c === false) {
1366
				if ($matches[2] > 50) $year = '19'.$matches[2];
1367
				else $year = '20'.$matches[2];
1368
				$result['date_end'] = $year.'/'.$matches[3].'/'.$matches[4].' '.$matches[5].':'.$matches[6];
1369
				$result['permanent'] = 0;
1370
				$c = true;
1371
			}
1372
			elseif (preg_match('#(^|\s)C\) ([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2}) (EST|PERM)$#',$line,$matches) && $c === false) {
1373
				if ($matches[2] > 50) $year = '19'.$matches[2];
1374
				else $year = '20'.$matches[2];
1375
				$result['date_end'] = $year.'/'.$matches[3].'/'.$matches[4].' '.$matches[5].':'.$matches[6];
1376
				if ($matches[7] == 'EST') $result['estimated'] = 1;
1377
				else $result['estimated'] = 0;
1378
				if ($matches[7] == 'PERM') $result['permanent'] = 1;
1379
				else $result['permanent'] = 0;
1380
				$c = true;
1381
			}
1382
			elseif (preg_match('#(^|\s)C\) (EST|PERM)$#',$line,$matches) && $c === false) {
1383
				$result['date_end'] = '2030/12/20 12:00';
1384
				if ($matches[2] == 'EST') $result['estimated'] = 1;
1385
				else $result['estimated'] = 0;
1386
				if ($matches[2] == 'PERM') $result['permanent'] = 1;
1387
				else $result['permanent'] = 0;
1388
				$c = true;
1389
			}
1390
			elseif (preg_match('#(^|\s)E\) (.*)#',$line,$matches) && $e === false) {
1391
				$rtext = array();
1392
				$text = explode(' ',$matches[2]);
1393
				foreach ($text as $word) {
1394
					if (isset($this->abbr[$word])) $rtext[] = strtoupper($this->abbr[$word]);
1395
					elseif (ctype_digit(strval(substr($word,3))) && isset($this->abbr[substr($word,0,3)])) $rtext[] = strtoupper($this->abbr[substr($word,0,3)]).' '.substr($word,3);
1396
					else $rtext[] = $word;
1397
				}
1398
				$result['text'] = implode(' ',$rtext);
1399
				$e = true;
1400
			//} elseif (preg_match('#F\) (.*)#',$line,$matches)) {
1401
			//} elseif (preg_match('#G\) (.*)#',$line,$matches)) {
1402
			} elseif (preg_match('#(NOTAMN|NOTAMR|NOTAMC)#',$line,$matches)) {
1403
				$text = explode(' ',$line);
1404
				$result['ref'] = $text[0];
1405
				if ($matches[1] == 'NOTAMN') $result['type'] = 'new';
1406
				if ($matches[1] == 'NOTAMC') {
1407
					$result['type'] = 'cancel';
1408
					$result['ref_cancelled'] = $text[2];
1409
				}
1410
				if ($matches[1] == 'NOTAMR') {
1411
					$result['type'] = 'replace';
1412
					$result['ref_replaced'] = $text[2];
1413
				}
1414
			}
1415
		}
1416
		return $result;
1417
	}
1418
	
1419
	public function parse_code($code) {
1420
		$code = str_split($code);
1421
		$code_fp = $code[1].$code[2];
1422
		$code_sp = $code[3].$code[4];
1423
		$result = '';
1424
		switch ($code[1]) {
1425
			case 'A':
1426
				$result = 'Airspace organization ';
1427
				if (isset($this->code_airspace[$code_fp])) $result .= $this->code_airspace[$code_fp];
1428
				break;
1429
			case 'C':
1430
				$result = 'Communications and radar facilities ';
1431
				if (isset($this->code_comradar[$code_fp])) $result .= $this->code_comradar[$code_fp];
1432
				break;
1433
			case 'F':
1434
				$result = 'Facilities and services ';
1435
				if (isset($this->code_facilities[$code_fp])) $result .= $this->code_facilities[$code_fp];
1436
				break;
1437
			case 'I':
1438
				$result = 'Instrument and Microwave Landing System ';
1439
				if (isset($this->code_instrumentlanding[$code_fp])) $result .= $this->code_instrumentlanding[$code_fp];
1440
				break;
1441
			case 'L':
1442
				$result = 'Lighting facilities ';
1443
				if (isset($this->code_lightingfacilities[$code_fp])) $result .= $this->code_lightingfacilities[$code_fp];
1444
				break;
1445
			case 'M':
1446
				$result = 'Movement and landing areas ';
1447
				if (isset($this->code_movementareas[$code_fp])) $result .= $this->code_movementareas[$code_fp];
1448
				break;
1449
			case 'N':
1450
				$result = 'Terminal and En Route Navigation Facilities ';
1451
				if (isset($this->code_terminalfacilities[$code_fp])) $result .= $this->code_terminalfacilities[$code_fp];
1452
				break;
1453
			case 'O':
1454
				$result = 'Other information ';
1455
				if (isset($this->code_information[$code_fp])) $result .= $this->code_information[$code_fp];
1456
				break;
1457
			case 'P':
1458
				$result = 'Air Traffic procedures ';
1459
				if (isset($this->code_airtraffic[$code_fp])) $result .= $this->code_airtraffic[$code_fp];
1460
				break;
1461
			case 'R':
1462
				$result = 'Navigation Warnings: Airspace Restrictions ';
1463
				if (isset($this->code_navigationw[$code_fp])) $result .= $this->code_navigationw[$code_fp];
1464
				break;
1465
			case 'S':
1466
				$result = 'Air Traffic and VOLMET Services ';
1467
				if (isset($this->code_volmet[$code_fp])) $result .= $this->code_volmet[$code_fp];
1468
				break;
1469
			case 'W':
1470
				$result = 'Navigation Warnings: Warnings ';
1471
				if (isset($this->code_warnings[$code_fp])) $result .= $this->code_warnings[$code_fp];
1472
				break;
1473
		}
1474
		switch ($code[3]) {
1475
			case 'A':
1476
				// Availability
1477
				if (isset($this->code_sp_availabity[$code_sp])) $result .= ' '.$this->code_sp_availabity[$code_sp];
1478
				break;
1479
			case 'C':
1480
				// Changes
1481
				if (isset($this->code_sp_changes[$code_sp])) $result .= ' '.$this->code_sp_changes[$code_sp];
1482
				break;
1483
			case 'H':
1484
				// Hazardous conditions
1485
				if (isset($this->code_sp_hazardous[$code_sp])) $result .= ' '.$this->code_sp_hazardous[$code_sp];
1486
				break;
1487
			case 'L':
1488
				// Limitations
1489
				if (isset($this->code_sp_limitations[$code_sp])) $result .= ' '.$this->code_sp_limitations[$code_sp];
1490
				break;
1491
			case 'X':
1492
				// Other Information
1493
				break;
1494
		}
1495
		return trim($result);
1496
	}
1497
}
1498
/*
1499
$NOTAM = new NOTAM();
1500
//print_r($NOTAM->downloadNOTAM('lfll'));
1501
//print_r($NOTAM->parse(''));
1502
//$NOTAM->deleteAllNOTAM();
1503
//$NOTAM->updateNOTAMallAirports();
1504
//echo $NOTAM->parse_code('QFATT');
1505
//$NOTAM->createNOTAMtextFile('../install/tmp/notam.txt');
1506
$NOTAM->updateNOTAMfromTextFile('../install/tmp/notam.txt');
1507
*/
1508
1509
?>